[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] src/vimode: Begin transitioning to a "m_currentMode" rather than switching on type (Se
From: Simon St James <kdedevel () etotheipiplusone ! com>
Date: 2016-06-17 8:18:10
Message-ID: E1bDoyg-0002ZN-7i () scm ! kde ! org
[Download RAW message or body]
Git commit 0b3e3198c3bd29bcecd1e35c831993933010e05c by Simon St James.
Committed on 17/06/2016 at 08:14.
Pushed by sstjames into branch 'master'.
Begin transitioning to a "m_currentMode" rather than switching on type (Search vs \
Command vs InteractiveSedReplace) everywhere.
M +45 -53 src/vimode/emulatedcommandbar.cpp
M +25 -7 src/vimode/emulatedcommandbar.h
http://commits.kde.org/ktexteditor/0b3e3198c3bd29bcecd1e35c831993933010e05c
diff --git a/src/vimode/emulatedcommandbar.cpp b/src/vimode/emulatedcommandbar.cpp
index dad7847..f9fa607 100644
--- a/src/vimode/emulatedcommandbar.cpp
+++ b/src/vimode/emulatedcommandbar.cpp
@@ -369,7 +369,15 @@ void EmulatedCommandBar::init(EmulatedCommandBar::Mode mode, \
const QString &init
showBarTypeIndicator(mode);
- m_searchMode->init(mode == SearchBackward ? \
SearchMode::SearchDirection::Backward : SearchMode::SearchDirection::Forward); + \
if (mode == KateVi::EmulatedCommandBar::SearchBackward || mode == SearchForward) + \
{ + switchToMode(m_searchMode.data());
+ m_searchMode->init(mode == SearchBackward ? \
SearchMode::SearchDirection::Backward : SearchMode::SearchDirection::Forward); + }
+ else
+ {
+ switchToMode(m_commandMode.data());
+ }
m_edit->setFocus();
m_edit->setText(initialText);
@@ -402,13 +410,9 @@ void EmulatedCommandBar::closed()
m_matchHighligher->updateMatchHighlight(KTextEditor::Range::invalid());
m_completerTmp->m_completer->popup()->hide();
m_isActive = false;
- m_interactiveSedReplaceMode->deactivate();
- if (m_mode == SearchForward || m_mode == SearchBackward) {
- m_searchMode->deactivate(m_wasAborted);
- } else {
- m_commandMode->deactivate(m_wasAborted);
- }
+ m_currentMode->deactivate(m_wasAborted);
+ m_currentMode = nullptr;
}
void EmulatedCommandBar::updateMatchHighlightAttrib()
@@ -435,12 +439,7 @@ bool EmulatedCommandBar::completerHandledKeypress ( const \
QKeyEvent* keyEvent ) }
if ((keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == \
Qt::Key_P) || keyEvent->key() == Qt::Key_Down) { if \
(!m_completerTmp->m_completer->popup()->isVisible()) {
- CompletionStartParams completionStartParams;
- if (m_mode == Command) {
- completionStartParams = \
m_commandMode->completionInvoked(CompletionInvocation::ExtraContext);
- } else {
- completionStartParams = \
m_searchMode->completionInvoked(CompletionInvocation::ExtraContext);
- }
+ const CompletionStartParams completionStartParams = \
m_currentMode->completionInvoked(CompletionInvocation::ExtraContext); \
m_completerTmp->startCompletion(completionStartParams); if \
(m_completerTmp->m_currentCompletionType != None) { \
m_completerTmp->setCompletionIndex(0); @@ -457,12 +456,7 @@ bool \
EmulatedCommandBar::completerHandledKeypress ( const QKeyEvent* keyEvent ) }
if ((keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == \
Qt::Key_N) || keyEvent->key() == Qt::Key_Up) { if \
(!m_completerTmp->m_completer->popup()->isVisible()) {
- CompletionStartParams completionStartParams;
- if (m_mode == Command) {
- completionStartParams = \
m_commandMode->completionInvoked(CompletionInvocation::NormalContext);
- } else {
- completionStartParams = \
m_searchMode->completionInvoked(CompletionInvocation::NormalContext);
- }
+ const CompletionStartParams completionStartParams = \
m_currentMode->completionInvoked(CompletionInvocation::NormalContext); \
m_completerTmp->startCompletion(completionStartParams);
m_completerTmp->setCompletionIndex(m_completerTmp->m_completer->completionCount() \
- 1); } else {
@@ -476,22 +470,22 @@ bool EmulatedCommandBar::completerHandledKeypress ( const \
QKeyEvent* keyEvent ) return true;
}
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
- if (m_completerTmp->m_completer->popup()->isVisible() && \
m_completerTmp->m_currentCompletionType == \
EmulatedCommandBar::WordFromDocument) {
- m_completerTmp->deactivateCompletion();
- } else {
- m_wasAborted = false;
- m_completerTmp->deactivateCompletion();
- if (m_mode == Command) {
- m_commandMode->completionChosen();
- } else {
- emit hideMe();
- }
+ if (!m_completerTmp->m_completer->popup()->isVisible() || \
m_completerTmp->m_currentCompletionType != EmulatedCommandBar::WordFromDocument) { + \
m_currentMode->completionChosen(); }
+ m_completerTmp->deactivateCompletion();
return true;
}
return false;
}
+void EmulatedCommandBar::switchToMode ( EmulatedCommandBar::ActiveMode* newMode )
+{
+ if (m_currentMode)
+ m_currentMode->deactivate(false);
+ m_currentMode = newMode;
+}
+
bool EmulatedCommandBar::barHandledKeypress ( const QKeyEvent* keyEvent )
{
if ((keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == \
Qt::Key_H) || keyEvent->key() == Qt::Key_Backspace) { @@ -604,11 +598,6 @@ bool \
EmulatedCommandBar::handleKeyPress(const QKeyEvent *keyEvent) \
insertRegisterContents(keyEvent); return true;
}
- if (m_interactiveSedReplaceMode->isActive()) {
- const bool handled = m_interactiveSedReplaceMode->handleKeyPress(keyEvent);
- if (handled)
- return true;
- }
const bool completerHandled = completerHandledKeypress(keyEvent);
if (completerHandled)
return true;
@@ -624,11 +613,9 @@ bool EmulatedCommandBar::handleKeyPress(const QKeyEvent \
*keyEvent) return true;
// Can the current mode handle it?
- if (m_mode == Command) {
- const bool commandModeHandled = m_commandMode->handleKeyPress(keyEvent);
- if (commandModeHandled)
- return true;
- }
+ const bool currentModeHandled = m_currentMode->handleKeyPress(keyEvent);
+ if (currentModeHandled)
+ return true;
// Couldn't handle this key event.
// Send the keypress back to the QLineEdit. Ideally, instead of doing this, we \
would simply return "false" @@ -654,6 +641,7 @@ bool \
EmulatedCommandBar::isSendingSyntheticSearchCompletedKeypress() void \
EmulatedCommandBar::startInteractiveSearchAndReplace(QSharedPointer<SedReplace::InteractiveSedReplacer> \
interactiveSedReplace) {
Q_ASSERT_X(interactiveSedReplace->currentMatch().isValid(), \
"startInteractiveSearchAndReplace", "KateCommands shouldn't initiate an interactive \
sed replace with no initial match"); + \
switchToMode(m_interactiveSedReplaceMode.data()); \
m_interactiveSedReplaceMode->activate(interactiveSedReplace); }
@@ -686,7 +674,6 @@ void EmulatedCommandBar::closeWithStatusMessage(const QString \
&exitStatusMessage {
// Display the message for a while. Become inactive, so we don't steal keys in \
the meantime. m_isActive = false;
- m_interactiveSedReplaceMode->deactivate();
m_exitStatusMessageDisplay->show();
m_exitStatusMessageDisplay->setText(exitStatusMessage);
hideAllWidgetsExcept(m_exitStatusMessageDisplay);
@@ -706,14 +693,7 @@ void EmulatedCommandBar::moveCursorTo(const KTextEditor::Cursor \
&cursorPos) void EmulatedCommandBar::editTextChanged(const QString &newText)
{
Q_ASSERT(!m_interactiveSedReplaceMode->isActive());
- if (m_mode == SearchForward || m_mode == SearchBackward) {
- m_searchMode->editTextChanged(newText);
- }
- else
- {
- m_commandMode->editTextChanged(newText);
- }
-
+ m_currentMode->editTextChanged(newText);
m_completerTmp->editTextChanged(newText);
}
@@ -762,6 +742,12 @@ void EmulatedCommandBar::ActiveMode::updateMatchHighlight(const \
KTextEditor::Ran m_matchHighligher->updateMatchHighlight(matchRange);
}
+void EmulatedCommandBar::ActiveMode::close( bool wasAborted )
+{
+ m_emulatedCommandBar->m_wasAborted = wasAborted;
+ m_emulatedCommandBar->hideMe();
+}
+
void EmulatedCommandBar::ActiveMode::closeWithStatusMessage(const QString& \
exitStatusMessage) {
m_emulatedCommandBar->closeWithStatusMessage(exitStatusMessage);
@@ -987,8 +973,9 @@ bool \
EmulatedCommandBar::InteractiveSedReplaceMode::handleKeyPress(const QKeyEve return \
false; }
-void EmulatedCommandBar::InteractiveSedReplaceMode::deactivate()
+void EmulatedCommandBar::InteractiveSedReplaceMode::deactivate( bool wasAborted )
{
+ Q_UNUSED(wasAborted);
m_isActive = false;
m_interactiveSedReplaceLabel->hide();
}
@@ -1005,7 +992,7 @@ void \
EmulatedCommandBar::InteractiveSedReplaceMode::updateInteractiveSedReplaceL
void EmulatedCommandBar::InteractiveSedReplaceMode::finishInteractiveSedReplace()
{
- deactivate();
+ deactivate(false);
closeWithStatusMessage(m_interactiveSedReplacer->finalStatusReportMessage());
m_interactiveSedReplacer.clear();
}
@@ -1021,7 +1008,6 @@ EmulatedCommandBar::SearchMode::SearchMode(EmulatedCommandBar* \
emulatedCommandBa void EmulatedCommandBar::SearchMode::init ( \
EmulatedCommandBar::SearchMode::SearchDirection searchDirection) {
m_searchDirection = searchDirection;
- setBarBackground(SearchMode::Normal);
m_startingCursorPos = m_view->cursorPosition();
}
@@ -1096,6 +1082,7 @@ void EmulatedCommandBar::SearchMode::deactivate(bool \
wasAborted) }
}
m_startingCursorPos = KTextEditor::Cursor::invalid();
+ setBarBackground(SearchMode::Normal);
// Send a synthetic keypress through the system that signals whether the search \
was aborted or
// not. If not, the keypress will "complete" the search motion, thus triggering \
it.
// We send to KateViewInternal as it updates the status bar and removes the "?".
@@ -1112,8 +1099,6 @@ void EmulatedCommandBar::SearchMode::deactivate(bool \
wasAborted)
// from Vim-style regex; without case-sensitivity markers stripped; etc.
// Vim does this even if the search was aborted, so we follow suit.
m_viInputModeManager->globalState()->searchHistory()->append(m_edit->text());
-
-
}
EmulatedCommandBar::CompletionStartParams \
EmulatedCommandBar::SearchMode::completionInvoked ( \
EmulatedCommandBar::CompletionInvocation invocationType ) @@ -1122,6 +1107,12 @@ \
EmulatedCommandBar::CompletionStartParams EmulatedCommandBar::SearchMode::comple \
return activateSearchHistoryCompletion(); }
+void EmulatedCommandBar::SearchMode::completionChosen()
+{
+ // Choose completion with Enter/ Return -> close bar (the search will have \
already taken effect at this point), marking as not aborted . + close(false);
+}
+
EmulatedCommandBar::CompletionStartParams \
EmulatedCommandBar::SearchMode::activateSearchHistoryCompletion() {
setCompletionMode(KateVi::EmulatedCommandBar::SearchHistory);
@@ -1273,6 +1264,7 @@ void EmulatedCommandBar::CommandMode::completionChosen()
}
const QString commandResponseMessage = executeCommand(commandToExecute);
+ // Don't close the bar if executing the command switched us to Interactive Sed \
Replace mode. if (!m_interactiveSedReplaceMode->isActive()) {
if (commandResponseMessage.isEmpty()) {
m_emulatedCommandBar->hideMe();
diff --git a/src/vimode/emulatedcommandbar.h b/src/vimode/emulatedcommandbar.h
index 2e6ca83..533df3b 100644
--- a/src/vimode/emulatedcommandbar.h
+++ b/src/vimode/emulatedcommandbar.h
@@ -148,11 +148,25 @@ private:
}
virtual ~ActiveMode() = 0;
virtual bool handleKeyPress(const QKeyEvent *keyEvent) = 0;
+ virtual void editTextChanged(const QString &newText)
+ {
+ Q_UNUSED(newText);
+ }
+ virtual CompletionStartParams completionInvoked(CompletionInvocation \
invocationType) + {
+ Q_UNUSED(invocationType);
+ return CompletionStartParams();
+ };
+ virtual void completionChosen()
+ {
+ }
+ virtual void deactivate(bool wasAborted) = 0;
protected:
// Helper methods.
void hideAllWidgetsExcept(QWidget* widgetToKeepVisible);
void moveCursorTo(const KTextEditor::Cursor &cursorPos);
void updateMatchHighlight(const KTextEditor::Range &matchRange);
+ void close(bool wasAborted);
void closeWithStatusMessage(const QString& exitStatusMessage);
void setCompletionMode(CompletionType completionType)
{
@@ -178,7 +192,7 @@ private:
return m_isActive;
}
virtual bool handleKeyPress(const QKeyEvent* keyEvent);
- void deactivate();
+ virtual void deactivate(bool wasAborted);
QWidget *label();
private:
void updateInteractiveSedReplaceLabelText();
@@ -200,9 +214,10 @@ private:
void init(SearchDirection);
void setViInputModeManager(InputModeManager *viInputModeManager);
virtual bool handleKeyPress ( const QKeyEvent* keyEvent );
- void editTextChanged(const QString &newText);
- CompletionStartParams completionInvoked(CompletionInvocation \
invocationType);
- void deactivate(bool wasAborted);
+ virtual void editTextChanged(const QString &newText);
+ virtual CompletionStartParams completionInvoked(CompletionInvocation \
invocationType); + virtual void completionChosen();
+ virtual void deactivate(bool wasAborted);
bool isSendingSyntheticSearchCompletedKeypress() const
{
return m_isSendingSyntheticSearchCompletedKeypress;
@@ -230,11 +245,11 @@ private:
}
void setViInputModeManager(InputModeManager *viInputModeManager);
virtual bool handleKeyPress ( const QKeyEvent* keyEvent );
- void editTextChanged(const QString &newText);
+ virtual void editTextChanged(const QString &newText);
+ virtual CompletionStartParams completionInvoked(CompletionInvocation \
invocationType); + virtual void completionChosen();
void deactivate(bool wasAborted);
QString executeCommand(const QString &commandToExecute);
- CompletionStartParams completionInvoked(CompletionInvocation \
invocationType);
- void completionChosen();
private:
CompletionStartParams activateCommandCompletion();
CompletionStartParams activateCommandHistoryCompletion();
@@ -283,6 +298,9 @@ private:
void moveCursorTo(const KTextEditor::Cursor &cursorPos);
+ void switchToMode(ActiveMode *newMode);
+ ActiveMode *m_currentMode = nullptr;
+
bool barHandledKeypress(const QKeyEvent* keyEvent);
void insertRegisterContents(const QKeyEvent *keyEvent);
bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic