[gcalctool] Lazy load the dialogs



commit f225c1feb58d90189460baf5dae2042c3caa86ec
Author: Robert Ancell <robert ancell gmail com>
Date:   Sat Apr 3 17:17:00 2010 +1100

    Lazy load the dialogs

 data/Makefile.am  |    1 +
 data/gcalctool.ui |  411 +----------------------------------------------------
 src/gtk.c         |  287 ++++++++++++++++++++-----------------
 3 files changed, 160 insertions(+), 539 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index f3dcf12..76502ef 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,6 +1,7 @@
 uidir = $(datadir)/gcalctool
 ui_DATA = \
 	gcalctool.ui \
+	dialogs.ui \
 	financial.ui
 
 schemadir   = @GCONF_SCHEMA_FILE_DIR@
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index 1664049..c43b124 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -2250,7 +2250,7 @@
                     <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
                   </packing>
                 </child>
-                <child>                
+                <child>
                   <object class="GtkButton" id="calc_percentage_button">
                     <property name="label">%</property>
                     <property name="visible">True</property>
@@ -2981,7 +2981,7 @@
                     <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
                   </packing>
                 </child>
-                <child>                
+                <child>
                   <object class="GtkButton" id="calc_modulus_divide_button">
                     <property name="label">mod</property>
                     <property name="visible">True</property>
@@ -4287,88 +4287,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkListStore" id="angle_unit_model">
-    <columns>
-      <!-- column-name label -->
-      <column type="gchararray"/>
-      <!-- column-name units -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes" comments="Preferences dialog: Angle unit combo box: Use degrees for trigonometric calculations">Degrees</col>
-        <col id="1">degrees</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Preferences dialog: Angle unit combo box: Use radians for trigonometric calculations">Radians</col>
-        <col id="1">radians</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Preferences dialog: Angle unit combo box: Use gradians for trigonometric calculations">Gradians</col>
-        <col id="1">gradians</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="display_format_model">
-    <columns>
-      <!-- column-name label -->
-      <column type="gchararray"/>
-      <!-- column-name format -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes" comments="Number display mode combo: Decimal, e.g. 1234">Decimal</col>
-        <col id="1">decimal</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Number display mode combo: Scientific, e.g. 1.234&#xD7;10^3">Scientific</col>
-        <col id="1">scientific</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Number display mode combo: Engineering, e.g. 1.234k">Engineering</col>
-        <col id="1">engineering</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Number display mode combo: Binary, e.g. 10011010010&#x2082;">Binary</col>
-        <col id="1">binary</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Number display mode combo: Octal, e.g. 2322&#x2088;">Octal</col>
-        <col id="1">octal</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Number display mode combo: Hexadecimal, e.g. 4D2&#x2081;&#x2086;">Hexadecimal</col>
-        <col id="1">hexadecimal</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="word_size_model">
-    <columns>
-      <!-- column-name label -->
-      <column type="gchararray"/>
-      <!-- column-name size -->
-      <column type="gint"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes" comments="Word size combo: 8 bits">8-bit</col>
-        <col id="1">8</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Word size combo: 16 bits">16-bit</col>
-        <col id="1">16</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Word size combo: 32 bits">32-bit</col>
-        <col id="1">32</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes" comments="Word size combo: 64 bits">64-bit</col>
-        <col id="1">64</col>
-      </row>
-    </data>
-  </object>
   <object class="GtkMenu" id="memory_store_popup">
     <child>
       <object class="GtkMenuItem" id="store_menu_item0">
@@ -4457,101 +4375,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkDialog" id="ascii_dialog">
-    <property name="border_width">6</property>
-    <property name="title" translatable="yes" comments="Title of insert ASCII dialog">Insert ASCII Value</property>
-    <property name="resizable">False</property>
-    <property name="type_hint">dialog</property>
-    <property name="has_separator">False</property>
-    <signal name="response" handler="ascii_dialog_response_cb"/>
-    <signal name="delete_event" handler="ascii_dialog_delete_cb"/>
-    <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox3">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkHBox" id="hbox21">
-            <property name="visible">True</property>
-            <property name="border_width">5</property>
-            <child>
-              <object class="GtkLabel" id="label39">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes" comments="Insert ASCII dialog: Label before character entry">Ch_aracter:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">ascii_entry</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEntry" id="ascii_entry">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="max_length">1</property>
-                <property name="invisible_char">&#x25CF;</property>
-                <signal name="activate" handler="ascii_dialog_activate_cb"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area3">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="button8">
-                <property name="label">gtk-cancel</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="button9">
-                <property name="label" translatable="yes" comments="Insert ASCII dialog: Button to insert selected character">_Insert</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_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</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>
-      <action-widget response="-6">button8</action-widget>
-      <action-widget response="-5">button9</action-widget>
-    </action-widgets>
-  </object>
   <object class="GtkTextBuffer" id="display_buffer"/>
   <object class="GtkAccelGroup" id="accelgroup1"/>
   <object class="GtkImage" id="image1">
@@ -4559,235 +4382,5 @@
     <property name="stock">gtk-help</property>
     <property name="icon-size">1</property>
   </object>
-  <object class="GtkDialog" id="preferences_dialog">
-    <property name="border_width">8</property>
-    <property name="title" translatable="yes">Preferences</property>
-    <property name="type_hint">normal</property>
-    <property name="has_separator">False</property>
-    <signal name="response" handler="preferences_response_cb"/>
-    <signal name="delete_event" handler="preferences_dialog_delete_cb"/>
-    <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox4">
-        <property name="visible">True</property>
-        <property name="spacing">5</property>
-        <child>
-          <object class="GtkTable" id="table1">
-            <property name="visible">True</property>
-            <property name="border_width">5</property>
-            <property name="n_rows">4</property>
-            <property name="n_columns">2</property>
-            <property name="column_spacing">6</property>
-            <property name="row_spacing">12</property>
-            <child>
-              <object class="GtkLabel" id="label8">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes" comments="Preferences dialog: Label for angle unit combo box">_Angle units:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">angle_unit_combobox</property>
-              </object>
-              <packing>
-                <property name="x_options">GTK_FILL</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="label9">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes" comments="Preferences dialog: Label for display format combo box">Display _Format:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">display_format_combobox</property>
-              </object>
-              <packing>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-                <property name="x_options">GTK_FILL</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBox" id="angle_unit_combobox">
-                <property name="visible">True</property>
-                <property name="model">angle_unit_model</property>
-                <signal name="changed" handler="angle_unit_combobox_changed_cb"/>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBox" id="display_format_combobox">
-                <property name="visible">True</property>
-                <property name="model">display_format_model</property>
-                <signal name="changed" handler="display_format_combobox_changed_cb"/>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="label11">
-                <property name="visible">True</property>
-                <property name="xalign">0</property>
-                <property name="label" translatable="yes" comments="Preferences dialog: label for word size combo box">Word _size:</property>
-                <property name="use_underline">True</property>
-                <property name="mnemonic_widget">word_size_combobox</property>
-              </object>
-              <packing>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
-                <property name="x_options">GTK_FILL</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkComboBox" id="word_size_combobox">
-                <property name="visible">True</property>
-                <property name="model">word_size_model</property>
-                <signal name="changed" handler="word_size_combobox_changed_cb"/>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkAlignment" id="alignment1">
-                <property name="visible">True</property>
-                <property name="bottom_padding">6</property>
-                <property name="left_padding">12</property>
-                <child>
-                  <object class="GtkTable" id="table2">
-                    <property name="visible">True</property>
-                    <property name="n_rows">3</property>
-                    <property name="row_spacing">6</property>
-                    <child>
-                      <object class="GtkCheckButton" id="trailing_zeroes_check">
-                        <property name="label" translatable="yes" comments="Preferences dialog: label for show trailing zeroes check button">Show trailing _zeroes</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="draw_indicator">True</property>
-                        <signal name="toggled" handler="trailing_zeroes_check_toggled_cb"/>
-                      </object>
-                      <packing>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkCheckButton" id="thousands_separator_check">
-                        <property name="label" translatable="yes" comments="Preferences dialog: label for show thousands separator check button">Show _thousands separators</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="draw_indicator">True</property>
-                        <signal name="toggled" handler="thousands_separator_check_toggled_cb"/>
-                      </object>
-                      <packing>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkHBox" id="hbox1">
-                        <property name="visible">True</property>
-                        <property name="spacing">6</property>
-                        <child>
-                          <object class="GtkLabel" id="decimal_places_label1">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" comments="Not translated by Gtk+, is translated as one string">Show</property>
-                            <property name="use_underline">True</property>
-                            <property name="mnemonic_widget">decimal_places_spin</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkSpinButton" id="decimal_places_spin">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="invisible_char">&#x25CF;</property>
-                            <property name="adjustment">decimal_places_adjustment</property>
-                            <signal name="value_changed" handler="decimal_places_spin_change_value_cb"/>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="decimal_places_label2">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" comments="Not translated by Gtk+, is translated as one string">decimal _places</property>
-                            <property name="use_underline">True</property>
-                            <property name="mnemonic_widget">decimal_places_spin</property>
-                          </object>
-                          <packing>
-                            <property name="position">2</property>
-                          </packing>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area4">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="button1">
-                <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">False</property>
-                <property name="position">0</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>
-      <action-widget response="0">button1</action-widget>
-    </action-widgets>
-  </object>
   <object class="GtkTextBuffer" id="info_buffer"/>
-  <object class="GtkAdjustment" id="decimal_places_adjustment">
-    <property name="upper">9</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">1</property>
-  </object>
 </interface>
diff --git a/src/gtk.c b/src/gtk.c
index 176220e..b5ac776 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -105,8 +105,9 @@ static char *finc_dialog_fields[][5] = {
     {NULL,        NULL,          NULL,         NULL,         NULL}
 };
 
-#define UI_FILE      UI_DIR "/gcalctool.ui"
-#define UI_FINC_FILE UI_DIR "/financial.ui"
+#define UI_FILE         UI_DIR "/gcalctool.ui"
+#define UI_FINC_FILE    UI_DIR "/financial.ui"
+#define UI_DIALOGS_FILE UI_DIR "/dialogs.ui"
 
 #define MAXBITS 64      /* Bit panel: number of bit fields. */
 
@@ -116,6 +117,10 @@ static char *finc_dialog_fields[][5] = {
           GTK_WIDGET(GET_OBJECT((name)))
 #define GET_FINC_WIDGET(name) \
           GTK_WIDGET(gtk_builder_get_object(X.financial, (name)))
+#define GET_DIALOG_OBJECT(name) \
+          gtk_builder_get_object(X.dialogs, (name))
+#define GET_DIALOG_WIDGET(name) \
+          GTK_WIDGET(gtk_builder_get_object(X.dialogs, (name)))
 
 /* Calculator modes. */
 typedef enum {
@@ -130,6 +135,7 @@ typedef struct {
     ModeType mode;  /* Current calculator mode. */
 
     GtkBuilder *ui;
+    GtkBuilder *dialogs;
     GtkBuilder *financial;
 
     GtkWidget *main_window;
@@ -567,6 +573,152 @@ about_cb(GtkWidget *widget)
 }
 
 
+static void
+set_combo_box_from_config(const gchar *name, const gchar *key_name, GType key_type)
+{
+    GtkWidget *combo;
+    GtkTreeModel *model;
+    gchar *str_key_value = NULL;
+    int int_key_value;
+    GtkTreeIter iter;
+    gboolean valid;
+
+    combo = GET_DIALOG_WIDGET(name);
+    model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
+    valid = gtk_tree_model_get_iter_first(model, &iter);
+
+    switch (key_type)
+    {
+    case G_TYPE_STRING:
+        str_key_value = get_resource(key_name);
+        if (!str_key_value)
+            valid = FALSE;
+        break;
+    case G_TYPE_INT:
+        if (!get_int_resource(key_name, &int_key_value))
+            valid = FALSE;
+        break;
+    default:
+        break;
+    }
+
+    while (valid) {
+        gchar *str_value;
+        gint int_value;
+        gboolean matched = FALSE;
+
+        switch (key_type)
+        {
+        case G_TYPE_STRING:
+            gtk_tree_model_get(model, &iter, 1, &str_value, -1);
+            matched = strcmp(str_value, str_key_value) == 0;
+            break;
+        case G_TYPE_INT:
+            gtk_tree_model_get(model, &iter, 1, &int_value, -1);
+            matched = int_value == int_key_value;
+            break;
+        default:
+            break;
+        }
+
+        if (matched)
+            break;
+
+        valid = gtk_tree_model_iter_next(model, &iter);
+    }
+    if (!valid)
+        valid = gtk_tree_model_get_iter_first(model, &iter);
+
+    gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
+
+    g_free(str_key_value);
+}
+
+
+static void
+create_dialogs()
+{
+    GtkWidget *widget;
+    GtkCellRenderer *renderer;
+    gchar *string, **tokens;
+    int value;
+  
+    if (X.dialogs)
+        return;
+  
+    X.dialogs = gtk_builder_new();
+    load_ui(X.dialogs, UI_DIALOGS_FILE);
+
+    X.ascii_dialog = GET_DIALOG_WIDGET("ascii_dialog");
+    X.ascii_entry = GET_DIALOG_WIDGET("ascii_entry");
+
+    /* Make dialogs transient of the main window */
+    gtk_window_set_transient_for(GTK_WINDOW(X.ascii_dialog), GTK_WINDOW(X.main_window));
+
+    X.preferences_dialog = GET_DIALOG_WIDGET("preferences_dialog");
+
+    /* Configuration dialog */
+
+    widget = GET_DIALOG_WIDGET("angle_unit_combobox");
+    renderer = gtk_cell_renderer_text_new();
+    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
+    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(widget), renderer, "text", 0);
+
+    widget = GET_DIALOG_WIDGET("display_format_combobox");
+    renderer = gtk_cell_renderer_text_new();
+    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
+    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(widget), renderer, "text", 0);
+
+    widget = GET_DIALOG_WIDGET("word_size_combobox");
+    renderer = gtk_cell_renderer_text_new();
+    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
+    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(widget), renderer, "text", 0);
+
+    /* Label used in preferences dialog.  The %d is replaced by a spinbutton */
+    string = _("Show %d decimal _places");
+    tokens = g_strsplit(string, "%d", 2);
+    widget = GET_DIALOG_WIDGET("decimal_places_label1");
+    if (tokens[0])
+        string = g_strstrip(tokens[0]);
+    else
+        string = "";
+    if (string[0] != '\0')
+        gtk_label_set_text_with_mnemonic(GTK_LABEL(widget), string);
+    else
+        gtk_widget_hide(widget);
+
+    widget = GET_DIALOG_WIDGET("decimal_places_label2");
+    if (tokens[0] && tokens[1])
+        string = g_strstrip(tokens[1]);
+    else
+        string = "";
+    if (string[0] != '\0')
+        gtk_label_set_text_with_mnemonic(GTK_LABEL(widget), string);
+    else
+        gtk_widget_hide(widget);
+
+    g_strfreev(tokens);
+
+    set_combo_box_from_config("angle_unit_combobox", R_TRIG, G_TYPE_STRING);
+    set_combo_box_from_config("display_format_combobox", R_DISPLAY, G_TYPE_STRING);
+    set_combo_box_from_config("word_size_combobox", R_WORDLEN, G_TYPE_INT);
+
+    if (!get_int_resource(R_ACCURACY, &value))
+        value = 9;
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(GET_DIALOG_OBJECT("decimal_places_spin")), value);
+
+    if (!get_boolean_resource(R_TSEP, &value))
+        value = FALSE;
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(GET_DIALOG_OBJECT("thousands_separator_check")), value);
+
+    if (!get_boolean_resource(R_ZEROES, &value))
+        value = FALSE;
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(GET_DIALOG_OBJECT("trailing_zeroes_check")), value);
+
+    gtk_builder_connect_signals(X.dialogs, NULL);
+}
+
+
 G_MODULE_EXPORT
 void
 ascii_dialog_response_cb(GtkWidget *dialog, gint response_id)
@@ -1543,6 +1695,8 @@ G_MODULE_EXPORT
 void
 insert_ascii_cb(GtkWidget *widget)
 {
+    create_dialogs();
+  
     if (!gtk_widget_get_visible(X.ascii_dialog))
         position_popup(X.main_window, X.ascii_dialog, POPUP_LEFT);
     gtk_widget_grab_focus(GTK_WIDGET(X.ascii_entry));
@@ -1584,6 +1738,7 @@ G_MODULE_EXPORT
 void
 show_preferences_cb(GtkMenuItem *menu)
 {
+    create_dialogs();
     gtk_window_present(GTK_WINDOW(X.preferences_dialog));
 }
 
@@ -1622,7 +1777,6 @@ set_tint (GtkWidget *widget, GdkColor *tint, gint alpha)
     }
 }
 
-
 static void
 create_main_window()
 {
@@ -1631,7 +1785,6 @@ create_main_window()
     GtkWidget *widget;
     PangoFontDescription *font_desc;
     GtkCellRenderer *renderer;
-    gchar *string, **tokens;
     GdkColor colour_numbers, colour_action, colour_operator, colour_function, colour_memory, colour_trig, colour_group;
 
     X.ui = gtk_builder_new();
@@ -1641,8 +1794,6 @@ create_main_window()
     X.clipboard_atom   = gdk_atom_intern("CLIPBOARD", FALSE);
     X.primary_atom     = gdk_atom_intern("PRIMARY", FALSE);
     X.main_window      = GET_WIDGET("calc_window");
-    X.ascii_dialog     = GET_WIDGET("ascii_dialog");
-    X.ascii_entry      = GET_WIDGET("ascii_entry");
     X.menubar          = GET_WIDGET("menubar");
     X.scrolledwindow   = GET_WIDGET("display_scroll"),
     X.display_item     = GET_WIDGET("displayitem"),
@@ -1654,7 +1805,6 @@ create_main_window()
     X.bit_panel        = GET_WIDGET("bit_panel");
     X.superscript_toggle = GET_WIDGET("superscript_togglebutton");
     X.subscript_toggle   = GET_WIDGET("subscript_togglebutton");
-    X.preferences_dialog = GET_WIDGET("preferences_dialog");
     X.info_buffer = GTK_TEXT_BUFFER(GET_OBJECT("info_buffer"));
 
     /* Connect text to buttons */
@@ -1797,9 +1947,6 @@ create_main_window()
         set_int_data(X.ui, name, "bit_index", i);
     }
 
