* 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"
#include "support/lstrings.h"
+#include <boost/bind.hpp>
+
#include <QCloseEvent>
#include <QScrollBar>
#include <QTextCursor>
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",
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()) {
}
-ControlDocument & GuiDocumentDialog::controller() const
+ControlDocument & GuiDocumentDialog::controller()
{
- return static_cast<ControlDocument &>(Dialog::controller());
+ return static_cast<ControlDocument &>(GuiDialog::controller());
}
void GuiDocumentDialog::closeEvent(QCloseEvent * e)
{
- slotWMHide();
+ slotClose();
e->accept();
}
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);
}
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));
+ }
}
// 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;
}
+void GuiDocumentDialog::updateParams()
+{
+ BufferParams const & params = controller().params();
+ updateParams(params);
+}
+
+
void GuiDocumentDialog::updateParams(BufferParams const & params)
{
// set the default unit
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(
// text layout
latexModule->classCO->setCurrentIndex(params.getBaseClass());
-
+
updatePagestyle(controller().textClass().opt_pagestyle(),
params.pagestyle);
}
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()) {
}
-void GuiDocumentDialog::update_contents()
-{
- updateParams(controller().params());
-}
-
-
void GuiDocumentDialog::saveDocDefault()
{
// we have to apply the params first
}
+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();
}