[gthumb: 12/15] added 'resue active window' option



commit c758a48f41635fd8246f419cd3518a37a0a70a55
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Nov 23 10:27:20 2011 +0100

    added 'resue active window' option
    
    Added option to reuse the active window when opening files from an
    external application.
    
    [new feature]

 data/org.gnome.gthumb.gschema.xml.in |    6 ++++-
 data/ui/preferences.ui               |   45 +++++++++++++++++++++++++++-------
 gthumb/dlg-preferences.c             |   14 ++++++++++
 gthumb/gth-file-list.c               |    2 +
 gthumb/gth-preferences.h             |    1 +
 gthumb/main.c                        |   21 +++++++++++++++-
 6 files changed, 78 insertions(+), 11 deletions(-)
---
diff --git a/data/org.gnome.gthumb.gschema.xml.in b/data/org.gnome.gthumb.gschema.xml.in
index 0946dbb..63f6b92 100644
--- a/data/org.gnome.gthumb.gschema.xml.in
+++ b/data/org.gnome.gthumb.gschema.xml.in
@@ -134,7 +134,11 @@
     <key name="shrink-wrap-viewer" type="b">
       <default>false</default>
       <_description>Whether to resize the window to fit the size of the image</_description>
-    </key>     
+    </key>
+    <key name="reuse-active-window" type="b">
+      <default>false</default>
+      <_description>Open files in the active window</_description>
+    </key>
   </schema>
   
   <schema id="org.gnome.gthumb.dialogs" path="/org/gnome/gthumb/dialogs/">
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 78f0517..3221b0b 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -32,6 +32,7 @@
             <child>
               <object class="GtkButton" id="help_button">
                 <property name="label">gtk-help</property>
+                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -48,6 +49,7 @@
             <child>
               <object class="GtkButton" id="close_button">
                 <property name="label">gtk-ok</property>
+                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
@@ -170,15 +172,6 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
                                   <object class="GtkLabel" id="label10">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
@@ -213,6 +206,15 @@
                                     <property name="height">1</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </object>
                               <packing>
                                 <property name="expand">False</property>
@@ -263,6 +265,7 @@
                             <child>
                               <object class="GtkRadioButton" id="go_to_last_location_radiobutton">
                                 <property name="label" translatable="yes">Go to last _visited location</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -286,6 +289,7 @@
                                 <child>
                                   <object class="GtkRadioButton" id="use_startup_location_radiobutton">
                                     <property name="label" translatable="yes">Go to this _folder:</property>
+                                    <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">False</property>
@@ -329,6 +333,7 @@
                                 <child>
                                   <object class="GtkButton" id="set_to_current_button">
                                     <property name="label" translatable="yes">Set to C_urrent</property>
+                                    <property name="use_action_appearance">False</property>
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
                                     <property name="receives_default">True</property>
@@ -349,6 +354,24 @@
                                 <property name="position">2</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkCheckButton" id="reuse_active_window_checkbutton">
+                                <property name="label" translatable="yes">_Reuse the active window to open files</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="xalign">0</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">3</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>
@@ -392,6 +415,7 @@
                             <child>
                               <object class="GtkCheckButton" id="confirm_deletion_checkbutton">
                                 <property name="label" translatable="yes">As_k confirmation before deleting files or catalogs</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -409,6 +433,7 @@
                             <child>
                               <object class="GtkCheckButton" id="ask_to_save_checkbutton">
                                 <property name="label" translatable="yes">Ask whether to save _modified files</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -426,6 +451,7 @@
                             <child>
                               <object class="GtkCheckButton" id="embed_metadata_checkbutton">
                                 <property name="label" translatable="yes">_Store metadata inside files if possible</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -603,6 +629,7 @@
                             <child>
                               <object class="GtkCheckButton" id="slow_mime_type_checkbutton">
                                 <property name="label" translatable="yes">D_etermine image type from content (slower)</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
