Skip to content

Commit 3845f20

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 3845f20

3 files changed

Lines changed: 31 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. (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). (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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ 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. (6.8)
98+
# "sidebar-only" only show this action in the places sidebar context menu, not
99+
# in normal file views. (6.8)
96100

97101
#Conditions=desktop;
98102

libnemo-private/nemo-action.c

Lines changed: 24 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,9 @@ nemo_action_constructed (GObject *object)
871883

872884
TokenType token_type;
873885

886+
priv->sidebar_allow = sidebar_allow;
887+
priv->sidebar_only = sidebar_only;
888+
874889
priv->show_in_blank_desktop = is_desktop &&
875890
type == SELECTION_NONE &&
876891
find_token_type (exec, &token_type) == NULL;
@@ -1865,6 +1880,15 @@ get_visibility (NemoAction *action,
18651880
GtkWindow *window)
18661881
{
18671882
NemoActionPrivate *priv = nemo_action_get_instance_private (action);
1883+
1884+
if (for_places) {
1885+
if (!priv->sidebar_allow && !priv->sidebar_only)
1886+
return FALSE;
1887+
} else {
1888+
if (priv->sidebar_only)
1889+
return FALSE;
1890+
}
1891+
18681892
// Check DBUS
18691893
if (!priv->dbus_satisfied)
18701894
return FALSE;

0 commit comments

Comments
 (0)