diff --git a/src/vimode/emulatedcommandbar/activemode.h b/src/vimode/emulatedcommandbar/activemode.h index bc419eaf..308b44df 100644 --- a/src/vimode/emulatedcommandbar/activemode.h +++ b/src/vimode/emulatedcommandbar/activemode.h @@ -1,54 +1,54 @@ #ifndef KATEVI_EMULATED_COMMAND_BAR_ACTIVEMODE_H #define KATEVI_EMULATED_COMMAND_BAR_ACTIVEMODE_H #include "completer.h" class QKeyEvent; class QString; class QWidget; namespace KTextEditor { class Cursor; class Range; } namespace KateVi { class EmulatedCommandBar; class CompletionStartParams; class MatchHighlighter; class ActiveMode { public: ActiveMode(EmulatedCommandBar* emulatedCommandBar, MatchHighlighter* matchHighlighter) : m_emulatedCommandBar(emulatedCommandBar), - m_matchHighligher(matchHighlighter) + m_matchHighligher(matchHighlighter) { } virtual ~ActiveMode() = 0; virtual bool handleKeyPress(const QKeyEvent *keyEvent) = 0; virtual void editTextChanged(const QString &newText) { Q_UNUSED(newText); } virtual KateVi::CompletionStartParams completionInvoked(Completer::CompletionInvocation invocationType); 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 startCompletion(const CompletionStartParams& completionStartParams); - EmulatedCommandBar *m_emulatedCommandBar; + EmulatedCommandBar *m_emulatedCommandBar = nullptr; private: - MatchHighlighter *m_matchHighligher; + MatchHighlighter *m_matchHighligher = nullptr; }; } #endif diff --git a/src/vimode/emulatedcommandbar/emulatedcommandbar.h b/src/vimode/emulatedcommandbar/emulatedcommandbar.h index 09d4485a..aaf70d00 100644 --- a/src/vimode/emulatedcommandbar/emulatedcommandbar.h +++ b/src/vimode/emulatedcommandbar/emulatedcommandbar.h @@ -1,120 +1,121 @@ /* This file is part of the KDE libraries and the Kate part. * * Copyright (C) 2013 Simon St James * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KATEVI_EMULATED_COMMAND_BAR_H #define KATEVI_EMULATED_COMMAND_BAR_H #include "kateviewhelpers.h" #include #include #include #include "../searcher.h" #include "activemode.h" namespace KTextEditor { class ViewPrivate; class Command; } class QLabel; namespace KateVi { class MatchHighlighter; class InteractiveSedReplaceMode; class SearchMode; class CommandMode; /** * A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar, * including insertion of register contents via ctr-r; dismissal via * ctrl-c and ctrl-[; bi-directional incremental searching, with SmartCase; interactive sed-replace; * plus a few extensions such as completion from document and navigable sed search and sed replace history. */ class KTEXTEDITOR_EXPORT EmulatedCommandBar : public KateViewBarWidget { Q_OBJECT public: enum Mode { NoMode, SearchForward, SearchBackward, Command }; explicit EmulatedCommandBar(InputModeManager *viInputModeManager, QWidget *parent = 0); virtual ~EmulatedCommandBar(); void init(Mode mode, const QString &initialText = QString()); bool isActive(); void setCommandResponseMessageTimeout(long commandResponseMessageTimeOutMS); bool handleKeyPress(const QKeyEvent *keyEvent); bool isSendingSyntheticSearchCompletedKeypress(); void startInteractiveSearchAndReplace(QSharedPointer interactiveSedReplace); QString executeCommand(const QString &commandToExecute); void setViInputModeManager(InputModeManager *viInputModeManager); private: InputModeManager *m_viInputModeManager; bool m_isActive = false; Mode m_mode = NoMode; - KTextEditor::ViewPrivate *m_view; - QLineEdit *m_edit; - QLabel *m_barTypeIndicator; + KTextEditor::ViewPrivate *m_view = nullptr; + QLineEdit *m_edit = nullptr; + QLabel *m_barTypeIndicator = nullptr; void showBarTypeIndicator(Mode mode); bool m_wasAborted = true; bool m_suspendEditEventFiltering = false; bool m_waitingForRegister = false ; QLabel *m_waitingForRegisterIndicator; bool m_insertedTextShouldBeEscapedForSearchingAsLiteral = false; void hideAllWidgetsExcept(QWidget* widgetToKeepVisible); friend class ActiveMode; QScopedPointer m_matchHighligher; + QScopedPointer m_completer; + QScopedPointer m_interactiveSedReplaceMode; QScopedPointer m_searchMode; QScopedPointer m_commandMode; - void moveCursorTo(const KTextEditor::Cursor &cursorPos); - 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; void deleteSpacesToLeftOfCursor(); void deleteWordCharsToLeftOfCursor(); bool deleteNonWordCharsToLeftOfCursor(); - void closed() Q_DECL_OVERRIDE; void closeWithStatusMessage(const QString& exitStatusMessage); QTimer *m_exitStatusMessageDisplayHideTimer; QLabel *m_exitStatusMessageDisplay; long m_exitStatusMessageHideTimeOutMS = 4000; private Q_SLOTS: void editTextChanged(const QString &newText); void startHideExitStatusMessageTimer(); }; } #endif /* KATEVI_EMULATED_COMMAND_BAR_H */ diff --git a/src/vimode/emulatedcommandbar/matchhighlighter.cpp b/src/vimode/emulatedcommandbar/matchhighlighter.cpp index a05b6c86..ad257791 100644 --- a/src/vimode/emulatedcommandbar/matchhighlighter.cpp +++ b/src/vimode/emulatedcommandbar/matchhighlighter.cpp @@ -1,44 +1,44 @@ #include "matchhighlighter.h" #include "kateview.h" #include "katedocument.h" #include "kateconfig.h" using namespace KateVi; MatchHighlighter::MatchHighlighter ( KTextEditor::ViewPrivate* view ) -: m_view(view) + : m_view(view) { updateMatchHighlightAttrib(); m_highlightedMatch = m_view->doc()->newMovingRange(KTextEditor::Range::invalid(), Kate::TextRange::DoNotExpand); m_highlightedMatch->setView(m_view); // Show only in this view. m_highlightedMatch->setAttributeOnlyForViews(true); // Use z depth defined in moving ranges interface. m_highlightedMatch->setZDepth(-10000.0); m_highlightedMatch->setAttribute(m_highlightMatchAttribute); connect(m_view, SIGNAL(configChanged()), this, SLOT(updateMatchHighlightAttrib())); } MatchHighlighter::~MatchHighlighter() { delete m_highlightedMatch; } void MatchHighlighter::updateMatchHighlight ( const KTextEditor::Range& matchRange ) { // Note that if matchRange is invalid, the highlight will not be shown, so we // don't need to check for that explicitly. m_highlightedMatch->setRange(matchRange); } void MatchHighlighter::updateMatchHighlightAttrib() { const QColor &matchColour = m_view->renderer()->config()->searchHighlightColor(); if (!m_highlightMatchAttribute) { m_highlightMatchAttribute = new KTextEditor::Attribute; } m_highlightMatchAttribute->setBackground(matchColour); KTextEditor::Attribute::Ptr mouseInAttribute(new KTextEditor::Attribute()); m_highlightMatchAttribute->setDynamicAttribute(KTextEditor::Attribute::ActivateMouseIn, mouseInAttribute); m_highlightMatchAttribute->dynamicAttribute(KTextEditor::Attribute::ActivateMouseIn)->setBackground(matchColour); } diff --git a/src/vimode/emulatedcommandbar/matchhighlighter.h b/src/vimode/emulatedcommandbar/matchhighlighter.h index e160ea8a..0a6c1701 100644 --- a/src/vimode/emulatedcommandbar/matchhighlighter.h +++ b/src/vimode/emulatedcommandbar/matchhighlighter.h @@ -1,32 +1,32 @@ #ifndef KATEVI_EMULATED_COMMAND_BAR_MATCHHIGHLIGHTER_H #define KATEVI_EMULATED_COMMAND_BAR_MATCHHIGHLIGHTER_H #include #include namespace KTextEditor { class ViewPrivate; class Range; class MovingRange; } namespace KateVi { class MatchHighlighter : public QObject { Q_OBJECT public: MatchHighlighter(KTextEditor::ViewPrivate* view); ~MatchHighlighter(); void updateMatchHighlight(const KTextEditor::Range &matchRange); private Q_SLOTS: void updateMatchHighlightAttrib(); private: - KTextEditor::ViewPrivate *m_view; + KTextEditor::ViewPrivate *m_view = nullptr; KTextEditor::Attribute::Ptr m_highlightMatchAttribute; KTextEditor::MovingRange *m_highlightedMatch; }; } #endif