Skip to content

Commit

Permalink
[de] Add PermRangesManager
Browse files Browse the repository at this point in the history
Also add the first variant to manage the moving/deleting of permission marks
  • Loading branch information
KirillovIlya committed Nov 20, 2024
1 parent 09d0b3e commit 14a1018
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 21 deletions.
1 change: 1 addition & 0 deletions configs/cell.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
"word/Editor/Paragraph/Run/RunAutoCorrect.js",
"word/Editor/DocumentContentElementBase.js",
"word/Editor/ParagraphContentBase.js",
"word/Editor/annotations/perm-ranges-manager.js",
"word/Editor/annotations/annotation-mark-base.js",
"word/Editor/annotations/paragraph-perm.js",
"word/Editor/Bookmarks.js",
Expand Down
1 change: 1 addition & 0 deletions configs/word.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"word/Editor/ParagraphContentBase.js",
"word/Editor/Comments.js",
"word/Editor/CommentsChanges.js",
"word/Editor/annotations/perm-ranges-manager.js",
"word/Editor/annotations/annotation-mark-base.js",
"word/Editor/annotations/paragraph-perm.js",
"word/Editor/Bookmarks.js",
Expand Down
2 changes: 1 addition & 1 deletion word/Editor/Comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ ParaComment.prototype.IsUseInDocument = function()
return false;

return oParagraph.IsUseInDocument();
}
};
ParaComment.prototype.RemoveMark = function()
{
var oParagraph = this.GetParagraph();
Expand Down
46 changes: 46 additions & 0 deletions word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,9 @@ function CDocument(DrawingDocument, isMainLogicDocument)

// Класс, управляющий полями
this.FieldsManager = new CDocumentFieldsManager();

if (typeof AscWord.PermRangesManager !== "undefined")
this.PermRangesManager = new AscWord.PermRangesManager(this);

// Класс, управляющий закладками
if (typeof CBookmarksManager !== "undefined")
Expand Down Expand Up @@ -3018,6 +3021,9 @@ CDocument.prototype.private_CheckAdditionalOnFinalize = function()
if (this.Action.Additional.ContentControlChange)
this.private_FinalizeContentControlChange();

if (this.Action.Additional.DeletedAnnotationMarks)
this.private_FinalizeDeletingAnnotationsMarks();

if (this.OFormDocument)
this.OFormDocument.onEndAction();

Expand Down Expand Up @@ -3237,6 +3243,22 @@ CDocument.prototype.private_FinalizeContentControlChange = function()
this.Api.asc_OnChangeContentControl(this.Action.Additional.ContentControlChange[sId]);
}
};
CDocument.prototype.private_FinalizeDeletingAnnotationsMarks = function()
{
let docState = this.SaveDocumentState();

let permMarks = this.Action.Additional.DeletedAnnotationMarks.perm;
for (let rangeId in permMarks)
{
let info = permMarks[rangeId];
if (info.start && info.end)
continue;


}

this.LoadDocumentState(docState);
};
CDocument.prototype.private_FinalizeCheckFocusAndBlurCC = function()
{

Expand Down Expand Up @@ -25792,6 +25814,30 @@ CDocument.prototype.AddParaMath = function(nType)
this.UpdateSelection();
this.UpdateInterface();
};
CDocument.prototype.OnDeleteAnnotationMark = function(mark)
{
if (!this.Action.Start || this.Action.UndoRedo)
return;

if (!this.Action.Additional.DeletedAnnotationMarks)
this.Action.Additional.DeletedAnnotationMarks = {perm : {}, comments : {}, bookmarks : {}};

if (mark.isPerm())
{
let permMarks = this.Action.Additional.DeletedAnnotationMarks.perm;
let rangeId = mark.getRangeId();
if (permMarks[rangeId])
permMarks[rangeId] = {};

let docPos = mark.GetDocumentPositionFromObject();
if (mark.isStart())
permMarks[rangeId].start = {mark : mark, docPos : docPos};
else
permMarks[rangeId].end = {mark : mark, docPos : docPos};

this.CollaborativeEditing.Add_DocumentPosition(docPos);
}
};
CDocument.prototype.OnChangeContentControl = function(oControl)
{
if (!this.Action.Start && !this.Action.UndoRedo)
Expand Down
15 changes: 6 additions & 9 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -12729,23 +12729,20 @@ Paragraph.prototype.PreDelete = function()
// Кроме этого, если тут начинались или заканчивались комметарии, то их тоже
// удаляем.

let logicDocument = this.GetLogicDocument();
for (var Index = 0; Index < this.Content.length; Index++)
{
var Item = this.Content[Index];

if (Item.PreDelete)
Item.PreDelete(true);

if(this.LogicDocument)
if (logicDocument && logicDocument.IsDocumentEditor())
{
if (para_Comment === Item.Type && true === this.LogicDocument.RemoveCommentsOnPreDelete)
{
this.LogicDocument.RemoveComment(Item.CommentId, true, false);
}
if (para_Comment === Item.Type && true === logicDocument.RemoveCommentsOnPreDelete)
logicDocument.RemoveComment(Item.CommentId, true, false);
else if (para_Bookmark === Item.Type)
{
this.LogicDocument.GetBookmarksManager().SetNeedUpdate(true);
}
logicDocument.GetBookmarksManager().SetNeedUpdate(true);
}
}

Expand Down
13 changes: 13 additions & 0 deletions word/Editor/annotations/annotation-mark-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@
{
return false;
};
AnnotationMarkBase.prototype.isUseInDocument = function()
{
// TODO: Check appearance of this mark in the paragraph
let paragraph = this.getParagraph();
if (!paragraph)
return false;

return paragraph.IsUseInDocument();
};
AnnotationMarkBase.prototype.getParagraph = function()
{
return this.GetParagraph();
};
//--------------------------------------------------------export----------------------------------------------------
AscWord.AnnotationMarkBase = AnnotationMarkBase;
})();
Expand Down
21 changes: 10 additions & 11 deletions word/Editor/annotations/paragraph-perm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

