[glom] Allow many fields to be added to layouts (or the export format) at once.



commit a80474a4353ce7e5d568548bba32f08cc9e86f84
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jun 29 15:35:20 2009 +0200

    Allow many fields to be added to layouts (or the export format) at once.
    
    * glom/mode_data/dialog_choose_field.[h|cc]: Added get_fields_list() in
    addition to the existing get_field_list(), and allow multiple selection.
    * glom/base_db.[h|cc]: offer_field_list(): Rename to
    offer_field_list_select_one_field().
    Added offer_field_list() that returns a list of fields, allowing multiple
    selection.
    
    * *.[h|cc]: Adapted to use the appropriate function, allowing, for instance,
    the export dialog to use multiple selection to add many fields at once.
    
    Ubuntu Launchpad bug https://bugs.launchpad.net/ubuntu/+source/glom/+bug/393231
    (elmergato)

 ChangeLog                                          |   17 ++++
 glom/base_db.cc                                    |   55 +++++++++++-
 glom/base_db.h                                     |   23 ++++-
 glom/layout_item_dialogs/dialog_field_summary.cc   |    2 +-
 glom/layout_item_dialogs/dialog_group_by.cc        |    2 +-
 .../dialog_groupby_secondaryfields.cc              |   18 +++--
 .../dialog_groupby_sortfields.cc                   |   14 ++-
 glom/libglom/connectionpool.cc                     |    2 +-
 .../data_structure/layout/layoutitem_field.cc      |    8 ++-
 .../data_structure/layout/layoutitem_field.h       |   13 +--
 glom/mode_data/dialog_choose_field.cc              |   94 +++++++++++++++-----
 glom/mode_data/dialog_choose_field.h               |    3 +
 glom/mode_data/dialog_layout_calendar_related.cc   |   10 ++-
 glom/mode_data/dialog_layout_details.cc            |   10 ++-
 glom/mode_data/dialog_layout_export.cc             |   12 ++-
 glom/mode_data/dialog_layout_list_related.cc       |   10 ++-
 .../print_layouts/canvas_print_layout.cc           |    2 +-
 glom/reports/dialog_layout_report.cc               |    2 +-
 glom/utility_widgets/datawidget.cc                 |    2 +-
 glom/utility_widgets/datawidget.h                  |    1 +
 20 files changed, 227 insertions(+), 73 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 422f462..5a64945 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2009-06-29  Murray Cumming  <murrayc murrayc com>
 
+	Allow many fields to be added to layouts (or the export format) at once.
+	
+	* glom/mode_data/dialog_choose_field.[h|cc]: Added get_fields_list() in 
+	addition to the existing get_field_list(), and allow multiple selection.
+	* glom/base_db.[h|cc]: offer_field_list(): Rename to 
+	offer_field_list_select_one_field().
+	Added offer_field_list() that returns a list of fields, allowing multiple 
+	selection.
+
+	* *.[h|cc]: Adapted to use the appropriate function, allowing, for instance, 
+	the export dialog to use multiple selection to add many fields at once.
+
+	Ubuntu Launchpad bug https://bugs.launchpad.net/ubuntu/+source/glom/+bug/393231
+	(elmergato)
+	
+2009-06-29  Murray Cumming  <murrayc murrayc com>
+
 	Export: Offer File overwrite confirmation.
 	
 	* glom/frame_glom.cc: on_menu_file_export():
diff --git a/glom/base_db.cc b/glom/base_db.cc
index 3c76544..4ad0727 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -1661,12 +1661,12 @@ bool Base_DB::insert_example_data(const Glib::ustring& table_name) const
   return insert_succeeded;
 }
 
-sharedptr<LayoutItem_Field> Base_DB::offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for)
+sharedptr<LayoutItem_Field> Base_DB::offer_field_list_select_one_field(const Glib::ustring& table_name, Gtk::Window* transient_for)
 {
-  return offer_field_list(sharedptr<LayoutItem_Field>(), table_name, transient_for);
+  return offer_field_list_select_one_field(sharedptr<LayoutItem_Field>(), table_name, transient_for);
 }
 
-sharedptr<LayoutItem_Field> Base_DB::offer_field_list(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for)
+sharedptr<LayoutItem_Field> Base_DB::offer_field_list_select_one_field(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for)
 {
   sharedptr<LayoutItem_Field> result;
 
@@ -1701,7 +1701,6 @@ sharedptr<LayoutItem_Field> Base_DB::offer_field_list(const sharedptr<const Layo
       dialog->set_transient_for(*transient_for);
 
     dialog->set_document(get_document(), table_name, start_field);
-    //TODO: dialog->set_transient_for(*get_app_window());
     const int response = dialog->run();
     if(response == Gtk::RESPONSE_OK)
     {
@@ -1717,6 +1716,54 @@ sharedptr<LayoutItem_Field> Base_DB::offer_field_list(const sharedptr<const Layo
   return result;
 }
 
+Base_DB::type_list_field_items Base_DB::offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for)
+{
+  type_list_field_items result;
+
+  Glib::RefPtr<Gtk::Builder> refXml;
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+  {
+    refXml = Gtk::Builder::create_from_file(Utils::get_glade_file_path("glom_developer.glade"), "dialog_choose_field");
+  }
+  catch(const Gtk::BuilderError& ex)
+  {
+    std::cerr << ex.what() << std::endl;
+    return result;
+  }
+#else
+  std::auto_ptr<Gtk::BuilderError> error;
+  refXml = Gtk::Builder::create_from_file(Utils::get_glade_file_path("glom_developer.glade"), "dialog_choose_field", "", error);
+  if(error.get())
+  {
+    std::cerr << error->what() << std::endl;
+    return result;
+  }
+#endif
+
+  Dialog_ChooseField* dialog = 0;
+  refXml->get_widget_derived("dialog_choose_field", dialog);
+
+  if(dialog)
+  {
+    if(transient_for)
+      dialog->set_transient_for(*transient_for);
+
+    dialog->set_document(get_document(), table_name);
+    const int response = dialog->run();
+    if(response == Gtk::RESPONSE_OK)
+    {
+      //Get the chosen field:
+      result = dialog->get_fields_chosen();
+    }
+
+    delete dialog;
+  }
+
+  return result;
+}
+
 #ifndef GLOM_ENABLE_CLIENT_ONLY
 sharedptr<LayoutItem_Field> Base_DB::offer_field_formatting(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for)
 {
diff --git a/glom/base_db.h b/glom/base_db.h
index ec8c061..dfdb888 100644
--- a/glom/base_db.h
+++ b/glom/base_db.h
@@ -120,8 +120,25 @@ public:
   typedef std::vector< sharedptr<const LayoutItem_Field> > type_vecConstLayoutFields;
 
 protected:
-  sharedptr<LayoutItem_Field> offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
-  sharedptr<LayoutItem_Field> offer_field_list(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
+
+  /** Allow the user to select a field from the list of fields for the table.
+   */
+  sharedptr<LayoutItem_Field> offer_field_list_select_one_field(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
+  
+  /** Allow the user to select a field from the list of fields for the table, 
+   * with @a start_field selected by default.
+   */
+  sharedptr<LayoutItem_Field> offer_field_list_select_one_field(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
+  
+    
+  typedef std::list< sharedptr<LayoutItem_Field> > type_list_field_items;
+  typedef std::list< sharedptr<const LayoutItem_Field> > type_list_const_field_items;
+  
+  /** Allow the user to select fields from the list of fields for the table.
+   */
+  type_list_field_items offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
+  
+  
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   sharedptr<LayoutItem_Field> offer_field_formatting(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
   sharedptr<LayoutItem_Text> offer_textobject(const sharedptr<LayoutItem_Text>& start_textobject, Gtk::Window* transient_for = 0, bool show_title = true);
@@ -260,8 +277,6 @@ protected:
 
   typedef std::map<Glib::ustring, CalcInProgress> type_field_calcs;
 
-  typedef std::list< sharedptr<LayoutItem_Field> > type_list_field_items;
-  typedef std::list< sharedptr<const LayoutItem_Field> > type_list_const_field_items;
 
   /** Get the fields whose values should be recalculated when @a field_name changes.
    */
diff --git a/glom/layout_item_dialogs/dialog_field_summary.cc b/glom/layout_item_dialogs/dialog_field_summary.cc
index 0fad249..95bfdf0 100644
--- a/glom/layout_item_dialogs/dialog_field_summary.cc
+++ b/glom/layout_item_dialogs/dialog_field_summary.cc
@@ -65,7 +65,7 @@ sharedptr<LayoutItem_FieldSummary> Dialog_FieldSummary::get_item() const
 
 void Dialog_FieldSummary::on_button_field()
 {
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_layout_item, m_table_name, this);
+  sharedptr<LayoutItem_Field> field = offer_field_list_select_one_field(m_layout_item, m_table_name, this);
   if(field)
   {
     m_layout_item->set_field(field);
diff --git a/glom/layout_item_dialogs/dialog_group_by.cc b/glom/layout_item_dialogs/dialog_group_by.cc
index bfc0160..dbefaf2 100644
--- a/glom/layout_item_dialogs/dialog_group_by.cc
+++ b/glom/layout_item_dialogs/dialog_group_by.cc
@@ -105,7 +105,7 @@ sharedptr<LayoutItem_GroupBy> Dialog_GroupBy::get_item() const
 
 void Dialog_GroupBy::on_button_field_group_by()
 {
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_layout_item->get_field_group_by(), m_table_name, this);
+  sharedptr<LayoutItem_Field> field = offer_field_list_select_one_field(m_layout_item->get_field_group_by(), m_table_name, this);
   if(field)
   {
     m_layout_item->set_field_group_by(field);
diff --git a/glom/layout_item_dialogs/dialog_groupby_secondaryfields.cc b/glom/layout_item_dialogs/dialog_groupby_secondaryfields.cc
index 543813e..30b5644 100644
--- a/glom/layout_item_dialogs/dialog_groupby_secondaryfields.cc
+++ b/glom/layout_item_dialogs/dialog_groupby_secondaryfields.cc
@@ -215,10 +215,14 @@ void Dialog_GroupBy_SecondaryFields::on_treeview_fields_selection_changed()
 
 void Dialog_GroupBy_SecondaryFields::on_button_add_field()
 {
-  //Get the chosen field:
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_table_name, this);
-  if(field)
+  //Get the chosen fields:
+  type_list_field_items fields_list = offer_field_list(m_table_name, this);
+  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
   {
+    sharedptr<LayoutItem_Field> field = *iter_chosen; 
+    if(!field)
+      continue;
+  
     //Add the field details to the layout treeview:
     Gtk::TreeModel::iterator iter =  m_model_fields->append();
 
@@ -287,12 +291,12 @@ void Dialog_GroupBy_SecondaryFields::on_button_edit_field()
       sharedptr<const LayoutItem_Field> field = row[m_ColumnsFields.m_col_layout_item];
 
       //Get the chosen field:
-      sharedptr<LayoutItem_Field> field_chosen = offer_field_list(field, m_table_name, this);
-      if(field_chosen)
+      sharedptr<LayoutItem_Field> field_chosen = 
+        offer_field_list_select_one_field(field, m_table_name, this);
 
       //Set the field details in the layout treeview:
-
-      row[m_ColumnsFields.m_col_layout_item] = field_chosen;
+      if(field_chosen)
+        row[m_ColumnsFields.m_col_layout_item] = field_chosen;
 
       //Scroll to, and select, the new row:
       /*
diff --git a/glom/layout_item_dialogs/dialog_groupby_sortfields.cc b/glom/layout_item_dialogs/dialog_groupby_sortfields.cc
index 015b99d..38cc3d6 100644
--- a/glom/layout_item_dialogs/dialog_groupby_sortfields.cc
+++ b/glom/layout_item_dialogs/dialog_groupby_sortfields.cc
@@ -214,10 +214,15 @@ void Dialog_GroupBy_SortFields::on_treeview_fields_selection_changed()
 
 void Dialog_GroupBy_SortFields::on_button_add_field()
 {
-  //Get the chosen field:
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_table_name, this);
-  if(field)
+  //Get the chosen fields:
+  type_list_field_items fields_list = offer_field_list(m_table_name, this);
+  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
   {
+
+    sharedptr<LayoutItem_Field> field = *iter_chosen;
+    if(!field)
+      continue;
+
     //Add the field details to the layout treeview:
     Gtk::TreeModel::iterator iter =  m_model_fields->append();
 
@@ -287,7 +292,8 @@ void Dialog_GroupBy_SortFields::on_button_edit_field()
       sharedptr<const LayoutItem_Field> field = row[m_ColumnsFields.m_col_layout_item];
 
       //Get the chosen field:
-      sharedptr<LayoutItem_Field> field_chosen = offer_field_list(field, m_table_name, this);
+      sharedptr<LayoutItem_Field> field_chosen = 
+        offer_field_list_select_one_field(field, m_table_name, this);
       if(field_chosen)
 
       //Set the field details in the layout treeview:
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index ae7a310..28d7b0a 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -640,7 +640,7 @@ bool ConnectionPool::startup(const SlotProgress& slot_progress, bool network_sha
 
   //If we crash while running (unlikely, hopefully), then try to cleanup.
   //Comment this out if you want to see the backtrace in a debugger.
-  previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
+  //previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
 
   return true;
 }
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.cc b/glom/libglom/data_structure/layout/layoutitem_field.cc
index 89234f6..4666cb6 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_field.cc
@@ -270,9 +270,13 @@ void LayoutItem_Field::set_title_custom(const sharedptr<CustomTitle>& title)
 
 bool LayoutItem_Field::is_same_field(const sharedptr<const LayoutItem_Field>& field) const
 {
+  const UsesRelationship* uses_a = this;
+  const UsesRelationship* uses_b = &(*field);
+  if(!uses_a || !uses_b)
+    return false; //Shouldn't happen.
+    
   return (get_name() == field->get_name()) &&
-         (get_relationship_name() == field->get_relationship_name()) &&
-         (get_related_relationship_name() == field->get_related_relationship_name());
+         (*uses_a == *uses_b);
 }
 
 Glib::ustring LayoutItem_Field::get_sql_name(const Glib::ustring& parent_table) const
diff --git a/glom/libglom/data_structure/layout/layoutitem_field.h b/glom/libglom/data_structure/layout/layoutitem_field.h
index 47b626b..3ce24a4 100644
--- a/glom/libglom/data_structure/layout/layoutitem_field.h
+++ b/glom/libglom/data_structure/layout/layoutitem_field.h
@@ -45,15 +45,10 @@ public:
 
   bool operator() (const sharedptr<const T_Element>& element)
   {
-    const bool result = (m_layout_item->get_name() == element->get_name());
-    
-    if(!result)
-      return false;
-    
-    //Compare the relationship and related relationshp:
-    sharedptr<const UsesRelationship> uses_a = m_layout_item;
-    sharedptr<const UsesRelationship> uses_b = element;
-    return (*uses_a == *uses_b);
+    if(!m_layout_item && !element)
+      return true;
+       
+    return m_layout_item && m_layout_item->is_same_field(element);
   }
     
 private:
diff --git a/glom/mode_data/dialog_choose_field.cc b/glom/mode_data/dialog_choose_field.cc
index 990dcf7..44fb4a1 100644
--- a/glom/mode_data/dialog_choose_field.cc
+++ b/glom/mode_data/dialog_choose_field.cc
@@ -85,6 +85,13 @@ void Dialog_ChooseField::set_document(Document* document, const Glib::ustring& t
   else
     m_combo_relationship->set_selected_parent_table(table_name, document->get_table_title(table_name)); 
 
+  //If one start field was specified, then multiple selection would not make 
+  //much sense. The caller probably wants single selection.
+  //Make this explicit in the API if that is not always suitable.
+  Glib::RefPtr<Gtk::TreeView::Selection> selection = m_treeview->get_selection();
+  selection->set_mode((field && !(field->get_name().empty()))
+    ? Gtk::SELECTION_SINGLE : Gtk::SELECTION_MULTIPLE); 
+   
   //Select the current field at the start:
   if(field)
   {
@@ -103,7 +110,8 @@ void Dialog_ChooseField::set_document(Document* document, const Glib::ustring& t
 
     if(iterFound != m_model->children().end())
     {
-      m_treeview->get_selection()->select(iterFound);
+      
+      selection->select(iterFound);
 
       //Make sure that it is scrolled into view:
       m_treeview->scroll_to_row(Gtk::TreeModel::Path(iterFound));
@@ -126,6 +134,10 @@ void Dialog_ChooseField::set_document(Document* document, const Glib::ustring& t
   {
     g_warning("Dialog_ChooseField::set_document(): table_name is empty");
   }
+  
+  Glib::RefPtr<Gtk::TreeView::Selection> selection = m_treeview->get_selection();
+  selection->set_mode(Gtk::SELECTION_MULTIPLE); 
+   
 
   //Update the tree models from the document
   if(document)
@@ -183,37 +195,69 @@ sharedptr<LayoutItem_Field> Dialog_ChooseField::get_field_chosen() const
 {
   sharedptr<LayoutItem_Field> field;
 
-  //Field:
-  Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = m_treeview->get_selection();
-  if(refTreeSelection)
+  type_list_field_items list_fields = get_fields_chosen();
+  if(!(list_fields.empty()))
   {
-    Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
-    if(iter)
-    {
-      if(m_start_field)
-        field = m_start_field; //Start with this, to preserve extra information such as Translations.
-      else
-        field = sharedptr<LayoutItem_Field>::create();
+    field = *(list_fields.begin()); 
+  }
+  
+  return field;
+}
 
-      //Relationship:
-      //Note that a null relationship means that the parent table was selected instead.
-      sharedptr<Relationship> related_relationship;
-      sharedptr<Relationship> relationship = m_combo_relationship->get_selected_relationship(related_relationship);
+Dialog_ChooseField::type_list_field_items Dialog_ChooseField::get_fields_chosen() const
+{
+  type_list_field_items list_fields;
 
-      //field.set_relationship_name(relationship_name);
+  //Field:
+  Glib::RefPtr<Gtk::TreeSelection> refTreeSelection = m_treeview->get_selection();
+  if(!refTreeSelection)
+    return list_fields;
+    
+  //Relationship:
+  //Note that a null relationship means that the parent table was selected instead.
+  sharedptr<Relationship> related_relationship;
+  sharedptr<Relationship> relationship = m_combo_relationship->get_selected_relationship(related_relationship);
 
-      field->set_relationship(relationship);
-      field->set_related_relationship(related_relationship);
+    
+  typedef std::list<Gtk::TreeModel::Path> type_list_paths;
+  type_list_paths list_paths = refTreeSelection->get_selected_rows();
+  for(type_list_paths::const_iterator iter = list_paths.begin(); iter != list_paths.end(); iter++)
+  {
+    const Gtk::TreeModel::Path path = *iter;
+    Gtk::TreeModel::iterator tree_iter = m_model->get_iter(path);
+    if(!tree_iter)
+      continue;
+      
+
+    // Setup a LayoutItem_Field for the Field, 
+    // so is_same_field() can work:
+    sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::create();
+    field->set_relationship(relationship);
+    field->set_related_relationship(related_relationship);
+      
+    Gtk::TreeModel::Row row = *tree_iter;
+    sharedptr<Field> field_details = row[m_ColumnsFields.m_col_field];
+    field->set_full_field_details(field_details); 
+      
+    // Start with the original LayoutItem_Field, 
+    // to preserve extra information such as Translations:
+    if(m_start_field && m_start_field->is_same_field(field))
+      field = m_start_field; 
+    else
+      field = sharedptr<LayoutItem_Field>::create();
 
+    //Use the chosen field:
+    field->set_relationship(relationship);
+    field->set_related_relationship(related_relationship);
+    field->set_full_field_details(field_details); //So is_same_field() can work.
 
-      Gtk::TreeModel::Row row = *iter;
-      sharedptr<Field> field_details = row[m_ColumnsFields.m_col_field];
-      field->set_full_field_details(field_details);
-      field->set_name(row[m_ColumnsFields.m_col_name]);
-    }
+    field->set_full_field_details(field_details);
+    field->set_name(row[m_ColumnsFields.m_col_name]);
+    
+    list_fields.push_back(field);
   }
 
-  return field;
+  return list_fields;
 }
 
 void Dialog_ChooseField::on_row_activated(const Gtk::TreeModel::Path& /* path */, Gtk::TreeViewColumn* /* view_column */)
@@ -272,6 +316,7 @@ void Dialog_ChooseField::on_combo_relationship_changed()
 
 void Dialog_ChooseField::on_treeview_selection_changed()
 {
+#if 0
   Glib::RefPtr<Gtk::TreeView::Selection> refSelection = m_treeview->get_selection();
   if(refSelection)
   {
@@ -289,6 +334,7 @@ void Dialog_ChooseField::on_treeview_selection_changed()
       */
     }
   }
+#endif
 }
 
 } //namespace Glom
diff --git a/glom/mode_data/dialog_choose_field.h b/glom/mode_data/dialog_choose_field.h
index c606c64..13f29fc 100644
--- a/glom/mode_data/dialog_choose_field.h
+++ b/glom/mode_data/dialog_choose_field.h
@@ -50,6 +50,9 @@ public:
   //void select_item(const sharedptr<const Field>& field);
 
   sharedptr<LayoutItem_Field> get_field_chosen() const;
+  
+  typedef std::list< sharedptr<LayoutItem_Field> > type_list_field_items;
+  type_list_field_items get_fields_chosen() const;
 
 private:
 
diff --git a/glom/mode_data/dialog_layout_calendar_related.cc b/glom/mode_data/dialog_layout_calendar_related.cc
index a8ff694..a2f5093 100644
--- a/glom/mode_data/dialog_layout_calendar_related.cc
+++ b/glom/mode_data/dialog_layout_calendar_related.cc
@@ -375,9 +375,13 @@ void Dialog_Layout_Calendar_Related::on_button_add_field()
   //std::cout << "debug: related relationship=" << glom_get_sharedptr_name(m_portal->get_related_relationship()) << std::endl;
   //std::cout << "debug table used =" << m_portal->get_table_used(m_table_name) << std::endl;
 
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_portal->get_table_used(m_table_name), this);
-  if(field)
+  type_list_field_items fields_list = offer_field_list(m_table_name, this);
+  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
   {
+    sharedptr<LayoutItem_Field> field = *iter_chosen;
+    if(!field)
+      continue;
+
     //Add the field details to the layout treeview:
     Gtk::TreeModel::iterator iter =  m_model_items->append();
     if(iter)
@@ -409,7 +413,7 @@ void Dialog_Layout_Calendar_Related::on_button_edit()
       sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
 
       //Get the chosen field:
-      sharedptr<LayoutItem_Field> field_chosen = offer_field_list(field, m_portal->get_table_used(m_table_name), this);
+      sharedptr<LayoutItem_Field> field_chosen = offer_field_list_select_one_field(field, m_portal->get_table_used(m_table_name), this);
       if(field_chosen)
       {
         //Set the field details in the layout treeview:
diff --git a/glom/mode_data/dialog_layout_details.cc b/glom/mode_data/dialog_layout_details.cc
index ced02c7..bbb8478 100644
--- a/glom/mode_data/dialog_layout_details.cc
+++ b/glom/mode_data/dialog_layout_details.cc
@@ -515,9 +515,13 @@ void Dialog_Layout_Details::on_button_down()
 
 void Dialog_Layout_Details::on_button_add_field()
 {
-  sharedptr<LayoutItem_Field> layout_item = offer_field_list(m_table_name, this);
-  if(layout_item)
+  type_list_field_items fields_list = offer_field_list(m_table_name, this);
+  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
   {
+    sharedptr<LayoutItem_Field> layout_item = *iter_chosen;
+    if(!layout_item)
+      continue;
+
     //Add the field details to the layout treeview:
     Gtk::TreeModel::iterator iter = append_appropriate_row();
     if(iter)
@@ -1010,7 +1014,7 @@ void Dialog_Layout_Details::on_button_edit()
             sharedptr<LayoutItem_Field> layout_item_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
             if(layout_item_field)
             {
-              sharedptr<LayoutItem_Field> chosenitem = offer_field_list(layout_item_field, m_table_name, this);
+              sharedptr<LayoutItem_Field> chosenitem = offer_field_list_select_one_field(layout_item_field, m_table_name, this);
               if(chosenitem)
               {
                 *layout_item_field = *chosenitem;
diff --git a/glom/mode_data/dialog_layout_export.cc b/glom/mode_data/dialog_layout_export.cc
index da50f25..6c31f23 100644
--- a/glom/mode_data/dialog_layout_export.cc
+++ b/glom/mode_data/dialog_layout_export.cc
@@ -256,10 +256,14 @@ void Dialog_Layout_Export::on_treeview_fields_selection_changed()
 
 void Dialog_Layout_Export::on_button_add_field()
 {
-  //Get the chosen field:
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_table_name, this);
-  if(field)
+  //Get the chosen fields:
+  type_list_field_items fields_list = offer_field_list(m_table_name, this);
+  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
   {
+    sharedptr<LayoutItem_Field> field = *iter_chosen;
+    if(!field)
+      continue;
+
     //Add the field details to the layout treeview:
     Gtk::TreeModel::iterator iter =  m_model_fields->append();
 
@@ -334,7 +338,7 @@ void Dialog_Layout_Export::on_button_edit_field()
       sharedptr<LayoutItem_Field> field = row[m_ColumnsFields.m_col_layout_item];
 
       //Get the chosen field:
-      sharedptr<LayoutItem_Field> field_chosen = offer_field_list(field, m_table_name, this);
+      sharedptr<LayoutItem_Field> field_chosen = offer_field_list_select_one_field(field, m_table_name, this);
       if(field_chosen)
       {
         //Set the field details in the layout treeview:
diff --git a/glom/mode_data/dialog_layout_list_related.cc b/glom/mode_data/dialog_layout_list_related.cc
index 9789561..cd04d4e 100644
--- a/glom/mode_data/dialog_layout_list_related.cc
+++ b/glom/mode_data/dialog_layout_list_related.cc
@@ -376,9 +376,13 @@ void Dialog_Layout_List_Related::on_button_add_field()
   //std::cout << "debug: related relationship=" << glom_get_sharedptr_name(m_portal->get_related_relationship()) << std::endl;
   //std::cout << "debug table used =" << m_portal->get_table_used(m_table_name) << std::endl;
 
-  sharedptr<LayoutItem_Field> field = offer_field_list(m_portal->get_table_used(m_table_name), this);
-  if(field)
+  type_list_field_items fields_list = offer_field_list(m_portal->get_table_used(m_table_name), this);
+  for(type_list_field_items::iterator iter_chosen = fields_list.begin(); iter_chosen != fields_list.end(); iter_chosen++) 
   {
+    sharedptr<LayoutItem_Field> field = *iter_chosen;
+    if(!field)
+      continue;
+
     //Add the field details to the layout treeview:
     Gtk::TreeModel::iterator iter = m_model_items->append();
     if(iter)
@@ -410,7 +414,7 @@ void Dialog_Layout_List_Related::on_button_edit()
       sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
 
       //Get the chosen field:
-      sharedptr<LayoutItem_Field> field_chosen = offer_field_list(field, m_portal->get_table_used(m_table_name), this);
+      sharedptr<LayoutItem_Field> field_chosen = offer_field_list_select_one_field(field, m_portal->get_table_used(m_table_name), this);
       if(field_chosen)
       {
         //Set the field details in the layout treeview:
diff --git a/glom/mode_design/print_layouts/canvas_print_layout.cc b/glom/mode_design/print_layouts/canvas_print_layout.cc
index 1c406c0..62f0ce5 100644
--- a/glom/mode_design/print_layouts/canvas_print_layout.cc
+++ b/glom/mode_design/print_layouts/canvas_print_layout.cc
@@ -345,7 +345,7 @@ void Canvas_PrintLayout::on_context_menu_edit()
   sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
   if(field)
   {
-    sharedptr<LayoutItem_Field> field_chosen = offer_field_list(field, m_table_name, parent);
+    sharedptr<LayoutItem_Field> field_chosen = offer_field_list_select_one_field(field, m_table_name, parent);
     if(field_chosen)
       m_context_item->set_layout_item(field_chosen);
   }
diff --git a/glom/reports/dialog_layout_report.cc b/glom/reports/dialog_layout_report.cc
index bfd8675..0cdf213 100644
--- a/glom/reports/dialog_layout_report.cc
+++ b/glom/reports/dialog_layout_report.cc
@@ -869,7 +869,7 @@ void Dialog_Layout_Report::on_button_edit()
         sharedptr<LayoutItem_Field> field = sharedptr<LayoutItem_Field>::cast_dynamic(item);
         if(field)
         {
-          sharedptr<LayoutItem_Field> chosenitem = offer_field_list(field, m_table_name, this);
+          sharedptr<LayoutItem_Field> chosenitem = offer_field_list_select_one_field(field, m_table_name, this);
           if(chosenitem)
           {
             *field = *chosenitem; //TODO_Performance.
diff --git a/glom/utility_widgets/datawidget.cc b/glom/utility_widgets/datawidget.cc
index 111f496..b37a798 100644
--- a/glom/utility_widgets/datawidget.cc
+++ b/glom/utility_widgets/datawidget.cc
@@ -598,7 +598,7 @@ sharedptr<LayoutItem_Field> DataWidget::offer_field_list(const Glib::ustring& ta
 
 sharedptr<LayoutItem_Field> DataWidget::offer_field_list(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& start_field)
 {
-  return offer_field_list (table_name, start_field, get_document(), get_application());
+  return offer_field_list(table_name, start_field, get_document(), get_application());
 }
 
 sharedptr<LayoutItem_Field> DataWidget::offer_field_list(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& start_field, Document* document, App_Glom* app)
diff --git a/glom/utility_widgets/datawidget.h b/glom/utility_widgets/datawidget.h
index 27be179..4d16513 100644
--- a/glom/utility_widgets/datawidget.h
+++ b/glom/utility_widgets/datawidget.h
@@ -63,6 +63,7 @@ public:
   static sharedptr<LayoutItem_Field> offer_field_list(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& start_field, Document* document, App_Glom* app);
   sharedptr<LayoutItem_Field> offer_field_list(const Glib::ustring& table_name);
   sharedptr<LayoutItem_Field> offer_field_list(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& start_field);
+
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   sharedptr<LayoutItem_Field> offer_field_layout(const sharedptr<const LayoutItem_Field>& start_field);
 #endif // !GLOM_ENABLE_CLIENT_ONLY



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