std::string SaveFileBaseCommand::saveAsDialog( Context* context, const std::string& dlgTitle, const std::string& initialFilename, const bool markAsSaved, const bool saveInBackground, const std::string& forbiddenFilename) { Doc* document = context->activeDocument(); std::string filename; if (!m_filename.empty()) { filename = m_filename; } else { base::paths exts = get_writable_extensions(); filename = initialFilename; #ifdef ENABLE_UI again:; base::paths newfilename; if (!app::show_file_selector( dlgTitle, filename, exts, FileSelectorType::Save, newfilename)) return std::string(); filename = newfilename.front(); if (!forbiddenFilename.empty() && base::normalize_path(forbiddenFilename) == base::normalize_path(filename)) { ui::Alert::show(Strings::alerts_cannot_file_overwrite_on_export()); goto again; } #endif // ENABLE_UI } if (saveInBackground) { saveDocumentInBackground( context, document, filename, markAsSaved); } return filename; }
void saveAsDialog(const ContextReader& reader, const char* dlgTitle, bool markAsSaved) { const Document* document = reader.document(); std::string filename; if (!m_filename.empty()) { filename = m_filename; } else { filename = document->filename(); char exts[4096]; get_writable_extensions(exts, sizeof(exts)); for (;;) { std::string newfilename = app::show_file_selector(dlgTitle, filename, exts); if (newfilename.empty()) return; filename = newfilename; // Ask if the user wants overwrite the existent file. int ret = 0; if (base::is_file(filename)) { ret = ui::Alert::show("Warning<<The file already exists, overwrite it?<<%s||&Yes||&No||&Cancel", base::get_file_name(filename).c_str()); // Check for read-only attribute. if (ret == 1) { if (!confirmReadonly(filename)) ret = 2; // Select file again. else break; } } else break; // "yes": we must continue with the operation... if (ret == 1) { break; } // "cancel" or <esc> per example: we back doing nothing else if (ret != 2) return; // "no": we must back to select other file-name } } { ContextWriter writer(reader); Document* documentWriter = writer.document(); std::string oldFilename = documentWriter->filename(); // Change the document file name documentWriter->setFilename(filename.c_str()); m_selectedFilename = filename; // Save the document save_document_in_background(writer.context(), documentWriter, markAsSaved); if (documentWriter->isModified()) documentWriter->setFilename(oldFilename); update_screen_for_document(documentWriter); } }