Here is an attempt to provide a child document with some knowledge about its master.
It fixes several drawbacks of our current unidirectional child document handling. Since the document has now always access to the master buffer (previously, this was only the case if the child was opened from the master), it can retrieve information such as bibliography and labels. Furthermore, master-buffer-[view|update] now works also directly from a child. The approach is limited in that it assumes one fixed master, whereas a document might be included in different master files. However, for the information the child receives, the output would break anyway if some master would differ with regard to that information. If we want to support such things, we need to bind the master andling to some kind of branch handling. But that's something for later. Opinions? Jürgen
Index: lib/lyx2lyx/LyX.py =================================================================== --- lib/lyx2lyx/LyX.py (Revision 24506) +++ lib/lyx2lyx/LyX.py (Arbeitskopie) @@ -80,7 +80,7 @@ ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 2)), - ("1_6", range(277,329), minor_versions("1.6" , 0))] # Uwe: support for Spanish(Mexico) + ("1_6", range(277,330), minor_versions("1.6" , 0))] def formats_list(): Index: lib/lyx2lyx/lyx_1_6.py =================================================================== --- lib/lyx2lyx/lyx_1_6.py (Revision 24506) +++ lib/lyx2lyx/lyx_1_6.py (Arbeitskopie) @@ -1977,7 +1977,7 @@ def revert_mexican(document): - "Set language Spanish(Mexico) to Spanish" + ' Set language Spanish(Mexico) to Spanish ' i = 0 if document.language == "spanish-mexico": document.language = "spanish" @@ -1994,13 +1994,20 @@ def remove_embedding(document): - ' Remove embed tag from all insets' + ' Remove embed tag from all insets ' revert_inset_embedding(document, 'Graphics') revert_inset_embedding(document, 'External') revert_inset_embedding(document, 'CommandInset include') revert_inset_embedding(document, 'CommandInset bibtex') +def revert_master(document): + ' Remove master param ' + i = find_token(document.header, "\\master", 0) + if i != -1: + del document.header[i] + + ## # Conversion hub # @@ -2058,9 +2065,11 @@ [326, []], [327, []], [328, [remove_embedding, remove_extra_embedded_files, remove_inzip_options]], + [329, []], ] -revert = [[327, []], +revert = [[328, [revert_master]], + [327, []], [326, [revert_mexican]], [325, [revert_pdfpages]], [324, []], Index: src/BufferParams.h =================================================================== --- src/BufferParams.h (Revision 24506) +++ src/BufferParams.h (Arbeitskopie) @@ -223,6 +223,8 @@ /// std::string options; /// + std::string master; + /// std::string float_placement; /// unsigned int columns; Index: src/frontends/qt4/GuiDocument.h =================================================================== --- src/frontends/qt4/GuiDocument.h (Revision 24506) +++ src/frontends/qt4/GuiDocument.h (Arbeitskopie) @@ -135,6 +135,7 @@ void enableSkip(bool); void portraitChanged(); void browseLayout(); + void browseMaster(); void classChanged(); void updateModuleInfo(); Index: src/frontends/qt4/GuiDocument.cpp =================================================================== --- src/frontends/qt4/GuiDocument.cpp (Revision 24506) +++ src/frontends/qt4/GuiDocument.cpp (Arbeitskopie) @@ -876,6 +876,12 @@ this, SLOT(change_adaptor())); connect(latexModule->layoutPB, SIGNAL(clicked()), this, SLOT(browseLayout())); + connect(latexModule->childDocGB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(latexModule->childDocLE, SIGNAL(textChanged(const QString &)), + this, SLOT(change_adaptor())); + connect(latexModule->childDocPB, SIGNAL(clicked()), + this, SLOT(browseMaster())); selectionManager = new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV, @@ -1262,6 +1268,20 @@ } +void GuiDocument::browseMaster() +{ + QString const title = qt_("Select master document"); + QString const dir1 = toqstr(lyxrc.document_path); + QString const old = latexModule->childDocLE->text(); + QString const docpath = toqstr(support::onlyPath(buffer().absFileName())); + QStringList const filter(qt_("LyX Files (*.lyx)")); + QString file = browseRelFile(old, docpath, title, filter, false, + qt_("Documents|#o#O"), toqstr(lyxrc.document_path)); + + latexModule->childDocLE->setText(file); +} + + void GuiDocument::classChanged() { int idx = latexModule->classCO->currentIndex(); @@ -1610,6 +1630,12 @@ params.options = fromqstr(latexModule->optionsLE->text()); + if (latexModule->childDocGB->isChecked()) + params.master = + fromqstr(latexModule->childDocLE->text()); + else + params.master = string(); + params.float_placement = floatModule->get(); // fonts @@ -1901,6 +1927,15 @@ latexModule->optionsLE->setText(QString()); } + if (!params.master.empty()) { + latexModule->childDocGB->setChecked(true); + latexModule->childDocLE->setText( + toqstr(params.master)); + } else { + latexModule->childDocLE->setText(QString()); + latexModule->childDocGB->setChecked(false); + } + floatModule->set(params.float_placement); // Fonts @@ -2201,6 +2236,15 @@ // and then update the buffer's layout. dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY); + if (!params().master.empty()) { + FileName const master_file = support::makeAbsPath(params().master, + support::onlyPath(buffer().absFileName())); + if (isLyXFilename(master_file.absFilename())) { + Buffer * master = checkAndLoadLyXFile(master_file); + buffer().setParent(master); + } + } + // Generate the colours requested by each new branch. BranchList & branchlist = params().branchlist(); if (!branchlist.empty()) { Index: src/frontends/qt4/ui/LaTeXUi.ui =================================================================== --- src/frontends/qt4/ui/LaTeXUi.ui (Revision 24506) +++ src/frontends/qt4/ui/LaTeXUi.ui (Arbeitskopie) @@ -6,7 +6,7 @@ <x>0</x> <y>0</y> <width>381</width> - <height>375</height> + <height>413</height> </rect> </property> <property name="windowTitle" > @@ -19,7 +19,55 @@ <property name="spacing" > <number>6</number> </property> - <item row="4" column="2" > + <item row="3" column="0" colspan="6" > + <widget class="QGroupBox" name="childDocGB" > + <property name="toolTip" > + <string>Select if the current document is included to a master file</string> + </property> + <property name="statusTip" > + <string/> + </property> + <property name="title" > + <string>C&hild Document</string> + </property> + <property name="checkable" > + <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="childDocLA" > + <property name="text" > + <string>&Master:</string> + </property> + <property name="buddy" > + <cstring>childDocLE</cstring> + </property> + </widget> + </item> + <item row="0" column="1" > + <widget class="QLineEdit" name="childDocLE" > + <property name="toolTip" > + <string>Enter the name of the master document</string> + </property> + </widget> + </item> + <item row="0" column="2" > + <widget class="QPushButton" name="childDocPB" > + <property name="text" > + <string>&Browse...</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="5" column="2" colspan="3" > <spacer> <property name="orientation" > <enum>Qt::Vertical</enum> @@ -32,7 +80,85 @@ </property> </spacer> </item> - <item row="3" column="0" colspan="4" > + <item row="0" column="2" colspan="3" > + <widget class="QComboBox" name="classCO" > + <property name="maxVisibleItems" > + <number>20</number> + </property> + </widget> + </item> + <item row="0" column="0" > + <widget class="QLabel" name="classL" > + <property name="text" > + <string>Document &class:</string> + </property> + <property name="buddy" > + <cstring>classCO</cstring> + </property> + </widget> + </item> + <item row="0" column="5" > + <widget class="QPushButton" name="layoutPB" > + <property name="sizePolicy" > + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip" > + <string>Click to select a local document class definition file</string> + </property> + <property name="text" > + <string>&Local Layout...</string> + </property> + </widget> + </item> + <item row="1" column="0" > + <widget class="QLabel" name="optionsL" > + <property name="text" > + <string>&Options:</string> + </property> + <property name="buddy" > + <cstring>optionsLE</cstring> + </property> + </widget> + </item> + <item row="1" column="2" colspan="4" > + <widget class="QLineEdit" name="optionsLE" /> + </item> + <item row="2" column="0" > + <widget class="QLabel" name="psdriverL" > + <property name="text" > + <string>&Postscript driver:</string> + </property> + <property name="buddy" > + <cstring>psdriverCO</cstring> + </property> + </widget> + </item> + <item row="2" column="2" > + <widget class="QComboBox" name="psdriverCO" > + <property name="duplicatesEnabled" > + <bool>false</bool> + </property> + </widget> + </item> + <item row="2" column="4" colspan="2" > + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" > + <size> + <width>261</width> + <height>22</height> + </size> + </property> + </spacer> + </item> + <item row="4" column="0" colspan="6" > <widget class="QGroupBox" name="modulesGB" > <property name="title" > <string>Modules</string> @@ -125,84 +251,6 @@ </layout> </widget> </item> - <item row="2" column="2" colspan="2" > - <spacer> - <property name="orientation" > - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" > - <size> - <width>261</width> - <height>22</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="1" > - <widget class="QComboBox" name="psdriverCO" > - <property name="duplicatesEnabled" > - <bool>false</bool> - </property> - </widget> - </item> - <item row="2" column="0" > - <widget class="QLabel" name="psdriverL" > - <property name="text" > - <string>&Postscript driver:</string> - </property> - <property name="buddy" > - <cstring>psdriverCO</cstring> - </property> - </widget> - </item> - <item row="1" column="1" colspan="3" > - <widget class="QLineEdit" name="optionsLE" /> - </item> - <item row="1" column="0" > - <widget class="QLabel" name="optionsL" > - <property name="text" > - <string>&Options:</string> - </property> - <property name="buddy" > - <cstring>optionsLE</cstring> - </property> - </widget> - </item> - <item row="0" column="3" > - <widget class="QPushButton" name="layoutPB" > - <property name="sizePolicy" > - <sizepolicy> - <hsizetype>1</hsizetype> - <vsizetype>0</vsizetype> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip" > - <string>Click to select a local document class definition file</string> - </property> - <property name="text" > - <string>&Local Layout...</string> - </property> - </widget> - </item> - <item row="0" column="0" > - <widget class="QLabel" name="classL" > - <property name="text" > - <string>Document &class:</string> - </property> - <property name="buddy" > - <cstring>classCO</cstring> - </property> - </widget> - </item> - <item row="0" column="1" colspan="2" > - <widget class="QComboBox" name="classCO" > - <property name="maxVisibleItems" > - <number>20</number> - </property> - </widget> - </item> </layout> </widget> <tabstops> Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (Revision 24506) +++ src/Buffer.cpp (Arbeitskopie) @@ -115,7 +115,7 @@ namespace { -int const LYX_FORMAT = 328; +int const LYX_FORMAT = 329; typedef map<string, bool> DepClean; typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache; @@ -441,6 +441,7 @@ params().branchlist().clear(); params().preamble.erase(); params().options.erase(); + params().master.erase(); params().float_placement.erase(); params().paperwidth.erase(); params().paperheight.erase(); @@ -550,6 +551,15 @@ } } + if (!params().master.empty()) { + FileName const master_file = makeAbsPath(params().master, + onlyPath(absFileName())); + if (isLyXFilename(master_file.absFilename())) { + Buffer * master = checkAndLoadLyXFile(master_file); + d->parent_buffer = master; + } + } + // read main text bool const res = text().read(*this, lex, errorList, &(d->inset)); Index: src/BufferParams.cpp =================================================================== --- src/BufferParams.cpp (Revision 24506) +++ src/BufferParams.cpp (Arbeitskopie) @@ -497,6 +497,9 @@ } else if (token == "\\options") { lex.eatLine(); options = lex.getString(); + } else if (token == "\\master") { + lex.eatLine(); + master = lex.getString(); } else if (token == "\\language") { readLanguage(lex); } else if (token == "\\inputencoding") { @@ -688,6 +691,11 @@ if (!options.empty()) { os << "\\options " << options << '\n'; } + + // the master document + if (!master.empty()) { + os << "\\master " << master << '\n'; + } //the modules if (!layoutModules_.empty()) {