]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Embed: allow the use of embedded layout and class (.cls, .sty) files.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 61fbdf8255f3945042129866fedec16c308fbaf5..045d0b9cd1ef16809c298f3cf09b5e49b9caabd3 100644 (file)
@@ -870,6 +870,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(classChanged()));
        connect(latexModule->classCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
+       connect(latexModule->layoutPB, SIGNAL(clicked()),
+               this, SLOT(browseLayout()));
        
        selectionManager = 
                new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV, 
@@ -1220,6 +1222,50 @@ void GuiDocument::updatePagestyle(string const & items, string const & sel)
 }
 
 
+void GuiDocument::browseLayout()
+{
+       QString const label1 = qt_("Layouts|#o#O");
+       QString const dir1 = toqstr(lyxrc.document_path);
+       FileFilterList const filter(_("LyX Layout (*.layout)"));
+       QString file = browseRelFile(QString(), bufferFilepath(),
+               qt_("Local layout file"), filter, false,
+               label1, dir1);
+
+       if (!suffixIs(fromqstr(file), ".layout"))
+               return;
+
+       FileName layoutFile = makeAbsPath(fromqstr(file),
+               fromqstr(bufferFilepath()));
+       
+       // load the layout file
+       LayoutFileList & bcl = LayoutFileList::get();
+       string classname = layoutFile.onlyFileName();
+       LayoutFileIndex name = bcl.addLayoutFile(
+               classname.substr(0, classname.size() - 7),
+               layoutFile.onlyPath().absFilename(),
+               LayoutFileList::Local);
+
+       if (name.empty()) {
+               Alert::error(_("Error"),
+                       _("Unable to read local layout file."));                
+               return;
+       }
+
+       // do not trigger classChanged if there is no change.
+       if (latexModule->classCO->currentText() == toqstr(name))
+               return;
+               
+       // add to combo box
+       int idx = latexModule->classCO->findText(toqstr(name));
+       if (idx == -1) {
+               classes_model_.insertRow(0, toqstr(name), name);
+               latexModule->classCO->setCurrentIndex(0);
+       } else
+               latexModule->classCO->setCurrentIndex(idx);
+       classChanged();
+}
+
+
 void GuiDocument::classChanged()
 {
        int idx = latexModule->classCO->currentIndex();
@@ -1239,6 +1285,16 @@ 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;
+               }
        }
        if (!bp_.setBaseClass(classname)) {
                Alert::error(_("Error"), _("Unable to set document class."));
@@ -1371,8 +1427,14 @@ void GuiDocument::setExtraEmbeddedFileList()
 
 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"), FileFilterList(), true);
+               qt_("Extra embedded file"), filter, true, label1, dir1);
+
+       if (file.isEmpty())
+               return;
 
        if (embeddedFilesModule->extraLW->findItems(file, Qt::MatchExactly).empty())
                embeddedFilesModule->extraLW->addItem(file);