Commit 30c1a046 authored by hjk's avatar hjk
Browse files

fakevim: partial implementation of :history

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