From 260a98d295c54ba1009236cf7101a76cba20bd03 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sat, 23 May 2015 17:49:33 +0200 Subject: [PATCH] Save the document directory path only if explicitly allowed. A new preference is introduced for allowing the record of the document directory path in the saved file. Without explicit consent, it is not saved. If the origin tag contains an invalid/wrong path or garbage, LyX behaves exactly as before, i.e., included files are simply not found. --- src/BufferParams.cpp | 3 ++- src/LyXRC.cpp | 13 +++++++++++++ src/LyXRC.h | 3 +++ src/frontends/qt4/GuiPrefs.cpp | 4 ++++ src/frontends/qt4/ui/PrefDocHandlingUi.ui | 11 +++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 8b193e00ec..34f1a50187 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -983,7 +983,8 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const // Prints out the buffer info into the .lyx file given by file // the document directory - os << "\\origin " << buf->filePath() << '\n'; + os << "\\origin " + << (lyxrc.save_origin ? buf->filePath() : "unavailable") << '\n'; // the textclass os << "\\textclass " << buf->includedFilePath(addName(buf->layoutPos(), diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 0bf6d1d168..650b1dfdf4 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -172,6 +172,7 @@ LexerKeyword lyxrcTags[] = { { "\\print_to_printer", LyXRC::RC_PRINTTOPRINTER }, { "\\printer", LyXRC::RC_PRINTER }, { "\\save_compressed", LyXRC::RC_SAVE_COMPRESSED }, + { "\\save_origin", LyXRC::RC_SAVE_ORIGIN }, { "\\screen_dpi", LyXRC::RC_SCREEN_DPI }, { "\\screen_font_roman", LyXRC::RC_SCREEN_FONT_ROMAN }, { "\\screen_font_roman_foundry", LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY }, @@ -295,6 +296,7 @@ void LyXRC::setDefaults() load_session = false; make_backup = true; save_compressed = false; + save_origin = false; backupdir_path.erase(); display_graphics = true; // Spellchecker settings: @@ -987,6 +989,9 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format) case RC_SAVE_COMPRESSED: lexrc >> save_compressed; break; + case RC_SAVE_ORIGIN: + lexrc >> save_origin; + break; case RC_BACKUPDIR_PATH: if (lexrc.next()) { backupdir_path = os::internal_path(lexrc.getString()); @@ -2424,6 +2429,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c } if (tag != RC_LAST) break; + case RC_SAVE_ORIGIN: + if (ignore_system_lyxrc || + save_origin != system_lyxrc.save_origin) { + os << "\\save_origin " << convert(save_origin) << '\n'; + } + if (tag != RC_LAST) + break; case RC_BACKUPDIR_PATH: if (ignore_system_lyxrc || backupdir_path != system_lyxrc.backupdir_path) { @@ -3022,6 +3034,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_PRINT_ADAPTOUTPUT: case LyXRC::RC_PRINT_COMMAND: case LyXRC::RC_SAVE_COMPRESSED: + case LyXRC::RC_SAVE_ORIGIN: case LyXRC::RC_SCREEN_DPI: case LyXRC::RC_SCREEN_FONT_ROMAN: case LyXRC::RC_SCREEN_FONT_ROMAN_FOUNDRY: diff --git a/src/LyXRC.h b/src/LyXRC.h index 613a9c7f06..9392a0ef6d 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -148,6 +148,7 @@ public: RC_PRINT_ADAPTOUTPUT, RC_PRINT_COMMAND, RC_SAVE_COMPRESSED, + RC_SAVE_ORIGIN, RC_SCREEN_DPI, RC_SCREEN_FONT_ROMAN, RC_SCREEN_FONT_ROMAN_FOUNDRY, @@ -320,6 +321,8 @@ public: bool load_session; /// do we save new documents as compressed by default bool save_compressed; + /// whether or not to save the document dir in the file + bool save_origin; /// shall a backup file be created bool make_backup; /// A directory for storing backup files diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 23e42f1045..2bb538eb00 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -2628,6 +2628,8 @@ PrefDocHandling::PrefDocHandling(GuiPreferences * form) this, SIGNAL(changed())); connect(saveCompressedCB, SIGNAL(clicked()), this, SIGNAL(changed())); + connect(saveOriginCB, SIGNAL(clicked()), + this, SIGNAL(changed())); } @@ -2639,6 +2641,7 @@ void PrefDocHandling::applyRC(LyXRC & rc) const rc.autosave = autoSaveCB->isChecked() ? autoSaveSB->value() * 60 : 0; rc.make_backup = backupCB->isChecked(); rc.save_compressed = saveCompressedCB->isChecked(); + rc.save_origin = saveOriginCB->isChecked(); rc.open_buffers_in_tabs = openDocumentsInTabsCB->isChecked(); rc.single_instance = singleInstanceCB->isChecked(); rc.single_close_tab_button = singleCloseTabButtonCB->isChecked(); @@ -2674,6 +2677,7 @@ void PrefDocHandling::updateRC(LyXRC const & rc) autoSaveSB->setEnabled(autosave); backupCB->setChecked(rc.make_backup); saveCompressedCB->setChecked(rc.save_compressed); + saveOriginCB->setChecked(rc.save_origin); openDocumentsInTabsCB->setChecked(rc.open_buffers_in_tabs); singleInstanceCB->setChecked(rc.single_instance && !rc.lyxpipes.empty()); singleInstanceCB->setEnabled(!rc.lyxpipes.empty()); diff --git a/src/frontends/qt4/ui/PrefDocHandlingUi.ui b/src/frontends/qt4/ui/PrefDocHandlingUi.ui index 265172b491..3fdd71680a 100644 --- a/src/frontends/qt4/ui/PrefDocHandlingUi.ui +++ b/src/frontends/qt4/ui/PrefDocHandlingUi.ui @@ -149,6 +149,16 @@ + + + + If this is checked, the document directory path will be saved in the document. This allows moving the document elsewhere and still finding the included files. + + + Save the &document directory path + + + @@ -261,6 +271,7 @@ autoSaveCB autoSaveSB saveCompressedCB + saveOriginCB qt_i18n.h -- 2.39.2