[glade] Enhanced preferences



commit a267d502f9c04b4ca512b3ddaf13aac60408853c
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Fri Apr 12 02:18:29 2013 +0900

    Enhanced preferences
    
    Now the user can choose if they want to ignore versioning errors, deprecation
    warnings or warnings about unrecognized types at save time. This avoids
    the dialog in the case you might save often but don't care to be warned
    every time.

 src/glade-preferences.c     |   57 ++++++++++++
 src/glade-preferences.glade |  203 +++++++++++++++++++++++++++++++++---------
 src/glade-preferences.h     |    4 +
 src/glade-window.c          |   16 +++-
 4 files changed, 232 insertions(+), 48 deletions(-)
---
diff --git a/src/glade-preferences.c b/src/glade-preferences.c
index 5111b5f..24e99c7 100644
--- a/src/glade-preferences.c
+++ b/src/glade-preferences.c
@@ -31,6 +31,11 @@
 #define CONFIG_KEY_AUTOSAVE         "autosave"
 #define CONFIG_KEY_AUTOSAVE_SECONDS "autosave-seconds"
 
+#define CONFIG_GROUP_SAVE_WARNINGS  "Save Warnings"
+#define CONFIG_KEY_VERSIONING       "versioning"
+#define CONFIG_KEY_DEPRECATIONS     "deprecations"
+#define CONFIG_KEY_UNRECOGNIZED     "unrecognized"
+
 enum {
   COLUMN_PATH = 0,
   COLUMN_CANONICAL_PATH
@@ -45,6 +50,10 @@ struct _GladePreferencesPrivate
   GtkWidget *create_backups_toggle;
   GtkWidget *autosave_toggle;
   GtkWidget *autosave_spin;
+
+  GtkWidget *versioning_toggle;
+  GtkWidget *deprecations_toggle;
+  GtkWidget *unrecognized_toggle;
 };
 
 
@@ -188,6 +197,9 @@ glade_preferences_class_init (GladePreferencesClass *klass)
   gtk_widget_class_bind_child (widget_class, GladePreferencesPrivate, create_backups_toggle);
   gtk_widget_class_bind_child (widget_class, GladePreferencesPrivate, autosave_toggle);
   gtk_widget_class_bind_child (widget_class, GladePreferencesPrivate, autosave_spin);
+  gtk_widget_class_bind_child (widget_class, GladePreferencesPrivate, versioning_toggle);
+  gtk_widget_class_bind_child (widget_class, GladePreferencesPrivate, deprecations_toggle);
+  gtk_widget_class_bind_child (widget_class, GladePreferencesPrivate, unrecognized_toggle);
 
   /* Declare the callback ports that this widget class exposes, to bind with <signal>
    * connections defined in the GtkBuilder xml
@@ -235,6 +247,7 @@ glade_preferences_save (GladePreferences *prefs,
   
   g_key_file_set_string (config, CONFIG_GROUP, CONFIG_KEY_CATALOG_PATHS, string->str);
 
+  /* Load and save */
   g_key_file_set_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP,
                          glade_preferences_backup (prefs));
   g_key_file_set_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE,
@@ -242,6 +255,14 @@ glade_preferences_save (GladePreferences *prefs,
   g_key_file_set_integer (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_AUTOSAVE_SECONDS,
                          glade_preferences_autosave_seconds (prefs));
 
+  /* Warnings */
+  g_key_file_set_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING,
+                         glade_preferences_warn_versioning (prefs));
+  g_key_file_set_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS,
+                         glade_preferences_warn_deprecations (prefs));
+  g_key_file_set_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED,
+                         glade_preferences_warn_unrecognized (prefs));
+
   g_string_free (string, TRUE);
 }
 
