[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] src: Move InteractiveSedReplaceMode into its own source files.
From: Simon St James <kdedevel () etotheipiplusone ! com>
Date: 2016-06-17 8:18:10
Message-ID: E1bDoyg-0002ZN-Jm () scm ! kde ! org
[Download RAW message or body]
Git commit 1196603732225af6dcc2754d3b57342da32b794c by Simon St James.
Committed on 17/06/2016 at 08:14.
Pushed by sstjames into branch 'master'.
Move InteractiveSedReplaceMode into its own source files.
M +1 -0 src/CMakeLists.txt
M +1 -1 src/vimode/emulatedcommandbar/activemode.cpp
M +1 -83 src/vimode/emulatedcommandbar/emulatedcommandbar.cpp
M +2 -28 src/vimode/emulatedcommandbar/emulatedcommandbar.h
A +89 -0 src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp \
[License: UNKNOWN] * A +42 -0 \
src/vimode/emulatedcommandbar/interactivesedreplacemode.h [License: UNKNOWN] *
The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.
http://commits.kde.org/ktexteditor/1196603732225af6dcc2754d3b57342da32b794c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b50de81..9e4dc5b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -279,6 +279,7 @@ if (BUILD_VIMODE)
vimode/emulatedcommandbar/matchhighlighter.cpp
vimode/emulatedcommandbar/completer.cpp
vimode/emulatedcommandbar/activemode.cpp
+ vimode/emulatedcommandbar/interactivesedreplacemode.cpp
vimode/commandrangeexpressionparser.cpp
vimode/keymapper.cpp
vimode/marks.cpp
diff --git a/src/vimode/emulatedcommandbar/activemode.cpp \
b/src/vimode/emulatedcommandbar/activemode.cpp index 3f2a11e..86f7d6a 100644
--- a/src/vimode/emulatedcommandbar/activemode.cpp
+++ b/src/vimode/emulatedcommandbar/activemode.cpp
@@ -9,7 +9,7 @@ CompletionStartParams \
ActiveMode::completionInvoked(Completer::CompletionInvocat {
Q_UNUSED(invocationType);
return CompletionStartParams();
-};
+}
ActiveMode::~ActiveMode()
{
diff --git a/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp \
b/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp index 3075796..00b0355 100644
--- a/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp
+++ b/src/vimode/emulatedcommandbar/emulatedcommandbar.cpp
@@ -29,6 +29,7 @@
#include <vimode/inputmodemanager.h>
#include <vimode/modes/normalvimode.h>
#include "matchhighlighter.h"
+#include "interactivesedreplacemode.h"
#include <vimode/cmds.h>
#include <vimode/modes/visualvimode.h>
@@ -648,89 +649,6 @@ void EmulatedCommandBar::hideAllWidgetsExcept(QWidget* \
widgetToKeepVisible)
}
-EmulatedCommandBar::InteractiveSedReplaceMode::InteractiveSedReplaceMode(EmulatedCommandBar* \
emulatedCommandBar, MatchHighlighter* matchHighlighter)
- : ActiveMode(emulatedCommandBar, matchHighlighter),
- m_isActive(false)
-{
- m_interactiveSedReplaceLabel = new QLabel();
- m_interactiveSedReplaceLabel->setObjectName(QStringLiteral("interactivesedreplace"));
-}
-
-void EmulatedCommandBar::InteractiveSedReplaceMode::activate(QSharedPointer<SedReplace::InteractiveSedReplacer> \
interactiveSedReplace)
-{
- Q_ASSERT_X(interactiveSedReplace->currentMatch().isValid(), \
"startInteractiveSearchAndReplace", "KateCommands shouldn't initiate an interactive \
sed replace with no initial match");
-
- m_isActive = true;
- m_interactiveSedReplacer = interactiveSedReplace;
-
- hideAllWidgetsExcept(m_interactiveSedReplaceLabel);
- m_interactiveSedReplaceLabel->show();
- updateInteractiveSedReplaceLabelText();
-
- updateMatchHighlight(interactiveSedReplace->currentMatch());
- moveCursorTo(interactiveSedReplace->currentMatch().start());
-}
-
-bool EmulatedCommandBar::InteractiveSedReplaceMode::handleKeyPress(const QKeyEvent* \
keyEvent)
-{
- // TODO - it would be better to use e.g. keyEvent->key() == Qt::Key_Y instead of \
keyEvent->text() == "y",
- // but this would require some slightly dicey changes to the "feed key press" \
code in order to make it work
- // with mappings and macros.
- if (keyEvent->text() == QLatin1String("y") || keyEvent->text() == \
QLatin1String("n")) {
- const KTextEditor::Cursor cursorPosIfFinalMatch = \
m_interactiveSedReplacer->currentMatch().start();
- if (keyEvent->text() == QLatin1String("y")) {
- m_interactiveSedReplacer->replaceCurrentMatch();
- } else {
- m_interactiveSedReplacer->skipCurrentMatch();
- }
- updateMatchHighlight(m_interactiveSedReplacer->currentMatch());
- updateInteractiveSedReplaceLabelText();
- moveCursorTo(m_interactiveSedReplacer->currentMatch().start());
-
- if (!m_interactiveSedReplacer->currentMatch().isValid()) {
- moveCursorTo(cursorPosIfFinalMatch);
- finishInteractiveSedReplace();
- }
- return true;
- } else if (keyEvent->text() == QLatin1String("l")) {
- m_interactiveSedReplacer->replaceCurrentMatch();
- finishInteractiveSedReplace();
- return true;
- } else if (keyEvent->text() == QLatin1String("q")) {
- finishInteractiveSedReplace();
- return true;
- } else if (keyEvent->text() == QLatin1String("a")) {
- m_interactiveSedReplacer->replaceAllRemaining();
- finishInteractiveSedReplace();
- return true;
- }
- return false;
-}
-
-void EmulatedCommandBar::InteractiveSedReplaceMode::deactivate( bool wasAborted )
-{
- Q_UNUSED(wasAborted);
- m_isActive = false;
- m_interactiveSedReplaceLabel->hide();
-}
-
-QWidget* EmulatedCommandBar::InteractiveSedReplaceMode::label()
-{
- return m_interactiveSedReplaceLabel;
-}
-
-void EmulatedCommandBar::InteractiveSedReplaceMode::updateInteractiveSedReplaceLabelText()
-{
- m_interactiveSedReplaceLabel->setText(m_interactiveSedReplacer->currentMatchReplacementConfirmationMessage() \
+ QLatin1String(" (y/n/a/q/l)"));
-}
-
-void EmulatedCommandBar::InteractiveSedReplaceMode::finishInteractiveSedReplace()
-{
- deactivate(false);
- closeWithStatusMessage(m_interactiveSedReplacer->finalStatusReportMessage());
- m_interactiveSedReplacer.clear();
-}
-
EmulatedCommandBar::SearchMode::SearchMode(EmulatedCommandBar* emulatedCommandBar, \
MatchHighlighter* matchHighlighter, KTextEditor::ViewPrivate* view, QLineEdit* edit) \
: ActiveMode ( emulatedCommandBar, matchHighlighter), \
m_emulatedCommandBar(emulatedCommandBar),
diff --git a/src/vimode/emulatedcommandbar/emulatedcommandbar.h \
b/src/vimode/emulatedcommandbar/emulatedcommandbar.h index 0e2f708..736a6dc 100644
--- a/src/vimode/emulatedcommandbar/emulatedcommandbar.h
+++ b/src/vimode/emulatedcommandbar/emulatedcommandbar.h
@@ -39,6 +39,7 @@ class QLabel;
namespace KateVi
{
class MatchHighlighter;
+class InteractiveSedReplaceMode;
/**
* A KateViewBarWidget that attempts to emulate some of the features of Vim's own \
command bar, @@ -82,37 +83,10 @@ private:
void hideAllWidgetsExcept(QWidget* widgetToKeepVisible);
- QScopedPointer<MatchHighlighter> m_matchHighligher;
-
friend class ActiveMode;
+ QScopedPointer<MatchHighlighter> m_matchHighligher;
QScopedPointer<Completer> m_completer;
- friend class ActiveMode;
-
- class InteractiveSedReplaceMode : public ActiveMode
- {
- public:
- InteractiveSedReplaceMode(EmulatedCommandBar* emulatedCommandBar, \
MatchHighlighter* matchHighlighter);
- virtual ~InteractiveSedReplaceMode()
- {
- };
- void activate(QSharedPointer<SedReplace::InteractiveSedReplacer> \
interactiveSedReplace);
- bool isActive() const
- {
- return m_isActive;
- }
- virtual bool handleKeyPress(const QKeyEvent* keyEvent);
- virtual void deactivate(bool wasAborted);
- QWidget *label();
- private:
- void updateInteractiveSedReplaceLabelText();
- void finishInteractiveSedReplace();
- QSharedPointer<SedReplace::InteractiveSedReplacer> m_interactiveSedReplacer;
- bool m_isActive;
- QLabel *m_interactiveSedReplaceLabel;
- };
-
-
class SearchMode : public ActiveMode
{
public:
diff --git a/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp \
b/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp new file mode 100644
index 0000000..0bd424c
--- /dev/null
+++ b/src/vimode/emulatedcommandbar/interactivesedreplacemode.cpp
@@ -0,0 +1,89 @@
+#include "interactivesedreplacemode.h"
+
+#include <QLabel>
+#include <QKeyEvent>
+
+using namespace KateVi;
+
+InteractiveSedReplaceMode::InteractiveSedReplaceMode(EmulatedCommandBar* \
emulatedCommandBar, MatchHighlighter* matchHighlighter) + : \
ActiveMode(emulatedCommandBar, matchHighlighter), + m_isActive(false)
+{
+ m_interactiveSedReplaceLabel = new QLabel();
+ m_interactiveSedReplaceLabel->setObjectName(QStringLiteral("interactivesedreplace"));
+}
+
+void InteractiveSedReplaceMode::activate(QSharedPointer<SedReplace::InteractiveSedReplacer> \
interactiveSedReplace) +{
+ Q_ASSERT_X(interactiveSedReplace->currentMatch().isValid(), \
"startInteractiveSearchAndReplace", "KateCommands shouldn't initiate an interactive \
sed replace with no initial match"); +
+ m_isActive = true;
+ m_interactiveSedReplacer = interactiveSedReplace;
+
+ hideAllWidgetsExcept(m_interactiveSedReplaceLabel);
+ m_interactiveSedReplaceLabel->show();
+ updateInteractiveSedReplaceLabelText();
+
+ updateMatchHighlight(interactiveSedReplace->currentMatch());
+ moveCursorTo(interactiveSedReplace->currentMatch().start());
+}
+
+bool InteractiveSedReplaceMode::handleKeyPress(const QKeyEvent* keyEvent)
+{
+ // TODO - it would be better to use e.g. keyEvent->key() == Qt::Key_Y instead of \
keyEvent->text() == "y", + // but this would require some slightly dicey changes \
to the "feed key press" code in order to make it work + // with mappings and \
macros. + if (keyEvent->text() == QLatin1String("y") || keyEvent->text() == \
QLatin1String("n")) { + const KTextEditor::Cursor cursorPosIfFinalMatch = \
m_interactiveSedReplacer->currentMatch().start(); + if (keyEvent->text() == \
QLatin1String("y")) { + m_interactiveSedReplacer->replaceCurrentMatch();
+ } else {
+ m_interactiveSedReplacer->skipCurrentMatch();
+ }
+ updateMatchHighlight(m_interactiveSedReplacer->currentMatch());
+ updateInteractiveSedReplaceLabelText();
+ moveCursorTo(m_interactiveSedReplacer->currentMatch().start());
+
+ if (!m_interactiveSedReplacer->currentMatch().isValid()) {
+ moveCursorTo(cursorPosIfFinalMatch);
+ finishInteractiveSedReplace();
+ }
+ return true;
+ } else if (keyEvent->text() == QLatin1String("l")) {
+ m_interactiveSedReplacer->replaceCurrentMatch();
+ finishInteractiveSedReplace();
+ return true;
+ } else if (keyEvent->text() == QLatin1String("q")) {
+ finishInteractiveSedReplace();
+ return true;
+ } else if (keyEvent->text() == QLatin1String("a")) {
+ m_interactiveSedReplacer->replaceAllRemaining();
+ finishInteractiveSedReplace();
+ return true;
+ }
+ return false;
+}
+
+void InteractiveSedReplaceMode::deactivate( bool wasAborted )
+{
+ Q_UNUSED(wasAborted);
+ m_isActive = false;
+ m_interactiveSedReplaceLabel->hide();
+}
+
+QWidget* InteractiveSedReplaceMode::label()
+{
+ return m_interactiveSedReplaceLabel;
+}
+
+void InteractiveSedReplaceMode::updateInteractiveSedReplaceLabelText()
+{
+ m_interactiveSedReplaceLabel->setText(m_interactiveSedReplacer->currentMatchReplacementConfirmationMessage() \
+ QLatin1String(" (y/n/a/q/l)")); +}
+
+void InteractiveSedReplaceMode::finishInteractiveSedReplace()
+{
+ deactivate(false);
+ closeWithStatusMessage(m_interactiveSedReplacer->finalStatusReportMessage());
+ m_interactiveSedReplacer.clear();
+}
diff --git a/src/vimode/emulatedcommandbar/interactivesedreplacemode.h \
b/src/vimode/emulatedcommandbar/interactivesedreplacemode.h new file mode 100644
index 0000000..fe76774
--- /dev/null
+++ b/src/vimode/emulatedcommandbar/interactivesedreplacemode.h
@@ -0,0 +1,42 @@
+#ifndef KATEVI_EMULATED_COMMAND_BAR_INTERACTIVESEDREPLACEMODE_H
+#define KATEVI_EMULATED_COMMAND_BAR_INTERACTIVESEDREPLACEMODE_H
+
+#include "activemode.h"
+
+#include "../cmds.h"
+
+#include <QSharedPointer>
+
+class QKeyEvent;
+class QLabel;
+
+namespace KateVi
+{
+class EmulatedCommandBar;
+class MatchHighlighter;
+
+class InteractiveSedReplaceMode : public ActiveMode
+{
+public:
+ InteractiveSedReplaceMode(EmulatedCommandBar* emulatedCommandBar, \
MatchHighlighter* matchHighlighter); + virtual ~InteractiveSedReplaceMode()
+ {
+ };
+ void activate(QSharedPointer<SedReplace::InteractiveSedReplacer> \
interactiveSedReplace); + bool isActive() const
+ {
+ return m_isActive;
+ }
+ virtual bool handleKeyPress(const QKeyEvent* keyEvent);
+ virtual void deactivate(bool wasAborted);
+ QWidget *label();
+private:
+ void updateInteractiveSedReplaceLabelText();
+ void finishInteractiveSedReplace();
+ QSharedPointer<SedReplace::InteractiveSedReplacer> m_interactiveSedReplacer;
+ bool m_isActive;
+ QLabel *m_interactiveSedReplaceLabel;
+};
+}
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic