Commit 8a2aa96f authored by hjk's avatar hjk
Browse files

fakevim: reduce line noise

parent 816f60f0
......@@ -119,6 +119,7 @@ namespace FakeVim {
namespace Internal {
typedef QMap<QString, QRegExp> CommandMap;
typedef QLatin1String _;
class FakeVimOptionPage : public Core::IOptionsPage
{
......@@ -128,11 +129,12 @@ public:
FakeVimOptionPage() {}
// IOptionsPage
QString id() const { return QLatin1String(Constants::SETTINGS_ID); }
QString id() const { return _(Constants::SETTINGS_ID); }
QString displayName() const { return tr("General"); }
QString category() const { return QLatin1String(Constants::SETTINGS_CATEGORY); }
QString category() const { return _(Constants::SETTINGS_CATEGORY); }
QString displayCategory() const { return tr("FakeVim"); }
QIcon categoryIcon() const { return QIcon(QLatin1String(Constants::SETTINGS_CATEGORY_FAKEVIM_ICON)); }
QIcon categoryIcon() const
{ return QIcon(_(Constants::SETTINGS_CATEGORY_FAKEVIM_ICON)); }
QWidget *createPage(QWidget *parent);
void apply() { m_group.apply(ICore::instance()->settings()); }
......@@ -238,7 +240,7 @@ void FakeVimOptionPage::setQtStyle()
m_ui.checkBoxAutoIndent->setChecked(true);
m_ui.checkBoxSmartIndent->setChecked(true);
m_ui.checkBoxIncSearch->setChecked(true);
m_ui.lineEditBackspace->setText(QLatin1String("indent,eol,start"));
m_ui.lineEditBackspace->setText(_("indent,eol,start"));
}
void FakeVimOptionPage::setPlainStyle()
......@@ -275,7 +277,7 @@ struct CommandItem
QTreeWidgetItem *m_item;
};
Q_DECLARE_METATYPE(CommandItem*);
Q_DECLARE_METATYPE(CommandItem *);
namespace FakeVim {
namespace Internal {
......@@ -288,9 +290,9 @@ public:
FakeVimExCommandsPage(FakeVimPluginPrivate *q) : m_q(q) {}
// IOptionsPage
QString id() const { return QLatin1String(Constants::SETTINGS_EX_CMDS_ID); }
QString id() const { return _(Constants::SETTINGS_EX_CMDS_ID); }
QString displayName() const { return tr("Ex Command Mapping"); }
QString category() const { return QLatin1String(Constants::SETTINGS_CATEGORY); }
QString category() const { return _(Constants::SETTINGS_CATEGORY); }
QString displayCategory() const { return tr("FakeVim"); }
QIcon categoryIcon() const { return QIcon(); } // TODO: Icon for FakeVim
......@@ -525,6 +527,8 @@ private:
FakeVimOptionPage *m_fakeVimOptionsPage;
FakeVimExCommandsPage *m_fakeVimExCommandsPage;
QHash<Core::IEditor *, FakeVimHandler *> m_editorToHandler;
QPointer<EditorManager> m_editorManager;
EditorManager *editorManager() const { return m_editorManager; }
void triggerAction(const QString &code);
void setActionChecked(const QString &code, bool check);
......@@ -560,7 +564,7 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
QRegExp("^tag?$");
defaultExCommandMap()[Core::Constants::GO_BACK] =
QRegExp("^pop?$");
defaultExCommandMap()[QLatin1String("QtCreator.Locate")] =
defaultExCommandMap()[_("QtCreator.Locate")] =
QRegExp("^e$");
}
......@@ -584,6 +588,7 @@ void FakeVimPluginPrivate::aboutToShutdown()
bool FakeVimPluginPrivate::initialize()
{
m_editorManager = Core::ICore::instance()->editorManager();
Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
QTC_ASSERT(actionManager, return false);
......@@ -607,10 +612,9 @@ bool FakeVimPluginPrivate::initialize()
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_EDITOR);
// EditorManager
QObject *editorManager = Core::ICore::instance()->editorManager();
connect(editorManager, SIGNAL(editorAboutToClose(Core::IEditor*)),
connect(editorManager(), SIGNAL(editorAboutToClose(Core::IEditor*)),
this, SLOT(editorAboutToClose(Core::IEditor*)));
connect(editorManager, SIGNAL(editorOpened(Core::IEditor*)),
connect(editorManager(), SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(editorOpened(Core::IEditor*)));
connect(theFakeVimSetting(ConfigUseFakeVim), SIGNAL(valueChanged(QVariant)),
......@@ -645,7 +649,7 @@ static const char *idKey = "Command";
void FakeVimPluginPrivate::writeSettings(QSettings *settings)
{
settings->beginWriteArray(QLatin1String(exCommandMapGroup));
settings->beginWriteArray(_(exCommandMapGroup));
int count = 0;
typedef CommandMap::const_iterator Iterator;
......@@ -657,8 +661,8 @@ void FakeVimPluginPrivate::writeSettings(QSettings *settings)
if ((defaultExCommandMap().contains(id) && defaultExCommandMap()[id] != re)
|| (!defaultExCommandMap().contains(id) && !re.pattern().isEmpty())) {
settings->setArrayIndex(count);
settings->setValue(QLatin1String(idKey), id);
settings->setValue(QLatin1String(reKey), re.pattern());
settings->setValue(_(idKey), id);
settings->setValue(_(reKey), re.pattern());
++count;
}
}
......@@ -670,11 +674,11 @@ void FakeVimPluginPrivate::readSettings(QSettings *settings)
{
exCommandMap() = defaultExCommandMap();
int size = settings->beginReadArray(QLatin1String(exCommandMapGroup));
int size = settings->beginReadArray(_(exCommandMapGroup));
for (int i = 0; i < size; ++i) {
settings->setArrayIndex(i);
const QString id = settings->value(QLatin1String(idKey)).toString();
const QString re = settings->value(QLatin1String(reKey)).toString();
const QString id = settings->value(_(idKey)).toString();
const QString re = settings->value(_(reKey)).toString();
exCommandMap()[id] = QRegExp(re);
}
settings->endArray();
......@@ -702,8 +706,8 @@ void FakeVimPluginPrivate::maybeReadVimRc()
void FakeVimPluginPrivate::showSettingsDialog()
{
Core::ICore::instance()->showOptionsDialog(
QLatin1String(Constants::SETTINGS_CATEGORY),
QLatin1String(Constants::SETTINGS_ID));
_(Constants::SETTINGS_CATEGORY),
_(Constants::SETTINGS_ID));
}
void FakeVimPluginPrivate::triggerAction(const QString &code)
......@@ -873,15 +877,15 @@ void FakeVimPluginPrivate::setUseFakeVim(const QVariant &value)
if (Find::FindPlugin::instance())
Find::FindPlugin::instance()->setUseFakeVim(on);
if (on) {
Core::EditorManager::instance()->showEditorStatusBar(
QLatin1String(Constants::MINI_BUFFER),
editorManager()->showEditorStatusBar(
_(Constants::MINI_BUFFER),
"vi emulation mode. Type :q to leave. Use , Ctrl-R to trigger run.",
tr("Quit FakeVim"), this, SLOT(quitFakeVim()));
foreach (Core::IEditor *editor, m_editorToHandler.keys())
m_editorToHandler[editor]->setupWidget();
} else {
Core::EditorManager::instance()->hideEditorStatusBar(
QLatin1String(Constants::MINI_BUFFER));
editorManager()->hideEditorStatusBar(
_(Constants::MINI_BUFFER));
TextEditor::TabSettings ts =
TextEditor::TextEditorSettings::instance()->tabSettings();
foreach (Core::IEditor *editor, m_editorToHandler.keys())
......@@ -920,8 +924,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
if (!handler)
return;
EditorManager *editorManager = EditorManager::instance();
QTC_ASSERT(editorManager, return);
QTC_ASSERT(editorManager(), return);
*handled = true;
if (cmd.cmd == "w" || cmd.cmd == "write") {
......@@ -1102,8 +1105,8 @@ void FakeVimPluginPrivate::quitFakeVim()
void FakeVimPluginPrivate::showCommandBuffer(const QString &contents)
{
//qDebug() << "SHOW COMMAND BUFFER" << contents;
Core::EditorManager::instance()->showEditorStatusBar(
QLatin1String(Constants::MINI_BUFFER), contents,
editorManager()->showEditorStatusBar(
_(Constants::MINI_BUFFER), contents,
tr("Quit FakeVim"), this, SLOT(quitFakeVim()));
}
......@@ -1124,12 +1127,11 @@ void FakeVimPluginPrivate::changeSelection
void FakeVimPluginPrivate::switchFile(bool previous)
{
Core::EditorManager *em = Core::EditorManager::instance();
Core::OpenEditorsModel *model = em->openedEditorsModel();
Core::OpenEditorsModel *model = editorManager()->openedEditorsModel();
IEditor *cur = Core::EditorManager::instance()->currentEditor();
int curIdx = model->indexOf(cur).row();
int nIdx = (curIdx + model->rowCount() + (previous ? -1 : 1)) % model->rowCount();
em->activateEditor(model->index(nIdx, 0), 0);
editorManager()->activateEditor(model->index(nIdx, 0), 0);
}
void FakeVimPluginPrivate::switchFileNext()
......
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