[Glade-devel] [patch, glade3] move query_property functions



--=-OlMqSzfct/m4ODKXB6C6
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

IMHO the dialog that query the user for the property of a widget (e.g
how many rows should have a vbox) belongs to glade-widget.c not to
glade-project-window.c, as a matter of fact glade-widget is the only
place where the function is called.

The attached patch moves the dialog code from glade-project-window.c to
glade-widget. While at it I removed the separator from the dialog since
AFAIK is what the HIG suggest.

ciao
        paolo

--=-OlMqSzfct/m4ODKXB6C6
Content-Disposition: attachment; filename=move_query_properties.patch
Content-Type: text/x-patch; name=move_query_properties.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog     2003-04-18 12:37:36.000000000 +0200
+++ glade3/ChangeLog    2003-04-18 18:37:40.000000000 +0200
@@ -1,3 +1,9 @@
+2003-04-18  Paolo Borelli <pborelli katamail com>
+
+       * src/glade-widget.c: move here the query_property functions
+       * src/glade-project-window.[ch]: removed the above, those functione 
+       belong to glade-widget.c
+
 2003-04-17  Joaquin Cuenca Abela  <e98cuenc yahoo com>
 
        * src/glade-project-window.c: modify the confirmation dialog on quit
diff -upr gnome2/glade3/src/glade-project-window.c glade3/src/glade-project-window.c
--- gnome2/glade3/src/glade-project-window.c    2003-04-18 12:37:38.000000000 +0200
+++ glade3/src/glade-project-window.c   2003-04-18 18:32:23.000000000 +0200
@@ -31,7 +31,6 @@
 #include "glade-clipboard-view.h"
 #include "glade-widget.h"
 #include "glade-widget-class.h"
-#include "glade-parameter.h"
 #include "glade-property.h"
 #include "glade-property-class.h"
 #include "glade-project.h"
@@ -1130,129 +1129,6 @@ glade_project_window_set_add_class (Glad
        
 }
 
-static GtkWidget *
-glade_project_append_query (GtkWidget *table, GladePropertyClass *property_class, gint row)
-{
-       GladePropertyQuery *query;
-       GtkAdjustment *adjustment;
-       GtkWidget *label;
-       GtkWidget *spin;
-       gchar *text;
-
-       query = property_class->query;
-       
-       if (property_class->type != GLADE_PROPERTY_TYPE_INTEGER) {
-               g_warning ("We can only query integer types for now. Trying to query %d. FIXME please ;-)", 
property_class->type);
-               return NULL;
-       }
-       
-       /* Label */
-       text = g_strdup_printf ("%s :", query->question);
-       label = gtk_label_new (text);
-       g_free (text);
-       gtk_widget_show (label);
-       gtk_table_attach_defaults (GTK_TABLE (table), label,
-                                  0, 1, row, row +1);
-
-       /* Spin/Entry */
-       adjustment = glade_parameter_adjustment_new (property_class->parameters, property_class->def);
-       spin = gtk_spin_button_new (adjustment, 1, 0);
-       gtk_widget_show (spin);
-       gtk_table_attach_defaults (GTK_TABLE (table), spin,
-                                  1, 2, row, row +1);
-
-       return spin;
-}
-
-void
-glade_project_window_query_properties_set (gpointer key_,
-                                          gpointer value_,
-                                          gpointer user_data)
-{
-       GladePropertyQueryResult *result = user_data;
-       GtkWidget *spin = value_;
-       const gchar *key = key_;
-       gint num;
-
-       num = (gint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin));
-       glade_property_query_result_set_int (result, key, num);
-}
-
-/**
- * glade_project_window_query_properties:
- * @class: 
- * @result: 
- * 
- * Queries the user for some property values before a GladeWidget creation
- * for example before creating a GtkVBox we want to ask the user the number
- * of columns he wants.
- * 
- * Return Value: FALSE if the query was canceled
- **/
-gboolean 
-glade_project_window_query_properties (GladeWidgetClass *class,
-                                      GladePropertyQueryResult *result)
-{
-       GladePropertyClass *property_class;
-       GHashTable *hash;
-       GtkWidget *dialog;
-       GtkWidget *table;
-       GtkWidget *vbox;
-       GtkWidget *spin = NULL;
-       GList *list;
-       gint response;
-       gint row = 0;
-
-       g_return_val_if_fail (class  != NULL, FALSE);
-       g_return_val_if_fail (result != NULL, FALSE);
-
-       dialog = gtk_dialog_new_with_buttons (NULL /* name */,
-                                             NULL /* parent, FIXME: parent should be the project window */,
-                                             GTK_DIALOG_MODAL,
-                                             GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
-                                             GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
-                                             NULL);
-       gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);       
-       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);     
-
-       vbox = GTK_DIALOG (dialog)->vbox;
-       table = gtk_table_new (0, 0, FALSE);
-       gtk_widget_show (table);
-       gtk_box_pack_start_defaults (GTK_BOX (vbox), table);
-       
-       hash = g_hash_table_new (g_str_hash, g_str_equal);
-
-       list = class->properties;
-       for (; list != NULL; list = list->next) {
-               property_class = list->data;
-               if (property_class->query) {
-                       spin = glade_project_append_query (table, property_class, row++);
-                       g_hash_table_insert (hash, property_class->id, spin);
-               }
-       }
-       if (spin == NULL)
-               return TRUE;
-
-       response = gtk_dialog_run (GTK_DIALOG (dialog));
-       switch (response) {
-       case GTK_RESPONSE_ACCEPT:
-               g_hash_table_foreach (hash,
-                                     glade_project_window_query_properties_set,
-                                     result);
-               break;
-       case GTK_RESPONSE_REJECT:
-               gtk_widget_destroy (dialog);
-               return TRUE;
-       default:
-               g_warning ("Dunno what to do, unexpected GtkResponse");
-       }
-
-       g_hash_table_destroy (hash);
-       gtk_widget_destroy (dialog);
-       
-       return FALSE;
-}
-
 GladeProject *
 glade_project_window_get_project (void)
 {
diff -upr gnome2/glade3/src/glade-project-window.h glade3/src/glade-project-window.h
--- gnome2/glade3/src/glade-project-window.h    2003-04-03 18:44:47.000000000 +0200
+++ glade3/src/glade-project-window.h   2003-04-18 18:24:19.000000000 +0200
@@ -69,9 +69,6 @@ void glade_project_window_add_project   
 void glade_project_window_refresh_undo_redo   (GladeProjectWindow *gpw);
 void glade_project_window_refresh_title       (GladeProjectWindow *gpw);
 
-gboolean glade_project_window_query_properties (GladeWidgetClass *class,
-                                               GladePropertyQueryResult *result);
-
 G_END_DECLS
 
 #endif /* __GLADE_PROJECT_WINDOW_H__ */
diff -upr gnome2/glade3/src/glade-widget.c glade3/src/glade-widget.c
--- gnome2/glade3/src/glade-widget.c    2003-04-03 18:44:57.000000000 +0200
+++ glade3/src/glade-widget.c   2003-04-18 18:32:21.000000000 +0200
@@ -28,6 +28,7 @@
 #include "glade-placeholder.h"
 #include "glade-project.h"
 #include "glade-project-window.h"
+#include "glade-parameter.h"
 #include "glade-property.h"
 #include "glade-property-class.h"
 #include "glade-popup.h"
@@ -791,6 +792,132 @@ glade_widget_new_full (GladeProject *pro
        return widget;
 }
 
+static GtkWidget *
+glade_widget_append_query (GtkWidget *table,
+                          GladePropertyClass *property_class,
+                          gint row)
+{
+       GladePropertyQuery *query;
+       GtkAdjustment *adjustment;
+       GtkWidget *label;
+       GtkWidget *spin;
+       gchar *text;
+
+       query = property_class->query;
+       
+       if (property_class->type != GLADE_PROPERTY_TYPE_INTEGER) {
+               g_warning ("We can only query integer types for now. Trying to query %d. FIXME please ;-)", 
property_class->type);
+               return NULL;
+       }
+       
+       /* Label */
+       text = g_strdup_printf ("%s :", query->question);
+       label = gtk_label_new (text);
+       g_free (text);
+       gtk_widget_show (label);
+       gtk_table_attach_defaults (GTK_TABLE (table), label,
+                                  0, 1, row, row +1);
+
+       /* Spin/Entry */
+       adjustment = glade_parameter_adjustment_new (property_class->parameters, property_class->def);
+       spin = gtk_spin_button_new (adjustment, 1, 0);
+       gtk_widget_show (spin);
+       gtk_table_attach_defaults (GTK_TABLE (table), spin,
+                                  1, 2, row, row +1);
+
+       return spin;
+}
+
+void
+glade_widget_query_properties_set (gpointer key_,
+                                  gpointer value_,
+                                  gpointer user_data)
+{
+       GladePropertyQueryResult *result = user_data;
+       GtkWidget *spin = value_;
+       const gchar *key = key_;
+       gint num;
+
+       num = (gint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin));
+       glade_property_query_result_set_int (result, key, num);
+}
+
+/**
+ * glade_widget_query_properties:
+ * @class: 
+ * @result: 
+ * 
+ * Queries the user for some property values before a GladeWidget creation
+ * for example before creating a GtkVBox we want to ask the user the number
+ * of columns he wants.
+ * 
+ * Return Value: FALSE if the query was canceled
+ **/
+gboolean 
+glade_widget_query_properties (GladeWidgetClass *class,
+                              GladePropertyQueryResult *result)
+{
+       GladePropertyClass *property_class;
+       GHashTable *hash;
+       GtkWidget *dialog;
+       GtkWidget *table;
+       GtkWidget *vbox;
+       GtkWidget *spin = NULL;
+       GList *list;
+       gint response;
+       gint row = 0;
+
+       g_return_val_if_fail (class  != NULL, FALSE);
+       g_return_val_if_fail (result != NULL, FALSE);
+
+       dialog = gtk_dialog_new_with_buttons (NULL /* name */,
+                                             NULL /* parent, FIXME: parent should be the project window */,
+                                             GTK_DIALOG_MODAL,
+                                             GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                                             GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+                                             NULL);
+       gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+       gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);       
+       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);     
+
+       vbox = GTK_DIALOG (dialog)->vbox;
+       table = gtk_table_new (0, 0, FALSE);
+       gtk_widget_show (table);
+       gtk_box_pack_start_defaults (GTK_BOX (vbox), table);
+       
+       hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+       list = class->properties;
+       for (; list != NULL; list = list->next) {
+               property_class = list->data;
+               if (property_class->query) {
+                       spin = glade_widget_append_query (table, property_class, row++);
+                       g_hash_table_insert (hash, property_class->id, spin);
+               }
+       }
+       if (spin == NULL)
+               return TRUE;
+
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+       switch (response) {
+       case GTK_RESPONSE_ACCEPT:
+               g_hash_table_foreach (hash,
+                                     glade_widget_query_properties_set,
+                                     result);
+               break;
+       case GTK_RESPONSE_REJECT:
+               gtk_widget_destroy (dialog);
+               return TRUE;
+       default:
+               g_warning ("Dunno what to do, unexpected GtkResponse");
+       }
+
+       g_hash_table_destroy (hash);
+       gtk_widget_destroy (dialog);
+       
+       return FALSE;
+}
+
 /**
  * glade_widget_new_from_class_full:
  * @project: 
@@ -804,7 +931,9 @@ glade_widget_new_full (GladeProject *pro
  * Return Value: A newly creatred GladeWidget, NULL on user cancel or error    
  **/
 static GladeWidget *
-glade_widget_new_from_class_full (GladeWidgetClass *class, GladeProject *project, GladeWidget *parent)
+glade_widget_new_from_class_full (GladeWidgetClass *class,
+                                 GladeProject *project,
+                                 GladeWidget *parent)
 {
        GladePropertyQueryResult *result = NULL;
        GladeWidget *widget;
@@ -814,7 +943,7 @@ glade_widget_new_from_class_full (GladeW
 
        if (glade_widget_class_has_queries (class)) {
                result = glade_property_query_result_new ();
-               if (glade_project_window_query_properties (class, result))
+               if (glade_widget_query_properties (class, result))
                        return NULL;
        }
 

--=-OlMqSzfct/m4ODKXB6C6--





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