]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
This is the last of a series of patches that merges the layout modules development...
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 305dc6cf7eb288e8733377efba44216168cd4e86..7b3e9e254ee27f312aef9a8f49b74280156cb163 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Edwin Leuven
+ * \author Richard Heck (modules)
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "GuiViewSource.h" // For latexHighlighter use in the preamble.
 
+#include "frontend_helpers.h"
 #include "BufferParams.h"
 #include "Encoding.h"
 #include "gettext.h"
-#include "frontend_helpers.h" // getSecond()
 #include "Language.h"
 #include "LyXRC.h" // defaultUnit
 #include "TextClassList.h"
@@ -36,6 +37,8 @@
 
 #include "support/lstrings.h"
 
+#include <boost/bind.hpp>
+
 #include <QCloseEvent>
 #include <QScrollBar>
 #include <QTextCursor>
@@ -54,6 +57,17 @@ using std::vector;
 using std::string;
 
 
+///
+template<class Pair>
+std::vector<typename Pair::second_type> const
+getSecond(std::vector<Pair> const & pr)
+{
+        std::vector<typename Pair::second_type> tmp(pr.size());
+        std::transform(pr.begin(), pr.end(), tmp.begin(),
+                                        boost::bind(&Pair::second, _1));
+        return tmp;
+}
+
 char const * const tex_graphics[] =
 {
        "default", "dvips", "dvitops", "emtex",
@@ -552,12 +566,26 @@ GuiDocumentDialog::GuiDocumentDialog(LyXView & lv)
                this, SLOT(change_adaptor()));
        connect(latexModule->classCO, SIGNAL(activated(int)),
                this, SLOT(classChanged()));
-       // packages
+       
+       selectionManager = 
+               new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV, 
+                       latexModule->addPB, latexModule->deletePB, 
+                       latexModule->upPB, latexModule->downPB, 
+                       availableModel(), selectedModel());
+       connect(selectionManager, SIGNAL(updateHook()),
+               this, SLOT(updateModuleInfo()));
+       connect(selectionManager, SIGNAL(updateHook()),
+               this, SLOT(change_adaptor()));
+       
+       // postscript drivers
        for (int n = 0; tex_graphics[n][0]; ++n) {
                QString enc = qt_(tex_graphics_gui[n]);
                latexModule->psdriverCO->addItem(enc);
        }
-       // latex
+       // latex classes
+       //FIXME This seems too involved with the kernel. Some of this
+       //should be moved to the controller---which should perhaps just
+       //give us a list of entries or something of the sort.
        for (TextClassList::const_iterator cit = textclasslist.begin();
             cit != textclasslist.end(); ++cit) {
                if (cit->isTeXClassAvailable()) {
@@ -612,9 +640,9 @@ GuiDocumentDialog::GuiDocumentDialog(LyXView & lv)
 }
 
 
-ControlDocument & GuiDocumentDialog::controller() const
+ControlDocument & GuiDocumentDialog::controller()
 {
-       return static_cast<ControlDocument &>(Dialog::controller());
+       return static_cast<ControlDocument &>(GuiDialog::controller());
 }
 
 
@@ -682,7 +710,7 @@ void GuiDocumentDialog::set_listings_msg()
 
 void GuiDocumentDialog::closeEvent(QCloseEvent * e)
 {
-       slotWMHide();
+       slotClose();
        e->accept();
 }
 
@@ -830,15 +858,15 @@ void GuiDocumentDialog::updatePagestyle(string const & items, string const & sel
                return;
        }
 
-       int n = 0;
+       int nn = 0;
 
        for (size_t i = 0; i < pagestyles.size(); ++i)
                if (pagestyles[i].first == sel)
-                       n = pageLayoutModule->pagestyleCO->findText(
+                       nn = pageLayoutModule->pagestyleCO->findText(
                                        toqstr(pagestyles[i].second));
 
-       if (n > 0)
-               pageLayoutModule->pagestyleCO->setCurrentIndex(n);
+       if (nn > 0)
+               pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
 }
 
 
@@ -849,7 +877,45 @@ void GuiDocumentDialog::classChanged()
        params.setJustBaseClass(tc);
        if (lyxrc.auto_reset_options)
                params.useClassDefaults();
-       update_contents();
+       updateContents();
+}
+
+
+void GuiDocumentDialog::updateModuleInfo()
+{
+       selectionManager->update();
+       //Module description
+       QListView const * const lv = selectionManager->selectedFocused() ?
+                                    latexModule->selectedLV :
+                       latexModule->availableLV;
+       if (lv->selectionModel()->selectedIndexes().isEmpty())
+               latexModule->infoML->document()->clear();
+       else {
+               QModelIndex const idx = lv->selectionModel()->currentIndex();
+               string const modName = fromqstr(idx.data().toString());
+               string desc = controller().getModuleDescription(modName);
+               vector<string> pkgList = controller().getPackageList(modName);
+               string pkgdesc;
+               //this mess formats the package list as "pkg1, pkg2, and pkg3"
+               int const pkgListSize = pkgList.size();
+               for (int i = 0; i < pkgListSize; ++i) {
+                       if (i == 1) {
+                               if (i == pkgListSize - 1) //last element
+                                       pkgdesc += " and ";
+                               else
+                                       pkgdesc += ", ";
+                       } else if (i > 1) {
+                               if (i == pkgListSize - 1) //last element
+                                       pkgdesc += ", and ";
+                               else
+                                       pkgdesc += ", ";
+                       }
+                       pkgdesc += pkgList[i];
+               }
+               if (!pkgdesc.empty())
+                       desc += " Requires " + pkgdesc + ".";
+               latexModule->infoML->document()->setPlainText(toqstr(desc));
+       }
 }
 
 
