[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktexteditor] src/vimode/emulatedcommandbar: Move moveCursorTo() into ActiveMode, and remove the dup
From:       Simon St James <kdedevel () etotheipiplusone ! com>
Date:       2016-06-17 8:18:10
Message-ID: E1bDoyg-0002ZN-OO () scm ! kde ! org
[Download RAW message or body]

Git commit 5245b396e738b538ecce7439ebf4af3a7805737c by Simon St James.
Committed on 17/06/2016 at 08:14.
Pushed by sstjames into branch 'master'.

Move moveCursorTo() into ActiveMode, and remove the duplicated copies of \
m_viInputModeManager, m_view and setViInputModeManager() etc.

M  +20   -5    src/vimode/emulatedcommandbar/activemode.cpp
M  +9    -2    src/vimode/emulatedcommandbar/activemode.h
M  +2    -8    src/vimode/emulatedcommandbar/commandmode.cpp
M  +1    -4    src/vimode/emulatedcommandbar/commandmode.h
M  +3    -14   src/vimode/emulatedcommandbar/emulatedcommandbar.cpp
M  +0    -2    src/vimode/emulatedcommandbar/emulatedcommandbar.h
M  +2    -2    src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp
M  +1    -1    src/vimode/emulatedcommandbar/interactivesedreplacemode.h
M  +2    -8    src/vimode/emulatedcommandbar/searchmode.cpp
M  +1    -4    src/vimode/emulatedcommandbar/searchmode.h

http://commits.kde.org/ktexteditor/5245b396e738b538ecce7439ebf4af3a7805737c

diff --git a/src/vimode/emulatedcommandbar/activemode.cpp \
b/src/vimode/emulatedcommandbar/activemode.cpp index 86f7d6a..fbecbdc 100644
--- a/src/vimode/emulatedcommandbar/activemode.cpp
+++ b/src/vimode/emulatedcommandbar/activemode.cpp
@@ -3,6 +3,11 @@
 #include "emulatedcommandbar.h"
 #include "matchhighlighter.h"
 
+#include <vimode/inputmodemanager.h>
+#include <vimode/modes/visualvimode.h>
+
+#include "kateview.h"
+
 using namespace KateVi;
 
 CompletionStartParams ActiveMode::completionInvoked(Completer::CompletionInvocation \
invocationType) @@ -11,6 +16,11 @@ CompletionStartParams \
ActiveMode::completionInvoked(Completer::CompletionInvocat  return \
CompletionStartParams();  }
 
+void ActiveMode::setViInputModeManager(InputModeManager* viInputModeManager)
+{
+    m_viInputModeManager = viInputModeManager;
+}
+
 ActiveMode::~ActiveMode()
 {
 
@@ -21,11 +31,6 @@ void ActiveMode::hideAllWidgetsExcept(QWidget* \
widgetToKeepVisible)  \
m_emulatedCommandBar->hideAllWidgetsExcept(widgetToKeepVisible);  }
 
-void ActiveMode::moveCursorTo(const KTextEditor::Cursor &cursorPos)
-{
-    m_emulatedCommandBar->moveCursorTo(cursorPos);
-}
-
 void ActiveMode::updateMatchHighlight(const KTextEditor::Range& matchRange)
 {
     m_matchHighligher->updateMatchHighlight(matchRange);
@@ -47,3 +52,13 @@ void ActiveMode::startCompletion ( const CompletionStartParams& \
                completionStartP
     m_emulatedCommandBar->m_completer->startCompletion(completionStartParams);
 }
 
+void ActiveMode::moveCursorTo(const KTextEditor::Cursor &cursorPos)
+{
+    m_view->setCursorPosition(cursorPos);
+    if (m_viInputModeManager->getCurrentViMode() == ViMode::VisualMode ||
+        m_viInputModeManager->getCurrentViMode() == ViMode::VisualLineMode) {
+
+        m_viInputModeManager->getViVisualMode()->goToPos(cursorPos);
+    }
+}
+
diff --git a/src/vimode/emulatedcommandbar/activemode.h \
b/src/vimode/emulatedcommandbar/activemode.h index 308b44d..d4048fa 100644
--- a/src/vimode/emulatedcommandbar/activemode.h
+++ b/src/vimode/emulatedcommandbar/activemode.h
@@ -11,6 +11,7 @@ namespace KTextEditor
 {
     class Cursor;
     class Range;
+    class ViewPrivate;
 }
 
 namespace KateVi
@@ -18,12 +19,15 @@ namespace KateVi
 class EmulatedCommandBar;
 class CompletionStartParams;
 class MatchHighlighter;
+class InputModeManager;
 
 class ActiveMode
 {
 public:
-    ActiveMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter) +    ActiveMode(EmulatedCommandBar* emulatedCommandBar, \
MatchHighlighter* matchHighlighter, InputModeManager* viInputModeManager, \
KTextEditor::ViewPrivate* view)  : m_emulatedCommandBar(emulatedCommandBar),
+      m_viInputModeManager(viInputModeManager),
+      m_view(view),
       m_matchHighligher(matchHighlighter)
     {
     }
@@ -38,15 +42,18 @@ public:
     {
     }
     virtual void deactivate(bool wasAborted) = 0;
+    void setViInputModeManager(InputModeManager *viInputModeManager);
 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 startCompletion(const CompletionStartParams& completionStartParams);
+    void moveCursorTo(const KTextEditor::Cursor &cursorPos);
     EmulatedCommandBar *m_emulatedCommandBar = nullptr;
+    InputModeManager* m_viInputModeManager = nullptr;
+    KTextEditor::ViewPrivate* m_view = nullptr;
 private:
     MatchHighlighter *m_matchHighligher = nullptr;
 };
diff --git a/src/vimode/emulatedcommandbar/commandmode.cpp \
b/src/vimode/emulatedcommandbar/commandmode.cpp index 215b5d0..992dbdd 100644
--- a/src/vimode/emulatedcommandbar/commandmode.cpp
+++ b/src/vimode/emulatedcommandbar/commandmode.cpp
@@ -21,10 +21,9 @@
 
 using namespace KateVi;
 
-CommandMode::CommandMode ( EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, KTextEditor::ViewPrivate* view,  QLineEdit* edit, \
                InteractiveSedReplaceMode *interactiveSedReplaceMode, Completer* \
                completer)
-    : ActiveMode ( emulatedCommandBar, matchHighlighter ),
+CommandMode::CommandMode ( EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, InputModeManager* viInputModeManager, KTextEditor::ViewPrivate* \
view, QLineEdit* edit, InteractiveSedReplaceMode* interactiveSedReplaceMode, \
Completer* completer) +    : ActiveMode ( emulatedCommandBar, matchHighlighter, \
viInputModeManager, view),  m_edit(edit),
-      m_view(view),
       m_interactiveSedReplaceMode(interactiveSedReplaceMode),
       m_completer(completer)
 {
@@ -51,11 +50,6 @@ CommandMode::CommandMode ( EmulatedCommandBar* emulatedCommandBar, \
MatchHighligh  }
 }
 
