1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using PaintDotNet.Measurement.HistoryMementos;
- using System.Collections.Generic;
- namespace PaintDotNet.Measurement.HistoryFunctions
- {
- public sealed class FlattenFunction
- : HistoryFunction
- {
- public static string StaticName
- {
- get
- {
- return PdnResources.GetString("FlattenFunction.Name");
- }
- }
- public override HistoryMemento OnExecute(IDocumentWorkspace historyWorkspace)
- {
- object savedSelection = null;
- List<HistoryMemento> actions = new List<HistoryMemento>();
- if (!historyWorkspace.GetSelection().IsEmpty)
- {
- savedSelection = historyWorkspace.GetSelection().Save();
- DeselectFunction da = new DeselectFunction();
- HistoryMemento hm = da.Execute(historyWorkspace);
- actions.Add(hm);
- }
- ReplaceDocumentHistoryMemento rdha = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace);
- actions.Add(rdha);
- CompoundHistoryMemento chm = new CompoundHistoryMemento(
- StaticName,
- PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"),
- actions);
- // TODO: we can save memory here by serializing, then flattening on to an existing layer
- Document flat = historyWorkspace.GetDocument().Flatten();
- EnterCriticalRegion();
- historyWorkspace.SetDocument(flat);
- if (savedSelection != null)
- {
- SelectionHistoryMemento shm = new SelectionHistoryMemento(null, null, historyWorkspace);
- historyWorkspace.GetSelection().Restore(savedSelection);
- chm.PushNewAction(shm);
- }
- return chm;
- }
- public FlattenFunction()
- : base(PaintDotNet.Measurement.Enum.ActionFlags.None)
- {
- }
- }
- }
|