]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3217: Create shortcut for edit current item in object browser
authorvsv <vsv@opencascade.com>
Fri, 10 Apr 2020 12:18:27 +0000 (15:18 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Thu, 2 Jul 2020 11:24:59 +0000 (14:24 +0300)
doc/gui/General/Introduction.rst
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_Workshop.cpp

index fe03d3c85079bb649f24de4c56e25befb671aca0..d11c9b6a940caaf030986a360d97f84742e97218 100644 (file)
@@ -209,7 +209,7 @@ Note, that the result used in feature as argument is removed.
 
 This child result can be restored using **Recover** feature.
 
-Each feature, result, construction, group, field, parameter can be renamed using *Rename* pop-up menu command.
+Each feature, result, construction, group, field, parameter can be renamed using *Rename* pop-up menu command (hotkey "F2").
 
 .. figure:: /images/popup_menu_object_browser_feature.png
    :align: center
index 8feca1f340912900ded52ea8c5db2c87e55a3059..787ddc25c70697907825def41408cc2542c0296e 100644 (file)
@@ -94,6 +94,7 @@ void XGUI_ContextMenuMgr::createActions()
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/rename_edit.png"), tr("Rename"),
                                            aDesktop, this, SLOT(onRename()));
+  aAction->setShortcut(Qt::Key_F2);
   addAction("RENAME_CMD", aAction);
 
   aAction = ModuleBase_Tools::createAction(QIcon(":pictures/move_to_end.png"),
index 3bca93a90f19e6fc9bd569c22014a91fecc42054..fc910e718ff2bbc099724dc1a036070bb5ffb9df 100644 (file)
@@ -65,8 +65,8 @@ public:
   /// Constructor
   /// \param theParent the parent to be deleted when the parent is deleted
   /// \param theOperationMgr the class to perform deletion
-  XGUI_ShortCutListener(QObject* theParent, XGUI_OperationMgr* theOperationMgr)
-    : QObject(theParent), myOperationMgr(theOperationMgr), myIsActive(false)
+  XGUI_ShortCutListener(XGUI_OperationMgr* theOperationMgr)
+    : QObject(theOperationMgr), myOperationMgr(theOperationMgr), myIsActive(false)
   {
     qApp->installEventFilter(this);
   }
@@ -76,61 +76,68 @@ public:
   void setActive(const bool theIsActive) { myIsActive = theIsActive; }
 
   /// Redefinition of virtual function to process Delete key release
-  virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
-  {
-    bool isAccepted = false;
-
-    if (myIsActive) {
-      // Do not process keys for modal dialogues: all keys has to be processed within the dialog
-      // There is only one exception: ModuleBase_EditorDialog
-      QWindow* aWnd = qApp->modalWindow();
-      QString aName = "NoModal";
-      if (aWnd) {
-        if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
-          aName = aWnd->objectName();
-      }
-      if (aName == "NoModal") {
-        if (theEvent->type() == QEvent::KeyRelease) {
-          QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-          if (aKeyEvent) {
-            myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-            switch (aKeyEvent->key()) {
-            case Qt::Key_Delete:
-              isAccepted = myOperationMgr->onProcessDelete(theObject);
-              break;
-            default:
-              isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
-              break;
-            }
+  virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
+
+private:
+  XGUI_OperationMgr* myOperationMgr; /// processor for key event
+  bool myIsActive; /// boolean state whether the event filter perform own signal processing
+};
+
+bool XGUI_ShortCutListener::eventFilter(QObject *theObject, QEvent *theEvent)
+{
+  bool isAccepted = false;
+
+  if (myIsActive) {
+    // Do not process keys for modal dialogues: all keys has to be processed within the dialog
+    // There is only one exception: ModuleBase_EditorDialog
+    QWindow* aWnd = qApp->modalWindow();
+    QString aName = "NoModal";
+    if (aWnd) {
+      if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
+        aName = aWnd->objectName();
+    }
+    if (aName == "NoModal") {
+      if (theEvent->type() == QEvent::KeyRelease) {
+        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+        if (aKeyEvent) {
+          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+          switch (aKeyEvent->key()) {
+          case Qt::Key_Delete:
+            isAccepted = myOperationMgr->onProcessDelete(theObject);
+            break;
+          case Qt::Key_F2:
+            myOperationMgr->xworkshop()->objectBrowser()->onEditItem();
+            break;
+          default:
+            isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
+            break;
           }
         }
-        else if (theEvent->type() == QEvent::KeyPress) {
-          if (myOperationMgr->hasOperation()) {
-            QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-            myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-            isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
-          }
+      }
+      else if (theEvent->type() == QEvent::KeyPress) {
+        if (myOperationMgr->hasOperation()) {
+          QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+          isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
         }
       }
     }
-    if (!isAccepted)
-      isAccepted = QObject::eventFilter(theObject, theEvent);
-    return isAccepted;
   }
+  if (!isAccepted)
+    isAccepted = QObject::eventFilter(theObject, theEvent);
+  return isAccepted;
+}
+
 
-private:
-  XGUI_OperationMgr* myOperationMgr; /// processor for key event
-  bool myIsActive; /// boolean state whether the event filter perform own signal processing
-};
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
-                                     ModuleBase_IWorkshop* theWorkshop)
+  ModuleBase_IWorkshop* theWorkshop)
 : QObject(theParent), myWorkshop(theWorkshop), myActiveMessageBox(0), mySHIFTPressed(false)
 {
   /// we need to install filter to the application in order to react to 'Delete' key button
   /// this key can not be a short cut for a corresponded action because we need to set
   /// the actions priority
-  myShortCutListener = new XGUI_ShortCutListener(theParent, this);
+  myShortCutListener = new XGUI_ShortCutListener(this);
 }
 
 XGUI_OperationMgr::~XGUI_OperationMgr()
@@ -930,3 +937,9 @@ QMessageBox* XGUI_OperationMgr::createInformationBox(const QString& theMessage)
 
   return aMessageBox;
 }
+
+XGUI_Workshop* XGUI_OperationMgr::xworkshop() const
+{
+  XGUI_ModuleConnector* aConnector = (XGUI_ModuleConnector*) myWorkshop;
+  return aConnector->workshop();
+}
index 7e03f56ef2562f29bc9992102be3deb8a1051536..15f89922d3c3855f85268e41cf8318ee7ac70351 100644 (file)
@@ -78,6 +78,9 @@ public:
   /// Current workshop
   ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
 
+  /// Current workshop
+  XGUI_Workshop* xworkshop() const;
+
   /// Returns the current operation or NULL
   /// \return the current operation
   ModuleBase_Operation* currentOperation() const;
index bca2c85b32608781aa20c1b6fee858db37f718b3..3a15e274e42ea7b2d49b1c41ecf2b49a676b315e 100644 (file)
@@ -210,7 +210,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
 {
   mySelector = new XGUI_SelectionMgr(this);
   myModuleConnector = new XGUI_ModuleConnector(this);
-  myOperationMgr = new XGUI_OperationMgr(this, 0);
+  myOperationMgr = new XGUI_OperationMgr(this, myModuleConnector);
   ModuleBase_IWorkshop* aWorkshop = moduleConnector();
   // Has to be defined first in order to get errors and messages from other components
   myEventsListener = new XGUI_WorkshopListener(this);
@@ -273,8 +273,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   //connect(myViewerProxy, SIGNAL(selectionChanged()),
   //        myActionsMgr,  SLOT(updateOnViewSelection()));
 
-  myOperationMgr->setWorkshop(aWorkshop);
-
   myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop);
 
   connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),