forked from qt-creator/qt-creator
fakevim: partial implementation of :history
This commit is contained in:
@@ -211,6 +211,7 @@ private:
|
|||||||
void enterCommandMode();
|
void enterCommandMode();
|
||||||
void showRedMessage(const QString &msg);
|
void showRedMessage(const QString &msg);
|
||||||
void showBlackMessage(const QString &msg);
|
void showBlackMessage(const QString &msg);
|
||||||
|
void notImplementedYet();
|
||||||
void updateMiniBuffer();
|
void updateMiniBuffer();
|
||||||
void updateSelection();
|
void updateSelection();
|
||||||
void quit();
|
void quit();
|
||||||
@@ -550,6 +551,12 @@ void FakeVimHandler::Private::showBlackMessage(const QString &msg)
|
|||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::notImplementedYet()
|
||||||
|
{
|
||||||
|
showRedMessage("Not implemented in FakeVim");
|
||||||
|
updateMiniBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
|
bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
|
||||||
const QString &text)
|
const QString &text)
|
||||||
{
|
{
|
||||||
@@ -1084,6 +1091,7 @@ int FakeVimHandler::Private::readLineCode(QString &cmd)
|
|||||||
int mark = m_marks.value(cmd.at(0).unicode());
|
int mark = m_marks.value(cmd.at(0).unicode());
|
||||||
if (!mark) {
|
if (!mark) {
|
||||||
showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
|
showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
|
||||||
|
cmd = cmd.mid(1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cmd = cmd.mid(1);
|
cmd = cmd.mid(1);
|
||||||
@@ -1104,6 +1112,7 @@ int FakeVimHandler::Private::readLineCode(QString &cmd)
|
|||||||
//qDebug() << " MARK: " << cmd.at(0) << pos << lineForPosition(pos);
|
//qDebug() << " MARK: " << cmd.at(0) << pos << lineForPosition(pos);
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
|
showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0)));
|
||||||
|
cmd = cmd.mid(1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cmd = cmd.mid(1);
|
cmd = cmd.mid(1);
|
||||||
@@ -1159,11 +1168,12 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
|||||||
endLine = line;
|
endLine = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
//qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0;
|
//qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0 << m_marks;
|
||||||
|
|
||||||
static QRegExp reWrite("^w!?( (.*))?$");
|
static QRegExp reWrite("^w!?( (.*))?$");
|
||||||
static QRegExp reDelete("^d( (.*))?$");
|
static QRegExp reDelete("^d( (.*))?$");
|
||||||
static QRegExp reSet("^set?( (.*))?$");
|
static QRegExp reSet("^set?( (.*))?$");
|
||||||
|
static QRegExp reHistory("^his(tory)?( (.*))?$");
|
||||||
|
|
||||||
if (cmd.isEmpty()) {
|
if (cmd.isEmpty()) {
|
||||||
m_tc.setPosition(positionForLine(beginLine));
|
m_tc.setPosition(positionForLine(beginLine));
|
||||||
@@ -1247,6 +1257,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
|||||||
recordOperation(op);
|
recordOperation(op);
|
||||||
|
|
||||||
enterCommandMode();
|
enterCommandMode();
|
||||||
|
//qDebug() << "FILTER: " << command;
|
||||||
showBlackMessage(tr("%1 lines filtered").arg(text.count('\n')));
|
showBlackMessage(tr("%1 lines filtered").arg(text.count('\n')));
|
||||||
} else if (cmd == "red" || cmd == "redo") { // :redo
|
} else if (cmd == "red" || cmd == "redo") { // :redo
|
||||||
redo();
|
redo();
|
||||||
@@ -1258,7 +1269,25 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
|||||||
QString info;
|
QString info;
|
||||||
foreach (const QString &key, m_config.keys())
|
foreach (const QString &key, m_config.keys())
|
||||||
info += key + ": " + m_config.value(key) + "\n";
|
info += key + ": " + m_config.value(key) + "\n";
|
||||||
emit q->extraInformationChanged(info);
|
emit q->extraInformationChanged(editor(), info);
|
||||||
|
} else {
|
||||||
|
notImplementedYet();
|
||||||
|
}
|
||||||
|
enterCommandMode();
|
||||||
|
updateMiniBuffer();
|
||||||
|
} else if (reHistory.indexIn(cmd) != -1) { // :history
|
||||||
|
QString arg = reSet.cap(3);
|
||||||
|
if (arg.isEmpty()) {
|
||||||
|
QString info;
|
||||||
|
info += "# command history\n";
|
||||||
|
int i = 0;
|
||||||
|
foreach (const QString &item, m_commandHistory) {
|
||||||
|
++i;
|
||||||
|
info += QString("%1 %2\n").arg(i, -8).arg(item);
|
||||||
|
}
|
||||||
|
emit q->extraInformationChanged(editor(), info);
|
||||||
|
} else {
|
||||||
|
notImplementedYet();
|
||||||
}
|
}
|
||||||
enterCommandMode();
|
enterCommandMode();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
@@ -1581,6 +1610,7 @@ void FakeVimHandler::Private::enterVisualMode(VisualMode visualMode)
|
|||||||
{
|
{
|
||||||
m_visualMode = visualMode;
|
m_visualMode = visualMode;
|
||||||
m_marks['<'] = m_tc.position();
|
m_marks['<'] = m_tc.position();
|
||||||
|
m_marks['>'] = m_tc.position();
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
updateSelection();
|
updateSelection();
|
||||||
}
|
}
|
||||||
@@ -1588,7 +1618,6 @@ void FakeVimHandler::Private::enterVisualMode(VisualMode visualMode)
|
|||||||
void FakeVimHandler::Private::leaveVisualMode()
|
void FakeVimHandler::Private::leaveVisualMode()
|
||||||
{
|
{
|
||||||
m_visualMode = NoVisualMode;
|
m_visualMode = NoVisualMode;
|
||||||
m_marks['>'] = m_tc.position();
|
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
updateSelection();
|
updateSelection();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void commandBufferChanged(const QString &msg);
|
void commandBufferChanged(const QString &msg);
|
||||||
void statusDataChanged(const QString &msg);
|
void statusDataChanged(const QString &msg);
|
||||||
void extraInformationChanged(const QString &msg);
|
void extraInformationChanged(QWidget *widget, const QString &msg);
|
||||||
void quitRequested(QWidget *);
|
void quitRequested(QWidget *widget);
|
||||||
void selectionChanged(QWidget *widget,
|
void selectionChanged(QWidget *widget,
|
||||||
const QList<QTextEdit::ExtraSelection> &selection);
|
const QList<QTextEdit::ExtraSelection> &selection);
|
||||||
void writeFile(const QString &fileName, const QString &contents);
|
void writeFile(const QString &fileName, const QString &contents);
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ private slots:
|
|||||||
void installHandler(QWidget *widget);
|
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(QWidget *, const QString &msg);
|
||||||
void editorOpened(Core::IEditor *);
|
void editorOpened(Core::IEditor *);
|
||||||
void editorAboutToClose(Core::IEditor *);
|
void editorAboutToClose(Core::IEditor *);
|
||||||
void changeSelection(QWidget *widget,
|
void changeSelection(QWidget *widget,
|
||||||
@@ -200,8 +200,8 @@ void FakeVimPluginPrivate::installHandler()
|
|||||||
|
|
||||||
void FakeVimPluginPrivate::installHandler(QWidget *widget)
|
void FakeVimPluginPrivate::installHandler(QWidget *widget)
|
||||||
{
|
{
|
||||||
connect(m_handler, SIGNAL(extraInformationChanged(QString)),
|
connect(m_handler, SIGNAL(extraInformationChanged(QWidget *, QString)),
|
||||||
this, SLOT(showExtraInformation(QString)));
|
this, SLOT(showExtraInformation(QWidget *, QString)));
|
||||||
connect(m_handler, SIGNAL(commandBufferChanged(QString)),
|
connect(m_handler, SIGNAL(commandBufferChanged(QString)),
|
||||||
this, SLOT(showCommandBuffer(QString)));
|
this, SLOT(showCommandBuffer(QString)));
|
||||||
connect(m_handler, SIGNAL(quitRequested(QWidget *)),
|
connect(m_handler, SIGNAL(quitRequested(QWidget *)),
|
||||||
@@ -281,9 +281,9 @@ void FakeVimPluginPrivate::showCommandBuffer(const QString &contents)
|
|||||||
tr("Quit FakeVim"), m_handler, SLOT(quit()));
|
tr("Quit FakeVim"), m_handler, SLOT(quit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::showExtraInformation(const QString &text)
|
void FakeVimPluginPrivate::showExtraInformation(QWidget *widget, const QString &text)
|
||||||
{
|
{
|
||||||
QMessageBox::information(0, tr("FakeVim Information"), text);
|
QMessageBox::information(widget, tr("FakeVim Information"), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::changeSelection(QWidget *widget,
|
void FakeVimPluginPrivate::changeSelection(QWidget *widget,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QApplication>
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QPlainTextEdit>
|
#include <QtGui/QPlainTextEdit>
|
||||||
#include <QtGui/QStatusBar>
|
#include <QtGui/QStatusBar>
|
||||||
#include <QtGui/QTextEdit>
|
#include <QtGui/QTextEdit>
|
||||||
@@ -16,7 +17,7 @@ class Proxy : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Proxy(QWidget *widget) : QObject(0), m_widget(widget) {}
|
Proxy() : QObject(0) {}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void changeSelection(QWidget *w, const QList<QTextEdit::ExtraSelection> &s)
|
void changeSelection(QWidget *w, const QList<QTextEdit::ExtraSelection> &s)
|
||||||
@@ -26,8 +27,11 @@ public slots:
|
|||||||
else if (QTextEdit *ed = qobject_cast<QTextEdit *>(w))
|
else if (QTextEdit *ed = qobject_cast<QTextEdit *>(w))
|
||||||
ed->setExtraSelections(s);
|
ed->setExtraSelections(s);
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
QWidget *m_widget;
|
void changeExtraInformation(QWidget *w, const QString &info)
|
||||||
|
{
|
||||||
|
QMessageBox::information(w, "Information", info);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -50,7 +54,7 @@ int main(int argc, char *argv[])
|
|||||||
widget->resize(450, 350);
|
widget->resize(450, 350);
|
||||||
widget->setFocus();
|
widget->setFocus();
|
||||||
|
|
||||||
Proxy proxy(widget);
|
Proxy proxy;
|
||||||
|
|
||||||
|
|
||||||
FakeVimHandler handler;
|
FakeVimHandler handler;
|
||||||
@@ -78,6 +82,9 @@ int main(int argc, char *argv[])
|
|||||||
QObject::connect(&handler,
|
QObject::connect(&handler,
|
||||||
SIGNAL(selectionChanged(QWidget*,QList<QTextEdit::ExtraSelection>)),
|
SIGNAL(selectionChanged(QWidget*,QList<QTextEdit::ExtraSelection>)),
|
||||||
&proxy, SLOT(changeSelection(QWidget*,QList<QTextEdit::ExtraSelection>)));
|
&proxy, SLOT(changeSelection(QWidget*,QList<QTextEdit::ExtraSelection>)));
|
||||||
|
QObject::connect(&handler,
|
||||||
|
SIGNAL(extraInformationChanged(QWidget*,QString)),
|
||||||
|
&proxy, SLOT(changeExtraInformation(QWidget*,QString)));
|
||||||
|
|
||||||
handler.addWidget(widget);
|
handler.addWidget(widget);
|
||||||
if (args.size() >= 1)
|
if (args.size() >= 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user