From 5cc47af7171a51610d15ff5c589a12bb1b9cf991 Mon Sep 17 00:00:00 2001 From: andreas <andreas@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Tue, 11 May 2010 14:59:31 +0000 Subject: [PATCH] fixed automatic indentation in shell changed position of popup for completion proposals git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/branches/new_shell@2239 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gui/src/python_shell/completer_base.cc | 1 + .../src/python_shell/python_shell_widget.cc | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/gui/src/python_shell/completer_base.cc b/modules/gui/src/python_shell/completer_base.cc index 1b92a4736..d9d46b3a3 100644 --- a/modules/gui/src/python_shell/completer_base.cc +++ b/modules/gui/src/python_shell/completer_base.cc @@ -61,6 +61,7 @@ void OstCompleterBase::complete(const QRect & rect,bool inline_completion) (popup()->verticalScrollBar()->isVisible() ? popup()->verticalScrollBar()->width():0); popup()->setFixedWidth(popup_width); + popup()->move(popup()->pos()+QPoint(0,-popup()->height()-rect.height())); } QString OstCompleterBase::GetCommonMatch() diff --git a/modules/gui/src/python_shell/python_shell_widget.cc b/modules/gui/src/python_shell/python_shell_widget.cc index 5d8015b85..0a0c7726f 100644 --- a/modules/gui/src/python_shell/python_shell_widget.cc +++ b/modules/gui/src/python_shell/python_shell_widget.cc @@ -172,7 +172,6 @@ void PythonShellWidget::setup_state_machine_() true, new BlockStatusGuard(this,CODE_BLOCK_COMPLETE | CODE_BLOCK_ERROR)); single_line->addTransition(tr1); - connect(tr1,SIGNAL(triggered()),this,SLOT(OnEnterTransition())); KeyEventTransition* tr3=new KeyEventTransition(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, @@ -191,7 +190,6 @@ void PythonShellWidget::setup_state_machine_() true, new BlockStatusGuard(this,CODE_BLOCK_COMPLETE | CODE_BLOCK_ERROR)); multi_line_inactive->addTransition(tr4); - connect(tr4,SIGNAL(triggered()),this,SLOT(OnEnterTransition())); KeyEventTransition* tr6=new KeyEventTransition(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, @@ -213,7 +211,6 @@ void PythonShellWidget::setup_state_machine_() true, new BlockStatusGuard(this,CODE_BLOCK_COMPLETE | CODE_BLOCK_ERROR)); multiline_active_state_->addTransition(tr7); - connect(tr7,SIGNAL(triggered()),this,SLOT(OnEnterTransition())); KeyEventTransition* tr8=new KeyEventTransition(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, @@ -257,6 +254,17 @@ void PythonShellWidget::OnEnterTransition() QTextCursor cursor=textCursor(); cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor); setTextCursor(cursor); + cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); + bool new_indent=cursor.selectedText()==":"; + cursor.movePosition(QTextCursor::StartOfLine); + cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor); + insertPlainText(QString(QChar::ParagraphSeparator)); + if(cursor.selectedText()[0].isSpace() && ! cursor.atBlockEnd()){ + insertPlainText(QString(cursor.selectedText())); + } + if (new_indent){ + insertPlainText(QString("\t")); + } } void PythonShellWidget::OnSingleLineStateEntered() { @@ -264,7 +272,6 @@ void PythonShellWidget::OnSingleLineStateEntered() } void PythonShellWidget::OnMultiLineActiveStateEntered() { - insertPlainText(QString(QChar::ParagraphSeparator)); set_block_edit_mode_(EDITMODE_MULTILINE_ACTIVE); } void PythonShellWidget::OnMultiLineInactiveStateEntered() @@ -285,6 +292,9 @@ void PythonShellWidget::OnHistoryDownStateEntered() } void PythonShellWidget::OnExecuteStateEntered() { + QTextCursor cursor=textCursor(); + cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor); + setTextCursor(cursor); set_block_type_(block_edit_start_,textCursor().block(),BLOCKTYPE_CODE); insertPlainText(QString(QChar::ParagraphSeparator)); QString command=GetCommand(); -- GitLab