-void CommandMode::setViInputModeManager ( InputModeManager* viInputModeManager )
-{
-    m_viInputModeManager = viInputModeManager;
-}
-
 bool CommandMode::handleKeyPress ( const QKeyEvent* keyEvent )
 {
     if (keyEvent->modifiers() == Qt::ControlModifier && (keyEvent->key() == \
                Qt::Key_D || keyEvent->key() == Qt::Key_F)) {
diff --git a/src/vimode/emulatedcommandbar/commandmode.h \
b/src/vimode/emulatedcommandbar/commandmode.h index f160315..e85aeb5 100644
--- a/src/vimode/emulatedcommandbar/commandmode.h
+++ b/src/vimode/emulatedcommandbar/commandmode.h
@@ -22,11 +22,10 @@ class InputModeManager;
 class CommandMode : public ActiveMode
 {
 public:
-    CommandMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, KTextEditor::ViewPrivate* view,  QLineEdit* edit, \
InteractiveSedReplaceMode *interactiveSedReplaceMode, Completer* completer); +    \
CommandMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, InputModeManager* viInputModeManager, KTextEditor::ViewPrivate* \
view,  QLineEdit* edit, InteractiveSedReplaceMode *interactiveSedReplaceMode, \
Completer* completer);  virtual ~CommandMode()
     {
     }
-    void setViInputModeManager(InputModeManager *viInputModeManager);
     virtual bool handleKeyPress ( const QKeyEvent* keyEvent );
     virtual void editTextChanged(const QString &newText);
     virtual CompletionStartParams completionInvoked(Completer::CompletionInvocation \
invocationType); @@ -67,8 +66,6 @@ private:
     void replaceCommandBeforeCursorWith(const QString &newCommand);
     int commandBeforeCursorBegin();
     QLineEdit *m_edit;
-    InputModeManager *m_viInputModeManager = nullptr;
-    KTextEditor::ViewPrivate *m_view;
     InteractiveSedReplaceMode *m_interactiveSedReplaceMode;
     Completer *m_completer;
     KCompletion m_cmdCompletion;
diff --git a/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp \
b/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp index 7ee21a1..6d071fa 100644
--- a/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp
+++ b/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp
@@ -33,7 +33,6 @@
 #include "searchmode.h"
 #include "commandmode.h"
 
-#include <vimode/modes/visualvimode.h>
 #include "../history.h"
 
 #include "../registers.h"
@@ -98,16 +97,16 @@ EmulatedCommandBar::EmulatedCommandBar(InputModeManager \
*viInputModeManager, QWi  
     m_matchHighligher.reset(new MatchHighlighter(m_view));
 
-    m_interactiveSedReplaceMode.reset(new InteractiveSedReplaceMode(this, \
m_matchHighligher.data())); +    m_interactiveSedReplaceMode.reset(new \
InteractiveSedReplaceMode(this, m_matchHighligher.data(), m_viInputModeManager, \
m_view));  layout->addWidget(m_interactiveSedReplaceMode->label());
 
     m_completer.reset(new Completer(this, m_view, m_edit));
 
-    m_searchMode.reset(new SearchMode(this, m_matchHighligher.data(), m_view, \
m_edit)); +    m_searchMode.reset(new SearchMode(this, m_matchHighligher.data(), \
m_viInputModeManager, m_view, m_edit));  \
m_searchMode->setViInputModeManager(viInputModeManager);  
 
-    m_commandMode.reset(new CommandMode(this, m_matchHighligher.data(), m_view, \
m_edit, m_interactiveSedReplaceMode.data(), m_completer.data())); +    \
m_commandMode.reset(new CommandMode(this, m_matchHighligher.data(), \
m_viInputModeManager, m_view, m_edit, m_interactiveSedReplaceMode.data(), \
m_completer.data()));  
     m_edit->installEventFilter(this);
     connect(m_edit, SIGNAL(textChanged(QString)), this, \
SLOT(editTextChanged(QString))); @@ -387,16 +386,6 @@ void \
                EmulatedCommandBar::closeWithStatusMessage(const QString \
                &exitStatusMessage
     m_exitStatusMessageDisplayHideTimer->start(m_exitStatusMessageHideTimeOutMS);
 }
 
-void EmulatedCommandBar::moveCursorTo(const KTextEditor::Cursor &cursorPos)
-{
-    m_view->setCursorPosition(cursorPos);
-    if (m_viInputModeManager->getCurrentViMode() == ViMode::VisualMode ||
-        m_viInputModeManager->getCurrentViMode() == ViMode::VisualLineMode) {
-
-        m_viInputModeManager->getViVisualMode()->goToPos(cursorPos);
-    }
-}
-
 void EmulatedCommandBar::editTextChanged(const QString &newText)
 {
     Q_ASSERT(!m_interactiveSedReplaceMode->isActive());
diff --git a/src/vimode/emulatedcommandbar/emulatedcommandbar.h \
b/src/vimode/emulatedcommandbar/emulatedcommandbar.h index aaf70d0..18f4ac9 100644
--- a/src/vimode/emulatedcommandbar/emulatedcommandbar.h
+++ b/src/vimode/emulatedcommandbar/emulatedcommandbar.h
@@ -97,8 +97,6 @@ private:
     void switchToMode(ActiveMode *newMode);
     ActiveMode *m_currentMode = nullptr;
 
-    void moveCursorTo(const KTextEditor::Cursor &cursorPos);
-
     bool barHandledKeypress(const QKeyEvent* keyEvent);
     void insertRegisterContents(const QKeyEvent *keyEvent);
     bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
diff --git a/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp \
b/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp index 0bd424c..0c84985 \
                100644
--- a/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp
+++ b/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp
@@ -5,8 +5,8 @@
 
 using namespace KateVi;
 
-InteractiveSedReplaceMode::InteractiveSedReplaceMode(EmulatedCommandBar* \
                emulatedCommandBar, MatchHighlighter* matchHighlighter)
-    : ActiveMode(emulatedCommandBar, matchHighlighter),
+InteractiveSedReplaceMode::InteractiveSedReplaceMode(EmulatedCommandBar* \
emulatedCommandBar, MatchHighlighter* matchHighlighter, InputModeManager* \
viInputModeManager, KTextEditor::ViewPrivate* view) +    : \
ActiveMode(emulatedCommandBar, matchHighlighter, viInputModeManager, view),  \
m_isActive(false)  {
     m_interactiveSedReplaceLabel = new QLabel();
diff --git a/src/vimode/emulatedcommandbar/interactivesedreplacemode.h \
b/src/vimode/emulatedcommandbar/interactivesedreplacemode.h index fe76774..aa4ccf9 \
                100644
--- a/src/vimode/emulatedcommandbar/interactivesedreplacemode.h
+++ b/src/vimode/emulatedcommandbar/interactivesedreplacemode.h
@@ -18,7 +18,7 @@ class MatchHighlighter;
 class InteractiveSedReplaceMode : public ActiveMode
 {
 public:
-    InteractiveSedReplaceMode(EmulatedCommandBar* emulatedCommandBar, \
MatchHighlighter* matchHighlighter); +    \
InteractiveSedReplaceMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, InputModeManager* viInputModeManager, KTextEditor::ViewPrivate* \
view);  virtual ~InteractiveSedReplaceMode()
     {
     };
diff --git a/src/vimode/emulatedcommandbar/searchmode.cpp \
b/src/vimode/emulatedcommandbar/searchmode.cpp index 20c0128..35b66f6 100644
--- a/src/vimode/emulatedcommandbar/searchmode.cpp
+++ b/src/vimode/emulatedcommandbar/searchmode.cpp
@@ -231,10 +231,9 @@ QStringList KateVi::reversed(const QStringList &originalList)
     return reversedList;
 }
 
-SearchMode::SearchMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
                matchHighlighter, KTextEditor::ViewPrivate* view, QLineEdit* edit)
-    : ActiveMode ( emulatedCommandBar, matchHighlighter),
+SearchMode::SearchMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, InputModeManager* viInputModeManager, KTextEditor::ViewPrivate* \
view, QLineEdit* edit) +    : ActiveMode ( emulatedCommandBar, matchHighlighter, \
viInputModeManager, view),  m_emulatedCommandBar(emulatedCommandBar),
-      m_view(view),
       m_edit(edit)
 {
 }
@@ -245,11 +244,6 @@ void SearchMode::init ( SearchMode::SearchDirection \
searchDirection)  m_startingCursorPos = m_view->cursorPosition();
 }
 
-void SearchMode::setViInputModeManager ( InputModeManager* viInputModeManager )
-{
-    m_viInputModeManager = viInputModeManager;
-}
-
 bool SearchMode::handleKeyPress ( const QKeyEvent* keyEvent )
 {
     Q_UNUSED(keyEvent);
diff --git a/src/vimode/emulatedcommandbar/searchmode.h \
b/src/vimode/emulatedcommandbar/searchmode.h index f691536..1700ddc 100644
--- a/src/vimode/emulatedcommandbar/searchmode.h
+++ b/src/vimode/emulatedcommandbar/searchmode.h
@@ -21,13 +21,12 @@ QStringList reversed(const QStringList &originalList);
 class SearchMode : public ActiveMode
 {
 public:
-    SearchMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, KTextEditor::ViewPrivate* view, QLineEdit* edit); +    \
SearchMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* \
matchHighlighter, InputModeManager* viInputModeManager, KTextEditor::ViewPrivate* \
view, QLineEdit* edit);  virtual ~SearchMode()
     {
     };
     enum class SearchDirection { Forward, Backward };
     void init(SearchDirection);
-    void setViInputModeManager(InputModeManager *viInputModeManager);
     virtual bool handleKeyPress ( const QKeyEvent* keyEvent );
     virtual void editTextChanged(const QString &newText);
     virtual CompletionStartParams completionInvoked(Completer::CompletionInvocation \
invocationType); @@ -39,8 +38,6 @@ public:
     }
 private:
     EmulatedCommandBar *m_emulatedCommandBar = nullptr;
-    KTextEditor::ViewPrivate *m_view = nullptr;
-    InputModeManager *m_viInputModeManager = nullptr;
     QLineEdit *m_edit = nullptr;
     SearchDirection m_searchDirection;
     KTextEditor::Cursor m_startingCursorPos;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic