fakevim: listen to editor opening and closing

This commit is contained in:
hjk
2009-01-09 17:57:48 +01:00
parent fb93fdaea2
commit fb8e1bb205
3 changed files with 38 additions and 13 deletions

View File

@@ -291,8 +291,12 @@ bool FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
{ {
int key = ev->key(); int key = ev->key();
// FIXME
if (m_mode == PassingMode && key != Qt::Key_Control && key != Qt::Key_Shift) { if (m_mode == PassingMode && key != Qt::Key_Control && key != Qt::Key_Shift) {
enterCommandMode(); if (key == ',') { // use ',,' to leave, too.
quit();
return true;
}
return false; return false;
} }
@@ -1109,6 +1113,8 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
info += key + ": " + m_config.value(key) + "\n"; info += key + ": " + m_config.value(key) + "\n";
emit q->extraInformationChanged(info); emit q->extraInformationChanged(info);
} }
enterCommandMode();
updateMiniBuffer();
} else { } else {
showRedMessage("E492: Not an editor command: " + cmd0); showRedMessage("E492: Not an editor command: " + cmd0);
} }

View File

@@ -136,6 +136,14 @@ bool FakeVimPlugin::initialize(const QStringList &arguments, QString *error_mess
connect(m_installHandlerAction, SIGNAL(triggered()), connect(m_installHandlerAction, SIGNAL(triggered()),
this, SLOT(installHandler())); this, SLOT(installHandler()));
// EditorManager
QObject *editorManager = m_core->editorManager();
connect(editorManager, SIGNAL(editorAboutToClose(Core::IEditor*)),
this, SLOT(editorAboutToClose(Core::IEditor*)));
connect(editorManager, SIGNAL(editorOpened(Core::IEditor*)),
this, SLOT(editorOpened(Core::IEditor*)));
return true; return true;
} }
@@ -145,14 +153,12 @@ void FakeVimPlugin::extensionsInitialized()
void FakeVimPlugin::installHandler() void FakeVimPlugin::installHandler()
{ {
if (!m_core || !m_core->editorManager()) if (Core::IEditor *editor = m_core->editorManager()->currentEditor())
return; installHandler(editor->widget());
}
Core::IEditor *editor = m_core->editorManager()->currentEditor();
ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
if (!textEditor)
return;
void FakeVimPlugin::installHandler(QWidget *widget)
{
connect(m_handler, SIGNAL(extraInformationChanged(QString)), connect(m_handler, SIGNAL(extraInformationChanged(QString)),
this, SLOT(showExtraInformation(QString))); this, SLOT(showExtraInformation(QString)));
connect(m_handler, SIGNAL(commandBufferChanged(QString)), connect(m_handler, SIGNAL(commandBufferChanged(QString)),
@@ -160,11 +166,9 @@ void FakeVimPlugin::installHandler()
connect(m_handler, SIGNAL(quitRequested(QWidget *)), connect(m_handler, SIGNAL(quitRequested(QWidget *)),
this, SLOT(removeHandler(QWidget *))); this, SLOT(removeHandler(QWidget *)));
m_handler->addWidget(textEditor->widget()); m_handler->addWidget(widget);
BaseTextEditor *baseTextEditor =
qobject_cast<BaseTextEditor *>(editor->widget());
BaseTextEditor *baseTextEditor = qobject_cast<BaseTextEditor *>(widget);
if (baseTextEditor) { if (baseTextEditor) {
using namespace TextEditor; using namespace TextEditor;
using namespace FakeVim::Constants; using namespace FakeVim::Constants;
@@ -184,11 +188,23 @@ void FakeVimPlugin::installHandler()
void FakeVimPlugin::removeHandler(QWidget *widget) void FakeVimPlugin::removeHandler(QWidget *widget)
{ {
m_handler->removeWidget(widget); //m_handler->removeWidget(widget);
Core::EditorManager::instance()->hideEditorInfoBar( Core::EditorManager::instance()->hideEditorInfoBar(
QLatin1String(Constants::MINI_BUFFER)); QLatin1String(Constants::MINI_BUFFER));
} }
void FakeVimPlugin::editorOpened(Core::IEditor *editor)
{
//qDebug() << "OPENING: " << editor << editor->widget();
//installHandler(editor->widget());
}
void FakeVimPlugin::editorAboutToClose(Core::IEditor *editor)
{
//qDebug() << "CLOSING: " << editor << editor->widget();
removeHandler(editor->widget());
}
void FakeVimPlugin::showCommandBuffer(const QString &contents) void FakeVimPlugin::showCommandBuffer(const QString &contents)
{ {
Core::EditorManager::instance()->showEditorInfoBar( Core::EditorManager::instance()->showEditorInfoBar(

View File

@@ -78,9 +78,12 @@ private:
private slots: private slots:
void installHandler(); void installHandler();
void installHandler(QWidget *widget);
void removeHandler(QWidget *widget); void removeHandler(QWidget *widget);
void showCommandBuffer(const QString &contents); void showCommandBuffer(const QString &contents);
void showExtraInformation(const QString &msg); void showExtraInformation(const QString &msg);
void editorOpened(Core::IEditor *);
void editorAboutToClose(Core::IEditor *);
private: private:
FakeVimHandler *m_handler; FakeVimHandler *m_handler;