glom r1423 - in trunk: . glom glom/mode_data



Author: jhs
Date: Tue Feb 19 14:37:15 2008
New Revision: 1423
URL: http://svn.gnome.org/viewvc/glom?rev=1423&view=rev

Log:
2008-02-19  Johannes Schmid <johannes schmid openismus com>

	* glom/frame_glom.cc:
	Fixed crasher when using Tables menu
	
	* glom/glom.glade:
	Removed unused dialog

2008-02-19  Johannes Schmid <johannes schmid openismus com>

	* glom/mode_data/flowtablewithfields.cc:
	* glom/mode_data/flowtablewithfields.h:
	Cleaned up dnd code in FlowTableWithFields


Modified:
   trunk/ChangeLog
   trunk/glom/frame_glom.cc
   trunk/glom/glom.glade
   trunk/glom/mode_data/flowtablewithfields.cc
   trunk/glom/mode_data/flowtablewithfields.h

Modified: trunk/glom/frame_glom.cc
==============================================================================
--- trunk/glom/frame_glom.cc	(original)
+++ trunk/glom/frame_glom.cc	Tue Feb 19 14:37:15 2008
@@ -251,7 +251,8 @@
 
 void Frame_Glom::on_box_tables_selected(const Glib::ustring& strName)
 {
-  m_pDialog_Tables->hide(); //cause_close();
+  if (m_pDialog_Tables)
+    m_pDialog_Tables->hide(); //cause_close();
 
   show_table(strName);
 }
@@ -853,6 +854,7 @@
 
 void Frame_Glom::do_menu_Navigate_Table(bool open_default)
 {
+  
   if(get_document()->get_connection_database().empty())
   {
     alert_no_table();
@@ -862,13 +864,6 @@
   Glib::ustring default_table_name;
   if(open_default)
     default_table_name = get_document()->get_default_table();
-
-  if(!default_table_name.empty())
-  {
-    //Show the default table, and let the user navigate to another table manually if he wants:
-    show_table(default_table_name);
-    return;
-  }
   
   //Create the dialog, if it has not already been created:
   if(!m_pBox_Tables)
@@ -896,7 +891,15 @@
   //Let the user choose a table:
   //m_pDialog_Tables->set_policy(false, true, false); //TODO_port
   //m_pDialog_Tables->load_from_document(); //Refresh
-  m_pDialog_Tables->show();
+  if(!default_table_name.empty())
+  {
+    //Show the default table, and let the user navigate to another table manually if he wants:
+    show_table(default_table_name);
+  }
+  else
+  {
+    m_pDialog_Tables->show();
+  }
 }
 
 const Gtk::Window* Frame_Glom::get_app_window() const

Modified: trunk/glom/glom.glade
==============================================================================
--- trunk/glom/glom.glade	(original)
+++ trunk/glom/glom.glade	Tue Feb 19 14:37:15 2008
@@ -251,10 +251,10 @@
                           <widget class="GtkRecentChooserWidget" id="existing_or_new_recentchooser">
                             <property name="visible">True</property>
                             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                            <property name="show_not_found">True</property>
                             <property name="show_tips">True</property>
-                            <property name="limit">15</property>
                             <property name="sort_type">GTK_RECENT_SORT_MRU</property>
-                            <property name="show_not_found">True</property>
+                            <property name="limit">15</property>
                           </widget>
                         </child>
                       </widget>
@@ -449,128 +449,128 @@
                     <property name="column_spacing">6</property>
                     <property name="row_spacing">6</property>
                     <child>
-                      <widget class="GtkEntry" id="entry_host">
+                      <widget class="GtkLabel" id="label_database">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="invisible_char">*</property>
+                        <property name="xalign">0</property>
                       </widget>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkLabel" id="label64">
+                      <widget class="GtkLabel" id="label68">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_Host</property>
-                        <property name="use_underline">True</property>
+                        <property name="label" translatable="yes">Database</property>
                         <property name="justify">GTK_JUSTIFY_RIGHT</property>
-                        <property name="mnemonic_widget">entry_host</property>
-                        <accessibility>
-                          <atkrelation target="entry_host" type="label-for"/>
-                        </accessibility>
                       </widget>
                       <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkLabel" id="label66">
+                      <widget class="GtkLabel" id="label65">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_Password</property>
+                        <property name="label" translatable="yes">_User</property>
                         <property name="use_underline">True</property>
                         <property name="justify">GTK_JUSTIFY_RIGHT</property>
-                        <property name="mnemonic_widget">entry_password</property>
+                        <property name="mnemonic_widget">entry_user</property>
                         <accessibility>
-                          <atkrelation target="entry_password" type="label-for"/>
+                          <atkrelation target="entry_user" type="label-for"/>
                         </accessibility>
                       </widget>
                       <packing>
-                        <property name="top_attach">3</property>
-                        <property name="bottom_attach">4</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkEntry" id="entry_password">
+                      <widget class="GtkEntry" id="entry_user">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
-                        <property name="has_focus">True</property>
-                        <property name="visibility">False</property>
                         <property name="invisible_char">*</property>
-                        <property name="activates_default">True</property>
                       </widget>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">3</property>
-                        <property name="bottom_attach">4</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkEntry" id="entry_user">
+                      <widget class="GtkEntry" id="entry_password">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
+                        <property name="has_focus">True</property>
+                        <property name="visibility">False</property>
                         <property name="invisible_char">*</property>
+                        <property name="activates_default">True</property>
                       </widget>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkLabel" id="label65">
+                      <widget class="GtkLabel" id="label66">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">_User</property>
+                        <property name="label" translatable="yes">_Password</property>
                         <property name="use_underline">True</property>
                         <property name="justify">GTK_JUSTIFY_RIGHT</property>
-                        <property name="mnemonic_widget">entry_user</property>
+                        <property name="mnemonic_widget">entry_password</property>
                         <accessibility>
-                          <atkrelation target="entry_user" type="label-for"/>
+                          <atkrelation target="entry_password" type="label-for"/>
                         </accessibility>
                       </widget>
                       <packing>
-                        <property name="top_attach">2</property>
-                        <property name="bottom_attach">3</property>
+                        <property name="top_attach">3</property>
+                        <property name="bottom_attach">4</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkLabel" id="label68">
+                      <widget class="GtkLabel" id="label64">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Database</property>
+                        <property name="label" translatable="yes">_Host</property>
+                        <property name="use_underline">True</property>
                         <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                        <property name="mnemonic_widget">entry_host</property>
+                        <accessibility>
+                          <atkrelation target="entry_host" type="label-for"/>
+                        </accessibility>
                       </widget>
                       <packing>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
                         <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkLabel" id="label_database">
+                      <widget class="GtkEntry" id="entry_host">
                         <property name="visible">True</property>
-                        <property name="xalign">0</property>
+                        <property name="can_focus">True</property>
+                        <property name="invisible_char">*</property>
                       </widget>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
-                        <property name="x_options">GTK_FILL</property>
                         <property name="y_options"></property>
                       </packing>
                     </child>
@@ -1249,12 +1249,9 @@
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkButton" id="button_find_all">
+                      <widget class="GtkLabel" id="label_records_count">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="label" translatable="yes">Find All</property>
-                        <property name="use_underline">True</property>
-                        <property name="response_id">0</property>
+                        <property name="label" translatable="yes">0</property>
                       </widget>
                       <packing>
                         <property name="expand">False</property>
@@ -1264,9 +1261,12 @@
                       </packing>
                     </child>
                     <child>
-                      <widget class="GtkLabel" id="label_records_count">
+                      <widget class="GtkButton" id="button_find_all">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">0</property>
+                        <property name="can_focus">True</property>
+                        <property name="label" translatable="yes">Find All</property>
+                        <property name="use_underline">True</property>
+                        <property name="response_id">0</property>
                       </widget>
                       <packing>
                         <property name="expand">False</property>
@@ -1320,128 +1320,4 @@
       </widget>
     </child>
   </widget>
-  <widget class="GtkDialog" id="dialog_drop_field">
-    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">Add layout item</property>
-    <property name="modal">True</property>
-    <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
-    <child internal-child="vbox">
-      <widget class="GtkVBox" id="dialog-vbox7">
-        <property name="visible">True</property>
-        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-        <property name="spacing">2</property>
-        <child>
-          <widget class="GtkTable" id="table2">
-            <property name="visible">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="n_rows">3</property>
-            <property name="n_columns">2</property>
-            <child>
-              <widget class="GtkLabel" id="label2">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">&lt;b&gt;Please enter the information for the new field: &lt;/b&gt;</property>
-                <property name="use_markup">True</property>
-              </widget>
-              <packing>
-                <property name="right_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkEntry" id="entry_name">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-              </widget>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkLabel" id="label1">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Name:</property>
-              </widget>
-              <packing>
-                <property name="top_attach">1</property>
-                <property name="bottom_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkEntry" id="entry_title">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-              </widget>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="right_attach">2</property>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-              </packing>
-            </child>
-            <child>
-              <widget class="GtkLabel" id="label3">
-                <property name="visible">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="yes">Title:</property>
-              </widget>
-              <packing>
-                <property name="top_attach">2</property>
-                <property name="bottom_attach">3</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="padding">5</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <widget class="GtkHButtonBox" id="dialog-action_area7">
-            <property name="visible">True</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
-            <child>
-              <widget class="GtkButton" id="button1">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="no">gtk-cancel</property>
-                <property name="use_stock">True</property>
-                <property name="response_id">-6</property>
-              </widget>
-            </child>
-            <child>
-              <widget class="GtkButton" id="button2">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="label" translatable="no">gtk-ok</property>
-                <property name="use_stock">True</property>
-                <property name="response_id">-5</property>
-              </widget>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </widget>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
-          </packing>
-        </child>
-      </widget>
-    </child>
-  </widget>
 </glade-interface>

Modified: trunk/glom/mode_data/flowtablewithfields.cc
==============================================================================
--- trunk/glom/mode_data/flowtablewithfields.cc	(original)
+++ trunk/glom/mode_data/flowtablewithfields.cc	Tue Feb 19 14:37:15 2008
@@ -1128,7 +1128,7 @@
 #ifndef GLOM_ENABLE_CLIENT_ONLY
 void FlowTableWithFields::on_dnd_add_layout_item_field(LayoutWidgetBase* above)
 {
-  //Ask the user to choose the layout item:
+  //Ask the user to choose the layout item
   sharedptr<LayoutItem_Field> layout_item_field = 
     DataWidget::offer_field_list(m_table_name, sharedptr<LayoutItem_Field>(), 
       get_document(), App_Glom::get_application());
@@ -1137,66 +1137,24 @@
     realize();
     return;
   }
-
-  //Add a widget for this layout item, after the "above" item:
-  type_list_layoutwidgets::iterator cur_widget;
-  if(above)
-    cur_widget = std::find (m_list_layoutwidgets.begin(), m_list_layoutwidgets.end(), above);
-  else
-    cur_widget = m_list_layoutwidgets.end();
-
-  //Get the layout group that the "above" widget's layout item is in:
-  sharedptr<LayoutGroup> layout_group = sharedptr<LayoutGroup>::cast_dynamic(get_layout_item());
-  if(!layout_group)
-  {
-    std::cerr << "FlowTableWithFields::on_datawidget_layout_item_added(): layout_group is null." << std::endl;
-    return;
-  }
+  sharedptr<LayoutItem> item = sharedptr<LayoutItem>::cast_dynamic(layout_item_field);
+  dnd_add_to_layout_group (item, above);
   
-  if (above && above->get_layout_item())
-    layout_group->add_item(layout_item_field, above->get_layout_item());
-  else
-    layout_group->add_item(layout_item_field);
-
-  //Tell the parent to tell the document to save the layout:
+  //Tell the parent to tell the document to save the layout
   signal_layout_changed().emit();
 }
 
 void FlowTableWithFields::on_dnd_add_layout_group(LayoutWidgetBase* above)
 {
   type_list_layoutwidgets::iterator cur_widget;
-  if(above)
-    cur_widget = std::find(m_list_layoutwidgets.begin(), m_list_layoutwidgets.end(), above);
-  else
-    cur_widget = m_list_layoutwidgets.end();
   
   sharedptr<LayoutGroup> group(new LayoutGroup());
   group->set_title(_("New Group"));
   group->set_name (_("Group"));
-
-
-  //Get the layout group that the "above" widget's layout item is in
-  sharedptr<LayoutGroup> layout_group = get_layout_group();
-  if(!layout_group)
-  {
-    std::cerr << "FlowTableWithFields::on_dnd_layout_group_added(): layout_group is null." << std::endl;
-    return;
-  }
-
-  std::cout << "Group: " << layout_group->get_title() << std::endl;
   
-  //add_layout_group_at_position (group, cur_widget);
-  if(above && above->get_layout_item())
-  {
-    std::cout << "Adding group above item" << std::endl;
-    layout_group->add_item(group, above->get_layout_item());
-  }
-  else
-  {
-    std::cout << "Adding group at the end" << std::endl;
-    layout_group->add_item(group);
-  }  
-    
+  sharedptr<LayoutItem> item = sharedptr<LayoutItem>::cast_dynamic(group);
+  dnd_add_to_layout_group (item, above);
+  
   //Tell the parent to tell the document to save the layout
   signal_layout_changed().emit();
 }
@@ -1208,28 +1166,8 @@
   layout_item_button->set_title(_("New Button")); //Give the button a default title, so it is big enough, and so people see that they should change it.
   layout_item_button->set_name ("new_button");
   sharedptr<LayoutItem> layout_item = sharedptr<LayoutItem>::cast_dynamic(layout_item_button);
-    
-  //Add a widget for this layout item, after the "above" item:
-  type_list_layoutwidgets::iterator cur_widget;
-  if (above && above->get_layout_item())
-    cur_widget = std::find (m_list_layoutwidgets.begin(), m_list_layoutwidgets.end(), above);
-  else
-    cur_widget = m_list_layoutwidgets.end();
-
-  //Get the layout group that the "above" widget's layout item is in:
-  sharedptr<LayoutGroup> layout_group = sharedptr<LayoutGroup>::cast_dynamic(get_layout_item());
-  if(!layout_group)
-  {
-    return;
-  }
-
-  add_layout_item_at_position(layout_item_button, cur_widget);
-
-  if (above && above->get_layout_item())
-    layout_group->add_item(layout_item_button, above->get_layout_item());
-  else
-    layout_group->add_item(layout_item_button);
 
+  dnd_add_to_layout_group (layout_item, above);
   //Tell the parent to tell the document to save the layout:
   signal_layout_changed().emit();
 }
