fakevim: synchronize with master

In theory this should have been a backport of the search-related commits
7e8c345a and 46fa3aa7, but they are buried in the middle of the Big
Commandline Reorganization. Just taking everything has lower risk and
is faster.
This commit is contained in:
hjk
2010-06-02 11:09:14 +02:00
parent 878462f72e
commit b67369393e
6 changed files with 1388 additions and 973 deletions

View File

@@ -209,10 +209,13 @@ FakeVimSettings *theFakeVimSettings()
item->setSettingsKey(group, _("IsKeyword")); item->setSettingsKey(group, _("IsKeyword"));
instance->insertItem(ConfigIsKeyword, item, _("iskeyword"), _("isk")); instance->insertItem(ConfigIsKeyword, item, _("iskeyword"), _("isk"));
// Invented here.
item = new SavedAction(instance); item = new SavedAction(instance);
item->setText(QCoreApplication::translate("FakeVim::Internal", item->setDefaultValue(false);
"FakeVim properties...")); item->setValue(false);
instance->insertItem(SettingsDialog, item); item->setSettingsKey(group, _("ShowMarks"));
item->setCheckable(true);
instance->insertItem(ConfigShowMarks, item, _("showmarks"), _("sm"));
return instance; return instance;
} }

View File

@@ -64,7 +64,7 @@ enum FakeVimSettingsCode
ConfigIsKeyword, ConfigIsKeyword,
// other actions // other actions
SettingsDialog, ConfigShowMarks,
}; };
class FakeVimSettings : public QObject class FakeVimSettings : public QObject

File diff suppressed because it is too large Load Diff

View File

@@ -38,6 +38,38 @@
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
enum RangeMode
{
RangeCharMode, // v
RangeLineMode, // V
RangeLineModeExclusive,
RangeBlockMode, // Ctrl-v
RangeBlockAndTailMode, // Ctrl-v for D and X
};
struct Range
{
Range();
Range(int b, int e, RangeMode m = RangeCharMode);
QString toString() const;
int beginPos;
int endPos;
RangeMode rangemode;
};
struct ExCommand
{
ExCommand() : hasBang(false) {}
ExCommand(const QString &cmd, const QString &args = QString(),
const Range &range = Range());
QString cmd;
bool hasBang;
QString args;
Range range;
};
class FakeVimHandler : public QObject class FakeVimHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -53,6 +85,8 @@ public:
public slots: public slots:
void setCurrentFileName(const QString &fileName); void setCurrentFileName(const QString &fileName);
QString currentFileName() const;
void showBlackMessage(const QString &msg); void showBlackMessage(const QString &msg);
void showRedMessage(const QString &msg); void showRedMessage(const QString &msg);
@@ -76,8 +110,6 @@ signals:
void statusDataChanged(const QString &msg); void statusDataChanged(const QString &msg);
void extraInformationChanged(const QString &msg); void extraInformationChanged(const QString &msg);
void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection); void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection);
void writeFileRequested(bool *handled,
const QString &fileName, const QString &contents);
void writeAllRequested(QString *error); void writeAllRequested(QString *error);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
void checkForElectricCharacter(bool *result, QChar c); void checkForElectricCharacter(bool *result, QChar c);
@@ -86,8 +118,7 @@ signals:
void windowCommandRequested(int key); void windowCommandRequested(int key);
void findRequested(bool reverse); void findRequested(bool reverse);
void findNextRequested(bool reverse); void findNextRequested(bool reverse);
void handleExCommandRequested(const QString &cmd); void handleExCommandRequested(bool *handled, const ExCommand &cmd);
void handleSetCommandRequested(bool *handled, const QString &cmd);
public: public:
class Private; class Private;
@@ -101,4 +132,7 @@ private:
} // namespace Internal } // namespace Internal
} // namespace FakeVim } // namespace FakeVim
Q_DECLARE_METATYPE(FakeVim::Internal::ExCommand);
#endif // FAKEVIM_HANDLER_H #endif // FAKEVIM_HANDLER_H

View File

