diff --git a/pdf/api.js b/pdf/api.js index 7293d34b10..050f30eb8f 100644 --- a/pdf/api.js +++ b/pdf/api.js @@ -1133,10 +1133,36 @@ let oDoc = this.getPDFDoc(); oDoc.DoAction(function() { - let oField = oDoc.CreateCheckboxField(true); + let oField = oDoc.CreateRadiobuttonField(true); oDoc.AddField(oField, oDoc.GetCurPage()); }, AscDFH.historydescription_Pdf_AddField, this); }; + PDFEditorApi.prototype.AddComboboxField = function() { + let oDoc = this.getPDFDoc(); + + oDoc.DoAction(function() { + let oField = oDoc.CreateComboboxField(true); + oDoc.AddField(oField, oDoc.GetCurPage()); + }, AscDFH.historydescription_Pdf_AddField, this); + }; + PDFEditorApi.prototype.AddListboxField = function() { + let oDoc = this.getPDFDoc(); + + oDoc.DoAction(function() { + let oField = oDoc.CreateListboxField(true); + oDoc.AddField(oField, oDoc.GetCurPage()); + }, AscDFH.historydescription_Pdf_AddField, this); + }; + PDFEditorApi.prototype.AddListFieldOption = function(option, nPos) { + let oDoc = this.getPDFDoc(); + + oDoc.DoAction(function() { + let oField = oDoc.activeForm; + if (oField && [AscPDF.FIELD_TYPES.combobox, AscPDF.FIELD_TYPES.listbox].includes(oField.GetType())) { + oField.AddOption(option, nPos); + } + }, AscDFH.historydescription_Pdf_AddField, this); + }; ///////////////////////////////////////////////////////////// ///////// For drawings //////////////////////////////////////////////////////////// @@ -3179,6 +3205,8 @@ PDFEditorApi.prototype['AddImageField'] = PDFEditorApi.prototype.AddImageField; PDFEditorApi.prototype['AddCheckboxField'] = PDFEditorApi.prototype.AddCheckboxField; PDFEditorApi.prototype['AddRadiobuttonField'] = PDFEditorApi.prototype.AddRadiobuttonField; + PDFEditorApi.prototype['AddComboboxField'] = PDFEditorApi.prototype.AddComboboxField; + PDFEditorApi.prototype['AddListboxField'] = PDFEditorApi.prototype.AddListboxField; // drawings PDFEditorApi.prototype['AddTextArt'] = PDFEditorApi.prototype.AddTextArt; diff --git a/pdf/src/document.js b/pdf/src/document.js index 5d3a633549..7aefa138d8 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -483,21 +483,42 @@ var CPresentation = CPresentation || function(){}; return oButtonField; }; - CPDFDoc.prototype.CreateCheckboxField = function(bRadio) { + CPDFDoc.prototype.CreateCheckboxField = function() { let sName = 'CheckboxField1'; - let nType = bRadio ? AscPDF.FIELD_TYPES.radiobutton : AscPDF.FIELD_TYPES.checkbox; let aRect = [320, 45, 338, 63]; - let oCheckboxField = this.CreateField(sName, nType, aRect); - + let oCheckboxField = this.CreateField(sName, AscPDF.FIELD_TYPES.checkbox, aRect); oCheckboxField.SetBorderColor([0]); - if (bRadio) { - oCheckboxField.SetBorderStyle(AscPDF.BORDER_TYPES.inset); - } - return oCheckboxField; }; + CPDFDoc.prototype.CreateRadiobuttonField = function() { + let sName = 'RadiobuttonField1'; + let aRect = [320, 45, 338, 63]; + + let oRadiobuttonField = this.CreateField(sName, AscPDF.FIELD_TYPES.radiobutton, aRect); + + oRadiobuttonField.SetBorderColor([0]); + oRadiobuttonField.SetBorderStyle(AscPDF.BORDER_TYPES.inset); + + return oRadiobuttonField; + }; + CPDFDoc.prototype.CreateComboboxField = function() { + let sName = 'ComboboxField1'; + let aRect = [382, 45, 454, 65]; + + let oComboboxField = this.CreateField(sName, AscPDF.FIELD_TYPES.combobox, aRect); + + return oComboboxField; + }; + CPDFDoc.prototype.CreateListboxField = function() { + let sName = 'ListboxField1'; + let aRect = [382, 81, 482, 153]; + + let oListboxField = this.CreateField(sName, AscPDF.FIELD_TYPES.listbox, aRect); + + return oListboxField; + }; CPDFDoc.prototype.FillFormsParents = function(aParentsInfo) { let oChilds = this.GetParentsMap(); let oParents = {}; @@ -519,8 +540,8 @@ var CPresentation = CPresentation || function(){}; if (aParentsInfo[i]["i"] != null) oParent.SetApIdx(aParentsInfo[i]["i"]); if (aParentsInfo[i]["curIdxs"]) - oParent.SetApiCurIdxs(aParentsInfo[i]["curIdxs"]); - if (aParentsInfo[i]["Opt"] && oParent instanceof AscPDF.CBaseCheckBoxField) + oParent.SetParentCurIdxs(aParentsInfo[i]["curIdxs"]); + if (aParentsInfo[i]["Opt"]) oParent.SetOptions(aParentsInfo[i]["Opt"]); oParents[nIdx] = oParent; diff --git a/pdf/src/forms/base/baselist.js b/pdf/src/forms/base/baselist.js index 728f13d1ea..cb14a154ce 100644 --- a/pdf/src/forms/base/baselist.js +++ b/pdf/src/forms/base/baselist.js @@ -47,19 +47,21 @@ AscPDF.CBaseField.call(this, sName, sType, nPage, aRect, oDoc); this._commitOnSelChange = false; - this._currentValueIndices = undefined; + this._currentValueIndices = []; this._textFont = AscPDF.DEFAULT_FIELD_FONT; this._options = []; + AscCommon.History.StartNoHistoryMode(); this.content = new AscPDF.CTextBoxContent(this, oDoc); + AscCommon.History.EndNoHistoryMode(); } CBaseListField.prototype = Object.create(AscPDF.CBaseField.prototype); CBaseListField.prototype.constructor = CBaseListField; - CBaseListField.prototype.SetApiCurIdxs = function(aIdxs) { + CBaseListField.prototype.SetParentCurIdxs = function(aIdxs) { let oParent = this.GetParent(); if (oParent && this.IsWidget() && oParent.IsAllKidsWidgets()) - oParent.SetApiCurIdxs(aIdxs); + oParent.SetParentCurIdxs(aIdxs); else { let oDoc = this.GetDocument(); oDoc.History.Add(new CChangesPDFListFormParentCurIdxs(this, this.GetParentCurIdxs(), aIdxs)); @@ -86,12 +88,20 @@ return this._commitOnSelChange; }; - CBaseListField.prototype.GetOptions = function() { - return this._options; + CBaseListField.prototype.GetOptions = function(bInherit) { + let oParent = this.GetParent(); + if (oParent == null) + return this._options; + else if (bInherit === false || (this.GetPartialName() != null)) { + return this._options; + } + + if (oParent) + return oParent.GetOptions(); }; // export CBaseListField.prototype["getOptions"] = function() { - return this._options; + return this.GetOptions(); }; if (!window["AscPDF"]) diff --git a/pdf/src/forms/combobox.js b/pdf/src/forms/combobox.js index 1b90caee55..ceb965e94c 100644 --- a/pdf/src/forms/combobox.js +++ b/pdf/src/forms/combobox.js @@ -44,9 +44,11 @@ this._doNotSpellCheck = false; this._editable = false; + AscCommon.History.StartNoHistoryMode(); // content for formatting value // Note: draw this content instead of main if form has a "format" action this.contentFormat = new AscPDF.CTextBoxContent(this, oDoc, true); + AscCommon.History.EndNoHistoryMode(); this._markRect = {}; this._useDisplayValue = true; @@ -274,7 +276,7 @@ var pageObject = oViewer.getPageByCoords(x, y); - if (pageObject.x >= this._markRect.x1 && pageObject.x <= this._markRect.x2 && pageObject.y >= this._markRect.y1 && pageObject.y <= this._markRect.y2 && this._options.length != 0) { + if (pageObject.x >= this._markRect.x1 && pageObject.x <= this._markRect.x2 && pageObject.y >= this._markRect.y1 && pageObject.y <= this._markRect.y2 && this.GetOptions()) { editor.sendEvent("asc_onShowPDFFormsActions", this, x, y); this.content.MoveCursorToStartPos(); } @@ -317,11 +319,14 @@ let oRun = oPara.GetElement(0); oRun.ClearContent(); - if (Array.isArray(this._options[nIdx])) { - oRun.AddText(this._options[nIdx][0]); - } - else { - oRun.AddText(this._options[nIdx]); + let aOptions = this.GetOptions(); + if (aOptions[nIdx]) { + if (Array.isArray(aOptions[nIdx])) { + oRun.AddText(aOptions[nIdx][0]); + } + else { + oRun.AddText(aOptions[nIdx]); + } } this.SetNeedRecalc(true); @@ -342,10 +347,10 @@ } if (Asc.editor.getDocumentRenderer().IsOpenFormsInProgress) - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); } else - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); this.SetNeedCommit(false); }; @@ -357,17 +362,18 @@ let isOnOpen = oDoc.Viewer.IsOpenFormsInProgress; let sTextToAdd = ""; - for (let i = 0; i < this._options.length; i++) { - if (Array.isArray(this._options[i]) && this._options[i][1] == sValue) { - sTextToAdd = this._options[i][0]; + let aOptions = this.GetOptions(); + for (let i = 0; i < aOptions.length; i++) { + if (Array.isArray(aOptions[i]) && aOptions[i][1] == sValue) { + sTextToAdd = aOptions[i][0]; aIdxs.push(i); break; } } if (sTextToAdd == "") { - for (let i = 0; i < this._options.length; i++) { - if (this._options[i] == sValue) { - sTextToAdd = this._options[i]; + for (let i = 0; i < aOptions.length; i++) { + if (aOptions[i] == sValue) { + sTextToAdd = aOptions[i]; aIdxs.push(i); break; } @@ -385,29 +391,30 @@ if (isOnOpen) { this.SetParentValue(sValue); - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); } } else { this.SetParentValue(sValue); - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); } }; CComboBoxField.prototype.private_SetValue = function(sValue) { let aIdxs = []; if (this.IsWidget()) { + let aOptions = this.GetOptions(); let sTextToAdd = ""; - for (let i = 0; i < this._options.length; i++) { - if (Array.isArray(this._options[i]) && this._options[i][1] == sValue) { - sTextToAdd = this._options[i][0]; + for (let i = 0; i < aOptions.length; i++) { + if (Array.isArray(aOptions[i]) && aOptions[i][1] == sValue) { + sTextToAdd = aOptions[i][0]; aIdxs.push(i); break; } } if (sTextToAdd == "") { - for (let i = 0; i < this._options.length; i++) { - if (this._options[i] == sValue) { - sTextToAdd = this._options[i]; + for (let i = 0; i < aOptions.length; i++) { + if (aOptions[i] == sValue) { + sTextToAdd = aOptions[i]; aIdxs.push(i); break; } @@ -422,7 +429,7 @@ } else { this.SetParentValue(sValue); - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); } }; @@ -508,7 +515,7 @@ let isChanged = false; for (let i = 0; i < aCurIdxs.length; i++) { - if (aCurIdxs[i] === undefined || aApiIdxs[i] === undefined || aCurIdxs[i] !== aApiIdxs[i]) { + if (!aApiIdxs || aCurIdxs[i] === undefined || aApiIdxs[i] === undefined || aCurIdxs[i] !== aApiIdxs[i]) { isChanged = true; break; } @@ -552,7 +559,7 @@ } this.SetParentValue(this.GetValue()); - this.SetApiCurIdxs(aCurIdxs); + this.SetParentCurIdxs(aCurIdxs); // когда выравнивание посередине или справа, то после того // как ширина контента будет больше чем размер формы, выравнивание становится слева, пока текста вновь не станет меньше чем размер формы @@ -580,22 +587,23 @@ * @returns {number} */ CComboBoxField.prototype.UpdateIndexies = function() { + let aOptions = this.GetOptions(); let sValue = this.content.GetElement(0).GetText({ParaEndToSpace: false}); let nIdx = -1; - for (let i = 0; i < this._options.length; i++) { - if (this._options[i][0] === sValue) { + for (let i = 0; i < aOptions.length; i++) { + if (aOptions[i][0] === sValue) { nIdx = i; break; } } - for (let i = 0; i < this._options.length; i++) { - if (this._options[i] === sValue) { + for (let i = 0; i < aOptions.length; i++) { + if (aOptions[i] === sValue) { nIdx = i; break; } } - this.SetApiCurIdxs([nIdx]); + this.SetParentCurIdxs([nIdx]); return nIdx; }; @@ -612,24 +620,60 @@ return false; }; - CComboBoxField.prototype.SetOptions = function(aOpt) { - let aOptToPush = []; - for (let i = 0; i < aOpt.length; i++) { - if (aOpt[i] == null) - continue; - if (typeof(aOpt[i]) == "string" && aOpt[i] != "") - aOptToPush.push(aOpt[i]); - else if (Array.isArray(aOpt[i]) && aOpt[i][0] != undefined && aOpt[i][1] != undefined) { - if (aOpt[i][0].toString && aOpt[i][1].toString) { - aOptToPush.push([aOpt[i][0].toString(), aOpt[i][1].toString()]) - } + CComboBoxField.prototype.AddOption = function(option, nPos) { + let oParent = this.GetParent(); + if (oParent && oParent.GetType() == this.GetType()) + return oParent.AddOption(option, nPos); + + if (option == null) return; + + let formattedOption; + + if (option[0] !== undefined && option[1] !== undefined) { + if (option[0].toString && option[1].toString) { + formattedOption = [option[0].toString(), option[1].toString()]; } - else if (typeof(aOpt[i]) != "string" && aOpt[i].toString) { - aOptToPush.push(aOpt[i].toString()); + } else if (option.toString) { + formattedOption = option.toString(); + } + + if (formattedOption !== undefined) { + if (nPos == undefined) { + nPos = this._options.length; } + + this._options.splice(nPos, 0, formattedOption); } - this._options = aOptToPush; + AscCommon.History.Add(new CChangesPDFListOption(this, nPos, formattedOption, true)); + + this.SetWasChanged(true); + this.SetNeedRecalc(true); + }; + CComboBoxField.prototype.RemoveOption = function(nPos) { + if (Number.isInteger(nPos) && nPos >= 0 && nPos < this._options.length) { + if (this.GetCurIdxs().includes(nPos)) { + let oPara = this.content.GetElement(0); + let oRun = oPara.GetElement(0); + + oRun.ClearContent(); + } + + let option = this._options.splice(nPos, 1); + + AscCommon.History.Add(new CChangesPDFListOption(this, nPos, option, false)); + + this.SetWasChanged(true); + this.SetNeedRecalc(true); + } + }; + CComboBoxField.prototype.SetOptions = function(aOpt) { + while (this._options.length > 0) { + this.RemoveOption(0); + } + for (let i = 0; i < aOpt.length; i++) { + this.AddOption(aOpt[i]); + } }; CComboBoxField.prototype.GetValue = function(bDisplayValue) { @@ -658,15 +702,16 @@ if (bApiValue) return this._currentValueIndices; + let aOptions = this.GetOptions(); let sValue = this.content.GetElement(0).GetText({ParaEndToSpace: false}); - for (let i = 0; i < this._options.length; i++) { - if (Array.isArray(this._options[i])) { - if (this._options[i][0] == sValue) + for (let i = 0; i < aOptions.length; i++) { + if (Array.isArray(aOptions[i])) { + if (aOptions[i][0] == sValue) return [i]; } } - for (let i = 0; i < this._options.length; i++) { - if (this._options[i] === sValue) { + for (let i = 0; i < aOptions.length; i++) { + if (aOptions[i] === sValue) { return [i]; } } @@ -727,7 +772,7 @@ } // элементы списка выбора - let aOptions = this.GetOptions(); + let aOptions = this.GetOptions(false); if (aOptions) { memory.fieldDataFlags |= (1 << 10); memory.WriteLong(aOptions.length); diff --git a/pdf/src/forms/listbox.js b/pdf/src/forms/listbox.js index a35771cca3..a92b551094 100644 --- a/pdf/src/forms/listbox.js +++ b/pdf/src/forms/listbox.js @@ -91,9 +91,7 @@ return; if (!this.RecalculateContentRect()) { - this.content.Content.forEach(function(element) { - element.Recalculate_Page(0); - }); + this.content.Recalculate_Page(0, true); } this.SetNeedRecalc(false); @@ -202,7 +200,7 @@ this.ScrollVerticalEnd(true); let isChanged = false; for (let i = 0; i < aCurIdxs.length; i++) { - if (aCurIdxs[i] === undefined || aApiIdxs[i] === undefined || aCurIdxs[i] !== aApiIdxs[i]) { + if (!aApiIdxs || aCurIdxs[i] === undefined || aApiIdxs[i] === undefined || aCurIdxs[i] !== aApiIdxs[i]) { isChanged = true; break; } @@ -230,7 +228,7 @@ this._bAutoShiftContentView = true; this.SetParentValue(this.GetValue()); - this.SetApiCurIdxs(aCurIdxs); + this.SetParentCurIdxs(aCurIdxs); }; CListBoxField.prototype.UpdateTopIndex = function() { let oParaBounds = this.content.GetElement(0).GetPageBounds(0); @@ -317,36 +315,71 @@ oApiPara.Paragraph.RecalcCompiledPr(true); this.SetNeedRecalc(true); }; - CListBoxField.prototype.SetOptions = function(aOpt) { - this.content.Internal_Content_RemoveAll(); - for (let i = 0; i < aOpt.length; i++) { - if (aOpt[i] == null) - continue; - let sCaption = ""; - if (typeof(aOpt[i]) == "string" && aOpt[i] != "") { - sCaption = aOpt[i]; - this._options.push(aOpt[i]); - } - else if (Array.isArray(aOpt[i]) && aOpt[i][0] != undefined && aOpt[i][1] != undefined) { - if (aOpt[i][0].toString && aOpt[i][1].toString) { - this._options.push([aOpt[i][0].toString(), aOpt[i][1].toString()]); - sCaption = aOpt[i][0].toString(); - } + CListBoxField.prototype.AddOption = function(option, nPos) { + let oParent = this.GetParent(); + if (oParent && oParent.GetType() == this.GetType()) + return oParent.AddOption(option, nPos); + + if (option == null) return; + + let formattedOption; + let sCaption = ""; + if (typeof option === "string" && option !== "") { + formattedOption = option; + sCaption = option; + } + else if (Array.isArray(option) && option[0] !== undefined && option[1] !== undefined) { + if (option[0].toString && option[1].toString) { + formattedOption = [option[0].toString(), option[1].toString()]; + sCaption = option[0].toString(); } - else if (typeof(aOpt[i]) != "string" && aOpt[i].toString) { - this._options.push(aOpt[i].toString()); - sCaption = aOpt[i].toString(); + } + else if (option.toString) { + formattedOption = option.toString(); + sCaption = option.toString(); + } + + if (formattedOption !== undefined) { + if (nPos == undefined) { + nPos = this._options.length; } + AscCommon.History.Add(new CChangesPDFListOption(this, nPos, formattedOption, true)); + this._options.push(formattedOption); if (sCaption !== "") { - AscFonts.FontPickerByCharacter.getFontsByString(sCaption); - - let oPara = new AscWord.Paragraph(this.content, false); - let oRun = new AscWord.ParaRun(oPara, false); - this.content.Internal_Content_Add(i, oPara); - oPara.Add(oRun); - oRun.AddText(sCaption); + let oDoc = this.GetDocument(); + let aFields = oDoc.GetAllWidgets(this.GetFullName()); + + aFields.forEach(function(field) { + AscFonts.FontPickerByCharacter.getFontsByString(sCaption); + let oPara = new AscWord.Paragraph(this.content, false); + let oRun = new AscWord.ParaRun(oPara, false); + field.content.Internal_Content_Add(nPos, oPara); + oPara.Add(oRun); + oRun.AddText(sCaption); + + field.SetWasChanged(true); + field.SetNeedRecalc(true); + }); } + + this.SetWasChanged(true); + } + }; + CListBoxField.prototype.RemoveOption = function(nPos) { + if (Number.isInteger(nPos) && nPos >= 0 && nPos < this._options.length) { + AscCommon.History.Add(new CChangesPDFListOption(this, nPos, option, false)); + + this._options.splice(nPos, 1); + this.content.Internal_Content_Remove(nPos); + } + }; + CListBoxField.prototype.SetOptions = function(aOpt) { + while (this._options.length > 0) { + this.RemoveOption(0); + } + for (let i = 0; i < aOpt.length; i++) { + this.AddOption(aOpt[i]); } }; CListBoxField.prototype.SetValue = function(value) { @@ -416,13 +449,13 @@ if (editor.getDocumentRenderer().IsOpenFormsInProgress) { this.SetParentValue(value); - this.SetApiCurIdxs(aIndexes); + this.SetParentCurIdxs(aIndexes); } } else { this.SetParentValue(value); - this.SetApiCurIdxs(aIndexes); + this.SetParentCurIdxs(aIndexes); } }; CListBoxField.prototype.private_SetValue = CListBoxField.prototype.SetValue; @@ -886,10 +919,10 @@ oDoc.History.EndNoHistoryMode(); if (editor.getDocumentRenderer().IsOpenFormsInProgress) - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); } else { - this.SetApiCurIdxs(aIdxs); + this.SetParentCurIdxs(aIdxs); } this.SetNeedCommit(false); diff --git a/pdf/src/forms/text.js b/pdf/src/forms/text.js index f526a26131..2d29fd7bb1 100644 --- a/pdf/src/forms/text.js +++ b/pdf/src/forms/text.js @@ -303,30 +303,6 @@ return true; }; - // /** - // * Sets the value to childs fields. - // * @memberof CTextField - // * @typeofeditors ["PDF"] - // */ - // CTextField.prototype.SetValueToKids = function(sValue) { - // let oField, sName; - // let aDoneFields = []; - // for (let i = 0; i < this._kids.length; i++) { - // oField = this._kids[i]; - // sName = oField.GetPartialName(); - - // if (oField.IsWidget()) { - // if (aDoneFields.includes(sName) == false) { - // aDoneFields.push(oField.GetFullName()); - // oField.SetValue(sValue); - // oField.Commit(); - // } - // } - // else - // oField.SetValueToKids(sValue); - // } - // }; - /** * Gets the value of current form (can be not commited). * @memberof CTextField diff --git a/pdf/src/history/formsChanges.js b/pdf/src/history/formsChanges.js index f52e3559e1..2b3cfc371d 100644 --- a/pdf/src/history/formsChanges.js +++ b/pdf/src/history/formsChanges.js @@ -435,7 +435,7 @@ CChangesPDFListFormParentCurIdxs.prototype.Type = AscDFH.historyitem_Pdf_List_Fo CChangesPDFListFormParentCurIdxs.prototype.private_SetValue = function(Value) { var oField = this.Class; - oField.SetApiCurIdxs(Value); + oField.SetParentCurIdxs(Value); }; CChangesPDFListFormParentCurIdxs.prototype.WriteToBinary = function(Writer) @@ -522,6 +522,121 @@ CChangesPDFListTopIndex.prototype.private_SetValue = function(Value) oField.AddToRedraw(); }; +/** + * @constructor + * @extends {AscDFH.CChangesBaseContentChange} + */ +function CChangesPDFListOption(Class, Pos, Items, isAdd) { + AscDFH.CChangesBaseContentChange.call(this, Class, Pos, Items, isAdd); +} + +CChangesPDFListOption.prototype = Object.create(AscDFH.CChangesBaseContentChange.prototype); +CChangesPDFListOption.prototype.constructor = CChangesPDFListOption; +CChangesPDFListOption.prototype.Type = AscDFH.historyitem_Pdf_List_Form_Option; + +CChangesPDFListOption.prototype.WriteToBinary = function (writer) { + writer.WriteBool(this.IsAdd()); + writer.WriteLong(this.Pos); + writer.WriteString2(JSON.stringify(this.Items)); +}; +CChangesPDFListOption.prototype.ReadFromBinary = function (reader) { + reader.Seek2(reader.GetCurPos() - 4); + this.Type = reader.GetLong(); + this.Add = reader.GetBool(); + this.Pos = reader.GetLong(); + + this.Items = JSON.parse(reader.GetString2()); +}; +CChangesPDFListOption.prototype.private_GetChangedArray = function () { + return this.Class._options; +}; +CChangesPDFListOption.prototype.private_InsertInArrayLoad = function () { + if (this.Items.length <= 0) + return; + + let aChangedArray = this.private_GetChangedArray(); + if (null !== aChangedArray) { + aChangedArray.splice(this.Pos, 0, this.Items); + } +}; +CChangesPDFListOption.prototype.private_RemoveInArrayLoad = function () { + + var aChangedArray = this.private_GetChangedArray(); + if (null !== aChangedArray) { + aChangedArray.splice(this.Pos, 1); + } +}; +CChangesPDFListOption.prototype.private_InsertInArrayUndoRedo = function () { + var aChangedArray = this.private_GetChangedArray(); + if (null !== aChangedArray) { + aChangedArray.splice(this.Pos, 0, this.Items); + } +}; +CChangesPDFListOption.prototype.private_RemoveInArrayUndoRedo = function () { + + var aChangedArray = this.private_GetChangedArray(); + if (null !== aChangedArray) { + aChangedArray.splice(this.Pos, 1); + } +}; +CChangesPDFListOption.prototype.Load = function () { + if (this.IsAdd()) { + this.private_InsertInArrayLoad(); + } + else { + this.private_RemoveInArrayLoad(); + } + this.RefreshRecalcData(); +}; +CChangesPDFListOption.prototype.Undo = function () { + if (this.IsAdd()) { + this.private_RemoveInArrayUndoRedo(); + } + else { + this.private_InsertInArrayUndoRedo(); + } +}; +CChangesPDFListOption.prototype.Redo = function () { + if (this.IsAdd()) { + this.private_InsertInArrayUndoRedo(); + } + else { + this.private_RemoveInArrayUndoRedo(); + } +}; +CChangesPDFListOption.prototype.IsContentChange = function () { + return false; +}; +CChangesPDFListOption.prototype.Copy = function() +{ + var oChanges = new this.constructor(this.Class, this.Type, this.Pos, this.Items, this.Add); + + oChanges.UseArray = this.UseArray; + + for (var nIndex = 0, nCount = this.PosArray.length; nIndex < nCount; ++nIndex) + oChanges.PosArray[nIndex] = this.PosArray[nIndex]; + + return oChanges; +}; +CChangesPDFListOption.prototype.ConvertToSimpleChanges = function() +{ + let arrSimpleActions = this.ConvertToSimpleActions(); + let arrChanges = []; + for (let nIndex = 0, nCount = arrSimpleActions.length; nIndex < nCount; ++nIndex) + { + let oAction = arrSimpleActions[nIndex]; + let oChange = new this.constructor(this.Class, this.Type, oAction.Pos, [oAction.Item], oAction.Add); + arrChanges.push(oChange); + } + return arrChanges; +}; +CChangesPDFListOption.prototype.CreateReverseChange = function(){ + var oRet = this.private_CreateReverseChange(this.constructor); + oRet.Type = this.Type; + oRet.Pos = this.Pos; + return oRet; +}; + /** * @constructor * @extends {AscDFH.CChangesBaseStringProperty}