]> git.lyx.org Git - lyx.git/blobdiff - src/LyXRC.cpp
LyXRC: allow space in {editor,viewer}_alternatives
[lyx.git] / src / LyXRC.cpp
index fa86a02fd16bbbd9a007e022f2439c3133c6afd2..24967a3dab7a79e5a2d0ebcefe675a1f8536ece1 100644 (file)
@@ -55,7 +55,7 @@ namespace os = support::os;
 
 namespace {
 
-static unsigned int const LYXRC_FILEFORMAT = 6; // younes: add use_qimage option
+static unsigned int const LYXRC_FILEFORMAT = 10; // tommaso: new prefs option: close_buffer_with_last_view
 
 // when adding something to this array keep it sorted!
 LexerKeyword lyxrcTags[] = {
@@ -73,6 +73,7 @@ LexerKeyword lyxrcTags[] = {
        { "\\bind_file", LyXRC::RC_BINDFILE },
        { "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES },
        { "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND },
+       { "\\close_buffer_with_last_view", LyXRC::RC_CLOSE_BUFFER_WITH_LAST_VIEW },
        { "\\completion_cursor_text", LyXRC::RC_COMPLETION_CURSOR_TEXT },
        { "\\completion_inline_delay", LyXRC::RC_COMPLETION_INLINE_DELAY },
        { "\\completion_inline_dots", LyXRC::RC_COMPLETION_INLINE_DOTS },
@@ -91,7 +92,6 @@ LexerKeyword lyxrcTags[] = {
        { "\\date_insert_format", LyXRC::RC_DATE_INSERT_FORMAT },
        { "\\def_file", LyXRC::RC_DEFFILE },
        { "\\default_decimal_point", LyXRC::RC_DEFAULT_DECIMAL_POINT },
-       { "\\default_language", LyXRC::RC_DEFAULT_LANGUAGE },
        { "\\default_length_unit", LyXRC::RC_DEFAULT_LENGTH_UNIT },
        { "\\default_view_format", LyXRC::RC_DEFAULT_VIEW_FORMAT },
        { "\\dialogs_iconify_with_main", LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN },
@@ -319,7 +319,6 @@ void LyXRC::setDefaults()
        language_command_local = "\\foreignlanguage{$$lang}{";
        sort_layouts = false;
        group_layouts = true;
-       default_language = "english";
        gui_language = "auto";
        show_banner = true;
        windows_style_tex_paths = false;
@@ -372,6 +371,7 @@ void LyXRC::setDefaults()
        default_decimal_point = ".";
        default_length_unit = Length::CM;
        cursor_width = 1;
+       close_buffer_with_last_view = "yes";
 }
 
 
@@ -1044,6 +1044,9 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                case RC_VISUAL_CURSOR:
                        lexrc >> visual_cursor;
                        break;
+               case RC_CLOSE_BUFFER_WITH_LAST_VIEW:
+                       lexrc >> close_buffer_with_last_view;
+                       break;
                case RC_AUTO_NUMBER:
                        lexrc >> auto_number;
                        break;
@@ -1085,28 +1088,29 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                        break;
                }
                case RC_FILEFORMAT: {
+                       bool ok = true;
                        string format, extensions, prettyname, shortcut;
-                       lexrc >> format >> extensions >> prettyname >> shortcut;
+                       if (!(lexrc >> format >> extensions))
+                               ok = false;
+                       if (ok && lexrc.next(true))
+                               prettyname  = lexrc.getString();
+                       else
+                               ok = false;
+                       if (ok)
+                               if(!(lexrc >> shortcut))
+                                       ok = false;
                        string viewer, editor;
-                       if (lexrc.next(true))
+                       if (ok && lexrc.next(true))
                                viewer = lexrc.getString();
-                       if (lexrc.next(true))
+                       else
+                               ok = false;
+                       if (ok && lexrc.next(true))
                                editor = lexrc.getString();
-                       string flags;
-                       // Hack to ensure compatibility with versions older
-                       // than 1.5.0
-                       int le = lexrc.lex();
-                       if (le != Lexer::LEX_FEOF && le != Lexer::LEX_UNDEF) {
-                               flags = lexrc.getString();
-                               if (le != Lexer::LEX_DATA) {
-                                       // We have got a known token.
-                                       // Therefore this is an old style
-                                       // format definition without
-                                       // flags.
-                                       lexrc.pushToken(flags);
-                                       flags.erase();
-                               }
-                       }
+                       else
+                               ok = false;
+                       string flags, mime;
+                       if (!(lexrc >> flags >> mime))
+                               ok = false;
                        int flgs = Format::none;
                        while (!flags.empty()) {
                                string flag;
@@ -1124,32 +1128,30 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                                               << flag << "' for format `"
                                               << format << "'.");
                        }
-                       if (prettyname.empty()) {
+                       if (!ok)
+                               LYXERR0("Syntax error in format " << format);
+                       else if (prettyname.empty()) {
                                if (theConverters().formatIsUsed(format))
                                        LYXERR0("Can't delete format " << format);
                                else
                                        formats.erase(format);
                        } else {
                                formats.add(format, extensions, prettyname,
-                                           shortcut, viewer, editor, flgs);
+                                           shortcut, viewer, editor, mime, flgs);
                        }
                        break;
                }
                case RC_VIEWER_ALTERNATIVES:  {
                        string format, command;
-                       if (lexrc.next())
-                               format = lexrc.getString();
-                       if (lexrc.eatLine())
-                               command = lexrc.getString();
+                       lexrc >> format;
+                       lexrc >> command;
                        viewer_alternatives[format].insert(command);
                        break;
                }
                case RC_EDITOR_ALTERNATIVES:  {
                        string format, command;
-                       if (lexrc.next())
-                               format = lexrc.getString();
-                       if (lexrc.eatLine())
-                               command = lexrc.getString();
+                       lexrc >> format;
+                       lexrc >> command;
                        editor_alternatives[format].insert(command);
                        break;
                }
@@ -1158,10 +1160,6 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
                        lexrc >> default_view_format;
                        break;
 
-               case RC_DEFAULT_LANGUAGE:
-                       lexrc >> default_language;
-                       break;
-
                case RC_GUI_LANGUAGE:
                        lexrc >> gui_language;
                        break;
@@ -2531,6 +2529,14 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
+       case RC_CLOSE_BUFFER_WITH_LAST_VIEW:
+               if (ignore_system_lyxrc ||
+                       close_buffer_with_last_view != system_lyxrc.close_buffer_with_last_view) {
+                       os << "# When closing last view, buffer closes (yes), hides (no), or ask the user (ask)\n";
+                       os << "\\close_buffer_with_last_view " << close_buffer_with_last_view << '\n';
+               }
+               if (tag != RC_LAST)
+                       break;
        case RC_LANGUAGE_CUSTOM_PACKAGE:
                if (ignore_system_lyxrc ||
                    language_custom_package != system_lyxrc.language_custom_package) {
@@ -2636,13 +2642,6 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                }
                if (tag != RC_LAST)
                        break;
-       case RC_DEFAULT_LANGUAGE:
-               if (ignore_system_lyxrc ||
-                   default_language != system_lyxrc.default_language) {
-                       os << "\\default_language " << default_language << '\n';
-               }
-               if (tag != RC_LAST)
-                       break;
        case RC_GUI_LANGUAGE:
                if (ignore_system_lyxrc ||
                    gui_language != system_lyxrc.gui_language) {
@@ -2711,7 +2710,8 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                            format->editor() != cit->editor() ||
                            format->documentFormat() != cit->documentFormat() ||
                            format->vectorFormat() != cit->vectorFormat() ||
-                           format->inExportMenu() != cit->inExportMenu()) {
+                           format->inExportMenu() != cit->inExportMenu() ||
+                           format->mime() != cit->mime()) {
                                os << "\\format \"" << cit->name() << "\" \""
                                   << cit->extensions() << "\" \""
                                   << cit->prettyname() << "\" \""
@@ -2729,7 +2729,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                                        flags.push_back("menu=export");
 
                                os << getStringFromVector(flags);
-                               os << "\"\n";
+                               os << "\" \"" << cit->mime() << "\"\n";
                        }
                }
 
@@ -2738,7 +2738,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                     cit != system_formats.end(); ++cit)
                        if (!formats.getFormat(cit->name()))
                                os << "\\format \"" << cit->name()
-                                  << "\" \"\" \"\" \"\" \"\" \"\" \"\"\n";
+                                  << "\" \"\" \"\" \"\" \"\" \"\" \"\" \"\"\n";
                if (tag != RC_LAST)
                        break;
        case RC_VIEWER_ALTERNATIVES: {
@@ -2760,7 +2760,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                                    || sysfmt == sysend               // format not found
                                         || sysfmt->second.count(cmd) == 0 // this command not found
                                   )
-                                       os << "\\viewer_alternatives " << fmt << " " << cmd << "\n";
+                                       os << "\\viewer_alternatives " << fmt << " \"" << cmd << "\"\n";
                        }
                }
                if (tag != RC_LAST)
