Skip to content
Open
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
53 changes: 37 additions & 16 deletions src/Widgets/AppContextMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions src/Widgets/MenuIcon.vala
Original file line number Diff line number Diff line change
@@ -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 <torik.habib@gamail.com>
*
*/

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;
});
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down