MCPcopy Create free account
hub / github.com/KDE/kdevelop / save

Method save

kdevplatform/shell/textdocument.cpp:381–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381bool TextDocument::save(DocumentSaveMode mode)
382{
383 Q_D(TextDocument);
384
385 if (!d->document)
386 return true;
387
388 if (mode & Discard)
389 return true;
390
391 switch (d->state)
392 {
393 case IDocument::Clean:
394 return true;
395
396 case IDocument::Modified:
397 break;
398
399 case IDocument::Dirty:
400 case IDocument::DirtyAndModified:
401 if (!(mode & Silent))
402 {
403 int code = KMessageBox::warningTwoActionsCancel(
404 Core::self()->uiController()->activeMainWindow(),
405 i18n("The file \"%1\" is modified on disk.\n\nAre "
406 "you sure you want to overwrite it? (External "
407 "changes will be lost.)",
408 d->document->url().toLocalFile()),
409 i18nc("@title:window", "Document Externally Modified"),
410 KGuiItem(i18nc("@action:button", "Overwrite External Changes"), QStringLiteral("document-save")),
411 KStandardGuiItem::discard());
412 if (code == KMessageBox::SecondaryAction) {
413 return true; // Discard
414 } else if (code == KMessageBox::Cancel) {
415 return false;
416 }
417 mode = Silent; // prevent documentSave() from asking essentially the same question again
418 }
419 break;
420 }
421
422 if (!KDevelop::ensureWritable(QList<QUrl>() << url())) {
423 return false;
424 }
425
426 if (mode & Silent) {
427 // Set the KTextEditor equivalent to DocumentSaveMode::Silent.
428 d->document->setModifiedOnDiskWarning(false);
429 }
430 const auto saved = d->document->documentSave();
431 if (mode & Silent) {
432 // Restore the default value. Unfortunately, a getter to query the previous value is missing.
433 d->document->setModifiedOnDiskWarning(true);
434 }
435 return saved;
436}
437
438IDocument::DocumentState TextDocument::state() const

Callers

nothing calls this directly

Calls 6

ensureWritableFunction · 0.85
urlFunction · 0.85
uiControllerMethod · 0.80
toLocalFileMethod · 0.80
activeMainWindowMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected