Skip to content

Commit 8580163

Browse files
committed
actions: Add UriScheme specifier in the action definition.
Condition visibility on whether or not a file's uri scheme matches the one given. For example: ... UriScheme=sftp ... sftp://[email protected]/ matches file:///home/joe/.bashrc does not
1 parent ad25353 commit 8580163

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,13 @@ EscapeSpaces=true
113113
# Optional - by default this is false
114114

115115
#Terminal=false
116+
117+
# Uri scheme - provide a uri scheme that the current location's scheme must match
118+
# For example:
119+
# ...
120+
# UriScheme=sftp
121+
# ...
122+
# sftp://[email protected]/ matches
123+
# file:///home/joe/.bashrc does not
124+
125+
#UriScheme=file

libnemo-private/nemo-action.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ enum
6767
PROP_QUOTE_TYPE,
6868
PROP_ESCAPE_SPACE,
6969
PROP_RUN_IN_TERMINAL,
70-
PROP_CONDITIONS
70+
PROP_CONDITIONS,
71+
PROP_URI_SCHEME,
72+
PROP_LAST
7173
};
7274

7375
enum {
@@ -141,6 +143,7 @@ nemo_action_init (NemoAction *action)
141143
action->escape_space = FALSE;
142144
action->show_in_blank_desktop = FALSE;
143145
action->run_in_terminal = FALSE;
146+
action->uri_scheme = NULL;
144147

145148
action->constructing = TRUE;
146149
}
@@ -277,6 +280,15 @@ nemo_action_class_init (NemoActionClass *klass)
277280
G_PARAM_READWRITE)
278281
);
279282

283+
g_object_class_install_property (object_class,
284+
PROP_URI_SCHEME,
285+
g_param_spec_string ("uri-scheme",
286+
"Limit selection by uri scheme (like file, sftp, etc...)",
287+
"Limit selection by uri scheme (like file, sftp, etc...)",
288+
NULL,
289+
G_PARAM_READWRITE)
290+
);
291+
280292
signals[CONDITION_CHANGED] = g_signal_new ("condition-changed",
281293
G_TYPE_FROM_CLASS (object_class),
282294
G_SIGNAL_RUN_LAST,
@@ -685,6 +697,11 @@ nemo_action_constructed (GObject *object)
685697
KEY_SEPARATOR,
686698
NULL);
687699

700+
gchar *uri_scheme = g_key_file_get_string (key_file,
701+
ACTION_FILE_GROUP,
702+
KEY_URI_SCHEME,
703+
NULL);
704+
688705
gchar *quote_type_string = g_key_file_get_string (key_file,
689706
ACTION_FILE_GROUP,
690707
KEY_QUOTE_TYPE,
@@ -829,6 +846,7 @@ nemo_action_constructed (GObject *object)
829846
"conditions", conditions,
830847
"escape-space", escape_space,
831848
"run-in-terminal", run_in_terminal,
849+
"uri-scheme", uri_scheme,
832850
NULL);
833851

834852
action->constructing = FALSE;
@@ -846,6 +864,7 @@ nemo_action_constructed (GObject *object)
846864
g_free (parent_dir);
847865
g_free (quote_type_string);
848866
g_free (separator);
867+
g_free (uri_scheme);
849868
g_strfreev (ext);
850869
g_strfreev (mimes);
851870
g_strfreev (conditions);
@@ -981,6 +1000,7 @@ nemo_action_finalize (GObject *object)
9811000
g_free (action->orig_label);
9821001
g_free (action->orig_tt);
9831002
g_free (action->separator);
1003+
g_free (action->uri_scheme);
9841004

9851005
if (action->dbus) {
9861006
g_list_free_full (action->dbus, (GDestroyNotify) dbus_condition_free);
@@ -1060,6 +1080,9 @@ nemo_action_set_property (GObject *object,
10601080
case PROP_RUN_IN_TERMINAL:
10611081
action->run_in_terminal = g_value_get_boolean (value);
10621082
break;
1083+
case PROP_URI_SCHEME:
1084+
action->uri_scheme = g_strdup (g_value_get_string (value));
1085+
break;
10631086
default:
10641087
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
10651088
break;
@@ -1120,6 +1143,9 @@ nemo_action_get_property (GObject *object,
11201143
case PROP_RUN_IN_TERMINAL:
11211144
g_value_set_boolean (value, action->run_in_terminal);
11221145
break;
1146+
case PROP_URI_SCHEME:
1147+
g_value_set_string (value, action->uri_scheme);
1148+
break;
11231149
default:
11241150
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
11251151
break;
@@ -1681,6 +1707,10 @@ nemo_action_get_visibility (NemoAction *action,
16811707
if (!action->gsettings_satisfied)
16821708
return FALSE;
16831709

1710+
if ((action->uri_scheme != NULL) && !nemo_file_has_uri_scheme (parent, action->uri_scheme)) {
1711+
return FALSE;
1712+
}
1713+
16841714
// Check selection
16851715
gboolean selection_type_show = FALSE;
16861716
guint selected_count = g_list_length (selection);

libnemo-private/nemo-action.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#define KEY_WHITESPACE "EscapeSpaces"
7676
#define KEY_DOUBLE_ESCAPE_QUOTES "DoubleEscapeQuotes"
7777
#define KEY_TERMINAL "Terminal"
78+
#define KEY_URI_SCHEME "UriScheme"
7879

7980
typedef struct _NemoAction NemoAction;
8081
typedef struct _NemoActionClass NemoActionClass;
@@ -132,6 +133,7 @@ struct _NemoAction {
132133
gboolean escape_space;
133134
gboolean show_in_blank_desktop;
134135
gboolean run_in_terminal;
136+
gchar *uri_scheme;
135137

136138
gboolean constructing;
137139
};

libnemo-private/nemo-file.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,22 @@ nemo_file_get_uri_scheme (NemoFile *file)
16771677
return scheme;
16781678
}
16791679

1680+
gboolean
1681+
nemo_file_has_uri_scheme (NemoFile *file,
1682+
const gchar *scheme)
1683+
{
1684+
gchar *file_uri_scheme;
1685+
gboolean has;
1686+
1687+
g_return_val_if_fail (NEMO_IS_FILE (file), FALSE);
1688+
1689+
file_uri_scheme = nemo_file_get_uri_scheme (file);
1690+
has = g_strcmp0 (scheme, file_uri_scheme) == 0;
1691+
g_free (file_uri_scheme);
1692+
1693+
return has;
1694+
}
1695+
16801696
NemoFileOperation *
16811697
nemo_file_operation_new (NemoFile *file,
16821698
NemoFileOperationCallback callback,

libnemo-private/nemo-file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ char * nemo_file_get_description (NemoFile *file);
196196
char * nemo_file_get_uri (NemoFile *file);
197197
char * nemo_file_get_path (NemoFile *file);
198198
char * nemo_file_get_uri_scheme (NemoFile *file);
199+
gboolean nemo_file_has_uri_scheme (NemoFile *file, const gchar *scheme);
199200
NemoFile * nemo_file_get_parent (NemoFile *file);
200201
GFile * nemo_file_get_parent_location (NemoFile *file);
201202
char * nemo_file_get_parent_uri (NemoFile *file);

0 commit comments

Comments
 (0)