-    /* Make dialogs transient of the main window */
-    gtk_window_set_transient_for(GTK_WINDOW(X.ascii_dialog), GTK_WINDOW(X.main_window));
-
     X.display_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(X.display_item));
     gtk_widget_ensure_style(X.display_item);
     font_desc = pango_font_description_copy(gtk_widget_get_style(X.display_item)->font_desc);
@@ -1835,48 +1982,6 @@ create_main_window()
     set_data(X.ui, "calc_finc_straight_line_depreciation_button", "finc_dialog", "sln_dialog");
     set_data(X.ui, "calc_finc_sum_of_the_years_digits_depreciation_button", "finc_dialog", "syd_dialog");
     set_data(X.ui, "calc_finc_term_button", "finc_dialog", "term_dialog");
-
-    /* Configuration dialog */
-
-    widget = GET_WIDGET("angle_unit_combobox");
-    renderer = gtk_cell_renderer_text_new();
-    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
-    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(widget), renderer, "text", 0);
-
-    widget = GET_WIDGET("display_format_combobox");
-    renderer = gtk_cell_renderer_text_new();
-    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
-    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(widget), renderer, "text", 0);
-
-    widget = GET_WIDGET("word_size_combobox");
-    renderer = gtk_cell_renderer_text_new();
-    gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE);
-    gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(widget), renderer, "text", 0);
-
-    /* Label used in preferences dialog.  The %d is replaced by a spinbutton */
-    string = _("Show %d decimal _places");
-    tokens = g_strsplit(string, "%d", 2);
-    widget = GET_WIDGET("decimal_places_label1");
-    if (tokens[0])
-        string = g_strstrip(tokens[0]);
-    else
-        string = "";
-    if (string[0] != '\0')
-        gtk_label_set_text_with_mnemonic(GTK_LABEL(widget), string);
-    else
-        gtk_widget_hide(widget);
-
-    widget = GET_WIDGET("decimal_places_label2");
-    if (tokens[0] && tokens[1])
-        string = g_strstrip(tokens[1]);
-    else
-        string = "";
-    if (string[0] != '\0')
-        gtk_label_set_text_with_mnemonic(GTK_LABEL(widget), string);
-    else
-        gtk_widget_hide(widget);
-
-    g_strfreev(tokens);
 }
 
 
