work on fakevim integration

This commit is contained in:
hjk
2009-01-07 18:05:45 +01:00
parent 3005f28462
commit 993be401ef
3 changed files with 36 additions and 18 deletions

View File

@@ -160,14 +160,15 @@ void FakeVimPlugin::installHandler()
void FakeVimPlugin::removeHandler(QWidget *widget) void FakeVimPlugin::removeHandler(QWidget *widget)
{ {
m_handler->removeWidget(widget); m_handler->removeWidget(widget);
Core::EditorManager::instance() Core::EditorManager::instance()->hideEditorInfoBar(
->hideEditorInfoBar(QLatin1String(Constants::MINI_BUFFER)); QLatin1String(Constants::MINI_BUFFER));
} }
void FakeVimPlugin::showCommandBuffer(const QString &contents) void FakeVimPlugin::showCommandBuffer(const QString &contents)
{ {
Core::EditorManager::instance() Core::EditorManager::instance()->showEditorInfoBar(
->showEditorInfoBar(QLatin1String(Constants::MINI_BUFFER), contents); QLatin1String(Constants::MINI_BUFFER), contents,
tr("Quit FakeVim"), m_handler, SLOT(quit()));
} }

View File

@@ -189,6 +189,7 @@ public:
void showMessage(const QString &msg); void showMessage(const QString &msg);
void updateMiniBuffer(); void updateMiniBuffer();
void updateSelection(); void updateSelection();
void quit();
public: public:
QTextEdit *m_textedit; QTextEdit *m_textedit;
@@ -429,25 +430,26 @@ void FakeVimHandler::Private::updateMiniBuffer()
msg += c; msg += c;
} }
} }
msg += " ";
} }
int w = columnsOnScreen();
if (w > 1 && msg.size() > w - 20)
msg = ">" + msg.right(w - 19);
qDebug() << "W: " << w << " MSG: " << msg;
emit q->commandBufferChanged(msg);
int linesInDoc = linesInDocument(); int linesInDoc = linesInDocument();
int l = cursorLineInDocument(); int l = cursorLineInDocument();
int w = columnsOnScreen(); QString status;
if (msg.size() > w - 20)
msg = ">" + msg.right(w - 19);
msg += QString(w, ' ');
msg = msg.left(w - 19);
QString pos = tr("%1,%2").arg(l + 1).arg(cursorColumnInDocument() + 1); 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 // FIXME: physical "-" logical
if (linesInDoc != 0) { if (linesInDoc != 0) {
msg += tr("%1").arg(l * 100 / linesInDoc, 4); status += tr("%1").arg(l * 100 / linesInDoc, 4);
msg += "%"; status += "%";
} else { } else {
msg += "All"; status += "All";
} }
emit q->commandBufferChanged(msg); emit q->statusDataChanged(status);
} }
void FakeVimHandler::Private::showMessage(const QString &msg) void FakeVimHandler::Private::showMessage(const QString &msg)
@@ -949,9 +951,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
m_tc.setPosition(positionForLine(beginLine)); m_tc.setPosition(positionForLine(beginLine));
showMessage(QString()); showMessage(QString());
} else if (cmd == "q!" || cmd == "q") { // :q } else if (cmd == "q!" || cmd == "q") { // :q
showMessage(QString()); quit();
EDITOR(setOverwriteMode(false));
q->quitRequested(editor());
} else if (reDelete.indexIn(cmd) != -1) { // :d } else if (reDelete.indexIn(cmd) != -1) { // :d
if (beginLine == -1) if (beginLine == -1)
beginLine = cursorLineInDocument(); beginLine = cursorLineInDocument();
@@ -1172,6 +1172,7 @@ int FakeVimHandler::Private::columnsOnScreen() const
if (!editor()) if (!editor())
return 1; return 1;
QRect rect = EDITOR(cursorRect()); QRect rect = EDITOR(cursorRect());
qDebug() << "WID: " << EDITOR(width()) << "RECT: " << rect;
return EDITOR(width()) / rect.width(); return EDITOR(width()) / rect.width();
} }
@@ -1335,6 +1336,13 @@ void FakeVimHandler::Private::enterCommandMode()
m_mode = CommandMode; 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); d->handleExCommand(cmd);
} }
void FakeVimHandler::quit()
{
d->quit();
}

View File

@@ -52,16 +52,20 @@ public:
FakeVimHandler(QObject *parent = 0); FakeVimHandler(QObject *parent = 0);
~FakeVimHandler(); ~FakeVimHandler();
public slots:
// The same handler can be installed on several widgets // The same handler can be installed on several widgets
// FIXME: good idea?
void addWidget(QWidget *widget); void addWidget(QWidget *widget);
void removeWidget(QWidget *widget); void removeWidget(QWidget *widget);
// This executes an "ex" style command taking context // This executes an "ex" style command taking context
// information from \p widget; // information from \p widget;
void handleCommand(QWidget *widget, const QString &cmd); void handleCommand(QWidget *widget, const QString &cmd);
void quit();
signals: signals:
void commandBufferChanged(const QString &msg); void commandBufferChanged(const QString &msg);
void statusDataChanged(const QString &msg);
void quitRequested(QWidget *); void quitRequested(QWidget *);
private: private: