forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -1988,28 +1988,30 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
|
|||||||
*handled = true;
|
*handled = true;
|
||||||
if ((cmd.matches("w", "write") || cmd.cmd == "wq") && cmd.args.isEmpty()) {
|
if ((cmd.matches("w", "write") || cmd.cmd == "wq") && cmd.args.isEmpty()) {
|
||||||
// :w[rite]
|
// :w[rite]
|
||||||
|
bool saved = false;
|
||||||
IEditor *editor = m_editorToHandler.key(handler);
|
IEditor *editor = m_editorToHandler.key(handler);
|
||||||
const QString fileName = handler->currentFileName();
|
const QString fileName = handler->currentFileName();
|
||||||
if (editor && editor->document()->filePath().toString() == fileName) {
|
if (editor && editor->document()->filePath().toString() == fileName) {
|
||||||
// Handle that as a special case for nicer interaction with core
|
triggerAction(Core::Constants::SAVE);
|
||||||
DocumentManager::saveDocument(editor->document());
|
saved = !editor->document()->isModified();
|
||||||
// Check result by reading back.
|
if (saved) {
|
||||||
QFile file3(fileName);
|
QFile file3(fileName);
|
||||||
file3.open(QIODevice::ReadOnly);
|
file3.open(QIODevice::ReadOnly);
|
||||||
QByteArray ba = file3.readAll();
|
const QByteArray ba = file3.readAll();
|
||||||
handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written")
|
handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written")
|
||||||
.arg(fileName).arg(' ').arg(ba.count('\n')).arg(ba.size()));
|
.arg(fileName).arg(' ').arg(ba.count('\n')).arg(ba.size()));
|
||||||
if (cmd.cmd == "wq")
|
if (cmd.cmd == "wq")
|
||||||
delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
|
delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
|
||||||
} else {
|
}
|
||||||
handler->showMessage(MessageError, Tr::tr("File not saved"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!saved)
|
||||||
|
handler->showMessage(MessageError, Tr::tr("File not saved"));
|
||||||
} else if (cmd.matches("wa", "wall")) {
|
} else if (cmd.matches("wa", "wall")) {
|
||||||
// :w[all]
|
// :w[all]
|
||||||
QList<IDocument *> toSave = DocumentManager::modifiedDocuments();
|
triggerAction(Core::Constants::SAVEALL);
|
||||||
QList<IDocument *> failed;
|
const QList<IDocument *> failed = DocumentManager::modifiedDocuments();
|
||||||
bool success = DocumentManager::saveModifiedDocuments(toSave, QString(), 0, QString(), 0, &failed);
|
if (failed.isEmpty())
|
||||||
if (!success)
|
|
||||||
handler->showMessage(MessageInfo, Tr::tr("Saving succeeded"));
|
handler->showMessage(MessageInfo, Tr::tr("Saving succeeded"));
|
||||||
else
|
else
|
||||||
handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size()));
|
handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size()));
|
||||||
|
|||||||
Reference in New Issue
Block a user