[glom] Field Definition: Move Default formatting into a separate window.



commit 2bb23a44dd615a167d19ae83cbfd1cadb9ba1866
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Oct 27 15:30:50 2013 +0100

    Field Definition: Move Default formatting into a separate window.
    
    * glom/mode_dsign/fields/dialog_fielddefinition.[h|cc]:
    * data/ui/developer/window_field_definition_edit.glade:
      Move the Default Formatting notebook tab into:
    * glom/mode_design/fields/dialog_defaultformatting.[h|cc]:
    * data/ui/developer/window_default_formatting.glade:
    
    * glom/utility_widgets/adddel/adddel.[h|cc]:
      Add signal_user_requested_extra.
    * glom/utility_widgets/adddel/adddel_withbuttons.[h|cc]:
      Add set_edit_button_label() and set_extra_button_label()
      and override show_all_vfunc() to not show the extra button if
      it has no label.
    
    * glom/mode_design/fields/box_db_table_definition.[h|cc]:
      Use the new button to show the new dialog.

 Makefile.am                                        |    1 +
 Makefile_glom.am                                   |    2 +
 data/glom.gresource.xml                            |    1 +
 data/ui/developer/box_formatting.glade             |   11 +--
 data/ui/developer/window_default_formatting.glade  |   81 ++++++++++++++++
 .../developer/window_field_definition_edit.glade   |   26 -----
 glom/mode_design/fields/box_db_table_definition.cc |   82 +++++++++++++---
 glom/mode_design/fields/box_db_table_definition.h  |   14 ++-
 .../mode_design/fields/dialog_defaultformatting.cc |  101 ++++++++++++++++++++
 glom/mode_design/fields/dialog_defaultformatting.h |   64 ++++++++++++
 glom/mode_design/fields/dialog_fielddefinition.cc  |   32 +------
 glom/utility_widgets/adddel/adddel.cc              |    6 +-
 glom/utility_widgets/adddel/adddel.h               |    8 ++
 glom/utility_widgets/adddel/adddel_withbuttons.cc  |   76 +++++++++++++--
 glom/utility_widgets/adddel/adddel_withbuttons.h   |   18 ++++
 15 files changed, 430 insertions(+), 93 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 1793b5b..008bac6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -140,6 +140,7 @@ EXTRA_DIST += \
        data/ui/developer/window_button_script.glade \
        data/ui/developer/window_data_layout_export.glade \
        data/ui/developer/window_data_layout.glade \
+       data/ui/developer/window_default_formatting.glade \
        data/ui/developer/window_design.glade \
        data/ui/developer/window_field_calculation.glade \
        data/ui/developer/window_field_definition_edit.glade \
diff --git a/Makefile_glom.am b/Makefile_glom.am
index 27e7a6a..1d6b551 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -298,6 +298,8 @@ glom_source_files +=                                                        \
        glom/mode_design/fields/box_db_table_definition.h               \
        glom/mode_design/fields/combo_fieldtype.cc                      \
        glom/mode_design/fields/combo_fieldtype.h                       \
+       glom/mode_design/fields/dialog_defaultformatting.cc             \
+       glom/mode_design/fields/dialog_defaultformatting.h              \
        glom/mode_design/fields/dialog_fieldcalculation.cc              \
        glom/mode_design/fields/dialog_fieldcalculation.h               \
        glom/mode_design/fields/dialog_fielddefinition.cc               \
diff --git a/data/glom.gresource.xml b/data/glom.gresource.xml
index 051e1da..a064c46 100644
--- a/data/glom.gresource.xml
+++ b/data/glom.gresource.xml
@@ -28,6 +28,7 @@
     <file preprocess="xml-stripblanks">data/ui/developer/window_button_script.glade</file>
     <file preprocess="xml-stripblanks">data/ui/developer/window_data_layout_export.glade</file>
     <file preprocess="xml-stripblanks">data/ui/developer/window_data_layout.glade</file>
+    <file preprocess="xml-stripblanks">data/ui/developer/window_default_formatting.glade</file>
     <file preprocess="xml-stripblanks">data/ui/developer/window_design.glade</file>
     <file preprocess="xml-stripblanks">data/ui/developer/window_field_calculation.glade</file>
     <file preprocess="xml-stripblanks">data/ui/developer/window_field_definition_edit.glade</file>
diff --git a/data/ui/developer/box_formatting.glade b/data/ui/developer/box_formatting.glade
index b983617..b1470bf 100644
--- a/data/ui/developer/box_formatting.glade
+++ b/data/ui/developer/box_formatting.glade
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.0 on Fri Oct 25 11:09:31 2013 -->
+<!-- Generated with glade 3.15.4 on Sun Oct 27 15:01:29 2013 -->
 <interface>
   <!-- interface-requires gtk+ 3.6 -->
   <object class="GtkWindow" id="window_formatting">
@@ -148,7 +148,7 @@
               <object class="GtkLabel" id="label10">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">&lt;b&gt;Numeric Formatting&lt;/b&gt;</property>
+                <property name="label" translatable="yes">Numeric Formatting</property>
                 <property name="use_markup">True</property>
               </object>
               <packing>
@@ -396,7 +396,7 @@
               <object class="GtkLabel" id="label5">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">&lt;b&gt;Text Formatting&lt;/b&gt;</property>
+                <property name="label" translatable="yes">Text Formatting</property>
                 <property name="use_markup">True</property>
               </object>
               <packing>
@@ -669,9 +669,6 @@
                                 <child>
                                   <placeholder/>
                                 </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
                               </object>
                             </child>
                           </object>
@@ -796,7 +793,7 @@
               <object class="GtkLabel" id="label9">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="label" translatable="yes">&lt;b&gt;Choices&lt;/b&gt;</property>
+                <property name="label" translatable="yes">Choices</property>
                 <property name="use_markup">True</property>
               </object>
               <packing>
diff --git a/data/ui/developer/window_default_formatting.glade 
b/data/ui/developer/window_default_formatting.glade
new file mode 100644
index 0000000..d16c00a
--- /dev/null
+++ b/data/ui/developer/window_default_formatting.glade
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.15.4 on Sun Oct 27 14:36:19 2013 -->
+<interface>
+  <!-- interface-requires gtk+ 3.6 -->
+  <object class="GtkWindow" id="window_default_formatting">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="title" translatable="yes">Default Formatting</property>
+    <property name="window_position">center-on-parent</property>
+    <child>
+      <object class="GtkBox" id="vbox11">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkBox" id="box_formatting_placeholder">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButtonBox" id="hbuttonbox8">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">6</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button_cancel">
+                <property name="label">gtk-cancel</property>
+                <property name="use_action_appearance">False</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="button_save">
+                <property name="label">gtk-save</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_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">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/data/ui/developer/window_field_definition_edit.glade 
b/data/ui/developer/window_field_definition_edit.glade
index 9067880..e02bb27 100644
--- a/data/ui/developer/window_field_definition_edit.glade
+++ b/data/ui/developer/window_field_definition_edit.glade
@@ -484,32 +484,6 @@
                 <property name="tab_fill">False</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkBox" id="box_formatting_placeholder">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="border_width">6</property>
-                <property name="orientation">vertical</property>
-                <child>
-                  <placeholder/>
-                </child>
-              </object>
-              <packing>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child type="tab">
-              <object class="GtkLabel" id="label188">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label" translatable="yes">Default Formatting</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="position">2</property>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">True</property>
diff --git a/glom/mode_design/fields/box_db_table_definition.cc 
b/glom/mode_design/fields/box_db_table_definition.cc
index 657c537..68a3850 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -31,6 +31,8 @@ namespace Glom
 {
 
 Box_DB_Table_Definition::Box_DB_Table_Definition()
+: m_dialog_field_definition(0),
+  m_dialog_default_formatting(0)
 {
   init();
 }
@@ -45,20 +47,29 @@ void Box_DB_Table_Definition::init()
 {
   //m_strHint = _("Click [Edit] to edit the field definition in more detail.\nUse the Mode menu to see Data 
or perform a Find.");
 
-  Utils::get_glade_widget_derived_with_warning(m_pDialog);
+  Utils::get_glade_widget_derived_with_warning(m_dialog_field_definition);
+  add_view(m_dialog_field_definition); //Give it access to the document.
+
+  Utils::get_glade_widget_derived_with_warning(m_dialog_default_formatting);
+  add_view(m_dialog_default_formatting);
+  m_dialog_default_formatting->signal_apply().connect(sigc::mem_fun(*this, 
&Box_DB_Table_Definition::on_field_definition_apply));
 
-  add_view(m_pDialog); //Give it access to the document.
 
   pack_start(m_AddDel);
   m_colName = m_AddDel.add_column(_("Name"));
   m_AddDel.prevent_duplicates(m_colName); //Don't allow adding of fields that already exist.
-  m_AddDel.set_prevent_duplicates_warning(_("This field already exists. Please choose a different field 
name"));
+  m_AddDel.set_prevent_duplicates_warning(_("This field already exists. Please choose a different field 
name."));
 
   m_colTitle = m_AddDel.add_column(_("Title"));
 
   m_colType = m_AddDel.add_column(_("Type"), AddDelColumnInfo::STYLE_Choices);
   m_AddDel.set_column_width(m_colType, 100); //TODO: Auto-size columns.
 
+
+  //Setup the buttons:
+  m_AddDel.set_edit_button_label(_("_Field Definition"));
+  m_AddDel.set_extra_button_label(_("_Default Formatting"));
+
   //Set Type choices:
 
   Field::type_map_type_names mapFieldTypes = Field::get_usable_type_names();
@@ -79,17 +90,24 @@ void Box_DB_Table_Definition::init()
   m_AddDel.signal_user_requested_delete().connect(sigc::mem_fun(*this, 
&Box_DB_Table_Definition::on_adddel_delete));
   m_AddDel.signal_user_changed().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_adddel_changed));
   m_AddDel.signal_user_requested_edit().connect(sigc::mem_fun(*this, 
&Box_DB_Table_Definition::on_adddel_edit));
+  m_AddDel.signal_user_requested_extra().connect(sigc::mem_fun(*this, 
&Box_DB_Table_Definition::on_adddel_extra));
 
   //React to changes in the field properties:
-  m_pDialog->signal_apply().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_Properties_apply));
+  m_dialog_field_definition->signal_apply().connect(sigc::mem_fun(*this, 
&Box_DB_Table_Definition::on_field_definition_apply));
 }
 
 Box_DB_Table_Definition::~Box_DB_Table_Definition()
 {
-  if(m_pDialog)
+  if(m_dialog_field_definition)
   {
-    remove_view(m_pDialog);
-    delete m_pDialog;
+    remove_view(m_dialog_field_definition);
+    delete m_dialog_field_definition;
+  }
+
+  if(m_dialog_default_formatting)
+  {
+    remove_view(m_dialog_default_formatting);
+    delete m_dialog_default_formatting;
   }
 }
 
@@ -395,15 +413,31 @@ void Box_DB_Table_Definition::on_adddel_edit(const Gtk::TreeModel::iterator& row
   sharedptr<const Field> constfield = get_field_definition(row);
   m_Field_BeingEdited = constfield;
 
-  m_pDialog->set_field(m_Field_BeingEdited, m_table_name);
+  m_dialog_field_definition->set_field(m_Field_BeingEdited, m_table_name);
+
+  //m_dialog_field_definition->set_modified(false); //Disable [Apply] at start.
+
+  Gtk::Window* parent_window = get_app_window();
+  if(parent_window)
+    m_dialog_field_definition->set_transient_for(*parent_window);
+
+  m_dialog_field_definition->show();
+}
+
+void Box_DB_Table_Definition::on_adddel_extra(const Gtk::TreeModel::iterator& row)
+{
+  sharedptr<const Field> constfield = get_field_definition(row);
+  m_Field_BeingEdited = constfield;
+
+  m_dialog_default_formatting->set_field(m_Field_BeingEdited, m_table_name);
 
-  //m_pDialog->set_modified(false); //Disable [Apply] at start.
+  //m_dialog_field_definition->set_modified(false); //Disable [Apply] at start.
 
   Gtk::Window* parent_window = get_app_window();
   if(parent_window)
-    m_pDialog->set_transient_for(*parent_window);
+    m_dialog_default_formatting->set_transient_for(*parent_window);
 
-  m_pDialog->show();
+  m_dialog_default_formatting->show();
 }
 
 sharedptr<Field> Box_DB_Table_Definition::get_field_definition(const Gtk::TreeModel::iterator& row)
@@ -482,9 +516,29 @@ sharedptr<Field> Box_DB_Table_Definition::get_field_definition(const Gtk::TreeMo
   return fieldResult;
 }
 
-void Box_DB_Table_Definition::on_Properties_apply()
+void Box_DB_Table_Definition::on_field_definition_apply()
+{
+  sharedptr<Field> field_New = m_dialog_field_definition->get_field();
+
+  if(*m_Field_BeingEdited != *field_New)
+  {
+    const bool bcontinue = check_field_change(m_Field_BeingEdited, field_New);
+    if(bcontinue)
+    {
+      change_definition(m_Field_BeingEdited, field_New);
+      m_Field_BeingEdited = field_New;
+    }
+
+    //Update the list:
+    fill_from_database();
+  }
+
+  m_dialog_field_definition->hide();
+}
+
+void Box_DB_Table_Definition::on_default_formatting_apply()
 {
-  sharedptr<Field> field_New = m_pDialog->get_field();
+  sharedptr<Field> field_New = m_dialog_default_formatting->get_field();
 
   if(*m_Field_BeingEdited != *field_New)
   {
@@ -499,7 +553,7 @@ void Box_DB_Table_Definition::on_Properties_apply()
     fill_from_database();
   }
 
-  m_pDialog->hide();
+  m_dialog_default_formatting->hide();
 }
 
 sharedptr<Field> Box_DB_Table_Definition::change_definition(const sharedptr<const Field>& fieldOld, const 
sharedptr<const Field>& field)
diff --git a/glom/mode_design/fields/box_db_table_definition.h 
b/glom/mode_design/fields/box_db_table_definition.h
index 6ebf0e9..412e27c 100644
--- a/glom/mode_design/fields/box_db_table_definition.h
+++ b/glom/mode_design/fields/box_db_table_definition.h
@@ -21,8 +21,9 @@
 #ifndef GLOM_MODE_DESIGN_BOX_DB_TABLE_DEFINITION_H
 #define GLOM_MODE_DESIGN_BOX_DB_TABLE_DEFINITION_H
 
-#include "../../box_db_table.h"
-#include "dialog_fielddefinition.h"
+#include <glom/box_db_table.h>
+#include <glom/mode_design/fields/dialog_fielddefinition.h>
+#include <glom/mode_design/fields/dialog_defaultformatting.h>
 
 namespace Glom
 {
@@ -53,8 +54,10 @@ private:
   void on_adddel_delete(const Gtk::TreeModel::iterator& rowStart, const Gtk::TreeModel::iterator& rowEnd);
   void on_adddel_changed(const Gtk::TreeModel::iterator& row, guint col);
   void on_adddel_edit(const Gtk::TreeModel::iterator& row);
+  void on_adddel_extra(const Gtk::TreeModel::iterator& row);
 
-  void on_Properties_apply();
+  void on_field_definition_apply();
+  void on_default_formatting_apply();
 
   bool check_field_change(const sharedptr<const Field>& field_old, const sharedptr<const Field>& field_new);
 
@@ -62,7 +65,10 @@ private:
 
   guint m_colName, m_colTitle, m_colType, m_colUnique, m_colPrimaryKey;
 
-  Dialog_FieldDefinition* m_pDialog;
+  Dialog_FieldDefinition* m_dialog_field_definition;
+
+  Dialog_DefaultFormatting* m_dialog_default_formatting;
+
   sharedptr<const Field> m_Field_BeingEdited; //TODO_FieldShared
   type_vec_fields m_vecFields;
 };
diff --git a/glom/mode_design/fields/dialog_defaultformatting.cc 
b/glom/mode_design/fields/dialog_defaultformatting.cc
new file mode 100644
index 0000000..ecb17a0
--- /dev/null
+++ b/glom/mode_design/fields/dialog_defaultformatting.cc
@@ -0,0 +1,101 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include "dialog_defaultformatting.h"
+#include <glom/glade_utils.h>
+#include <glom/utils_ui.h>
+#include <glom/appwindow.h>
+#include "../../box_db_table.h"
+#include <libglom/db_utils.h>
+//#include <libgnome/gnome-i18n.h>
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+const char* Dialog_DefaultFormatting::glade_id("window_default_formatting");
+const bool Dialog_DefaultFormatting::glade_developer(true);
+
+Dialog_DefaultFormatting::Dialog_DefaultFormatting(BaseObjectType* cobject, const 
Glib::RefPtr<Gtk::Builder>& builder)
+: Dialog_Properties(cobject, builder),
+  m_box_formatting_placeholder(0),
+  m_box_formatting(0)
+{
+  //Get the place to put the Formatting stuff:
+  builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
+
+  //Get the formatting stuff:
+  Utils::get_glade_child_widget_derived_with_warning(m_box_formatting);
+
+  if(m_box_formatting) //Unlikely to fail and it already warns on stderr.
+    m_box_formatting_placeholder->pack_start(*m_box_formatting);
+
+  add_view(m_box_formatting);
+
+  if(m_box_formatting)
+  {
+    on_foreach_connect(*m_box_formatting);
+
+    //Plus an extra signal for the related extra show-also fields:
+    m_box_formatting->signal_modified().connect(
+     sigc::mem_fun(*this, &Dialog_DefaultFormatting::on_anything_changed));
+  }
+
+  Dialog_Properties::set_modified(false);
+
+  show_all_children();
+}
+
+Dialog_DefaultFormatting::~Dialog_DefaultFormatting()
+{
+  remove_view(m_box_formatting);
+}
+
+void Dialog_DefaultFormatting::set_field(const sharedptr<const Field>& field, const Glib::ustring& 
table_name)
+{
+  set_blocked();
+
+  m_Field = glom_sharedptr_clone(field); //Remember it so we save any details that are not in our UI.
+  m_table_name = table_name;  //Used for lookup combo boxes.
+
+  //Formatting:
+  m_box_formatting->set_formatting_for_field(field->m_default_formatting, m_table_name, field);
+
+  set_blocked(false);
+
+  Dialog_Properties::set_modified(false);
+}
+
+sharedptr<Field> Dialog_DefaultFormatting::get_field() const
+{
+  sharedptr<Field> field = glom_sharedptr_clone(m_Field); //Start with the old details, to preserve anything 
that is not in our UI.
+  // const_cast is necessary and save here for the window (jhs)
+  sharedptr<SharedConnection> sharedcnc = connect_to_server(const_cast<Dialog_DefaultFormatting*>(this));
+  Glib::RefPtr<Gnome::Gda::Connection> cnc = sharedcnc->get_gda_connection();
+
+  //Get the field info from the widgets:
+
+  //Formatting:
+  m_box_formatting->get_formatting(field->m_default_formatting);
+
+  return field;
+}
+
+} //namespace Glom
diff --git a/glom/mode_design/fields/dialog_defaultformatting.h 
b/glom/mode_design/fields/dialog_defaultformatting.h
new file mode 100644
index 0000000..5b06de0
--- /dev/null
+++ b/glom/mode_design/fields/dialog_defaultformatting.h
@@ -0,0 +1,64 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GLOM_MODE_DESIGN_DIALOG_DEFAULTFORMATTING_H
+#define GLOM_MODE_DESIGN_DIALOG_DEFAULTFORMATTING_H
+
+#include <gtkmm/dialog.h>
+#include <gtkmm/checkbutton.h>
+#include <gtkmm/comboboxtext.h>
+#include <gtkmm/alignment.h>
+#include <gtkmm/entry.h>
+#include <glom/mode_design/layout/combobox_relationship.h>
+//#include "../../utility_widgets/entry_numerical.h"
+#include "../../utility_widgets/dialog_properties.h"
+#include <glom/mode_data/datawidget/datawidget.h>
+#include <libglom/data_structure/field.h>
+#include <glom/mode_design/layout/layout_item_dialogs/box_formatting.h>
+#include <glom/base_db.h>
+
+namespace Glom
+{
+
+class Dialog_DefaultFormatting
+ : public Dialog_Properties,
+   public Base_DB //Give this class access to the current document, and to some utility methods.
+{
+public:
+  static const char* glade_id;
+  static const bool glade_developer;
+
+  Dialog_DefaultFormatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
+  virtual ~Dialog_DefaultFormatting();
+
+  virtual void set_field(const sharedptr<const Field>& field, const Glib::ustring& table_name);
+  virtual sharedptr<Field> get_field() const; //TODO_FieldShared
+
+private:
+  Gtk::Box* m_box_formatting_placeholder;
+  Box_Formatting* m_box_formatting;
+
+  sharedptr<Field> m_Field;
+  Glib::ustring m_table_name;
+};
+
+} //namespace Glom
+
+#endif // GLOM_MODE_DESIGN_DIALOG_DEFAULTFORMATTING_H
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc 
b/glom/mode_design/fields/dialog_fielddefinition.cc
index 2b8c61f..b62dbb1 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -36,9 +36,7 @@ const bool Dialog_FieldDefinition::glade_developer(true);
 
 Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& 
builder)
 : Dialog_Properties(cobject, builder),
-  m_pDataWidget_DefaultValueSimple(0),
-  m_box_formatting_placeholder(0),
-  m_box_formatting(0)
+  m_pDataWidget_DefaultValueSimple(0)
 {
   builder->get_widget_derived("combobox_type", m_pCombo_Type);
 
@@ -84,32 +82,11 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
   //Make sure that the correct Type Details are showing:
   on_combo_type_changed();
 
-  //Formatting:
-  //Get the place to put the Formatting stuff:
-  builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
-
-  //Get the formatting stuff:
-  Utils::get_glade_child_widget_derived_with_warning(m_box_formatting);
-
-  if(m_box_formatting) ////Unlikely to fail and it already warns on stderr.
-    m_box_formatting_placeholder->pack_start(*m_box_formatting);
-
-  add_view(m_box_formatting);
-
 
   on_foreach_connect(*this);
   on_foreach_connect(*m_pBox_DefaultValueSimple);
   on_foreach_connect(*m_pBox_ValueTab);
 
-  if(m_box_formatting)
-  {
-    on_foreach_connect(*m_box_formatting);
-
-    //Plus an extra signal for the related extra show-also fields:
-    m_box_formatting->signal_modified().connect(
-     sigc::mem_fun(*this, &Dialog_FieldDefinition::on_anything_changed));
-  }
-
   Dialog_Properties::set_modified(false);
 
   show_all_children();
@@ -117,7 +94,6 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
 
 Dialog_FieldDefinition::~Dialog_FieldDefinition()
 {
-  remove_view(m_box_formatting);
 }
 
 void Dialog_FieldDefinition::set_field(const sharedptr<const Field>& field, const Glib::ustring& table_name)
@@ -215,9 +191,6 @@ void Dialog_FieldDefinition::set_field(const sharedptr<const Field>& field, cons
 
   m_pEntry_Title->set_text(item_get_title(field));
 
-  //Formatting:
-  m_box_formatting->set_formatting_for_field(field->m_default_formatting, m_table_name, field);
-
   set_blocked(false);
 
   enforce_constraints();
@@ -275,9 +248,6 @@ sharedptr<Field> Dialog_FieldDefinition::get_field() const
 
   field->set_title(m_pEntry_Title->get_text(), AppWindow::get_current_locale());
 
-  //Formatting:
-  m_box_formatting->get_formatting(field->m_default_formatting);
-
   return field;
 }
 
diff --git a/glom/utility_widgets/adddel/adddel.cc b/glom/utility_widgets/adddel/adddel.cc
index c4269e2..eee99cf 100644
--- a/glom/utility_widgets/adddel/adddel.cc
+++ b/glom/utility_widgets/adddel/adddel.cc
@@ -1295,6 +1295,11 @@ AddDel::type_signal_user_requested_edit AddDel::signal_user_requested_edit()
   return m_signal_user_requested_edit;
 }
 
+AddDel::type_signal_user_requested_edit AddDel::signal_user_requested_extra()
+{
+  return m_signal_user_requested_extra;
+}
+
 AddDel::type_signal_user_requested_add AddDel::signal_user_requested_add()
 {
   return m_signal_user_requested_add;
@@ -1638,5 +1643,4 @@ bool AddDel::row_has_duplicates(const Gtk::TreeModel::iterator& iter) const
   return false;
 }
 
-
 } //namespace Glom
diff --git a/glom/utility_widgets/adddel/adddel.h b/glom/utility_widgets/adddel/adddel.h
index 655e105..b5454b8 100644
--- a/glom/utility_widgets/adddel/adddel.h
+++ b/glom/utility_widgets/adddel/adddel.h
@@ -199,6 +199,13 @@ public:
   typedef sigc::signal<void, const Gtk::TreeModel::iterator&> type_signal_user_requested_edit;
   type_signal_user_requested_edit signal_user_requested_edit();
 
+  //TODO: Add this to the menu?
+  /** This signal is emitted when the user presses the "extra" button.
+   * This sends the row number.
+   */
+  typedef sigc::signal<void, const Gtk::TreeModel::iterator&> type_signal_user_requested_extra;
+  type_signal_user_requested_extra signal_user_requested_extra();
+
   typedef sigc::signal<void> type_signal_user_requested_add;
   type_signal_user_requested_add signal_user_requested_add();
 
@@ -322,6 +329,7 @@ private:
   type_signal_user_changed m_signal_user_changed;
   type_signal_user_requested_delete m_signal_user_requested_delete;
   type_signal_user_requested_edit m_signal_user_requested_edit;
+  type_signal_user_requested_extra m_signal_user_requested_extra;
   type_signal_user_requested_add m_signal_user_requested_add;
   type_signal_user_activated m_signal_user_activated;
   type_signal_user_reordered_columns m_signal_user_reordered_columns;
diff --git a/glom/utility_widgets/adddel/adddel_withbuttons.cc 
b/glom/utility_widgets/adddel/adddel_withbuttons.cc
index 81f735e..e72eea2 100644
--- a/glom/utility_widgets/adddel/adddel_withbuttons.cc
+++ b/glom/utility_widgets/adddel/adddel_withbuttons.cc
@@ -62,7 +62,9 @@ void AddDel_WithButtons::init()
   m_Button_Add.signal_clicked().connect(sigc::mem_fun(*this, &AddDel_WithButtons::on_button_add));
   m_Button_Del.signal_clicked().connect(sigc::mem_fun(*this, &AddDel_WithButtons::on_button_del));
   m_Button_Edit.signal_clicked().connect(sigc::mem_fun(*this, &AddDel_WithButtons::on_button_edit));
+  m_Button_Extra.signal_clicked().connect(sigc::mem_fun(*this, &AddDel_WithButtons::on_button_extra));
 
+  m_Button_Extra.hide();
 }
 
 AddDel_WithButtons::~AddDel_WithButtons()
@@ -96,6 +98,22 @@ void AddDel_WithButtons::on_button_edit()
   on_MenuPopup_activate_Edit();
 }
 
+void AddDel_WithButtons::on_button_extra()
+{
+  Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_TreeView.get_selection();
+  if(!refSelection)
+    return;
+
+  Gtk::TreeModel::iterator iter = refSelection->get_selected();
+  if(!iter)
+    return;
+   
+  if(get_is_placeholder_row(iter))
+    return;
+
+  signal_user_requested_extra()(iter);
+}
+
 void AddDel_WithButtons::set_allow_add(bool val)
 {
   AddDel::set_allow_add(val);
@@ -128,6 +146,7 @@ void AddDel_WithButtons::set_allow_user_actions(bool bVal)
     m_ButtonBox.remove(m_Button_Add);
     m_ButtonBox.remove(m_Button_Del);
     m_ButtonBox.remove(m_Button_Edit);
+    m_ButtonBox.remove(m_Button_Extra);
   }
 
   //Recreate popup menu with correct items:
@@ -136,18 +155,55 @@ void AddDel_WithButtons::set_allow_user_actions(bool bVal)
 
 void AddDel_WithButtons::setup_buttons()
 {
-  //Put buttons below sheet:
-  //m_ButtonBox.remove(m_Button_Add);
-  //m_ButtonBox.remove(m_Button_Del);
-  //m_ButtonBox.remove(m_Button_Edit);
+  if(!get_allow_user_actions())
+    return;
 
-  if(get_allow_user_actions())
-  {
-    m_ButtonBox.pack_end(m_Button_Add, Gtk::PACK_SHRINK);
-    m_ButtonBox.pack_end(m_Button_Del, Gtk::PACK_SHRINK);
-    m_ButtonBox.pack_end(m_Button_Edit, Gtk::PACK_SHRINK);
-  }
+  m_ButtonBox.pack_end(m_Button_Add, Gtk::PACK_SHRINK);
+  m_Button_Add.show();
+
+  m_ButtonBox.pack_end(m_Button_Del, Gtk::PACK_SHRINK);
+  m_Button_Del.show();
+
+  m_ButtonBox.pack_end(m_Button_Edit, Gtk::PACK_SHRINK);
+  m_Button_Edit.show();
+
+  m_ButtonBox.pack_end(m_Button_Extra, Gtk::PACK_SHRINK);
+  if(!m_label_extra.empty())
+    m_Button_Extra.show();
+  else
+    m_Button_Extra.hide();
 }
 
+void AddDel_WithButtons::set_extra_button_label(const Glib::ustring& label)
+{
+  m_label_extra = label;
+  m_Button_Extra.set_label(m_label_extra);
+  m_Button_Extra.set_use_underline();
+
+  if(!m_label_extra.empty())
+    m_Button_Extra.show();
+  else
+    m_Button_Extra.hide();
+}
+
+void AddDel_WithButtons::set_edit_button_label(const Glib::ustring& label)
+{
+  m_Button_Edit.set_label(label);
+  m_Button_Edit.set_use_underline();
+}
+
+//We override this so we can avoid showing an empty Extra button:
+void AddDel_WithButtons::show_all_vfunc()
+{
+  //Call the base class:
+  Gtk::Box::show_all_vfunc();
+
+  if(!m_label_extra.empty())
+    m_Button_Extra.show();
+  else
+    m_Button_Extra.hide();
+}
+
+
 } //namespace Glom
 
diff --git a/glom/utility_widgets/adddel/adddel_withbuttons.h 
b/glom/utility_widgets/adddel/adddel_withbuttons.h
index af70920..ddcf6c8 100644
--- a/glom/utility_widgets/adddel/adddel_withbuttons.h
+++ b/glom/utility_widgets/adddel/adddel_withbuttons.h
@@ -38,6 +38,18 @@ public:
   virtual void set_allow_delete(bool val = true); //override
   virtual void set_allow_user_actions(bool bVal = true); //override
 
+  /**
+   * @param label The button label text, including the mnemonic underline.
+   */
+  void set_edit_button_label(const Glib::ustring& label);
+
+  /** Set the label of the extra button, if any.
+   * If there is no label text (the default) then the button will not be shown.
+   *
+   * @para label The button label text, including the mnemonic underline.
+   */
+  void set_extra_button_label(const Glib::ustring& label);
+
 private:
   void init();
   void setup_buttons();
@@ -45,12 +57,18 @@ private:
   void on_button_add();
   void on_button_del();
   void on_button_edit();
+  void on_button_extra();
+
+  virtual void show_all_vfunc();
 
   //member widgets:
   Gtk::ButtonBox m_ButtonBox;
   Gtk::Button m_Button_Add;
   Gtk::Button m_Button_Del;
   Gtk::Button m_Button_Edit;
+  Gtk::Button m_Button_Extra;
+
+  Glib::ustring m_label_extra;
 };
 
 } //namespace Glom


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