mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Add warning when performing destructive undo of global operation
This commit is contained in:
parent
d695226657
commit
d1a2c53bd7
2 changed files with 103 additions and 1 deletions
|
@ -278,6 +278,31 @@ namespace Beefy.utils
|
|||
return true;
|
||||
}
|
||||
|
||||
public void PreUndo(delegate void (UndoAction) dlg)
|
||||
{
|
||||
int undoIdx = mUndoIdx;
|
||||
if (undoIdx == 0)
|
||||
return;
|
||||
|
||||
var undoAction = mUndoList[undoIdx - 1];
|
||||
if (IUndoBatchEnd undoBatchEnd = undoAction as IUndoBatchEnd)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
dlg(undoAction);
|
||||
if (undoIdx == 0)
|
||||
return;
|
||||
undoIdx--;
|
||||
if ((undoAction == undoBatchEnd.BatchStart) || (undoIdx == 0))
|
||||
return;
|
||||
undoAction = mUndoList[undoIdx - 1];
|
||||
}
|
||||
}
|
||||
|
||||
dlg(undoAction);
|
||||
undoIdx--;
|
||||
}
|
||||
|
||||
public bool Redo()
|
||||
{
|
||||
mSkipNextMerge = true;
|
||||
|
|
|
@ -16,6 +16,7 @@ using Beefy.geom;
|
|||
using Beefy.events;
|
||||
using System.Security.Cryptography;
|
||||
using System.IO;
|
||||
using IDE.Util;
|
||||
|
||||
namespace IDE.ui
|
||||
{
|
||||
|
@ -5196,6 +5197,82 @@ namespace IDE.ui
|
|||
base.MouseDown(x, y, btn, btnCount);
|
||||
}
|
||||
|
||||
public void Undo(bool force)
|
||||
{
|
||||
if (!force)
|
||||
{
|
||||
String undoWarnFiles = scope .();
|
||||
|
||||
mData.mUndoManager.PreUndo(scope [&] (undoAction) =>
|
||||
{
|
||||
if (var globalUndoAction = undoAction as GlobalUndoAction)
|
||||
{
|
||||
bool panelFoundInAll = true;
|
||||
|
||||
for (var fileEditData in globalUndoAction.mUndoData.mFileEditDatas)
|
||||
{
|
||||
bool actionFound = false;
|
||||
bool foundPanel = false;
|
||||
var data = fileEditData.mEditWidget.mEditWidgetContent.mData;
|
||||
|
||||
for (var user in data.mUsers)
|
||||
{
|
||||
if (var sewc = user as SourceEditWidgetContent)
|
||||
{
|
||||
if (sewc.mSourceViewPanel != null)
|
||||
{
|
||||
foundPanel = true;
|
||||
}
|
||||
}
|
||||
if (!foundPanel)
|
||||
panelFoundInAll = false;
|
||||
}
|
||||
|
||||
data.mUndoManager.PreUndo(scope [&] (subUndoAction) =>
|
||||
{
|
||||
if (var subGlobalUndoAction = subUndoAction as GlobalUndoAction)
|
||||
{
|
||||
if (subGlobalUndoAction.mUndoData == globalUndoAction.mUndoData)
|
||||
actionFound = true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (!actionFound)
|
||||
{
|
||||
if (!undoWarnFiles.IsEmpty)
|
||||
undoWarnFiles.Append(", ");
|
||||
undoWarnFiles.AppendF("'");
|
||||
Path.GetFileName(fileEditData.mFilePath, undoWarnFiles);
|
||||
undoWarnFiles.AppendF("'");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!undoWarnFiles.IsEmpty)
|
||||
{
|
||||
Dialog dialog = ThemeFactory.mDefault.CreateDialog("Undo/Redo Warning", scope $"You are attempting to undo a global operation which will revert subsequent changes in {undoWarnFiles}. Do you wish to proceed?", DarkTheme.sDarkTheme.mIconWarning);
|
||||
dialog.mDefaultButton = dialog.AddButton("Yes", new (evt) =>
|
||||
{
|
||||
dialog.Close();
|
||||
var svPanel = gApp.GetActiveSourceViewPanel();
|
||||
if ((svPanel != null) && (svPanel.mEditWidget == mEditWidget))
|
||||
Undo(true);
|
||||
});
|
||||
dialog.mEscButton = dialog.AddButton("No", new (evt) =>
|
||||
{
|
||||
//dialog.Close();
|
||||
});
|
||||
dialog.PopupWindow(gApp.GetActiveWindow());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
base.Undo();
|
||||
}
|
||||
|
||||
public override void Undo()
|
||||
{
|
||||
var symbolReferenceHelper = IDEApp.sApp.mSymbolReferenceHelper;
|
||||
|
@ -5205,7 +5282,7 @@ namespace IDE.ui
|
|||
return;
|
||||
}
|
||||
|
||||
base.Undo();
|
||||
Undo(false);
|
||||
}
|
||||
|
||||
public override void Redo()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue