diff --git a/src/Widgets/AppContextMenu.vala b/src/Widgets/AppContextMenu.vala index f96bc0676..93efe4e78 100644 --- a/src/Widgets/AppContextMenu.vala +++ b/src/Widgets/AppContextMenu.vala @@ -18,6 +18,9 @@ public class Slingshot.AppContextMenu : Gtk.Menu { public signal void app_launched (); + private const string DESKTOP_ACTION_KEY = "Actions"; + private const string DESKTOP_ACTION_GROUP_NAME = "Desktop Action %s"; + public string desktop_id { get; construct; } public string desktop_path { get; construct; } private DesktopAppInfo app_info; @@ -54,15 +57,29 @@ public class Slingshot.AppContextMenu : Gtk.Menu { construct { app_info = new DesktopAppInfo (desktop_id); - foreach (unowned string _action in app_info.list_actions ()) { - string action = _action.dup (); - var menuitem = new Gtk.MenuItem.with_mnemonic (app_info.get_action_name (action)); - add (menuitem); - - menuitem.activate.connect (() => { - app_info.launch_action (action, new AppLaunchContext ()); - app_launched (); - }); + try { + var file = new KeyFile (); + file.load_from_file (app_info.get_filename (), 0); + if (file.has_key (KeyFileDesktop.GROUP, DESKTOP_ACTION_KEY)) { + foreach (unowned string g_action in file.get_string_list (KeyFileDesktop.GROUP, DESKTOP_ACTION_KEY)) { + var action = g_action.dup (); + var group = DESKTOP_ACTION_GROUP_NAME.printf (action); + + var menuitem = new MenuIcon () { + menu_label = file.get_locale_string (group, KeyFileDesktop.KEY_NAME) + }; + if (file.has_key (group, KeyFileDesktop.KEY_ICON)) { + menuitem.menu_image = file.get_locale_string (group, KeyFileDesktop.KEY_ICON); + } + add (menuitem); + menuitem.activate.connect (() => { + app_info.launch_action (action, new AppLaunchContext ()); + app_launched (); + }); + } + } + } catch (Error e) { + critical ("%s", e.message); } #if HAS_PLANK @@ -73,14 +90,14 @@ public class Slingshot.AppContextMenu : Gtk.Menu { has_system_item = true; - var plank_menuitem = new Gtk.MenuItem (); - plank_menuitem.use_underline = true; - + var plank_menuitem = new MenuIcon () { + menu_image = "plank" + }; docked = (desktop_uri in plank_client.get_persistent_applications ()); if (docked) { - plank_menuitem.label = _("Remove from _Dock"); + plank_menuitem.menu_label = _("Remove from Dock"); } else { - plank_menuitem.label = _("Add to _Dock"); + plank_menuitem.menu_label = _("Add to Dock"); } plank_menuitem.activate.connect (plank_menuitem_activate); @@ -94,12 +111,16 @@ public class Slingshot.AppContextMenu : Gtk.Menu { add (new Gtk.SeparatorMenuItem ()); } - uninstall_menuitem = new Gtk.MenuItem.with_label (_("Uninstall")) { + uninstall_menuitem = new MenuIcon () { + menu_label = _("Uninstall"), + menu_image = "edit-delete", sensitive = false }; uninstall_menuitem.activate.connect (uninstall_menuitem_activate); - appcenter_menuitem = new Gtk.MenuItem.with_label (_("View in AppCenter")) { + appcenter_menuitem = new MenuIcon () { + menu_label = _("View in AppCenter"), + menu_image = "io.elementary.appcenter", sensitive = false }; appcenter_menuitem.activate.connect (open_in_appcenter); diff --git a/src/Widgets/MenuIcon.vala b/src/Widgets/MenuIcon.vala new file mode 100644 index 000000000..813e1e5fe --- /dev/null +++ b/src/Widgets/MenuIcon.vala @@ -0,0 +1,47 @@ +/* + * Copyright 2021 elementary, Inc. (https://elementary.io) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Torikulhabib + * + */ + +private class MenuIcon : Gtk.MenuItem { + public string menu_image { get; set; } + public string menu_label { get; set; } + + construct { + var label = new Gtk.Label (null) { + xalign = 0 + }; + + var image_menu = new Gtk.Image (); + + var grid = new Gtk.Grid (); + grid.add (image_menu); + grid.add (label); + add (grid); + + notify["menu-image"].connect (()=>{ + image_menu.set_from_gicon (new ThemedIcon (menu_image), Gtk.IconSize.BUTTON); + }); + + notify["menu-label"].connect (()=>{ + label.label = menu_label; + }); + } +} diff --git a/src/meson.build b/src/meson.build index 9459c4f4f..bf6b2d8ad 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,6 +28,7 @@ sources = [ 'Widgets/Switcher.vala', 'Widgets/SearchItem.vala', 'Widgets/PageChecker.vala', + 'Widgets/MenuIcon.vala', 'synapse-core/Actions/TerminalRunnerAction.vala', 'synapse-core/Actions/RunnerAction.vala',