From 1d1343cc198a3c37db6a0da6a62d6fdb175cc485 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 28 Sep 2022 17:51:15 +0800 Subject: [PATCH] Fix #7423 - tidy up open file list --- src/Builder4/MainWindow.bjs | 46 +++++++++++++++++++++++++++++++++--- src/Builder4/MainWindow.vala | 46 +++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/Builder4/MainWindow.bjs b/src/Builder4/MainWindow.bjs index 052ac265a..7019c9de1 100644 --- a/src/Builder4/MainWindow.bjs +++ b/src/Builder4/MainWindow.bjs @@ -93,7 +93,31 @@ "\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.", @@ -104,13 +128,29 @@ " \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});", diff --git a/src/Builder4/MainWindow.vala b/src/Builder4/MainWindow.vala index edf96b4e2..cf861239e 100644 --- a/src/Builder4/MainWindow.vala +++ b/src/Builder4/MainWindow.vala @@ -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(); }); -- 2.39.2