diff --git a/gthumb/dlg-preferences.c b/gthumb/dlg-preferences.c
index 73626fb..542535c 100644
--- a/gthumb/dlg-preferences.c
+++ b/gthumb/dlg-preferences.c
@@ -171,6 +171,14 @@ file_properties_position_combobox_changed_cb (GtkWidget  *widget,
 
 
 static void
+reuse_active_window_checkbutton_toggled_cb (GtkToggleButton *button,
+					    DialogData      *data)
+{
+	g_settings_set_boolean (data->browser_settings, PREF_BROWSER_REUSE_ACTIVE_WINDOW, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reuse_active_window_checkbutton"))));
+}
+
+
+static void
 confirm_deletion_toggled_cb (GtkToggleButton *button,
 			     DialogData      *data)
 {
@@ -281,6 +289,8 @@ dlg_preferences (GthBrowser *browser)
 	g_object_unref (file_source);
 	g_free (startup_location);
 
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reuse_active_window_checkbutton")),
+				      g_settings_get_boolean (data->browser_settings, PREF_BROWSER_REUSE_ACTIVE_WINDOW));
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("confirm_deletion_checkbutton")),
 				      g_settings_get_boolean (data->messages_settings, PREF_MSG_CONFIRM_DELETION));
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ask_to_save_checkbutton")),
@@ -341,6 +351,10 @@ dlg_preferences (GthBrowser *browser)
 			  "clicked",
 			  G_CALLBACK (set_to_current_cb),
 			  data);
+	g_signal_connect (G_OBJECT (GET_WIDGET ("reuse_active_window_checkbutton")),
+			  "toggled",
+			  G_CALLBACK (reuse_active_window_checkbutton_toggled_cb),
+			  data);
 	g_signal_connect (G_OBJECT (GET_WIDGET ("confirm_deletion_checkbutton")),
 			  "toggled",
 			  G_CALLBACK (confirm_deletion_toggled_cb),
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index e936cb2..f5a4a8b 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -670,6 +670,8 @@ void
 gth_file_list_set_type (GthFileList     *file_list,
 			GthFileListType  list_type)
 {
+	g_return_if_fail (GTH_IS_FILE_LIST (file_list));
+
 	file_list->priv->type = list_type;
 
 	if ((file_list->priv->type == GTH_FILE_LIST_TYPE_SELECTOR) || (file_list->priv->type == GTH_FILE_LIST_TYPE_NO_SELECTION))
diff --git a/gthumb/gth-preferences.h b/gthumb/gth-preferences.h
index ff3affa..3a542e8 100644
--- a/gthumb/gth-preferences.h
+++ b/gthumb/gth-preferences.h
@@ -78,6 +78,7 @@ G_BEGIN_DECLS
 #define PREF_BROWSER_VIEWER_SIDEBAR_WIDTH     "viewer-sidebar-width"
 #define PREF_BROWSER_VIEWER_THUMBNAILS_ORIENT "viewer-thumbnails-orientation"
 #define PREF_BROWSER_SHRINK_WRAP_VIEWER       "shrink-wrap-viewer"
+#define PREF_BROWSER_REUSE_ACTIVE_WINDOW      "reuse-active-window"
 
 /* keys: add to catalog */
 
diff --git a/gthumb/main.c b/gthumb/main.c
index 5f7d605..bbb69b7 100644
--- a/gthumb/main.c
+++ b/gthumb/main.c
@@ -86,9 +86,28 @@ static void
 open_browser_window (GFile *location,
 		     GFile *file_to_select)
 {
+	GSettings *settings;
+	gboolean   reuse_active_window;
 	GtkWidget *window;
 
-	window = gth_browser_new (location, file_to_select);
+	settings = g_settings_new (GTHUMB_BROWSER_SCHEMA);
+	reuse_active_window = g_settings_get_boolean (settings, PREF_BROWSER_REUSE_ACTIVE_WINDOW);
+	g_object_unref (settings);
+
+	window = NULL;
+	if (reuse_active_window) {
+		GList *windows = gtk_application_get_windows (Main_Application);
+		if (windows != NULL)
+			window = windows->data;
+	}
+
+	if (window == NULL)
+		window = gth_browser_new (location, file_to_select);
+	else if (file_to_select != NULL)
+		gth_browser_go_to (GTH_BROWSER (window), location, file_to_select);
+	else
+		gth_browser_load_location (GTH_BROWSER (window), location);
+
 	if (! StartSlideshow)
 		gtk_window_present (GTK_WINDOW (window));
 }



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