From 1f772f685e1cfb2fa5600b4e20432c1953cec889 Mon Sep 17 00:00:00 2001 From: Joseph Battelle Date: Mon, 1 Feb 2021 18:20:12 -0800 Subject: [PATCH] Fix 'Dont Save' on Secondary Windows When you select 'Dont Save' on the close dialog of secondary windows, the projectSource is left with changes and no SourceViewPanel, and then VerifyModifiedBuffers will fail. This fix uses refactored code from CloseDocument, 'RevertSourceViewPanel', to revert changes on close. --- IDE/src/IDEApp.bf | 115 +++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index ca6b033b..ef58e26a 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -1273,6 +1273,12 @@ namespace IDE }); aDialog.AddButton("Don't Save", new (evt) => { + var _this = this; + WithSourceViewPanelsOf(window, scope [&] (sourceViewPanel) => + { + if (sourceViewPanel.HasUnsavedChanges()) + _this.RevertSourceViewPanel(sourceViewPanel); + }); mMainWindow.SetForeground(); window.Close(true); }); @@ -6477,6 +6483,61 @@ namespace IDE aDialog.PopupWindow(mMainWindow); } + void RevertSourceViewPanel(SourceViewPanel sourceViewPanel) + { + // When we close a Beef file that has modified text, we need to revert by + // reparsing from the actual source file + if (sourceViewPanel.mIsBeefSource) + { + mBfResolveHelper.DeferReparse(sourceViewPanel.mFilePath, null); + //mBfResolveHelper.DeferRefreshVisibleViews(null); + } + + var projectSource = sourceViewPanel.mProjectSource; + if (projectSource != null) + { + var editData = GetEditData(projectSource, true); + if (editData != null) + { + var editWidgetContent = editData.mEditWidget.mEditWidgetContent; + + //TODO: Verify this, once we have multiple panes allowed within a single SourceViewContent + if (editWidgetContent.mData.mUsers.Count == 1) // Is last view of data... + { + if ((editData != null) && (editData.mHadRefusedFileChange)) + { + // If we didn't take an external file change then closing the file means we want to revert + // our data to the version on disk + sourceViewPanel.Reload(); + } + else + { + // Undo until we either get to whatever the last saved state was, or until we + // get to a global action like renaming a symbol - we need to leave those + // so the global undo actually works if invoked from another file + while (editData.HasTextChanged()) + { + var nextUndoAction = editWidgetContent.mData.mUndoManager.GetLastUndoAction(); + if (nextUndoAction == null) + break; + if (nextUndoAction is UndoBatchEnd) + { + var undoBatchEnd = (UndoBatchEnd)nextUndoAction; + if (undoBatchEnd.Name.StartsWith("#")) + { + break; + } + } + editWidgetContent.mData.mUndoManager.Undo(); + } + + editWidgetContent.mData.mTextIdData.Prepare(); + } + } + } + } + } + public void CloseDocument(Widget documentPanel) { bool hasFocus = false; @@ -6492,59 +6553,7 @@ namespace IDE hasFocus = sourceViewPanel.mEditWidget.mHasFocus;*/ if ((sourceViewPanel != null) && (sourceViewPanel.HasUnsavedChanges())) - { - // When we close a Beef file that has modified text, we need to revert by - // reparsing from the actual source file - if (sourceViewPanel.mIsBeefSource) - { - mBfResolveHelper.DeferReparse(sourceViewPanel.mFilePath, null); - //mBfResolveHelper.DeferRefreshVisibleViews(null); - } - - var projectSource = sourceViewPanel.mProjectSource; - if (projectSource != null) - { - var editData = GetEditData(projectSource, true); - if (editData != null) - { - var editWidgetContent = editData.mEditWidget.mEditWidgetContent; - - //TODO: Verify this, once we have multiple panes allowed within a single SourceViewContent - if (editWidgetContent.mData.mUsers.Count == 1) // Is last view of data... - { - if ((editData != null) && (editData.mHadRefusedFileChange)) - { - // If we didn't take an external file change then closing the file means we want to revert - // our data to the version on disk - sourceViewPanel.Reload(); - } - else - { - // Undo until we either get to whatever the last saved state was, or until we - // get to a global action like renaming a symbol - we need to leave those - // so the global undo actually works if invoked from another file - while (editData.HasTextChanged()) - { - var nextUndoAction = editWidgetContent.mData.mUndoManager.GetLastUndoAction(); - if (nextUndoAction == null) - break; - if (nextUndoAction is UndoBatchEnd) - { - var undoBatchEnd = (UndoBatchEnd)nextUndoAction; - if (undoBatchEnd.Name.StartsWith("#")) - { - break; - } - } - editWidgetContent.mData.mUndoManager.Undo(); - } - - editWidgetContent.mData.mTextIdData.Prepare(); - } - } - } - } - } + RevertSourceViewPanel(sourceViewPanel); DarkTabbedView tabbedView = null; DarkTabbedView.DarkTabButton tabButton = null;