From f5e629de4995ce47390631b15f4cc01cad68c11c Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 6 Feb 2026 11:24:37 +0000 Subject: [PATCH 1/5] Add "order-folders" setting --- data/io.elementary.code.gschema.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index 185986686..0cfce65a0 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -58,6 +58,11 @@ Terminal visibility Whether or not the terminal pane is visible + + true + Sort open projects + Keep the open projects in alphabetical order + '' Last opened path From 19d13052226aa5bf6ef34a55a67a74a92617a417 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 6 Feb 2026 11:53:29 +0000 Subject: [PATCH 2/5] Create sort_action from setting and use in menuitem --- src/Widgets/Sidebar.vala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index 2f95327ea..188a45c9f 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -22,6 +22,8 @@ public class Code.Sidebar : Gtk.Grid { URI_LIST } + public const string SIDEBAR_ACTION_GROUP = "sidebar"; + public const string SIDEBAR_ACTION_PREFIX = SIDEBAR_ACTION_GROUP + "."; public Gtk.Stack stack { get; private set; } public Code.ChooseProjectButton choose_project_button { get; private set; } public Hdy.HeaderBar headerbar { get; private set; } @@ -80,8 +82,15 @@ public class Code.Sidebar : Gtk.Grid { var collapse_all_menu_item = new GLib.MenuItem (_("Collapse All"), Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_COLLAPSE_ALL_FOLDERS); - var order_projects_menu_item = new GLib.MenuItem (_("Alphabetize"), Scratch.MainWindow.ACTION_PREFIX - + Scratch.MainWindow.ACTION_ORDER_FOLDERS); + var action_group = new SimpleActionGroup (); + var sort_action = (SimpleAction) Scratch.saved_state.create_action ("order-folders"); + action_group.add_action (sort_action); + insert_action_group (SIDEBAR_ACTION_GROUP, action_group); + + var order_projects_menu_item = new GLib.MenuItem ( + _("Keep Sorted"), + SIDEBAR_ACTION_PREFIX + sort_action.name + ); var project_menu = new GLib.Menu (); project_menu.append_item (collapse_all_menu_item); From 111f7eb539d8560bfecdbe834d29f278eb51ff8a Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 6 Feb 2026 12:11:29 +0000 Subject: [PATCH 3/5] (Re-)order folders when settings change and when folder added --- src/FolderManager/FileView.vala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 31c858e96..1c1fa7276 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -83,6 +83,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane toplevel_action_group = get_action_group (MainWindow.ACTION_GROUP); assert_nonnull (toplevel_action_group); }); + + Scratch.saved_state.changed["order-folders"].connect (() => { + order_folders (); + }); } private void action_close_folder (SimpleAction action, GLib.Variant? parameter) { @@ -158,6 +162,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane } public void order_folders () { + if (!Scratch.saved_state.get_boolean ("order-folders")) { + return; + } + var list = new Gee.ArrayList (); foreach (var child in root.children) { @@ -587,6 +595,8 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane }); yield; + + order_folders (); } private bool is_open (File folder) { From 205f48a56a833bfae09054ef9ba18e63340757b6 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 6 Feb 2026 12:11:40 +0000 Subject: [PATCH 4/5] Lose unused --- src/MainWindow.vala | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3a4d3260b..1e09bc066 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -78,7 +78,6 @@ namespace Scratch { public const string ACTION_OPEN_FOLDER = "action-open-folder"; public const string ACTION_OPEN_PROJECT = "action-open-project"; public const string ACTION_COLLAPSE_ALL_FOLDERS = "action-collapse-all-folders"; - public const string ACTION_ORDER_FOLDERS = "action-order-folders"; public const string ACTION_GO_TO = "action-go-to"; public const string ACTION_SORT_LINES = "action-sort-lines"; public const string ACTION_NEW_TAB = "action-new-tab"; @@ -142,7 +141,6 @@ namespace Scratch { { ACTION_OPEN_FOLDER, action_open_folder, "s" }, { ACTION_OPEN_PROJECT, action_open_project }, { ACTION_COLLAPSE_ALL_FOLDERS, action_collapse_all_folders }, - { ACTION_ORDER_FOLDERS, action_order_folders }, { ACTION_PREFERENCES, action_preferences }, { ACTION_REVERT, action_revert }, { ACTION_SAVE, action_save }, @@ -1121,10 +1119,6 @@ namespace Scratch { folder_manager_view.collapse_all (); } - private void action_order_folders () { - folder_manager_view.order_folders (); - } - private void action_save () { var doc = get_current_document (); /* may return null */ if (doc != null) { From acc90dd25ce3d0c47b63846586bc2d78866ab7cc Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 6 Feb 2026 12:11:53 +0000 Subject: [PATCH 5/5] Revert invalid cast --- src/Widgets/Sidebar.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index 188a45c9f..0b6a7ef47 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -83,7 +83,7 @@ public class Code.Sidebar : Gtk.Grid { + Scratch.MainWindow.ACTION_COLLAPSE_ALL_FOLDERS); var action_group = new SimpleActionGroup (); - var sort_action = (SimpleAction) Scratch.saved_state.create_action ("order-folders"); + var sort_action = Scratch.saved_state.create_action ("order-folders"); action_group.add_action (sort_action); insert_action_group (SIDEBAR_ACTION_GROUP, action_group);