diff options
author | plonibarploni <[email protected]> | 2020-04-06 18:08:02 -0400 |
---|---|---|
committer | raveit65 <[email protected]> | 2022-07-23 16:22:55 +0200 |
commit | b6a306d1a5c5b2863822b4c792a7060116121474 (patch) | |
tree | 3ce4f3ca3d3258d400acbc1e16dac43265552982 /src | |
parent | 343064289eabc3a2c901d674c7a5707bdd31da07 (diff) | |
download | caja-b6a306d1a5c5b2863822b4c792a7060116121474.tar.bz2 caja-b6a306d1a5c5b2863822b4c792a7060116121474.tar.xz |
support an explicit --select command line option
ported from nautilus:
https://github.com/GNOME/nautilus/commit/dc7e851ae4a223522c3158dd4134a3b313283596
Diffstat (limited to 'src')
-rw-r--r-- | src/caja-application.c | 75 |
1 files changed, 70 insertions, 5 deletions
diff --git a/src/caja-application.c b/src/caja-application.c index 692d4f4b..fea5557a 100644 --- a/src/caja-application.c +++ b/src/caja-application.c @@ -1784,6 +1784,7 @@ do_cmdline_sanity_checks (CajaApplication *self, gboolean perform_self_check, gboolean version, gboolean kill_shell, + gboolean select_uris, gchar **remaining) { gboolean retval = FALSE; @@ -1807,6 +1808,12 @@ do_cmdline_sanity_checks (CajaApplication *self, goto out; } + if (select_uris && remaining == NULL) { + g_printerr ("%s\n", + _("--select must be used with at least an URI.")); + goto out; + } + retval = TRUE; out: @@ -1831,6 +1838,55 @@ do_perform_self_checks (gint *exit_status) *exit_status = EXIT_SUCCESS; } +static void +select_items_ready_cb (GObject *source, + GAsyncResult *res, + gpointer user_data) +{ + GDBusConnection *connection = G_DBUS_CONNECTION (source); + CajaApplication *self = user_data; + GError *error = NULL; + + g_dbus_connection_call_finish (connection, res, &error); + + if (error != NULL) { + g_warning ("Unable to select specified URIs %s\n", error->message); + g_error_free (error); + + /* open default location instead */ + g_application_open (G_APPLICATION (self), NULL, 0, ""); + } +} + +static void +caja_application_select (CajaApplication *self, + GFile **files, + gint len) +{ + GDBusConnection *connection = g_application_get_dbus_connection (G_APPLICATION (self)); + GVariantBuilder builder; + gint idx; + gchar *uri; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); + for (idx = 0; idx < len; idx++) { + uri = g_file_get_uri (files[idx]); + g_variant_builder_add (&builder, "s", uri); + g_free (uri); + } + + g_dbus_connection_call (connection, + CAJA_FDO_DBUS_NAME, + CAJA_FDO_DBUS_PATH, + CAJA_FDO_DBUS_IFACE, + "ShowItems", + g_variant_new ("(ass)", &builder, ""), NULL, + G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, + select_items_ready_cb, self); + + g_variant_builder_clear (&builder); +} + static gboolean running_in_mate (void) { @@ -1857,6 +1913,7 @@ caja_application_local_command_line (GApplication *application, gboolean kill_shell = FALSE; const gchar *autostart_id; gboolean no_default_window = FALSE; + gboolean select_uris = FALSE; gchar **remaining = NULL; CajaApplication *self = CAJA_APPLICATION (application); @@ -1885,6 +1942,8 @@ caja_application_local_command_line (GApplication *application, N_("Open a browser window."), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell, N_("Quit Caja."), NULL }, + { "select", 's', 0, G_OPTION_ARG_NONE, &select_uris, + N_("Select specified URI in parent folder."), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL, N_("[URI...]") }, { NULL } @@ -1930,7 +1989,7 @@ caja_application_local_command_line (GApplication *application, } if (!do_cmdline_sanity_checks (self, perform_self_check, - version, kill_shell, remaining)) { + version, kill_shell, select_uris, remaining)) { *exit_status = EXIT_FAILURE; goto out; } @@ -1993,7 +2052,7 @@ caja_application_local_command_line (GApplication *application, g_strfreev (remaining); } - if (files == NULL && !no_default_window) { + if (files == NULL && !no_default_window && !select_uris) { files = g_malloc0 (2 * sizeof (GFile *)); len = 1; @@ -2001,9 +2060,15 @@ caja_application_local_command_line (GApplication *application, files[1] = NULL; } - /*Set up --geometry, --browser and --tabs options */ - /*Invoke "Open" to create new windows */ - if (len > 0) { + if (len == 0) { + goto out; + } + + if (select_uris) { + caja_application_select (self, files, len); + } else { + /*Set up --geometry, --browser and --tabs options */ + /*Invoke "Open" to create new windows */ gchar* concatOptions = g_malloc0(64); if (self->priv->geometry == NULL) { g_snprintf (concatOptions, 64, "%d=NULL=%d", browser_window, open_in_tabs); |