Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User can see close focused project folder, alphabetize folders, and collapse folders. #657

23 changes: 23 additions & 0 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ namespace Scratch.FolderManager {
write_settings ();
}

public void collapse_all () {
foreach (var child in root.children) {
(child as ProjectFolderItem).collapse_all ();
}
}

public void order_folders () {
var list = new Gee.ArrayList<ProjectFolderItem> ();

foreach (var child in root.children) {
root.remove (child as ProjectFolderItem);
list.add (child as ProjectFolderItem);
}

list.sort ( (a, b) => {
return a.name.down () > b.name.down () ? 0 : -1;
});

foreach (var item in list) {
root.add (item);
}
}

public void select_path (string path) {
selected = find_path (root, path);
}
Expand Down
12 changes: 12 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace Scratch {
public const string ACTION_FIND_PREVIOUS = "action_find_previous";
public const string ACTION_OPEN = "action_open";
public const string ACTION_OPEN_FOLDER = "action_open_folder";
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_NEW_VIEW = "action_new_view";
public const string ACTION_SORT_LINES = "action_sort_lines";
Expand Down Expand Up @@ -97,6 +99,8 @@ namespace Scratch {
{ ACTION_FIND_PREVIOUS, action_find_previous },
{ ACTION_OPEN, action_open },
{ ACTION_OPEN_FOLDER, action_open_folder },
{ 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 @@ -815,6 +819,14 @@ namespace Scratch {
chooser.destroy ();
}

private void action_collapse_all_folders () {
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
5 changes: 0 additions & 5 deletions src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ namespace Scratch.Widgets {
_("Open a file")
);

var open_folder_button = new Gtk.Button.from_icon_name ("folder-saved-search", Gtk.IconSize.LARGE_TOOLBAR);
open_folder_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_OPEN_FOLDER;
open_folder_button.tooltip_text = _("Open a folder");

templates_button = new Gtk.Button.from_icon_name ("text-x-generic-template", Gtk.IconSize.LARGE_TOOLBAR);
templates_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_TEMPLATES;
templates_button.tooltip_text = _("Project templates");
Expand Down Expand Up @@ -188,7 +184,6 @@ namespace Scratch.Widgets {
set_custom_title (format_bar);

pack_start (open_button);
pack_start (open_folder_button);
pack_start (templates_button);
pack_start (save_button);
pack_start (save_as_button);
Expand Down
36 changes: 36 additions & 0 deletions src/Widgets/Pane.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,50 @@ public class Code.Pane : Gtk.Grid {
no_show_all = true;

get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR);

stack = new Gtk.Stack ();
stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;

stack_switcher = new Gtk.StackSwitcher ();
stack_switcher.no_show_all = true;
stack_switcher.visible = false;
stack_switcher.stack = stack;
stack_switcher.homogeneous = true;

var toolbar = new Gtk.Toolbar ();
toolbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR);
toolbar.icon_size = Gtk.IconSize.SMALL_TOOLBAR;

var add_folder_button = new Gtk.ToolButton (new Gtk.Image.from_icon_name ("folder-saved-search", Gtk.IconSize.BUTTON), null);
add_folder_button.action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_OPEN_FOLDER;
add_folder_button.tooltip_text = _("Add Project Folder…");

var project_more_button = new Gtk.MenuToolButton (null, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a "open-menu" symbolic icon rather than the default down arrow which I associate with downloading or a combobox. A "hamburger" type icon would be nice but I am not sure that one is available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just using the default icon which I believe is used in other similar "dropdown" contexts, but I'd be fine to change to something else. I wanted to avoid using a settings-type icon because this is not necessarily settings, it's actions. view-more-symbolic might work. Thoughts from @elementary/ux?

project_more_button.tooltip_text = _("Manage project folders…");

var collapse_all_menu_item = new Gtk.MenuItem.with_label (_("Collapse All"));
collapse_all_menu_item.action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_COLLAPSE_ALL_FOLDERS;

var order_projects_menu_item = new Gtk.MenuItem.with_label (_("Alphabetize"));
order_projects_menu_item.action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_ORDER_FOLDERS;

var project_menu = new Gtk.Menu ();
project_menu.append (collapse_all_menu_item);
project_menu.append (order_projects_menu_item);
project_menu.show_all ();
project_more_button.set_menu (project_menu);

var separator_tool_item = new Gtk.SeparatorToolItem ();
separator_tool_item.set_expand (true);
separator_tool_item.draw = false;

toolbar.add (add_folder_button);
toolbar.add (separator_tool_item);
toolbar.add (project_more_button);

add (stack_switcher);
add (stack);
add (toolbar);

stack.add.connect (() => {
if (stack.get_children ().length () > 1) {
Expand Down Expand Up @@ -64,6 +99,7 @@ public class Code.Pane : Gtk.Grid {
stack.add (tab);
stack.child_set_property (tab, "title", tab.title);
stack.child_set_property (tab, "icon-name", tab.icon_name);

tab.notify["title"].connect (() => {
stack.child_set_property (tab, "title", tab.title);
});
Expand Down