Fix #7423 - tidy up open file list
authorAlan <alan@roojs.com>
Wed, 28 Sep 2022 09:51:15 +0000 (17:51 +0800)
committerAlan <alan@roojs.com>
Wed, 28 Sep 2022 09:51:15 +0000 (17:51 +0800)
src/Builder4/MainWindow.bjs
src/Builder4/MainWindow.vala

index 052ac26..7019c9d 100644 (file)
           "\t \t this.el.popup.remove(m);",
           "\t }",
           "\t this.mitems.clear();",
-          "\t   ",
+          "\t ",
+          "\t BuilderApplication.windows.sort((a,b) => {",
+          "\t \tif (a.windowstate == null ||",
+          " \t\t\t a.windowstate.file == null || ",
+          " \t\t\t b.windowstate == null ||",
+          " \t\t\t b.windowstate.file == null",
+          " \t\t\t ) { ",
+          " \t\t\treturn 0;",
+          "\t\t}",
+          "",
+          "\t \tvar ap = a.windowstate.file.project.name;",
+          "\t \tvar bp = b.windowstate.file.project.name;",
+          "\t \t",
+          "",
+          "\t \t",
+          "\t \tif (ap != bp) {",
+          "\t \t\treturn ap.collate(bp);",
+          "\t \t}",
+          "\t \tvar af = a.windowstate.file.getTitle();",
+          "\t \tvar bf = b.windowstate.file.getTitle();\t \t",
+          "\t\treturn af.collate(bf);",
+          "\t ",
+          "\t });",
+          "\t ",
+          "\t var p = \"\";",
           "\t foreach(var w in BuilderApplication.windows) {",
           "\t \tvar wid = BuilderApplication.windows.index_of(w);",
           "\t \t// fixme find a better way to display this.",
           " \t\t\t ) { ",
           " \t\t\tcontinue;",
           "\t\t}",
-          "\t \t",
+          "\t \t// should not happen...",
           "\t \tif (w.windowstate.file.path == _this.windowstate.file.path) {",
           "\t \t\tcontinue;",
           " \t\t}",
+          " \t\tif (w.windowstate.file.project.name != p || p != \"\") {",
+          " \t\t\tvar ms = new Gtk.SeparatorMenuItem();",
+          " \t\t\tthis.el.popup.append(ms);",
+          "\t\t \tms.show();",
+          "\t\t \tthis.mitems.add(ms);",
+          " \t\t}",
+          " \t\t",
+          " \t\tp = w.windowstate.file.project.name;",
+          " \t\t",
           "",
           " \t\tGLib.debug(\"add menuitem %s\", w.windowstate.file.path);",
-          "\t \tvar m = new Gtk.MenuItem.with_label(w.windowstate.file.path);",
+          " \t\t",
+          " \t\t",
+          " \t\t",
+          "\t \tvar m = new Gtk.MenuItem.with_label(",
+          "\t\t \tw.windowstate.file.project.name + \" : \" + w.windowstate.file.getTitle()",
+          "\t \t);",
+          "\t \t",
+          "\t \t//w.windowstate.file.path);",
           "\t \tm.activate.connect(() => {",
           "\t \t\t BuilderApplication.windows.get(wid).el.present();",
           "\t \t});",
index edf96b4..cf86123 100644 (file)
@@ -242,7 +242,31 @@ public class Xcls_MainWindow : Object
                         this.el.popup.remove(m);
                 }
                 this.mitems.clear();
-                  
+                
+                BuilderApplication.windows.sort((a,b) => {
+                       if (a.windowstate == null ||
+                                a.windowstate.file == null || 
+                                b.windowstate == null ||
+                                b.windowstate.file == null
+                                ) { 
+                               return 0;
+                       }
+        
+                       var ap = a.windowstate.file.project.name;
+                       var bp = b.windowstate.file.project.name;
+                       
+        
+                       
+                       if (ap != bp) {
+                               return ap.collate(bp);
+                       }
+                       var af = a.windowstate.file.getTitle();
+                       var bf = b.windowstate.file.getTitle();         
+                       return af.collate(bf);
+                
+                });
+                
+                var p = "";
                 foreach(var w in BuilderApplication.windows) {
                        var wid = BuilderApplication.windows.index_of(w);
                        // fixme find a better way to display this.
@@ -253,13 +277,29 @@ public class Xcls_MainWindow : Object
                                 ) { 
                                continue;
                        }
-                       
+                       // should not happen...
                        if (w.windowstate.file.path == _this.windowstate.file.path) {
                                continue;
                        }
+                       if (w.windowstate.file.project.name != p || p != "") {
+                               var ms = new Gtk.SeparatorMenuItem();
+                               this.el.popup.append(ms);
+                               ms.show();
+                               this.mitems.add(ms);
+                       }
+                       
+                       p = w.windowstate.file.project.name;
+                       
         
                        GLib.debug("add menuitem %s", w.windowstate.file.path);
-                       var m = new Gtk.MenuItem.with_label(w.windowstate.file.path);
+                       
+                       
+                       
+                       var m = new Gtk.MenuItem.with_label(
+                               w.windowstate.file.project.name + " : " + w.windowstate.file.getTitle()
+                       );
+                       
+                       //w.windowstate.file.path);
                        m.activate.connect(() => {
                                 BuilderApplication.windows.get(wid).el.present();
                        });