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