Salome HOME
Copyright update 2022
[modules/gui.git] / tools / PyEditor / src / PyEditor_FindTool.cxx
index b91000ab17bb6d2a1462fc1ab7b8682a8bbdfb65..5bb8df12e665ecc4d9f2ce4651acefcfe387a551 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016  OPEN CASCADE
+// Copyright (C) 2015-2022  OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -110,10 +110,10 @@ PyEditor_FindTool::PyEditor_FindTool( PyEditor_Editor* editor, QWidget* parent )
   addAction( new QAction( tr( "CASE_SENSITIVE_CHECK" ), this ) );
   addAction( new QAction( tr( "WHOLE_WORDS_CHECK" ), this ) );
   addAction( new QAction( tr( "REGEX_CHECK" ), this ) );
-  addAction( new QAction( tr( "Find" ), this ) );
+  addAction( new QAction( QIcon( ":/images/py_find.png" ), tr( "Find" ), this ) );
   addAction( new QAction( tr( "FindPrevious" ), this ) );
   addAction( new QAction( tr( "FindNext" ), this ) );
-  addAction( new QAction( tr( "Replace" ), this ) );
+  addAction( new QAction( QIcon( ":/images/py_replace.png" ), tr( "Replace" ), this ) );
 
   foreach ( QAction* action, actions().mid( CaseSensitive, RegExp+1 ) )
   {
@@ -135,6 +135,7 @@ PyEditor_FindTool::PyEditor_FindTool( PyEditor_Editor* editor, QWidget* parent )
   }
 
   myEditor->installEventFilter( this );
+  connect( myEditor, SIGNAL( customizeMenu( QMenu* ) ), this, SLOT( customizeMenu( QMenu* ) ) );
 
   hide();
 }
@@ -221,7 +222,10 @@ bool PyEditor_FindTool::eventFilter( QObject* o, QEvent* e )
       {
       case Qt::Key_Escape:
         if ( isVisible() )
+        {
           hide();
+          return true;
+        }
         break;
       default:
         break;
@@ -239,6 +243,16 @@ void PyEditor_FindTool::activateFind()
   activate( Find );
 }
 
+/*!
+  \brief Customize menu for editor.
+*/
+void PyEditor_FindTool::customizeMenu( QMenu* menu )
+{
+  menu->addSeparator();
+  menu->addAction( actions()[Find] );
+  menu->addAction( actions()[Replace] );
+}
+
 /*!
   \brief Slot: activate 'Replace' dialog.
 */
@@ -406,8 +420,8 @@ QList<QKeySequence> PyEditor_FindTool::shortcuts( int action ) const
     bindings << QKeySequence( QKeySequence::FindNext );
     break;
   case Replace:
-    bindings << QKeySequence( QKeySequence::Replace );
     bindings << QKeySequence( "Ctrl+H" );
+    bindings << QKeySequence( QKeySequence::Replace );
     break;
   default:
     break;
@@ -604,7 +618,7 @@ void PyEditor_FindTool::addCompletion( const QString& text, bool replace )
   QStringListModel& model = replace ? myReplaceCompletion : myFindCompletion;
 
   QStringList completions = model.stringList();
-  if ( !text.isEmpty() and !completions.contains( text ) )
+  if ( !text.isEmpty() && !completions.contains( text ) )
   {
     completions.prepend( text );
     model.setStringList( completions );