Skip to content

Commit

Permalink
nemo actions: Implement reverse dependencies.
Browse files Browse the repository at this point in the history
This allows an action's visiblity to be conditional on a program
*not* being found.
  • Loading branch information
mtwebster committed Apr 2, 2021
1 parent d5e3a3b commit 7fe8363
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
5 changes: 4 additions & 1 deletion files/usr/share/nemo/actions/sample.nemo_action
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ Extensions=any;
# You can also supply an absolute path to a file (i.e. /usr/lib/gvfs/gvfsd-archive) to check
# instead of or in addition to an executable in the path.
# This is an array, separate entries with semi-colon, and terminate with a semicolon.
#Dependencies=gedit;
#
# v3.0: Reverse dependencies: Prefixing a program with '!' will reverse the logic - if
# the program exists, the check will FAIL.
#Dependencies=xed;!gedit;

# Conditions - semicolon-separated array of special conditions:
# "desktop" current (parent) folder is desktop
Expand Down
31 changes: 24 additions & 7 deletions libnemo-private/nemo-action.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,20 +925,37 @@ nemo_action_new (const gchar *name,
if (deps != NULL) {
guint i = 0;
for (i = 0; i < g_strv_length (deps); i++) {
if (g_path_is_absolute (deps[i])) {
if (!g_file_test (deps[i], G_FILE_TEST_EXISTS)) {
gboolean reverse, found;

reverse = g_str_has_prefix (deps[i], "!");
found = FALSE;

const gchar *prg_name = reverse ? deps[i] + 1 : deps[i];

if (g_path_is_absolute (prg_name)) {
if (g_file_test (prg_name, G_FILE_TEST_EXISTS)) {
found = TRUE;
}
} else {
gchar *p = g_find_program_in_path (prg_name);
if (p != NULL) {
found = TRUE;
g_free (p);
}
}

if (reverse) {
if (found) {
finish = FALSE;
DEBUG ("Missing action dependency: %s", deps[i]);
DEBUG ("Missing action reverse dependency: %s", deps[i]);
break;
}
} else {
gchar *p = g_find_program_in_path (deps[i]);
if (p == NULL) {
if (!found) {
finish = FALSE;
DEBUG ("Missing action dependency: %s", deps[i]);
g_free (p);
break;
}
g_free (p);
}
}
}
Expand Down

0 comments on commit 7fe8363

Please sign in to comment.