mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-19 00:20:25 +02:00
Merge pull request #883 from bttelle/fix-sec-win-close-w-changed-inactive-tab
Fixes for incorrect SecondaryAllowClose logic
This commit is contained in:
commit
7e139f5d7c
1 changed files with 140 additions and 101 deletions
|
@ -1241,40 +1241,62 @@ namespace IDE
|
||||||
if (mRunningTestScript)
|
if (mRunningTestScript)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
void CloseTabs()
|
||||||
|
{
|
||||||
|
WithDocumentTabbedViewsOf(window, scope (tabbedView) => {
|
||||||
|
tabbedView.CloseTabs(false, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseWindow()
|
||||||
|
{
|
||||||
|
mMainWindow.SetForeground();
|
||||||
|
window.Close(true);
|
||||||
|
}
|
||||||
|
|
||||||
List<String> changedList = scope List<String>();
|
List<String> changedList = scope List<String>();
|
||||||
defer ClearAndDeleteItems(changedList);
|
defer ClearAndDeleteItems(changedList);
|
||||||
WithSourceViewPanels(scope (sourceViewPanel) =>
|
WithSourceViewPanelsOf(window, scope (sourceViewPanel) =>
|
||||||
{
|
{
|
||||||
if ((sourceViewPanel.mWidgetWindow == window) && (sourceViewPanel.HasUnsavedChanges()))
|
if (sourceViewPanel.HasUnsavedChanges())
|
||||||
{
|
{
|
||||||
var fileName = new String();
|
var fileName = new String();
|
||||||
Path.GetFileName(sourceViewPanel.mFilePath, fileName);
|
Path.GetFileName(sourceViewPanel.mFilePath, fileName);
|
||||||
changedList.Add(fileName);
|
changedList.Add(fileName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (changedList.Count == 0)
|
|
||||||
|
if (changedList.Count == 0) {
|
||||||
|
CloseTabs();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
var aDialog = QuerySaveFiles(changedList, (WidgetWindow)window);
|
var aDialog = QuerySaveFiles(changedList, (WidgetWindow)window);
|
||||||
aDialog.mDefaultButton = aDialog.AddButton("Save", new (evt) =>
|
aDialog.mDefaultButton = aDialog.AddButton("Save", new (evt) =>
|
||||||
{
|
{
|
||||||
bool hadError = false;
|
bool hadError = false;
|
||||||
// We use a close delay after saving so the user can see we actually saved before closing down
|
// We use a close delay after saving so the user can see we actually saved before closing down
|
||||||
var _this = this;
|
var _this = this;
|
||||||
WithSourceViewPanels(scope [&] (sourceViewPanel) =>
|
WithSourceViewPanelsOf(window, scope [&] (sourceViewPanel) =>
|
||||||
{
|
{
|
||||||
if ((!hadError) && (sourceViewPanel.mWidgetWindow == window) && (sourceViewPanel.HasUnsavedChanges()))
|
if ((!hadError) && (sourceViewPanel.HasUnsavedChanges()))
|
||||||
if (!_this.SaveFile(sourceViewPanel))
|
if (!_this.SaveFile(sourceViewPanel))
|
||||||
hadError = true;
|
hadError = true;
|
||||||
});
|
});
|
||||||
if (hadError)
|
if (hadError)
|
||||||
return;
|
return;
|
||||||
mMainWindow.SetForeground();
|
CloseTabs();
|
||||||
window.Close(true);
|
CloseWindow();
|
||||||
});
|
});
|
||||||
aDialog.AddButton("Don't Save", new (evt) =>
|
aDialog.AddButton("Don't Save", new (evt) =>
|
||||||
{
|
{
|
||||||
mMainWindow.SetForeground();
|
var _this = this;
|
||||||
window.Close(true);
|
WithSourceViewPanelsOf(window, scope [&] (sourceViewPanel) =>
|
||||||
|
{
|
||||||
|
if (sourceViewPanel.HasUnsavedChanges())
|
||||||
|
_this.RevertSourceViewPanel(sourceViewPanel);
|
||||||
|
});
|
||||||
|
CloseTabs();
|
||||||
|
CloseWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
aDialog.mEscButton = aDialog.AddButton("Cancel");
|
aDialog.mEscButton = aDialog.AddButton("Cancel");
|
||||||
|
@ -5560,30 +5582,32 @@ namespace IDE
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WithDocumentTabbedViews(delegate void(DarkTabbedView) func)
|
public void WithDocumentTabbedViewsOf(BFWindow window, delegate void(DarkTabbedView) func)
|
||||||
{
|
{
|
||||||
for (int32 windowIdx = 0; windowIdx < mWindows.Count; windowIdx++)
|
var widgetWindow = window as WidgetWindow;
|
||||||
{
|
if (widgetWindow != null)
|
||||||
var window = mWindows[windowIdx];
|
{
|
||||||
var widgetWindow = window as WidgetWindow;
|
var darkDockingFrame = widgetWindow.mRootWidget as DarkDockingFrame;
|
||||||
if (widgetWindow != null)
|
if (widgetWindow == mMainWindow)
|
||||||
{
|
darkDockingFrame = mDockingFrame;
|
||||||
var darkDockingFrame = widgetWindow.mRootWidget as DarkDockingFrame;
|
|
||||||
if (widgetWindow == mMainWindow)
|
|
||||||
darkDockingFrame = mDockingFrame;
|
|
||||||
|
|
||||||
if (darkDockingFrame != null)
|
if (darkDockingFrame != null)
|
||||||
{
|
{
|
||||||
darkDockingFrame.WithAllDockedWidgets(scope (dockedWidget) =>
|
darkDockingFrame.WithAllDockedWidgets(scope (dockedWidget) =>
|
||||||
{
|
{
|
||||||
var tabbedView = dockedWidget as DarkTabbedView;
|
var tabbedView = dockedWidget as DarkTabbedView;
|
||||||
if (tabbedView != null)
|
if (tabbedView != null)
|
||||||
func(tabbedView);
|
func(tabbedView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void WithDocumentTabbedViews(delegate void(DarkTabbedView) func)
|
||||||
|
{
|
||||||
|
for (let window in mWindows)
|
||||||
|
WithDocumentTabbedViewsOf(window, func);
|
||||||
|
}
|
||||||
|
|
||||||
public void EnsureDocumentArea()
|
public void EnsureDocumentArea()
|
||||||
{
|
{
|
||||||
|
@ -5682,13 +5706,19 @@ namespace IDE
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WithTabs(delegate void(TabbedView.TabButton) func)
|
public void WithTabsOf(BFWindow window, delegate void(TabbedView.TabButton) func)
|
||||||
{
|
{
|
||||||
WithDocumentTabbedViews(scope (documentTabbedView) =>
|
WithDocumentTabbedViewsOf(window, scope (documentTabbedView) =>
|
||||||
{
|
{
|
||||||
documentTabbedView.WithTabs(func);
|
documentTabbedView.WithTabs(func);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WithTabs(delegate void(TabbedView.TabButton) func)
|
||||||
|
{
|
||||||
|
for (let window in mWindows)
|
||||||
|
WithTabsOf(window, func);
|
||||||
|
}
|
||||||
|
|
||||||
public TabbedView.TabButton GetTab(Widget content)
|
public TabbedView.TabButton GetTab(Widget content)
|
||||||
{
|
{
|
||||||
|
@ -5701,15 +5731,21 @@ namespace IDE
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WithSourceViewPanels(delegate void(SourceViewPanel) func)
|
public void WithSourceViewPanelsOf(BFWindow window, delegate void(SourceViewPanel) func)
|
||||||
{
|
{
|
||||||
WithTabs(scope (tab) =>
|
WithTabsOf(window, scope (tab) =>
|
||||||
{
|
{
|
||||||
var sourceViewPanel = tab.mContent as SourceViewPanel;
|
var sourceViewPanel = tab.mContent as SourceViewPanel;
|
||||||
if (sourceViewPanel != null)
|
if (sourceViewPanel != null)
|
||||||
func(sourceViewPanel);
|
func(sourceViewPanel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void WithSourceViewPanels(delegate void(SourceViewPanel) func)
|
||||||
|
{
|
||||||
|
for (let window in mWindows)
|
||||||
|
WithSourceViewPanelsOf(window, func);
|
||||||
|
}
|
||||||
|
|
||||||
TabbedView.TabButton SetupTab(TabbedView tabView, String name, float width, Widget content, bool ownsContent) // 2
|
TabbedView.TabButton SetupTab(TabbedView tabView, String name, float width, Widget content, bool ownsContent) // 2
|
||||||
{
|
{
|
||||||
|
@ -6463,6 +6499,61 @@ namespace IDE
|
||||||
aDialog.PopupWindow(mMainWindow);
|
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)
|
public void CloseDocument(Widget documentPanel)
|
||||||
{
|
{
|
||||||
bool hasFocus = false;
|
bool hasFocus = false;
|
||||||
|
@ -6478,59 +6569,7 @@ namespace IDE
|
||||||
hasFocus = sourceViewPanel.mEditWidget.mHasFocus;*/
|
hasFocus = sourceViewPanel.mEditWidget.mHasFocus;*/
|
||||||
|
|
||||||
if ((sourceViewPanel != null) && (sourceViewPanel.HasUnsavedChanges()))
|
if ((sourceViewPanel != null) && (sourceViewPanel.HasUnsavedChanges()))
|
||||||
{
|
RevertSourceViewPanel(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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DarkTabbedView tabbedView = null;
|
DarkTabbedView tabbedView = null;
|
||||||
DarkTabbedView.DarkTabButton tabButton = null;
|
DarkTabbedView.DarkTabButton tabButton = null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue