[glom/feature_choices_related_layout] Choices: Show Also: Use an Edit button



commit a370578ce6d849a935cabbec513ed8b6be7f2d75
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Sep 7 10:05:55 2010 +0200

    Choices: Show Also: Use an Edit button

 Makefile.am                                        |    2 +-
 glom/glom_developer.glade                          |   24 ++++-
 glom/libglom/utils.cc                              |   17 +++
 glom/libglom/utils.h                               |    4 +
 .../layout/layout_item_dialogs/box_formatting.cc   |  121 +++++++++++++-------
 .../layout/layout_item_dialogs/box_formatting.h    |   15 ++-
 .../layout/layout_item_dialogs/dialog_group_by.cc  |   18 +---
 po/POTFILES.in                                     |    2 +-
 8 files changed, 141 insertions(+), 62 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e0470ac..c811224 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,7 +22,7 @@
 ## error-prone:  http://miller.emu.id.au/pmiller/books/rmch/
 
 # Put compiled object files into the same sub-directory as their sources
-AUTOMAKE_OPTIONS = subdir-objects
+AUTOMAKE_OPTIONS = subdir-objects color-tests
 
 # Use .cc as default extension if no _SOURCES have been defined
 AM_DEFAULT_SOURCE_EXT = .cc
diff --git a/glom/glom_developer.glade b/glom/glom_developer.glade
index 322a238..c5bada8 100644
--- a/glom/glom_developer.glade
+++ b/glom/glom_developer.glade
@@ -6727,8 +6727,30 @@ Which user should be added to this group?</property>
                                 <property name="column_spacing">6</property>
                                 <property name="row_spacing">6</property>
                                 <child>
-                                  <object class="GtkComboBox" id="combobox_choices_related_field_second">
+                                  <object class="GtkHBox" id="hbox1">
                                     <property name="visible">True</property>
+                                    <child>
+                                      <object class="GtkLabel" id="label_choices_related_extra_fields">
+                                        <property name="visible">True</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">label</property>
+                                      </object>
+                                      <packing>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkButton" id="button_choices_related_extra_fields">
+                                        <property name="label">gtk-edit</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="position">1</property>
+                                      </packing>
+                                    </child>
                                   </object>
                                   <packing>
                                     <property name="left_attach">1</property>
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 839d788..8fb125c 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -1139,5 +1139,22 @@ Glib::ustring Utils::get_directory_child_with_suffix(const Glib::ustring& uri_di
   return Glib::ustring();
 }
 
+Glib::ustring Utils::get_list_of_layout_items_for_display(const LayoutGroup::type_list_items& list_layout_fields)
+{
+  Glib::ustring result;
+  for(LayoutGroup::type_list_items::const_iterator iter = list_layout_fields.begin(); iter != list_layout_fields.end(); ++iter)
+  {
+    const sharedptr<LayoutItem> item = *iter;
+    if(item)
+    {
+      if(!result.empty())
+       result += ", ";
+
+      result += item->get_layout_display_name();
+    }
+  }
+
+  return result;
+}
 
 } //namespace Glom
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index 8fd204e..e50e350 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -177,6 +177,10 @@ bool delete_directory(const std::string& uri);
  */
 Glib::ustring get_directory_child_with_suffix(const Glib::ustring& uri_directory, const std::string& suffix, bool recursive);
 
+/** Get a string to display to the user, as a representation of a list of layout items.
+ */
+Glib::ustring get_list_of_layout_items_for_display(const LayoutGroup::type_list_items& list_layout_fields);
+
 } //namespace Utils
 
 } //namespace Glom
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index ee95316..174f91a 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -18,8 +18,12 @@
  * Boston, MA 02111-1307, USA.
  */
 
+
 #include "box_formatting.h"
+#include <glom/utils_ui.h>
+#include <glom/glade_utils.h>
 #include <libglom/data_structure/glomconversions.h>
+#include <glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.h>
 #include <glibmm/i18n.h>
 
 namespace Glom
@@ -59,8 +63,10 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   m_col_index_custom_choices(0),
   m_combo_choices_relationship(0),
   m_combo_choices_field(0),
-  m_combo_choices_field_second(0),
+  m_label_choices_extra_fields(0),
+  m_button_choices_extra_fields(0),
   m_checkbutton_choices_related_show_all(0),
+  m_dialog_choices_extra_fields(0),
   m_for_print_layout(false),
   m_show_numeric(true),
   m_show_choices(true)
@@ -115,7 +121,7 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
 
   m_combo_format_text_horizontal_alignment->set_model(m_model_alignment);
   m_combo_format_text_horizontal_alignment->pack_start(m_columns_alignment.m_col_title);
-  
+
 
   //Choices:
   builder->get_widget("vbox_choices", m_vbox_choices);
@@ -126,11 +132,12 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   m_adddel_choices_custom->set_auto_add();
 
   builder->get_widget("checkbutton_choices_restrict", m_checkbutton_choices_restricted);
-  builder->get_widget("checkbutton_choices_restrict_as_radio_buttons", m_checkbutton_choices_restricted_as_radio_buttons); 
+  builder->get_widget("checkbutton_choices_restrict_as_radio_buttons", m_checkbutton_choices_restricted_as_radio_buttons);
 
   builder->get_widget_derived("combobox_choices_related_relationship", m_combo_choices_relationship);
   builder->get_widget_derived("combobox_choices_related_field", m_combo_choices_field);
-  builder->get_widget_derived("combobox_choices_related_field_second", m_combo_choices_field_second);
+  builder->get_widget("label_choices_related_extra_fields", m_label_choices_extra_fields);
+  builder->get_widget("button_choices_related_extra_fields", m_button_choices_extra_fields);
   builder->get_widget("checkbutton_choices_related_show_all", m_checkbutton_choices_related_show_all);
   builder->get_widget("radiobutton_choices_custom", m_radiobutton_choices_custom);
   builder->get_widget("radiobutton_choices_related", m_radiobutton_choices_related);
@@ -143,12 +150,24 @@ Box_Formatting::Box_Formatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::
   m_checkbox_format_text_color_background->signal_toggled().connect( sigc::mem_fun(*this, &Box_Formatting::on_checkbox) );
   m_checkbox_format_color_negatives->signal_toggled().connect( sigc::mem_fun(*this, &Box_Formatting::on_checkbox) );
   m_checkbutton_choices_restricted->signal_toggled().connect( sigc::mem_fun(*this, &Box_Formatting::on_checkbox) );
+  m_button_choices_extra_fields->signal_clicked().connect( sigc::mem_fun(*this, &Box_Formatting::on_button_choices_extra) );
+
+  if(!m_dialog_choices_extra_fields)
+  {
+    Utils::get_glade_widget_derived_with_warning(m_dialog_choices_extra_fields);
+    add_view(m_dialog_choices_extra_fields); //Give it access to the document.
+  }
 
   show_all_children();
 }
 
 Box_Formatting::~Box_Formatting()
 {
+  if(m_dialog_choices_extra_fields)
+  {
+    remove_view(m_dialog_choices_extra_fields); //Give it access to the document.
+    delete m_dialog_choices_extra_fields;
+  }
 }
 
 void Box_Formatting::set_is_for_print_layout()
@@ -156,7 +175,7 @@ void Box_Formatting::set_is_for_print_layout()
   m_for_print_layout = true;
   m_show_choices = false;
 
-  //Add labels (because we will hide the checkboxes): 
+  //Add labels (because we will hide the checkboxes):
   Gtk::Label* label = Gtk::manage(new Gtk::Label(_("Font")));
   label->show();
   m_hbox_font->pack_start(*label, Gtk::PACK_SHRINK);
@@ -165,7 +184,7 @@ void Box_Formatting::set_is_for_print_layout()
   m_hbox_color_foreground->pack_start(*label, Gtk::PACK_SHRINK);
   label = Gtk::manage(new Gtk::Label(_("Background Color")));
   label->show();
-  m_hbox_color_background->pack_start(*label, Gtk::PACK_SHRINK); 
+  m_hbox_color_background->pack_start(*label, Gtk::PACK_SHRINK);
 
   enforce_constraints();
 }
@@ -200,9 +219,9 @@ void Box_Formatting::set_formatting(const FieldFormatting& format, bool show_num
     format.m_numeric_format.m_alt_foreground_color_for_negatives );
 
   //Text formatting
-  const FieldFormatting::HorizontalAlignment alignment = 
+  const FieldFormatting::HorizontalAlignment alignment =
     format.get_horizontal_alignment();
-  Gtk::TreeModel::Children children = m_model_alignment->children(); 
+  Gtk::TreeModel::Children children = m_model_alignment->children();
   for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter)
   {
     Gtk::TreeModel::Row row = *iter;
@@ -249,30 +268,24 @@ void Box_Formatting::set_formatting(const FieldFormatting& format, bool show_num
     sharedptr<const LayoutGroup> choices_field_extras;
     bool choices_show_all = false;
     format.get_choices_related(choices_relationship, choices_field, choices_field_extras, choices_show_all);
-    
-    sharedptr<const LayoutItem_Field> choices_field_second;
-    if(choices_field_extras)
-    {
-      const LayoutGroup::type_list_const_items extra_fields
-        = choices_field_extras->get_items_recursive();
-
-      for(LayoutGroup::type_list_const_items::const_iterator iterExtra = extra_fields.begin();
-          iterExtra != extra_fields.end(); ++iterExtra)
-      {
-        const sharedptr<const LayoutItem> item = *iterExtra;
-        const sharedptr<const LayoutItem_Field> item_field = sharedptr<const LayoutItem_Field>::cast_dynamic(item);
-        if(item_field)
-        {
-          choices_field_second = item_field;
-          break;
-        }
-      }
-    }
 
     m_combo_choices_relationship->set_selected_relationship(choices_relationship);
     on_combo_choices_relationship_changed(); //Fill the combos so we can set their active items.
     m_combo_choices_field->set_selected_field(choices_field ? choices_field->get_name() : Glib::ustring());
-    m_combo_choices_field_second->set_selected_field(choices_field_second ? choices_field_second->get_name() : Glib::ustring());
+
+    //Show the list of fields in a label:
+    const Glib::ustring text_extra_fields =
+      Utils::get_list_of_layout_items_for_display(choices_field_extras->m_list_items);
+     m_label_choices_extra_fields->set_text(text_extra_fields);
+
+    //Update the contents of the dialog that will be shown if Edit is clicked:
+    if(choices_field_extras)
+      m_dialog_choices_extra_fields->set_fields(m_table_name, choices_field_extras->m_list_items);
+    else
+      m_dialog_choices_extra_fields->set_fields(m_table_name, LayoutGroup::type_list_items());
+
+
+
     m_checkbutton_choices_related_show_all->set_active(choices_show_all);
 
     //Custom choices:
@@ -304,7 +317,7 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
 
   m_format.m_numeric_format.m_currency_symbol = m_entry_currency_symbol->get_entry()->get_text();
 
-  m_format.m_numeric_format.m_alt_foreground_color_for_negatives = 
+  m_format.m_numeric_format.m_alt_foreground_color_for_negatives =
     m_checkbox_format_color_negatives->get_active();
 
   //Text formatting:
@@ -337,18 +350,18 @@ bool Box_Formatting::get_formatting(FieldFormatting& format) const
   if(m_field)
   {
     m_format.set_choices_restricted(
-      m_checkbutton_choices_restricted->get_active(), 
+      m_checkbutton_choices_restricted->get_active(),
       m_checkbutton_choices_restricted_as_radio_buttons->get_active());
 
     const sharedptr<const Relationship> choices_relationship = m_combo_choices_relationship->get_selected_relationship();
     sharedptr<LayoutItem_Field> layout_choice_first = sharedptr<LayoutItem_Field>::create();
     layout_choice_first->set_name(m_combo_choices_field->get_selected_field_name());
-    sharedptr<LayoutItem_Field> layout_choice_second = sharedptr<LayoutItem_Field>::create();
-    layout_choice_second->set_name(m_combo_choices_field_second->get_selected_field_name());
-    sharedptr<LayoutGroup> layout_choice_extras = sharedptr<LayoutGroup>::create();
-    layout_choice_extras->add_item(layout_choice_second);
+
+    sharedptr<LayoutGroup> layout_choice_extra = sharedptr<LayoutGroup>::create();
+    layout_choice_extra->m_list_items = m_dialog_choices_extra_fields->get_fields();
+
     m_format.set_choices_related(choices_relationship,
-      layout_choice_first, layout_choice_extras,
+      layout_choice_first, layout_choice_extra,
       m_checkbutton_choices_related_show_all->get_active());
 
     //Custom choices:
@@ -389,10 +402,19 @@ void Box_Formatting::on_combo_choices_relationship_changed()
     //Show the list of formats from this relationship:
     if(relationship)
     {
-      Document::type_vec_fields vecFields = pDocument->get_table_fields(relationship->get_to_table());
-
+      const Document::type_vec_fields vecFields = pDocument->get_table_fields(relationship->get_to_table());
       m_combo_choices_field->set_fields(vecFields);
-      m_combo_choices_field_second->set_fields(vecFields, true /* with_none_item */); //We add a "None" item so this GtkComboBox can be cleared by the user.
+
+      //Update the show-all dialog's list:
+      //If the related table name has changed then the list of fields will probably
+      //be ignored, clearing the list, but we try to preserve it if possible:
+      const LayoutGroup::type_list_items list_fields = m_dialog_choices_extra_fields->get_fields();
+      m_dialog_choices_extra_fields->set_fields(relationship->get_to_table(), list_fields);
+
+      //Update the label:
+      const Glib::ustring text_extra_fields =
+        Utils::get_list_of_layout_items_for_display(m_dialog_choices_extra_fields->get_fields());
+       m_label_choices_extra_fields->set_text(text_extra_fields);
     }
   }
 }
@@ -457,7 +479,7 @@ void Box_Formatting::enforce_constraints()
   //Radio buttons only make sense when the items are restricted, instead of free-form:
   m_checkbutton_choices_restricted_as_radio_buttons->set_sensitive(
      m_checkbutton_choices_restricted->get_active());
-     
+
   if(m_show_numeric)
     m_vbox_numeric_format->show();
   else
@@ -474,4 +496,25 @@ void Box_Formatting::on_checkbox()
   enforce_constraints();
 }
 
+void Box_Formatting::on_button_choices_extra()
+{
+  if(!m_dialog_choices_extra_fields)
+    return;
+
+  const int response = Glom::Utils::dialog_run_with_help(m_dialog_choices_extra_fields);
+  m_dialog_choices_extra_fields->hide();
+  if(response == Gtk::RESPONSE_OK && m_dialog_choices_extra_fields->get_modified())
+  {
+    //Update the label:
+    const Glib::ustring text_extra_fields =
+      Utils::get_list_of_layout_items_for_display(m_dialog_choices_extra_fields->get_fields());
+     m_label_choices_extra_fields->set_text(text_extra_fields);
+
+    //TODO: Mark the dialog as modified.
+  }
+
+
+  //update_labels();
+}
+
 } //namespace Glom
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
index 21db584..e4e5197 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.h
@@ -28,10 +28,13 @@
 #include <glom/mode_design/comboentry_currency.h>
 #include <glom/mode_design/layout/combobox_relationship.h>
 #include <glom/mode_design/layout/combobox_fields.h>
+#include <glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.h>
 
 namespace Glom
 {
 
+class Dialog_FieldsList;
+
 class Box_Formatting
  : public Gtk::VBox,
    public View_Composite_Glom
@@ -47,7 +50,7 @@ public:
    * @param format The starting information.
    */
   void set_formatting(const FieldFormatting& format, bool show_numeric = true, bool show_choices = true);
-  
+
   /**
    * @param format The starting information.
    * @param table_name The field's table.
@@ -56,7 +59,7 @@ public:
   void set_formatting(const FieldFormatting& format, const Glib::ustring& table_name, const sharedptr<const Field>& field);
   bool get_formatting(FieldFormatting& format) const;
 
-  //When used for print layout items, 
+  //When used for print layout items,
   //we hide some stuff:
   void set_is_for_print_layout();
 
@@ -64,6 +67,7 @@ private:
   //Signal handlers:
   void on_combo_choices_relationship_changed();
   void on_checkbox();
+  void on_button_choices_extra();
 
   void enforce_constraints();
 
@@ -98,15 +102,18 @@ private:
   guint m_col_index_custom_choices;
   ComboBox_Relationship* m_combo_choices_relationship;
   ComboBox_Fields* m_combo_choices_field;
-  ComboBox_Fields* m_combo_choices_field_second;
+  Gtk::Label* m_label_choices_extra_fields;
+  Gtk::Button* m_button_choices_extra_fields;
   Gtk::CheckButton* m_checkbutton_choices_related_show_all;
 
+  Dialog_FieldsList* m_dialog_choices_extra_fields;
+
   mutable FieldFormatting m_format;
 
   Glib::ustring m_table_name;
   sharedptr<const Field> m_field;
 
-  //We show different options when 
+  //We show different options when
   //showing this on a print layout.
   bool m_for_print_layout;
 
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
index 0089315..dce12be 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
@@ -209,22 +209,8 @@ void Dialog_GroupBy::update_labels()
     m_label_sort_by->set_text( Glib::ustring() );
 
   //Secondary Fields:
-  Glib::ustring text_secondary_fields;
-  if(m_layout_item->m_group_secondary_fields)
-  {
-    const LayoutGroup::type_list_items& map_items = m_layout_item->m_group_secondary_fields->m_list_items;
-    for(LayoutGroup::type_list_items::const_iterator iter = map_items.begin(); iter != map_items.end(); ++iter)
-    {
-      if(*iter)
-      {
-        if(!text_secondary_fields.empty())
-          text_secondary_fields += ", ";
-
-        text_secondary_fields += (*iter)->get_layout_display_name();
-      }
-    }
-  }
-
+  const Glib::ustring text_secondary_fields =
+    Utils::get_list_of_layout_items_for_display(m_layout_item->m_group_secondary_fields->m_list_items);
   m_label_secondary_fields->set_text(text_secondary_fields);
 }
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f0e47fd..12a4099 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -90,7 +90,7 @@ glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_field_summary.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_group_by.cc
-glom/mode_design/layout/layout_item_dialogs/dialog_groupby_secondaryfields.cc
+glom/mode_design/layout/layout_item_dialogs/dialog_fieldslist.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_groupby_sortfields.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_imageobject.cc
 glom/mode_design/layout/layout_item_dialogs/dialog_notebook.cc



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