Commit 993be401 authored by hjk's avatar hjk
Browse files

work on fakevim integration

parent 3005f284
......@@ -160,14 +160,15 @@ void FakeVimPlugin::installHandler()
void FakeVimPlugin::removeHandler(QWidget *widget)
{
m_handler->removeWidget(widget);
Core::EditorManager::instance()
->hideEditorInfoBar(QLatin1String(Constants::MINI_BUFFER));
Core::EditorManager::instance()->hideEditorInfoBar(
QLatin1String(Constants::MINI_BUFFER));
}
void FakeVimPlugin::showCommandBuffer(const QString &contents)
{
Core::EditorManager::instance()
->showEditorInfoBar(QLatin1String(Constants::MINI_BUFFER), contents);
Core::EditorManager::instance()->showEditorInfoBar(
QLatin1String(Constants::MINI_BUFFER), contents,
tr("Quit FakeVim"), m_handler, SLOT(quit()));
}
......
......@@ -189,6 +189,7 @@ public:
void showMessage(const QString &msg);
void updateMiniBuffer();
void updateSelection();
void quit();
public:
QTextEdit *m_textedit;
......@@ -429,25 +430,26 @@ void FakeVimHandler::Private::updateMiniBuffer()
msg += c;
}
}
msg += " ";
}
int linesInDoc = linesInDocument();
int l = cursorLineInDocument();
int w = columnsOnScreen();
if (msg.size() > w - 20)
if (w > 1 && msg.size() > w - 20)
msg = ">" + msg.right(w - 19);
msg += QString(w, ' ');
msg = msg.left(w - 19);
qDebug() << "W: " << w << " MSG: " << msg;
emit q->commandBufferChanged(msg);
int linesInDoc = linesInDocument();
int l = cursorLineInDocument();
QString status;
QString pos = tr("%1,%2").arg(l + 1).arg(cursorColumnInDocument() + 1);
msg += tr("%1").arg(pos, -10);
status += tr("%1").arg(pos, -10);
// FIXME: physical "-" logical
if (linesInDoc != 0) {
msg += tr("%1").arg(l * 100 / linesInDoc, 4);
msg += "%";
status += tr("%1").arg(l * 100 / linesInDoc, 4);
status += "%";
} else {
msg += "All";
status += "All";
}
emit q->commandBufferChanged(msg);
emit q->statusDataChanged(status);
}
void FakeVimHandler::Private::showMessage(const QString &msg)
......@@ -949,9 +951,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
m_tc.setPosition(positionForLine(beginLine));
showMessage(QString());
} else if (cmd == "q!" || cmd == "q") { // :q
showMessage(QString());
EDITOR(setOverwriteMode(false));
q->quitRequested(editor());
quit();
} else if (reDelete.indexIn(cmd) != -1) { // :d
if (beginLine == -1)
beginLine = cursorLineInDocument();
......@@ -1172,6 +1172,7 @@ int FakeVimHandler::Private::columnsOnScreen() const
if (!editor())
return 1;
QRect rect = EDITOR(cursorRect());
qDebug() << "WID: " << EDITOR(width()) << "RECT: " << rect;
return EDITOR(width()) / rect.width();
}
......@@ -1335,6 +1336,13 @@ void FakeVimHandler::Private::enterCommandMode()
m_mode = CommandMode;
}
void FakeVimHandler::Private::quit()
{
showMessage(QString());
EDITOR(setOverwriteMode(false));
q->quitRequested(editor());
}
///////////////////////////////////////////////////////////////////////
//
......@@ -1387,3 +1395,8 @@ void FakeVimHandler::handleCommand(QWidget *widget, const QString &cmd)
d->handleExCommand(cmd);
}
void FakeVimHandler::quit()
{
d->quit();
}
......@@ -52,16 +52,20 @@ public:
FakeVimHandler(QObject *parent = 0);
~FakeVimHandler();
public slots:
// The same handler can be installed on several widgets
// FIXME: good idea?
void addWidget(QWidget *widget);
void removeWidget(QWidget *widget);
// This executes an "ex" style command taking context
// information from \p widget;
void handleCommand(QWidget *widget, const QString &cmd);
void quit();
signals:
void commandBufferChanged(const QString &msg);
void statusDataChanged(const QString &msg);
void quitRequested(QWidget *);
private:
......
Supports Markdown
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