(function()
{

/**
* @constructor
* @extends {CParagraphContentBase}
Expand All @@ -47,7 +48,7 @@

ParagraphPermBase.prototype = Object.create(CParagraphContentBase.prototype);
ParagraphPermBase.prototype.constructor = ParagraphPermBase;
ParagraphPermBase.assign(ParagraphPermBase.prototype, AscWord.AnnotationMarkBase.prototype);
Object.assign(ParagraphPermBase.prototype, AscWord.AnnotationMarkBase.prototype);

ParagraphPermBase.prototype.Get_Id = function()
{
Expand All @@ -64,19 +65,17 @@
ParagraphPermBase.prototype.PreDelete = function()
{
let logicDocument = this.GetLogicDocument();
if (!logicDocument
|| !logicDocument.IsDocumentEditor()
|| !logicDocument.IsActionStarted())
if (!logicDocument || !logicDocument.IsDocumentEditor())
return;



logicDocument.OnDeleteAnnotationMark(this);
};
ParagraphPermBase.prototype.isPermMark = function()
ParagraphPermBase.prototype.SetParagraph = function(p)
{
return true;
CParagraphContentBase.prototype.SetParagraph.call(this, p);
AscWord.registerPermRangeMark(this);
};
ParagraphPermBase.prototype.isStart = function()
ParagraphPermBase.prototype.isPermMark = function()
{
return true;
};
Expand Down Expand Up @@ -255,9 +254,9 @@

return new ParagraphPermEnd(obj.id);
};
ParagraphPermEnd.prototype.isStart = function()
ParagraphPermEnd.prototype.isEnd = function()
{
return false;
return true;
};
ParagraphPermEnd.prototype.Draw_HighLights = function(PDSH)
{
Expand Down
102 changes: 102 additions & 0 deletions word/Editor/annotations/perm-ranges-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/

"use strict";

(function()
{
let marksToCheck = [];

/**
* @param logicDocument {AscWord.Document}
* @constructor
*/
function PermRangesManager(logicDocument)
{
this.logicDocument = logicDocument

this.ranges = {};
}

PermRangesManager.prototype.addMark = function(mark)
{
let rangeId = mark.getRangeId();
if (!this.ranges[rangeId])
this.ranges[rangeId] = {};

if (mark.isStart())
this.ranges[rangeId].start = mark;
else
this.ranges[rangeId].end = mark;
};
PermRangesManager.prototype.getStartMark = function(rangeId)
{
this.updateMarks();

if (!this.ranges[rangeId] || !this.ranges[rangeId].start)
return null

return this.ranges[rangeId].start;
};
PermRangesManager.prototype.getEndMark = function(rangeId)
{
this.updateMarks();

if (!this.ranges[rangeId] || !this.ranges[rangeId].end)
return null;

return this.ranges[rangeId].end;
};
PermRangesManager.prototype.updateMarks = function()
{
for (let i = 0, count = marksToCheck.length; i < count; ++i)
{
let mark = marksToCheck[i];
if (!mark.isUseInDocument())
continue;

this.addMark(mark);
}

marksToCheck.length = 0;
};

function registerPermRangeMark(mark)
{
marksToCheck.push(mark);
}
//--------------------------------------------------------export----------------------------------------------------
AscWord.PermRangesManager = PermRangesManager;
AscWord.registerPermRangeMark = registerPermRangeMark;

})();

0 comments on commit 14a1018

Please sign in to comment.