]> git.lyx.org Git - lyx.git/commitdiff
Introduce a switch for overwriting files during a batch export.
authorEnrico Forestieri <forenr@lyx.org>
Mon, 19 Apr 2010 23:53:23 +0000 (23:53 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 19 Apr 2010 23:53:23 +0000 (23:53 +0000)
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

src/Buffer.cpp
src/LyX.cpp
src/LyX.h

index b0688cb318a531704bb7e70e77a057af322e04d1..1d52a823b5656e201e8138f3565b2e811ae50063 100644 (file)
@@ -3377,7 +3377,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;
        
        vector<ExportedFile>::const_iterator it = files.begin();
        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."));
        } 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);
index 7fa09164178b205b80a37e7bd34a0f82d614cf9d..15ef92eff01c464e20999a776eaabae14b4d978c 100644 (file)
@@ -88,6 +88,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.
+
+overwrite_files force_overwrite = NO_FILES;
+
+
 namespace {
 
 // 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"
                  "                  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-batch          execute commands without launching GUI and exit.\n"
                  "\t-version        summarize version and build info\n"
                               "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
 
 
@@ -1124,6 +1150,8 @@ void LyX::easyParse(int & argc, char * argv[])
        cmdmap["--import"] = parse_import;
        cmdmap["-geometry"] = parse_geometry;
        cmdmap["-batch"] = parse_batch;
+       cmdmap["-f"] = parse_force;
+       cmdmap["--force-overwrite"] = parse_force;
 
        for (int i = 1; i < argc; ++i) {
                map<string, cmd_helper>::const_iterator it
index 238fe38de0c708f05ee4c8432ae6d1cc4fe2fa93..dd98a370a5240f38c6546927ef56e9e5eaf2b62d 100644 (file)
--- a/src/LyX.h
+++ b/src/LyX.h
@@ -34,7 +34,14 @@ class ServerSocket;
 class Session;
 class SpellChecker;
 
+enum overwrite_files {
+       NO_FILES,
+       MAIN_FILE,
+       ALL_FILES
+};
+
 extern bool use_gui;
+extern overwrite_files force_overwrite;
 
 namespace frontend {
 class Application;