[glom] Script Library: Prevent a crash when opening the dialog.



commit 2d6befd23b734cdc9c7f570d08c0357f254a5952
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Sep 9 09:17:50 2011 +0200

    Script Library: Prevent a crash when opening the dialog.
    
    * ui/developer/dialog_script_library.glade: Change the GtkComboBox to a
    GtkComboBoxText as intended, to prevent a crash when it has no model.
    * glom/utility_widgets/combo_textglade.[h|cc]: Add a check that there is a
    model.

 ChangeLog                                |    9 +++
 glom/utility_widgets/combo_textglade.cc  |    6 ++
 glom/utility_widgets/combo_textglade.h   |    1 +
 ui/developer/dialog_script_library.glade |  116 +++++++++++++++++-------------
 4 files changed, 83 insertions(+), 49 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 119a9dc..5c020a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-09-09  Murray Cumming  <murrayc murrayc com>
+
+	Script Library: Prevent a crash when opening the dialog.
+
+	* ui/developer/dialog_script_library.glade: Change the GtkComboBox to a 
+	GtkComboBoxText as intended, to prevent a crash when it has no model.
+	* glom/utility_widgets/combo_textglade.[h|cc]: Add a check that there is a 
+	model.
+
 2011-09-08  Murray Cumming  <murrayc murrayc com>
 
 	DataWidget: Do not expand the Open and Find buttons.
diff --git a/glom/utility_widgets/combo_textglade.cc b/glom/utility_widgets/combo_textglade.cc
index 344a73c..12cbee2 100644
--- a/glom/utility_widgets/combo_textglade.cc
+++ b/glom/utility_widgets/combo_textglade.cc
@@ -26,11 +26,17 @@ namespace Glom
 Combo_TextGlade::Combo_TextGlade(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& /* builder */)
 : Gtk::ComboBoxText(cobject)
 {
+  //Check that this was really created from a GtkComboBoxText in the .glade file,
+  //instead of just a GtkComboBox, which would not usually have a model.
+  g_assert(get_model());
 }
 
 void Combo_TextGlade::set_first_active()
 {
   Glib::RefPtr<Gtk::TreeModel> model = get_model();
+  if(!model)
+    return;
+
   Gtk::TreeModel::iterator iter = model->children().begin();
   set_active(iter);
 }
diff --git a/glom/utility_widgets/combo_textglade.h b/glom/utility_widgets/combo_textglade.h
index 041ee11..2ddca63 100644
--- a/glom/utility_widgets/combo_textglade.h
+++ b/glom/utility_widgets/combo_textglade.h
@@ -30,6 +30,7 @@ namespace Glom
 {
 
 /** This class just derives from Gtk::ComboBoxText and provides a constuctor suitable for libglade's get_widget_derived() template.
+ * TODO: Remove this now that GtkComboBoxText is a real class that can be instantiated from Glade?
  */
 class Combo_TextGlade : public Gtk::ComboBoxText
 {
diff --git a/ui/developer/dialog_script_library.glade b/ui/developer/dialog_script_library.glade
index d946ca8..1b4afcd 100644
--- a/ui/developer/dialog_script_library.glade
+++ b/ui/developer/dialog_script_library.glade
@@ -1,27 +1,73 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-requires gtksourceview 0.0 -->
-  <!-- interface-naming-policy toplevel-contextual -->
-
   <object class="GtkDialog" id="dialog_script_library">
+    <property name="can_focus">False</property>
     <property name="title" translatable="yes">Script Library</property>
     <property name="default_width">500</property>
     <property name="default_height">600</property>
     <property name="type_hint">dialog</property>
     <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox32">
+      <object class="GtkBox" id="dialog-vbox32">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area32">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="helpbutton1">
+                <property name="label">gtk-help</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="okbutton5">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</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="GtkVBox" id="vbox1">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="border_width">6</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
               <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">These modules will be available to your button scripts and field calculations via the python import keyword.</property>
                 <property name="wrap">True</property>
@@ -35,22 +81,28 @@
             <child>
               <object class="GtkHBox" id="hbox1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkLabel" id="label2">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">Module name:</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
+                    <property name="fill">True</property>
                     <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkComboBox" id="combobox_name">
+                  <object class="GtkComboBoxText" id="combobox_name">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                   </object>
                   <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
                     <property name="position">1</property>
                   </packing>
                 </child>
@@ -60,6 +112,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="receives_default">False</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="use_stock">True</property>
                   </object>
                   <packing>
@@ -74,6 +127,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="receives_default">False</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="use_stock">True</property>
                   </object>
                   <packing>
@@ -85,6 +139,7 @@
               </object>
               <packing>
                 <property name="expand">False</property>
+                <property name="fill">True</property>
                 <property name="padding">6</property>
                 <property name="position">1</property>
               </packing>
@@ -93,8 +148,6 @@
               <object class="GtkScrolledWindow" id="scrolledwindow2">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="hscrollbar_policy">automatic</property>
-                <property name="vscrollbar_policy">automatic</property>
                 <property name="shadow_type">in</property>
                 <child>
                   <object class="GtkSourceView" id="textview_script">
@@ -106,12 +159,15 @@
                 </child>
               </object>
               <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
                 <property name="position">2</property>
               </packing>
             </child>
             <child>
               <object class="GtkHButtonBox" id="hbuttonbox1">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="layout_style">end</property>
                 <child>
                   <object class="GtkButton" id="button_check">
@@ -120,6 +176,7 @@
                     <property name="can_focus">True</property>
                     <property name="can_default">True</property>
                     <property name="receives_default">False</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="use_underline">True</property>
                   </object>
                   <packing>
@@ -137,50 +194,11 @@
             </child>
           </object>
           <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area32">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="helpbutton1">
-                <property name="label">gtk-help</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="okbutton5">
-                <property name="label">gtk-ok</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
       </object>
     </child>
     <action-widgets>



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