diff --git a/IDE/src/ui/FindAndReplaceDialog.bf b/IDE/src/ui/FindAndReplaceDialog.bf index 7e0a0a7d..d7290fcd 100644 --- a/IDE/src/ui/FindAndReplaceDialog.bf +++ b/IDE/src/ui/FindAndReplaceDialog.bf @@ -44,7 +44,7 @@ namespace IDE.ui mLocationCombo = new PathComboBox(); mLocationCombo.MakeEditable(new PathEditWidget()); - mLocationCombo.Label = FindResultsPanel.sEntireSolution; + mLocationCombo.Label = isReplace ? FindResultsPanel.sCurrentDocument : FindResultsPanel.sEntireSolution; mLocationCombo.mPopulateMenuAction.Add(new => PopulateLocationMenu); mLocationCombo.mEditWidget.mOnContentChanged.Add(new (evt) => { UpdateUI(); }); AddWidget(mLocationCombo); diff --git a/IDE/src/ui/FindResultsPanel.bf b/IDE/src/ui/FindResultsPanel.bf index 7025cfe6..679b7701 100644 --- a/IDE/src/ui/FindResultsPanel.bf +++ b/IDE/src/ui/FindResultsPanel.bf @@ -730,12 +730,58 @@ namespace IDE.ui line.AppendF(" {0}: Replaced {1} instance{2}\n", filePath, replaceInFileCount, (replaceInFileCount == 1) ? "" : "s"); Write(line); } + + if (replaceCount > 0) + { + Write("\n"); + base.Update(); + var ewc = (OutputWidgetContent)EditWidget.mEditWidgetContent; + + var actionButton = new UndoRenameActionButton(); + actionButton.mPanel = this; + actionButton.mLine = ewc.GetLineCount() - 1; + actionButton.Label = "Undo Replace"; + actionButton.mGlobalUndoData = globalUndoData; + ewc.AddWidget(actionButton); + ewc.mActionWidgets.Add(actionButton); + } } StopSearch(); } } + class UndoRenameActionButton : OutputActionButton + { + public GlobalUndoData mGlobalUndoData; + + bool IsValid => ((!gApp.mGlobalUndoManager.mGlobalUndoDataList.IsEmpty) && + (gApp.mGlobalUndoManager.mGlobalUndoDataList.Back == mGlobalUndoData) && + (mGlobalUndoData.mUndoCount == 0)); + + public override void Update() + { + base.Update(); + + if (!IsValid) + Close(); + } + + public override void MouseClicked(float x, float y, float origX, float origY, int32 btn) + { + base.MouseClicked(x, y, origX, origY, btn); + if (!IsValid) + { + Close(); + return; + } + + GlobalUndoAction undoAction = scope .(null, mGlobalUndoData); + undoAction.Undo(); + } + } + + public override void Clear() { base.Clear(); diff --git a/IDE/src/ui/OutputPanel.bf b/IDE/src/ui/OutputPanel.bf index f8885374..cc40a3fc 100644 --- a/IDE/src/ui/OutputPanel.bf +++ b/IDE/src/ui/OutputPanel.bf @@ -45,6 +45,40 @@ namespace IDE.ui public int32 mLineChar; } + public class OutputActionButton : DarkButton + { + public OutputPanel mPanel; + public int mLine; + + public void Close() + { + RemoveSelf(); + gApp.DeferDelete(this); + } + + public override void RemovedFromParent(Widget previousParent, WidgetWindow window) + { + base.RemovedFromParent(previousParent, window); + var ewc = (OutputWidgetContent)mPanel.EditWidget.mEditWidgetContent; + ewc.mActionWidgets.Remove(this); + } + + public override void Update() + { + base.Update(); + var ewc = (OutputWidgetContent)mPanel.EditWidget.mEditWidgetContent; + if (mLine >= ewc.GetLineCount()) + { + Close(); + return; + } + + var font = DarkTheme.sDarkTheme.mSmallFont; + ewc.GetTextCoordAtLineChar(mLine, 0, var x, var y); + Resize(GS!(4), y, font.GetWidth(mLabel) + GS!(32), GS!(24)); + } + } + public OutputWidget mOutputWidget; String mQueuedText = new String() ~ delete _; List mQueuedDisplayChanges = new List() ~ delete _; diff --git a/IDE/src/ui/OutputWidget.bf b/IDE/src/ui/OutputWidget.bf index 646d1367..812e94f7 100644 --- a/IDE/src/ui/OutputWidget.bf +++ b/IDE/src/ui/OutputWidget.bf @@ -12,6 +12,7 @@ namespace IDE.ui public class OutputWidgetContent : SourceEditWidgetContent { public bool mRemapToHighestCompileIdx; + public List mActionWidgets = new .() ~ delete _; public this() { @@ -260,6 +261,18 @@ namespace IDE.ui MouseClicked(x, y, x, y, 1); } } + + public override void TextChanged() + { + base.TextChanged(); + + for (var widget in mActionWidgets) + { + widget.RemoveSelf(); + delete widget; + } + mActionWidgets.Clear(); + } } public class OutputWidget : SourceEditWidget