From da508156c1083a56913594b94cd122f2dfb564c5 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 28 Sep 2020 05:56:09 -0700 Subject: [PATCH] Separate Close Panel and Close Document --- IDE/src/Commands.bf | 3 ++- IDE/src/IDEApp.bf | 47 +++++++++++++++++++++++++++++++++++++++++---- IDE/src/Settings.bf | 6 +++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/IDE/src/Commands.bf b/IDE/src/Commands.bf index 73f5534e..4c2ccb6f 100644 --- a/IDE/src/Commands.bf +++ b/IDE/src/Commands.bf @@ -190,7 +190,8 @@ namespace IDE Add("Clean", new => gApp.Cmd_Clean); Add("Close All Panels", new () => { gApp.[Friend]TryCloseAllDocuments(true); }); Add("Close All Panels Except", new () => { gApp.[Friend]TryCloseAllDocuments(false); }); - Add("Close Panel", new () => { gApp.[Friend]TryCloseCurrentDocument(); }); + Add("Close Document", new () => { gApp.[Friend]TryCloseCurrentDocument(); }); + Add("Close Panel", new () => { gApp.[Friend]TryCloseCurrentPanel(); }); Add("Close Workspace", new => gApp.[Friend]Cmd_CloseWorkspaceAndSetupNew); Add("Comment Selection", new => gApp.[Friend]CommentSelection); Add("Compile File", new => gApp.Cmd_CompileFile); diff --git a/IDE/src/IDEApp.bf b/IDE/src/IDEApp.bf index 65168e25..1d4a56c3 100644 --- a/IDE/src/IDEApp.bf +++ b/IDE/src/IDEApp.bf @@ -5065,6 +5065,11 @@ namespace IDE menu.SetDisabled(GetActiveDocumentPanel() == null); } + public void UpdateMenuItem_HasLastActiveDocument(IMenu menu) + { + menu.SetDisabled(GetLastActiveDocumentPanel() == null); + } + public void UpdateMenuItem_HasWorkspace(IMenu menu) { menu.SetDisabled(!gApp.mWorkspace.IsInitialized); @@ -5377,7 +5382,8 @@ namespace IDE ////////// mWindowMenu = root.AddMenuItem("&Window"); - AddMenuItem(mWindowMenu, "&Close", "Close Panel", new => UpdateMenuItem_HasActivePanel); + AddMenuItem(mWindowMenu, "&Close Document", "Close Document", new => UpdateMenuItem_HasLastActiveDocument); + AddMenuItem(mWindowMenu, "Close &Panel", "Close Panel", new => UpdateMenuItem_HasActivePanel); AddMenuItem(mWindowMenu, "&Close All", "Close All Panels"); AddMenuItem(mWindowMenu, "Close All Except Current", "Close All Panels Except"); AddMenuItem(mWindowMenu, "&New View into File", "View New", new => UpdateMenuItem_HasActiveDocument); @@ -5587,6 +5593,24 @@ namespace IDE return activePanel; return null; } + + public Widget GetLastActiveDocumentPanel() + { + var activePanel = GetActiveDocumentPanel(); + if (activePanel != null) + return activePanel; + if (mActiveDocumentsTabbedView != null) + { + let activeTab = mActiveDocumentsTabbedView.GetActiveTab(); + if (activeTab != null) + { + var lastActivePanel = activeTab.mContent; + if ((lastActivePanel is SourceViewPanel) || (lastActivePanel is DisassemblyPanel)) + return lastActivePanel; + } + } + return null; + } public void WithTabs(delegate void(TabbedView.TabButton) func) { @@ -6514,7 +6538,7 @@ namespace IDE void TryCloseCurrentDocument() { - var activeDocumentPanel = GetActiveDocumentPanel(); + var activeDocumentPanel = GetLastActiveDocumentPanel(); if (activeDocumentPanel != null) { if (activeDocumentPanel is SourceViewPanel) @@ -6524,13 +6548,28 @@ namespace IDE return; } CloseDocument(activeDocumentPanel); - return; } + } + + void TryCloseCurrentPanel() + { + var activeDocumentPanel = GetActiveDocumentPanel(); + if (activeDocumentPanel != null) + { + if (activeDocumentPanel is SourceViewPanel) + { + var sourceViewPanel = (SourceViewPanel)activeDocumentPanel; + DocumentCloseClicked(sourceViewPanel); + return; + } + CloseDocument(activeDocumentPanel); + return; + } var activePanel = GetActivePanel(); if (activePanel != null) CloseDocument(activePanel); - } + } void TryCloseAllDocuments(bool closeCurrent) { diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index 25f0960d..8b8aca25 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -670,7 +670,7 @@ namespace IDE Add("Breakpoint Toggle Thread", "Shift+F9"); Add("Build Solution", "F7"); Add("Cancel Build", "Ctrl+Break"); - Add("Close Panel", "Ctrl+W"); + Add("Close Document", "Ctrl+W"); Add("Compile File", "Ctrl+F7"); Add("Comment Selection", "Ctrl+K, Ctrl+C"); Add("Duplicate Line", "Ctrl+D"); @@ -890,6 +890,10 @@ namespace IDE let entry = new Entry(); entry.mCommand = new String(cmdStr); + // Fix for command rename + if ((cmdStr == "Close Panel") && (!sd.Contains("Close Document"))) + entry.mCommand.Set("Close Document"); + let keyList = scope List(); KeyState.Parse(keyStr, keyList);