diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index fd1be75a56eac160ce77c6a0ccd4ae11d12c481b..15b03ea48d13757e41b567fdfd82e34ac915b4c2 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -1745,27 +1745,31 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) //qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0 << m_marks; + static QRegExp reQuit("^qa?!?$"); static QRegExp reDelete("^d( (.*))?$"); static QRegExp reHistory("^his(tory)?( (.*))?$"); static QRegExp reNormal("^norm(al)?( (.*))?$"); static QRegExp reSet("^set?( (.*))?$"); - static QRegExp reWrite("^w!?( (.*))?$"); + static QRegExp reWrite("^[wx]q?a?!?( (.*))?$"); static QRegExp reSubstitute("^s(.)(.*)\\1(.*)\\1([gi]*)"); if (cmd.isEmpty()) { setPosition(firstPositionInLine(beginLine)); showBlackMessage(QString()); enterCommandMode(); - } else if (cmd == "q!" || cmd == "q") { // :q + } else if (reQuit.indexIn(cmd) != -1) { // :q showBlackMessage(QString()); - q->quitRequested(cmd == "q!"); + if (cmd.contains(QChar('a'))) + q->quitAllRequested(cmd.contains(QChar('!'))); + else + q->quitRequested(cmd.contains(QChar('!'))); } else if (reDelete.indexIn(cmd) != -1) { // :d selectRange(beginLine, endLine); QString reg = reDelete.cap(2); QString text = removeSelectedText(); if (!reg.isEmpty()) m_registers[reg.at(0).unicode()] = text; - } else if (reWrite.indexIn(cmd) != -1) { // :w + } else if (reWrite.indexIn(cmd) != -1) { // :w and :x enterCommandMode(); bool noArgs = (beginLine == -1); if (beginLine == -1) @@ -1773,7 +1777,15 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) if (endLine == -1) endLine = linesInDocument(); //qDebug() << "LINES: " << beginLine << endLine; - bool forced = cmd.startsWith("w!"); + int indexOfSpace = cmd.indexOf(QChar(' ')); + QString prefix; + if (indexOfSpace < 0) + prefix = cmd; + else + prefix = cmd.left(indexOfSpace); + bool forced = prefix.contains(QChar('!')); + bool quit = prefix.contains(QChar('q')) || prefix.contains(QChar('x')); + bool quitAll = quit && prefix.contains(QChar('a')); QString fileName = reWrite.cap(2); if (fileName.isEmpty()) fileName = m_currentFileName; @@ -1809,6 +1821,10 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) showBlackMessage(tr("\"%1\" %2 %3L, %4C written") .arg(fileName).arg(exists ? " " : " [New] ") .arg(ba.count('\n')).arg(ba.size())); + if (quitAll) + q->quitAllRequested(forced); + else if (quit) + q->quitRequested(forced); } else { showRedMessage(tr("Cannot open file '%1' for reading").arg(fileName)); } diff --git a/src/plugins/fakevim/fakevimhandler.h b/src/plugins/fakevim/fakevimhandler.h index 61e9ed097d738a200ff847a0c4c5d1468b863d8a..c1f859657ae7fd91edebb310b69f9e6cdd7f76fb 100644 --- a/src/plugins/fakevim/fakevimhandler.h +++ b/src/plugins/fakevim/fakevimhandler.h @@ -66,6 +66,7 @@ signals: void statusDataChanged(const QString &msg); void extraInformationChanged(const QString &msg); void quitRequested(bool force); + void quitAllRequested(bool force); void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection); void writeFileRequested(bool *handled, const QString &fileName, const QString &contents); diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index d656b0df16ed50d8a159b3b956cfe13eac49b63f..df084665f4e1c8e40e87a9eba3510c0af6cb5e93 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -242,6 +242,7 @@ private slots: void changeSelection(const QList<QTextEdit::ExtraSelection> &selections); void writeFile(bool *handled, const QString &fileName, const QString &contents); void quitFile(bool forced); + void quitAllFiles(bool forced); void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); void indentRegion(int *amount, int beginLine, int endLine, QChar typedChar); @@ -391,6 +392,8 @@ void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor) this, SLOT(showCommandBuffer(QString))); connect(handler, SIGNAL(quitRequested(bool)), this, SLOT(quitFile(bool)), Qt::QueuedConnection); + connect(handler, SIGNAL(quitAllRequested(bool)), + this, SLOT(quitAllFiles(bool)), Qt::QueuedConnection); connect(handler, SIGNAL(writeFileRequested(bool*,QString,QString)), this, SLOT(writeFile(bool*,QString,QString))); connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), @@ -460,6 +463,11 @@ void FakeVimPluginPrivate::quitFile(bool forced) Core::EditorManager::instance()->closeEditors(editors, !forced); } +void FakeVimPluginPrivate::quitAllFiles(bool forced) +{ + Core::EditorManager::instance()->closeAllEditors(!forced); +} + void FakeVimPluginPrivate::writeFile(bool *handled, const QString &fileName, const QString &contents) {