@@ -66,6 +66,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2">
<widget class="QCheckBox" name="checkBoxShowMarks">
<property name="text">
<string>Show position of text marks</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkBoxSmartTab"> <widget class="QCheckBox" name="checkBoxSmartTab">
<property name="text"> <property name="text">

View File

@@ -73,9 +73,9 @@
#include <indenter.h> #include <indenter.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QtPlugin> #include <QtCore/QtPlugin>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QPoint>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
@@ -120,6 +120,8 @@ const char * const CMD_FILE_PREV = "FakeVim.SwitchFilePrev";
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
typedef QMap<QString, QRegExp> CommandMap;
class FakeVimOptionPage : public Core::IOptionsPage class FakeVimOptionPage : public Core::IOptionsPage
{ {
Q_OBJECT Q_OBJECT
@@ -168,6 +170,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent)
m_ui.checkBoxHlSearch); m_ui.checkBoxHlSearch);
m_group.insert(theFakeVimSetting(ConfigShiftWidth), m_group.insert(theFakeVimSetting(ConfigShiftWidth),
m_ui.spinBoxShiftWidth); m_ui.spinBoxShiftWidth);
m_group.insert(theFakeVimSetting(ConfigShowMarks),
m_ui.checkBoxShowMarks);
m_group.insert(theFakeVimSetting(ConfigSmartTab), m_group.insert(theFakeVimSetting(ConfigSmartTab),
m_ui.checkBoxSmartTab); m_ui.checkBoxSmartTab);
@@ -199,8 +203,8 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent)
QTextStream(&m_searchKeywords) QTextStream(&m_searchKeywords)
<< ' ' << m_ui.checkBoxAutoIndent->text() << ' ' << m_ui.checkBoxAutoIndent->text()
<< ' ' << m_ui.checkBoxExpandTab->text() << ' ' << m_ui.checkBoxExpandTab->text()
<< ' ' << m_ui.checkBoxShowMarks->text()
<< ' ' << m_ui.checkBoxSmartIndent->text() << ' ' << m_ui.checkBoxSmartIndent->text()
<< ' ' << m_ui.checkBoxExpandTab->text()
<< ' ' << m_ui.checkBoxHlSearch->text() << ' ' << m_ui.checkBoxHlSearch->text()
<< ' ' << m_ui.checkBoxIncSearch->text() << ' ' << m_ui.checkBoxIncSearch->text()
<< ' ' << m_ui.checkBoxSmartTab->text() << ' ' << m_ui.checkBoxSmartTab->text()
@@ -278,16 +282,12 @@ Q_DECLARE_METATYPE(CommandItem*);
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
static QMap<QString, QRegExp> s_exCommandMap;
static QMap<QString, QRegExp> s_defaultExCommandMap;
class FakeVimExCommandsPage : public Core::CommandMappings class FakeVimExCommandsPage : public Core::CommandMappings
{ {
Q_OBJECT Q_OBJECT
public: public:
FakeVimExCommandsPage() {} FakeVimExCommandsPage(FakeVimPluginPrivate *q) : m_q(q) {}
// IOptionsPage // IOptionsPage
QString id() const { return QLatin1String(Constants::SETTINGS_EX_CMDS_ID); } QString id() const { return QLatin1String(Constants::SETTINGS_EX_CMDS_ID); }
@@ -298,6 +298,8 @@ public:
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void initialize(); void initialize();
CommandMap &exCommandMap();
CommandMap &defaultExCommandMap();
public slots: public slots:
void commandChanged(QTreeWidgetItem *current); void commandChanged(QTreeWidgetItem *current);
@@ -309,6 +311,7 @@ public slots:
private: private:
void setRegex(const QString &regex); void setRegex(const QString &regex);
QList<CommandItem *> m_citems; QList<CommandItem *> m_citems;
FakeVimPluginPrivate *m_q;
}; };
QWidget *FakeVimExCommandsPage::createPage(QWidget *parent) QWidget *FakeVimExCommandsPage::createPage(QWidget *parent)
@@ -341,15 +344,16 @@ void FakeVimExCommandsPage::initialize()
QTreeWidgetItem *item = new QTreeWidgetItem; QTreeWidgetItem *item = new QTreeWidgetItem;
ci->m_cmd = c; ci->m_cmd = c;
ci->m_item = item; ci->m_item = item;
m_citems << ci; m_citems.append(ci);
const QString name = uidm->stringForUniqueIdentifier(c->id()); const QString name = uidm->stringForUniqueIdentifier(c->id());
const int pos = name.indexOf(QLatin1Char('.')); const int pos = name.indexOf(QLatin1Char('.'));
const QString section = name.left(pos); const QString section = name.left(pos);
const QString subId = name.mid(pos+1); const QString subId = name.mid(pos + 1);
if (!sections.contains(section)) { if (!sections.contains(section)) {
QTreeWidgetItem *categoryItem = new QTreeWidgetItem(commandList(), QStringList() << section); QTreeWidgetItem *categoryItem =
new QTreeWidgetItem(commandList(), QStringList() << section);
QFont f = categoryItem->font(0); QFont f = categoryItem->font(0);
f.setBold(true); f.setBold(true);
categoryItem->setFont(0, f); categoryItem->setFont(0, f);
@@ -361,14 +365,16 @@ void FakeVimExCommandsPage::initialize()
item->setText(0, subId); item->setText(0, subId);
if (c->action()) { if (c->action()) {
QString text = c->hasAttribute(Command::CA_UpdateText) && !c->defaultText().isNull() ? c->defaultText() : c->action()->text(); QString text = c->hasAttribute(Command::CA_UpdateText)
&& !c->defaultText().isNull()
? c->defaultText() : c->action()->text();
text.remove(QRegExp("&(?!&)")); text.remove(QRegExp("&(?!&)"));
item->setText(1, text); item->setText(1, text);
} else { } else {
item->setText(1, c->shortcut()->whatsThis()); item->setText(1, c->shortcut()->whatsThis());
} }
if (s_exCommandMap.contains(name)) { if (exCommandMap().contains(name)) {
ci->m_regex = s_exCommandMap[name].pattern(); ci->m_regex = exCommandMap()[name].pattern();
} else { } else {
ci->m_regex.clear(); ci->m_regex.clear();
} }
@@ -376,7 +382,7 @@ void FakeVimExCommandsPage::initialize()
item->setText(2, ci->m_regex); item->setText(2, ci->m_regex);
item->setData(0, Qt::UserRole, qVariantFromValue(ci)); item->setData(0, Qt::UserRole, qVariantFromValue(ci));
if (ci->m_regex != s_defaultExCommandMap[name].pattern()) if (ci->m_regex != defaultExCommandMap()[name].pattern())
setModified(item, true); setModified(item, true);
} }
@@ -407,10 +413,10 @@ void FakeVimExCommandsPage::targetIdentifierChanged()
if (current->data(0, Qt::UserRole).isValid()) { if (current->data(0, Qt::UserRole).isValid()) {
citem->m_regex = targetEdit()->text(); citem->m_regex = targetEdit()->text();
current->setText(2, citem->m_regex); current->setText(2, citem->m_regex);
s_exCommandMap[name] = QRegExp(citem->m_regex); exCommandMap()[name] = QRegExp(citem->m_regex);
} }
if (citem->m_regex != s_defaultExCommandMap[name].pattern()) if (citem->m_regex != defaultExCommandMap()[name].pattern())
setModified(current, true); setModified(current, true);
else else
setModified(current, false); setModified(current, false);
@@ -429,8 +435,8 @@ void FakeVimExCommandsPage::resetTargetIdentifier()
if (current && current->data(0, Qt::UserRole).isValid()) { if (current && current->data(0, Qt::UserRole).isValid()) {
CommandItem *citem = qVariantValue<CommandItem *>(current->data(0, Qt::UserRole)); CommandItem *citem = qVariantValue<CommandItem *>(current->data(0, Qt::UserRole));
const QString &name = uidm->stringForUniqueIdentifier(citem->m_cmd->id()); const QString &name = uidm->stringForUniqueIdentifier(citem->m_cmd->id());
if (s_defaultExCommandMap.contains(name)) if (defaultExCommandMap().contains(name))
setRegex(s_defaultExCommandMap[name].pattern()); setRegex(defaultExCommandMap()[name].pattern());
else else
setRegex(QString()); setRegex(QString());
} }
@@ -446,8 +452,8 @@ void FakeVimExCommandsPage::defaultAction()
UniqueIDManager *uidm = UniqueIDManager::instance(); UniqueIDManager *uidm = UniqueIDManager::instance();
foreach (CommandItem *item, m_citems) { foreach (CommandItem *item, m_citems) {
const QString &name = uidm->stringForUniqueIdentifier(item->m_cmd->id()); const QString &name = uidm->stringForUniqueIdentifier(item->m_cmd->id());
if (s_defaultExCommandMap.contains(name)) { if (defaultExCommandMap().contains(name)) {
item->m_regex = s_defaultExCommandMap[name].pattern(); item->m_regex = defaultExCommandMap()[name].pattern();
} else { } else {
item->m_regex.clear(); item->m_regex.clear();
} }
@@ -479,6 +485,7 @@ public:
FakeVimPluginPrivate(FakeVimPlugin *); FakeVimPluginPrivate(FakeVimPlugin *);
~FakeVimPluginPrivate(); ~FakeVimPluginPrivate();
friend class FakeVimPlugin; friend class FakeVimPlugin;
friend class FakeVimExCommandsPage;
bool initialize(); bool initialize();
void aboutToShutdown(); void aboutToShutdown();
@@ -499,12 +506,10 @@ private slots:
void showCommandBuffer(const QString &contents); void showCommandBuffer(const QString &contents);
void showExtraInformation(const QString &msg); void showExtraInformation(const QString &msg);
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections); void changeSelection(const QList<QTextEdit::ExtraSelection> &selections);
void writeFile(bool *handled, const QString &fileName, const QString &contents);
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
void checkForElectricCharacter(bool *result, QChar c); void checkForElectricCharacter(bool *result, QChar c);
void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar); void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar);
void handleExCommand(const QString &cmd); void handleExCommand(bool *handled, const ExCommand &cmd);
void handleSetCommand(bool *handled, QString cmd);
void handleDelayedQuitAll(bool forced); void handleDelayedQuitAll(bool forced);
void handleDelayedQuit(bool forced, Core::IEditor *editor); void handleDelayedQuit(bool forced, Core::IEditor *editor);
@@ -523,11 +528,16 @@ private:
FakeVimExCommandsPage *m_fakeVimExCommandsPage; FakeVimExCommandsPage *m_fakeVimExCommandsPage;
QHash<Core::IEditor *, FakeVimHandler *> m_editorToHandler; QHash<Core::IEditor *, FakeVimHandler *> m_editorToHandler;
void triggerAction(const QString& code); void triggerAction(const QString &code);
void setActionChecked(const QString& code, bool check); void setActionChecked(const QString &code, bool check);
void readSettings(QSettings *settings); void readSettings(QSettings *settings);
void writeSettings(QSettings *settings); void writeSettings(QSettings *settings);
CommandMap &exCommandMap() { return m_exCommandMap; }
CommandMap &defaultExCommandMap() { return m_exCommandMap; }
CommandMap m_exCommandMap;
CommandMap m_defaultExCommandMap;
}; };
} // namespace Internal } // namespace Internal
@@ -538,23 +548,22 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
q = plugin; q = plugin;
m_fakeVimOptionsPage = 0; m_fakeVimOptionsPage = 0;
m_fakeVimExCommandsPage = 0; m_fakeVimExCommandsPage = 0;
defaultExCommandMap()[Constants::CMD_FILE_NEXT] =
s_defaultExCommandMap[Constants::CMD_FILE_NEXT] =
QRegExp("^n(ext)?!?( (.*))?$"); QRegExp("^n(ext)?!?( (.*))?$");
s_defaultExCommandMap[Constants::CMD_FILE_PREV] = defaultExCommandMap()[Constants::CMD_FILE_PREV] =
QRegExp("^(N(ext)?|prev(ious)?)!?( (.*))?$"); QRegExp("^(N(ext)?|prev(ious)?)!?( (.*))?$");
s_defaultExCommandMap[CppTools::Constants::SWITCH_HEADER_SOURCE] = defaultExCommandMap()[CppTools::Constants::SWITCH_HEADER_SOURCE] =
QRegExp("^A$"); QRegExp("^A$");
s_defaultExCommandMap[ProjectExplorer::Constants::BUILD] = defaultExCommandMap()["Coreplugin.OutputPane.previtem"] =
QRegExp("^make$");
s_defaultExCommandMap["Coreplugin.OutputPane.previtem"] =
QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$"); QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$");
s_defaultExCommandMap["Coreplugin.OutputPane.nextitem"] = defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] =
QRegExp("^cn(ext)?!?( (.*))?$"); QRegExp("^cn(ext)?!?( (.*))?$");
s_defaultExCommandMap[CppEditor::Constants::JUMP_TO_DEFINITION] = defaultExCommandMap()[CppEditor::Constants::JUMP_TO_DEFINITION] =
QRegExp("^tag?$"); QRegExp("^tag?$");
s_defaultExCommandMap[Core::Constants::GO_BACK] = defaultExCommandMap()[Core::Constants::GO_BACK] =
QRegExp("^pop?$"); QRegExp("^pop?$");
defaultExCommandMap()[QLatin1String("QtCreator.Locate")] =
QRegExp("^e$");
} }
FakeVimPluginPrivate::~FakeVimPluginPrivate() FakeVimPluginPrivate::~FakeVimPluginPrivate()
@@ -587,7 +596,7 @@ bool FakeVimPluginPrivate::initialize()
q->addObject(m_fakeVimOptionsPage); q->addObject(m_fakeVimOptionsPage);
theFakeVimSettings()->readSettings(Core::ICore::instance()->settings()); theFakeVimSettings()->readSettings(Core::ICore::instance()->settings());
m_fakeVimExCommandsPage = new FakeVimExCommandsPage; m_fakeVimExCommandsPage = new FakeVimExCommandsPage(this);
q->addObject(m_fakeVimExCommandsPage); q->addObject(m_fakeVimExCommandsPage);
readSettings(Core::ICore::instance()->settings()); readSettings(Core::ICore::instance()->settings());
@@ -607,8 +616,6 @@ bool FakeVimPluginPrivate::initialize()
connect(editorManager, SIGNAL(editorOpened(Core::IEditor*)), connect(editorManager, SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(editorOpened(Core::IEditor*))); this, SLOT(editorOpened(Core::IEditor*)));
connect(theFakeVimSetting(SettingsDialog), SIGNAL(triggered()),
this, SLOT(showSettingsDialog()));
connect(theFakeVimSetting(ConfigUseFakeVim), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigUseFakeVim), SIGNAL(valueChanged(QVariant)),
this, SLOT(setUseFakeVim(QVariant))); this, SLOT(setUseFakeVim(QVariant)));
connect(theFakeVimSetting(ConfigReadVimRc), SIGNAL(valueChanged(QVariant)), connect(theFakeVimSetting(ConfigReadVimRc), SIGNAL(valueChanged(QVariant)),
@@ -624,7 +631,7 @@ bool FakeVimPluginPrivate::initialize()
cmd->setAttribute(Command::CA_Hide); cmd->setAttribute(Command::CA_Hide);
connect(switchFilePrevAction, SIGNAL(triggered()), this, SLOT(switchFilePrev())); connect(switchFilePrevAction, SIGNAL(triggered()), this, SLOT(switchFilePrev()));
// Delayed operatiosn // Delayed operations.
connect(this, SIGNAL(delayedQuitRequested(bool,Core::IEditor*)), connect(this, SIGNAL(delayedQuitRequested(bool,Core::IEditor*)),
this, SLOT(handleDelayedQuit(bool,Core::IEditor*)), Qt::QueuedConnection); this, SLOT(handleDelayedQuit(bool,Core::IEditor*)), Qt::QueuedConnection);
connect(this, SIGNAL(delayedQuitAllRequested(bool)), connect(this, SIGNAL(delayedQuitAllRequested(bool)),
@@ -644,14 +651,14 @@ void FakeVimPluginPrivate::writeSettings(QSettings *settings)
settings->beginWriteArray(QLatin1String(exCommandMapGroup)); settings->beginWriteArray(QLatin1String(exCommandMapGroup));
int count = 0; int count = 0;
typedef QMap<QString, QRegExp>::const_iterator Iterator; typedef CommandMap::const_iterator Iterator;
const Iterator end = s_exCommandMap.constEnd(); const Iterator end = exCommandMap().constEnd();
for (Iterator it = s_exCommandMap.constBegin(); it != end; ++it) { for (Iterator it = exCommandMap().constBegin(); it != end; ++it) {
const QString &id = it.key(); const QString &id = it.key();
const QRegExp &re = it.value(); const QRegExp &re = it.value();
if ((s_defaultExCommandMap.contains(id) && s_defaultExCommandMap[id] != re) if ((defaultExCommandMap().contains(id) && defaultExCommandMap()[id] != re)
|| (!s_defaultExCommandMap.contains(id) && !re.pattern().isEmpty())) { || (!defaultExCommandMap().contains(id) && !re.pattern().isEmpty())) {
settings->setArrayIndex(count); settings->setArrayIndex(count);
settings->setValue(QLatin1String(idKey), id); settings->setValue(QLatin1String(idKey), id);
settings->setValue(QLatin1String(reKey), re.pattern()); settings->setValue(QLatin1String(reKey), re.pattern());
@@ -664,14 +671,14 @@ void FakeVimPluginPrivate::writeSettings(QSettings *settings)
void FakeVimPluginPrivate::readSettings(QSettings *settings) void FakeVimPluginPrivate::readSettings(QSettings *settings)
{ {
s_exCommandMap = s_defaultExCommandMap; exCommandMap() = defaultExCommandMap();
int size = settings->beginReadArray(QLatin1String(exCommandMapGroup)); int size = settings->beginReadArray(QLatin1String(exCommandMapGroup));
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i); settings->setArrayIndex(i);
const QString id = settings->value(QLatin1String(idKey)).toString(); const QString id = settings->value(QLatin1String(idKey)).toString();
const QString re = settings->value(QLatin1String(reKey)).toString(); const QString re = settings->value(QLatin1String(reKey)).toString();
s_exCommandMap[id] = QRegExp(re); exCommandMap()[id] = QRegExp(re);
} }
settings->endArray(); settings->endArray();
} }
@@ -702,18 +709,18 @@ void FakeVimPluginPrivate::showSettingsDialog()
QLatin1String(Constants::SETTINGS_ID)); QLatin1String(Constants::SETTINGS_ID));
} }
void FakeVimPluginPrivate::triggerAction(const QString& code) void FakeVimPluginPrivate::triggerAction(const QString &code)
{ {
Core::ActionManager *am = Core::ICore::instance()->actionManager(); Core::ActionManager *am = Core::ICore::instance()->actionManager();
QTC_ASSERT(am, return); QTC_ASSERT(am, return);
Core::Command *cmd = am->command(code); Core::Command *cmd = am->command(code);
QTC_ASSERT(cmd, return); QTC_ASSERT(cmd, qDebug() << "UNKNOW CODE: " << code; return);
QAction *action = cmd->action(); QAction *action = cmd->action();
QTC_ASSERT(action, return); QTC_ASSERT(action, return);
action->trigger(); action->trigger();
} }
void FakeVimPluginPrivate::setActionChecked(const QString& code, bool check) void FakeVimPluginPrivate::setActionChecked(const QString &code, bool check)
{ {
Core::ActionManager *am = Core::ICore::instance()->actionManager(); Core::ActionManager *am = Core::ICore::instance()->actionManager();
QTC_ASSERT(am, return); QTC_ASSERT(am, return);
@@ -826,8 +833,6 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
this, SLOT(showExtraInformation(QString))); this, SLOT(showExtraInformation(QString)));
connect(handler, SIGNAL(commandBufferChanged(QString)), connect(handler, SIGNAL(commandBufferChanged(QString)),
this, SLOT(showCommandBuffer(QString))); this, SLOT(showCommandBuffer(QString)));
connect(handler, SIGNAL(writeFileRequested(bool*,QString,QString)),
this, SLOT(writeFile(bool*,QString,QString)));
connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)),
this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>))); this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)), connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)),
@@ -845,10 +850,8 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
connect(handler, SIGNAL(findNextRequested(bool)), connect(handler, SIGNAL(findNextRequested(bool)),
this, SLOT(findNext(bool))); this, SLOT(findNext(bool)));
connect(handler, SIGNAL(handleExCommandRequested(QString)), connect(handler, SIGNAL(handleExCommandRequested(bool*,ExCommand)),
this, SLOT(handleExCommand(QString))); this, SLOT(handleExCommand(bool*,ExCommand)));
connect(handler, SIGNAL(handleSetCommandRequested(bool *,QString)),
this, SLOT(handleSetCommand(bool *,QString)));
handler->setCurrentFileName(editor->file()->fileName()); handler->setCurrentFileName(editor->file()->fileName());
handler->installEventFilter(); handler->installEventFilter();
@@ -909,33 +912,12 @@ void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c)
*result = bt->isElectricCharacter(c); *result = bt->isElectricCharacter(c);
} }
void FakeVimPluginPrivate::writeFile(bool *handled, void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
const QString &fileName, const QString &contents)
{ {
Q_UNUSED(contents)
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
if (!handler)
return;
Core::IEditor *editor = m_editorToHandler.key(handler);
if (editor && editor->file()->fileName() == fileName) {
// Handle that as a special case for nicer interaction with core
Core::IFile *file = editor->file();
Core::ICore::instance()->fileManager()->blockFileChange(file);
file->save(fileName);
Core::ICore::instance()->fileManager()->unblockFileChange(file);
*handled = true;
}
}
void FakeVimPluginPrivate::handleExCommand(const QString &cmd)
{
static QRegExp reWriteAll("^wa(ll)?!?$");
static QRegExp reQuit("^q!?$");
static QRegExp reQuitAll("^qa!?$");
using namespace Core; using namespace Core;
//qDebug() << "PLUGIN HANDLE: " << cmd.cmd;
*handled = false;
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()); FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
if (!handler) if (!handler)
@@ -944,7 +926,27 @@ void FakeVimPluginPrivate::handleExCommand(const QString &cmd)
EditorManager *editorManager = EditorManager::instance(); EditorManager *editorManager = EditorManager::instance();
QTC_ASSERT(editorManager, return); QTC_ASSERT(editorManager, return);
if (reWriteAll.indexIn(cmd) != -1) { *handled = true;
if (cmd.cmd == "w" || cmd.cmd == "write") {
Core::IEditor *editor = m_editorToHandler.key(handler);
const QString fileName = handler->currentFileName();
if (editor && editor->file()->fileName() == fileName) {
// Handle that as a special case for nicer interaction with core
Core::IFile *file = editor->file();
Core::ICore::instance()->fileManager()->blockFileChange(file);
file->save(fileName);
Core::ICore::instance()->fileManager()->unblockFileChange(file);
// Check result by reading back.
QFile file3(fileName);
file3.open(QIODevice::ReadOnly);
QByteArray ba = file3.readAll();
handler->showBlackMessage(FakeVimHandler::tr("\"%1\" %2 %3L, %4C written")
.arg(fileName).arg(" ")
.arg(ba.count('\n')).arg(ba.size()));
} else {
handler->showRedMessage(tr("File not saved"));
}
} else if (cmd.cmd == "wa" || cmd.cmd == "wall") {
// :wa // :wa
FileManager *fm = ICore::instance()->fileManager(); FileManager *fm = ICore::instance()->fileManager();
QList<IFile *> toSave = fm->modifiedFiles(); QList<IFile *> toSave = fm->modifiedFiles();
@@ -953,43 +955,47 @@ void FakeVimPluginPrivate::handleExCommand(const QString &cmd)
handler->showBlackMessage(tr("Saving succeeded")); handler->showBlackMessage(tr("Saving succeeded"));
else else
handler->showRedMessage(tr("%n files not saved", 0, failed.size())); handler->showRedMessage(tr("%n files not saved", 0, failed.size()));
} else if (reQuit.indexIn(cmd) != -1) { } else if (cmd.cmd == "q" || cmd.cmd == "quit") {
// :q // :q[uit]
bool forced = cmd.contains(QChar('!')); emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
emit delayedQuitRequested(forced, m_editorToHandler.key(handler)); } else if (cmd.cmd == "qa" || cmd.cmd == "qall") {
} else if (reQuitAll.indexIn(cmd) != -1) {
// :qa // :qa
bool forced = cmd.contains(QChar('!')); emit delayedQuitAllRequested(cmd.hasBang);
emit delayedQuitAllRequested(forced); } else if (cmd.cmd == "sp" || cmd.cmd == "split") {
// :sp[lit]
triggerAction(Core::Constants::SPLIT);
} else if (cmd.cmd == "vs" || cmd.cmd == "vsplit") {
// :vs[plit]
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
} else if (cmd.cmd == "mak" || cmd.cmd == "make") {
// :mak[e][!] [arguments]
triggerAction(ProjectExplorer::Constants::BUILD);
} else if (cmd.cmd == "se" || cmd.cmd == "set") {
if (cmd.args.isEmpty()) {
// :set
showSettingsDialog();
} else if (cmd.args == "ic" || cmd.args == "ignorecase") {
// :set noic
setActionChecked(Find::Constants::CASE_SENSITIVE, false);
*handled = false; // Let the handler see it as well.
} else if (cmd.args == "noic" || cmd.args == "noignorecase") {
// :set noic
setActionChecked(Find::Constants::CASE_SENSITIVE, true);
*handled = false; // Let the handler see it as well.
}
} else { } else {
typedef QMap<QString, QRegExp>::const_iterator Iterator; // Check whether one of the configure commands matches.
const Iterator end = s_exCommandMap.constEnd(); typedef CommandMap::const_iterator Iterator;
for (Iterator it = s_exCommandMap.constBegin(); it != end; ++it) { const Iterator end = exCommandMap().constEnd();
for (Iterator it = exCommandMap().constBegin(); it != end; ++it) {
const QString &id = it.key(); const QString &id = it.key();
const QRegExp &re = it.value(); const QRegExp &re = it.value();
if (!re.pattern().isEmpty() && re.indexIn(cmd.cmd) != -1) {
if (!re.pattern().isEmpty() && re.indexIn(cmd) != -1) {
triggerAction(id); triggerAction(id);
return; return;
} }
} }
*handled = false;
handler->showRedMessage(tr("Not an editor command: %1").arg(cmd));
}
}
void FakeVimPluginPrivate::handleSetCommand(bool *handled, QString cmd)
{
*handled = false;
bool value = true;
if (cmd.startsWith("no")) {
value = false;
cmd = cmd.mid(2);
}
if (cmd == "ic" || cmd == "ignorecase") {
setActionChecked(Find::Constants::CASE_SENSITIVE, value);
*handled = true;
} }
} }
@@ -1064,8 +1070,7 @@ void FakeVimPluginPrivate::indentRegion(int *amount, int beginLine, int endLine,
const QTextDocument *doc = bt->document(); const QTextDocument *doc = bt->document();
const TextEditor::TextBlockIterator docStart(doc->begin()); const TextEditor::TextBlockIterator docStart(doc->begin());
QTextBlock cur = doc->findBlockByNumber(beginLine); QTextBlock cur = doc->findBlockByNumber(beginLine);
for(int i = beginLine; i<= endLine; ++i) for (int i = beginLine; i <= endLine; ++i) {
{
if (typedChar == 0 && cur.text().simplified().isEmpty()) { if (typedChar == 0 && cur.text().simplified().isEmpty()) {
// clear empty lines // clear empty lines
*amount = 0; *amount = 0;
@@ -1130,6 +1135,17 @@ void FakeVimPluginPrivate::switchFilePrev()
switchFile(true); switchFile(true);
} }
CommandMap &FakeVimExCommandsPage::exCommandMap()
{
return m_q->exCommandMap();
}
CommandMap &FakeVimExCommandsPage::defaultExCommandMap()
{
return m_q->defaultExCommandMap();
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
// FakeVimPlugin // FakeVimPlugin