Skip to content

Commit bdc4e53

Browse files
committed
Reorder folders on add folder if option true
1 parent f67a756 commit bdc4e53

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/FolderManager/FileView.vala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
6363
public ActionGroup toplevel_action_group { get; private set; }
6464
public string icon_name { get; set; }
6565
public string title { get; set; }
66+
public bool order_folders { get; set; default = true; }
6667

6768
public FileView (Scratch.Services.PluginsManager plugins_manager) {
6869
plugins = plugins_manager;
@@ -85,6 +86,12 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
8586
toplevel_action_group = get_action_group (MainWindow.ACTION_GROUP);
8687
assert_nonnull (toplevel_action_group);
8788
});
89+
90+
notify["order-folders"].connect (() => {
91+
if (order_folders) {
92+
reorder_folders ();
93+
}
94+
});
8895
}
8996

9097
private void action_close_folder (SimpleAction action, GLib.Variant? parameter) {
@@ -168,9 +175,9 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
168175
}
169176
}
170177

171-
public void order_folders () {
178+
private void reorder_folders () {
179+
// This is not efficient but SourceList does not currently allow `insert_sorted` or setting a sort function
172180
var list = new Gee.ArrayList<ProjectFolderItem> ();
173-
174181
foreach (var child in root.children) {
175182
root.remove (child as ProjectFolderItem);
176183
list.add (child as ProjectFolderItem);
@@ -567,8 +574,12 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
567574
// Process any closed signals emitted before proceeding
568575
Idle.add (() => {
569576
var folder_root = new ProjectFolderItem (folder, this); // Constructor adds project to GitManager
570-
this.root.add (folder_root);
577+
this.root.add (folder_root); // TODO Implement add_sorted;
571578
rename_items_with_same_name (folder_root);
579+
if (order_folders) {
580+
reorder_folders ();
581+
}
582+
572583

573584
folder_root.expanded = expand;
574585
folder_root.closed.connect (() => {

src/MainWindow.vala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace Scratch {
141141
{ ACTION_OPEN_FOLDER, action_open_folder, "s" },
142142
{ ACTION_OPEN_PROJECT, action_open_project },
143143
{ ACTION_COLLAPSE_ALL_FOLDERS, action_collapse_all_folders },
144-
{ ACTION_ORDER_FOLDERS, action_order_folders },
144+
{ ACTION_ORDER_FOLDERS, action_order_folders, null, "true" },
145145
{ ACTION_PREFERENCES, action_preferences },
146146
{ ACTION_REVERT, action_revert },
147147
{ ACTION_SAVE, action_save },
@@ -347,6 +347,10 @@ namespace Scratch {
347347
sidebar_action.set_state (saved_state.get_boolean ("sidebar-visible"));
348348
update_toolbar_button (ACTION_TOGGLE_SIDEBAR, saved_state.get_boolean ("sidebar-visible"));
349349

350+
// var order_folders_action = Utils.action_from_group (ACTION_ORDER_FOLDERS, actions);
351+
// order_folders_action.set_state (saved_state.get_boolean ("order-folders"));
352+
// update_toolbar_button (ACTION_ORDER_FOLDERS, saved_state.get_boolean ("order-folders"));
353+
350354
var outline_action = Utils.action_from_group (ACTION_TOGGLE_OUTLINE, actions);
351355
outline_action.set_state (saved_state.get_boolean ("outline-visible"));
352356
update_toolbar_button (ACTION_TOGGLE_OUTLINE, saved_state.get_boolean ("outline-visible"));
@@ -1126,7 +1130,10 @@ namespace Scratch {
11261130
}
11271131

11281132
private void action_order_folders () {
1129-
folder_manager_view.order_folders ();
1133+
var action = Utils.action_from_group (ACTION_ORDER_FOLDERS, actions);
1134+
var to_show = !action.get_state ().get_boolean ();
1135+
action.set_state (to_show);
1136+
folder_manager_view.order_folders = to_show;
11301137
}
11311138

11321139
private void action_save () {

0 commit comments

Comments
 (0)