]> git.lyx.org Git - lyx.git/blobdiff - src/lyxrc.C
Fix #1736
[lyx.git] / src / lyxrc.C
index 9481951d056352962e53e1dff86491c599e7d143..ea6f37b002281cb2073bb1b0ed6de2948b450f15 100644 (file)
 #include "converter.h"
 #include "format.h"
 #include "gettext.h"
+#include "lastfiles.h"
 #include "LColor.h"
 #include "lyxlex.h"
 #include "lyxfont.h"
+#include "mover.h"
 
 #include "graphics/GraphicsTypes.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
-#include "support/translator.h"
 #include "support/tostr.h"
 #include "support/userinfo.h"
 
 using lyx::support::ascii_lowercase;
+using lyx::support::bformat;
 using lyx::support::ExpandPath;
 using lyx::support::GetEnv;
 using lyx::support::LibFileSearch;
@@ -70,6 +72,7 @@ keyword_item lyxrcTags[] = {
        { "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES },
        { "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND },
        { "\\converter", LyXRC::RC_CONVERTER },
+       { "\\copier", LyXRC::RC_COPIER },
        { "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR },
        { "\\custom_export_command", LyXRC::RC_CUSTOM_EXPORT_COMMAND },
        { "\\custom_export_format", LyXRC::RC_CUSTOM_EXPORT_FORMAT },
@@ -82,6 +85,7 @@ keyword_item lyxrcTags[] = {
        { "\\escape_chars", LyXRC::RC_ESC_CHARS },
        { "\\font_encoding", LyXRC::RC_FONT_ENCODING },
        { "\\format", LyXRC::RC_FORMAT },
+       { "\\index_command", LyXRC::RC_INDEX_COMMAND },
        { "\\input", LyXRC::RC_INPUT },
        { "\\kbmap", LyXRC::RC_KBMAP },
        { "\\kbmap_primary", LyXRC::RC_KBMAP_PRIMARY },
@@ -161,6 +165,7 @@ keyword_item lyxrcTags[] = {
        { "\\user_email", LyXRC::RC_USER_EMAIL },
        { "\\user_name", LyXRC::RC_USER_NAME },
        { "\\view_dvi_paper_option", LyXRC::RC_VIEWDVI_PAPEROPTION },
+       // compatibility with versions older than 1.4.0 only
        { "\\viewer" ,LyXRC::RC_VIEWER},
        { "\\wheel_jump", LyXRC::RC_WHEEL_JUMP }
 };
@@ -204,6 +209,7 @@ void LyXRC::setDefaults() {
        chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38";
        bibtex_command = "bibtex";
        fontenc = "default";
+       index_command = "makeindex -c -q";
        dpi = 75;
        // Because a screen typically is wider than a piece of paper:
        zoom = 150;
@@ -232,7 +238,7 @@ void LyXRC::setDefaults() {
        auto_region_delete = true;
        auto_reset_options = false;
        ascii_linelen = 65;
-       num_lastfiles = 4;
+       num_lastfiles = maxlastfiles;
        check_lastfiles = true;
        make_backup = true;
        backupdir_path.erase();
@@ -264,16 +270,13 @@ void LyXRC::setDefaults() {
        cursor_follows_scrollbar = false;
        dialogs_iconify_with_main = false;
        label_init_length = 3;
-       preview = false;
+       preview = PREVIEW_OFF;
        preview_hashed_labels  = false;
        preview_scale_factor = 0.9;
 
        user_name = lyx::support::user_name();
 
        user_email = lyx::support::user_email();
-
-       if (user_email.empty())
-               user_email = _("email address unknown");
 }
 
 
@@ -587,6 +590,12 @@ int LyXRC::read(LyXLex & lexrc)
                        }
                        break;
 
+               case RC_INDEX_COMMAND:
+                       if (lexrc.next()) {
+                               index_command = lexrc.getString();
+                       }
+                       break;
+
                case RC_SCREEN_DPI:
                        if (lexrc.next()) {
                                dpi = lexrc.getInteger();
@@ -786,9 +795,9 @@ int LyXRC::read(LyXLex & lexrc)
                                break;
                        }
 
-                       LColor::color const col = 
+                       LColor::color const col =
                                lcolor.getFromLyXName(lyx_name);
-                       if (col == LColor::none || 
+                       if (col == LColor::none ||
                            col == LColor::inherit ||
                            col == LColor::ignore)
                                break;
@@ -957,6 +966,18 @@ int LyXRC::read(LyXLex & lexrc)
                        }
                        break;
 
+               case RC_COPIER: {
+                       string fmt, command;
+                       if (lexrc.next()) {
+                               fmt = lexrc.getString();
+                       }
+                       if (lexrc.next()) {
+                               command = lexrc.getString();
+                       }
+                       movers.set(fmt, command);
+                       break;
+               }
+
                case RC_CONVERTER: {
                        string from, to, command, flags;
                        if (lexrc.next()) {
@@ -979,6 +1000,7 @@ int LyXRC::read(LyXLex & lexrc)
                        }
                        break;
                }
+               // compatibility with versions older than 1.4.0 only
                case RC_VIEWER: {
                        string format, command;
                        if (lexrc.next()) {
@@ -1006,6 +1028,29 @@ int LyXRC::read(LyXLex & lexrc)
                        if (lexrc.next()) {
                                shortcut = lexrc.getString();
                        }
+                       string viewer, editor;
+                       // Hack to ensure compatibility with versions older
+                       // than 1.4.0
+                       int le = lexrc.lex();
+                       if (le != LyXLex::LEX_FEOF && le != LyXLex::LEX_UNDEF) {
+                               viewer = lexrc.getString();
+                               if (le == LyXLex::LEX_DATA) {
+                                       if (token(viewer, ' ', 0) == "none")
+                                               viewer.erase();
+                                       if (lexrc.next()) {
+                                               editor = lexrc.getString();
+                                               if (token(editor, ' ', 0) == "none")
+                                                       editor.erase();
+                                       }
+                               } else {
+                                       // We have got a known token.
+                                       // Therefore this is an old style
+                                       // format definition without
+                                       // viewer and editor.
+                                       lexrc.pushToken(viewer);
+                                       viewer.erase();
+                               }
+                       }
                        if (prettyname.empty()) {
                                if (converters.formatIsUsed(format)) {
                                        lyxerr << "Can't delete format "
@@ -1015,7 +1060,7 @@ int LyXRC::read(LyXLex & lexrc)
                                }
                        } else {
                                formats.add(format, extension, prettyname,
-                                           shortcut);
+                                           shortcut, viewer, editor);
                        }
                        break;
                }
@@ -1039,7 +1084,18 @@ int LyXRC::read(LyXLex & lexrc)
 
                case RC_PREVIEW:
                        if (lexrc.next()) {
-                               preview = lexrc.getBool();
+                               string const tmp = lexrc.getString();
+                               if (tmp == "true" || tmp == "on")
+                                       preview = PREVIEW_ON;
+                               else if (tmp == "no_math")
+                                       preview = PREVIEW_NO_MATH;
+                               else {
+                                       preview = PREVIEW_OFF;
+                                       if (tmp != "false" && tmp != "off")
+                                               lyxerr << "Unrecognized "
+                                                       "preview status \""
+                                                      << tmp << '\n' << endl;
+                               }
                        }
                        break;
 
@@ -1094,6 +1150,23 @@ void LyXRC::print() const
 }
 
 
+struct SameMover {
+       typedef std::pair<std::string, SpecialisedMover> Data;
+
+       SameMover(Data const & comparison)
+               : comparison_(comparison) {}
+
+       bool operator()(Data const & data) const
+       {
+               return data.first == comparison_.first &&
+                       data.second.command() == comparison_.second.command();
+       }
+
+private:
+       Data comparison_;
+};
+
+
 void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
 {
        os << "### This file is part of\n"
@@ -1212,6 +1285,11 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
                    bibtex_command != system_lyxrc.bibtex_command) {
                        os << "\\bibtex_command \"" << bibtex_command << "\"\n";
                }
+       case RC_INDEX_COMMAND:
+               if (ignore_system_lyxrc ||
+                   index_command != system_lyxrc.index_command) {
+                       os << "\\index_command \"" << index_command << "\"\n";
+               }
        case RC_KBMAP:
                if (ignore_system_lyxrc ||
                    use_kbmap != system_lyxrc.use_kbmap) {
@@ -1261,7 +1339,19 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
        case RC_PREVIEW:
                if (ignore_system_lyxrc ||
                    preview != system_lyxrc.preview) {
-                       os << "\\preview " << tostr(preview) << '\n';
+                       string status;
+                       switch (preview) {
+                       case PREVIEW_ON:
+                               status = "on";
+                               break;
+                       case PREVIEW_NO_MATH:
+                               status = "no_math";
+                               break;
+                       case PREVIEW_OFF:
+                               status = "off";
+                               break;
+                       }
+                       os << "\\preview " << status << '\n';
                }
 
        case RC_PREVIEW_HASHED_LABELS:
@@ -1801,7 +1891,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
                   << "#\n\n";
 
        case RC_FORMAT:
-               // Look for deleted formats
+               // New/modifed formats
                for (Formats::const_iterator cit = formats.begin();
                     cit != formats.end(); ++cit) {
                        Format const * format =
@@ -1809,29 +1899,25 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
                        if (!format ||
                            format->extension() != cit->extension() ||
                            format->prettyname() != cit->prettyname() ||
-                           format->shortcut() != cit->shortcut())
+                           format->shortcut() != cit->shortcut() ||
+                           format->viewer() != cit->viewer() ||
+                           format->editor() != cit->editor())
                                os << "\\format \"" << cit->name() << "\" \""
                                   << cit->extension() << "\" \""
                                   << cit->prettyname() << "\" \""
-                                  << cit->shortcut() << "\"\n";
+                                  << cit->shortcut() << "\" \""
+                                  << cit->viewer() << "\" \""
+                                  << cit->editor() << "\"\n";
                }
 
-               // New/modifed formats
+               // Look for deleted formats
                for (Formats::const_iterator cit = system_formats.begin();
                     cit != system_formats.end(); ++cit)
                        if (!formats.getFormat(cit->name()))
                                os << "\\format \"" << cit->name()
-                                  << "\" \"\" \"\" \"\"\n";
+                                  << "\" \"\" \"\" \"\" \"\" \"\"\n";
        case RC_VIEWER:
-               for (Formats::const_iterator cit = formats.begin();
-                    cit != formats.end(); ++cit) {
-                       Format const * format =
-                               system_formats.getFormat(cit->name());
-                       if ((!format || format->viewer() != cit->viewer()) &&
-                           (format || !cit->viewer().empty()))
-                               os << "\\viewer \"" << cit->name() << "\" \""
-                                  << cit->viewer() << "\"\n";
-               }
+               // Ignore it
 
                os << "\n#\n"
                   << "# CONVERTERS SECTION ##########################\n"
@@ -1860,7 +1946,34 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
                                os << "\\converter \"" << cit->from
                                   << "\" \"" << cit->to << "\" \"\" \"\"\n";
 
+       case RC_COPIER:
+               os << "\n#\n"
+                  << "# COPIERS SECTION ##########################\n"
+                  << "#\n\n";
+
+               // Look for new movers
+               Movers::iterator const sysbegin = system_movers.begin();
+               Movers::iterator const sysend = system_movers.end();
+
+               for (Movers::iterator it = movers.begin(), end = movers.end();
+                    it != end; ++it) {
+                       Movers::iterator const sysit =
+                               std::find_if(sysbegin, sysend, SameMover(*it));
+                       if (sysit == sysend) {
+                               std::string const & fmt = it->first;
+                               std::string const & command =
+                                       it->second.command();
+
+                               os << "\\copier " << fmt
+                                  << " \"" << command << "\"\n";
+                       }
+               }
+
+               // We don't actually delete SpecialisedMover(s) from the
+               // map, just clear their 'command', so there's no need
+               // to test for anything else.
        }
+
        os.flush();
 }
 
@@ -2059,7 +2172,7 @@ string const LyXRC::getDescription(LyXRCTags tag)
                break;
 
        case RC_NUMLASTFILES:
-               str = _("Maximal number of lastfiles. Up to 9 can appear in the file menu.");
+               str = bformat(_("Maximal number of lastfiles. Up to %1$s can appear in the file menu."), tostr(maxlastfiles));
                break;
 
        case RC_CHECKLASTFILES:
@@ -2110,7 +2223,11 @@ string const LyXRC::getDescription(LyXRCTags tag)
                break;
 
        case RC_BIBTEX_COMMAND:
-               str = _("Define the options of bibtex (cf. man bibtex) or select and alternative compiler (e.g. mlbibtex or bibulus).");
+               str = _("Define the options of bibtex (cf. man bibtex) or select an alternative compiler (e.g. mlbibtex or bibulus).");
+               break;
+
+       case RC_INDEX_COMMAND:
+               str = _("Define the options of makeindex (cf. man makeindex) or select an alternative compiler. E.g., using xindy/make-rules, the command string would be \"makeindex.sh -m $$lang\".");
                break;
 
        case RC_CURSOR_FOLLOWS_SCROLLBAR: