Skip to content

Commit bf73732

Browse files
committed
actions: Don't show in the places-sidebar menu, unless Conditions
allow it. By default, actions will no longer appear in context menus for places-sidebar entries. To opt back in to sidebar visibility, two new Conditions are added: - sidebar-allow: Display in the sidebar, along with any other valid locations assuming all conditions are met (consider this 'legacy' behavior). - sidebar-only: The action will only be shown in the sidebar, provided other Conditions are met, and nowhere else. Use this for actions that only make sense when applied to sidebar items (bookmarks, mounts, etc...).
1 parent 4825be2 commit bf73732

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ Can be one or more of:
160160
- `gsettings <schema> <boolean key>`: The boolean key in the given schema must be true.
161161
- `gsettings <schema> <key> <key-type> <[eq|ne|gt|lt]> <value>`: The value of `<key>` is [`equal|not equal|greater than|less than`] `<value>`. The `<key-types>` must match, but the comparisons are not clearly defined for non-numerical types.
162162
- `exec <program>`: Run `<program>` (absolute path or PATH executable) and interpret its exit code as 0 for passing, and non-0 for failure.
163+
- `sidebar-allow`: Also show this action in the places sidebar's context menu. By default, actions are hidden from the sidebar. Cannot be used with `sidebar-only`. (6.8)
164+
- `sidebar-only`: Only show this action in the places sidebar's context menu, never in normal file views. Useful with actions that only make sense against sidebar entries (bookmarks, mounts, etc). Cannot be used with `sidebar-allow` (6.8)
163165

164166
**Terminal** (optional): Set to true to execute the Exec line in a spawned terminal window.
165167

@@ -239,7 +241,7 @@ Separator=,
239241
Quote=single|double|backtick
240242
Dependencies=notify-send;!zenity;
241243
UriScheme=sftp
242-
Conditions=desktop;dbus <name>;gsettings foo_schema foo_boolkey;removable;exec <program>;
244+
Conditions=desktop;dbus <name>;gsettings foo_schema foo_boolkey;removable;exec <program>;sidebar-allow;sidebar-only;
243245
Terminal=true|false
244246
Files=.bash*;!.bashrc;
245247
Locations=.*;!.config;

files/usr/share/nemo/actions/sample.nemo_action

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ Extensions=any;
9393
# "dbus <name>" exists
9494
# "exec <program>" run program and check its exit code (0 is pass, non-0 is fail).
9595
# Enclose in < > if the program resides in the action's folder.
96+
# "sidebar-allow" also show this action in the places sidebar context menu (by
97+
# default, actions are hidden from the sidebar). Cannot be used
98+
# with sidebar-only. (6.8)
99+
# "sidebar-only" only show this action in the places sidebar context menu, not
100+
# in normal file views. Cannot be used with sidebar-allow. (6.8)
96101

97102
#Conditions=desktop;
98103

libnemo-private/nemo-action.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ typedef struct {
5959
gboolean escape_underscores;
6060
gboolean escape_space;
6161
gboolean show_in_blank_desktop;
62+
gboolean sidebar_allow;
63+
gboolean sidebar_only;
6264
gboolean run_in_terminal;
6365
gchar *uri_scheme;
6466

@@ -831,6 +833,8 @@ nemo_action_constructed (GObject *object)
831833
g_strfreev (files);
832834

833835
gboolean is_desktop = FALSE;
836+
gboolean sidebar_allow = FALSE;
837+
gboolean sidebar_only = FALSE;
834838

835839
if (conditions && condition_count > 0) {
836840
guint j;
@@ -856,6 +860,14 @@ nemo_action_constructed (GObject *object)
856860
if (g_strcmp0 (condition, "removable") == 0) {
857861
/* this is handled in nemo_action_get_visibility() */
858862
}
863+
else
864+
if (g_strcmp0 (condition, "sidebar-allow") == 0) {
865+
sidebar_allow = TRUE;
866+
}
867+
else
868+
if (g_strcmp0 (condition, "sidebar-only") == 0) {
869+
sidebar_only = TRUE;
870+
}
859871
else {
860872
g_warning ("Ignoring invalid condition: %s."
861873
" See sample action at /usr/share/nemo/actions/sample.nemo_action", condition);
@@ -871,6 +883,16 @@ nemo_action_constructed (GObject *object)
871883

872884
TokenType token_type;
873885

886+
if (sidebar_allow && sidebar_only) {
887+
g_warning ("Action '%s' specifies both 'sidebar-allow' and 'sidebar-only' conditions;"
888+
" ignoring both.", action->key_file_path);
889+
sidebar_allow = FALSE;
890+
sidebar_only = FALSE;
891+
}
892+
893+
priv->sidebar_allow = sidebar_allow;
894+
priv->sidebar_only = sidebar_only;
895+
874896
priv->show_in_blank_desktop = is_desktop &&
875897
type == SELECTION_NONE &&
876898
find_token_type (exec, &token_type) == NULL;
@@ -1865,6 +1887,15 @@ get_visibility (NemoAction *action,
18651887
GtkWindow *window)
18661888
{
18671889
NemoActionPrivate *priv = nemo_action_get_instance_private (action);
1890+
1891+
if (for_places) {
1892+
if (!priv->sidebar_allow && !priv->sidebar_only)
1893+
return FALSE;
1894+
} else {
1895+
if (priv->sidebar_only)
1896+
return FALSE;
1897+
}
1898+
18681899
// Check DBUS
18691900
if (!priv->dbus_satisfied)
18701901
return FALSE;

0 commit comments

Comments
 (0)