]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
compile fix
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 1dd083077ea1509cef3611c0d56e19a15634d3aa..0ce3284cf50e468641c2590205c63338138f65b6 100644 (file)
@@ -43,7 +43,6 @@
 
 #include "support/debug.h"
 #include "support/FileName.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 
 
 #include <sstream>
 
+#ifdef IN
+#undef IN
+#endif
+
+
 using namespace std;
 using namespace lyx::support;
 
@@ -870,6 +874,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, 
@@ -917,13 +923,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>;
 
@@ -980,7 +979,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
@@ -1220,6 +1218,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);
+       QStringList const filter(qt_("LyX Layout (*.layout)"));
+       QString file = browseRelFile(QString(), bufferFilepath(),
+               qt_("Local layout file"), filter, false,
+               label1, dir1);
+
+       if (!file.endsWith(".layout"))
+               return;
+
+       FileName layoutFile = support::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();
@@ -1240,6 +1282,10 @@ void GuiDocument::classChanged()
                        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
+       // sitting on the combo box, we'll load a lot of TextClass objects
+       // very quickly. This could be changed.
        if (!bp_.setBaseClass(classname)) {
                Alert::error(_("Error"), _("Unable to set document class."));
                return;
@@ -1357,35 +1403,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 file = browseRelFile(QString(), bufferFilepath(),
-               qt_("Extra embedded file"), FileFilterList(), true);
-
-       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();
@@ -1422,18 +1439,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();
@@ -1450,25 +1467,25 @@ void GuiDocument::apply(BufferParams & params)
                                fromqstr(langModule->encodingCO->currentText());
        }
 
-       InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
+       InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
        switch (langModule->quoteStyleCO->currentIndex()) {
        case 0:
-               lga = InsetQuotes::EnglishQ;
+               lga = InsetQuotes::EnglishQuotes;
                break;
        case 1:
-               lga = InsetQuotes::SwedishQ;
+               lga = InsetQuotes::SwedishQuotes;
                break;
        case 2:
-               lga = InsetQuotes::GermanQ;
+               lga = InsetQuotes::GermanQuotes;
                break;
        case 3:
-               lga = InsetQuotes::PolishQ;
+               lga = InsetQuotes::PolishQuotes;
                break;
        case 4:
-               lga = InsetQuotes::FrenchQ;
+               lga = InsetQuotes::FrenchQuotes;
                break;
        case 5:
-               lga = InsetQuotes::DanishQ;
+               lga = InsetQuotes::DanishQuotes;
                break;
        }
        params.quotes_language = lga;
@@ -1560,9 +1577,9 @@ void GuiDocument::apply(BufferParams & params)
                InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
 
        if (textLayoutModule->indentRB->isChecked())
-               params.paragraph_separation = BufferParams::PARSEP_INDENT;
+               params.paragraph_separation = BufferParams::ParagraphIndentSeparation;
        else
-               params.paragraph_separation = BufferParams::PARSEP_SKIP;
+               params.paragraph_separation = BufferParams::ParagraphSkipSeparation;
 
        switch (textLayoutModule->skipCO->currentIndex()) {
        case 0:
@@ -1688,14 +1705,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 (size_t i = 0; i < embeddedFilesModule->extraLW->count(); ++i) {
-               QListWidgetItem * item = embeddedFilesModule->extraLW->item(i);
-               files.push_back(fromqstr(item->text()));
-       }
 }
 
 
@@ -1744,17 +1753,17 @@ void GuiDocument::updateParams(BufferParams const & params)
 
        // biblio
        biblioModule->citeDefaultRB->setChecked(
-               params.getEngine() == biblio::ENGINE_BASIC);
+               params.citeEngine() == ENGINE_BASIC);
 
        biblioModule->citeNatbibRB->setChecked(
-               params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
-               params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
+               params.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
+               params.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
 
        biblioModule->citeStyleCO->setCurrentIndex(
-               params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
+               params.citeEngine() == ENGINE_NATBIB_NUMERICAL);
 
        biblioModule->citeJurabibRB->setChecked(
-               params.getEngine() == biblio::ENGINE_JURABIB);
+               params.citeEngine() == ENGINE_JURABIB);
 
        biblioModule->bibtopicCB->setChecked(
                params.use_bibtopic);
@@ -1845,7 +1854,7 @@ void GuiDocument::updateParams(BufferParams const & params)
        }
        setLSpacing(nitem);
 
-       if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
+       if (params.paragraph_separation == BufferParams::ParagraphIndentSeparation)
                textLayoutModule->indentRB->setChecked(true);
        else
                textLayoutModule->skipRB->setChecked(true);
@@ -2000,8 +2009,6 @@ void GuiDocument::updateParams(BufferParams const & params)
 
        pdfSupportModule->optionsLE->setText(
                toqstr(pdf.quoted_options));
-       
-       setExtraEmbeddedFileList();
 }
 
 
@@ -2022,11 +2029,12 @@ void GuiDocument::saveDocDefault()
 void GuiDocument::updateAvailableModules() 
 {
        modules_av_model_.clear();
-       vector<modInfoStruct> const modInfoList = getModuleInfo();
+       vector<modInfoStruct> const modInfoList = getModuleInfo();
        int const mSize = modInfoList.size();
        for (int i = 0; i != mSize; ++i) {
                modInfoStruct const & modInfo = modInfoList[i];
-               modules_av_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
+               modules_av_model_.insertRow(i, modInfo.name, modInfo.id, 
+                               modInfo.description);
        }
 }
 
@@ -2039,7 +2047,8 @@ void GuiDocument::updateSelectedModules()
        int const sSize = selModList.size();
        for (int i = 0; i != sSize; ++i) {
                modInfoStruct const & modInfo = selModList[i];
-               modules_sel_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
+               modules_sel_model_.insertRow(i, modInfo.name, modInfo.id,
+                               modInfo.description);
        }
 }
 
@@ -2157,9 +2166,9 @@ vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
                m.id = *it;
                LyXModule * mod = moduleList[*it];
                if (mod)
-                       m.name = mod->getName();
+                       m.name = qt_(mod->getName());
                else 
-                       m.name = *it + " (Not Found)";
+                       m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
                mInfo.push_back(m);
        }
        return mInfo;
@@ -2173,7 +2182,7 @@ DocumentClass const & GuiDocument::documentClass() const
 
 
 static void dispatch_bufferparams(Dialog const & dialog,
-       BufferParams const & bp, kb_action lfun)
+       BufferParams const & bp, FuncCode lfun)
 {
        ostringstream ss;
        ss << "\\begin_header\n";
@@ -2290,7 +2299,13 @@ void GuiDocument::loadModuleInfo()
        for (; it != end; ++it) {
                modInfoStruct m;
                m.id = it->getID();
-               m.name = it->getName();
+               m.name = qt_(it->getName());
+               // this is supposed to give us the first sentence of the description
+               QString desc = qt_(it->getDescription());
+               int const pos = desc.indexOf(".");
+               if (pos > 0)
+                       desc.truncate(pos + 1);
+               m.description = desc;
                moduleNames_.push_back(m);
        }
 }