Skip to content

Commit 13c8bd6

Browse files
authored
Option to keep folders sorted (#1687)
* Add "order-folders" setting * Create sort_action from setting and use in menuitem * (Re-)order folders when settings change and when folder added * Lose unused * Revert invalid cast
1 parent 705d7e6 commit 13c8bd6

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

data/io.elementary.code.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
<summary>Terminal visibility</summary>
5959
<description>Whether or not the terminal pane is visible</description>
6060
</key>
61+
<key name="order-folders" type="b">
62+
<default>true</default>
63+
<summary>Sort open projects</summary>
64+
<description>Keep the open projects in alphabetical order</description>
65+
</key>
6166
<key name="last-opened-path" type="s">
6267
<default>''</default>
6368
<summary>Last opened path</summary>

src/FolderManager/FileView.vala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
8383
toplevel_action_group = get_action_group (MainWindow.ACTION_GROUP);
8484
assert_nonnull (toplevel_action_group);
8585
});
86+
87+
Scratch.saved_state.changed["order-folders"].connect (() => {
88+
order_folders ();
89+
});
8690
}
8791

8892
private void action_close_folder (SimpleAction action, GLib.Variant? parameter) {
@@ -158,6 +162,10 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
158162
}
159163

160164
public void order_folders () {
165+
if (!Scratch.saved_state.get_boolean ("order-folders")) {
166+
return;
167+
}
168+
161169
var list = new Gee.ArrayList<ProjectFolderItem> ();
162170

163171
foreach (var child in root.children) {
@@ -587,6 +595,8 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
587595
});
588596

589597
yield;
598+
599+
order_folders ();
590600
}
591601

592602
private bool is_open (File folder) {

src/MainWindow.vala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ namespace Scratch {
7878
public const string ACTION_OPEN_FOLDER = "action-open-folder";
7979
public const string ACTION_OPEN_PROJECT = "action-open-project";
8080
public const string ACTION_COLLAPSE_ALL_FOLDERS = "action-collapse-all-folders";
81-
public const string ACTION_ORDER_FOLDERS = "action-order-folders";
8281
public const string ACTION_GO_TO = "action-go-to";
8382
public const string ACTION_SORT_LINES = "action-sort-lines";
8483
public const string ACTION_NEW_TAB = "action-new-tab";
@@ -142,7 +141,6 @@ namespace Scratch {
142141
{ ACTION_OPEN_FOLDER, action_open_folder, "s" },
143142
{ ACTION_OPEN_PROJECT, action_open_project },
144143
{ ACTION_COLLAPSE_ALL_FOLDERS, action_collapse_all_folders },
145-
{ ACTION_ORDER_FOLDERS, action_order_folders },
146144
{ ACTION_PREFERENCES, action_preferences },
147145
{ ACTION_REVERT, action_revert },
148146
{ ACTION_SAVE, action_save },
@@ -1121,10 +1119,6 @@ namespace Scratch {
11211119
folder_manager_view.collapse_all ();
11221120
}
11231121

1124-
private void action_order_folders () {
1125-
folder_manager_view.order_folders ();
1126-
}
1127-
11281122
private void action_save () {
11291123
var doc = get_current_document (); /* may return null */
11301124
if (doc != null) {

src/Widgets/Sidebar.vala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Code.Sidebar : Gtk.Grid {
2222
URI_LIST
2323
}
2424

25+
public const string SIDEBAR_ACTION_GROUP = "sidebar";
26+
public const string SIDEBAR_ACTION_PREFIX = SIDEBAR_ACTION_GROUP + ".";
2527
public Gtk.Stack stack { get; private set; }
2628
public Code.ChooseProjectButton choose_project_button { get; private set; }
2729
public Hdy.HeaderBar headerbar { get; private set; }
@@ -80,8 +82,15 @@ public class Code.Sidebar : Gtk.Grid {
8082
var collapse_all_menu_item = new GLib.MenuItem (_("Collapse All"), Scratch.MainWindow.ACTION_PREFIX
8183
+ Scratch.MainWindow.ACTION_COLLAPSE_ALL_FOLDERS);
8284

83-
var order_projects_menu_item = new GLib.MenuItem (_("Alphabetize"), Scratch.MainWindow.ACTION_PREFIX
84-
+ Scratch.MainWindow.ACTION_ORDER_FOLDERS);
85+
var action_group = new SimpleActionGroup ();
86+
var sort_action = Scratch.saved_state.create_action ("order-folders");
87+
action_group.add_action (sort_action);
88+
insert_action_group (SIDEBAR_ACTION_GROUP, action_group);
89+
90+
var order_projects_menu_item = new GLib.MenuItem (
91+
_("Keep Sorted"),
92+
SIDEBAR_ACTION_PREFIX + sort_action.name
93+
);
8594

8695
var project_menu = new GLib.Menu ();
8796
project_menu.append_item (collapse_all_menu_item);

0 commit comments

Comments
 (0)