From ff2bb73f3de2433118ec3ff37174da2fbfef9965 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Fri, 7 Mar 2025 21:16:49 +0100 Subject: [PATCH] editor window, keep last focus document visible in any situation --- CrowEditBase/src/CrowEditBase.cs | 9 +++------ CrowEditBase/src/TextDocument.cs | 3 --- src/CrowEdit.cs | 12 ++++++++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CrowEditBase/src/CrowEditBase.cs b/CrowEditBase/src/CrowEditBase.cs index 8af5540..69fe5a4 100644 --- a/CrowEditBase/src/CrowEditBase.cs +++ b/CrowEditBase/src/CrowEditBase.cs @@ -325,12 +325,9 @@ namespace CrowEditBase return; int idx = OpenedDocuments.IndexOf (doc); OpenedDocuments.Remove (doc); - if (doc == CurrentDocument) { - if (OpenedDocuments.Count > 0) - CurrentDocument = OpenedDocuments[Math.Min (idx, OpenedDocuments.Count - 1)]; - else - CurrentDocument = null; - } + doc.CloseEvent -= onQueryCloseDocument; + if (CurrentDocument == null && OpenedDocuments.Count > 0) + CurrentDocument = OpenedDocuments[Math.Min (idx, OpenedDocuments.Count - 1)]; } protected void onQueryCloseDocument (object sender, EventArgs e) { Document doc = sender as Document; diff --git a/CrowEditBase/src/TextDocument.cs b/CrowEditBase/src/TextDocument.cs index 12fbf26..6996455 100644 --- a/CrowEditBase/src/TextDocument.cs +++ b/CrowEditBase/src/TextDocument.cs @@ -9,9 +9,6 @@ using System.IO; using Crow; using Crow.Text; using static CrowEditBase.CrowEditBase; -using System.Collections.Immutable; -using System.Reflection.Metadata; -using System.Diagnostics; namespace CrowEditBase { diff --git a/src/CrowEdit.cs b/src/CrowEdit.cs index db22283..5af9f99 100644 --- a/src/CrowEdit.cs +++ b/src/CrowEdit.cs @@ -120,7 +120,12 @@ namespace CrowEdit ); ViewCommands = new CommandGroup ("View", new ActionCommand("Explorer", () => LoadWindow ("#CrowEdit.ui.windows.winFileExplorer.crow", this), "#icons.folder.svg"), - new ActionCommand("Editors", () => LoadWindow ("#CrowEdit.ui.windows.winEditor.crow", this), "#icons.edit.svg"), + new ActionCommand("Editors", () => { + if (!TryGetWindow("#CrowEdit.ui.windows.winEditor.crow", out Window we)) { + LoadWindow ("#CrowEdit.ui.windows.winEditor.crow", this); + selecteLastCurrentDocument(); + } + }, "#icons.edit.svg"), new ActionCommand("Exceptions", () => LoadWindow ("#CrowEdit.ui.windows.winExceptions.crow", this), "#icons.exclamation.svg"), new ActionCommand("Projects", () => LoadWindow ("#CrowEdit.ui.windows.winProjects.crow", this)), new ActionCommand("Logs", () => LoadWindow ("#CrowEdit.ui.windows.winLogs.crow", this), "#icons.log.svg"), @@ -255,12 +260,15 @@ namespace CrowEdit return; foreach (string f in tmp.Split(';')) openOrCreateFile (f); + selecteLastCurrentDocument(); + } + void selecteLastCurrentDocument() { string lastCurDoc = Configuration.Global.Get ("CurrentDocument"); if (string.IsNullOrEmpty (lastCurDoc)) return; Document doc = OpenedDocuments.FirstOrDefault (d => d.FullPath == lastCurDoc); if (doc != null) - CurrentDocument = doc; + CurrentDocument = doc; } void saveProjectList () { if (Projects.Count == 0) -- 2.47.3