Salome HOME
Issue #2340: Provide list of accessible Undo/Redo commands for widgets
authorvsv <vsv@opencascade.com>
Thu, 7 Dec 2017 12:18:58 +0000 (15:18 +0300)
committervsv <vsv@opencascade.com>
Thu, 7 Dec 2017 12:19:16 +0000 (15:19 +0300)
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/selection.png [new file with mode: 0644]

index c63e684cbe7bf7539ce0d885f2af06d42091f76e..18a201a39870749351b2ac003c3bea1f4ee9f210 100644 (file)
@@ -24,6 +24,7 @@
 #include <ModuleBase.h>
 #include <ModuleBase_ActionType.h>
 #include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_ActionInfo.h>
 #include <ModelAPI_Feature.h>
 
 #include <QWidget>
@@ -252,6 +253,11 @@ Q_OBJECT
   /// Returns true if the event is processed. The default implementation is empty, returns false.
   virtual bool processAction(ModuleBase_ActionType theActionType);
 
+  /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list.
+  /// \param theActionType type of action. It can be ActionUndo or ActionRedo.
+  virtual QList<ActionInfo> actionsList(ModuleBase_ActionType theActionType) const
+  { return QList<ActionInfo>(); }
+
   /// Sends Update and Redisplay for the given object
   /// \param theObj is updating object
   void updateObject(ObjectPtr theObj);
index 15be27427a803b0a94c54e306b9a0c07220982c7..53350edaf448a4e28caa7a58cf895ddba6dbed18 100755 (executable)
@@ -505,6 +505,7 @@ void ModuleBase_WidgetMultiSelector::appendSelectionInHistory()
   QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
   myCurrentHistoryIndex++;
   mySelectedHistoryValues.append(aSelected);
+  int aNb = mySelectedHistoryValues.count();
   myWorkshop->updateCommandStatus();
 
 #ifdef DEBUG_UNDO_REDO
@@ -882,3 +883,32 @@ bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
   }
   return aFound;
 }
+
+QList<ActionInfo> ModuleBase_WidgetMultiSelector::actionsList(ModuleBase_ActionType theActionType) const
+{
+  QList<ActionInfo> aList;
+  if (myCurrentHistoryIndex > -1) {
+    int i = 0;
+    QString aTitle("Selection %1 items");
+    QIcon aIcon(":pictures/selection.png");
+    switch (theActionType) {
+    case ActionUndo:
+      i = 1;
+      while (i <= myCurrentHistoryIndex) {
+        ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count()));
+        aList.append(aInfo);
+        i++;
+      }
+      break;
+    case ActionRedo:
+      i = mySelectedHistoryValues.length() - 1;
+      while (i > myCurrentHistoryIndex) {
+        ActionInfo aInfo(aIcon, aTitle.arg(mySelectedHistoryValues.at(i).count()));
+        aList.append(aInfo);
+        i--;
+      }
+      break;
+    }
+  }
+  return aList;
+}
\ No newline at end of file
index 6b35b93801dfb77e054fbf63938bb46709ac29a5..96542e3f20441de4892634aea2819869eda2c1f6 100755 (executable)
@@ -103,6 +103,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   /// \return a boolean value
   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
 
+  /// Returns list of accessible actions for Undo/Redo commands. By default it returns empty list.
+  /// \param theActionType type of action. It can be ActionUndo or ActionRedo.
+  virtual QList<ActionInfo> actionsList(ModuleBase_ActionType theActionType) const;
+
 public slots:
   /// Slot is called on selection type changed
   void onSelectionTypeChanged();
index 5d935ad3ffe320aee5f25f87aaf51c1cf495f1de..e4fc24368d2ab890d8cb274497b87a3de308ff78 100755 (executable)
@@ -1265,12 +1265,21 @@ void XGUI_Workshop::updateCommandStatus()
 //******************************************************
 void XGUI_Workshop::updateHistory()
 {
-  std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
-  QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
-  emit updateUndoHistory(aUndoRes);
+  bool isActionEnabled = false;
+  ModuleBase_ModelWidget* anActiveWidget = myOperationMgr->activeWidget();
+  QList<ActionInfo> aUndoRes;
+  QList<ActionInfo> aRedoRes;
+  if (anActiveWidget && anActiveWidget->canProcessAction(ActionUndo, isActionEnabled)) {
+    aUndoRes = anActiveWidget->actionsList(ActionUndo);
+    aRedoRes = anActiveWidget->actionsList(ActionRedo);
+  } else {
+    std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
+    aUndoRes = processHistoryList(aUndoList);
 
-  std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
-  QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
+    std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
+    aRedoRes = processHistoryList(aRedoList);
+  }
+  emit updateUndoHistory(aUndoRes);
   emit updateRedoHistory(aRedoRes);
 }
 
index cc92ee6fb0955fdc58ca6f119adfa1a2e819d53d..14e55f36780dc71be9dbd426a0f08b37e3ed7498 100644 (file)
@@ -68,5 +68,6 @@
      <file>pictures/insert_folder_before.png</file>
      <file>pictures/move_out_after.png</file>
      <file>pictures/move_out_before.png</file>
+     <file>pictures/selection.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/selection.png b/src/XGUI/pictures/selection.png
new file mode 100644 (file)
index 0000000..4cc4088
Binary files /dev/null and b/src/XGUI/pictures/selection.png differ