Files
PDFPatcher/App/Functions/Editor/Commands/DeleteBookmarkItemCommand.cs
T
2022-04-21 21:43:45 +08:00

44 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using PDFPatcher.Processor;
namespace PDFPatcher.Functions.Editor
{
sealed class DeleteBookmarkItemCommand : IEditorCommand
{
public void Process(Controller controller, params string[] parameters) {
RemoveItems(controller, controller.View.Bookmark.GetSelectedElements(false));
}
static void RemoveItems(Controller controller, System.Collections.IList si) {
if (si.Count == 0) {
return;
}
var b = controller.View.Bookmark;
b.RemoveObjects(si);
var undo = new UndoActionGroup();
var l = new List<XmlNode>();
foreach (XmlElement item in si) {
if (item == null || item.ParentNode == null) {
continue;
}
undo.Add(new AddElementAction(item));
var p = item.ParentNode;
p.RemoveChild(item);
if (l.Contains(p) == false) {
l.Add(p);
}
}
foreach (var item in l) {
if (item.ParentNode != null) {
b.RefreshObject(item);
}
}
controller.Model.Undo.AddUndo("删除书签", undo);
}
}
}