Commit be71d4a0 authored by Ilya Kirillov's avatar Ilya Kirillov

Implemented function for adding a ContentControl into the current cursor position.

parent 582f6f25
......@@ -7404,20 +7404,14 @@ CDocument.prototype.Get_NearestPos = function(PageNum, X, Y, bAnchor, Drawing)
var ElementPageIndex = this.private_GetElementPageIndexByXY(ContentPos, X, Y, PageNum);
return this.Content[ContentPos].GetNearestPos(ElementPageIndex, X, Y, bAnchor, Drawing);
};
CDocument.prototype.Internal_Content_Add = function(Position, NewObject, bCheckTable)
CDocument.prototype.Internal_Content_Add = function(Position, NewObject, bCheckLastElement)
{
// Position = this.Content.length допускается
if (Position < 0 || Position > this.Content.length)
return;
var PrevObj = this.Content[Position - 1];
var NextObj = this.Content[Position];
if ("undefined" == typeof(PrevObj))
PrevObj = null;
if ("undefined" == typeof(NextObj))
NextObj = null;
var PrevObj = this.Content[Position - 1] ? this.Content[Position - 1] : null;
var NextObj = this.Content[Position] ? this.Content[Position] : null;
this.private_RecalculateNumbering([NewObject]);
this.History.Add(new CChangesDocumentAddItem(this, Position, [NewObject]));
......@@ -7438,28 +7432,22 @@ CDocument.prototype.Internal_Content_Add = function(Position, NewObject, bCheckT
// Проверим последний параграф
this.Check_SectionLastParagraph();
// Проверим, что последний элемент не таблица
if (false != bCheckTable && type_Table == this.Content[this.Content.length - 1].GetType())
// Проверим, что последний элемент - параграф
if (false !== bCheckLastElement && type_Paragraph !== this.Content[this.Content.length - 1].GetType())
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this));
// Запоминаем, что нам нужно произвести переиндексацию элементов
this.private_ReindexContent(Position);
};
CDocument.prototype.Internal_Content_Remove = function(Position, Count, bCorrectionCheck)
CDocument.prototype.Internal_Content_Remove = function(Position, Count, bCheckLastElement)
{
var ChangePos = -1;
if (Position < 0 || Position >= this.Content.length || Count <= 0)
return -1;
var PrevObj = this.Content[Position - 1];
var NextObj = this.Content[Position + Count];
if ("undefined" == typeof(PrevObj))
PrevObj = null;
if ("undefined" == typeof(NextObj))
NextObj = null;
var PrevObj = this.Content[Position - 1] ? this.Content[Position - 1] : null;
var NextObj = this.Content[Position + Count] ? this.Content[Position + Count] : null;
for (var Index = 0; Index < Count; Index++)
{
......@@ -7476,8 +7464,8 @@ CDocument.prototype.Internal_Content_Remove = function(Position, Count, bCorrect
if (null != NextObj)
NextObj.Set_DocumentPrev(PrevObj);
// Проверим, что последний параграф
if (false !== bCorrectionCheck && (this.Content.length <= 0 || type_Paragraph !== this.Content[this.Content.length - 1].GetType()))
// Проверим, что последний элемент - параграф
if (false !== bCheckLastElement && (this.Content.length <= 0 || type_Paragraph !== this.Content[this.Content.length - 1].GetType()))
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this));
// Обновим информацию о секциях
......@@ -15030,6 +15018,10 @@ CDocument.prototype.controller_GetCurrentSectionPr = function()
var nContentPos = this.CurPos.ContentPos;
return this.SectionsInfo.Get_SectPr(nContentPos).SectPr;
};
CDocument.prototype.controller_AddContentControl = function()
{
this.private_AddContentControl();
};
//----------------------------------------------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------------------------------------------
......@@ -15225,6 +15217,13 @@ CDocument.prototype.OnContentControlTrackEnd = function(Id, NearestPos, isCopy)
}
}
};
CDocument.prototype.AddContentControl = function()
{
if (true === this.IsSelectionUse())
this.RemoveBeforePaste();
this.Controller.AddContentControl();
};
function CDocumentSelectionState()
{
......
......@@ -7209,75 +7209,63 @@ CDocumentContent.prototype.private_CheckCurPage = function()
}
}
};
CDocumentContent.prototype.Internal_Content_Add = function(Position, NewObject, bCheckTable)
CDocumentContent.prototype.Internal_Content_Add = function(Position, NewObject, bCheckLastElement)
{
// Position = this.Content.length допускается
if (Position < 0 || Position > this.Content.length)
return;
var PrevObj = this.Content[Position - 1];
var NextObj = this.Content[Position];
if ("undefined" == typeof(PrevObj))
PrevObj = null;
// Position = this.Content.length допускается
if (Position < 0 || Position > this.Content.length)
return;
if ("undefined" == typeof(NextObj))
NextObj = null;
var PrevObj = this.Content[Position - 1] ? this.Content[Position - 1] : null;
var NextObj = this.Content[Position] ? this.Content[Position] : null;
this.private_RecalculateNumbering([NewObject]);
History.Add(new CChangesDocumentContentAddItem(this, Position, [NewObject]));
this.Content.splice(Position, 0, NewObject);
NewObject.Set_Parent(this);
NewObject.Set_DocumentNext(NextObj);
NewObject.Set_DocumentPrev(PrevObj);
this.private_RecalculateNumbering([NewObject]);
History.Add(new CChangesDocumentContentAddItem(this, Position, [NewObject]));
this.Content.splice(Position, 0, NewObject);
NewObject.Set_Parent(this);
NewObject.Set_DocumentNext(NextObj);
NewObject.Set_DocumentPrev(PrevObj);
if (null != PrevObj)
PrevObj.Set_DocumentNext(NewObject);
if (null != PrevObj)
PrevObj.Set_DocumentNext(NewObject);
if (null != NextObj)
NextObj.Set_DocumentPrev(NewObject);
if (null != NextObj)
NextObj.Set_DocumentPrev(NewObject);
if (Position <= this.CurPos.TableMove)
this.CurPos.TableMove++;
if (Position <= this.CurPos.TableMove)
this.CurPos.TableMove++;
// Проверим, что последний элемент не таблица
if (false != bCheckTable && type_Table == this.Content[this.Content.length - 1].GetType())
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this, this.bPresentation === true));
// Проверим, что последний элемент - параграф
if (false != bCheckLastElement && type_Paragraph !== this.Content[this.Content.length - 1].GetType())
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this, this.bPresentation === true));
this.private_ReindexContent(Position);
this.private_ReindexContent(Position);
};
CDocumentContent.prototype.Internal_Content_Remove = function(Position, Count, bCorrectionCheck)
CDocumentContent.prototype.Internal_Content_Remove = function(Position, Count, bCheckLastElement)
{
if (Position < 0 || Position >= this.Content.length || Count <= 0)
return;
var PrevObj = this.Content[Position - 1];
var NextObj = this.Content[Position + Count];
if ("undefined" == typeof(PrevObj))
PrevObj = null;
if (Position < 0 || Position >= this.Content.length || Count <= 0)
return;
if ("undefined" == typeof(NextObj))
NextObj = null;
var PrevObj = this.Content[Position - 1] ? this.Content[Position - 1] : null;
var NextObj = this.Content[Position + Count] ? this.Content[Position + Count] : null;
for (var Index = 0; Index < Count; Index++)
this.Content[Position + Index].PreDelete();
for (var Index = 0; Index < Count; Index++)
this.Content[Position + Index].PreDelete();
History.Add(new CChangesDocumentContentRemoveItem(this, Position, this.Content.slice(Position, Position + Count)));
var Elements = this.Content.splice(Position, Count);
this.private_RecalculateNumbering(Elements);
History.Add(new CChangesDocumentContentRemoveItem(this, Position, this.Content.slice(Position, Position + Count)));
var Elements = this.Content.splice(Position, Count);
this.private_RecalculateNumbering(Elements);
if (null != PrevObj)
PrevObj.Set_DocumentNext(NextObj);
if (null != PrevObj)
PrevObj.Set_DocumentNext(NextObj);
if (null != NextObj)
NextObj.Set_DocumentPrev(PrevObj);
if (null != NextObj)
NextObj.Set_DocumentPrev(PrevObj);
// Проверим, что последний элемент не таблица
if (false !== bCorrectionCheck && (this.Content.length <= 0 || type_Table == this.Content[this.Content.length - 1].GetType()))
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this, this.bPresentation === true));
// Проверим, что последний элемент - параграф
if (false !== bCheckLastElement && (this.Content.length <= 0 || type_Paragraph !== this.Content[this.Content.length - 1].GetType()))
this.Internal_Content_Add(this.Content.length, new Paragraph(this.DrawingDocument, this, this.bPresentation === true));
this.private_ReindexContent(Position);
this.private_ReindexContent(Position);
};
CDocumentContent.prototype.Clear_ContentChanges = function()
{
......@@ -8490,6 +8478,13 @@ CDocumentContent.prototype.IsSelectedAll = function()
return false;
};
CDocumentContent.prototype.AddContentControl = function()
{
if (docpostype_DrawingObjects === this.CurPos.Type)
this.DrawingObjects.AddContentControl();
else
this.private_AddContentControl();
};
function CDocumentContentStartState(DocContent)
......
......@@ -695,4 +695,38 @@ CDocumentContentBase.prototype.private_Remove = function(Count, bOnlyText, bRemo
CDocumentContentBase.prototype.IsBlockLevelSdtContent = function()
{
return false;
};
CDocumentContentBase.prototype.private_AddContentControl = function()
{
// Селекта быть не должно при выполнении данной функции, поэтому не проверяем
var oElement = this.Content[this.CurPos.ContentPos];
if (type_Paragraph === oElement.GetType())
{
var oSdt = new CBlockLevelSdt(editor.WordControl.m_oLogicDocument, this);
if (oElement.IsCursorAtEnd())
{
this.Internal_Content_Add(this.CurPos.ContentPos + 1, oSdt);
this.CurPos.ContentPos = this.CurPos.ContentPos + 1;
}
else if (oElement.IsCursorAtBegin())
{
this.Internal_Content_Add(this.CurPos.ContentPos, oSdt);
}
else
{
var oNewParagraph = new Paragraph(this.DrawingDocument, this);
oElement.Split(oNewParagraph);
this.Internal_Content_Add(this.CurPos.ContentPos + 1, oSdt);
this.Internal_Content_Add(this.CurPos.ContentPos + 2, oNewParagraph);
this.CurPos.ContentPos = this.CurPos.ContentPos + 1;
}
oSdt.MoveCursorToStartPos(false);
}
else
{
oElement.AddContentControl();
}
};
\ No newline at end of file
......@@ -571,6 +571,9 @@ CDocumentContentElementBase.prototype.GetSelectionAnchorPos = function()
{
return null;
};
CDocumentContentElementBase.prototype.AddContentControl = function()
{
};
//----------------------------------------------------------------------------------------------------------------------
// Функции для работы с номерами страниц
//----------------------------------------------------------------------------------------------------------------------
......
......@@ -732,3 +732,7 @@ CDocumentControllerBase.prototype.GetCurrentSectionPr = function(){return null;}
* Отличие от RemoveSelection в том, что сбрасываем селект с текста, но не сбрасываем с автофигур
*/
CDocumentControllerBase.prototype.RemoveTextSelection = function(){};
/**
* Добавляем класс CBlockLevelSdt в текущую позицию курсора.
*/
CDocumentControllerBase.prototype.AddContentControl = function(){};
\ No newline at end of file
......@@ -516,4 +516,8 @@ CDrawingsController.prototype.GetCurrentSectionPr = function()
CDrawingsController.prototype.RemoveTextSelection = function()
{
this.DrawingObjects.removeTextSelection();
};
CDrawingsController.prototype.AddContentControl = function()
{
this.DrawingObjects.AddContentControl();
};
\ No newline at end of file
......@@ -3218,6 +3218,11 @@ CFootnotesController.prototype.ResetRecalculateCache = function()
this.Footnote[Id].Reset_RecalculateCache();
}
};
CFootnotesController.prototype.AddContentControl = function()
{
if (this.CurFootnote)
this.CurFootnote.AddContentControl();
};
function CFootEndnotePageColumn()
......
......@@ -481,4 +481,10 @@ CHdrFtrController.prototype.RemoveTextSelection = function()
var CurHdrFtr = this.HdrFtr.CurHdrFtr;
if (null != CurHdrFtr)
return CurHdrFtr.Content.RemoveTextSelection();
};
CHdrFtrController.prototype.AddContentControl = function()
{
var CurHdrFtr = this.HdrFtr.CurHdrFtr;
if (null != CurHdrFtr)
return CurHdrFtr.Content.AddContentControl();
};
\ No newline at end of file
......@@ -378,3 +378,7 @@ CLogicDocumentController.prototype.RemoveTextSelection = function()
{
return this.RemoveSelection();
};
CLogicDocumentController.prototype.AddContentControl = function()
{
return this.LogicDocument.controller_AddContentControl();
};
\ No newline at end of file
......@@ -596,6 +596,10 @@ CBlockLevelSdt.prototype.DrawContentControlsTrack = function(isHover)
oDrawingDocument.OnDrawContentControl(this.GetId(), isHover ? c_oContentControlTrack.Hover : c_oContentControlTrack.In, arrRects);
};
CBlockLevelSdt.prototype.AddContentControl = function()
{
this.Content.AddContentControl();
};
//----------------------------------------------------------------------------------------------------------------------
CBlockLevelSdt.prototype.Is_HdrFtr = function(bReturnHdrFtr)
{
......@@ -754,11 +758,13 @@ function TEST_ADD_SDT()
oLogicDocument.Create_NewHistoryPoint();
var oSdt = new CBlockLevelSdt(oLogicDocument, oLogicDocument);
oSdt.Content.AddToParagraph(new ParaText("S"));
oSdt.Content.AddToParagraph(new ParaText("d"));
oSdt.Content.AddToParagraph(new ParaText("t"));
oLogicDocument.AddContentControl();
oLogicDocument.AddToParagraph(new ParaText("S"));
oLogicDocument.AddToParagraph(new ParaText("d"));
oLogicDocument.AddToParagraph(new ParaText("t"));
oLogicDocument.Internal_Content_Add(1, oSdt);
oLogicDocument.Recalculate_FromStart();
oLogicDocument.Recalculate();
oLogicDocument.Document_UpdateSelectionState();
oLogicDocument.Document_UpdateInterfaceState();
oLogicDocument.Document_UpdateRulersState();
}
\ No newline at end of file
......@@ -11999,6 +11999,11 @@ CTable.prototype.GetTableProps = function()
{
return this.Get_Props();
};
CTable.prototype.AddContentControl = function()
{
if (this.CurCell)
this.CurCell.Content.AddContentControl();
};
//----------------------------------------------------------------------------------------------------------------------
// Класс CTableLook
//----------------------------------------------------------------------------------------------------------------------
......
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