@@ -252,6 +273,9 @@ glade_preferences_load (GladePreferences *prefs,
   gchar *string;
   gboolean backups = TRUE;
   gboolean autosave = TRUE;
+  gboolean warn_versioning = TRUE;
+  gboolean warn_deprecations = FALSE;
+  gboolean warn_unrecognized = TRUE;
   gint autosave_seconds = 30;
   
   string = g_key_file_get_string (config, CONFIG_GROUP, CONFIG_KEY_CATALOG_PATHS, NULL);
@@ -289,6 +313,7 @@ glade_preferences_load (GladePreferences *prefs,
       g_strfreev (paths);
     }
 
+  /* Load and save */
   if (g_key_file_has_key (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, NULL))
     backups = g_key_file_get_boolean (config, CONFIG_GROUP_LOAD_SAVE, CONFIG_KEY_BACKUP, NULL);
 
@@ -303,6 +328,20 @@ glade_preferences_load (GladePreferences *prefs,
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (prefs->priv->autosave_spin), autosave_seconds);
   gtk_widget_set_sensitive (prefs->priv->autosave_spin, autosave);
 
+  /* Warnings */
+  if (g_key_file_has_key (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, NULL))
+    warn_versioning = g_key_file_get_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_VERSIONING, 
NULL);
+
+  if (g_key_file_has_key (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, NULL))
+    warn_deprecations = g_key_file_get_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_DEPRECATIONS, 
NULL);
+
+  if (g_key_file_has_key (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, NULL))
+    warn_unrecognized = g_key_file_get_boolean (config, CONFIG_GROUP_SAVE_WARNINGS, CONFIG_KEY_UNRECOGNIZED, 
NULL);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->versioning_toggle), warn_versioning);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->deprecations_toggle), warn_deprecations);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prefs->priv->unrecognized_toggle), warn_unrecognized);
+
   g_free (string);
 }
 
@@ -323,3 +362,21 @@ glade_preferences_autosave_seconds (GladePreferences *prefs)
 {
   return (gint)gtk_spin_button_get_value (GTK_SPIN_BUTTON (prefs->priv->autosave_spin));
 }
+
+gboolean
+glade_preferences_warn_versioning (GladePreferences *prefs)
+{
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->versioning_toggle));
+}
+
+gboolean
+glade_preferences_warn_deprecations (GladePreferences *prefs)
+{
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->deprecations_toggle));
+}
+
+gboolean
+glade_preferences_warn_unrecognized (GladePreferences *prefs)
+{
+  return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prefs->priv->unrecognized_toggle));
+}
diff --git a/src/glade-preferences.glade b/src/glade-preferences.glade
index 45cfbea..fd20f78 100644
--- a/src/glade-preferences.glade
+++ b/src/glade-preferences.glade
@@ -24,38 +24,12 @@
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="preferences_close_button">
-                <property name="label">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
         <child>
-          <object class="GtkBox" id="box1">
+          <object class="GtkGrid" id="grid4">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="border_width">3</property>
-            <property name="orientation">vertical</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">6</property>
             <child>
               <object class="GtkFrame" id="frame2">
                 <property name="visible">True</property>
@@ -69,11 +43,11 @@
                     <property name="can_focus">False</property>
                     <property name="margin_left">12</property>
                     <property name="margin_top">6</property>
-                    <property name="row_spacing">6</property>
-                    <property name="column_spacing">6</property>
+                    <property name="row_spacing">2</property>
+                    <property name="column_spacing">2</property>
                     <child>
                       <object class="GtkCheckButton" id="create_backups_toggle">
-                        <property name="label" translatable="yes">Create Backups</property>
+                        <property name="label" translatable="yes">Create bsackups</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
@@ -84,7 +58,24 @@
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">0</property>
-                        <property name="width">2</property>
+                        <property name="width">3</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="tooltip_text" translatable="yes">Automatically save the project to 
an alternate file whenever
+the project is modified and the specified timeout elapses</property>
+                        <property name="halign">start</property>
+                        <property name="hexpand">False</property>
+                        <property name="label" translatable="yes">seconds</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="width">1</property>
                         <property name="height">1</property>
                       </packing>
                     </child>
@@ -92,6 +83,10 @@
                       <object class="GtkSpinButton" id="autosave_spin">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Automatically save the project to 
an alternate file whenever
+the project is modified and the specified timeout elapses</property>
+                        <property name="halign">start</property>
+                        <property name="hexpand">False</property>
                         <property name="invisible_char">•</property>
                         <property name="numeric">True</property>
                       </object>
@@ -104,12 +99,14 @@
                     </child>
                     <child>
                       <object class="GtkCheckButton" id="autosave_toggle">
-                        <property name="label" translatable="yes">Autosave after timeout:</property>
+                        <property name="label" translatable="yes">Automatically save project after</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="tooltip_text" translatable="yes">Automatically save the project 
after the specified timeout passes
-whenever the project is modified</property>
+                        <property name="tooltip_text" translatable="yes">Automatically save the project to 
an alternate file whenever
+the project is modified and the specified timeout elapses</property>
+                        <property name="halign">start</property>
+                        <property name="hexpand">False</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
                         <signal name="toggled" handler="autosave_toggled" swapped="no"/>
