mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +00:00
Introduce a switch for overwriting files during a batch export.
Using "-f all", or simply "-f", all files are silently overwritten. Using "-f main", only the main file is overwritten. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34224 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1df3f70ed1
commit
b121ac47c6
@ -3377,7 +3377,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
|
|||||||
vector<ExportedFile> const files =
|
vector<ExportedFile> const files =
|
||||||
runparams.exportdata->externalFiles(format);
|
runparams.exportdata->externalFiles(format);
|
||||||
string const dest = onlyPath(result_file);
|
string const dest = onlyPath(result_file);
|
||||||
CopyStatus status = SUCCESS;
|
CopyStatus status = !use_gui && force_overwrite == ALL_FILES ? FORCE
|
||||||
|
: SUCCESS;
|
||||||
|
|
||||||
vector<ExportedFile>::const_iterator it = files.begin();
|
vector<ExportedFile>::const_iterator it = files.begin();
|
||||||
vector<ExportedFile>::const_iterator const en = files.end();
|
vector<ExportedFile>::const_iterator const en = files.end();
|
||||||
@ -3392,6 +3393,8 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
|
|||||||
message(_("Document export cancelled."));
|
message(_("Document export cancelled."));
|
||||||
} else if (tmp_result_file.exists()) {
|
} else if (tmp_result_file.exists()) {
|
||||||
// Finally copy the main file
|
// Finally copy the main file
|
||||||
|
if (!use_gui && force_overwrite != NO_FILES)
|
||||||
|
status = FORCE;
|
||||||
status = copyFile(format, tmp_result_file,
|
status = copyFile(format, tmp_result_file,
|
||||||
FileName(result_file), result_file,
|
FileName(result_file), result_file,
|
||||||
status == FORCE);
|
status == FORCE);
|
||||||
|
28
src/LyX.cpp
28
src/LyX.cpp
@ -88,6 +88,13 @@ namespace os = support::os;
|
|||||||
|
|
||||||
bool use_gui = true;
|
bool use_gui = true;
|
||||||
|
|
||||||
|
|
||||||
|
// Tell what files can be silently overwritten during batch export.
|
||||||
|
// Possible values are: NO_FILES, MAIN_FILE, ALL_FILES.
|
||||||
|
|
||||||
|
overwrite_files force_overwrite = NO_FILES;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Filled with the command line arguments "foo" of "-sysdir foo" or
|
// Filled with the command line arguments "foo" of "-sysdir foo" or
|
||||||
@ -1000,6 +1007,11 @@ int parse_help(string const &, string const &, string &)
|
|||||||
"\t-i [--import] fmt file.xxx\n"
|
"\t-i [--import] fmt file.xxx\n"
|
||||||
" where fmt is the import format of choice\n"
|
" where fmt is the import format of choice\n"
|
||||||
" and file.xxx is the file to be imported.\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-batch execute commands without launching GUI and exit.\n"
|
"\t-batch execute commands without launching GUI and exit.\n"
|
||||||
"\t-version summarize version and build info\n"
|
"\t-version summarize version and build info\n"
|
||||||
"Check the LyX man page for more details.")) << endl;
|
"Check the LyX man page for more details.")) << endl;
|
||||||
@ -1102,6 +1114,20 @@ int parse_batch(string const &, 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
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
@ -1124,6 +1150,8 @@ void LyX::easyParse(int & argc, char * argv[])
|
|||||||
cmdmap["--import"] = parse_import;
|
cmdmap["--import"] = parse_import;
|
||||||
cmdmap["-geometry"] = parse_geometry;
|
cmdmap["-geometry"] = parse_geometry;
|
||||||
cmdmap["-batch"] = parse_batch;
|
cmdmap["-batch"] = parse_batch;
|
||||||
|
cmdmap["-f"] = parse_force;
|
||||||
|
cmdmap["--force-overwrite"] = parse_force;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
map<string, cmd_helper>::const_iterator it
|
map<string, cmd_helper>::const_iterator it
|
||||||
|
@ -34,7 +34,14 @@ class ServerSocket;
|
|||||||
class Session;
|
class Session;
|
||||||
class SpellChecker;
|
class SpellChecker;
|
||||||
|
|
||||||
|
enum overwrite_files {
|
||||||
|
NO_FILES,
|
||||||
|
MAIN_FILE,
|
||||||
|
ALL_FILES
|
||||||
|
};
|
||||||
|
|
||||||
extern bool use_gui;
|
extern bool use_gui;
|
||||||
|
extern overwrite_files force_overwrite;
|
||||||
|
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
class Application;
|
class Application;
|
||||||
|
Loading…
Reference in New Issue
Block a user