I attached a patch against trunk how to get this.
take the attached corrected patch instead
Index: lib/ui/stdmenus.inc =================================================================== --- lib/ui/stdmenus.inc (revision 21744) +++ lib/ui/stdmenus.inc (working copy) @@ -35,6 +35,7 @@ Item "New|N" "buffer-new" Item "New from Template...|m" "buffer-new-template" Item "Open...|O" "file-open" + Item "Open Example|l" "file-open-example" Submenu "Open Recent|t" "file_lastfiles" Separator Item "Close|C" "buffer-close" @@ -360,6 +361,7 @@ Separator Item "Hyphenation Point|H" "hyphenation-point-insert" Item "Ligature Break|k" "ligature-break-insert" + Item "New Line|w" "new-line" Item "Line Break|B" "break-line" Separator Item "New Page|N" "newpage-insert" Index: src/buffer_funcs.cpp =================================================================== --- src/buffer_funcs.cpp (revision 21744) +++ src/buffer_funcs.cpp (working copy) @@ -111,6 +111,45 @@ // FIXME newFile() should probably be a member method of Application... +/*Buffer * newFile(string const & filename, string const & examplename, + bool const isNamed) +{ + // get a free buffer + Buffer * b = theBufferList().newBuffer(filename); + BOOST_ASSERT(b); + + FileName tname; + // use example_lyxified.lyx as a default example if it exists. + if (examplename.empty()) + tname = libFileSearch("examples", "example_lyxified.lyx"); + else + tname = makeAbsPath(examplename); + + if (!tname.empty()) { + if (!b->readFile(tname)) { + docstring const file = makeDisplayPath(tname.absFilename(), 50); + docstring const text = bformat( + _("The specified document example\n%1$s\ncould not be read."), + file); + Alert::error(_("Could not read example"), text); + theBufferList().release(b); + return 0; + } + } + + if (!isNamed) { + b->setUnnamed(); + b->setFileName(filename); + } + + b->setReadonly(false); + b->setFullyLoaded(true); + + return b; +}*/ + + +// FIXME newFile() should probably be a member method of Application... Buffer * newFile(string const & filename, string const & templatename, bool const isNamed) { Index: src/frontends/qt4/GuiPrefs.cpp =================================================================== --- src/frontends/qt4/GuiPrefs.cpp (revision 21744) +++ src/frontends/qt4/GuiPrefs.cpp (working copy) @@ -736,6 +736,7 @@ : PrefModule(_("Paths"), form, parent) { setupUi(this); + connect(exampleDirPB, SIGNAL(clicked()), this, SLOT(select_exampledir())); connect(templateDirPB, SIGNAL(clicked()), this, SLOT(select_templatedir())); connect(tempDirPB, SIGNAL(clicked()), this, SLOT(select_tempdir())); connect(backupDirPB, SIGNAL(clicked()), this, SLOT(select_backupdir())); @@ -743,6 +744,8 @@ connect(lyxserverDirPB, SIGNAL(clicked()), this, SLOT(select_lyxpipe())); connect(workingDirED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); + connect(exampleDirPB, SIGNAL(textChanged(QString)), + this, SIGNAL(changed())); connect(templateDirED, SIGNAL(textChanged(QString)), this, SIGNAL(changed())); connect(backupDirED, SIGNAL(textChanged(QString)), @@ -759,6 +762,7 @@ void PrefPaths::apply(LyXRC & rc) const { rc.document_path = internal_path(fromqstr(workingDirED->text())); + rc.example_path = internal_path(fromqstr(exampleDirED->text())); rc.template_path = internal_path(fromqstr(templateDirED->text())); rc.backupdir_path = internal_path(fromqstr(backupDirED->text())); rc.tempdir_path = internal_path(fromqstr(tempDirED->text())); @@ -771,6 +775,7 @@ void PrefPaths::update(LyXRC const & rc) { workingDirED->setText(toqstr(external_path(rc.document_path))); + exampleDirED->setText(toqstr(external_path(rc.example_path))); templateDirED->setText(toqstr(external_path(rc.template_path))); backupDirED->setText(toqstr(external_path(rc.backupdir_path))); tempDirED->setText(toqstr(external_path(rc.tempdir_path))); @@ -780,6 +785,16 @@ } +void PrefPaths::select_exampledir() +{ + docstring file(form_->browsedir( + from_utf8(internal_path(fromqstr(exampleDirED->text()))), + _("Select a document templates directory"))); + if (!file.empty()) + exampleDirED->setText(toqstr(file)); +} + + void PrefPaths::select_templatedir() { docstring file(form_->browsedir( Index: src/frontends/qt4/GuiPrefs.h =================================================================== --- src/frontends/qt4/GuiPrefs.h (revision 21744) +++ src/frontends/qt4/GuiPrefs.h (working copy) @@ -197,6 +197,7 @@ void update(LyXRC const & rc); private Q_SLOTS: + void select_exampledir(); void select_templatedir(); void select_tempdir(); void select_backupdir(); Index: src/frontends/qt4/ui/PrefPathsUi.ui =================================================================== --- src/frontends/qt4/ui/PrefPathsUi.ui (revision 21744) +++ src/frontends/qt4/ui/PrefPathsUi.ui (working copy) @@ -6,31 +6,28 @@ <x>0</x> <y>0</y> <width>347</width> - <height>227</height> + <height>259</height> </rect> </property> <property name="windowTitle" > <string/> </property> <layout class="QGridLayout" > - <property name="margin" > - <number>9</number> - </property> - <property name="spacing" > - <number>6</number> - </property> - <item row="3" column="0" > - <widget class="QLabel" name="lyxserverDirLA" > + <item row="0" column="0" > + <widget class="QLabel" name="workingDirLA" > <property name="text" > - <string>Ly&XServer pipe:</string> + <string>&Working directory:</string> </property> <property name="buddy" > - <cstring>lyxserverDirED</cstring> + <cstring>workingDirED</cstring> </property> </widget> </item> - <item row="1" column="2" > - <widget class="QPushButton" name="templateDirPB" > + <item row="0" column="1" > + <widget class="QLineEdit" name="workingDirED" /> + </item> + <item row="0" column="2" > + <widget class="QPushButton" name="workingDirPB" > <property name="text" > <string>Browse...</string> </property> @@ -39,11 +36,21 @@ </property> </widget> </item> - <item row="5" column="1" colspan="2" > - <widget class="QLineEdit" name="pathPrefixED" /> + <item row="1" column="0" > + <widget class="QLabel" name="templateDirLA" > + <property name="text" > + <string>&Document templates:</string> + </property> + <property name="buddy" > + <cstring>templateDirED</cstring> + </property> + </widget> </item> - <item row="2" column="2" > - <widget class="QPushButton" name="backupDirPB" > + <item row="1" column="1" > + <widget class="QLineEdit" name="templateDirED" /> + </item> + <item row="1" column="2" > + <widget class="QPushButton" name="templateDirPB" > <property name="text" > <string>Browse...</string> </property> @@ -52,24 +59,21 @@ </property> </widget> </item> - <item row="4" column="2" > - <widget class="QPushButton" name="tempDirPB" > + <item row="2" column="0" > + <widget class="QLabel" name="exampleDirLA" > <property name="text" > - <string>Browse...</string> + <string>&Example files:</string> </property> - <property name="autoDefault" > - <bool>false</bool> + <property name="buddy" > + <cstring>templateDirED</cstring> </property> </widget> </item> - <item row="3" column="1" > - <widget class="QLineEdit" name="lyxserverDirED" /> + <item row="2" column="1" > + <widget class="QLineEdit" name="exampleDirED" /> </item> - <item row="1" column="1" > - <widget class="QLineEdit" name="templateDirED" /> - </item> - <item row="0" column="2" > - <widget class="QPushButton" name="workingDirPB" > + <item row="2" column="2" > + <widget class="QPushButton" name="exampleDirPB" > <property name="text" > <string>Browse...</string> </property> @@ -78,43 +82,43 @@ </property> </widget> </item> - <item row="5" column="0" > - <widget class="QLabel" name="pathPrefixLA" > + <item row="3" column="0" > + <widget class="QLabel" name="backupDirLA" > <property name="text" > - <string>&PATH prefix:</string> + <string>&Backup directory:</string> </property> <property name="buddy" > - <cstring>pathPrefixED</cstring> + <cstring>backupDirED</cstring> </property> </widget> </item> - <item row="4" column="0" > - <widget class="QLabel" name="tempDirLA" > + <item row="3" column="1" > + <widget class="QLineEdit" name="backupDirED" /> + </item> + <item row="3" column="2" > + <widget class="QPushButton" name="backupDirPB" > <property name="text" > - <string>&Temporary directory:</string> + <string>Browse...</string> </property> - <property name="buddy" > - <cstring>tempDirED</cstring> + <property name="autoDefault" > + <bool>false</bool> </property> </widget> </item> - <item row="2" column="0" > - <widget class="QLabel" name="backupDirLA" > + <item row="4" column="0" > + <widget class="QLabel" name="lyxserverDirLA" > <property name="text" > - <string>&Backup directory:</string> + <string>Ly&XServer pipe:</string> </property> <property name="buddy" > - <cstring>backupDirED</cstring> + <cstring>lyxserverDirED</cstring> </property> </widget> </item> - <item row="2" column="1" > - <widget class="QLineEdit" name="backupDirED" /> + <item row="4" column="1" > + <widget class="QLineEdit" name="lyxserverDirED" /> </item> - <item row="0" column="1" > - <widget class="QLineEdit" name="workingDirED" /> - </item> - <item row="3" column="2" > + <item row="4" column="2" > <widget class="QPushButton" name="lyxserverDirPB" > <property name="text" > <string>Browse...</string> @@ -124,30 +128,43 @@ </property> </widget> </item> - <item row="0" column="0" > - <widget class="QLabel" name="workingDirLA" > + <item row="5" column="0" > + <widget class="QLabel" name="tempDirLA" > <property name="text" > - <string>&Working directory:</string> + <string>&Temporary directory:</string> </property> <property name="buddy" > - <cstring>workingDirED</cstring> + <cstring>tempDirED</cstring> </property> </widget> </item> - <item row="1" column="0" > - <widget class="QLabel" name="templateDirLA" > + <item row="5" column="1" > + <widget class="QLineEdit" name="tempDirED" /> + </item> + <item row="5" column="2" > + <widget class="QPushButton" name="tempDirPB" > <property name="text" > - <string>&Document templates:</string> + <string>Browse...</string> </property> + <property name="autoDefault" > + <bool>false</bool> + </property> + </widget> + </item> + <item row="6" column="0" > + <widget class="QLabel" name="pathPrefixLA" > + <property name="text" > + <string>&PATH prefix:</string> + </property> <property name="buddy" > - <cstring>templateDirED</cstring> + <cstring>pathPrefixED</cstring> </property> </widget> </item> - <item row="4" column="1" > - <widget class="QLineEdit" name="tempDirED" /> + <item row="6" column="1" colspan="2" > + <widget class="QLineEdit" name="pathPrefixED" /> </item> - <item row="6" column="0" colspan="3" > + <item row="7" column="0" colspan="3" > <spacer> <property name="orientation" > <enum>Qt::Vertical</enum> @@ -165,10 +182,6 @@ </item> </layout> </widget> - <pixmapfunction></pixmapfunction> - <includes> - <include location="local" >qt_helpers.h</include> - </includes> <tabstops> <tabstop>workingDirED</tabstop> <tabstop>workingDirPB</tabstop> @@ -181,6 +194,9 @@ <tabstop>tempDirED</tabstop> <tabstop>tempDirPB</tabstop> </tabstops> + <includes> + <include location="local" >qt_helpers.h</include> + </includes> <resources/> <connections/> </ui> Index: src/lfuns.h =================================================================== --- src/lfuns.h (revision 21744) +++ src/lfuns.h (working copy) @@ -223,6 +223,7 @@ LFUN_FILE_INSERT_PLAINTEXT_PARA,// Levon 2001-02-14 LFUN_FILE_NEW, // for scripting purposes LFUN_FILE_OPEN, + LFUN_FILE_OPEN_EXAMPLE, // uwestoehr 2007-11-23 LFUN_PARAGRAPH_UP, // Asger 1996-10-01 // 145 LFUN_PARAGRAPH_UP_SELECT, // Asger 1996-10-01 Index: src/LyX.cpp =================================================================== --- src/LyX.cpp (revision 21744) +++ src/LyX.cpp (working copy) @@ -785,6 +785,10 @@ lyxrc.tempdir_path = package().temp_dir().absFilename(); lyxrc.document_path = package().document_dir().absFilename(); + if (lyxrc.example_path.empty()) { + lyxrc.example_path = addPath(package().system_support().absFilename(), + "examples"); + } if (lyxrc.template_path.empty()) { lyxrc.template_path = addPath(package().system_support().absFilename(), "templates"); Index: src/LyXAction.cpp =================================================================== --- src/LyXAction.cpp (revision 21744) +++ src/LyXAction.cpp (working copy) @@ -171,6 +171,7 @@ { LFUN_FILE_INSERT_PLAINTEXT_PARA, "file-insert-plaintext-para", Noop, Edit }, { LFUN_FILE_NEW, "file-new", NoBuffer, Buffer }, { LFUN_FILE_OPEN, "file-open", NoBuffer, Buffer }, + { LFUN_FILE_OPEN_EXAMPLE,"file-open-example", NoBuffer, Buffer }, { LFUN_FLOAT_INSERT, "float-insert", Noop, Edit }, { LFUN_FLOAT_WIDE_INSERT, "float-wide-insert", Noop, Edit }, { LFUN_WRAP_INSERT, "wrap-insert", Noop, Edit }, Index: src/LyXFunc.cpp =================================================================== --- src/LyXFunc.cpp (revision 21744) +++ src/LyXFunc.cpp (working copy) @@ -683,6 +683,7 @@ case LFUN_HELP_OPEN: case LFUN_FILE_NEW: case LFUN_FILE_OPEN: + case LFUN_FILE_OPEN_EXAMPLE: case LFUN_DROP_LAYOUTS_CHOICE: case LFUN_MENU_OPEN: case LFUN_SERVER_GET_NAME: @@ -919,15 +920,20 @@ // --- Menus ----------------------------------------------- case LFUN_BUFFER_NEW: - menuNew(argument, false); + menuNew(argument, false, false); updateFlags = Update::None; break; case LFUN_BUFFER_NEW_TEMPLATE: - menuNew(argument, true); + menuNew(argument, true, false); updateFlags = Update::None; break; + case LFUN_FILE_OPEN_EXAMPLE: + menuNew(argument, false, true); + updateFlags = Update::None; + break; + case LFUN_BUFFER_CLOSE: closeBuffer(); updateFlags = Update::None; @@ -1947,7 +1953,8 @@ } -void LyXFunc::menuNew(string const & name, bool fromTemplate) +void LyXFunc::menuNew(string const & name, bool fromTemplate, + bool fromExample) { // FIXME: initpath is not used. What to do? string initpath = lyxrc.document_path; @@ -1974,6 +1981,29 @@ } } + // The example stuff + string examplname; + if (fromExample) { + FileDialog dlg(_("Select example file")); + dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); + dlg.setButton1(_("Examples|#T#t"), from_utf8(lyxrc.example_path)); + + FileDialog::Result result = + dlg.open(from_utf8(lyxrc.example_path), + FileFilterList(_("LyX Documents (*.lyx)")), + docstring()); + + if (result.first == FileDialog::Later) + return; + if (result.second.empty()) + return; + examplname = to_utf8(result.second); + + Buffer * const b = newFile(filename, examplname, !name.empty()); + if (b) + lyx_view_->setBuffer(b); + } + // The template stuff string templname; if (fromTemplate) { @@ -1991,11 +2021,12 @@ if (result.second.empty()) return; templname = to_utf8(result.second); + + Buffer * const b = newFile(filename, templname, !name.empty()); + if (b) + lyx_view_->setBuffer(b); } - Buffer * const b = newFile(filename, templname, !name.empty()); - if (b) - lyx_view_->setBuffer(b); } Index: src/LyXFunc.h =================================================================== --- src/LyXFunc.h (revision 21744) +++ src/LyXFunc.h (working copy) @@ -122,7 +122,8 @@ // I think the following should be moved to BufferView. (Asger) /// - void menuNew(std::string const & argument, bool fromTemplate); + void menuNew(std::string const & argument, bool fromTemplate, + bool fromExample); /// void open(std::string const &); /// Index: src/LyXRC.cpp =================================================================== --- src/LyXRC.cpp (revision 21744) +++ src/LyXRC.cpp (working copy) @@ -92,6 +92,7 @@ { "\\display_graphics", LyXRC::RC_DISPLAY_GRAPHICS }, { "\\document_path", LyXRC::RC_DOCUMENTPATH }, { "\\escape_chars", LyXRC::RC_ESC_CHARS }, + { "\\example_path", LyXRC::RC_EXAMPLEPATH }, { "\\font_encoding", LyXRC::RC_FONT_ENCODING }, { "\\format", LyXRC::RC_FORMAT }, { "\\index_command", LyXRC::RC_INDEX_COMMAND }, @@ -705,6 +706,13 @@ } break; + case RC_EXAMPLEPATH: + if (lexrc.next()) { + example_path = os::internal_path(lexrc.getString()); + example_path = expandPath(example_path); + } + break; + case RC_TEMPLATEPATH: if (lexrc.next()) { template_path = os::internal_path(lexrc.getString()); @@ -1932,6 +1940,14 @@ } if (tag != RC_LAST) break; + case RC_EXAMPLEPATH: + if (ignore_system_lyxrc || + example_path != system_lyxrc.example_path) { + string const path = os::external_path(example_path); + os << "\\example_path \"" << path << "\"\n"; + } + if (tag != RC_LAST) + break; case RC_TEMPLATEPATH: if (ignore_system_lyxrc || template_path != system_lyxrc.template_path) { @@ -2411,6 +2427,10 @@ str = _("Specify additional chars that can be part of a word."); break; + case RC_EXAMPLEPATH: + str = _("The path that LyX will set when offering to choose an example. An empty value selects the directory LyX was started from."); + break; + case RC_FONT_ENCODING: str = _("The font encoding used for the LaTeX2e fontenc package. T1 is highly recommended for non-English languages."); break; Index: src/LyXRC.h =================================================================== --- src/LyXRC.h (revision 21744) +++ src/LyXRC.h (working copy) @@ -63,6 +63,7 @@ RC_DISPLAY_GRAPHICS, RC_DOCUMENTPATH, RC_ESC_CHARS, + RC_EXAMPLEPATH, RC_FONT_ENCODING, RC_FORMAT, RC_INDEX_COMMAND, @@ -226,6 +227,8 @@ /// std::string document_path; /// + std::string example_path; + /// std::string template_path; /// std::string tempdir_path;