Commit b1f4889a authored by hjk's avatar hjk
Browse files

fakevim: use tab settings from creator base text editor

parent 5f9669d8
......@@ -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();
......
......@@ -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);
......
......@@ -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)
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment