[eog] Allow reusing an existing window for another image from the commandline



commit 45ed40ecb15a1db97ad34752a237d187b2aec34c
Author: Michael WÃnsch <liganic-eog gmx org>
Date:   Thu Oct 6 17:56:16 2011 +0200

    Allow reusing an existing window for another image from the commandline
    
    Reuses an existing window instead of opening a new one.
    For now this is only supported from the commandline.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=617735

 src/eog-application.c |   40 +++++++++++++++++++++++++++++++++++-----
 src/eog-window.h      |    3 ++-
 src/main.c            |    5 +++++
 3 files changed, 42 insertions(+), 6 deletions(-)
---
diff --git a/src/eog-application.c b/src/eog-application.c
index 258db1b..6ced253 100644
--- a/src/eog-application.c
+++ b/src/eog-application.c
@@ -295,6 +295,27 @@ eog_application_get_file_window (EogApplication *application, GFile *file)
 	return file_window;
 }
 
+static EogWindow *
+eog_application_get_first_window (EogApplication *application)
+{
+	g_return_val_if_fail (EOG_IS_APPLICATION (application), NULL);
+
+	GList *windows;
+	GList *l;
+	EogWindow *window = NULL;
+	windows = gtk_window_list_toplevels ();
+	for (l = windows; l != NULL; l = l->next) {
+		if (EOG_IS_WINDOW (l->data)) {
+			window = EOG_WINDOW (l->data);
+			break;
+		}
+	}
+	g_list_free (windows);
+
+	return window;
+}
+
+
 static void
 eog_application_show_window (EogWindow *window, gpointer user_data)
 {
@@ -314,6 +335,8 @@ eog_application_show_window (EogWindow *window, gpointer user_data)
  * Opens a list of files in a #EogWindow. If an #EogWindow displaying the first
  * image in the list is already open, this will be used. Otherwise, an empty
  * #EogWindow is used, either already existing or newly created.
+ * If the EOG_STARTUP_SINGLE_WINDOW flag is set, the files are opened in the
+ * first #EogWindow and no new one is opened.
  *
  * Returns: Currently always %TRUE.
  **/
@@ -326,13 +349,20 @@ eog_application_open_file_list (EogApplication  *application,
 {
 	EogWindow *new_window = NULL;
 
-	if (file_list != NULL)
-		new_window = eog_application_get_file_window (application,
-							      (GFile *) file_list->data);
+	if (file_list != NULL) {
+		if(flags & EOG_STARTUP_SINGLE_WINDOW)
+			new_window = eog_application_get_first_window (application);
+		else
+			new_window = eog_application_get_file_window (application,
+								      (GFile *) file_list->data);
+	}
 
 	if (new_window != NULL) {
-		gtk_window_present_with_time (GTK_WINDOW (new_window),
-					      timestamp);
+		if(flags & EOG_STARTUP_SINGLE_WINDOW)
+		        eog_window_open_file_list (new_window, file_list);
+		else
+			gtk_window_present_with_time (GTK_WINDOW (new_window),
+						      timestamp);
 		return TRUE;
 	}
 
diff --git a/src/eog-window.h b/src/eog-window.h
index 7c5d29c..fc337dc 100644
--- a/src/eog-window.h
+++ b/src/eog-window.h
@@ -78,7 +78,8 @@ typedef enum {
 typedef enum {
 	EOG_STARTUP_FULLSCREEN         = 1 << 0,
 	EOG_STARTUP_SLIDE_SHOW         = 1 << 1,
-	EOG_STARTUP_DISABLE_GALLERY    = 1 << 2
+	EOG_STARTUP_DISABLE_GALLERY    = 1 << 2,
+	EOG_STARTUP_SINGLE_WINDOW      = 1 << 3
 } EogStartupFlags;
 
 struct _EogWindow {
diff --git a/src/main.c b/src/main.c
index 771cd46..4e78732 100644
--- a/src/main.c
+++ b/src/main.c
@@ -52,6 +52,7 @@ static gboolean fullscreen = FALSE;
 static gboolean slide_show = FALSE;
 static gboolean disable_gallery = FALSE;
 static gboolean force_new_instance = FALSE;
+static gboolean single_window = FALSE;
 static gchar **startup_files = NULL;
 
 static gboolean
@@ -71,6 +72,7 @@ static const GOptionEntry goption_options[] =
 	{ "disable-gallery", 'g', 0, G_OPTION_ARG_NONE, &disable_gallery, N_("Disable image gallery"), NULL  },
 	{ "slide-show", 's', 0, G_OPTION_ARG_NONE, &slide_show, N_("Open in slideshow mode"), NULL  },
 	{ "new-instance", 'n', 0, G_OPTION_ARG_NONE, &force_new_instance, N_("Start a new instance instead of reusing an existing one"), NULL },
+	{ "single-window", 'w', 0, G_OPTION_ARG_NONE, &single_window, N_("Open in a single window, if multiple windows are open the first one is used"), NULL },
 	{ "version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
 	  _print_version_and_exit, N_("Show the application's version"), NULL},
 	{ NULL }
@@ -87,6 +89,9 @@ set_startup_flags (void)
 
   if (slide_show)
     flags |= EOG_STARTUP_SLIDE_SHOW;
+
+  if (single_window)
+    flags |= EOG_STARTUP_SINGLE_WINDOW;
 }
 
 int



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]