]> O.S.I.I.S - jp/crowedit.git/commitdiff
editor window, keep last focus document visible in any situation
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 7 Mar 2025 20:16:49 +0000 (21:16 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 7 Mar 2025 20:16:49 +0000 (21:16 +0100)
CrowEditBase/src/CrowEditBase.cs
CrowEditBase/src/TextDocument.cs
src/CrowEdit.cs

index 8af5540ba7b7e8abd3815b37956a75c7cf99cd1d..69fe5a45cb98c5819076045f67fa605cec989436 100644 (file)
@@ -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;
index 12fbf263cd9613981977adc68b4292713e6d3bce..699645582d47aa9496c0c171eed95e1ad2616126 100644 (file)
@@ -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
 {
index db222835a712038bbab3c3198a7f1410a83aaaf4..5af9f990c04c7d6cd90d48a35e0d8f4b75512a14 100644 (file)
@@ -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<string> ("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)