summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Oehl <oehl.tim@gmail.com>2021-02-22 12:17:36 +0100
committerAlexander Schwinn <alexxcons@xfce.org>2021-03-07 00:20:29 +0100
commit70f75b89cbfd7f330710631998ae21902f7a10e5 (patch)
treef323a642be74c9be0494559791736c47ba9175a1
parent4dcff28647d15ec3226e8552a88128f4764ed964 (diff)
downloadthunar-70f75b89cbfd7f330710631998ae21902f7a10e5.tar.gz
Bookmarks no longer need an existing, underlying file (Issue #47)
Co-authored-by: Dito didio <ditodidio@key-idea.de>
-rw-r--r--thunar/thunar-shortcuts-model.c72
1 files changed, 45 insertions, 27 deletions
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index 9f684803..3dd25c2f 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -1330,47 +1330,40 @@ thunar_shortcuts_model_load_line (GFile *file_path,
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (model));
_thunar_return_if_fail (name == NULL || g_utf8_validate (name, -1, NULL));
- /* handle local and remove files differently */
+ shortcut = g_slice_new0 (ThunarShortcut);
+ shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
+
+ /* handle local and remote files differently */
if (thunar_shortcuts_model_local_file (file_path))
{
/* try to open the file corresponding to the uri */
file = thunar_file_get (file_path, NULL);
if (G_UNLIKELY (file == NULL))
- return;
-
- /* make sure the file refers to a directory */
- if (G_UNLIKELY (thunar_file_is_directory (file)))
{
- /* create the shortcut entry */
- shortcut = g_slice_new0 (ThunarShortcut);
- shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
- shortcut->file = file;
- shortcut->sort_id = row_num;
- shortcut->hidden = thunar_shortcuts_model_get_hidden (model, shortcut);
- shortcut->name = g_strdup (name);
-
- /* append the shortcut to the list */
- thunar_shortcuts_model_add_shortcut (model, shortcut);
+ shortcut->gicon = g_themed_icon_new ("folder");
+ shortcut->location = g_object_ref (file_path);
}
else
{
- g_object_unref (file);
+ /* make sure the file refers to a directory */
+ if (G_UNLIKELY (thunar_file_is_directory (file)))
+ shortcut->file = file;
+ else
+ g_object_unref (file);
}
}
else
{
- /* create the shortcut entry */
- shortcut = g_slice_new0 (ThunarShortcut);
- shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
shortcut->gicon = g_themed_icon_new ("folder-remote");
shortcut->location = g_object_ref (file_path);
- shortcut->sort_id = row_num;
- shortcut->hidden = thunar_shortcuts_model_get_hidden (model, shortcut);
- shortcut->name = g_strdup (name);
-
- /* append the shortcut to the list */
- thunar_shortcuts_model_add_shortcut (model, shortcut);
}
+
+ shortcut->sort_id = row_num;
+ shortcut->hidden = thunar_shortcuts_model_get_hidden (model, shortcut);
+ shortcut->name = g_strdup (name);
+
+ /* append the shortcut to the list */
+ thunar_shortcuts_model_add_shortcut (model, shortcut);
}
@@ -1574,6 +1567,11 @@ thunar_shortcuts_model_file_changed (ThunarFile *file,
path = gtk_tree_path_new_from_indices (idx, -1);
gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
gtk_tree_path_free (path);
+
+ /* the shortcuts list was changed, so write the gtk bookmarks file */
+ if (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
+ thunar_shortcuts_model_save (model);
+
break;
}
}
@@ -1602,9 +1600,29 @@ thunar_shortcuts_model_file_destroy (ThunarFile *file,
/* verify that we actually found a shortcut */
_thunar_assert (lp != NULL);
_thunar_assert (THUNAR_IS_FILE (shortcut->file));
+ if (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
+ {
+ if (G_LIKELY (shortcut->gicon != NULL))
+ g_object_unref (shortcut->gicon);
- /* drop the shortcut from the model */
- thunar_shortcuts_model_remove_shortcut (model, shortcut);
+ if (G_LIKELY (shortcut->location != NULL))
+ g_object_unref (shortcut->location);
+
+ shortcut->gicon = g_themed_icon_new ("folder");
+ shortcut->location = g_object_ref (thunar_file_get_file (shortcut->file));
+
+ thunar_file_unwatch (shortcut->file);
+ g_signal_handlers_disconnect_matched (shortcut->file,
+ G_SIGNAL_MATCH_DATA, 0,
+ 0, NULL, NULL, model);
+ g_object_unref (shortcut->file);
+ shortcut->file = NULL;
+ }
+ else
+ {
+ /* drop the shortcut from the model */
+ thunar_shortcuts_model_remove_shortcut (model, shortcut);
+ }
}