1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-18 16:10:26 +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:
Brian Fiete 2021-02-02 05:40:38 -08:00 committed by GitHub
commit 7e139f5d7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,11 +5582,8 @@ 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 window = mWindows[windowIdx];
var widgetWindow = window as WidgetWindow; var widgetWindow = window as WidgetWindow;
if (widgetWindow != null) if (widgetWindow != null)
{ {
@ -5583,6 +5602,11 @@ namespace IDE
} }
} }
} }
public void WithDocumentTabbedViews(delegate void(DarkTabbedView) func)
{
for (let window in mWindows)
WithDocumentTabbedViewsOf(window, func);
} }
public void EnsureDocumentArea() public void EnsureDocumentArea()
@ -5682,14 +5706,20 @@ 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)
{ {
TabbedView.TabButton tab = null; TabbedView.TabButton tab = null;
@ -5701,9 +5731,9 @@ 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)
@ -5711,6 +5741,12 @@ namespace IDE
}); });
} }
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
{ {
TabbedView.TabButton tabButton = tabView.AddTab(name, width, content, ownsContent); TabbedView.TabButton tabButton = tabView.AddTab(name, width, content, ownsContent);
@ -6463,21 +6499,7 @@ namespace IDE
aDialog.PopupWindow(mMainWindow); aDialog.PopupWindow(mMainWindow);
} }
public void CloseDocument(Widget documentPanel) void RevertSourceViewPanel(SourceViewPanel sourceViewPanel)
{
bool hasFocus = false;
var sourceViewPanel = documentPanel as SourceViewPanel;
if ((documentPanel.mWidgetWindow != null) && (documentPanel.mWidgetWindow.mFocusWidget != null))
{
if (documentPanel.mWidgetWindow.mFocusWidget.HasParent(documentPanel))
hasFocus = true;
}
/*if (sourceViewPanel != null)
hasFocus = sourceViewPanel.mEditWidget.mHasFocus;*/
if ((sourceViewPanel != null) && (sourceViewPanel.HasUnsavedChanges()))
{ {
// When we close a Beef file that has modified text, we need to revert by // When we close a Beef file that has modified text, we need to revert by
// reparsing from the actual source file // reparsing from the actual source file
@ -6532,6 +6554,23 @@ namespace IDE
} }
} }
public void CloseDocument(Widget documentPanel)
{
bool hasFocus = false;
var sourceViewPanel = documentPanel as SourceViewPanel;
if ((documentPanel.mWidgetWindow != null) && (documentPanel.mWidgetWindow.mFocusWidget != null))
{
if (documentPanel.mWidgetWindow.mFocusWidget.HasParent(documentPanel))
hasFocus = true;
}
/*if (sourceViewPanel != null)
hasFocus = sourceViewPanel.mEditWidget.mHasFocus;*/
if ((sourceViewPanel != null) && (sourceViewPanel.HasUnsavedChanges()))
RevertSourceViewPanel(sourceViewPanel);
DarkTabbedView tabbedView = null; DarkTabbedView tabbedView = null;
DarkTabbedView.DarkTabButton tabButton = null; DarkTabbedView.DarkTabButton tabButton = null;
WithTabs(scope [&] (tab) => WithTabs(scope [&] (tab) =>