@@ -2785,7 +2785,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
                                    || sysfmt == sysend               // format not found
                                    || sysfmt->second.count(cmd) == 0 // this command not found
                                   )
-                                       os << "\\editor_alternatives " << fmt << " " << cmd << "\n";
+                                       os << "\\editor_alternatives " << fmt << " \"" << cmd << "\"\n";
                        }
                }
                if (tag != RC_LAST)
@@ -2912,7 +2912,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
        case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
        case LyXRC::RC_DATE_INSERT_FORMAT:
-       case LyXRC::RC_DEFAULT_LANGUAGE:
        case LyXRC::RC_GUI_LANGUAGE:
        case LyXRC::RC_DEFAULT_VIEW_FORMAT:
        case LyXRC::RC_DEFFILE:
@@ -3035,6 +3034,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_FULL_SCREEN_TOOLBARS:
        case LyXRC::RC_FULL_SCREEN_WIDTH:
        case LyXRC::RC_VISUAL_CURSOR:
+       case LyXRC::RC_CLOSE_BUFFER_WITH_LAST_VIEW:
        case LyXRC::RC_VIEWER:
        case LyXRC::RC_VIEWER_ALTERNATIVES:
        case LyXRC::RC_FORWARD_SEARCH_DVI:
@@ -3149,10 +3149,6 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = _("The default format used with LFUN_BUFFER_[VIEW|UPDATE].");
                break;
 
-       case RC_DEFAULT_LANGUAGE:
-               str = _("New documents will be assigned this language.");
-               break;
-
        case RC_DIALOGS_ICONIFY_WITH_MAIN:
                str = _("Iconify the dialogs when the main window is iconified. (Affects only dialogs shown after the change has been made.)");
                break;
@@ -3401,6 +3397,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
                str = _("Select to have visual bidi cursor movement, unselect for logical movement.");
                break;
 
+       case RC_CLOSE_BUFFER_WITH_LAST_VIEW:
+               str = _("Specify whether, closing the last view of an open document, LyX should close the document (yes), hide it (no), or ask the user (ask).");
+               break;
+
        case RC_SCREEN_DPI:
                str = _("DPI (dots per inch) of your monitor is auto-detected by LyX. If that goes wrong, override the setting here.");
                break;