Commit fc9c0204 authored by Ilya Kirillov's avatar Ilya Kirillov

Reworked replacing content control function.

parent de3dc3e3
...@@ -15328,6 +15328,25 @@ CDocument.prototype.GetContentControl = function(Id) ...@@ -15328,6 +15328,25 @@ CDocument.prototype.GetContentControl = function(Id)
{ {
return this.TableId.Get_ById(Id); return this.TableId.Get_ById(Id);
}; };
CDocument.prototype.ClearContentControl = function(Id)
{
var oContentControl = this.TableId.Get_ById(Id);
if (!oContentControl)
return null;
this.RemoveSelection();
if (oContentControl.GetContentControlType
&& (AscCommonWord.sdttype_BlockLevel === oContentControl.GetContentControlType()
|| AscCommonWord.sdttype_InlineLevel === oContentControl.GetContentControlType()))
{
oContentControl.ClearContentControl();
oContentControl.SetThisElementCurrent();
oContentControl.MoveCursorToStartPos();
}
return oContentControl;
};
CDocument.prototype.GetAllSignatures = function() CDocument.prototype.GetAllSignatures = function()
{ {
return this.DrawingObjects.getAllSignatures(); return this.DrawingObjects.getAllSignatures();
......
...@@ -2762,6 +2762,18 @@ CParagraphContentWithParagraphLikeContent.prototype.SelectThisElement = function ...@@ -2762,6 +2762,18 @@ CParagraphContentWithParagraphLikeContent.prototype.SelectThisElement = function
return true; return true;
}; };
CParagraphContentWithParagraphLikeContent.prototype.SetThisElementCurrent = function()
{
var ContentPos = this.Paragraph.Get_PosByElement(this);
if (!ContentPos)
return;
var StartPos = ContentPos.Copy();
this.Get_StartPos(StartPos, StartPos.Get_Depth() + 1);
this.Paragraph.Set_ParaContentPos(StartPos, true, -1, -1);
this.Paragraph.Document_SetThisElementCurrent(false);
};
CParagraphContentWithParagraphLikeContent.prototype.GetSelectedContentControls = function(arrContentControls) CParagraphContentWithParagraphLikeContent.prototype.GetSelectedContentControls = function(arrContentControls)
{ {
if (true === this.Selection.Use) if (true === this.Selection.Use)
......
...@@ -932,6 +932,10 @@ CBlockLevelSdt.prototype.SelectContentControl = function() ...@@ -932,6 +932,10 @@ CBlockLevelSdt.prototype.SelectContentControl = function()
this.SelectAll(1); this.SelectAll(1);
this.Set_CurrentElement(false, 0, this.Content); this.Set_CurrentElement(false, 0, this.Content);
}; };
CBlockLevelSdt.prototype.SetThisElementCurrent = function()
{
this.Set_CurrentElement(false, 0, this.Content);
};
CBlockLevelSdt.prototype.RemoveContentControlWrapper = function() CBlockLevelSdt.prototype.RemoveContentControlWrapper = function()
{ {
if (!this.Parent) if (!this.Parent)
...@@ -1071,6 +1075,15 @@ CBlockLevelSdt.prototype.Restart_CheckSpelling = function() ...@@ -1071,6 +1075,15 @@ CBlockLevelSdt.prototype.Restart_CheckSpelling = function()
{ {
this.Content.Restart_CheckSpelling(); this.Content.Restart_CheckSpelling();
}; };
CBlockLevelSdt.prototype.ClearContentControl = function()
{
var oPara = new Paragraph(this.LogicDocument.Get_DrawingDocument(), this.Content);
oPara.Correct_Content();
this.Content.Add_ToContent(0, oPara);
this.Content.Remove_FromContent(1, this.Content.Get_ElementsCount() - 1);
this.Content.MoveCursorToStartPos(false);
};
//--------------------------------------------------------export-------------------------------------------------------- //--------------------------------------------------------export--------------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {}; window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CBlockLevelSdt = CBlockLevelSdt; window['AscCommonWord'].CBlockLevelSdt = CBlockLevelSdt;
......
...@@ -491,6 +491,11 @@ CInlineLevelSdt.prototype.GetSelectedContentControls = function(arrContentContro ...@@ -491,6 +491,11 @@ CInlineLevelSdt.prototype.GetSelectedContentControls = function(arrContentContro
arrContentControls.push(this); arrContentControls.push(this);
CParagraphContentWithParagraphLikeContent.prototype.GetSelectedContentControls.call(this, arrContentControls); CParagraphContentWithParagraphLikeContent.prototype.GetSelectedContentControls.call(this, arrContentControls);
}; };
CInlineLevelSdt.prototype.ClearContentControl = function()
{
this.Add_ToContent(0, new ParaRun(this.GetParagraph(), false));
this.Remove_FromContent(1, this.Content.length - 1);
};
//--------------------------------------------------------export-------------------------------------------------------- //--------------------------------------------------------export--------------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {}; window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].CInlineLevelSdt = CInlineLevelSdt; window['AscCommonWord'].CInlineLevelSdt = CInlineLevelSdt;
......
...@@ -434,20 +434,36 @@ ...@@ -434,20 +434,36 @@
while (this.current < this.documents.length) // no recursion while (this.current < this.documents.length) // no recursion
{ {
if (false === LogicDocument.Document_Is_SelectionLocked(AscCommon.changestype_Document_Content_Add)) var _current = this.documents[this.current];
var _isLocked = false;
if ((_current["Url"] !== undefined || _current["Script"] !== undefined) && undefined !== _current["Props"]["InternalId"])
{ {
var _current = this.documents[this.current]; var _internalId = _current["Props"]["InternalId"];
var _contentControl = g_oTableId.Get_ById(_internalId);
_isLocked = LogicDocument.Document_Is_SelectionLocked(AscCommon.changestype_None, {
Type : AscCommon.changestype_2_ElementsArray_and_Type,
Elements : [_contentControl],
CheckType : AscCommon.changestype_Document_Content_Add
});
}
else
{
_isLocked = LogicDocument.Document_Is_SelectionLocked(AscCommon.changestype_Document_Content_Add);
}
if (false === _isLocked)
{
var _content_control_pr; var _content_control_pr;
var _blockStd; var _blockStd;
var _isReplaced = false;
if (_current["Url"] !== undefined || _current["Script"] !== undefined) if (_current["Url"] !== undefined || _current["Script"] !== undefined)
{ {
_blockStd = null;
if (undefined !== _current["Props"]["InternalId"]) if (undefined !== _current["Props"]["InternalId"])
{ {
// remove block sdt _blockStd = LogicDocument.ClearContentControl(_current["Props"]["InternalId"]);
LogicDocument.SelectContentControl(_current["Props"]["InternalId"]); _isReplaced = true;
LogicDocument.RemoveContentControl(_current["Props"]["InternalId"]);
} }
_content_control_pr = new AscCommonWord.CContentControlPr(); _content_control_pr = new AscCommonWord.CContentControlPr();
...@@ -456,11 +472,15 @@ ...@@ -456,11 +472,15 @@
_content_control_pr.Lock = AscCommonWord.sdtlock_Unlocked; _content_control_pr.Lock = AscCommonWord.sdtlock_Unlocked;
_content_control_pr.InternalId = _current["Props"]["InternalId"]; _content_control_pr.InternalId = _current["Props"]["InternalId"];
var oCurPara = LogicDocument.GetCurrentParagraph(); if (null === _blockStd)
if (oCurPara && !oCurPara.IsCursorAtBegin()) {
LogicDocument.AddNewParagraph(false, true); var oCurPara = LogicDocument.GetCurrentParagraph();
if (oCurPara && !oCurPara.IsCursorAtBegin())
LogicDocument.AddNewParagraph(false, true);
_blockStd = LogicDocument.AddContentControl(AscCommonWord.sdttype_BlockLevel);
}
var _blockStd = LogicDocument.AddContentControl(AscCommonWord.sdttype_BlockLevel);
_blockStd.SetContentControlPr(_content_control_pr); _blockStd.SetContentControlPr(_content_control_pr);
_obj = _blockStd.GetContentControlPr(); _obj = _blockStd.GetContentControlPr();
...@@ -497,12 +517,22 @@ ...@@ -497,12 +517,22 @@
var _script = "(function(){ var Api = window.g_asc_plugins.api;\n" + _current["Script"] + "\n})();"; var _script = "(function(){ var Api = window.g_asc_plugins.api;\n" + _current["Script"] + "\n})();";
eval(_script); eval(_script);
if(_blockStd.Content.Get_ElementsCount() > 1) if (_isReplaced)
{ {
_blockStd.Content.Remove_FromContent(_blockStd.Content.Get_ElementsCount() - 1 , 1); if (_blockStd.Content.Get_ElementsCount() > 1)
_blockStd.MoveCursorToEndPos(false, false); _blockStd.Content.Remove_FromContent(_blockStd.Content.Get_ElementsCount() - 1, 1);
_blockStd.MoveCursorToStartPos(false);
}
else
{
if (_blockStd.Content.Get_ElementsCount() > 1)
{
_blockStd.Content.Remove_FromContent(_blockStd.Content.Get_ElementsCount() - 1, 1);
_blockStd.MoveCursorToEndPos(false, false);
}
LogicDocument.MoveCursorRight(false, false, true);
} }
LogicDocument.MoveCursorRight(false, false, true);
var _worker = _api.__content_control_worker; var _worker = _api.__content_control_worker;
if (_worker.documents[_worker.current]["Props"]) if (_worker.documents[_worker.current]["Props"])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment