Skip to content

Commit 677f377

Browse files
committed
nemo-action.c: Fix issues in the recent:// folder.
- Use a file's activation uri/location from the recent folder. - Recent files don't have a parent path - disallow that. - Guard against NULL parents when first loading recents. Fixes: #3645
1 parent dc1e4fd commit 677f377

File tree

1 file changed

+70
-44
lines changed

1 file changed

+70
-44
lines changed

libnemo-private/nemo-action.c

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,16 @@ get_path (NemoAction *action, NemoFile *file)
11791179
{
11801180
NemoActionPrivate *priv = nemo_action_get_instance_private (action);
11811181
gchar *ret, *orig;
1182+
GFile *location;
11821183

1183-
orig = nemo_file_get_path (file);
1184+
if (nemo_file_is_in_recent (file)) {
1185+
location = nemo_file_get_activation_location (file);
1186+
} else {
1187+
location = nemo_file_get_location (file);
1188+
}
1189+
1190+
orig = g_file_get_path (location);
1191+
g_object_unref (location);
11841192

11851193
if (priv->quote_type == QUOTE_TYPE_DOUBLE) {
11861194
ret = eel_str_escape_double_quoted_content (orig);
@@ -1320,7 +1328,14 @@ get_insertion_string (NemoAction *action,
13201328
if (!first)
13211329
str = insert_separator (action, str);
13221330
str = insert_quote (action, str);
1323-
gchar *uri = nemo_file_get_uri (NEMO_FILE (l->data));
1331+
gchar *uri;
1332+
1333+
if (nemo_file_is_in_recent (NEMO_FILE (l->data))) {
1334+
uri = nemo_file_get_activation_uri (NEMO_FILE (l->data));
1335+
} else {
1336+
uri = nemo_file_get_uri (NEMO_FILE (l->data));
1337+
}
1338+
13241339
str = score_append (action, str, uri);
13251340
g_free (uri);
13261341
str = insert_quote (action, str);
@@ -1334,46 +1349,55 @@ get_insertion_string (NemoAction *action,
13341349
;
13351350
default_parent_path:
13361351
;
1337-
gchar *path = get_path (action, parent);
1338-
if (path == NULL) {
1339-
gchar *name = nemo_file_get_display_name (parent);
1340-
if (g_strcmp0 (name, "x-nemo-desktop") == 0)
1341-
path = nemo_get_desktop_directory ();
1342-
else
1343-
path = g_strdup ("");
1344-
g_free (name);
1352+
if (parent != NULL) {
1353+
gchar *path = get_path (action, parent);
1354+
if (path == NULL) {
1355+
gchar *name = nemo_file_get_display_name (parent);
1356+
if (g_strcmp0 (name, "x-nemo-desktop") == 0)
1357+
path = nemo_get_desktop_directory ();
1358+
else
1359+
path = g_strdup ("");
1360+
g_free (name);
1361+
}
1362+
1363+
str = insert_quote (action, str);
1364+
str = score_append (action, str, path);
1365+
str = insert_quote (action, str);
1366+
g_free (path);
1367+
} else {
1368+
if (g_list_length (selection) > 0 && nemo_file_is_in_recent (NEMO_FILE (selection->data))) {
1369+
g_warning_once ("The recent:// location does not support parent path (%%P) action tokens.");
1370+
}
13451371
}
1346-
str = insert_quote (action, str);
1347-
str = score_append (action, str, path);
1348-
str = insert_quote (action, str);
1349-
g_free (path);
13501372
break;
13511373
case TOKEN_PARENT_URI:
13521374
;
13531375
default_parent_uri:
13541376
;
1355-
gchar *uri;
1356-
gchar *name = nemo_file_get_display_name (parent);
1357-
if (g_strcmp0 (name, "x-nemo-desktop") == 0) {
1358-
gchar *real_desktop_path = nemo_get_desktop_directory ();
1359-
if (real_desktop_path) {
1360-
GFile *file;
1361-
file = g_file_new_for_path (real_desktop_path);
1362-
uri = g_file_get_uri (file);
1363-
g_object_unref (file);
1364-
g_free (real_desktop_path);
1377+
if (parent != NULL) {
1378+
gchar *uri;
1379+
gchar *name = nemo_file_get_display_name (parent);
1380+
if (g_strcmp0 (name, "x-nemo-desktop") == 0) {
1381+
gchar *real_desktop_path = nemo_get_desktop_directory ();
1382+
if (real_desktop_path) {
1383+
GFile *file;
1384+
file = g_file_new_for_path (real_desktop_path);
1385+
uri = g_file_get_uri (file);
1386+
g_object_unref (file);
1387+
g_free (real_desktop_path);
1388+
} else {
1389+
uri = NULL;
1390+
}
13651391
} else {
1366-
uri = NULL;
1392+
uri = nemo_file_get_uri (parent);
13671393
}
1368-
} else {
1369-
uri = nemo_file_get_uri (parent);
1370-
}
13711394

1372-
str = insert_quote (action, str);
1373-
str = score_append (action, str, uri);
1374-
str = insert_quote (action, str);
1375-
g_free (name);
1376-
g_free (uri);
1395+
str = insert_quote (action, str);
1396+
str = score_append (action, str, uri);
1397+
str = insert_quote (action, str);
1398+
g_free (name);
1399+
g_free (uri);
1400+
}
13771401
break;
13781402
case TOKEN_FILE_DISPLAY_NAME:
13791403
if (g_list_length (selection) > 0) {
@@ -1388,17 +1412,19 @@ get_insertion_string (NemoAction *action,
13881412
;
13891413
default_parent_display_name:
13901414
;
1391-
gchar *parent_display_name;
1392-
gchar *real_display_name = nemo_file_get_display_name (parent);
1393-
if (g_strcmp0 (real_display_name, "x-nemo-desktop") == 0)
1394-
parent_display_name = g_strdup_printf (_("Desktop"));
1395-
else
1396-
parent_display_name = nemo_file_get_display_name (parent);
1397-
g_free (real_display_name);
1398-
str = insert_quote (action, str);
1399-
str = score_append (action, str, parent_display_name);
1400-
str = insert_quote (action, str);
1401-
g_free (parent_display_name);
1415+
if (parent != NULL) {
1416+
gchar *parent_display_name;
1417+
gchar *real_display_name = nemo_file_get_display_name (parent);
1418+
if (g_strcmp0 (real_display_name, "x-nemo-desktop") == 0)
1419+
parent_display_name = g_strdup_printf (_("Desktop"));
1420+
else
1421+
parent_display_name = nemo_file_get_display_name (parent);
1422+
g_free (real_display_name);
1423+
str = insert_quote (action, str);
1424+
str = score_append (action, str, parent_display_name);
1425+
str = insert_quote (action, str);
1426+
g_free (parent_display_name);
1427+
}
14021428
break;
14031429
case TOKEN_DEVICE:
14041430
if (g_list_length (selection) > 0) {

0 commit comments

Comments
 (0)