[glom] Allow to disable navigation in the related record layout.



commit 19ae8e52f0e4ff130bba90b6941e69ebe8fe066b
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Apr 23 18:14:53 2009 +0200

    Allow to disable navigation in the related record layout.
    
    * glom/libglom/data_structure/layout/layoutitem_portal.[h|cc] ctor(),
    [set|get]_navigation_relationship_specific(), [set|get]_navigation_type(),
    set_navigation_type(): Replaced the flag for whether a specific navigation
    relationship should be used with an enum type, since we now have an
    additional state (no navigation relationship) in the Glom::LayoutItem_Portal
    class. Additionally, this internal state no longer needs to be exported so
    [set|get]_navigation_relationship_specific() can now be called without
    supplying a boolean output parameter.
    * glom/libglom/document/document.cc load_after_layout_group(),
    save_before_layout_group(): Added load and save support for the
    no-navigation-relationship option.
    * glom/mode_data/box_data_portal.cc get_suitable_table_to_view_details():
    Return an empty table name if the navigation relationship type was set to
    none.
    * glom/mode_data/dialog_layout_list_related.[h,cc] ctor(), update_ui(),
    save_to_document(), glom/glom_developer.glade: Insert a third choice (none)
    for the navigation radio buttons.
    * glom/mode_data/dialog_layout_calendar_related.cc update_ui(),
    save_to_document(): Replaced calls to
    LayoutItem_Portal::[set|get]_navigation_relationship_specific() that still
    used a boolean output parameter.
---
 ChangeLog                                          |   26 ++++++++
 glom/glom_developer.glade                          |   29 +++++++++-
 .../data_structure/layout/layoutitem_portal.cc     |   47 +++++++++------
 .../data_structure/layout/layoutitem_portal.h      |   24 +++++--
 glom/libglom/document/document.cc                  |   65 +++++++++++++-------
 glom/mode_data/box_data_portal.cc                  |   20 +++---
 glom/mode_data/dialog_layout_calendar_related.cc   |   14 ++---
 glom/mode_data/dialog_layout_list_related.cc       |   50 +++++++++++----
 glom/mode_data/dialog_layout_list_related.h        |    1 +
 9 files changed, 196 insertions(+), 80 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 338a714..a3510d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2009-04-22  Michael Hasselmann  <michaelh openismus com>
+
+	Allow to disable navigation in the related record layout.
+
+	* glom/libglom/data_structure/layout/layoutitem_portal.[h|cc] ctor(),
+	[set|get]_navigation_relationship_specific(), [set|get]_navigation_type(),
+	set_navigation_type(): Replaced the flag for whether a specific navigation
+	relationship should be used with an enum type, since we now have an
+	additional state (no navigation relationship) in the Glom::LayoutItem_Portal
+	class. Additionally, this internal state no longer needs to be exported so
+	[set|get]_navigation_relationship_specific() can now be called without
+	supplying a boolean output parameter.
+	* glom/libglom/document/document.cc load_after_layout_group(),
+	save_before_layout_group(): Added load and save support for the
+	no-navigation-relationship option.
+	* glom/mode_data/box_data_portal.cc get_suitable_table_to_view_details():
+	Return an empty table name if the navigation relationship type was set to
+	none.
+	* glom/mode_data/dialog_layout_list_related.[h,cc] ctor(), update_ui(),
+	save_to_document(), glom/glom_developer.glade: Insert a third choice ("none")
+	for the navigation radio buttons.
+	* glom/mode_data/dialog_layout_calendar_related.cc update_ui(),
+	save_to_document(): Replaced calls to
+	LayoutItem_Portal::[set|get]_navigation_relationship_specific() that still
+	used a boolean output parameter.
+
 2009-04-17  Murray Cumming  <murrayc murrayc com>
 
 	Makes navigation work to alternate specified relationships.
diff --git a/glom/glom_developer.glade b/glom/glom_developer.glade
index 673fd2c..6f7248a 100644
--- a/glom/glom_developer.glade
+++ b/glom/glom_developer.glade
@@ -9488,6 +9488,33 @@ What name should this module have?</property>
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkHBox" id="hbox130b">
+                        <property name="visible">True</property>
+                        <property name="spacing">6</property>
+                        <child>
+                          <object class="GtkRadioButton" id="radiobutton_navigation_none">
+                            <property name="label" translatable="yes">None</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>
+                            <property name="group">radiobutton_navigation_automatic</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="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkHBox" id="hbox131">
                         <property name="visible">True</property>
                         <child>
@@ -9516,7 +9543,7 @@ What name should this module have?</property>
                         </child>
                       </object>
                       <packing>
-                        <property name="position">2</property>
+                        <property name="position">3</property>
                       </packing>
                     </child>
                   </object>
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.cc b/glom/libglom/data_structure/layout/layoutitem_portal.cc
index c961f00..e34f645 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.cc
@@ -25,17 +25,17 @@ namespace Glom
 {
 
 LayoutItem_Portal::LayoutItem_Portal()
-: m_navigation_relationship_specific_main(false),
-  m_print_layout_row_height(20) //arbitrary default.
+: m_print_layout_row_height(20), //arbitrary default.
+  m_navigation_type(LayoutItem_Portal::NAVIGATION_AUTOMATIC)
 {
 }
 
 LayoutItem_Portal::LayoutItem_Portal(const LayoutItem_Portal& src)
 : LayoutGroup(src),
   UsesRelationship(src),
-  m_navigation_relationship_specific_main(src.m_navigation_relationship_specific_main),
   m_navigation_relationship_specific(src.m_navigation_relationship_specific),
-  m_print_layout_row_height(src.m_print_layout_row_height)
+  m_print_layout_row_height(src.m_print_layout_row_height),
+  m_navigation_type(src.m_navigation_type)
 {
 }
 
@@ -54,9 +54,9 @@ LayoutItem_Portal& LayoutItem_Portal::operator=(const LayoutItem_Portal& src)
   LayoutGroup::operator=(src);
   UsesRelationship::operator=(src);
 
-  m_navigation_relationship_specific_main = src.m_navigation_relationship_specific_main;
   m_navigation_relationship_specific = src.m_navigation_relationship_specific;
   m_print_layout_row_height = src.m_print_layout_row_height;
+  m_navigation_type = src.m_navigation_type;
 
   return *this;
 }
@@ -102,41 +102,42 @@ void LayoutItem_Portal::change_field_item_name(const Glib::ustring& table_name,
   }
 }
 
-sharedptr<UsesRelationship> LayoutItem_Portal::get_navigation_relationship_specific(bool& main_relationship)
+sharedptr<UsesRelationship> LayoutItem_Portal::get_navigation_relationship_specific()
 {
-  main_relationship = m_navigation_relationship_specific_main;
-  if(!main_relationship)
+  if(this->get_navigation_type() == LayoutItem_Portal::NAVIGATION_SPECIFIC)
     return m_navigation_relationship_specific;
   else
     return sharedptr<UsesRelationship>();
 }
 
-sharedptr<const UsesRelationship> LayoutItem_Portal::get_navigation_relationship_specific(bool& main_relationship) const
+sharedptr<const UsesRelationship> LayoutItem_Portal::get_navigation_relationship_specific() const
 {
-  main_relationship = m_navigation_relationship_specific_main;
-  if(!main_relationship)
+  if(this->get_navigation_type() == LayoutItem_Portal::NAVIGATION_SPECIFIC)
     return m_navigation_relationship_specific;
   else
     return sharedptr<UsesRelationship>();
 }
 
-void LayoutItem_Portal::set_navigation_relationship_specific(bool main_relationship, const sharedptr<UsesRelationship>& relationship)
+void LayoutItem_Portal::set_navigation_relationship_specific(const sharedptr<UsesRelationship>& relationship)
+{
+  m_navigation_relationship_specific = relationship;
+  m_navigation_type = LayoutItem_Portal::NAVIGATION_SPECIFIC;
+}
+
+void LayoutItem_Portal::reset_navigation_relationship()
 {
-  m_navigation_relationship_specific_main = main_relationship;
-  if(!m_navigation_relationship_specific_main)
-    m_navigation_relationship_specific = relationship;
-  else
     m_navigation_relationship_specific = sharedptr<UsesRelationship>();
+    m_navigation_type = LayoutItem_Portal::NAVIGATION_AUTOMATIC;
 }
 
 Glib::ustring LayoutItem_Portal::get_from_table() const
 {
   Glib::ustring from_table;
-  
+
   sharedptr<const Relationship> relationship = get_relationship();
   if(relationship)
     from_table = relationship->get_from_table();
-  
+
   return from_table;
 }
 
@@ -150,6 +151,16 @@ void LayoutItem_Portal::set_print_layout_row_height(double row_height)
   m_print_layout_row_height = row_height;
 }
 
+LayoutItem_Portal::navigation_type LayoutItem_Portal::get_navigation_type() const
+{
+  return m_navigation_type;
+}
+
+void LayoutItem_Portal::set_navigation_type(LayoutItem_Portal::navigation_type type)
+{
+  m_navigation_type = type;
+}
+
 /*
 void LayoutItem_Portal::debug(guint level) const
 {
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.h b/glom/libglom/data_structure/layout/layoutitem_portal.h
index b3fd787..7fd6593 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.h
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.h
@@ -51,9 +51,10 @@ public:
 
   //virtual void debug(guint level = 0) const;
 
-  sharedptr<UsesRelationship> get_navigation_relationship_specific(bool& main_relationship);
-  sharedptr<const UsesRelationship> get_navigation_relationship_specific(bool& main_relationship) const;
-  void set_navigation_relationship_specific(bool main_relationship, const sharedptr<UsesRelationship>& relationship);
+  sharedptr<UsesRelationship> get_navigation_relationship_specific();
+  sharedptr<const UsesRelationship> get_navigation_relationship_specific() const;
+  void set_navigation_relationship_specific(const sharedptr<UsesRelationship>& relationship);
+  void reset_navigation_relationship();
 
   /// This is used only for the print layouts.
   double get_print_layout_row_height() const;
@@ -61,19 +62,28 @@ public:
   /// This is used only for the print layouts.
   void set_print_layout_row_height(double row_height);
 
+  enum navigation_type
+  {
+    NAVIGATION_NONE,
+    NAVIGATION_AUTOMATIC,
+    NAVIGATION_SPECIFIC
+  };
+
+  navigation_type get_navigation_type() const;
+  void set_navigation_type(navigation_type type);
+
 private:
 
-  //If no navigation relationship has been specified then it will be automatically chosen: 
-  bool m_navigation_relationship_specific_main;
   sharedptr<UsesRelationship> m_navigation_relationship_specific;
 
   // This is used only for the print layouts.
   double m_print_layout_row_height;
+
+  //If no navigation relationship has been specified then it will be automatically chosen or navigation will be disabled:
+  navigation_type m_navigation_type;
 };
 
 } //namespace Glom
 
 #endif //GLOM_DATASTRUCTURE_LAYOUTITEM_PORTAL_H
 
-
-
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 31aebd1..082baec 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -74,6 +74,7 @@ namespace Glom
 #define GLOM_NODE_DATA_LAYOUT_PORTAL "data_layout_portal"
 #define GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP "portal_navigation_relationship"
 #define GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN "navigation_main"
+#define GLOM_ATTRIBUTE_PORTAL_NAVIGATION_TYPE "navigation_type"
 #define GLOM_NODE_DATA_LAYOUT_CALENDAR_PORTAL "data_layout_calendar_portal"
 #define GLOM_ATTRIBUTE_PORTAL_PRINT_LAYOUT_ROW_HEIGHT "row_height"
 #define GLOM_ATTRIBUTE_PORTAL_CALENDAR_DATE_FIELD "date_field"
@@ -2168,28 +2169,35 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
           portal = calendar_portal;
         }
 
-        load_after_layout_item_usesrelationship(element, table_name, portal); 
-       
-        sharedptr<UsesRelationship> relationship_navigation_specific;
-        bool relationship_navigation_specific_main = false;
+        load_after_layout_item_usesrelationship(element, table_name, portal);
+
         xmlpp::Element* elementNavigationRelationshipSpecific = get_node_child_named(element, GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP);
         if(elementNavigationRelationshipSpecific)
         {
-           relationship_navigation_specific = sharedptr<UsesRelationship>::create();
-           load_after_layout_item_usesrelationship(elementNavigationRelationshipSpecific, portal->get_table_used(table_name), relationship_navigation_specific);
-           relationship_navigation_specific_main = get_node_attribute_value_as_bool(elementNavigationRelationshipSpecific, GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN);
-
-           if(relationship_navigation_specific)
-           {
-            std::cout << "  debug: relationship_navigation_specific->relationship=" << relationship_navigation_specific->get_relationship_name() << std::endl;
-
-           }
+          const Glib::ustring navigation_type_as_string = get_node_attribute_value(elementNavigationRelationshipSpecific, GLOM_ATTRIBUTE_PORTAL_NAVIGATION_TYPE);
+          // If no GLOM_ATTRIBUTE_PORTAL_NAVIGATION_TYPE was found, or if the
+          // string it contains could not be mapped then we stick with the
+          // portal class' default for its navigation_type member,
+          // LayoutItem_Portal::NAVIGATION_AUTOMATIC. This keeps us
+          // read-compatible with older versions of Glom files.
+          if(0 == navigation_type_as_string.compare("automatic"))
+          {
+            portal->set_navigation_type(LayoutItem_Portal::NAVIGATION_AUTOMATIC);
+          }
+          else if(0 == navigation_type_as_string.compare("none"))
+          {
+            portal->set_navigation_type(LayoutItem_Portal::NAVIGATION_NONE);
+          }
+          else if(0 == navigation_type_as_string.compare("specific"))
+          {
+            sharedptr<UsesRelationship>relationship_navigation_specific = sharedptr<UsesRelationship>::create();
+            load_after_layout_item_usesrelationship(elementNavigationRelationshipSpecific, portal->get_table_used(table_name), relationship_navigation_specific);
+            portal->set_navigation_relationship_specific(relationship_navigation_specific);
+          }
         }
 
-        portal->set_navigation_relationship_specific(relationship_navigation_specific_main, relationship_navigation_specific);
-
         load_after_layout_group(element, portal->get_table_used(table_name), portal, with_print_layout_positions);
-        
+
         //Get the calendar portal's date field:
         if(calendar_portal)
         {
@@ -3012,14 +3020,25 @@ void Document::save_before_layout_group(xmlpp::Element* node, const sharedptr<co
               save_before_layout_item_usesrelationship(child, portal);
 
               //Portal navigation details:
-              bool navigation_specific_main = false;
-              sharedptr<const UsesRelationship> relationship_navigation_specific = portal->get_navigation_relationship_specific(navigation_specific_main);
-              if(navigation_specific_main || relationship_navigation_specific) //Avoid wasting a node if these are not even specified.
+              xmlpp::Element* child_navigation_relationship = child->add_child(GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP);
+              if(portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_AUTOMATIC)
               {
-                xmlpp::Element* child_navigation_relationship_specific = child->add_child(GLOM_NODE_DATA_LAYOUT_PORTAL_NAVIGATIONRELATIONSHIP);
-
-                save_before_layout_item_usesrelationship(child_navigation_relationship_specific, relationship_navigation_specific);
-                set_node_attribute_value_as_bool(child_navigation_relationship_specific, GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN, navigation_specific_main);
+                sharedptr<const UsesRelationship> relationship_navigation_none;
+                save_before_layout_item_usesrelationship(child_navigation_relationship, relationship_navigation_none);
+                set_node_attribute_value(child_navigation_relationship, GLOM_ATTRIBUTE_PORTAL_NAVIGATION_TYPE, "automatic");
+              }
+              else if(portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_NONE)
+              {
+                sharedptr<const UsesRelationship> relationship_navigation_none;
+                save_before_layout_item_usesrelationship(child_navigation_relationship, relationship_navigation_none);
+                set_node_attribute_value(child_navigation_relationship, GLOM_ATTRIBUTE_PORTAL_NAVIGATION_TYPE, "none");
+              }
+              else if(portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_SPECIFIC)
+              {
+                sharedptr<const UsesRelationship> relationship_navigation_specific = portal->get_navigation_relationship_specific();
+                save_before_layout_item_usesrelationship(child_navigation_relationship, relationship_navigation_specific);
+                set_node_attribute_value_as_bool(child_navigation_relationship, GLOM_ATTRIBUTE_PORTAL_NAVIGATIONRELATIONSHIP_MAIN, false);
+                set_node_attribute_value(child_navigation_relationship, GLOM_ATTRIBUTE_PORTAL_NAVIGATION_TYPE, "specific");
               }
 
               //Print Layout specific stuff:
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index bfb3f48..6885a29 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -211,21 +211,21 @@ bool Box_Data_Portal::get_has_suitable_record_to_view_details() const
 
 void Box_Data_Portal::get_suitable_table_to_view_details(Glib::ustring& table_name, sharedptr<const UsesRelationship>& relationship) const
 {
- 
   //Initialize output parameters:
   table_name = Glib::ustring();
 
   if(!m_portal)
     return;
 
+
+  sharedptr<const UsesRelationship> navigation_relationship = m_portal->get_navigation_relationship_specific();
+
   //Check whether a relationship was specified:
-  bool navigation_relationship_main = false;
-  sharedptr<const UsesRelationship> navigation_relationship = m_portal->get_navigation_relationship_specific(navigation_relationship_main);
-  if(!navigation_relationship_main && !navigation_relationship)
+  if(m_portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_AUTOMATIC)
   {
     //std::cout << "debug: decide automatically." << std::endl;
     //Decide automatically:
-    navigation_relationship_main = false;
+    bool navigation_relationship_main = false; // no longer used
     navigation_relationship = get_portal_navigation_relationship_automatic(m_portal, navigation_relationship_main);
     //std::cout << "debug: auto main=" << navigation_relationship_main << ", navigation_relationship=" << (navigation_relationship ? navigation_relationship->get_name() : navigation_relationship->get_relationship()->get_name()) << std::endl;
   }
@@ -239,20 +239,22 @@ void Box_Data_Portal::get_suitable_table_to_view_details(Glib::ustring& table_na
 
   //Get the navigation table name from the chosen relationship:
   const Glib::ustring directly_related_table_name = m_portal->get_table_used(Glib::ustring() /* not relevant */);
- 
+
+  // The navigation_table_name (and therefore, the table_name output parameter,
+  // as well) stays empty if the navrel type was set to none.
   Glib::ustring navigation_table_name;
-  if(navigation_relationship_main)
+  if(m_portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_AUTOMATIC)
   {
     navigation_table_name = directly_related_table_name;
   }
-  else if(navigation_relationship)
+  else if(m_portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_SPECIFIC)
   {
     navigation_table_name = navigation_relationship->get_table_used(directly_related_table_name);
   }
 
   if(navigation_table_name.empty())
   {
-    std::cerr << "Box_Data_Portal::get_suitable_table_to_view_details(): navigation_table_name is empty." << std::endl;
+    //std::cerr << "Box_Data_Portal::get_suitable_table_to_view_details(): navigation_table_name is empty." << std::endl;
     return;
   }
 
diff --git a/glom/mode_data/dialog_layout_calendar_related.cc b/glom/mode_data/dialog_layout_calendar_related.cc
index 9c22da9..3049fc9 100644
--- a/glom/mode_data/dialog_layout_calendar_related.cc
+++ b/glom/mode_data/dialog_layout_calendar_related.cc
@@ -199,12 +199,9 @@ void Dialog_Layout_Calendar_Related::update_ui(bool including_relationship_list)
   //m_combo_navigation_specify->set_display_parent_table(""); //This would be superfluous, and a bit confusing.
 
   bool navigation_is_automatic = false;
-  bool navigation_specific_main = false;
-  sharedptr<UsesRelationship> navrel = m_portal->get_navigation_relationship_specific(navigation_specific_main);
-  if(navigation_specific_main)
-    m_combo_navigation_specify->set_selected_parent_table(related_table_name);
-  else if(navrel)
+  if(m_portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_SPECIFIC)
   {
+    sharedptr<UsesRelationship> navrel = m_portal->get_navigation_relationship_specific();
     //std::cout << "debug navrel=" << navrel->get_relationship()->get_name() << std::endl;
     m_combo_navigation_specify->set_selected_relationship(navrel->get_relationship(), navrel->get_related_relationship());
   }
@@ -227,7 +224,7 @@ void Dialog_Layout_Calendar_Related::update_ui(bool including_relationship_list)
   bool navigation_automatic_main = false;
   relationship_navigation_automatic = get_portal_navigation_relationship_automatic(m_portal, navigation_automatic_main);
   Glib::ustring automatic_navigation_description;
-  
+
   if(navigation_automatic_main)
     automatic_navigation_description = m_portal->get_relationship_name_used();
   else if(relationship_navigation_automatic)
@@ -300,14 +297,15 @@ void Dialog_Layout_Calendar_Related::save_to_document()
       uses_rel->set_relationship(rel);
       uses_rel->set_related_relationship(rel_related);
 
