diff --git a/data/icons/git-symbolic.svg b/data/icons/git-symbolic.svg new file mode 100644 index 0000000000..8d3a0dbd30 --- /dev/null +++ b/data/icons/git-symbolic.svg @@ -0,0 +1,4 @@ + +image/svg+xml + + diff --git a/data/io.elementary.code.gresource.xml b/data/io.elementary.code.gresource.xml index 2149e3b022..4f1e7c8c50 100644 --- a/data/io.elementary.code.gresource.xml +++ b/data/io.elementary.code.gresource.xml @@ -2,7 +2,6 @@ Application.css - icons/48/git.svg icons/SymbolOutline/abstractclass.svg icons/SymbolOutline/abstractmethod.svg icons/SymbolOutline/abstractproperty.svg @@ -30,8 +29,10 @@ icons/panel-right-symbolic.svg + icons/48/git.svg icons/48/open-project.svg icons/filter-symbolic.svg + icons/git-symbolic.svg icons/emblem-git-modified-symbolic.svg icons/emblem-git-new-symbolic.svg diff --git a/src/Utils.vala b/src/Utils.vala index 46b83a56b0..54f9c20a40 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -337,15 +337,4 @@ namespace Scratch.Utils { warning ("Accelerators were not found for the action: %s", detailed_action_name); return ""; } - - public Gtk.Button make_button_with_icon_and_label (string icon_name, string text) { - var box = new Gtk.Box (HORIZONTAL, 3); - var image = new Gtk.Image.from_icon_name (icon_name, BUTTON); - var label = new Gtk.Label (text); - box.add (image); - box.add (label); - return new Gtk.Button () { - child = box - }; - } } diff --git a/src/Widgets/ChooseProjectButton.vala b/src/Widgets/ChooseProjectButton.vala index 90fba92596..877f54925b 100644 --- a/src/Widgets/ChooseProjectButton.vala +++ b/src/Widgets/ChooseProjectButton.vala @@ -71,9 +71,23 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { project_scrolled.add (project_listbox); + var add_folder_button = new PopoverMenuItem (_("Open Folder…")) { + action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_OPEN_FOLDER, + action_target = new Variant.string (""), + icon_name = "folder-open-symbolic" + }; + + var clone_button = new PopoverMenuItem (_("Clone Git Repository…")) { + action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_CLONE_REPO, + icon_name = "git-symbolic" + }; + var popover_content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); popover_content.add (project_filter); popover_content.add (project_scrolled); + popover_content.add (new Gtk.Separator (HORIZONTAL)); + popover_content.add (add_folder_button); + popover_content.add (clone_button); popover_content.show_all (); diff --git a/src/Widgets/PopoverMenuItem.vala b/src/Widgets/PopoverMenuItem.vala new file mode 100644 index 0000000000..72461986fc --- /dev/null +++ b/src/Widgets/PopoverMenuItem.vala @@ -0,0 +1,48 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* SPDX-FileCopyrightText: 2017-2023 elementary, Inc. (https://elementary.io) +*/ + +public class Code.PopoverMenuItem : Gtk.Button { + /** + * The label for the button + */ + public string text { get; construct; } + + /** + * The icon name for the button + */ + public string icon_name { get; set; } + + public PopoverMenuItem (string text) { + Object (text: text); + } + + class construct { + set_css_name ("modelbutton"); + } + + construct { + var image = new Gtk.Image (); + + var label = new Granite.AccelLabel (text); + + var box = new Gtk.Box (HORIZONTAL, 6); + box.add (image); + box.add (label); + + child = box; + + get_accessible ().accessible_role = MENU_ITEM; + + clicked.connect (() => { + var popover = (Gtk.Popover) get_ancestor (typeof (Gtk.Popover)); + if (popover != null) { + popover.popdown (); + } + }); + + bind_property ("action-name", label, "action-name"); + bind_property ("icon-name", image, "icon-name"); + } +} diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index 9409094601..0656c33d0c 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -56,13 +56,6 @@ public class Code.Sidebar : Gtk.Grid { var actionbar = new Gtk.ActionBar (); actionbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR); - var add_folder_button = Scratch.Utils.make_button_with_icon_and_label ("folder-open-symbolic", _("Open…")); - add_folder_button.action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_OPEN_FOLDER; - add_folder_button.action_target = new Variant.string (""); - - var clone_button = Scratch.Utils.make_button_with_icon_and_label ("folder-download-symbolic", _("Clone…")); - clone_button.action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_CLONE_REPO; - var collapse_all_menu_item = new GLib.MenuItem (_("Collapse All"), Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_COLLAPSE_ALL_FOLDERS); @@ -74,23 +67,15 @@ public class Code.Sidebar : Gtk.Grid { project_menu.append_item (order_projects_menu_item); project_menu_model = project_menu; - var project_more_button = new Gtk.MenuButton (); - project_more_button.image = new Gtk.Image.from_icon_name ("view-more-symbolic", Gtk.IconSize.SMALL_TOOLBAR); - project_more_button.use_popover = false; - project_more_button.menu_model = project_menu_model; - project_more_button.tooltip_text = _("Manage project folders"); - - var tool_flowbox = new Gtk.FlowBox () { - orientation = HORIZONTAL, + var project_more_button = new Gtk.MenuButton () { hexpand = true, - selection_mode = NONE, - column_spacing = 0, - max_children_per_line = 2 + use_popover = false, + menu_model = project_menu_model, + label = _("Manage project folders…"), + xalign = 0.0f }; - tool_flowbox.add (add_folder_button); - tool_flowbox.add (clone_button); - actionbar.add (tool_flowbox); - actionbar.pack_end (project_more_button); + + actionbar.pack_start (project_more_button); add (headerbar); add (stack_switcher); diff --git a/src/meson.build b/src/meson.build index ec53d58bfc..b5a5aca596 100644 --- a/src/meson.build +++ b/src/meson.build @@ -50,6 +50,7 @@ code_files = files( 'Widgets/HeaderBar.vala', 'Widgets/Sidebar.vala', 'Widgets/PaneSwitcher.vala', + 'Widgets/PopoverMenuItem.vala', 'Widgets/SearchBar.vala', 'Widgets/SourceList/CellRendererBadge.vala', 'Widgets/SourceList/CellRendererExpander.vala',