Commit 03228170 authored by hjk's avatar hjk

fakevim: de-noise

Change-Id: I6b47304f43138d6944a55b2a2047c4832ced16d9
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 2b0fb76f
...@@ -96,28 +96,19 @@ ...@@ -96,28 +96,19 @@
#include <QTextEdit> #include <QTextEdit>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
using namespace FakeVim::Internal;
using namespace TextEditor; using namespace TextEditor;
using namespace Core; using namespace Core;
namespace FakeVim { namespace FakeVim {
namespace Constants { namespace Internal {
const char INSTALL_HANDLER[] = "TextEditor.FakeVimHandler"; const char INSTALL_HANDLER[] = "TextEditor.FakeVimHandler";
const char MINI_BUFFER[] = "TextEditor.FakeVimMiniBuffer";
const char SETTINGS_CATEGORY[] = "D.FakeVim"; const char SETTINGS_CATEGORY[] = "D.FakeVim";
const char SETTINGS_CATEGORY_FAKEVIM_ICON[] = ":/core/images/category_fakevim.png"; const char SETTINGS_CATEGORY_FAKEVIM_ICON[] = ":/core/images/category_fakevim.png";
const char SETTINGS_ID[] = "A.General"; const char SETTINGS_ID[] = "A.General";
const char SETTINGS_EX_CMDS_ID[] = "B.ExCommands"; const char SETTINGS_EX_CMDS_ID[] = "B.ExCommands";
const char SETTINGS_USER_CMDS_ID[] = "C.UserCommands"; const char SETTINGS_USER_CMDS_ID[] = "C.UserCommands";
} // namespace Constants
} // namespace FakeVim
namespace FakeVim {
namespace Internal {
class MiniBuffer : public QLabel class MiniBuffer : public QLabel
{ {
Q_OBJECT Q_OBJECT
...@@ -173,18 +164,18 @@ typedef QMap<QString, QRegExp> ExCommandMap; ...@@ -173,18 +164,18 @@ typedef QMap<QString, QRegExp> ExCommandMap;
typedef QMap<int, QString> UserCommandMap; typedef QMap<int, QString> UserCommandMap;
typedef QLatin1String _; typedef QLatin1String _;
class FakeVimOptionPage : public Core::IOptionsPage class FakeVimOptionPage : public IOptionsPage
{ {
Q_OBJECT Q_OBJECT
public: public:
FakeVimOptionPage() FakeVimOptionPage()
{ {
setId(_(Constants::SETTINGS_ID)); setId(_(SETTINGS_ID));
setDisplayName(tr("General")); setDisplayName(tr("General"));
setCategory(_(Constants::SETTINGS_CATEGORY)); setCategory(_(SETTINGS_CATEGORY));
setDisplayCategory(tr("FakeVim")); setDisplayCategory(tr("FakeVim"));
setCategoryIcon(_(Constants::SETTINGS_CATEGORY_FAKEVIM_ICON)); setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
} }
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
...@@ -330,7 +321,7 @@ bool FakeVimOptionPage::matches(const QString &s) const ...@@ -330,7 +321,7 @@ bool FakeVimOptionPage::matches(const QString &s) const
enum { CommandRole = Qt::UserRole }; enum { CommandRole = Qt::UserRole };
class FakeVimExCommandsPage : public Core::CommandMappings class FakeVimExCommandsPage : public CommandMappings
{ {
Q_OBJECT Q_OBJECT
...@@ -338,11 +329,11 @@ public: ...@@ -338,11 +329,11 @@ public:
FakeVimExCommandsPage(FakeVimPluginPrivate *q) FakeVimExCommandsPage(FakeVimPluginPrivate *q)
: m_q(q) : m_q(q)
{ {
setId(_(Constants::SETTINGS_EX_CMDS_ID)); setId(_(SETTINGS_EX_CMDS_ID));
setDisplayName(tr("Ex Command Mapping")); setDisplayName(tr("Ex Command Mapping"));
setCategory(_(Constants::SETTINGS_CATEGORY)); setCategory(_(SETTINGS_CATEGORY));
setDisplayCategory(tr("FakeVim")); setDisplayCategory(tr("FakeVim"));
setCategoryIcon(_(Constants::SETTINGS_CATEGORY_FAKEVIM_ICON)); setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
} }
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
...@@ -376,7 +367,7 @@ void FakeVimExCommandsPage::initialize() ...@@ -376,7 +367,7 @@ void FakeVimExCommandsPage::initialize()
{ {
QMap<QString, QTreeWidgetItem *> sections; QMap<QString, QTreeWidgetItem *> sections;
foreach (Command *c, Core::ActionManager::commands()) { foreach (Command *c, ActionManager::commands()) {
if (c->action() && c->action()->isSeparator()) if (c->action() && c->action()->isSeparator())
continue; continue;
...@@ -552,7 +543,7 @@ public: ...@@ -552,7 +543,7 @@ public:
} }
}; };
class FakeVimUserCommandsPage : public Core::IOptionsPage class FakeVimUserCommandsPage : public IOptionsPage
{ {
Q_OBJECT Q_OBJECT
...@@ -560,11 +551,11 @@ public: ...@@ -560,11 +551,11 @@ public:
FakeVimUserCommandsPage(FakeVimPluginPrivate *q) FakeVimUserCommandsPage(FakeVimPluginPrivate *q)
: m_q(q) : m_q(q)
{ {
setId(_(Constants::SETTINGS_USER_CMDS_ID)); setId(_(SETTINGS_USER_CMDS_ID));
setDisplayName(tr("User Command Mapping")); setDisplayName(tr("User Command Mapping"));
setCategory(_(Constants::SETTINGS_CATEGORY)); setCategory(_(SETTINGS_CATEGORY));
setDisplayCategory(tr("FakeVim")); setDisplayCategory(tr("FakeVim"));
setCategoryIcon(_(Constants::SETTINGS_CATEGORY_FAKEVIM_ICON)); setCategoryIcon(_(SETTINGS_CATEGORY_FAKEVIM_ICON));
} }
void apply(); void apply();
...@@ -610,15 +601,15 @@ void FakeVimUserCommandsPage::apply() ...@@ -610,15 +601,15 @@ void FakeVimUserCommandsPage::apply()
// //
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
class FakeVimCompletionAssistProvider : public TextEditor::CompletionAssistProvider class FakeVimCompletionAssistProvider : public CompletionAssistProvider
{ {
public: public:
bool supportsEditor(const Core::Id &) const bool supportsEditor(const Id &) const
{ {
return false; return false;
} }
TextEditor::IAssistProcessor *createProcessor() const; IAssistProcessor *createProcessor() const;
void setActive(const QString &needle, bool forward, FakeVimHandler *handler) void setActive(const QString &needle, bool forward, FakeVimHandler *handler)
{ {
...@@ -708,11 +699,11 @@ public: ...@@ -708,11 +699,11 @@ public:
class FakeVimCompletionAssistProcessor : public IAssistProcessor class FakeVimCompletionAssistProcessor : public IAssistProcessor
{ {
public: public:
FakeVimCompletionAssistProcessor(const TextEditor::IAssistProvider *provider) FakeVimCompletionAssistProcessor(const IAssistProvider *provider)
: m_provider(static_cast<const FakeVimCompletionAssistProvider *>(provider)) : m_provider(static_cast<const FakeVimCompletionAssistProvider *>(provider))
{} {}
virtual TextEditor::IAssistProposal *perform(const IAssistInterface *interface) IAssistProposal *perform(const IAssistInterface *interface)
{ {
const QString &needle = m_provider->needle(); const QString &needle = m_provider->needle();
...@@ -825,10 +816,10 @@ private: ...@@ -825,10 +816,10 @@ private:
FakeVimOptionPage *m_fakeVimOptionsPage; FakeVimOptionPage *m_fakeVimOptionsPage;
FakeVimExCommandsPage *m_fakeVimExCommandsPage; FakeVimExCommandsPage *m_fakeVimExCommandsPage;
FakeVimUserCommandsPage *m_fakeVimUserCommandsPage; FakeVimUserCommandsPage *m_fakeVimUserCommandsPage;
QHash<Core::IEditor *, FakeVimHandler *> m_editorToHandler; QHash<IEditor *, FakeVimHandler *> m_editorToHandler;
void triggerAction(const Core::Id &id); void triggerAction(const Id &id);
void setActionChecked(const Core::Id &id, bool check); void setActionChecked(const Id &id, bool check);
typedef int (*DistFunction)(const QRect &cursor, const QRect &other); typedef int (*DistFunction)(const QRect &cursor, const QRect &other);
void moveSomewhere(DistFunction f); void moveSomewhere(DistFunction f);
...@@ -843,7 +834,7 @@ private: ...@@ -843,7 +834,7 @@ private:
UserCommandMap m_userCommandMap; UserCommandMap m_userCommandMap;
UserCommandMap m_defaultUserCommandMap; UserCommandMap m_defaultUserCommandMap;
Core::StatusBarWidget *m_statusBar; StatusBarWidget *m_statusBar;
// @TODO: Delete // @TODO: Delete
//WordCompletion *m_wordCompletion; //WordCompletion *m_wordCompletion;
FakeVimCompletionAssistProvider *m_wordProvider; FakeVimCompletionAssistProvider *m_wordProvider;
...@@ -960,13 +951,13 @@ bool FakeVimPluginPrivate::initialize() ...@@ -960,13 +951,13 @@ bool FakeVimPluginPrivate::initialize()
readSettings(); readSettings();
Core::Command *cmd = 0; Command *cmd = 0;
cmd = Core::ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim), cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim),
Constants::INSTALL_HANDLER, globalcontext, true); INSTALL_HANDLER, globalcontext, true);
cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+V,Meta+V") : tr("Alt+V,Alt+V"))); cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Meta+V,Meta+V") : tr("Alt+V,Alt+V")));
ActionContainer *advancedMenu = ActionContainer *advancedMenu =
Core::ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED); ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_EDITOR); advancedMenu->addAction(cmd, Core::Constants::G_EDIT_EDITOR);
for (int i = 1; i < 10; ++i) { for (int i = 1; i < 10; ++i) {
...@@ -974,8 +965,8 @@ bool FakeVimPluginPrivate::initialize() ...@@ -974,8 +965,8 @@ bool FakeVimPluginPrivate::initialize()
act->setText(tr("Execute User Action #%1").arg(i)); act->setText(tr("Execute User Action #%1").arg(i));
act->setData(i); act->setData(i);
QString id = QString("FakeVim.UserAction%1").arg(i); QString id = QString("FakeVim.UserAction%1").arg(i);
cmd = Core::ActionManager::registerAction(act, Core::Id(id), globalcontext); cmd = ActionManager::registerAction(act, Id(id), globalcontext);
cmd->setDefaultKeySequence(QKeySequence((Core::UseMacShortcuts ? tr("Meta+V,%1") : tr("Alt+V,%1")).arg(i))); cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? tr("Meta+V,%1") : tr("Alt+V,%1")).arg(i)));
connect(act, SIGNAL(triggered()), SLOT(userActionTriggered())); connect(act, SIGNAL(triggered()), SLOT(userActionTriggered()));
} }
...@@ -1018,11 +1009,12 @@ void FakeVimPluginPrivate::userActionTriggered() ...@@ -1018,11 +1009,12 @@ void FakeVimPluginPrivate::userActionTriggered()
handler->handleInput(cmd); handler->handleInput(cmd);
} }
static const char exCommandMapGroup[] = "FakeVimExCommand";
static const char userCommandMapGroup[] = "FakeVimUserCommand"; const char exCommandMapGroup[] = "FakeVimExCommand";
static const char reKey[] = "RegEx"; const char userCommandMapGroup[] = "FakeVimUserCommand";
static const char cmdKey[] = "Cmd"; const char reKey[] = "RegEx";
static const char idKey[] = "Command"; const char cmdKey[] = "Cmd";
const char idKey[] = "Command";
void FakeVimPluginPrivate::writeSettings() void FakeVimPluginPrivate::writeSettings()
{ {
...@@ -1120,14 +1112,12 @@ void FakeVimPluginPrivate::maybeReadVimRc() ...@@ -1120,14 +1112,12 @@ void FakeVimPluginPrivate::maybeReadVimRc()
void FakeVimPluginPrivate::showSettingsDialog() void FakeVimPluginPrivate::showSettingsDialog()
{ {
ICore::showOptionsDialog( ICore::showOptionsDialog(_(SETTINGS_CATEGORY), _(SETTINGS_ID));
_(Constants::SETTINGS_CATEGORY),
_(Constants::SETTINGS_ID));
} }
void FakeVimPluginPrivate::triggerAction(const Id &id) void FakeVimPluginPrivate::triggerAction(const Id &id)
{ {
Core::Command *cmd = Core::ActionManager::command(id); Core::Command *cmd = ActionManager::command(id);
QTC_ASSERT(cmd, qDebug() << "UNKNOWN CODE: " << id.name(); return); QTC_ASSERT(cmd, qDebug() << "UNKNOWN CODE: " << id.name(); return);
QAction *action = cmd->action(); QAction *action = cmd->action();
QTC_ASSERT(action, return); QTC_ASSERT(action, return);
...@@ -1136,7 +1126,7 @@ void FakeVimPluginPrivate::triggerAction(const Id &id) ...@@ -1136,7 +1126,7 @@ void FakeVimPluginPrivate::triggerAction(const Id &id)
void FakeVimPluginPrivate::setActionChecked(const Id &id, bool check) void FakeVimPluginPrivate::setActionChecked(const Id &id, bool check)
{ {
Core::Command *cmd = Core::ActionManager::command(id); Core::Command *cmd = ActionManager::command(id);
QTC_ASSERT(cmd, return); QTC_ASSERT(cmd, return);
QAction *action = cmd->action(); QAction *action = cmd->action();
QTC_ASSERT(action, return); QTC_ASSERT(action, return);
...@@ -1315,7 +1305,7 @@ public: ...@@ -1315,7 +1305,7 @@ public:
} }
}; };
void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor) void FakeVimPluginPrivate::editorOpened(IEditor *editor)
{ {
if (!editor) if (!editor)
return; return;
...@@ -1380,7 +1370,7 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor) ...@@ -1380,7 +1370,7 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
} }
} }
void FakeVimPluginPrivate::editorAboutToClose(Core::IEditor *editor) void FakeVimPluginPrivate::editorAboutToClose(IEditor *editor)
{ {
//qDebug() << "CLOSING: " << editor << editor->widget(); //qDebug() << "CLOSING: " << editor << editor->widget();
m_editorToHandler.remove(editor); m_editorToHandler.remove(editor);
...@@ -1399,18 +1389,18 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on) ...@@ -1399,18 +1389,18 @@ void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
{ {
if (on) { if (on) {
//ICore *core = ICore::instance(); //ICore *core = ICore::instance();
//core->updateAdditionalContexts(Core::Context(FAKEVIM_CONTEXT), //core->updateAdditionalContexts(Context(FAKEVIM_CONTEXT),
// Core::Context()); // Context());
foreach (Core::IEditor *editor, m_editorToHandler.keys()) foreach (IEditor *editor, m_editorToHandler.keys())
m_editorToHandler[editor]->setupWidget(); m_editorToHandler[editor]->setupWidget();
} else { } else {
//ICore *core = ICore::instance(); //ICore *core = ICore::instance();
//core->updateAdditionalContexts(Core::Context(), //core->updateAdditionalContexts(Context(),
// Core::Context(FAKEVIM_CONTEXT)); // Context(FAKEVIM_CONTEXT));
showCommandBuffer(QString(), -1); showCommandBuffer(QString(), -1);
foreach (Core::IEditor *editor, m_editorToHandler.keys()) { foreach (IEditor *editor, m_editorToHandler.keys()) {
if (TextEditor::BaseTextEditorWidget *textEditor = if (BaseTextEditorWidget *textEditor =
qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget())) { qobject_cast<BaseTextEditorWidget *>(editor->widget())) {
m_editorToHandler[editor]->restoreWidget(textEditor->tabSettings().m_tabSize); m_editorToHandler[editor]->restoreWidget(textEditor->tabSettings().m_tabSize);
} }
} }
...@@ -1475,7 +1465,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) ...@@ -1475,7 +1465,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
*handled = true; *handled = true;
if (cmd.matches("w", "write") || cmd.cmd == "wq") { if (cmd.matches("w", "write") || cmd.cmd == "wq") {
// :w[rite] // :w[rite]
Core::IEditor *editor = m_editorToHandler.key(handler); IEditor *editor = m_editorToHandler.key(handler);
const QString fileName = handler->currentFileName(); const QString fileName = handler->currentFileName();
if (editor && editor->document()->fileName() == fileName) { if (editor && editor->document()->fileName() == fileName) {
// Handle that as a special case for nicer interaction with core // Handle that as a special case for nicer interaction with core
...@@ -1566,7 +1556,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) ...@@ -1566,7 +1556,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
} }
} }
void FakeVimPluginPrivate::handleDelayedQuit(bool forced, Core::IEditor *editor) void FakeVimPluginPrivate::handleDelayedQuit(bool forced, IEditor *editor)
{ {
// This tries to simulate vim behaviour. But the models of vim and // This tries to simulate vim behaviour. But the models of vim and
// Qt Creator core do not match well... // Qt Creator core do not match well...
...@@ -1574,7 +1564,7 @@ void FakeVimPluginPrivate::handleDelayedQuit(bool forced, Core::IEditor *editor) ...@@ -1574,7 +1564,7 @@ void FakeVimPluginPrivate::handleDelayedQuit(bool forced, Core::IEditor *editor)
if (editorManager->hasSplitter()) { if (editorManager->hasSplitter()) {
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT); triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
} else { } else {
QList<Core::IEditor *> editors; QList<IEditor *> editors;
editors.append(editor); editors.append(editor);
editorManager->closeEditors(editors, !forced); editorManager->closeEditors(editors, !forced);
} }
...@@ -1697,7 +1687,7 @@ int FakeVimPluginPrivate::currentFile() const ...@@ -1697,7 +1687,7 @@ int FakeVimPluginPrivate::currentFile() const
void FakeVimPluginPrivate::switchToFile(int n) void FakeVimPluginPrivate::switchToFile(int n)
{ {
EditorManager *editorManager = ICore::editorManager(); EditorManager *editorManager = ICore::editorManager();
Core::OpenEditorsModel *model = editorManager->openedEditorsModel(); OpenEditorsModel *model = editorManager->openedEditorsModel();
int size = model->rowCount(); int size = model->rowCount();
QTC_ASSERT(size, return); QTC_ASSERT(size, return);
n = n % size; n = n % size;
...@@ -1756,7 +1746,7 @@ ExtensionSystem::IPlugin::ShutdownFlag FakeVimPlugin::aboutToShutdown() ...@@ -1756,7 +1746,7 @@ ExtensionSystem::IPlugin::ShutdownFlag FakeVimPlugin::aboutToShutdown()
void FakeVimPlugin::extensionsInitialized() void FakeVimPlugin::extensionsInitialized()
{ {
d->m_statusBar = new Core::StatusBarWidget; d->m_statusBar = new StatusBarWidget;
d->m_statusBar->setWidget(new MiniBuffer); d->m_statusBar->setWidget(new MiniBuffer);
d->m_statusBar->setPosition(StatusBarWidget::Last); d->m_statusBar->setPosition(StatusBarWidget::Last);
addAutoReleasedObject(d->m_statusBar); addAutoReleasedObject(d->m_statusBar);
...@@ -1767,4 +1757,4 @@ void FakeVimPlugin::extensionsInitialized() ...@@ -1767,4 +1757,4 @@ void FakeVimPlugin::extensionsInitialized()
#include "fakevimplugin.moc" #include "fakevimplugin.moc"
Q_EXPORT_PLUGIN(FakeVimPlugin) Q_EXPORT_PLUGIN(FakeVim::Internal::FakeVimPlugin)
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