lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master d4ad57b 42/46: Disallow "Edit/Run" cell when


From: Greg Chicares
Subject: [lmi-commits] [lmi] master d4ad57b 42/46: Disallow "Edit/Run" cell when multiple grid rows are selected
Date: Wed, 22 Jul 2020 11:05:17 -0400 (EDT)

branch: master
commit d4ad57bc1142b1db81da8ac2de5968d45a446457
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Vadim Zeitlin <vadim@tt-solutions.com>

    Disallow "Edit/Run" cell when multiple grid rows are selected
    
    Editing and running cells was accidentally enabled even in the case when
    multiple rows were selected, when the intention was only to do it when
    either a single row is selected or there is no selection at all, for
    consistency with the rest of CensusGridView code, which considers the
    current row (containing the cursor cell) implicitly selected, if there
    is no explicit selection.
---
 census_view.cpp | 27 +++++++++++++++++++--------
 census_view.hpp |  4 +++-
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/census_view.cpp b/census_view.cpp
index bb876dd..ed4a953 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1793,7 +1793,11 @@ BEGIN_EVENT_TABLE(CensusView, ViewEx)
     EVT_MENU(XRCID("delete_cells"              ),CensusView::UponDeleteCells   
         )
     EVT_MENU(XRCID("column_width_varying"      
),CensusView::UponColumnWidthVarying     )
     EVT_MENU(XRCID("column_width_fixed"        
),CensusView::UponColumnWidthFixed       )
+    EVT_UPDATE_UI(XRCID("edit_cell"            
),CensusView::UponUpdateSingleSelection  )
+    EVT_UPDATE_UI(XRCID("edit_class"           
),CensusView::UponUpdateSingleSelection  )
     EVT_UPDATE_UI(XRCID("edit_case"            
),CensusView::UponUpdateAlwaysEnabled    )
+    EVT_UPDATE_UI(XRCID("run_cell"             
),CensusView::UponUpdateSingleSelection  )
+    EVT_UPDATE_UI(XRCID("run_class"            
),CensusView::UponUpdateSingleSelection  )
     EVT_UPDATE_UI(XRCID("run_case"             
),CensusView::UponUpdateAlwaysEnabled    )
     EVT_UPDATE_UI(XRCID("print_case"           
),CensusView::UponUpdateAlwaysEnabled    )
     EVT_UPDATE_UI(XRCID("print_case_to_disk"   
),CensusView::UponUpdateAlwaysEnabled    )
@@ -1818,10 +1822,6 @@ IMPLEMENT_DYNAMIC_CLASS(CensusDVCView, CensusView)
 BEGIN_EVENT_TABLE(CensusDVCView, CensusView)
     EVT_DATAVIEW_ITEM_CONTEXT_MENU (wxID_ANY    ,CensusDVCView::UponRightClick 
            )
     EVT_DATAVIEW_ITEM_VALUE_CHANGED(wxID_ANY    
,CensusDVCView::UponValueChanged           )
-    EVT_UPDATE_UI(XRCID("edit_cell"            
),CensusDVCView::UponUpdateSingleSelection  )
-    EVT_UPDATE_UI(XRCID("edit_class"           
),CensusDVCView::UponUpdateSingleSelection  )
-    EVT_UPDATE_UI(XRCID("run_cell"             
),CensusDVCView::UponUpdateSingleSelection  )
-    EVT_UPDATE_UI(XRCID("run_class"            
),CensusDVCView::UponUpdateSingleSelection  )
     EVT_UPDATE_UI(XRCID("delete_cells"         
),CensusDVCView::UponUpdateNonemptySelection)
 END_EVENT_TABLE()
 
@@ -1831,10 +1831,6 @@ BEGIN_EVENT_TABLE(CensusGridView, CensusView)
     EVT_GRID_CELL_RIGHT_CLICK(                   
CensusGridView::UponRightClick         )
     EVT_GRID_CELL_CHANGED(                       
CensusGridView::UponValueChanged       )
     EVT_GRID_COL_AUTO_SIZE(                      
CensusGridView::UponColumnAutoSize     )
-    EVT_UPDATE_UI(XRCID("edit_cell"            
),CensusGridView::UponUpdateAlwaysEnabled)
-    EVT_UPDATE_UI(XRCID("edit_class"           
),CensusGridView::UponUpdateAlwaysEnabled)
-    EVT_UPDATE_UI(XRCID("run_cell"             
),CensusGridView::UponUpdateAlwaysEnabled)
-    EVT_UPDATE_UI(XRCID("run_class"            
),CensusGridView::UponUpdateAlwaysEnabled)
     EVT_UPDATE_UI(XRCID("delete_cells"         
),CensusGridView::UponUpdateAlwaysEnabled)
 END_EVENT_TABLE()
 
@@ -2458,6 +2454,21 @@ void 
CensusDVCView::UponUpdateSingleSelection(wxUpdateUIEvent& e)
     e.Enable(is_single_sel);
 }
 
+void CensusGridView::UponUpdateSingleSelection(wxUpdateUIEvent& e)
+{
+    // We consider that in absence of any selected rows, the current row is the
+    // selected/active one, so what we actually check for here is that we do
+    // not have more than a single row selected.
+    auto const sel_blocks = grid_window_->GetSelectedRowBlocks();
+    bool const is_single_sel
+        =  sel_blocks.empty()
+        || (sel_blocks.size() == 1
+            && sel_blocks[0].GetTopRow() == sel_blocks[0].GetBottomRow())
+        ;
+
+    e.Enable(is_single_sel);
+}
+
 void CensusDVCView::UponUpdateNonemptySelection(wxUpdateUIEvent& e)
 {
     wxDataViewItemArray selection;
diff --git a/census_view.hpp b/census_view.hpp
index da39248..abc491e 100644
--- a/census_view.hpp
+++ b/census_view.hpp
@@ -85,6 +85,7 @@ class CensusView
     virtual void UponColumnWidthFixed       (wxCommandEvent&) = 0;
     void         UponUpdateAlwaysDisabled   (wxUpdateUIEvent&);
     void         UponUpdateAlwaysEnabled    (wxUpdateUIEvent&);
+    virtual void UponUpdateSingleSelection  (wxUpdateUIEvent&) = 0;
     virtual void UponUpdateColumnValuesVary (wxUpdateUIEvent&) = 0;
 
     bool DoAllCells(mcenum_emission);
@@ -157,7 +158,7 @@ class CensusDVCView final
     void UponDeleteCells            (wxCommandEvent&) override;
     void UponColumnWidthVarying     (wxCommandEvent&) override;
     void UponColumnWidthFixed       (wxCommandEvent&) override;
-    void UponUpdateSingleSelection  (wxUpdateUIEvent&);
+    void UponUpdateSingleSelection  (wxUpdateUIEvent&) override;
     void UponUpdateNonemptySelection(wxUpdateUIEvent&);
     void UponUpdateColumnValuesVary (wxUpdateUIEvent&) override;
 
@@ -199,6 +200,7 @@ class CensusGridView final
     void UponDeleteCells            (wxCommandEvent&) override;
     void UponColumnWidthVarying     (wxCommandEvent&) override;
     void UponColumnWidthFixed       (wxCommandEvent&) override;
+    void UponUpdateSingleSelection  (wxUpdateUIEvent&) override;
     void UponUpdateColumnValuesVary (wxUpdateUIEvent&) override;
 
     void Update() override;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]