From 3140c13baf4c2f0ae519d544c4eeb721a33b79e3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 5 Sep 2012 16:01:39 +0200 Subject: [PATCH] 0000822: Two little tweaks for the python console --- src/Gui/PythonConsole.cpp | 37 ++++++++++++++++++++++++++++++------- src/Gui/PythonConsole.h | 2 ++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index eaa7f53cb..2c62d316a 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -442,13 +442,8 @@ void PythonConsole::OnChange( Base::Subject &rCaller,const char* sR void PythonConsole::keyPressEvent(QKeyEvent * e) { bool restartHistory = true; - QTextCursor cursor = this->textCursor(); - - // construct reference cursor at begin of input line ... - QTextCursor inputLineBegin = cursor; - inputLineBegin.movePosition( QTextCursor::End ); - inputLineBegin.movePosition( QTextCursor::StartOfLine ); - inputLineBegin.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, promptLength ); + QTextCursor cursor = this->textCursor(); + QTextCursor inputLineBegin = this->inputBegin(); if (cursor < inputLineBegin) { @@ -579,6 +574,9 @@ void PythonConsole::keyPressEvent(QKeyEvent * e) // the event and afterwards update the list widget if (d->callTipsList->isVisible()) { d->callTipsList->validateCursor(); } + + // disable history restart if input line changed + restartHistory &= (inputLine != inputBlock.text().mid(promptLength)); } // any cursor move resets the history to its latest item. if (restartHistory) @@ -806,6 +804,21 @@ void PythonConsole::changeEvent(QEvent *e) TextEdit::changeEvent(e); } +void PythonConsole::mouseReleaseEvent( QMouseEvent *e ) +{ + TextEdit::mouseReleaseEvent( e ); + if (e->button() == Qt::LeftButton) + { + QTextCursor cursor = this->textCursor(); + if (cursor.hasSelection() == false + && cursor < this->inputBegin()) + { + cursor.movePosition( QTextCursor::End ); + this->setTextCursor( cursor ); + } + } +} + /** * Drops the event \a e and writes the right Python command. */ @@ -904,6 +917,16 @@ void PythonConsole::insertFromMimeData (const QMimeData * source) } } +QTextCursor PythonConsole::inputBegin( void ) const +{ + // construct cursor at begin of input line ... + QTextCursor inputLineBegin( this->textCursor() ); + inputLineBegin.movePosition( QTextCursor::End ); + inputLineBegin.movePosition( QTextCursor::StartOfLine ); + inputLineBegin.movePosition( QTextCursor::Right, QTextCursor::MoveAnchor, promptLength ); + return inputLineBegin; +} + QMimeData * PythonConsole::createMimeDataFromSelection () const { QMimeData* mime = new QMimeData(); diff --git a/src/Gui/PythonConsole.h b/src/Gui/PythonConsole.h index 9ac632adf..ceda0a5ec 100644 --- a/src/Gui/PythonConsole.h +++ b/src/Gui/PythonConsole.h @@ -126,6 +126,7 @@ protected: void dragEnterEvent ( QDragEnterEvent * e ); void dragMoveEvent ( QDragMoveEvent * e ); void changeEvent ( QEvent * e ); + void mouseReleaseEvent( QMouseEvent * e ); void overrideCursor(const QString& txt); @@ -134,6 +135,7 @@ protected: bool canInsertFromMimeData ( const QMimeData * source ) const; QMimeData * createMimeDataFromSelection () const; void insertFromMimeData ( const QMimeData * source ); + QTextCursor inputBegin( void ) const; private: void runSource(const QString&);