diff --git a/lyx.1in b/lyx.1in index b28eece202..dc85fd8100 100644 --- a/lyx.1in +++ b/lyx.1in @@ -72,6 +72,13 @@ Look on Tools->Preferences->File formats->Format to get an idea which parameters .TP \fB \-i [\-\-import]\fP \fIfmt file.xxx where fmt is the import format of choice and file.xxx is the file to be imported. +.TP +\fB \-f [\-\-force\-overwrite]\fP \fIwhat +where what is is either "\fBall\fR" or "\fBmain\fR". +Using "\fBall\fR", all files are overwritten during a batch export, otherwise +only the main file will be. When this switch is followed by anything else other +than "\fBall\fR" or "\fBmain\fR", the behavior is as if "\fBall\fR" was +specified, but what follows is left on the command line for further processing. .SH ENVIRONMENT .TP diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 95e0b5514f..ba135c4f0a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2639,7 +2639,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir, vector const files = runparams.exportdata->externalFiles(format); string const dest = onlyPath(result_file); - CopyStatus status = SUCCESS; + CopyStatus status = !use_gui && force_overwrite == ALL_FILES ? FORCE + : SUCCESS; for (vector::const_iterator it = files.begin(); it != files.end() && status != CANCEL; ++it) { string const fmt = formats.getFormatFromFile(it->sourceName); @@ -2651,6 +2652,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir, message(_("Document export cancelled.")); } else if (tmp_result_file.exists()) { // Finally copy the main file + if (!use_gui && force_overwrite != NO_FILES) + status = FORCE; status = copyFile(format, tmp_result_file, FileName(result_file), result_file, status == FORCE); diff --git a/src/Exporter.cpp b/src/Exporter.cpp index ffd747a93b..0930a19166 100644 --- a/src/Exporter.cpp +++ b/src/Exporter.cpp @@ -40,15 +40,15 @@ namespace Alert = frontend::Alert; static int checkOverwrite(FileName const & filename) { if (!filename.exists()) - return 0; + return 1; docstring text = bformat(_("The file %1$s already exists.\n\n" "Do you want to overwrite that file?"), makeDisplayPath(filename.absFilename())); return Alert::prompt(_("Overwrite file?"), - text, 0, 2, - _("&Overwrite"), _("Overwrite &all"), - _("&Cancel export")); + text, 0, 3, + _("&Keep file"), _("&Overwrite"), + _("Overwrite &all"), _("&Cancel export")); } @@ -79,9 +79,11 @@ CopyStatus copyFile(string const & format, if (!force) { switch(checkOverwrite(destFile)) { case 0: + return SUCCESS; + case 1: ret = SUCCESS; break; - case 1: + case 2: ret = FORCE; break; default: diff --git a/src/LyX.cpp b/src/LyX.cpp index 35dbbac118..98cf7c2daf 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -85,6 +85,13 @@ namespace os = support::os; bool use_gui = true; + +// Tell what files can be silently overwritten during batch export. +// Possible values are: NO_FILES, MAIN_FILE, ALL_FILES. + +OverwriteFiles force_overwrite = NO_FILES; + + namespace { // Filled with the command line arguments "foo" of "-sysdir foo" or @@ -971,6 +978,11 @@ int parse_help(string const &, string const &, string &) "\t-i [--import] fmt file.xxx\n" " where fmt is the import format of choice\n" " and file.xxx is the file to be imported.\n" + "\t-f [--force-overwrite] what\n" + " where what is either `all' or `main'.\n" + " Using `all', all files are overwritten during\n" + " a batch export, otherwise only the main file will be.\n" + " Anything else is equivalent to `all', but is not consumed.\n" "\t-version summarize version and build info\n" "Check the LyX man page for more details.")) << endl; exit(0); @@ -1065,6 +1077,20 @@ int parse_geometry(string const & arg1, string const &, string &) } +int parse_force(string const & arg, string const &, string &) +{ + if (arg == "all") { + force_overwrite = ALL_FILES; + return 1; + } else if (arg == "main") { + force_overwrite = MAIN_FILE; + return 1; + } + force_overwrite = ALL_FILES; + return 0; +} + + } // namespace anon @@ -1086,6 +1112,8 @@ void LyX::easyParse(int & argc, char * argv[]) cmdmap["-i"] = parse_import; cmdmap["--import"] = parse_import; cmdmap["-geometry"] = parse_geometry; + cmdmap["-f"] = parse_force; + cmdmap["--force-overwrite"] = parse_force; for (int i = 1; i < argc; ++i) { map::const_iterator it diff --git a/src/LyX.h b/src/LyX.h index 6be2a41fb8..8f541b80f3 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -33,7 +33,14 @@ class Server; class ServerSocket; class Session; +enum OverwriteFiles { + NO_FILES, + MAIN_FILE, + ALL_FILES +}; + extern bool use_gui; +extern OverwriteFiles force_overwrite; namespace frontend { class Application; diff --git a/src/frontends/alert.h b/src/frontends/alert.h index 433369d1b9..4f05234297 100644 --- a/src/frontends/alert.h +++ b/src/frontends/alert.h @@ -32,7 +32,9 @@ namespace Alert { */ int prompt(docstring const & title, docstring const & question, int default_button, int cancel_button, - docstring const & b1, docstring const & b2, docstring const & b3 = docstring()); + docstring const & b1, docstring const & b2, + docstring const & b3 = docstring(), + docstring const & b4 = docstring()); /** * Display a warning to the user. Title should be a short (general) summary. diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp index 913ed7e258..41dd844a3e 100644 --- a/src/frontends/qt4/GuiAlert.cpp +++ b/src/frontends/qt4/GuiAlert.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -141,7 +142,8 @@ namespace Alert { int prompt(docstring const & title0, docstring const & question, int default_button, int cancel_button, - docstring const & b1, docstring const & b2, docstring const & b3) + docstring const & b1, docstring const & b2, + docstring const & b3, docstring const & b4) { //lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() << endl; if (!use_gui || lyxerr.debugging()) { @@ -154,6 +156,7 @@ int prompt(docstring const & title0, docstring const & question, case 0: lyxerr << b1 << endl; case 1: lyxerr << b2 << endl; case 2: lyxerr << b3 << endl; + case 3: lyxerr << b4 << endl; } if (!use_gui) return default_button; @@ -167,13 +170,21 @@ int prompt(docstring const & title0, docstring const & question, // FIXME replace that with guiApp->currentView() //LYXERR0("FOCUS: " << qApp->focusWidget()); - int res = QMessageBox::information(qApp->focusWidget(), - toqstr(title), - toqstr(formatted(question)), - toqstr(b1), - toqstr(b2), - b3.empty() ? QString::null : toqstr(b3), - default_button, cancel_button); + QPushButton * b[4] = { 0, 0, 0, 0 }; + QMessageBox msg_box(QMessageBox::Information, + toqstr(title), toqstr(formatted(question)), + QMessageBox::NoButton, qApp->focusWidget()); + b[0] = msg_box.addButton(b1.empty() ? "OK" : toqstr(b1), + QMessageBox::ActionRole); + if (!b2.empty()) + b[1] = msg_box.addButton(toqstr(b2), QMessageBox::ActionRole); + if (!b3.empty()) + b[2] = msg_box.addButton(toqstr(b3), QMessageBox::ActionRole); + if (!b4.empty()) + b[3] = msg_box.addButton(toqstr(b4), QMessageBox::ActionRole); + msg_box.setDefaultButton(b[default_button]); + msg_box.setEscapeButton(static_cast(b[cancel_button])); + int res = msg_box.exec(); qApp->restoreOverrideCursor(); diff --git a/status.16x b/status.16x index 2721000339..86eee53470 100644 --- a/status.16x +++ b/status.16x @@ -24,6 +24,9 @@ What's new * DOCUMENT INPUT/OUTPUT +- Introduced new -f [--force-overwrite] command line flag. Without any + argument (or 'all' as argument) all files are silently overwritten on + export. Using 'main' as argument, only the main file will be overwritten. @@ -74,6 +77,9 @@ What's new - Don't allow creating multiple buffers with same name (bug 6645). +- Don't automatically overwrite files on export, unless the newly introduced + -f flag is used (bug 2762). + * USER INTERFACE