diff options
author | Lukas Holecek <hluk@email.cz> | 2017-01-22 15:30:31 +0100 |
---|---|---|
committer | Lukas Holecek <hluk@email.cz> | 2017-01-24 10:44:59 +0000 |
commit | 4ecbebace5bb2f9fbdb485ad0e38e76ad559125f (patch) | |
tree | 16d781d2d3e9f87ebe94b07ffa2d7ba486cda6be /src/plugins/fakevim | |
parent | ea2e05948845c02a5a51dc0817b350c01826f7d1 (diff) | |
download | qt-creator-4ecbebace5bb2f9fbdb485ad0e38e76ad559125f.tar.gz |
FakeVim: Allow plugin interaction before saving file
This allows plugins like Beautifier to interact with the document before
it's saved.
Change-Id: I74f9735214c0fa115635b1809dc467036170ae75
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/fakevim')
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index c3b78dab26..2d93eb5fcb 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -1988,28 +1988,30 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) *handled = true; if ((cmd.matches("w", "write") || cmd.cmd == "wq") && cmd.args.isEmpty()) { // :w[rite] + bool saved = false; IEditor *editor = m_editorToHandler.key(handler); const QString fileName = handler->currentFileName(); if (editor && editor->document()->filePath().toString() == fileName) { - // Handle that as a special case for nicer interaction with core - DocumentManager::saveDocument(editor->document()); - // Check result by reading back. - QFile file3(fileName); - file3.open(QIODevice::ReadOnly); - QByteArray ba = file3.readAll(); - handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written") - .arg(fileName).arg(' ').arg(ba.count('\n')).arg(ba.size())); - if (cmd.cmd == "wq") - delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler)); - } else { - handler->showMessage(MessageError, Tr::tr("File not saved")); + triggerAction(Core::Constants::SAVE); + saved = !editor->document()->isModified(); + if (saved) { + QFile file3(fileName); + file3.open(QIODevice::ReadOnly); + const QByteArray ba = file3.readAll(); + handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written") + .arg(fileName).arg(' ').arg(ba.count('\n')).arg(ba.size())); + if (cmd.cmd == "wq") + delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler)); + } } + + if (!saved) + handler->showMessage(MessageError, Tr::tr("File not saved")); } else if (cmd.matches("wa", "wall")) { // :w[all] - QList<IDocument *> toSave = DocumentManager::modifiedDocuments(); - QList<IDocument *> failed; - bool success = DocumentManager::saveModifiedDocuments(toSave, QString(), 0, QString(), 0, &failed); - if (!success) + triggerAction(Core::Constants::SAVEALL); + const QList<IDocument *> failed = DocumentManager::modifiedDocuments(); + if (failed.isEmpty()) handler->showMessage(MessageInfo, Tr::tr("Saving succeeded")); else handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size())); |