From 764b5cf859f6afeb4f866ad4a8f94de759d1afe6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 28 Apr 2008 16:38:56 +0000 Subject: [PATCH] support for default master document. file format change. This is the last feature for today. Promised. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24540 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 3 ++ lib/lyx2lyx/LyX.py | 2 +- lib/lyx2lyx/lyx_1_6.py | 15 +++++-- src/Buffer.cpp | 12 +++++- src/BufferParams.cpp | 8 ++++ src/BufferParams.h | 2 + src/frontends/qt4/GuiDocument.cpp | 44 +++++++++++++++++++ src/frontends/qt4/GuiDocument.h | 1 + src/frontends/qt4/ui/LaTeXUi.ui | 72 +++++++++++++++++++++++++------ 9 files changed, 142 insertions(+), 17 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 3e4676186d..3dda47ea9a 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2008-04-28 Jürgen Spitzmüller + * Format incremented to 329: new param \master. + 2008-04-18 Bo Peng * Format incremented to 328: Revert the support for embedding diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index cae99b7e52..b4b9648a72 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("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(): diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 4eee35daf2..60b1e31be1 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -1977,7 +1977,7 @@ def revert_pdfpages(document): 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 revert_mexican(document): 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 @@ convert = [[277, [fix_wrong_tables]], [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, []], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 2caf701774..686fee33c4 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -115,7 +115,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 328; +int const LYX_FORMAT = 329; typedef map DepClean; typedef map > RefCache; @@ -441,6 +441,7 @@ int Buffer::readHeader(Lexer & lex) 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 @@ bool Buffer::readDocument(Lexer & lex) } } + 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)); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 7477a9ac51..3f52f99702 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -497,6 +497,9 @@ string BufferParams::readToken(Lexer & lex, string const & token, } 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 @@ void BufferParams::writeFile(ostream & os) const if (!options.empty()) { os << "\\options " << options << '\n'; } + + // the master document + if (!master.empty()) { + os << "\\master " << master << '\n'; + } //the modules if (!layoutModules_.empty()) { diff --git a/src/BufferParams.h b/src/BufferParams.h index b622e443b1..46c0243340 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -223,6 +223,8 @@ public: /// std::string options; /// + std::string master; + /// std::string float_placement; /// unsigned int columns; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 0ce3284cf5..2ba63bacbf 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -876,6 +876,12 @@ GuiDocument::GuiDocument(GuiView & lv) 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::browseLayout() } +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 @@ void GuiDocument::apply(BufferParams & params) 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 @@ void GuiDocument::updateParams(BufferParams const & params) 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 @@ void GuiDocument::dispatchParams() // 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()) { diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 92965adea2..fa0ac26a81 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -135,6 +135,7 @@ private Q_SLOTS: void enableSkip(bool); void portraitChanged(); void browseLayout(); + void browseMaster(); void classChanged(); void updateModuleInfo(); diff --git a/src/frontends/qt4/ui/LaTeXUi.ui b/src/frontends/qt4/ui/LaTeXUi.ui index c3b663d559..7d4903376b 100644 --- a/src/frontends/qt4/ui/LaTeXUi.ui +++ b/src/frontends/qt4/ui/LaTeXUi.ui @@ -6,7 +6,7 @@ 0 0 381 - 375 + 413 @@ -19,20 +19,55 @@ 6 - - - - Qt::Vertical + + + + Select if the current document is included to a master file - - - 20 - 40 - + + - + + Select de&fault master document + + + true + + + + 9 + + + 6 + + + + + &Master: + + + childDocLE + + + + + + + &Browse... + + + + + + + Enter the name of the default master document + + + + + - + Modules @@ -203,6 +238,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + -- 2.39.2