]> 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 8f61c641eb9a37147c083313164c732c3084310c..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 "GuiDocument.h"
 
-#include "CheckedLineEdit.h"
 #include "FloatPlacement.h"
 #include "LengthCombo.h"
 #include "PanelStack.h"
-#include "Qt2BC.h"
 #include "qt_helpers.h"
 #include "Validator.h"
 
 
 #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"
 
 #include "support/lstrings.h"
 
+#include <boost/bind.hpp>
+
 #include <QCloseEvent>
 #include <QScrollBar>
 #include <QTextCursor>
 
-#include <map>
+#include <algorithm>
 
 using lyx::support::token;
 using lyx::support::bformat;
@@ -56,45 +57,73 @@ using std::vector;
 using std::string;
 
 
-char const * const tex_graphics[] = {"default", "dvips", "dvitops", "emtex",
-                     "ln", "oztex", "textures", "none", ""
+///
+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",
+       "ln", "oztex", "textures", "none", ""
 };
 
 
-char const * const tex_graphics_gui[] = {N_("Default"), "Dvips", "DVItoPS", "EmTeX",
-                     "LN", "OzTeX", "Textures", N_("None"), ""
+char const * const tex_graphics_gui[] =
+{
+       N_("Default"), "Dvips", "DVItoPS", "EmTeX",
+       "LN", "OzTeX", "Textures", N_("None"), ""
 };
 
 
-char const * const tex_fonts_roman[] = {"default", "cmr", "lmodern", "ae", "times", "palatino",
-                           "charter", "newcent", "bookman", "utopia", "beraserif", "ccfonts", "chancery", ""
+char const * const tex_fonts_roman[] =
+{
+       "default", "cmr", "lmodern", "ae", "times", "palatino",
+       "charter", "newcent", "bookman", "utopia", "beraserif",
+       "ccfonts", "chancery", ""
 };
 
 
-char const * tex_fonts_roman_gui[] = { N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
-                           N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"), N_("Bitstream Charter"),
-                           N_("New Century Schoolbook"), N_("Bookman"), N_("Utopia"),  N_("Bera Serif"),
-                           N_("Concrete Roman"), N_("Zapf Chancery"), ""
+char const * tex_fonts_roman_gui[] =
+{
+       N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
+       N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
+       N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
+       N_("Utopia"),  N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
+       ""
 };
 
 
-char const * const tex_fonts_sans[] = {"default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
+char const * const tex_fonts_sans[] =
+{
+       "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
 };
 
 
-char const * tex_fonts_sans_gui[] = { N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
-                           N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
+char const * tex_fonts_sans_gui[] =
+{
+       N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
+       N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
 };
 
 
-char const * const tex_fonts_monospaced[] = {"default", "cmtt", "lmtt", "courier", "beramono",
-                           "luximono", "cmtl", ""
+char const * const tex_fonts_monospaced[] =
+{
+       "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
 };
 
 
-char const * tex_fonts_monospaced_gui[] = { N_("Default"), N_("Computer Modern Typewriter"),
-                           N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"), N_("LuxiMono"),
-                           N_("CM Typewriter Light"), ""
+char const * tex_fonts_monospaced_gui[] =
+{
+       N_("Default"), N_("Computer Modern Typewriter"),
+       N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
+       N_("LuxiMono"), N_("CM Typewriter Light"), ""
 };
 
 
@@ -172,26 +201,31 @@ void PreambleModule::closeEvent(QCloseEvent * e)
 //
 /////////////////////////////////////////////////////////////////////
 
-GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
-       : form_(form),
-       lang_(getSecond(getLanguageData(false)))
+
+
+GuiDocumentDialog::GuiDocumentDialog(LyXView & lv)
+       : GuiDialog(lv, "document")
 {
        setupUi(this);
+       setController(new ControlDocument(*this));
+       setViewTitle(_("Document Settings"));
+
+       lang_ = getSecond(getLanguageData(false));
 
-       connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
+       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
+       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
+       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+       connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
 
        connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
        connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
 
        // Manage the restore, ok, apply, restore and cancel/close buttons
-       form_->bcview().setOK(okPB);
-       form_->bcview().setApply(applyPB);
-       form_->bcview().setCancel(closePB);
-       form_->bcview().setRestore(restorePB);
-
+       bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+       bc().setOK(okPB);
+       bc().setApply(applyPB);
+       bc().setCancel(closePB);
+       bc().setRestore(restorePB);
 
        textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
        // text layout
@@ -248,7 +282,7 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
                Spacing::Other, qt_("Custom"));
 
        // initialize the length validator
-       addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
+       bc().addCheckedLineEdit(textLayoutModule->skipLE);
 
        fontModule = new UiWidget<Ui::FontUi>;
        // fonts
@@ -279,19 +313,19 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
 
        for (int n = 0; tex_fonts_roman[n][0]; ++n) {
                QString font = qt_(tex_fonts_roman_gui[n]);
-               if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
+               if (!controller().isFontAvailable(tex_fonts_roman[n]))
                        font += qt_(" (not installed)");
                fontModule->fontsRomanCO->addItem(font);
        }
        for (int n = 0; tex_fonts_sans[n][0]; ++n) {
                QString font = qt_(tex_fonts_sans_gui[n]);
-               if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
+               if (!controller().isFontAvailable(tex_fonts_sans[n]))
                        font += qt_(" (not installed)");
                fontModule->fontsSansCO->addItem(font);
        }
        for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
                QString font = qt_(tex_fonts_monospaced_gui[n]);
-               if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
+               if (!controller().isFontAvailable(tex_fonts_monospaced[n]))
                        font += qt_(" (not installed)");
                fontModule->fontsTypewriterCO->addItem(font);
        }
@@ -338,9 +372,9 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
        pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
        pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
        pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
-       addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
+       bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
                pageLayoutModule->paperheightL);
-       addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
+       bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
                pageLayoutModule->paperwidthL);
 
        // paper
@@ -365,8 +399,6 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
                pageLayoutModule->paperwidthLE));
 
 
-
-
        marginsModule = new UiWidget<Ui::MarginsUi>;
        // margins
        connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
@@ -416,19 +448,19 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
        marginsModule->footskipLE->setValidator(unsignedLengthValidator(
                marginsModule->footskipLE));
 
-       addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
+       bc().addCheckedLineEdit(marginsModule->topLE,
                marginsModule->topL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
+       bc().addCheckedLineEdit(marginsModule->bottomLE,
                marginsModule->bottomL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
+       bc().addCheckedLineEdit(marginsModule->innerLE,
                marginsModule->innerL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
+       bc().addCheckedLineEdit(marginsModule->outerLE,
                marginsModule->outerL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
+       bc().addCheckedLineEdit(marginsModule->headsepLE,
                marginsModule->headsepL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
+       bc().addCheckedLineEdit(marginsModule->headheightLE,
                marginsModule->headheightL);
-       addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
+       bc().addCheckedLineEdit(marginsModule->footskipLE,
                marginsModule->footskipL);
 
 
@@ -451,8 +483,7 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
        vector<LanguagePair>::const_iterator lit  = langs.begin();
        vector<LanguagePair>::const_iterator lend = langs.end();
        for (; lit != lend; ++lit) {
-               langModule->languageCO->addItem(
-                       toqstr(lit->first));
+               langModule->languageCO->addItem(toqstr(lit->first));
        }
 
        // Always put the default encoding in the first position.
@@ -510,7 +541,6 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
        biblioModule->citeStyleCO->setCurrentIndex(0);
 
 
-
        mathsModule = new UiWidget<Ui::MathsUi>;
        connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
                mathsModule->amsCB, SLOT(setDisabled(bool)));
@@ -536,12 +566,26 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
                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()) {
@@ -596,6 +640,12 @@ GuiDocumentDialog::GuiDocumentDialog(GuiDocument * form)
 }
 
 
+ControlDocument & GuiDocumentDialog::controller()
+{
+       return static_cast<ControlDocument &>(GuiDialog::controller());
+}
+
+
 void GuiDocumentDialog::showPreamble()
 {
        docPS->setCurrentPanel(_("LaTeX Preamble"));
@@ -604,19 +654,19 @@ void GuiDocumentDialog::showPreamble()
 
 void GuiDocumentDialog::saveDefaultClicked()
 {
-       form_->saveDocDefault();
+       saveDocDefault();
 }
 
 
 void GuiDocumentDialog::useDefaultsClicked()
 {
-       form_->useClassDefaults();
+       useClassDefaults();
 }
 
 
 void GuiDocumentDialog::change_adaptor()
 {
-       form_->changed();
+       changed();
 }
 
 
@@ -660,7 +710,7 @@ void GuiDocumentDialog::set_listings_msg()
 
 void GuiDocumentDialog::closeEvent(QCloseEvent * e)
 {
-       form_->slotWMHide();
+       slotClose();
        e->accept();
 }
 
@@ -767,18 +817,15 @@ void GuiDocumentDialog::updateFontsize(string const & items, string const & sel)
 void GuiDocumentDialog::romanChanged(int item)
 {
        string const font = tex_fonts_roman[item];
-
-       fontModule->fontScCB->setEnabled(
-               form_->controller().providesSC(font));
-       fontModule->fontOsfCB->setEnabled(
-               form_->controller().providesOSF(font));
+       fontModule->fontScCB->setEnabled(controller().providesSC(font));
+       fontModule->fontOsfCB->setEnabled(controller().providesOSF(font));
 }
 
 
 void GuiDocumentDialog::sansChanged(int item)
 {
        string const font = tex_fonts_sans[item];
-       bool scaleable = form_->controller().providesScale(font);
+       bool scaleable = controller().providesScale(font);
        fontModule->scaleSansSB->setEnabled(scaleable);
        fontModule->scaleSansLA->setEnabled(scaleable);
 }
@@ -787,7 +834,7 @@ void GuiDocumentDialog::sansChanged(int item)
 void GuiDocumentDialog::ttChanged(int item)
 {
        string const font = tex_fonts_monospaced[item];
-       bool scaleable = form_->controller().providesScale(font);
+       bool scaleable = controller().providesScale(font);
        fontModule->scaleTypewriterSB->setEnabled(scaleable);
        fontModule->scaleTypewriterLA->setEnabled(scaleable);
 }
@@ -811,40 +858,70 @@ 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);
 }
 
 
 void GuiDocumentDialog::classChanged()
 {
-       ControlDocument & cntrl = form_->controller();
-       BufferParams & params = cntrl.params();
-
+       BufferParams & params = controller().params();
        textclass_type const tc = latexModule->classCO->currentIndex();
+       params.setJustBaseClass(tc);
+       if (lyxrc.auto_reset_options)
+               params.useClassDefaults();
+       updateContents();
+}
 
-       if (form_->controller().loadTextclass(tc)) {
-               params.setJustBaseClass(tc);
-               if (lyxrc.auto_reset_options)
-                       params.useClassDefaults();
-               form_->update_contents();
-       } else {
-               latexModule->classCO->setCurrentIndex(params.getBaseClass());
+
+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));
        }
 }
 
 
 void GuiDocumentDialog::updateNumbering()
 {
-       TextClass const & tclass =
-               form_->controller().params().getTextClass();
+       TextClass const & tclass = controller().params().getTextClass();
 
        numberingModule->tocTW->setUpdatesEnabled(false);
        numberingModule->tocTW->clear();
@@ -946,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;
@@ -1114,14 +1198,12 @@ void GuiDocumentDialog::apply(BufferParams & params)
        branchesModule->apply(params);
 }
 
-namespace {
 
 /** Return the position of val in the vector if found.
     If not found, return 0.
  */
 template<class A>
-typename std::vector<A>::size_type
-findPos(std::vector<A> const & vec, A const & val)
+static size_t findPos(std::vector<A> const & vec, A const & val)
 {
        typename std::vector<A>::const_iterator it =
                std::find(vec.begin(), vec.end(), val);
@@ -1130,7 +1212,12 @@ findPos(std::vector<A> const & vec, A const & val)
        return distance(vec.begin(), it);
 }
 
-} // namespace anom
+
+void GuiDocumentDialog::updateParams()
+{
+       BufferParams const & params = controller().params();
+       updateParams(params);
+}
 
 
 void GuiDocumentDialog::updateParams(BufferParams const & params)
@@ -1160,7 +1247,7 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
        }
 
        // preamble
