From b1f4889ac4deceed793f444a7405db4850fe9199 Mon Sep 17 00:00:00 2001 From: hjk <qtc-committer@nokia.com> Date: Fri, 9 Jan 2009 17:31:20 +0100 Subject: [PATCH] fakevim: use tab settings from creator base text editor --- src/plugins/fakevim/fakevimhandler.cpp | 18 +++++++++----- src/plugins/fakevim/fakevimhandler.h | 3 +-- src/plugins/fakevim/fakevimplugin.cpp | 34 +++++++++++++++++--------- src/plugins/fakevim/fakevimplugin.h | 4 --- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 7fc69764f72..0e25bfd41d6 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -146,6 +146,7 @@ public: void handleExCommand(const QString &cmd); private: + friend class FakeVimHandler; static int shift(int key) { return key + 32; } static int control(int key) { return key + 256; } @@ -187,7 +188,6 @@ private: int readLineCode(QString &cmd); QTextCursor selectRange(int beginLine, int endLine); -public: void setWidget(QWidget *ob); void enterInsertMode(); void enterCommandMode(); @@ -203,7 +203,6 @@ public: QPlainTextEdit *m_plaintextedit; bool m_wasReadOnly; // saves read-only state of document -private: FakeVimHandler *q; Mode m_mode; SubMode m_submode; @@ -282,12 +281,10 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent) m_visualMode = NoVisualMode; m_config[ConfigStartOfLine] = ConfigOn; - m_config[ConfigTabStop] = 8; + m_config[ConfigTabStop] = "8"; m_config[ConfigSmartTab] = ConfigOff; - m_config[ConfigShiftWidth] = 8; + m_config[ConfigShiftWidth] = "8"; m_config[ConfigExpandTab] = ConfigOff; - - emit q->configurationNeeded(&m_config); } bool FakeVimHandler::Private::handleEvent(QKeyEvent *ev) @@ -849,6 +846,10 @@ bool FakeVimHandler::Private::handleInsertMode(int key, const QString &text) } else if (key == Key_PageUp || key == control('b')) { m_tc.movePosition(Up, KeepAnchor, count() * (linesOnScreen() - 2)); m_lastInsertion.clear(); + } else if (key == Key_Tab && m_config[ConfigExpandTab] == ConfigOn) { + QString str = QString(m_config[ConfigTabStop].toInt(), ' '); + m_lastInsertion.append(str); + m_tc.insertText(str); } else if (!text.isEmpty()) { m_lastInsertion.append(text); m_tc.insertText(text); @@ -1557,6 +1558,11 @@ void FakeVimHandler::handleCommand(QWidget *widget, const QString &cmd) d->handleExCommand(cmd); } +void FakeVimHandler::setConfigValue(const QString &key, const QString &value) +{ + d->m_config[key] = value; +} + void FakeVimHandler::quit() { d->quit(); diff --git a/src/plugins/fakevim/fakevimhandler.h b/src/plugins/fakevim/fakevimhandler.h index 3e80dc71178..69bb363015f 100644 --- a/src/plugins/fakevim/fakevimhandler.h +++ b/src/plugins/fakevim/fakevimhandler.h @@ -39,7 +39,6 @@ QT_BEGIN_NAMESPACE class QString; class QEvent; -template <class Key, class Value> class QHash; QT_END_NAMESPACE namespace FakeVim { @@ -63,13 +62,13 @@ public slots: // information from \p widget; void handleCommand(QWidget *widget, const QString &cmd); void quit(); + void setConfigValue(const QString &key, const QString &value); signals: void commandBufferChanged(const QString &msg); void statusDataChanged(const QString &msg); void extraInformationChanged(const QString &msg); void quitRequested(QWidget *); - void configurationNeeded(QHash<QString, QString> *config); private: bool eventFilter(QObject *ob, QEvent *ev); diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index d48d71b3df8..f801de84ce7 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -51,6 +51,8 @@ #include <texteditor/basetextmark.h> #include <texteditor/itexteditor.h> #include <texteditor/texteditorconstants.h> +#include <texteditor/tabsettings.h> +#include <texteditor/texteditorsettings.h> #include <utils/qtcassert.h> @@ -67,7 +69,6 @@ using namespace FakeVim::Internal; -//using namespace FakeVim::Constants; using namespace TextEditor; using namespace Core; using namespace ProjectExplorer; @@ -146,6 +147,7 @@ void FakeVimPlugin::installHandler() { if (!m_core || !m_core->editorManager()) return; + Core::IEditor *editor = m_core->editorManager()->currentEditor(); ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor); if (!textEditor) @@ -157,10 +159,27 @@ void FakeVimPlugin::installHandler() this, SLOT(showCommandBuffer(QString))); connect(m_handler, SIGNAL(quitRequested(QWidget *)), this, SLOT(removeHandler(QWidget *))); - connect(m_handler, SIGNAL(configurationNeeded(QHash<QString, QString> *)), - this, SLOT(initializeConfiguration(QHash<QString, QString> *))); m_handler->addWidget(textEditor->widget()); + + BaseTextEditor *baseTextEditor = + qobject_cast<BaseTextEditor *>(editor->widget()); + + if (baseTextEditor) { + using namespace TextEditor; + using namespace FakeVim::Constants; + TabSettings settings = baseTextEditor->tabSettings(); + m_handler->setConfigValue(ConfigTabStop, + QString::number(settings.m_tabSize)); + m_handler->setConfigValue(ConfigShiftWidth, + QString::number(settings.m_indentSize)); + m_handler->setConfigValue(ConfigExpandTab, + settings.m_spacesForTabs ? ConfigOn : ConfigOff); + m_handler->setConfigValue(ConfigSmartTab, + settings.m_smartBackspace ? ConfigOn : ConfigOff); + //m_handler->setConfigValue(ConfigSmartTab, + // settings.m_autoIndent ? ConfigOn : ConfigOff); + } } void FakeVimPlugin::removeHandler(QWidget *widget) @@ -182,15 +201,6 @@ void FakeVimPlugin::showExtraInformation(const QString &text) QMessageBox::information(0, tr("FakeVim Information"), text); } -void FakeVimPlugin::initializeConfiguration(QHash<QString, QString> *config) -{ - qDebug() << "INIT CONFIG"; - //set shiftwidth=4 - //set expandtab - //set smarttab -} - - //#include "fakevimplugin.moc" Q_EXPORT_PLUGIN(FakeVimPlugin) diff --git a/src/plugins/fakevim/fakevimplugin.h b/src/plugins/fakevim/fakevimplugin.h index cbd2cbab566..fcaf8882ba8 100644 --- a/src/plugins/fakevim/fakevimplugin.h +++ b/src/plugins/fakevim/fakevimplugin.h @@ -40,9 +40,6 @@ QT_BEGIN_NAMESPACE class QAction; -class QCursor; -class QAbstractItemView; -template <class Key, class Value> class QHash; QT_END_NAMESPACE @@ -84,7 +81,6 @@ private slots: void removeHandler(QWidget *widget); void showCommandBuffer(const QString &contents); void showExtraInformation(const QString &msg); - void initializeConfiguration(QHash<QString, QString> *config); private: FakeVimHandler *m_handler; -- GitLab