summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Schwinn <alexxcons@xfce.org>2021-01-23 17:36:09 +0100
committerAlexander Schwinn <alexxcons@xfce.org>2021-01-24 18:49:33 +0100
commit7675b9ea4daa3ece93c747cd109a61760aebcfb1 (patch)
tree4d2de092b6af2128c4ffa3ee3244664b5ee99ee8
parentee967e7cf45bf5e261dc19baa9fc971865aca569 (diff)
downloadthunar-7675b9ea4daa3ece93c747cd109a61760aebcfb1.tar.gz
thunar-launcher: Unify way to set selected device/location/files
In order to minimize risk of memory leaks
-rw-r--r--thunar/thunar-launcher.c52
-rw-r--r--thunar/thunar-tree-view.c8
-rw-r--r--thunar/thunar-window.c3
3 files changed, 46 insertions, 17 deletions
diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c
index 37880383..9e8ef1a0 100644
--- a/thunar/thunar-launcher.c
+++ b/thunar/thunar-launcher.c
@@ -193,6 +193,10 @@ static void thunar_launcher_action_create_folder (Thuna
static void thunar_launcher_action_create_document (ThunarLauncher *launcher,
GtkWidget *menu_item);
static GtkWidget *thunar_launcher_create_document_submenu_new(ThunarLauncher *launcher);
+void thunar_launcher_set_selection (ThunarLauncher *launcher,
+ GList *selected_thunar_files,
+ ThunarDevice *selected_device,
+ GFile *selected_location);
@@ -487,7 +491,7 @@ thunar_launcher_set_property (GObject *object,
break;
case PROP_SELECTED_FILES:
- thunar_component_set_selected_files (THUNAR_COMPONENT (object), g_value_get_boxed (value));
+ thunar_launcher_set_selection (launcher, g_value_get_boxed (value), NULL, NULL);
break;
case PROP_WIDGET:
@@ -499,12 +503,12 @@ thunar_launcher_set_property (GObject *object,
break;
case PROP_SELECTED_DEVICE:
- launcher->device_to_process = g_value_get_pointer (value);
+ thunar_launcher_set_selection (launcher, NULL, g_value_get_boxed (value), NULL);
break;
case PROP_SELECTED_LOCATION:
- launcher->location_to_process = g_value_get_pointer (value);
- break;
+ thunar_launcher_set_selection (launcher, NULL, NULL, g_value_get_boxed (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -2717,8 +2721,6 @@ thunar_launcher_action_eject_finish (ThunarDevice *device,
thunar_dialogs_show_error (GTK_WIDGET (launcher->widget), error, _("Failed to eject \"%s\""), device_name);
g_free (device_name);
}
- else
- launcher->device_to_process = NULL;
g_object_unref (launcher);
}
@@ -2775,8 +2777,6 @@ thunar_launcher_action_unmount_finish (ThunarDevice *device,
thunar_dialogs_show_error (GTK_WIDGET (launcher->widget), error, _("Failed to unmount \"%s\""), device_name);
g_free (device_name);
}
- else
- launcher->device_to_process = NULL;
g_object_unref (launcher);
}
@@ -2968,3 +2968,39 @@ thunar_launcher_get_widget (ThunarLauncher *launcher)
_thunar_return_val_if_fail (THUNAR_IS_LAUNCHER (launcher), NULL);
return launcher->widget;
}
+
+
+
+/**
+ * thunar_launcher_set_selection:
+ * @launcher : a #ThunarLauncher instance
+ * @selected_thunar_files: #GList of selected #ThunarFile instances, or NULL
+ * @selected_device: selected #ThunarDevice or NULL
+ * @selected_location: selected #GFile (possibly only holds an URI), or NULL
+ *
+ * Will set the related items as "selection" and clear any previous selection.
+ * Note that always only one of the 3 "selected" arguments should be set.
+ **/
+void
+thunar_launcher_set_selection (ThunarLauncher *launcher,
+ GList *selected_thunar_files,
+ ThunarDevice *selected_device,
+ GFile *selected_location)
+{
+ _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher));
+
+ /* unref the current device/location */
+ if (launcher->device_to_process != NULL)
+ g_object_unref (launcher->device_to_process);
+ if (launcher->location_to_process != NULL)
+ g_object_unref (launcher->location_to_process);
+
+ /* ref the new device/location */
+ if (selected_device != NULL)
+ launcher->device_to_process = g_object_ref (selected_device);
+ if (selected_location != NULL)
+ launcher->location_to_process = g_object_ref (selected_location);
+
+ /* for selected files things are a bit more conmplicated */
+ thunar_launcher_set_selected_files (THUNAR_COMPONENT (launcher), selected_thunar_files);
+}
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index 22349b9a..4ba70d26 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -853,7 +853,6 @@ thunar_tree_view_key_press_event(GtkWidget *widget,
/* mark this path for selection after unmounting */
view->select_path = gtk_tree_path_copy(path);
g_object_set (G_OBJECT (view->launcher), "selected-device", device, NULL);
- g_object_set (G_OBJECT (view->launcher), "selected-files", NULL, "current-directory", NULL, NULL);
thunar_launcher_action_unmount (view->launcher);
g_object_unref (G_OBJECT (device));
}
@@ -872,7 +871,6 @@ thunar_tree_view_key_press_event(GtkWidget *widget,
if (device != NULL && thunar_device_is_mounted (device) == FALSE)
{
g_object_set (G_OBJECT (view->launcher), "selected-device", device, NULL);
- g_object_set (G_OBJECT (view->launcher), "selected-files", NULL, "current-directory", NULL, NULL);
thunar_launcher_action_mount (view->launcher);
}
else
@@ -1155,7 +1153,6 @@ thunar_tree_view_test_expand_row (GtkTreeView *tree_view,
/* we need to mount the device before we can expand the row */
expandable = FALSE;
g_object_set (G_OBJECT (view->launcher), "selected-device", device, NULL);
- g_object_set (G_OBJECT (view->launcher), "selected-files", NULL, "current-directory", NULL, NULL);
/* The closure will expand the row after the mount operation finished */
thunar_launcher_action_mount (view->launcher);
}
@@ -1238,8 +1235,6 @@ thunar_tree_view_context_menu (ThunarTreeView *view,
"launcher", view->launcher,
"force-section-open", TRUE, NULL);
- g_object_set (G_OBJECT (view->launcher), "selected-device", device, NULL);
-
file_is_available = (device == NULL || thunar_device_is_mounted (device));
if (file_is_available)
{
@@ -1272,7 +1267,7 @@ thunar_tree_view_context_menu (ThunarTreeView *view,
}
else
{
- g_object_set (G_OBJECT (view->launcher), "selected-files", NULL, "current-directory", NULL, NULL);
+ g_object_set (G_OBJECT (view->launcher), "selected-device", device, NULL);
thunar_launcher_append_menu_item (view->launcher, GTK_MENU_SHELL (context_menu), THUNAR_LAUNCHER_ACTION_OPEN, TRUE);
thunar_launcher_append_menu_item (view->launcher, GTK_MENU_SHELL (context_menu), THUNAR_LAUNCHER_ACTION_OPEN_IN_TAB, TRUE);
thunar_launcher_append_menu_item (view->launcher, GTK_MENU_SHELL (context_menu), THUNAR_LAUNCHER_ACTION_OPEN_IN_WINDOW, TRUE);
@@ -1484,7 +1479,6 @@ thunar_tree_view_action_open (ThunarTreeView *view)
else
{
g_object_set (G_OBJECT (view->launcher), "selected-device", device, NULL);
- g_object_set (G_OBJECT (view->launcher), "selected-files", NULL, "current-directory", NULL, NULL);
thunar_launcher_action_mount (view->launcher);
}
}
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 6157cf8c..12c3370c 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -3542,8 +3542,7 @@ thunar_window_action_open_bookmark (GFile *g_file)
window = g_object_get_data (G_OBJECT (g_file), I_("thunar-window"));
- g_object_set (G_OBJECT (window->launcher), "selected-location", g_file,
- "selected-files", NULL, NULL);
+ g_object_set (G_OBJECT (window->launcher), "selected-location", g_file, NULL);
thunar_launcher_activate_selected_files (window->launcher, THUNAR_LAUNCHER_CHANGE_DIRECTORY, NULL);
}