two new actions: "select block up" and "select block down", current default is Ctrl+U

This commit is contained in:
mae
2008-12-04 19:25:20 +01:00
parent e9ad023def
commit e594815842
6 changed files with 87 additions and 31 deletions

View File

@@ -597,6 +597,8 @@ void BaseTextEditor::slotSelectionChanged()
viewport()->update(); viewport()->update();
if (!d->m_inBlockSelectionMode) if (!d->m_inBlockSelectionMode)
d->m_blockSelectionExtraX = 0; d->m_blockSelectionExtraX = 0;
if (!d->m_selectBlockAnchor.isNull() && !textCursor().hasSelection())
d->m_selectBlockAnchor = QTextCursor();
} }
void BaseTextEditor::gotoBlockStart() void BaseTextEditor::gotoBlockStart()
@@ -627,6 +629,45 @@ void BaseTextEditor::gotoBlockEndWithSelection()
setTextCursor(cursor); setTextCursor(cursor);
} }
void BaseTextEditor::selectBlockUp()
{
QTextCursor cursor = textCursor();
if (!cursor.hasSelection())
d->m_selectBlockAnchor = cursor;
else
cursor.setPosition(cursor.selectionStart());
if (!TextBlockUserData::findPreviousOpenParenthesis(&cursor, false))
return;
if (!TextBlockUserData::findNextClosingParenthesis(&cursor, true))
return;
setTextCursor(cursor);
}
void BaseTextEditor::selectBlockDown()
{
QTextCursor tc = textCursor();
QTextCursor cursor = d->m_selectBlockAnchor;
if (!tc.hasSelection() || cursor.isNull())
return;
tc.setPosition(tc.selectionStart());
forever {
QTextCursor ahead = cursor;
if (!TextBlockUserData::findPreviousOpenParenthesis(&ahead, false))
break;
if (ahead.position() <= tc.position())
break;
cursor = ahead;
}
if ( cursor != d->m_selectBlockAnchor)
TextBlockUserData::findNextClosingParenthesis(&cursor, true);
setTextCursor(cursor);
}
void BaseTextEditor::keyPressEvent(QKeyEvent *e) void BaseTextEditor::keyPressEvent(QKeyEvent *e)

View File

@@ -326,6 +326,9 @@ public slots:
void gotoBlockStartWithSelection(); void gotoBlockStartWithSelection();
void gotoBlockEndWithSelection(); void gotoBlockEndWithSelection();
void selectBlockUp();
void selectBlockDown();
signals: signals:
void changed(); void changed();

View File

@@ -216,6 +216,7 @@ public:
void removeBlockSelection(const QString &text = QString()); void removeBlockSelection(const QString &text = QString());
QTextCursor m_findScope; QTextCursor m_findScope;
QTextCursor m_selectBlockAnchor;
void moveCursorVisible(); void moveCursorVisible();
}; };

View File

@@ -69,6 +69,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core,
= m_increaseFontSizeAction = m_decreaseFontSizeAction = m_increaseFontSizeAction = m_decreaseFontSizeAction
= m_gotoBlockStartAction = m_gotoBlockStartWithSelectionAction = m_gotoBlockStartAction = m_gotoBlockStartWithSelectionAction
= m_gotoBlockEndAction = m_gotoBlockEndWithSelectionAction = m_gotoBlockEndAction = m_gotoBlockEndWithSelectionAction
= m_selectBlockUpAction = m_selectBlockDownAction
= 0; = 0;
m_contextId << m_core->uniqueIDManager()->uniqueIdentifier(context); m_contextId << m_core->uniqueIDManager()->uniqueIdentifier(context);
@@ -163,13 +164,11 @@ void TextEditorActionHandler::createActions()
command = am->registerAction(m_collapseAction, Constants::COLLAPSE, m_contextId); command = am->registerAction(m_collapseAction, Constants::COLLAPSE, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+<"))); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+<")));
connect(m_collapseAction, SIGNAL(triggered()), this, SLOT(collapse())); connect(m_collapseAction, SIGNAL(triggered()), this, SLOT(collapse()));
advancedMenu->addAction(command);
m_expandAction = new QAction(tr("Expand"), this); m_expandAction = new QAction(tr("Expand"), this);
command = am->registerAction(m_expandAction, Constants::EXPAND, m_contextId); command = am->registerAction(m_expandAction, Constants::EXPAND, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+>"))); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+>")));
connect(m_expandAction, SIGNAL(triggered()), this, SLOT(expand())); connect(m_expandAction, SIGNAL(triggered()), this, SLOT(expand()));
advancedMenu->addAction(command);
m_unCollapseAllAction = new QAction(tr("(Un)&Collapse All"), this); m_unCollapseAllAction = new QAction(tr("(Un)&Collapse All"), this);
command = am->registerAction(m_unCollapseAllAction, Constants::UN_COLLAPSE_ALL, m_contextId); command = am->registerAction(m_unCollapseAllAction, Constants::UN_COLLAPSE_ALL, m_contextId);
@@ -208,6 +207,15 @@ void TextEditorActionHandler::createActions()
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+}"))); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+}")));
connect(m_gotoBlockEndWithSelectionAction, SIGNAL(triggered()), this, SLOT(gotoBlockEndWithSelection())); connect(m_gotoBlockEndWithSelectionAction, SIGNAL(triggered()), this, SLOT(gotoBlockEndWithSelection()));
m_selectBlockUpAction= new QAction(tr("Select Block Up"), this);
command = am->registerAction(m_selectBlockUpAction, Constants::SELECT_BLOCK_UP, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+U")));
connect(m_selectBlockUpAction, SIGNAL(triggered()), this, SLOT(selectBlockUp()));
m_selectBlockDownAction= new QAction(tr("Select Block Down"), this);
command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown()));
} }
bool TextEditorActionHandler::supportsAction(const QString & /*id */) const bool TextEditorActionHandler::supportsAction(const QString & /*id */) const
@@ -252,35 +260,30 @@ void TextEditorActionHandler::updateActions()
void TextEditorActionHandler::updateActions(UpdateMode um) void TextEditorActionHandler::updateActions(UpdateMode um)
{ {
if (m_pasteAction) if (!m_initialized)
m_pasteAction->setEnabled(um != NoEditor); return;
if (m_selectAllAction) m_pasteAction->setEnabled(um != NoEditor);
m_selectAllAction->setEnabled(um != NoEditor); m_selectAllAction->setEnabled(um != NoEditor);
if (m_gotoAction) m_gotoAction->setEnabled(um != NoEditor);
m_gotoAction->setEnabled(um != NoEditor); m_selectEncodingAction->setEnabled(um != NoEditor);
if (m_selectEncodingAction) m_printAction->setEnabled(um != NoEditor);
m_selectEncodingAction->setEnabled(um != NoEditor); m_formatAction->setEnabled((m_optionalActions & Format) && um != NoEditor);
if (m_printAction) m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != NoEditor);
m_printAction->setEnabled(um != NoEditor); m_collapseAction->setEnabled(um != NoEditor);
if (m_formatAction) m_expandAction->setEnabled(um != NoEditor);
m_formatAction->setEnabled((m_optionalActions & Format) && um != NoEditor); m_unCollapseAllAction->setEnabled((m_optionalActions & UnCollapseAll) && um != NoEditor);
if (m_unCommentSelectionAction) m_decreaseFontSizeAction->setEnabled(um != NoEditor);
m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != NoEditor); m_increaseFontSizeAction->setEnabled(um != NoEditor);
if (m_collapseAction) m_gotoBlockStartAction->setEnabled(um != NoEditor);
m_collapseAction->setEnabled(um != NoEditor); m_gotoBlockStartWithSelectionAction->setEnabled(um != NoEditor);
if (m_expandAction) m_gotoBlockEndAction->setEnabled(um != NoEditor);
m_expandAction->setEnabled(um != NoEditor); m_gotoBlockEndWithSelectionAction->setEnabled(um != NoEditor);
if (m_unCollapseAllAction) m_selectBlockUpAction->setEnabled(um != NoEditor);
m_unCollapseAllAction->setEnabled((m_optionalActions & UnCollapseAll) && um != NoEditor); m_selectBlockDownAction->setEnabled(um != NoEditor);
if (m_decreaseFontSizeAction)
m_decreaseFontSizeAction->setEnabled(um != NoEditor); m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
if (m_increaseFontSizeAction) if (m_currentEditor)
m_increaseFontSizeAction->setEnabled(um != NoEditor); m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
if (m_visualizeWhitespaceAction) {
m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
if (m_currentEditor)
m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
}
if (m_textWrappingAction) { if (m_textWrappingAction) {
m_textWrappingAction->setEnabled(um != NoEditor); m_textWrappingAction->setEnabled(um != NoEditor);
if (m_currentEditor) if (m_currentEditor)
@@ -411,6 +414,8 @@ FUNCTION(gotoBlockStart)
FUNCTION(gotoBlockEnd) FUNCTION(gotoBlockEnd)
FUNCTION(gotoBlockStartWithSelection) FUNCTION(gotoBlockStartWithSelection)
FUNCTION(gotoBlockEndWithSelection) FUNCTION(gotoBlockEndWithSelection)
FUNCTION(selectBlockUp)
FUNCTION(selectBlockDown)
void TextEditorActionHandler::updateCurrentEditor(Core::IContext *object) void TextEditorActionHandler::updateCurrentEditor(Core::IContext *object)
{ {

View File

@@ -113,6 +113,8 @@ private slots:
void gotoBlockEnd(); void gotoBlockEnd();
void gotoBlockStartWithSelection(); void gotoBlockStartWithSelection();
void gotoBlockEndWithSelection(); void gotoBlockEndWithSelection();
void selectBlockUp();
void selectBlockDown();
void updateCurrentEditor(Core::IContext *object); void updateCurrentEditor(Core::IContext *object);
private: private:
@@ -139,6 +141,8 @@ private:
QAction *m_gotoBlockEndAction; QAction *m_gotoBlockEndAction;
QAction *m_gotoBlockStartWithSelectionAction; QAction *m_gotoBlockStartWithSelectionAction;
QAction *m_gotoBlockEndWithSelectionAction; QAction *m_gotoBlockEndWithSelectionAction;
QAction *m_selectBlockUpAction;
QAction *m_selectBlockDownAction;
uint m_optionalActions; uint m_optionalActions;
QPointer<BaseTextEditor> m_currentEditor; QPointer<BaseTextEditor> m_currentEditor;

View File

@@ -52,6 +52,8 @@ const char * const GOTO_BLOCK_START = "TextEditor.GotoBlockStart";
const char * const GOTO_BLOCK_START_WITH_SELECTION = "TextEditor.GotoBlockStartWithSelection"; const char * const GOTO_BLOCK_START_WITH_SELECTION = "TextEditor.GotoBlockStartWithSelection";
const char * const GOTO_BLOCK_END = "TextEditor.GotoBlockEnd"; const char * const GOTO_BLOCK_END = "TextEditor.GotoBlockEnd";
const char * const GOTO_BLOCK_END_WITH_SELECTION = "TextEditor.GotoBlockEndWithSelection"; const char * const GOTO_BLOCK_END_WITH_SELECTION = "TextEditor.GotoBlockEndWithSelection";
const char * const SELECT_BLOCK_UP = "TextEditor.SelectBlockUp";
const char * const SELECT_BLOCK_DOWN = "TextEditor.SelectBlockDown";
const char * const DELETE_LINE = "TextEditor.DeleteLine"; const char * const DELETE_LINE = "TextEditor.DeleteLine";
const char * const DELETE_WORD = "TextEditor.DeleteWord"; const char * const DELETE_WORD = "TextEditor.DeleteWord";
const char * const SELECT_ENCODING = "TextEditor.SelectEncoding"; const char * const SELECT_ENCODING = "TextEditor.SelectEncoding";