Commit 27473595 authored by Ilya Kirillov's avatar Ilya Kirillov

The functions GetParent and GetPosInParent have been moved from the ParaRun...

The functions GetParent and GetPosInParent have been moved from the ParaRun class to the base class CParagraphContentBase. Updating of the TOC field were improved, now we delete the old TOC bookmarks and add new ones, we also add the PAGEREF field to the end of each line with links to new bookmarks.
parent 74848889
......@@ -131,6 +131,24 @@ CParagraphBookmark.prototype.GoToBookmark = function()
oParagraph.Set_ParaContentPos(oCurPos, false, -1, -1, true); // Корректировать позицию нужно обязательно
oParagraph.Document_SetThisElementCurrent(true);
};
CParagraphBookmark.prototype.RemoveBookmark = function()
{
var oParagraph = this.Paragraph;
if (!oParagraph)
return;
var oCurPos = oParagraph.Get_PosByElement(this);
if (!oCurPos)
return;
var oParent = this.GetParent();
var nPosInParent = this.GetPosInParent(oParent);
if (!oParent || -1 === nPosInParent)
return;
oParent.Remove_FromContent(nPosInParent, 1);
};
//----------------------------------------------------------------------------------------------------------------------
// Функции совместного редактирования
//----------------------------------------------------------------------------------------------------------------------
......@@ -220,19 +238,17 @@ CBookmarksManager.prototype.ProcessBookmarkChar = function(oParaBookmark)
this.BookmarksChars[sBookmarkId] = oParaBookmark;
}
var sBookmarkId = oParaBookmark.GetBookmarkId();
if (0 === sBookmarkId.indexOf("_Toc"))
var sBookmarkName = oParaBookmark.GetBookmarkName();
if (0 === sBookmarkName.indexOf("_Toc"))
{
var nId = parseInt(sBookmarkId.substring(4));
var nId = parseInt(sBookmarkName.substring(4));
if (!isNaN(nId))
this.IdCounterTOC = Math.max(this.IdCounterTOC, nId);
}
else
{
var nId = parseInt(sBookmarkId);
if (!isNaN(nId))
this.IdCounter = Math.max(this.IdCounter, nId);
}
var nId = parseInt(sBookmarkId);
if (!isNaN(nId))
this.IdCounter = Math.max(this.IdCounter, nId);
};
CBookmarksManager.prototype.EndCollectingProcess = function()
{
......@@ -294,12 +310,28 @@ CBookmarksManager.prototype.GetNewBookmarkId = function()
return ("" + ++this.IdCounter);
};
CBookmarksManager.prototype.GetNewBookmarkIdTOC = function()
CBookmarksManager.prototype.GetNewBookmarkNameTOC = function()
{
this.private_CheckValidate();
return ("_Toc" + ++this.IdCounterTOC);
};
CBookmarksManager.prototype.RemoveTOCBookmarks = function()
{
this.private_CheckValidate();
for (var nIndex = 0, nCount = this.Bookmarks.length; nIndex < nCount; ++nIndex)
{
var oStart = this.Bookmarks[nIndex][0];
var oEnd = this.Bookmarks[nIndex][1];
if (0 === oStart.GetBookmarkName().toLowerCase().indexOf("_toc"))
{
oStart.RemoveBookmark();
oEnd.RemoveBookmark();
}
}
};
......
......@@ -12436,6 +12436,14 @@ Paragraph.prototype.AddBookmarkForTOC = function()
return;
var oBookmarksManager = this.LogicDocument.GetBookmarksManager();
var sId = oBookmarksManager.GetNewBookmarkId();
var sName = oBookmarksManager.GetNewBookmarkNameTOC();
this.Add_ToContent(0, new CParagraphBookmark(true, sId, sName));
this.Add_ToContent(this.Content.length - 1, new CParagraphBookmark(false, sId, sName));
return sName;
};
Paragraph.prototype.AddBookmarkChar = function(oBookmarkChar, isUseSelection, isStartSelection)
{
......@@ -12484,6 +12492,25 @@ Paragraph.prototype.CheckPageRefLink = function(X, Y, CurPage)
return null;
};
/**
* Получаем абсолютное значение первой не пустой страницы
* @returns {number}
*/
Paragraph.prototype.GetFirstNonEmptyPageAbsolute = function()
{
var nPagesCount = this.Pages.length;
var nCurPage = 0;
while (this.Is_EmptyPage(nCurPage))
{
if (nCurPage >= nPagesCount - 1)
break;
nCurPage++;
}
return this.Get_AbsolutePage(nCurPage);
};
var pararecalc_0_All = 0;
var pararecalc_0_None = 1;
......
......@@ -264,14 +264,48 @@ CComplexField.prototype.Update = function()
{
this.LogicDocument.Create_NewHistoryPoint();
this.LogicDocument.GetBookmarksManager().RemoveTOCBookmarks();
var oStyles = this.LogicDocument.Get_Styles();
var arrOutline = this.LogicDocument.GetOutlineParagraphs();
var oSelectedContent = new CSelectedContent();
for (var nIndex = 0, nCount = arrOutline.length; nIndex < nCount; ++nIndex)
{
var oPara = arrOutline[nIndex].Paragraph.Copy();
var oSrcParagraph = arrOutline[nIndex].Paragraph;
var oPara = oSrcParagraph.Copy();
oPara.Style_Add(oStyles.GetDefaultTOC(arrOutline[nIndex].Lvl), false);
var sBookmarkName = oSrcParagraph.AddBookmarkForTOC();
// Значение таба зависит от текущей секции
var oTabs = new CParaTabs();
oTabs.Add(new CParaTab(tab_Right, 9345 / 20 / 72 * 25.4));
oPara.Set_Tabs(oTabs);
var oTabRun = new ParaRun(oPara, false);
oTabRun.Add_ToContent(0, new ParaTab());
// TODO: ParaEnd
oPara.Add_ToContent(oPara.Content.length - 1, oTabRun);
var oPageRefRun = new ParaRun(oPara, false);
var nTempIndex = -1;
oPageRefRun.Add_ToContent(++nTempIndex, new ParaFieldChar(fldchartype_Begin, this));
var sInstructionLine = "PAGEREF " + sBookmarkName + " \\h";
for (var nPos = 0, nCount2 = sInstructionLine.length; nPos < nCount2; ++nPos)
{
oPageRefRun.Add_ToContent(++nTempIndex, new ParaInstrText(sInstructionLine.charAt(nPos)));
}
oPageRefRun.Add_ToContent(++nTempIndex, new ParaFieldChar(fldchartype_Separate, this));
var sValue = "" + (oSrcParagraph.GetFirstNonEmptyPageAbsolute() + 1);
for (var nPos = 0, nCount2 = sValue.length; nPos < nCount2; ++nPos)
{
oPageRefRun.Add_ToContent(++nTempIndex, new ParaText(sValue.charAt(nPos)));
}
oPageRefRun.Add_ToContent(++nTempIndex, new ParaFieldChar(fldchartype_End, this));
oPara.Add_ToContent(oPara.Content.length - 1, oPageRefRun);
oSelectedContent.Add(new CSelectedElement(oPara, true));
}
......
......@@ -165,6 +165,32 @@ CParagraphContentBase.prototype.UpdateBookmarks = function(oManager)
CParagraphContentBase.prototype.Check_Spelling = function(SpellCheckerEngine, Depth)
{
};
CParagraphContentBase.prototype.GetParent = function()
{
if (!this.Paragraph)
return null;
var oContentPos = this.Paragraph.Get_PosByElement(this);
if (!oContentPos || oContentPos.Get_Depth() < 0)
return null;
oContentPos.Decrease_Depth(1);
return this.Paragraph.Get_ElementByPos(oContentPos);
};
CParagraphContentBase.prototype.GetPosInParent = function(_oParent)
{
var oParent = (_oParent? _oParent : this.GetParent());
if (!oParent || !oParent.Content)
return -1;
for (var nPos = 0, nCount = oParent.Content.length; nPos < nCount; ++nPos)
{
if (this === oParent.Content[nPos])
return nPos;
}
return -1;
};
//----------------------------------------------------------------------------------------------------------------------
// Функции пересчета
//----------------------------------------------------------------------------------------------------------------------
......
......@@ -8844,34 +8844,11 @@ ParaRun.prototype.Set_ReviewTypeWithInfo = function(ReviewType, ReviewInfo)
};
ParaRun.prototype.Get_Parent = function()
{
if (!this.Paragraph)
return null;
var ContentPos = this.Paragraph.Get_PosByElement(this);
if (null == ContentPos || undefined == ContentPos || ContentPos.Get_Depth() < 0)
return null;
ContentPos.Decrease_Depth(1);
return this.Paragraph.Get_ElementByPos(ContentPos);
return this.GetParent();
};
ParaRun.prototype.private_GetPosInParent = function(_Parent)
{
var Parent = (_Parent? _Parent : this.Get_Parent());
if (!Parent)
return -1;
// Ищем данный элемент в родительском классе
var RunPos = -1;
for (var Pos = 0, Count = Parent.Content.length; Pos < Count; Pos++)
{
if (this === Parent.Content[Pos])
{
RunPos = Pos;
break;
}
}
return RunPos;
return this.GetPosInParent(_Parent);
};
ParaRun.prototype.Make_ThisElementCurrent = function(bUpdateStates)
{
......
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