-      m_portal->set_navigation_relationship_specific(specify_main, uses_rel);
+      if (rel || rel_related)
+        m_portal->set_navigation_relationship_specific(uses_rel);
       //std::cout << "debug99 main=specify_main" << ", relationship=" << (rel ? rel->get_name() : "none") << std::endl;
     }
     else
     {
       //std::cout << "debug: set_navigation_relationship_specific(false, none)" << std::endl;
       sharedptr<UsesRelationship> none;
-      m_portal->set_navigation_relationship_specific(false, none);
+      m_portal->set_navigation_relationship_specific(none);
     }
     
     m_portal->set_date_field( m_combobox_date_field->get_selected_field() );
diff --git a/glom/mode_data/dialog_layout_list_related.cc b/glom/mode_data/dialog_layout_list_related.cc
index f93a309..9789561 100644
--- a/glom/mode_data/dialog_layout_list_related.cc
+++ b/glom/mode_data/dialog_layout_list_related.cc
@@ -35,6 +35,7 @@ Dialog_Layout_List_Related::Dialog_Layout_List_Related(BaseObjectType* cobject,
   m_combo_relationship(0),
   m_checkbutton_show_child_relationships(0),
   m_radio_navigation_automatic(0),
+  m_radio_navigation_none(0),
   m_radio_navigation_specify(0),
   m_label_navigation_automatic(0),
   m_combo_navigation_specify(0)
@@ -56,6 +57,8 @@ Dialog_Layout_List_Related::Dialog_Layout_List_Related(BaseObjectType* cobject,
   builder->get_widget("label_navigation_automatic", m_label_navigation_automatic);
   make_sensitivity_depend_on_toggle_button(*m_radio_navigation_automatic, *m_label_navigation_automatic);
 
+  builder->get_widget("radiobutton_navigation_none", m_radio_navigation_none);
+
   builder->get_widget("radiobutton_navigation_specify", m_radio_navigation_specify);
   builder->get_widget_derived("combobox_navigation_specify", m_combo_navigation_specify);
   make_sensitivity_depend_on_toggle_button(*m_radio_navigation_specify, *m_combo_navigation_specify);
@@ -190,29 +193,34 @@ void Dialog_Layout_List_Related::update_ui(bool including_relationship_list)
   m_combo_navigation_specify->set_relationships(document, related_table_name, true /* show related relationships */, false /* don't show parent table */); //TODO: Don't show the hidden tables, and don't show relationships that are not used by any fields.
   //m_combo_navigation_specify->set_display_parent_table(""); //This would be superfluous, and a bit confusing.
 
-  bool navigation_is_automatic = false;
-  bool navigation_specific_main = false;
-  sharedptr<UsesRelationship> navrel = m_portal->get_navigation_relationship_specific(navigation_specific_main);
-  if(navigation_specific_main)
-    m_combo_navigation_specify->set_selected_parent_table(related_table_name);
-  else if(navrel)
+  if(m_portal->get_navigation_type() == LayoutItem_Portal::NAVIGATION_SPECIFIC)
   {
+    sharedptr<UsesRelationship> navrel = m_portal->get_navigation_relationship_specific();
     //std::cout << "debug navrel=" << navrel->get_relationship()->get_name() << std::endl;
     m_combo_navigation_specify->set_selected_relationship(navrel->get_relationship(), navrel->get_related_relationship());
   }
   else
   {
-    navigation_is_automatic = true;
-
     sharedptr<const Relationship> none;
     m_combo_navigation_specify->set_selected_relationship(none);
   }
 
   //Set the appropriate radio button:
-  //std::cout << "debug: navigation_is_automatic=" << navigation_is_automatic << std::endl;
-  m_radio_navigation_automatic->set_active(navigation_is_automatic); 
-  m_radio_navigation_specify->set_active(!navigation_is_automatic); 
+  //std::cout << "debug: navrel_type=" << m_portal->get_navigation_relationship_type() << std::endl;
+  switch(m_portal->get_navigation_type())
+  {
+    case LayoutItem_Portal::NAVIGATION_NONE:
+      m_radio_navigation_none->set_active(true);
+      break;
 
+    case LayoutItem_Portal::NAVIGATION_AUTOMATIC:
+      m_radio_navigation_automatic->set_active(true);
+      break;
+
+    case LayoutItem_Portal::NAVIGATION_SPECIFIC:
+      m_radio_navigation_specify->set_active(true);
+      break;
+  }
 
   //Describe the automatic navigation:
   sharedptr<const UsesRelationship> relationship_navigation_automatic;
@@ -279,20 +287,34 @@ void Dialog_Layout_List_Related::save_to_document()
       sharedptr<Relationship> rel, rel_related;
       rel = m_combo_navigation_specify->get_selected_relationship(rel_related);
 
-      bool specify_main = (!rel && !rel_related);
       sharedptr<UsesRelationship> uses_rel = sharedptr<UsesRelationship>::create();
       uses_rel->set_relationship(rel);
       uses_rel->set_related_relationship(rel_related);
 
-      m_portal->set_navigation_relationship_specific(specify_main, uses_rel);
+      if(rel || rel_related)
+        m_portal->set_navigation_relationship_specific(uses_rel);
       //std::cout << "debug99 main=specify_main" << ", relationship=" << (rel ? rel->get_name() : "none") << std::endl;
     }
     else
     {
+      // TODO: Get rid of the else branch. Cleanup code for the relations should
+      // go into the Glom::LayoutItem_Portal::set_navigation_relationship_type_* functions.
+
       //std::cout << "debug: set_navigation_relationship_specific(false, none)" << std::endl;
       sharedptr<UsesRelationship> none;
-      m_portal->set_navigation_relationship_specific(false, none);
+      m_portal->set_navigation_relationship_specific(none);
     }
+
+    if (m_radio_navigation_automatic->get_active())
+      m_portal->set_navigation_type(LayoutItem_Portal::NAVIGATION_AUTOMATIC);
+
+    if(m_radio_navigation_none->get_active())
+    {
+      sharedptr<UsesRelationship> uses_rel = sharedptr<UsesRelationship>::create();
+      uses_rel->set_related_relationship(sharedptr<Relationship>());
+      m_portal->set_navigation_type(LayoutItem_Portal::NAVIGATION_NONE);
+    }
+
   }
 }
 
diff --git a/glom/mode_data/dialog_layout_list_related.h b/glom/mode_data/dialog_layout_list_related.h
index 0f2bbee..03c3c5c 100644
--- a/glom/mode_data/dialog_layout_list_related.h
+++ b/glom/mode_data/dialog_layout_list_related.h
@@ -66,6 +66,7 @@ protected:
   sharedptr<LayoutItem_Portal> m_portal;
 
   Gtk::RadioButton* m_radio_navigation_automatic;
+  Gtk::RadioButton* m_radio_navigation_none;
   Gtk::RadioButton* m_radio_navigation_specify;
   Gtk::Label* m_label_navigation_automatic;
   ComboBox_Relationship* m_combo_navigation_specify;



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