@@ -2022,68 +2127,6 @@ trailing_zeroes_check_toggled_cb(GtkWidget *check)
 }
 
 
-static void
-set_combo_box_from_config(const gchar *name, const gchar *key_name, GType key_type)
-{
-    GtkWidget *combo;
-    GtkTreeModel *model;
-    gchar *str_key_value = NULL;
-    int int_key_value;
-    GtkTreeIter iter;
-    gboolean valid;
-
-    combo = GET_WIDGET(name);
-    model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
-    valid = gtk_tree_model_get_iter_first(model, &iter);
-
-    switch (key_type)
-    {
-    case G_TYPE_STRING:
-        str_key_value = get_resource(key_name);
-        if (!str_key_value)
-            valid = FALSE;
-        break;
-    case G_TYPE_INT:
-        if (!get_int_resource(key_name, &int_key_value))
-            valid = FALSE;
-        break;
-    default:
-        break;
-    }
-
-    while (valid) {
-        gchar *str_value;
-        gint int_value;
-        gboolean matched = FALSE;
-
-        switch (key_type)
-        {
-        case G_TYPE_STRING:
-            gtk_tree_model_get(model, &iter, 1, &str_value, -1);
-            matched = strcmp(str_value, str_key_value) == 0;
-            break;
-        case G_TYPE_INT:
-            gtk_tree_model_get(model, &iter, 1, &int_value, -1);
-            matched = int_value == int_key_value;
-            break;
-        default:
-            break;
-        }
-
-        if (matched)
-            break;
-
-        valid = gtk_tree_model_iter_next(model, &iter);
-    }
-    if (!valid)
-        valid = gtk_tree_model_get_iter_first(model, &iter);
-
-    gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
-
-    g_free(str_key_value);
-}
-
-
 void
 ui_load(void)
 {
@@ -2092,22 +2135,6 @@ ui_load(void)
     /* Create main gcalctool window. */
     create_main_window();
     ui_set_undo_enabled(FALSE, FALSE);
-
-    set_combo_box_from_config("angle_unit_combobox", R_TRIG, G_TYPE_STRING);
-    set_combo_box_from_config("display_format_combobox", R_DISPLAY, G_TYPE_STRING);
-    set_combo_box_from_config("word_size_combobox", R_WORDLEN, G_TYPE_INT);
-
-    if (!get_int_resource(R_ACCURACY, &value))
-        value = 9;
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(GET_OBJECT("decimal_places_spin")), value);
-
-    if (!get_boolean_resource(R_TSEP, &value))
-        value = FALSE;
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(GET_OBJECT("thousands_separator_check")), value);
-
-    if (!get_boolean_resource(R_ZEROES, &value))
-        value = FALSE;
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(GET_OBJECT("trailing_zeroes_check")), value);
 }
 
 



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