Aditional remote command - window list
authorColin Clark <colin.clark@cclark.uk>
Fri, 15 Mar 2024 14:19:38 +0000 (14:19 +0000)
committerColin Clark <colin.clark@cclark.uk>
Fri, 15 Mar 2024 14:19:38 +0000 (14:19 +0000)
src/layout.cc
src/layout.h
src/remote.cc

index f955399..df0403f 100644 (file)
@@ -241,6 +241,41 @@ static void layout_box_folders_changed_cb(GtkWidget *widget, gpointer)
                }
 }
 
+static gint window_list_sort_cb(gconstpointer a, gconstpointer b)
+{
+       return CASE_SORT((gchar *)a, (gchar *)b);
+}
+
+GString *layout_get_window_list()
+{
+       LayoutWindow *lw;
+       GList *work;
+       GList *window_list = nullptr;
+       GString *ret = g_string_new(nullptr);
+
+       work = layout_window_list;
+       while (work)
+               {
+               lw = static_cast<LayoutWindow *>(work->data);
+               window_list = g_list_insert_sorted(window_list, g_strdup(lw->options.id), window_list_sort_cb);
+               work = work->next;
+               }
+
+       work = g_list_first(window_list);
+       g_string_append_printf(ret, "%s", (gchar *)work->data);
+       work = work->next;
+
+       while (work)
+               {
+               g_string_append_printf(ret, "\n%s", (gchar *)work->data);
+               work = work->next;
+               }
+
+       g_list_free(window_list);
+
+       return ret;
+}
+
 /*
  *-----------------------------------------------------------------------------
  * menu, toolbar, and dir view
index 711c147..78141e1 100644 (file)
@@ -192,6 +192,7 @@ guint layout_list_count(LayoutWindow *lw, gint64 *bytes);
 FileData *layout_list_get_fd(LayoutWindow *lw, gint index);
 gint layout_list_get_index(LayoutWindow *lw, FileData *fd);
 void layout_list_sync_fd(LayoutWindow *lw, FileData *fd);
+GString *layout_get_window_list();
 
 GList *layout_selection_list(LayoutWindow *lw);
 /* return list of pointers to int for selection */
index 7d47b17..e1102fd 100644 (file)
@@ -1426,6 +1426,18 @@ static void gr_config_load(const gchar *text, GIOChannel *, gpointer)
        g_free(filename);
 }
 
+static void gr_window_list(const gchar *, GIOChannel *channel, gpointer)
+{
+       GString *window_list;
+
+       window_list = layout_get_window_list();
+
+       g_io_channel_write_chars(channel, window_list->str, -1, nullptr, nullptr);
+       g_io_channel_write_chars(channel, "<gq_end_of_command>", -1, nullptr, nullptr);
+
+       g_string_free(window_list, TRUE);
+}
+
 static void gr_get_sidecars(const gchar *text, GIOChannel *channel, gpointer)
 {
        gchar *filename = expand_tilde(text);
@@ -1739,6 +1751,7 @@ static RemoteCommandEntry remote_commands[] = {
        { nullptr, "--get-render-intent",  gr_render_intent,       FALSE, FALSE, nullptr, N_("get render intent") },
        { nullptr, "--get-selection",      gr_get_selection,       FALSE, FALSE, nullptr, N_("get list of selected files") },
        { nullptr, "--get-sidecars:",      gr_get_sidecars,        TRUE,  FALSE, N_("<FILE>"), N_("get list of sidecars of FILE") },
+       { nullptr, "--get-window-list",    gr_window_list,         FALSE, FALSE, nullptr, N_("get window list") },
        { nullptr, "--id:",                gr_lw_id,               TRUE, FALSE, N_("<ID>"), N_("window id for following commands") },
        { nullptr, "--last",               gr_image_last,          FALSE, FALSE, nullptr, N_("last image") },
        { nullptr, "--list-add:",          gr_list_add,            TRUE,  FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },