Commit fb8e1bb2 authored by hjk's avatar hjk
Browse files

fakevim: listen to editor opening and closing

parent fb93fdae
......@@ -291,8 +291,12 @@ bool FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
{
int key = ev->key();
// FIXME
if (m_mode == PassingMode && key != Qt::Key_Control && key != Qt::Key_Shift) {
enterCommandMode();
if (key == ',') { // use ',,' to leave, too.
quit();
return true;
}
return false;
}
......@@ -1109,6 +1113,8 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
info += key + ": " + m_config.value(key) + "\n";
emit q->extraInformationChanged(info);
}
enterCommandMode();
updateMiniBuffer();
} else {
showRedMessage("E492: Not an editor command: " + cmd0);
}
......
......@@ -136,6 +136,14 @@ bool FakeVimPlugin::initialize(const QStringList &arguments, QString *error_mess
connect(m_installHandlerAction, SIGNAL(triggered()),
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;
}
......@@ -145,14 +153,12 @@ void FakeVimPlugin::extensionsInitialized()
void FakeVimPlugin::installHandler()
{
if (!m_core || !m_core->editorManager())
return;
Core::IEditor *editor = m_core->editorManager()->currentEditor();
ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
if (!textEditor)
return;
if (Core::IEditor *editor = m_core->editorManager()->currentEditor())
installHandler(editor->widget());
}
void FakeVimPlugin::installHandler(QWidget *widget)
{
connect(m_handler, SIGNAL(extraInformationChanged(QString)),
this, SLOT(showExtraInformation(QString)));
connect(m_handler, SIGNAL(commandBufferChanged(QString)),
......@@ -160,11 +166,9 @@ void FakeVimPlugin::installHandler()
connect(m_handler, SIGNAL(quitRequested(QWidget *)),
this, SLOT(removeHandler(QWidget *)));
m_handler->addWidget(textEditor->widget());
BaseTextEditor *baseTextEditor =
qobject_cast<BaseTextEditor *>(editor->widget());
m_handler->addWidget(widget);
BaseTextEditor *baseTextEditor = qobject_cast<BaseTextEditor *>(widget);
if (baseTextEditor) {
using namespace TextEditor;
using namespace FakeVim::Constants;
......@@ -184,11 +188,23 @@ void FakeVimPlugin::installHandler()
void FakeVimPlugin::removeHandler(QWidget *widget)
{
m_handler->removeWidget(widget);
//m_handler->removeWidget(widget);
Core::EditorManager::instance()->hideEditorInfoBar(
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)
{
Core::EditorManager::instance()->showEditorInfoBar(
......
......@@ -78,9 +78,12 @@ private:
private slots:
void installHandler();
void installHandler(QWidget *widget);
void removeHandler(QWidget *widget);
void showCommandBuffer(const QString &contents);
void showExtraInformation(const QString &msg);
void editorOpened(Core::IEditor *);
void editorAboutToClose(Core::IEditor *);
private:
FakeVimHandler *m_handler;
......
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