Fix bug #2762: LyX -> LaTeX export autonomously overwrites existing EPS files

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@34533 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-05-28 14:43:23 +00:00
parent cb2283ca02
commit 9993a1f1b7
8 changed files with 81 additions and 15 deletions

View File

@ -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

View File

@ -2639,7 +2639,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
vector<ExportedFile> 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<ExportedFile>::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);

View File

@ -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:

View File

@ -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<string, cmd_helper>::const_iterator it

View File

@ -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;

View File

@ -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.

View File

@ -31,6 +31,7 @@
#include <QMessageBox>
#include <QLineEdit>
#include <QInputDialog>
#include <QPushButton>
#include <QSettings>
#include <iomanip>
@ -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<QAbstractButton *>(b[cancel_button]));
int res = msg_box.exec();
qApp->restoreOverrideCursor();

View File

@ -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