Commit 45d9cca1 authored by hjk's avatar hjk
Browse files

fakevim: make visual selections also visual in creator

parent 669b56fd
......@@ -474,7 +474,7 @@ void FakeVimHandler::Private::updateSelection()
}
}
}
EDITOR(setExtraSelections(selections));
emit q->selectionChanged(editor(), selections);
}
void FakeVimHandler::Private::updateMiniBuffer()
......
......@@ -34,7 +34,8 @@
#ifndef FAKEVIM_HANDLER_H
#define FAKEVIM_HANDLER_H
#include <QObject>
#include <QtCore/QObject>
#include <QtGui/QTextEdit>
QT_BEGIN_NAMESPACE
class QString;
......@@ -69,6 +70,8 @@ signals:
void statusDataChanged(const QString &msg);
void extraInformationChanged(const QString &msg);
void quitRequested(QWidget *);
void selectionChanged(QWidget *widget,
const QList<QTextEdit::ExtraSelection> &selection);
private:
bool eventFilter(QObject *ob, QEvent *ev);
......
......@@ -165,14 +165,17 @@ void FakeVimPlugin::installHandler(QWidget *widget)
this, SLOT(showCommandBuffer(QString)));
connect(m_handler, SIGNAL(quitRequested(QWidget *)),
this, SLOT(removeHandler(QWidget *)));
connect(m_handler,
SIGNAL(selectionChanged(QWidget*,QList<QTextEdit::ExtraSelection>)),
this, SLOT(changeSelection(QWidget*,QList<QTextEdit::ExtraSelection>)));
m_handler->addWidget(widget);
BaseTextEditor *baseTextEditor = qobject_cast<BaseTextEditor *>(widget);
if (baseTextEditor) {
BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(widget);
if (bt) {
using namespace TextEditor;
using namespace FakeVim::Constants;
TabSettings settings = baseTextEditor->tabSettings();
TabSettings settings = bt->tabSettings();
m_handler->setConfigValue(ConfigTabStop,
QString::number(settings.m_tabSize));
m_handler->setConfigValue(ConfigShiftWidth,
......@@ -219,6 +222,13 @@ void FakeVimPlugin::showExtraInformation(const QString &text)
QMessageBox::information(0, tr("FakeVim Information"), text);
}
void FakeVimPlugin::changeSelection(QWidget *widget,
const QList<QTextEdit::ExtraSelection> &selection)
{
if (BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(widget))
bt->setExtraSelections(BaseTextEditor::FakeVimSelection, selection);
}
//#include "fakevimplugin.moc"
Q_EXPORT_PLUGIN(FakeVimPlugin)
......@@ -37,6 +37,8 @@
#include <extensionsystem/iplugin.h>
#include <QtCore/QObject>
#include <QtCore/QList>
#include <QtGui/QTextEdit>
QT_BEGIN_NAMESPACE
class QAction;
......@@ -84,6 +86,8 @@ private slots:
void showExtraInformation(const QString &msg);
void editorOpened(Core::IEditor *);
void editorAboutToClose(Core::IEditor *);
void changeSelection(QWidget *widget,
const QList<QTextEdit::ExtraSelection> &selections);
private:
FakeVimHandler *m_handler;
......
#include "handler.h"
#include "fakevimhandler.h"
#include <QtCore/QDebug>
......@@ -11,6 +11,25 @@
using namespace FakeVim::Internal;
class Proxy : public QObject
{
Q_OBJECT
public:
Proxy(QWidget *widget) : QObject(0), m_widget(widget) {}
public slots:
void changeSelection(QWidget *w, const QList<QTextEdit::ExtraSelection> &s)
{
if (QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(w))
ed->setExtraSelections(s);
else if (QTextEdit *ed = qobject_cast<QTextEdit *>(w))
ed->setExtraSelections(s);
}
private:
QWidget *m_widget;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
......@@ -31,8 +50,10 @@ int main(int argc, char *argv[])
widget->resize(450, 350);
widget->setFocus();
Proxy proxy(widget);
FakeVimHandler fakeVim;
FakeVimHandler handler;
QMainWindow mw;
mw.setWindowTitle("Fakevim (" + title + ")");
......@@ -50,14 +71,19 @@ int main(int argc, char *argv[])
widget->setFont(font);
mw.statusBar()->setFont(font);
QObject::connect(&fakeVim, SIGNAL(commandBufferChanged(QString)),
QObject::connect(&handler, SIGNAL(commandBufferChanged(QString)),
mw.statusBar(), SLOT(showMessage(QString)));
QObject::connect(&fakeVim, SIGNAL(quitRequested(QWidget *)),
QObject::connect(&handler, SIGNAL(quitRequested(QWidget *)),
&app, SLOT(quit()));
QObject::connect(&handler,
SIGNAL(selectionChanged(QWidget*,QList<QTextEdit::ExtraSelection>)),
&proxy, SLOT(changeSelection(QWidget*,QList<QTextEdit::ExtraSelection>)));
fakeVim.addWidget(widget);
handler.addWidget(widget);
if (args.size() >= 1)
fakeVim.handleCommand(widget, "r " + args.at(0));
handler.handleCommand(widget, "r " + args.at(0));
return app.exec();
}
#include "main.moc"
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