]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Hopefully fix locale aware language sorting in document and prefs dialogs.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 5b07599360012ead1e2c23396d64cee6a4bd2363..a36e8226f0c57dd5a0804283ae7fc10a1ee95b86 100644 (file)
 
 #include "GuiDocument.h"
 
+#include "GuiApplication.h"
+#include "GuiBranches.h"
+#include "LaTeXHighlighter.h"
+#include "LengthCombo.h"
+#include "PanelStack.h"
+#include "Validator.h"
+
 #include "LayoutFile.h"
 #include "BranchList.h"
 #include "buffer_funcs.h"
 #include "Encoding.h"
 #include "FloatPlacement.h"
 #include "FuncRequest.h"
-#include "support/gettext.h"
-#include "GuiBranches.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
-#include "LaTeXHighlighter.h"
 #include "Layout.h"
-#include "LengthCombo.h"
 #include "LyXRC.h" // defaultUnit
 #include "ModuleList.h"
 #include "OutputParams.h"
-#include "PanelStack.h"
 #include "PDFOptions.h"
 #include "qt_helpers.h"
 #include "Spacing.h"
-#include "Validator.h"
 
 #include "insets/InsetListingsParams.h"
 
 #include "support/debug.h"
 #include "support/FileName.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 #include "frontends/alert.h"
 
+#include <QAbstractItemModel>
 #include <QCloseEvent>
 #include <QScrollBar>
 #include <QTextCursor>
@@ -511,10 +513,6 @@ GuiDocument::GuiDocument(GuiView & lv)
 {
        setupUi(this);
 
-       QList<LanguagePair> langs = languageData(false);        
-       for (int i = 0; i != langs.size(); ++i)
-               lang_.append(langs[i].second);
-
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
@@ -790,11 +788,10 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
        // language & quotes
-
-       QList<LanguagePair>::const_iterator lit  = langs.begin();
-       QList<LanguagePair>::const_iterator lend = langs.end();
-       for (; lit != lend; ++lit)
-               langModule->languageCO->addItem(lit->first);
+       QAbstractItemModel * language_model = guiApp->languageModel();
+       // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
+       language_model->sort(0);
+       langModule->languageCO->setModel(language_model);
 
        // Always put the default encoding in the first position.
        // It is special because the displayed text is translated.
@@ -877,6 +874,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, 
@@ -924,13 +927,6 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(bulletsModule, SIGNAL(changed()),
                this, SLOT(change_adaptor()));
 
-       // embedded files
-       embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
-       connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
-               this, SLOT(addExtraEmbeddedFile()));
-       connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
-               this, SLOT(removeExtraEmbeddedFile()));
-
        // PDF support
        pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
 
@@ -987,7 +983,6 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(floatModule, qt_("Float Placement"));
        docPS->addPanel(bulletsModule, qt_("Bullets"));
        docPS->addPanel(branchesModule, qt_("Branches"));
-       docPS->addPanel(embeddedFilesModule, qt_("Embedded Files"));
        docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
        docPS->setCurrentPanel(qt_("Document Class"));
 // FIXME: hack to work around resizing bug in Qt >= 4.2
@@ -1231,15 +1226,15 @@ void GuiDocument::browseLayout()
 {
        QString const label1 = qt_("Layouts|#o#O");
        QString const dir1 = toqstr(lyxrc.document_path);
-       FileFilterList const filter(_("LyX Layout (*.layout)"));
+       QStringList const filter(qt_("LyX Layout (*.layout)"));
        QString file = browseRelFile(QString(), bufferFilepath(),
                qt_("Local layout file"), filter, false,
                label1, dir1);
 
-       if (!suffixIs(fromqstr(file), ".layout"))
+       if (!file.endsWith(".layout"))
                return;
 
-       FileName layoutFile = makeAbsPath(fromqstr(file),
+       FileName layoutFile = support::makeAbsPath(fromqstr(file),
                fromqstr(bufferFilepath()));
        
        // load the layout file
@@ -1271,6 +1266,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();
@@ -1290,16 +1299,6 @@ void GuiDocument::classChanged()
                        setLayoutComboByIDString(bp_.baseClassID());
                        return;
                }
-       } else if (prefixIs(classname, LayoutFileList::embeddedPrefix)) {
-               int const ret = Alert::prompt(_("Embedded layout"),
-                               _("The layout file you have selected is an embedded layout that\n"
-                                 "is embedded to a buffer. You cannot make use of it unless\n"
-                                 "it is already embedded to this buffer.\n"),
-                                 1, 1, _("&Set Layout"), _("&Cancel"));
-               if (ret == 1) {
-                       setLayoutComboByIDString(bp_.baseClassID());
-                       return;
-               }
        }
        // FIXME Note that by doing things this way, we load the TextClass
        // as soon as it is selected. So, if you use the scroll wheel when
@@ -1422,41 +1421,6 @@ void GuiDocument::updateModuleInfo()
 }
 
 
-void GuiDocument::setExtraEmbeddedFileList()
-{
-       embeddedFilesModule->extraLW->clear();
-       // add current embedded files
-       vector<string> const & files = buffer().params().extraEmbeddedFiles();
-       vector<string>::const_iterator fit = files.begin();
-       vector<string>::const_iterator fit_end = files.end();
-       for (; fit != fit_end; ++fit)
-               embeddedFilesModule->extraLW->addItem(toqstr(*fit));
-}
-
-
-void GuiDocument::addExtraEmbeddedFile()
-{
-       QString const label1 = qt_("Documents|#o#O");
-       QString const dir1 = toqstr(lyxrc.document_path);
-       FileFilterList const filter(_("LyX Layout (*.layout);;LaTeX Classes (*.{cls,sty});;BibTeX Databases (*.{bib,bst})"));
-       QString file = browseRelFile(QString(), bufferFilepath(),
-               qt_("Extra embedded file"), filter, true, label1, dir1);
-
-       if (file.isEmpty())
-               return;
-
-       if (embeddedFilesModule->extraLW->findItems(file, Qt::MatchExactly).empty())
-               embeddedFilesModule->extraLW->addItem(file);
-}
-
-
-void GuiDocument::removeExtraEmbeddedFile()
-{
-       int index = embeddedFilesModule->extraLW->currentRow();
-       delete embeddedFilesModule->extraLW->takeItem(index);
-}
-
-
 void GuiDocument::updateNumbering()
 {
        DocumentClass const & tclass = bp_.documentClass();
@@ -1493,18 +1457,18 @@ void GuiDocument::apply(BufferParams & params)
        preambleModule->apply(params);
 
        // biblio
-       params.setCiteEngine(biblio::ENGINE_BASIC);
+       params.setCiteEngine(ENGINE_BASIC);
 
        if (biblioModule->citeNatbibRB->isChecked()) {
                bool const use_numerical_citations =
                        biblioModule->citeStyleCO->currentIndex();
                if (use_numerical_citations)
-                       params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
+                       params.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
                else
-                       params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
+                       params.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
 
        } else if (biblioModule->citeJurabibRB->isChecked())
-               params.setCiteEngine(biblio::ENGINE_JURABIB);
+               params.setCiteEngine(ENGINE_JURABIB);
 
        params.use_bibtopic =
                biblioModule->bibtopicCB->isChecked();
@@ -1544,8 +1508,9 @@ void GuiDocument::apply(BufferParams & params)
        }
        params.quotes_language = lga;
 
-       int const pos = langModule->languageCO->currentIndex();
-       params.language = lyx::languages.getLanguage(fromqstr(lang_[pos]));
+       QString const lang = langModule->languageCO->itemData(
+               langModule->languageCO->currentIndex()).toString();
+       params.language = lyx::languages.getLanguage(fromqstr(lang));
 
        // numbering
        if (params.documentClass().hasTocLevels()) {
@@ -1664,6 +1629,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
@@ -1759,23 +1730,6 @@ void GuiDocument::apply(BufferParams & params)
                pdf.pagemode.clear();
        pdf.quoted_options = pdf.quoted_options_check(
                                fromqstr(pdfSupportModule->optionsLE->text()));
-
-       // Embedded files
-       vector<string> & files = params.extraEmbeddedFiles();
-       files.clear();
-       for (int i = 0; i < embeddedFilesModule->extraLW->count(); ++i) {
-               QListWidgetItem * item = embeddedFilesModule->extraLW->item(i);
-               files.push_back(fromqstr(item->text()));
-       }
-}
-
-
-static int findPos(QStringList const & vec, QString const & val)
-{
-       for (int i = 0; i != vec.size(); ++i)
-               if (vec[i] == val)
-                       return i;
-       return 0;
 }
 
 
@@ -1815,23 +1769,24 @@ void GuiDocument::updateParams(BufferParams const & params)
 
        // biblio
        biblioModule->citeDefaultRB->setChecked(
-               params.citeEngine() == biblio::ENGINE_BASIC);
+               params.citeEngine() == ENGINE_BASIC);
 
        biblioModule->citeNatbibRB->setChecked(
-               params.citeEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
-               params.citeEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
+               params.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
+               params.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
 
        biblioModule->citeStyleCO->setCurrentIndex(
-               params.citeEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
+               params.citeEngine() == ENGINE_NATBIB_NUMERICAL);
 
        biblioModule->citeJurabibRB->setChecked(
-               params.citeEngine() == biblio::ENGINE_JURABIB);
+               params.citeEngine() == ENGINE_JURABIB);
 
        biblioModule->bibtopicCB->setChecked(
                params.use_bibtopic);
 
        // language & quotes
-       int const pos = findPos(lang_, toqstr(params.language->lang()));
+       int const pos = langModule->languageCO->findData(toqstr(
+               params.language->lang()));
        langModule->languageCO->setCurrentIndex(pos);
 
        langModule->quoteStyleCO->setCurrentIndex(
@@ -1963,6 +1918,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
@@ -2071,8 +2035,6 @@ void GuiDocument::updateParams(BufferParams const & params)
 
        pdfSupportModule->optionsLE->setText(
                toqstr(pdf.quoted_options));
-       
-       setExtraEmbeddedFileList();
 }
 
 
@@ -2196,6 +2158,8 @@ char const * GuiDocument::fontfamilies_gui[5] = {
 bool GuiDocument::initialiseParams(string const &)
 {
        bp_ = buffer().params();
+       // Force update on next updateContent() round.
+       current_id_ = 0;
        loadModuleInfo();
        return true;
 }
@@ -2265,6 +2229,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()) {