Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/io.elementary.code.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<summary>Terminal visibility</summary>
<description>Whether or not the terminal pane is visible</description>
</key>
<key name="order-folders" type="b">
<default>true</default>
<summary>Sort open projects</summary>
<description>Keep the open projects in alphabetical order</description>
</key>
<key name="last-opened-path" type="s">
<default>''</default>
<summary>Last opened path</summary>
Expand Down
10 changes: 10 additions & 0 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<ProjectFolderItem> ();

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

yield;

order_folders ();
}

private bool is_open (File folder) {
Expand Down
6 changes: 0 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions src/Widgets/Sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 = 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);
Expand Down
Loading