@@ -1240,68 +1178,29 @@
   sharedptr<LayoutItem_Text> textobject = sharedptr<LayoutItem_Text>::create();
   textobject->set_title(_("Text Title")); //Give the button a default title, so it is big enough, and so people see that they should change it.
   sharedptr<LayoutItem> layout_item = sharedptr<LayoutItem>::cast_dynamic(textobject);
-    
-  //Add a widget for this layout item, after the "above" item:
-  type_list_layoutwidgets::iterator cur_widget;
-  if (above && above->get_layout_item())
-    cur_widget = std::find (m_list_layoutwidgets.begin(), m_list_layoutwidgets.end(), above);
-  else
-    cur_widget = m_list_layoutwidgets.end();
-
-  //Get the layout group that the "above" widget's layout item is in:
-  sharedptr<LayoutGroup> layout_group = sharedptr<LayoutGroup>::cast_dynamic(get_layout_item());
-  if(!layout_group)
-  {
-    std::cerr << "FlowTableWithFields::on_datawidget_layout_item_added(): layout_group is null." << std::endl;
-    return;
-  }
-  
-  add_layout_item_at_position(textobject, cur_widget);
 
-  if (above && above->get_layout_item())
-    layout_group->add_item(textobject, above->get_layout_item());
-  else
-    layout_group->add_item(textobject);
+  dnd_add_to_layout_group (layout_item, above);
+  //Tell the parent to tell the document to save the layout
 
-  //Tell the parent to tell the document to save the layout:
   signal_layout_changed().emit();
 }
 
 void FlowTableWithFields::on_dnd_add_placeholder(LayoutWidgetBase* above)
 {
-  type_list_layoutwidgets::iterator cur_widget;
-  
-  if(above)
-    cur_widget = std::find (m_list_layoutwidgets.begin(), m_list_layoutwidgets.end(), above);
-  else
-    cur_widget = m_list_layoutwidgets.end();
-
   if(m_placeholder)
   {
-    if(dynamic_cast<Glom::PlaceholderGlom*>(*cur_widget))
+    if(dynamic_cast<Glom::PlaceholderGlom*>(above))
       return;
 
     on_dnd_remove_placeholder();
   }
+  type_list_layoutwidgets::iterator cur_widget = std::find (m_list_layoutwidgets.begin(),
+                                                            m_list_layoutwidgets.end(),
+                                                            above);
   sharedptr<LayoutItem_Placeholder> placeholder_field(new LayoutItem_Placeholder);
-	add_layout_item_at_position (placeholder_field, cur_widget);
-  
-  //Get the layout group that the "above" widget's layout item is in
-  sharedptr<LayoutGroup> layout_group = get_layout_group();
-  if(!layout_group)
-  {
-    std::cerr << "FlowTableWithFields::on_dnd_add_placeholder: layout_group is null." << std::endl;
-    return;
-  }
-  
-  std::cout << "Group: " << layout_group->get_title() << std::endl;
-    
-  if(above)
-  {
-    layout_group->add_item(placeholder_field, above->get_layout_item());
-  }
-  else
-    layout_group->add_item(placeholder_field);
+  sharedptr<LayoutItem> item = sharedptr<LayoutItem>::cast_dynamic(placeholder_field);  
+  add_layout_item_at_position (placeholder_field, cur_widget);
+  dnd_add_to_layout_group (item, above, true /* ignore error*/);
 }
 
 void FlowTableWithFields::on_dnd_remove_placeholder()
@@ -1329,6 +1228,35 @@
   
   m_placeholder = 0;
 }
+
+void FlowTableWithFields::dnd_notify_failed_drop()
+{
+  // TODO: Avoid this error message
+  Gtk::MessageDialog dialog(_("You cannot drop anything here. Try to add a group first"),
+                      false, Gtk::MESSAGE_ERROR);
+  dialog.run();
+}
+
+bool FlowTableWithFields::dnd_add_to_layout_group (sharedptr<LayoutItem>& item, 
+                                                   LayoutWidgetBase* layoutwidget,
+                                                   bool ignore_error)
+{
+  //Get the layout group that the "above" widget's layout item is in:
+  sharedptr<LayoutGroup> layout_group = get_layout_group();
+  if(!layout_group)
+  {
+    if (!ignore_error)
+      dnd_notify_failed_drop();
+    return false;
+  }
+      
+  if (layoutwidget && layoutwidget->get_layout_item())
+    layout_group->add_item(item, layoutwidget->get_layout_item());
+  else
+    layout_group->add_item(item);
+  return true;
+}
+
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
 sharedptr<LayoutItem_Portal> FlowTableWithFields::get_layout_item_from_relation()

Modified: trunk/glom/mode_data/flowtablewithfields.h
==============================================================================
--- trunk/glom/mode_data/flowtablewithfields.h	(original)
+++ trunk/glom/mode_data/flowtablewithfields.h	Tue Feb 19 14:37:15 2008
@@ -206,6 +206,10 @@
   virtual void on_dnd_add_layout_item_text (LayoutWidgetBase* above);
   
   bool get_field_information (sharedptr<LayoutItem>& item);
+  void dnd_notify_failed_drop();
+  bool dnd_add_to_layout_group (sharedptr<LayoutItem>& item, 
+                                LayoutWidgetBase* layoutwidget,
+                                bool ignore_error = false);
   
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 



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