[glom] Allow deletion of multiple selected items via the context menu.



commit a2a336b3a5507907e04c1ff860043c5f55d9a247
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Aug 26 10:21:30 2011 +0200

    Allow deletion of multiple selected items via the context menu.
    
    	* glom/print_layout/canvas_print_layout.[h|cc]: on_context_menu_delete():
    	If the deleted item was selected, delete all selected items.

 ChangeLog                                |    7 +++++++
 glom/print_layout/canvas_print_layout.cc |   26 +++++++++++++++++++++++++-
 glom/print_layout/canvas_print_layout.h  |    1 +
 3 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c83a564..b341176 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-08-26  Murray Cumming  <murrayc murrayc com>
+
+	Allow deletion of multiple selected items via the context menu.
+
+	* glom/print_layout/canvas_print_layout.[h|cc]: on_context_menu_delete():
+	If the deleted item was selected, delete all selected items.
+
 2011-08-23  Murray Cumming  <murrayc murrayc com>
 
 	Print Layout: Related records: Corrections for column sizes.
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 8c2b0de..e8b0847 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -453,8 +453,32 @@ void Canvas_PrintLayout::on_context_menu_formatting()
 
 void Canvas_PrintLayout::on_context_menu_delete()
 {
-  m_context_item->remove();
+  //If the item to be deleted was not selected then just delete it:
+  if(!m_context_item->get_selected())
+  {
+    m_context_item->remove();
+    m_context_item.reset();
+    return;
+  }
+
+  //Requesting deletion of a selected item should delete all selected items:
+  //TODO: If there are multiple items, ask the user for confirmation?
   m_context_item.reset();
+  const type_vec_items items = get_selected_items();
+  for(type_vec_items::const_iterator iter = items.begin();
+    iter != items.end(); ++iter)
+  {
+    const Glib::RefPtr<CanvasItemMovable> selected_item = *iter;
+    if(!selected_item)
+      continue;
+      
+    const Glib::RefPtr<CanvasLayoutItem> canvas_layout_item = 
+      Glib::RefPtr<CanvasLayoutItem>::cast_dynamic(selected_item);
+    if(canvas_layout_item)
+      remove_canvas_layout_item(canvas_layout_item);
+  }
+  
+  signal_selection_changed().emit();
 }
 
 void Canvas_PrintLayout::on_dialog_format_hide()
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index cc0879c..b7b6288 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -98,6 +98,7 @@ private:
 #ifndef GLOM_ENABLE_CLIENT_ONLY
   sharedptr<LayoutItem_Portal> offer_related_records(const sharedptr<LayoutItem_Portal>& portal, Gtk::Window* parent);
 
+  //TODO: Make the signal send the item, so we can pass it by const reference:
   void on_item_show_context_menu(guint button, guint32 activate_time, Glib::RefPtr<CanvasLayoutItem> item);
   void on_context_menu_edit();
   void on_context_menu_formatting();



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