Skip to content

Commit f13caea

Browse files
committed
nemo-action.c: Support icons provided by Spices.
1 parent ad44137 commit f13caea

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

action-layout-editor/nemo_action_layout_editor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ def get_icon_type_and_data(self, original=False):
8080
if icon_string is None:
8181
return None
8282

83-
if icon_string.startswith("/"):
83+
if icon_string.startswith("<") and icon_string.endswith(">"):
84+
real_string = icon_string[1:-1]
85+
icon_string = str(self.path.parent / real_string)
86+
87+
if GLib.path_is_absolute(icon_string):
8488
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_string, 16, 16)
8589
surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, self.scale_factor, None)
8690
return ("surface", surface)

files/usr/share/nemo/action-info.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ Displays the action if all selected files have a mimetype included in this semic
106106
Comment=If you click this menu entry, %F will be acted upon!
107107
`
108108

109-
**Icon-Name** (optional): The name of the icon to display in Nemo's context menu next to the action entry. This must be an icon that is part of the GtkIconTheme. Symbolic icons are supported.
109+
**Icon-Name** (optional): The name of the icon to display in Nemo's context menu next to the action entry. This must be an icon that is part of the GtkIconTheme, or an absolute path. Symbolic icons are supported.
110110

111111
`
112112
Icon-Name=folder
113113
`
114114

115+
If you have a custom icon, you can enclose the filename in `<...>` to have it loaded from the action's directory. For instance, with `<my-action-icon.png>` nemo will look for an icon by that name in the same directory as the action file. If your action is a Spice and has its own subfolder, that can be included as a relative path (`my-action@me/my-action-icon.png`).
116+
115117
**Separator** (optional): Character(s) to separate multiple filenames if more than a single file is selected. By default a space is used.
116118

117119
`

libnemo-private/nemo-action.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,17 +670,34 @@ nemo_action_constructed (GObject *object)
670670
gicon = NULL;
671671

672672
if (icon_name != NULL) {
673-
if (g_path_is_absolute (icon_name)) {
674-
GFile *icon_file = g_file_new_for_path (icon_name);
673+
gboolean prepend_action_dir = FALSE;
674+
gchar *real_icon_name;
675+
676+
strip_custom_modifier (icon_name, &prepend_action_dir, &real_icon_name);
677+
678+
if (prepend_action_dir) {
679+
gchar *action_dir = g_path_get_dirname (action->key_file_path);
680+
gchar *icon_path = g_build_filename (action_dir, real_icon_name, NULL);
681+
682+
g_free (action_dir);
683+
g_free (real_icon_name);
684+
685+
real_icon_name = icon_path;
686+
}
687+
688+
if (g_path_is_absolute (real_icon_name)) {
689+
GFile *icon_file = g_file_new_for_path (real_icon_name);
675690
if (g_file_is_native (icon_file)) {
676691
gicon = g_file_icon_new (icon_file);
677692
}
678693
g_object_unref (icon_file);
679694
}
680695

681696
if (gicon == NULL) {
682-
gicon = g_themed_icon_new (icon_name);
697+
gicon = g_themed_icon_new (real_icon_name);
683698
}
699+
700+
g_free (real_icon_name);
684701
}
685702
g_free (icon_name);
686703

0 commit comments

Comments
 (0)