The attached patch lets you select a "default format" in Prefs>Output>Format. This format will be used on [master-]buffer-{view|update} if no argument is given. I have set the default to PDF (pdflatex).
Currently, only the default format for the latex/pdflatex backend can be selected. For the other backends, LyX currently selects the first format it finds. This works for XeTeX (where there's only one format anyway). Other backends need to be checked and adapted, if necessary. Furthermore, I propose to restructure the View menu as follows: View ... View Update View Master Document Update Master Document View (other formats) > Update (other formats) > (of course, the master entries are only there if the doc is a child). The aims of this change are: * GUI improvement: - the top level menu only has your preferred format, which is especially helpful for beginners, I think (at this was put forward in a past discussion IIRC) - we can finally add master-buffer-* without cluttering the menu - we can add an icon for the default format (currently, we only have icons for selected formats, e.g. not for pd2pdf) and for master-buffer-*. This is the first step only. My further plans are: * making the default format customizable on a per-document basis * making the default format customizable by the textclass (think of powerdot that does not work with pdflatex and needs ps2pdf). This second step still needs some pondering, though. Thoughts? BTW, I stumbled over the RCs "custom_export_format" and "custom_view_format", which seem both unused nowadays. Can I remove them? Jürgen
Index: lib/ui/stdmenus.inc =================================================================== --- lib/ui/stdmenus.inc (Revision 29119) +++ lib/ui/stdmenus.inc (Arbeitskopie) @@ -297,11 +297,15 @@ Item "Fold Math Macro" "math-macro-fold" Separator Item "View Source|S" "dialog-toggle view-source" - Submenu "Update|U" "view_update" - ViewFormats + Item "View|V" "buffer-view" + Item "Update|U" "buffer-update" + OptItem "View Master Document|M" "master-buffer-view" + OptItem "Update Master Document|a" "master-buffer-update" + Submenu "View (other formats)|f" "view_others" + Submenu "Update (other formats)|p" "view_update" Separator Item "Split View Into Left And Right Half|i" "split-view horizontal" - Item "Split View Into Upper And Lower Half|V" "split-view vertical" + Item "Split View Into Upper And Lower Half|e" "split-view vertical" Item "Close Tab Group|G" "close-tab-group" Item "Fullscreen|l" "ui-toggle fullscreen" Submenu "Toolbars|b" "toolbars" @@ -309,6 +313,10 @@ Documents End + Menu "view_others" + ViewFormats + End + Menu "view_update" UpdateFormats End Index: src/LyXRC.h =================================================================== --- src/LyXRC.h (Revision 29119) +++ src/LyXRC.h (Arbeitskopie) @@ -69,6 +69,7 @@ RC_DATE_INSERT_FORMAT, RC_DEFFILE, RC_DEFAULT_LANGUAGE, + RC_DEFAULT_VIEW_FORMAT, RC_GUI_LANGUAGE, RC_DEFAULT_PAPERSIZE, RC_DIALOGS_ICONIFY_WITH_MAIN, @@ -371,6 +372,8 @@ /// std::string gui_language; /// + std::string default_view_format; + /// bool mac_like_word_movement; /// bool cursor_follows_scrollbar; Index: src/Buffer.h =================================================================== --- src/Buffer.h (Revision 29119) +++ src/Buffer.h (Arbeitskopie) @@ -463,6 +463,8 @@ /// return the format of the buffer on a string std::string bufferFormat() const; + /// return the default output format of the current backend + std::string getDefaultOutputFormat() const; /// bool doExport(std::string const & format, bool put_in_tempdir, Index: src/frontends/qt4/GuiPrefs.cpp =================================================================== --- src/frontends/qt4/GuiPrefs.cpp (Revision 29119) +++ src/frontends/qt4/GuiPrefs.cpp (Arbeitskopie) @@ -1474,6 +1474,8 @@ this, SLOT(updatePrettyname())); connect(formatsCB->lineEdit(), SIGNAL(textEdited(QString)), this, SIGNAL(changed())); + connect(defaultFormatCB, SIGNAL(activated(QString)), + this, SIGNAL(changed())); } @@ -1492,36 +1494,55 @@ }; // namespace anon -void PrefFileformats::apply(LyXRC & /*rc*/) const +void PrefFileformats::apply(LyXRC & rc) const { + QString const default_format = defaultFormatCB->itemData( + defaultFormatCB->currentIndex()).toString(); + rc.default_view_format = fromqstr(default_format); } -void PrefFileformats::update(LyXRC const & /*rc*/) +void PrefFileformats::update(LyXRC const & rc) { + bool const init = defaultFormatCB->currentText().isEmpty(); updateView(); + if (init) { + int const pos = defaultFormatCB->findData(toqstr( + rc.default_view_format)); + defaultFormatCB->setCurrentIndex(pos); + } } void PrefFileformats::updateView() { QString const current = formatsCB->currentText(); + QString const current_def = defaultFormatCB->currentText(); // update combobox with formats formatsCB->blockSignals(true); + defaultFormatCB->blockSignals(true); formatsCB->clear(); form_->formats().sort(); Formats::const_iterator cit = form_->formats().begin(); Formats::const_iterator end = form_->formats().end(); - for (; cit != end; ++cit) + for (; cit != end; ++cit) { formatsCB->addItem(qt_(cit->prettyname()), - QVariant(form_->formats().getNumber(cit->name()))); + QVariant(form_->formats().getNumber(cit->name()))); + if (form_->converters().isReachable("latex", cit->name()) + || form_->converters().isReachable("pdflatex", cit->name())) + defaultFormatCB->addItem(qt_(cit->prettyname()), + QVariant(toqstr(cit->name()))); + } // restore selection - int const item = formatsCB->findText(current, Qt::MatchExactly); + int item = formatsCB->findText(current, Qt::MatchExactly); formatsCB->setCurrentIndex(item < 0 ? 0 : item); on_formatsCB_currentIndexChanged(item < 0 ? 0 : item); + item = defaultFormatCB->findText(current_def, Qt::MatchExactly); + defaultFormatCB->setCurrentIndex(item < 0 ? 0 : item); formatsCB->blockSignals(false); + defaultFormatCB->blockSignals(false); } Index: src/frontends/qt4/ui/PrefFileformatsUi.ui =================================================================== --- src/frontends/qt4/ui/PrefFileformatsUi.ui (Revision 29119) +++ src/frontends/qt4/ui/PrefFileformatsUi.ui (Arbeitskopie) @@ -5,8 +5,8 @@ <rect> <x>0</x> <y>0</y> - <width>414</width> - <height>322</height> + <width>427</width> + <height>413</height> </rect> </property> <property name="windowTitle" > @@ -19,6 +19,53 @@ <property name="spacing" > <number>6</number> </property> + <item row="10" column="0" colspan="4" > + <widget class="QGroupBox" name="defaultFormatGB" > + <property name="toolTip" > + <string>Specify the default output format when using (PDF)LaTeX</string> + </property> + <property name="title" > + <string>Default Format</string> + </property> + <property name="flat" > + <bool>true</bool> + </property> + <layout class="QGridLayout" > + <property name="margin" > + <number>9</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item row="0" column="0" > + <widget class="QLabel" name="defaultFormatLA" > + <property name="text" > + <string>De&fault Output Format:</string> + </property> + <property name="buddy" > + <cstring>defaultFormatCB</cstring> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QComboBox" name="defaultFormatCB" /> + </item> + </layout> + </widget> + </item> + <item row="9" column="1" > + <spacer> + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" > + <size> + <width>124</width> + <height>21</height> + </size> + </property> + </spacer> + </item> <item row="8" column="1" colspan="3" > <widget class="QLineEdit" name="copierED" /> </item> @@ -149,19 +196,6 @@ <item row="4" column="1" > <widget class="QLineEdit" name="extensionED" /> </item> - <item row="9" column="1" > - <spacer> - <property name="orientation" > - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" > - <size> - <width>168</width> - <height>21</height> - </size> - </property> - </spacer> - </item> <item row="8" column="0" > <widget class="QLabel" name="label" > <property name="text" > Index: src/frontends/qt4/Menus.cpp =================================================================== --- src/frontends/qt4/Menus.cpp (Revision 29119) +++ src/frontends/qt4/Menus.cpp (Arbeitskopie) @@ -791,8 +791,10 @@ label += "..."; break; case MenuItem::ViewFormats: + case MenuItem::UpdateFormats: + if ((*fit)->name() == buf->getDefaultOutputFormat()) + continue; case MenuItem::ExportFormats: - case MenuItem::UpdateFormats: if (!(*fit)->documentFormat()) continue; break; Index: src/LyXFunc.cpp =================================================================== --- src/LyXFunc.cpp (Revision 29123) +++ src/LyXFunc.cpp (Arbeitskopie) @@ -588,10 +588,17 @@ break; } + case LFUN_MASTER_BUFFER_UPDATE: + case LFUN_MASTER_BUFFER_VIEW: + if (!buf->parent()) { + enable = false; + break; + } case LFUN_BUFFER_UPDATE: - case LFUN_BUFFER_VIEW: - case LFUN_MASTER_BUFFER_UPDATE: - case LFUN_MASTER_BUFFER_VIEW: { + case LFUN_BUFFER_VIEW: { + string format = to_utf8(cmd.argument()); + if (cmd.argument().empty()) + format = buf->getDefaultOutputFormat(); typedef vector<Format const *> Formats; Formats formats; formats = buf->exportableFormats(true); @@ -599,7 +606,7 @@ Formats::const_iterator end = formats.end(); enable = false; for (; fit != end ; ++fit) { - if ((*fit)->name() == to_utf8(cmd.argument())) + if ((*fit)->name() == format) enable = true; } break; @@ -878,25 +885,41 @@ break; } - case LFUN_BUFFER_UPDATE: + case LFUN_BUFFER_UPDATE: { LASSERT(lyx_view_ && buffer, /**/); - buffer->doExport(argument, true); + string format = argument; + if (argument.empty()) + format = buffer->getDefaultOutputFormat(); + buffer->doExport(format, true); break; + } - case LFUN_BUFFER_VIEW: + case LFUN_BUFFER_VIEW: { LASSERT(lyx_view_ && buffer, /**/); - buffer->preview(argument); + string format = argument; + if (argument.empty()) + format = buffer->getDefaultOutputFormat(); + buffer->preview(format); break; + } - case LFUN_MASTER_BUFFER_UPDATE: + case LFUN_MASTER_BUFFER_UPDATE: { LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/); - buffer->masterBuffer()->doExport(argument, true); + string format = argument; + if (argument.empty()) + format = buffer->masterBuffer()->getDefaultOutputFormat(); + buffer->masterBuffer()->doExport(format, true); break; + } - case LFUN_MASTER_BUFFER_VIEW: + case LFUN_MASTER_BUFFER_VIEW: { LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/); - buffer->masterBuffer()->preview(argument); + string format = argument; + if (argument.empty()) + format = buffer->masterBuffer()->getDefaultOutputFormat(); + buffer->masterBuffer()->preview(format); break; + } case LFUN_BUILD_PROGRAM: LASSERT(lyx_view_ && buffer, /**/); @@ -1982,6 +2005,7 @@ case LyXRC::RC_DEFAULT_LANGUAGE: case LyXRC::RC_GUI_LANGUAGE: case LyXRC::RC_DEFAULT_PAPERSIZE: + case LyXRC::RC_DEFAULT_VIEW_FORMAT: case LyXRC::RC_DEFFILE: case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN: case LyXRC::RC_DISPLAY_GRAPHICS: Index: src/LyXRC.cpp =================================================================== --- src/LyXRC.cpp (Revision 29119) +++ src/LyXRC.cpp (Arbeitskopie) @@ -84,6 +84,7 @@ { "\\def_file", LyXRC::RC_DEFFILE }, { "\\default_language", LyXRC::RC_DEFAULT_LANGUAGE }, { "\\default_papersize", LyXRC::RC_DEFAULT_PAPERSIZE }, + { "\\default_view_format", LyXRC::RC_DEFAULT_VIEW_FORMAT }, { "\\dialogs_iconify_with_main", LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN }, { "\\display_graphics", LyXRC::RC_DISPLAY_GRAPHICS }, { "\\document_path", LyXRC::RC_DOCUMENTPATH }, @@ -227,6 +228,7 @@ view_dvi_paper_option.erase(); default_papersize = PAPER_DEFAULT; custom_export_format = "ps"; + default_view_format = "pdf2"; chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38"; bibtex_command = "bibtex"; fontenc = "default"; @@ -1017,6 +1019,10 @@ } break; } + case RC_DEFAULT_VIEW_FORMAT: + lexrc >> default_view_format; + break; + case RC_DEFAULT_LANGUAGE: lexrc >> default_language; break; @@ -2389,6 +2395,13 @@ << "\" \"\" \"\" \"\" \"\" \"\" \"\"\n"; if (tag != RC_LAST) break; + case RC_DEFAULT_VIEW_FORMAT: + if (ignore_system_lyxrc || + default_view_format != system_lyxrc.default_view_format) { + os << "\\default_view_format " << default_view_format << '\n'; + } + if (tag != RC_LAST) + break; case RC_VIEWER: // Ignore it if (tag != RC_LAST) @@ -2422,7 +2435,7 @@ << "\" \"" << cit->to << "\" \"\" \"\"\n"; if (tag != RC_LAST) break; - + case RC_COPIER: if (tag == RC_LAST) os << "\n#\n" @@ -2554,6 +2567,10 @@ str = _("Command definition file. Can either specify an absolute path, or LyX will look in its global and local commands/ directories."); break; + case RC_DEFAULT_VIEW_FORMAT: + str = _("The default format used with LFUN_BUFFER_[VIEW|UPDATE]."); + break; + case RC_DEFAULT_LANGUAGE: str = _("New documents will be assigned this language."); break; Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (Revision 29119) +++ src/Buffer.cpp (Arbeitskopie) @@ -2480,6 +2480,21 @@ } +string Buffer::getDefaultOutputFormat() const +{ + typedef vector<Format const *> Formats; + Formats formats = exportableFormats(true); + if (isDocBook() + || isLiterate() + || params().useXetex + || params().encoding().package() == Encoding::japanese) + // return the first we find + return formats.front()->name(); + return lyxrc.default_view_format; +} + + + bool Buffer::doExport(string const & format, bool put_in_tempdir, string & result_file) const {