Skip to content

Commit

Permalink
Add inline toolbar to sidebar (#569)
Browse files Browse the repository at this point in the history
* Add inline toolbar to sidebar

* Remove Open Folder button from HeaderBar

Since it's redundant

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

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

* removed close folder icon/functionality in the inline toolbar

* Update src/Widgets/Pane.vala

Co-Authored-By: roymckenzie <1065321+roymckenzie@users.noreply.github.com>

* Update src/Widgets/Pane.vala

Co-Authored-By: roymckenzie <1065321+roymckenzie@users.noreply.github.com>

* Update src/Widgets/Pane.vala

Co-Authored-By: roymckenzie <1065321+roymckenzie@users.noreply.github.com>

* Update src/Widgets/Pane.vala

Co-Authored-By: roymckenzie <1065321+roymckenzie@users.noreply.github.com>

* Move headerbar open folder button to inline toolbar

* Fix lint errors

* Revert icon change

* Fix lint error (again)
  • Loading branch information
cassidyjames authored and Jeremy Wootten committed Nov 25, 2019
1 parent 7335650 commit 88f39f7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
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-open-symbolic", 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);
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

0 comments on commit 88f39f7

Please sign in to comment.