@@ -135,9 +132,102 @@ whenever the project is modified</property>
                 </child>
               </object>
               <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="frame3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkGrid" id="grid3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">12</property>
+                    <property name="margin_top">6</property>
+                    <property name="row_spacing">2</property>
+                    <property name="column_spacing">12</property>
+                    <child>
+                      <object class="GtkCheckButton" id="versioning_toggle">
+                        <property name="label" translatable="yes">Versioning errors</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">Prompt the user at save time if the 
project uses any widgets, properties
+or signals which are not available in the project's target version</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">0</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="deprecations_toggle">
+                        <property name="label" translatable="yes">Deprecation warnings</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">Prompt the user at save time if the 
project uses any widgets,
+properties or signals which are deprecated</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="top_attach">0</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="unrecognized_toggle">
+                        <property name="label" translatable="yes">Unrecognized types</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">Prompt the user at save time if the 
project
+contains any unrecognized types</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="top_attach">1</property>
+                        <property name="width">1</property>
+                        <property name="height">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Show warnings when saving</property>
+                    <property name="use_markup">True</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
               </packing>
             </child>
             <child>
@@ -168,9 +258,7 @@ whenever the project is modified</property>
                             <property name="model">catalog_path_store</property>
                             <property name="headers_visible">False</property>
                             <child internal-child="selection">
-                              <object class="GtkTreeSelection" id="selection">
-                                <signal name="changed" handler="catalog_selection_changed" swapped="no"/>
-                              </object>
+                              <object class="GtkTreeSelection" id="selection"/>
                             </child>
                             <child>
                               <object class="GtkTreeViewColumn" id="column">
@@ -255,16 +343,43 @@ whenever the project is modified</property>
                 </child>
               </object>
               <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="preferences_close_button">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
+                <property name="position">2</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
             <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
           </packing>
         </child>
       </object>
diff --git a/src/glade-preferences.h b/src/glade-preferences.h
index 3d88d45..874855d 100644
--- a/src/glade-preferences.h
+++ b/src/glade-preferences.h
@@ -63,6 +63,10 @@ gboolean          glade_preferences_backup           (GladePreferences *prefs);
 gboolean          glade_preferences_autosave         (GladePreferences *prefs);
 gint              glade_preferences_autosave_seconds (GladePreferences *prefs);
 
+gboolean          glade_preferences_warn_versioning  (GladePreferences *prefs);
+gboolean          glade_preferences_warn_deprecations(GladePreferences *prefs);
+gboolean          glade_preferences_warn_unrecognized(GladePreferences *prefs);
+
 G_END_DECLS
 
 #endif /* __GLADE_PREFERENCES_H__ */
diff --git a/src/glade-window.c b/src/glade-window.c
index e197bdd..a4fa5bd 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -1148,6 +1148,7 @@ static gboolean
 do_save (GladeWindow *window, GladeProject *project, const gchar *path)
 {
   GError *error = NULL;
+  GladeVerifyFlags verify_flags = 0;
   gchar *display_path = g_strdup (path);
 
   if (glade_preferences_backup (window->priv->preferences) &&
@@ -1162,13 +1163,20 @@ do_save (GladeWindow *window, GladeProject *project, const gchar *path)
        }
     }
 
-  if (!glade_project_save (project, path, &error))
-    {
-      /* Reset path so future saves will prompt the file chooser */
-      glade_project_reset_path (project);
+  if (glade_preferences_warn_versioning (window->priv->preferences))
+    verify_flags |= GLADE_VERIFY_VERSIONS;
+  if (glade_preferences_warn_deprecations (window->priv->preferences))
+    verify_flags |= GLADE_VERIFY_DEPRECATIONS;
+  if (glade_preferences_warn_unrecognized (window->priv->preferences))
+    verify_flags |= GLADE_VERIFY_UNRECOGNIZED;
 
+  if (!glade_project_save_verify (project, path, verify_flags, &error))
+    {
       if (error)
         {
+         /* Reset path so future saves will prompt the file chooser */
+         glade_project_reset_path (project);
+
           glade_util_ui_message (GTK_WIDGET (window), GLADE_UI_ERROR, NULL,
                                  _("Failed to save %s: %s"),
                                  display_path, error->message);


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