-       preambleModule->update(params, form_->controller().id());
+       preambleModule->update(params, controller().id());
 
        // biblio
        biblioModule->citeDefaultRB->setChecked(
@@ -1205,9 +1292,9 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
        }
 
        // numbering
-       int const min_toclevel = form_->controller().textClass().min_toclevel();
-       int const max_toclevel = form_->controller().textClass().max_toclevel();
-       if (form_->controller().textClass().hasTocLevels()) {
+       int const min_toclevel = controller().textClass().min_toclevel();
+       int const max_toclevel = controller().textClass().max_toclevel();
+       if (controller().textClass().hasTocLevels()) {
                numberingModule->setEnabled(true);
                numberingModule->depthSL->setMinimum(min_toclevel - 1);
                numberingModule->depthSL->setMaximum(max_toclevel);
@@ -1232,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(
@@ -1252,8 +1340,8 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
 
        // text layout
        latexModule->classCO->setCurrentIndex(params.getBaseClass());
-
-       updatePagestyle(form_->controller().textClass().opt_pagestyle(),
+       
+       updatePagestyle(controller().textClass().opt_pagestyle(),
                                 params.pagestyle);
 
        textLayoutModule->lspacingCO->setCurrentIndex(nitem);
@@ -1263,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()) {
@@ -1309,13 +1395,13 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
                latexModule->optionsLE->setText(
                        toqstr(params.options));
        } else {
-               latexModule->optionsLE->setText("");
+               latexModule->optionsLE->setText(QString());
        }
 
        floatModule->set(params.float_placement);
 
-       //fonts
-       updateFontsize(form_->controller().textClass().opt_fontsize(),
+       // Fonts
+       updateFontsize(controller().textClass().opt_fontsize(),
                        params.fontsize);
 
        int n = findToken(tex_fonts_roman, params.fontsRoman);
@@ -1394,69 +1480,53 @@ void GuiDocumentDialog::updateParams(BufferParams const & params)
 }
 
 
-/////////////////////////////////////////////////////////////////////
-//
-// GuiDocument
-//
-/////////////////////////////////////////////////////////////////////
-
-
-GuiDocument::GuiDocument(Dialog & parent)
-       : GuiView<GuiDocumentDialog>(parent, _("Document Settings"))
-{}
-
-
-void GuiDocument::build_dialog()
+void GuiDocumentDialog::applyView()
 {
-       dialog_.reset(new GuiDocumentDialog(this));
+       apply(controller().params());
 }
 
 
-void GuiDocument::showPreamble()
+void GuiDocumentDialog::saveDocDefault()
 {
-       dialog_->showPreamble();
-}
-
-
-void GuiDocument::apply()
-{
-       if (!dialog_.get())
-               return;
-
-       dialog_->apply(controller().params());
+       // we have to apply the params first
+       applyView();
+       controller().saveAsDefault();
 }
 
 
-void GuiDocument::update_contents()
-{
-       if (!dialog_.get())
-               return;
-
-       dialog_->updateParams(controller().params());
-}
-
-void GuiDocument::saveDocDefault()
+void GuiDocumentDialog::updateContents()
 {
-       // we have to apply the params first
-       apply();
-       controller().saveAsDefault();
+       //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 GuiDocument::useClassDefaults()
+void GuiDocumentDialog::useClassDefaults()
 {
        BufferParams & params = controller().params();
 
-       params.setJustBaseClass(dialog_->latexModule->classCO->currentIndex());
-
+       params.setJustBaseClass(latexModule->classCO->currentIndex());
        params.useClassDefaults();
-       update_contents();
+       updateContents();
 }
 
 
-bool GuiDocument::isValid()
+bool GuiDocumentDialog::isValid()
 {
-       return dialog_->validate_listings_params().empty();
+       return validate_listings_params().empty();
 }