diff --git a/src/plugins/fakevim/fakevimactions.cpp b/src/plugins/fakevim/fakevimactions.cpp index be8b5daa284f18e799a6f30a0057c1c34ee8a860..741147559eef6ac28ed2a49c3e9423f0e67b6124 100644 --- a/src/plugins/fakevim/fakevimactions.cpp +++ b/src/plugins/fakevim/fakevimactions.cpp @@ -42,7 +42,11 @@ #include <QObject> #include <QCoreApplication> +#ifdef FAKEVIM_STANDALONE +using namespace FakeVim::Internal::Utils; +#else using namespace Utils; +#endif /////////////////////////////////////////////////////////////////////// // @@ -53,6 +57,29 @@ using namespace Utils; namespace FakeVim { namespace Internal { +typedef QLatin1String _; + +#ifdef FAKEVIM_STANDALONE +namespace Utils { + +SavedAction::SavedAction(QObject *parent) + : QObject(parent) +{ +} + +void SavedAction::setValue(const QVariant &value) +{ + m_value = value; +} + +QVariant SavedAction::value() const +{ + return m_value; +} + +} // namespace Utils +#endif // FAKEVIM_STANDALONE + FakeVimSettings::FakeVimSettings() {} @@ -64,7 +91,7 @@ FakeVimSettings::~FakeVimSettings() void FakeVimSettings::insertItem(int code, SavedAction *item, const QString &longName, const QString &shortName) { - QTC_ASSERT(!m_items.contains(code), qDebug() << code << item->toString(); return); + QTC_ASSERT(!m_items.contains(code), qDebug() << code; return); m_items[code] = item; if (!longName.isEmpty()) { m_nameToCode[longName] = code; @@ -74,6 +101,7 @@ void FakeVimSettings::insertItem(int code, SavedAction *item, m_nameToCode[shortName] = code; } +#ifndef FAKEVIM_STANDALONE void FakeVimSettings::readSettings(QSettings *settings) { foreach (SavedAction *item, m_items) @@ -85,6 +113,7 @@ void FakeVimSettings::writeSettings(QSettings *settings) foreach (SavedAction *item, m_items) item->writeSettings(settings); } +#endif // FAKEVIM_STANDALONE SavedAction *FakeVimSettings::item(int code) { @@ -114,162 +143,63 @@ QString FakeVimSettings::trySetValue(const QString &name, const QString &value) return QString(); } -FakeVimSettings *theFakeVimSettings() +SavedAction *createAction(FakeVimSettings *instance, int code, const QVariant &value, + const QString &settingsKey = QString(), + const QString &shortKey = QString()) { - static FakeVimSettings *instance = 0; - if (instance) - return instance; - - instance = new FakeVimSettings; - - typedef QLatin1String _; - SavedAction *item = 0; + SavedAction *item = new SavedAction(instance); + item->setValue(value); +#ifndef FAKEVIM_STANDALONE + item->setSettingsKey(_("FakeVim"), settingsKey); + item->setDefaultValue(value); + item->setCheckable( value.canConvert<bool>() ); +#endif + instance->insertItem(code, item, settingsKey.toLower(), shortKey); + return item; +} - const QString group = _("FakeVim"); - item = new SavedAction(instance); - item->setText(QCoreApplication::translate("FakeVim::Internal", +FakeVimSettings *theFakeVimSettings() +{ + static FakeVimSettings *s = 0; + if (s) + return s; + + s = new FakeVimSettings; + + // Specific FakeVim settings + createAction(s, ConfigUseFakeVim, true, _("UseFakeVim")); + createAction(s, ConfigReadVimRc, false, _("ReadVimRc")); + createAction(s, ConfigVimRcPath, QString(), _("VimRcPath")); +#ifndef FAKEVIM_STANDALONE + s->item(ConfigUseFakeVim)->setText(QCoreApplication::translate("FakeVim::Internal", "Use Vim-style Editing")); - item->setSettingsKey(group, _("UseFakeVim")); - item->setCheckable(true); - item->setValue(false); - instance->insertItem(ConfigUseFakeVim, item); - - item = new SavedAction(instance); - item->setText(QCoreApplication::translate("FakeVim::Internal", + s->item(ConfigReadVimRc)->setText(QCoreApplication::translate("FakeVim::Internal", "Read .vimrc")); - item->setSettingsKey(group, _("ReadVimRc")); - item->setCheckable(true); - item->setValue(false); - instance->insertItem(ConfigReadVimRc, item); - - item = new SavedAction(instance); - item->setText(QCoreApplication::translate("FakeVim::Internal", + s->item(ConfigVimRcPath)->setText(QCoreApplication::translate("FakeVim::Internal", "Path to .vimrc")); - item->setDefaultValue(QString()); - item->setSettingsKey(group, _("VimRcPath")); - instance->insertItem(ConfigVimRcPath, item); - - item = new SavedAction(instance); - item->setValue(true); - item->setDefaultValue(true); - item->setSettingsKey(group, _("StartOfLine")); - item->setCheckable(true); - instance->insertItem(ConfigStartOfLine, item, _("startofline"), _("sol")); - - item = new SavedAction(instance); - item->setDefaultValue(8); - item->setSettingsKey(group, _("TabStop")); - instance->insertItem(ConfigTabStop, item, _("tabstop"), _("ts")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("SmartTab")); - instance->insertItem(ConfigSmartTab, item, _("smarttab"), _("sta")); - - item = new SavedAction(instance); - item->setDefaultValue(true); - item->setValue(true); - item->setSettingsKey(group, _("HlSearch")); - item->setCheckable(true); - instance->insertItem(ConfigHlSearch, item, _("hlsearch"), _("hls")); - - item = new SavedAction(instance); - item->setDefaultValue(8); - item->setSettingsKey(group, _("ShiftWidth")); - instance->insertItem(ConfigShiftWidth, item, _("shiftwidth"), _("sw")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("ExpandTab")); - item->setCheckable(true); - instance->insertItem(ConfigExpandTab, item, _("expandtab"), _("et")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("AutoIndent")); - item->setValue(false); - item->setCheckable(true); - instance->insertItem(ConfigAutoIndent, item, _("autoindent"), _("ai")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("SmartIndent")); - item->setValue(false); - item->setCheckable(true); - instance->insertItem(ConfigSmartIndent, item, _("smartindent"), _("si")); - - item = new SavedAction(instance); - item->setDefaultValue(true); - item->setValue(true); - item->setSettingsKey(group, _("IncSearch")); - item->setCheckable(true); - instance->insertItem(ConfigIncSearch, item, _("incsearch"), _("is")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("UseCoreSearch")); item->setCheckable(true); - instance->insertItem(ConfigUseCoreSearch, item, - _("usecoresearch"), _("ucs")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("SmartCase")); item->setCheckable(true); - item->setCheckable(true); - instance->insertItem(ConfigSmartCase, item, _("smartcase"), _("scs")); - - item = new SavedAction(instance); - item->setDefaultValue(true); - item->setValue(true); - item->setSettingsKey(group, _("WrapScan")); item->setCheckable(true); - item->setCheckable(true); - instance->insertItem(ConfigWrapScan, item, _("wrapscan"), _("ws")); - - item = new SavedAction(instance); - item->setDefaultValue(_("indent,eol,start")); - item->setSettingsKey(group, _("Backspace")); - instance->insertItem(ConfigBackspace, item, _("backspace"), _("bs")); - - item = new SavedAction(instance); - item->setDefaultValue(_("@,48-57,_,192-255,a-z,A-Z")); - item->setSettingsKey(group, _("IsKeyword")); - instance->insertItem(ConfigIsKeyword, item, _("iskeyword"), _("isk")); - - // Invented here. - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("ShowMarks")); - item->setCheckable(true); - instance->insertItem(ConfigShowMarks, item, _("showmarks"), _("sm")); - - item = new SavedAction(instance); - item->setDefaultValue(false); - item->setValue(false); - item->setSettingsKey(group, _("PassControlKey")); - item->setCheckable(true); - instance->insertItem(ConfigPassControlKey, item, _("passcontrolkey"), _("pck")); - - item = new SavedAction(instance); - item->setDefaultValue(QString()); - item->setValue(QString()); - item->setSettingsKey(group, _("Clipboard")); - item->setCheckable(true); - instance->insertItem(ConfigClipboard, item, _("clipboard"), _("cb")); - - item = new SavedAction(instance); - item->setDefaultValue(true); - item->setValue(true); - item->setSettingsKey(group, _("ShowCmd")); item->setCheckable(true); - item->setCheckable(true); - instance->insertItem(ConfigShowCmd, item, _("showcmd"), _("sc")); - - return instance; +#endif + createAction(s, ConfigShowMarks, false, _("ShowMarks"), _("sm")); + createAction(s, ConfigPassControlKey, false, _("PassControlKey"), _("pck")); + + // Emulated Vim setting + createAction(s, ConfigStartOfLine, true, _("StartOfLine"), _("sol")); + createAction(s, ConfigTabStop, 8, _("TabStop"), _("ts")); + createAction(s, ConfigSmartTab, false, _("SmartTab"), _("sta")); + createAction(s, ConfigHlSearch, true, _("HlSearch"), _("hls")); + createAction(s, ConfigShiftWidth, 8, _("ShiftWidth"), _("sw")); + createAction(s, ConfigExpandTab, false, _("ExpandTab"), _("et")); + createAction(s, ConfigAutoIndent, false, _("AutoIndent"), _("ai")); + createAction(s, ConfigSmartIndent, false, _("SmartIndent"), _("si")); + createAction(s, ConfigIncSearch, true, _("IncSearch"), _("is")); + createAction(s, ConfigUseCoreSearch, false, _("UseCoreSearch"), _("ucs")); + createAction(s, ConfigSmartCase, false, _("SmartCase"), _("scs")); + createAction(s, ConfigWrapScan, true, _("WrapScan"), _("ws")); + createAction(s, ConfigShowCmd, true, _("ShowCmd"), _("sc")); + createAction(s, ConfigBackspace, _("indent,eol,start"), _("ConfigBackspace"), _("bs")); + createAction(s, ConfigIsKeyword, _("@,48-57,_,192-255,a-z,A-Z"), _("IsKeyword"), _("isk")); + createAction(s, ConfigClipboard, QString(), _("Clipboard"), _("cb")); + + return s; } SavedAction *theFakeVimSetting(int code) diff --git a/src/plugins/fakevim/fakevimactions.h b/src/plugins/fakevim/fakevimactions.h index a730af62fa6f94b24ffec0523f7f70f3b6a1242f..a3c8133aa9cf1d7c486f95d5d02a0c1c3fbdd40f 100644 --- a/src/plugins/fakevim/fakevimactions.h +++ b/src/plugins/fakevim/fakevimactions.h @@ -30,15 +30,33 @@ #ifndef FAKEVIM_ACTIONS_H #define FAKEVIM_ACTIONS_H -#include <utils/savedaction.h> +#ifndef FAKEVIM_STANDALONE +# include <utils/savedaction.h> +#endif #include <QHash> #include <QObject> #include <QString> +#include <QVariant> namespace FakeVim { namespace Internal { +#ifdef FAKEVIM_STANDALONE +namespace Utils { + +class SavedAction : public QObject +{ +public: + SavedAction(QObject *parent); + void setValue(const QVariant &value); + QVariant value() const; + QVariant m_value; +}; + +} // namespace Utils +#endif // FAKEVIM_STANDALONE + enum FakeVimSettingsCode { ConfigUseFakeVim, @@ -90,8 +108,10 @@ public: Utils::SavedAction *item(const QString &name); QString trySetValue(const QString &name, const QString &value); +#ifndef FAKEVIM_STANDALONE void readSettings(QSettings *settings); void writeSettings(QSettings *settings); +#endif private: QHash<int, Utils::SavedAction *> m_items; diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 058bc18b96ab14c71b0bd2e39ea7f8f6ce873f7a..583a96b410edced6fca6f49bab809ba4c6510e8d 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -59,6 +59,8 @@ #include "fakevimhandler.h" +#include "fakevimactions.h" + #include <utils/hostosinfo.h> #include <utils/qtcassert.h> @@ -105,6 +107,9 @@ #endif using namespace Utils; +#ifdef FAKEVIM_STANDALONE +using namespace FakeVim::Internal::Utils; +#endif namespace FakeVim { namespace Internal { @@ -1768,7 +1773,7 @@ public: // auto-indent QString tabExpand(int len) const; Column indentation(const QString &line) const; - void insertAutomaticIndentation(bool goingDown); + void insertAutomaticIndentation(bool goingDown, bool forceAutoIndent = false); bool removeAutomaticIndentation(); // true if something removed // number of autoindented characters int m_justAutoIndented; @@ -2045,12 +2050,14 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev) return EventPassedToCore; } +#ifndef FAKEVIM_STANDALONE bool inSnippetMode = false; QMetaObject::invokeMethod(editor(), "inSnippetMode", Q_ARG(bool *, &inSnippetMode)); if (inSnippetMode) return EventPassedToCore; +#endif // Fake "End of line" //m_tc = cursor(); @@ -4983,23 +4990,15 @@ bool FakeVimHandler::Private::handleExChangeCommand(const ExCommand &cmd) if (!cmd.matches(_("c"), _("change"))) return false; - const bool oldAutoIndent = hasConfig(ConfigAutoIndent); - // Temporarily set autoindent if ! is present. - if (cmd.hasBang) - theFakeVimSetting(ConfigAutoIndent)->setValue(true, false); - Range range = cmd.range; range.rangemode = RangeLineModeExclusive; removeText(range); - insertAutomaticIndentation(true); + insertAutomaticIndentation(true, cmd.hasBang); // FIXME: In Vim same or less number of lines can be inserted and position after insertion is // beginning of last inserted line. enterInsertMode(); - if (cmd.hasBang && !oldAutoIndent) - theFakeVimSetting(ConfigAutoIndent)->setValue(false, false); - return true; } @@ -5189,7 +5188,7 @@ bool FakeVimHandler::Private::handleExBangCommand(const ExCommand &cmd) // :! QProcess proc; proc.start(command); proc.waitForStarted(); - if (Utils::HostOsInfo::isWindowsHost()) + if (HostOsInfo::isWindowsHost()) text.replace(_("\n"), _("\r\n")); proc.write(text.toUtf8()); proc.closeWriteChannel(); @@ -6825,9 +6824,9 @@ QString FakeVimHandler::Private::tabExpand(int n) const + QString(n % ts, QLatin1Char(' ')); } -void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown) +void FakeVimHandler::Private::insertAutomaticIndentation(bool goingDown, bool forceAutoIndent) { - if (!hasConfig(ConfigAutoIndent) && !hasConfig(ConfigSmartIndent)) + if (!forceAutoIndent && !hasConfig(ConfigAutoIndent) && !hasConfig(ConfigSmartIndent)) return; if (hasConfig(ConfigSmartIndent)) { diff --git a/src/plugins/fakevim/fakevimhandler.h b/src/plugins/fakevim/fakevimhandler.h index 8999747530a6d04be4bc59920074edc787cdae03..6e742915d42a04e45776af86fc6bfdf36b7ea67c 100644 --- a/src/plugins/fakevim/fakevimhandler.h +++ b/src/plugins/fakevim/fakevimhandler.h @@ -30,8 +30,6 @@ #ifndef FAKEVIM_HANDLER_H #define FAKEVIM_HANDLER_H -#include "fakevimactions.h" - #include <QObject> #include <QTextEdit> diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 5a96b297e6de02f85fea2b264dce66c69371b83b..db30a5fa83f7f2b42059f4dc313d35150dfa4e3a 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -29,6 +29,7 @@ #include "fakevimplugin.h" +#include "fakevimactions.h" #include "fakevimhandler.h" #include "ui_fakevimoptions.h" diff --git a/tests/manual/fakevim/fakevim.pro b/tests/manual/fakevim/fakevim.pro index 4cb3db339012de1266b9fe144e1150ee53bb6ccd..69eacc5042c2ca818f242d7232282af7ef52a910 100644 --- a/tests/manual/fakevim/fakevim.pro +++ b/tests/manual/fakevim/fakevim.pro @@ -1,15 +1,19 @@ include(../../auto/qttest.pri) include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) +DEFINES += FAKEVIM_STANDALONE FAKEVIMDIR = $$IDE_SOURCE_TREE/src/plugins/fakevim -LIBSDIR = $$IDE_SOURCE_TREE/src/libs +UTILSDIR = $$IDE_SOURCE_TREE/src/libs/utils SOURCES += main.cpp \ $$FAKEVIMDIR/fakevimhandler.cpp \ - $$FAKEVIMDIR/fakevimactions.cpp + $$FAKEVIMDIR/fakevimactions.cpp \ + $$UTILSDIR/hostosinfo.cpp \ + $$UTILSDIR/qtcassert.cpp HEADERS += $$FAKEVIMDIR/fakevimhandler.h \ - $$FAKEVIMDIR/fakevimactions.h - -INCLUDEPATH += $$FAKEVIMDIR $$LIBSDIR + $$FAKEVIMDIR/fakevimactions.h \ + $$UTILSDIR/hostosinfo.h \ + $$UTILSDIR/qtcassert.h +INCLUDEPATH += $$FAKEVIMDIR $$UTILSDIR diff --git a/tests/manual/fakevim/main.cpp b/tests/manual/fakevim/main.cpp index 59ad34523b4b71deb9023527a941f2067581fb0b..fd965122be143c5c75aa7871335cea8a3b2ec264 100644 --- a/tests/manual/fakevim/main.cpp +++ b/tests/manual/fakevim/main.cpp @@ -29,17 +29,56 @@ #include "fakevimhandler.h" -#include <QDebug> - #include <QApplication> +#include <QFontMetrics> #include <QMainWindow> #include <QMessageBox> +#include <QPainter> #include <QPlainTextEdit> #include <QStatusBar> #include <QTextEdit> using namespace FakeVim::Internal; +typedef QLatin1String _; + +/** + * Simple editor widget. + * @tparam TextEdit QTextEdit or QPlainTextEdit as base class + */ +template <typename TextEdit> +class Editor : public TextEdit +{ +public: + Editor(QWidget *parent = 0) : TextEdit(parent) + { + TextEdit::setCursorWidth(0); + } + + void paintEvent(QPaintEvent *e) + { + TextEdit::paintEvent(e); + + // Draw text cursor. + QRect rect = TextEdit::cursorRect(); + if ( e->rect().contains(rect) ) { + QPainter painter(TextEdit::viewport()); + + if ( TextEdit::overwriteMode() ) { + QFontMetrics fm(TextEdit::font()); + rect.setWidth(fm.width(QLatin1Char('m'))); + painter.setPen(Qt::NoPen); + painter.setBrush(TextEdit::palette().color(QPalette::Base)); + painter.setCompositionMode(QPainter::CompositionMode_Difference); + } else { + rect.setWidth(TextEdit::cursorWidth()); + painter.setPen(TextEdit::palette().color(QPalette::Text)); + } + painter.drawRect(rect); + } + } +}; + class Proxy : public QObject { Q_OBJECT @@ -64,6 +103,44 @@ public slots: updateStatusBar(); } + void highlightMatches(const QString &pattern) + { + QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget); + if (!ed) + return; + + // Clear previous highlights. + ed->selectAll(); + QTextCursor cur = ed->textCursor(); + QTextCharFormat fmt = cur.charFormat(); + fmt.setBackground(Qt::transparent); + cur.setCharFormat(fmt); + + // Highlight matches. + QTextDocument *doc = ed->document(); + QRegExp re(pattern); + cur = doc->find(re); + + int a = cur.position(); + while ( !cur.isNull() ) { + if ( cur.hasSelection() ) { + fmt.setBackground(Qt::yellow); + cur.setCharFormat(fmt); + } else { + cur.movePosition(QTextCursor::NextCharacter); + } + cur = doc->find(re, cur); + int b = cur.position(); + if (a == b) { + cur.movePosition(QTextCursor::NextCharacter); + cur = doc->find(re, cur); + b = cur.position(); + if (a == b) break; + } + a = b; + } + } + void changeStatusMessage(const QString &contents, int cursorPos) { m_statusMessage = cursorPos == -1 ? contents @@ -83,6 +160,18 @@ public slots: m_mainWindow->statusBar()->showMessage(msg); } + void handleExCommand(bool *handled, const ExCommand &cmd) + { + if (cmd.matches(_("q"), _("quit")) || cmd.matches(_("qa"), _("qall"))) { + QApplication::quit(); + } else { + *handled = false; + return; + } + + *handled = true; + } + private: QWidget *m_widget; QMainWindow *m_mainWindow; @@ -90,55 +179,63 @@ private: QString m_statusData; }; -int main(int argc, char *argv[]) +QWidget *createEditorWidget(bool usePlainTextEdit) { - QApplication app(argc, argv); - - QStringList args = app.arguments(); - (void) args.takeFirst(); - - QWidget *widget = 0; - QString title; - bool usePlainTextEdit = args.size() < 2; + QWidget *editor = 0; if (usePlainTextEdit) { - QPlainTextEdit *w = new QPlainTextEdit; + Editor<QPlainTextEdit> *w = new Editor<QPlainTextEdit>; w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - title = QLatin1String("PlainTextEdit"); - widget = w; + editor = w; } else { - QTextEdit *w = new QTextEdit; + Editor<QTextEdit> *w = new Editor<QTextEdit>; w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - title = QLatin1String("TextEdit"); - widget = w; + editor = w; } - widget->setObjectName(QLatin1String("Editor")); - //widget->resize(450, 350); - widget->setFocus(); + editor->setObjectName(_("Editor")); + editor->setFocus(); + + return editor; +} - QMainWindow mw; - Proxy proxy(widget, &mw); +void initHandler(FakeVimHandler &handler) +{ + // Set some Vim options. + handler.handleCommand(_("set expandtab")); + handler.handleCommand(_("set shiftwidth=8")); + handler.handleCommand(_("set tabstop=16")); + handler.handleCommand(_("set autoindent")); - FakeVimHandler handler(widget, 0); + // Try to source file "fakevimrc" from current directory. + handler.handleCommand(_("source fakevimrc")); + + handler.installEventFilter(); + handler.setupWidget(); +} - mw.setWindowTitle(QLatin1String("Fakevim (") + title + QLatin1Char(')')); - mw.setCentralWidget(widget); - mw.resize(600, 650); - mw.move(0, 0); - mw.show(); +void initMainWindow(QMainWindow &mainWindow, QWidget *centralWidget, const QString &title) +{ + mainWindow.setWindowTitle(QString(_("FakeVim (%1)")).arg(title)); + mainWindow.setCentralWidget(centralWidget); + mainWindow.resize(600, 650); + mainWindow.move(0, 0); + mainWindow.show(); - QFont font = widget->font(); - //: -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1 - //font.setFamily("Misc"); - font.setFamily(QLatin1String("Monospace")); - //font.setStretch(QFont::SemiCondensed); + // Set monospace font for editor and status bar. + QFont font = QApplication::font(); + font.setFamily(_("Monospace")); + centralWidget->setFont(font); + mainWindow.statusBar()->setFont(font); +} - widget->setFont(font); - mw.statusBar()->setFont(font); +void readFile(FakeVimHandler &handler, const QString &editFileName) +{ + handler.handleCommand(QString(_("r %1")).arg(editFileName)); +} - QObject::connect(&handler, SIGNAL(commandBufferChanged(QString,int)), +void connectSignals(FakeVimHandler &handler, Proxy &proxy) +{ + QObject::connect(&handler, SIGNAL(commandBufferChanged(QString,int,int,int,QObject*)), &proxy, SLOT(changeStatusMessage(QString,int))); - //QObject::connect(&handler, SIGNAL(quitRequested(bool)), - // &app, SLOT(quit())); QObject::connect(&handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), &proxy, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>))); @@ -146,17 +243,42 @@ int main(int argc, char *argv[]) &proxy, SLOT(changeExtraInformation(QString))); QObject::connect(&handler, SIGNAL(statusDataChanged(QString)), &proxy, SLOT(changeStatusData(QString))); + QObject::connect(&handler, SIGNAL(highlightMatches(QString)), + &proxy, SLOT(highlightMatches(QString))); + QObject::connect(&handler, SIGNAL(handleExCommandRequested(bool*,ExCommand)), + &proxy, SLOT(handleExCommand(bool*,ExCommand))); +} - theFakeVimSetting(ConfigUseFakeVim)->setValue(true); - theFakeVimSetting(ConfigShiftWidth)->setValue(8); - theFakeVimSetting(ConfigTabStop)->setValue(8); - theFakeVimSetting(ConfigAutoIndent)->setValue(true); - theFakeVimSetting(ConfigIsKeyword)->setValue(QLatin1String("@,48-57,_,192-255,a-z,A-Z")); +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); - handler.installEventFilter(); - handler.setupWidget(); - if (args.size() >= 1) - handler.handleCommand(QLatin1String("r ") + args.at(0)); + QStringList args = app.arguments(); + + // If first argument is present use QPlainTextEdit instead on QTextEdit; + bool usePlainTextEdit = args.size() > 1; + // Second argument is path to file to edit. + const QString editFileName = args.value(2, QString(_("/usr/share/vim/vim73/tutor/tutor"))); + + // Create editor widget. + QWidget *editor = createEditorWidget(usePlainTextEdit); + + // Create FakeVimHandler instance which will emulate Vim behavior in editor widget. + FakeVimHandler handler(editor, 0); + + // Create main window. + QMainWindow mainWindow; + initMainWindow(mainWindow, editor, usePlainTextEdit ? _("QPlainTextEdit") : _("QTextEdit")); + + // Connect slots to FakeVimHandler signals. + Proxy proxy(editor, &mainWindow); + connectSignals(handler, proxy); + + // Initialize FakeVimHandler. + initHandler(handler); + + // Read file content to editor. + readFile(handler, editFileName); return app.exec(); }