@@ -957,6 +1023,13 @@ void GuiDocumentDialog::apply(BufferParams & params)
        // packages
        params.graphicsDriver =
                tex_graphics[latexModule->psdriverCO->currentIndex()];
+       
+       // Modules
+       params.clearLayoutModules();
+       QStringList const selMods = selectedModel()->stringList();
+       for (int i = 0; i != selMods.size(); ++i)
+               params.addLayoutModule(lyx::fromqstr(selMods[i]));
+
 
        if (mathsModule->amsautoCB->isChecked()) {
                params.use_amsmath = BufferParams::package_auto;
@@ -1140,6 +1213,13 @@ static size_t findPos(std::vector<A> const & vec, A const & val)
 }
 
 
+void GuiDocumentDialog::updateParams()
+{
+       BufferParams const & params = controller().params();
+       updateParams(params);
+}
+
+
 void GuiDocumentDialog::updateParams(BufferParams const & params)
 {
        // set the default unit
@@ -1239,7 +1319,8 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
        int nitem = findToken(tex_graphics, params.graphicsDriver);
        if (nitem >= 0)
                latexModule->psdriverCO->setCurrentIndex(nitem);
-
+       updateModuleInfo();
+       
        mathsModule->amsCB->setChecked(
                params.use_amsmath == BufferParams::package_on);
        mathsModule->amsautoCB->setChecked(
@@ -1259,7 +1340,7 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
 
        // text layout
        latexModule->classCO->setCurrentIndex(params.getBaseClass());
-
+       
        updatePagestyle(controller().textClass().opt_pagestyle(),
                                 params.pagestyle);
 
@@ -1270,12 +1351,10 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
        }
        setLSpacing(nitem);
 
-       if (params.paragraph_separation
-           == BufferParams::PARSEP_INDENT) {
+       if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
                textLayoutModule->indentRB->setChecked(true);
-       } else {
+       else
                textLayoutModule->skipRB->setChecked(true);
-       }
 
        int skip = 0;
        switch (params.getDefSkip().kind()) {
@@ -1407,12 +1486,6 @@ void GuiDocumentDialog::applyView()
 }
 
 
-void GuiDocumentDialog::update_contents()
-{
-       updateParams(controller().params());
-}
-
-
 void GuiDocumentDialog::saveDocDefault()
 {
        // we have to apply the params first
@@ -1421,14 +1494,33 @@ void GuiDocumentDialog::saveDocDefault()
 }
 
 
+void GuiDocumentDialog::updateContents()
+{
+       //update list of available modules
+       QStringList strlist;
+       vector<string> const modNames = controller().getModuleNames();
+       vector<string>::const_iterator it = modNames.begin();
+       for (; it != modNames.end(); ++it)
+               strlist.push_back(toqstr(*it));
+       available_model_.setStringList(strlist);
+       //and selected ones, too
+       QStringList strlist2;
+       vector<string> const & selMods = controller().getSelectedModules();
+       it = selMods.begin();
+       for (; it != selMods.end(); ++it)
+               strlist2.push_back(toqstr(*it));
+       selected_model_.setStringList(strlist2);
+
+       updateParams(controller().params());
+}
+
 void GuiDocumentDialog::useClassDefaults()
 {
        BufferParams & params = controller().params();
 
        params.setJustBaseClass(latexModule->classCO->currentIndex());
-
        params.useClassDefaults();
-       update_contents();
+       updateContents();
 }