Salome HOME
Join modifications from branch BR_3_1_0deb
[modules/gui.git] / src / PythonConsole / PythonConsole_PyEditor.cxx
index ba55b25ca3e2ad99d427102bfa77edc6c6e72f59..5bb4aed68f933ca15844601a6bc04e82ec320065 100755 (executable)
 //  File   : PythonConsole_PyEditor.cxx
 //  Author : Nicolas REJNERI
 //  Module : SALOME
-//  $Header$
 
 #include <PythonConsole_PyEditor.h> // this include must be first (see PyInterp_base.h)!
+
 #include <PyInterp_Dispatcher.h>
+
 #include <SUIT_Tools.h>
 
-#include <qapplication.h>
 #include <qmap.h>
 #include <qclipboard.h>
 #include <qdragobject.h>
+#include <qapplication.h>
+#include <qpopupmenu.h>
 
-//#include "utilities.h"
 using namespace std;
 
-
 //#ifdef _DEBUG_
 //static int MYDEBUG = 1;
 //#else
@@ -56,8 +56,10 @@ static QString DOTS_PROMPT  = "... ";
 class ExecCommand : public PyInterp_LockRequest
 {
 public:
-  ExecCommand(PyInterp_base* theInterp, const char* theCommand, PythonConsole_PyEditor* theListener)
-: PyInterp_LockRequest( theInterp, theListener ), myCommand(theCommand), myState( PyInterp_Event::OK )
+  ExecCommand(PyInterp_base* theInterp, const char* theCommand,
+              PythonConsole_PyEditor* theListener, bool sync = false)
+    : PyInterp_LockRequest( theInterp, theListener, sync ),
+      myCommand( theCommand ), myState( PyInterp_Event::OK )
   {}
 
 protected:
@@ -104,7 +106,8 @@ PythonConsole_PyEditor::PythonConsole_PyEditor(PyInterp_base* theInterp, QWidget
   QString fntSet( "" );
   QFont aFont = SUIT_Tools::stringToFont( fntSet );
   setFont(aFont);
-  setTextFormat(QTextEdit::PlainText);
+  //setTextFormat(QTextEdit::PlainText);
+  setUndoRedoEnabled( false );
 
   _currentPrompt = READY_PROMPT;
   setWordWrap(NoWrap);
@@ -149,7 +152,7 @@ void PythonConsole_PyEditor::exec( const QString& command )
   _currentPrompt = READY_PROMPT;
   _buf.truncate(0);
   _isInHistory = false;
-  setText(_currentPrompt); 
+  setText( "\n" + _currentPrompt); 
   setText( command + "\n" ); 
   handleReturn();
 }
@@ -307,8 +310,6 @@ void PythonConsole_PyEditor::keyPressEvent( QKeyEvent* e )
   bool ctrlPressed = e->state() & ControlButton;
   // check if <Shift> is pressed
   bool shftPressed = e->state() & ShiftButton;
-  // check if <Alt> is pressed
-  bool altPressed = e->state() & AltButton;
 
   // process <Ctrl>+<C> key-bindings
   if ( aKey == Key_C && ctrlPressed ) {
@@ -701,3 +702,28 @@ void PythonConsole_PyEditor::onPyInterpChanged( PyInterp_base* interp )
     }
   }
 }
+
+QPopupMenu* PythonConsole_PyEditor::createPopupMenu( const QPoint& pos )
+{
+  QPopupMenu* popup = QTextEdit::createPopupMenu( pos );
+
+  QValueList<int> ids;
+  for ( int i = 0; popup && i < popup->count(); i++ )
+  {
+    if ( !popup->isItemEnabled( popup->idAt( i ) ) )
+      ids.append( popup->idAt( i ) );
+  }
+
+  for ( QValueList<int>::const_iterator it = ids.begin(); it != ids.end(); ++it )
+    popup->removeItem( *it );
+
+  SUIT_Tools::simplifySeparators( popup );
+
+  if ( !popup->count() )
+  {
+    delete popup;
+    popup = 0;
+  }
+
+  return popup;
+}