diff --git a/src/frontends/controllers/ControlDocument.cpp b/src/frontends/controllers/ControlDocument.cpp index 10d2117884..1a75bc9317 100644 --- a/src/frontends/controllers/ControlDocument.cpp +++ b/src/frontends/controllers/ControlDocument.cpp @@ -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. */ @@ -17,11 +18,12 @@ #include "BufferParams.h" #include "BufferView.h" #include "buffer_funcs.h" +#include "Color.h" #include "FuncRequest.h" #include "gettext.h" #include "Language.h" #include "LaTeXFeatures.h" -#include "Color.h" +#include "ModuleList.h" #include "OutputParams.h" #include "TextClassList.h" @@ -34,6 +36,7 @@ using std::ostringstream; using std::string; +using std::vector; namespace lyx { namespace frontend { @@ -61,6 +64,7 @@ bool ControlDocument::initialiseParams(std::string const &) { bp_.reset(new BufferParams); *bp_ = buffer().params(); + loadModuleNames(); return true; } @@ -84,6 +88,36 @@ BufferId ControlDocument::id() const } +vector ControlDocument::getModuleNames() +{ + return moduleNames_; +} + + +vector const & ControlDocument::getSelectedModules() +{ + return params().getModules(); +} + + +string ControlDocument::getModuleDescription(string modName) const +{ + LyXModule const * const mod = moduleList[modName]; + if (!mod) + return string("Module unavailable!"); + return mod->description; +} + + +std::vector + ControlDocument::getPackageList(std::string modName) const { + LyXModule const * const mod = moduleList[modName]; + if (!mod) + return std::vector(); //empty such thing + return mod->packageList; +} + + TextClass const & ControlDocument::textClass() const { return textclasslist[bp_->getBaseClass()]; @@ -207,5 +241,16 @@ bool const ControlDocument::providesScale(std::string const & font) const } +void ControlDocument::loadModuleNames () +{ + moduleNames_.clear(); + LyXModuleList::const_iterator it = moduleList.begin(); + for (; it != moduleList.end(); ++it) + moduleNames_.push_back(it->name); + if (!moduleNames_.empty()) + sort(moduleNames_.begin(), moduleNames_.end()); +} + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/controllers/ControlDocument.h b/src/frontends/controllers/ControlDocument.h index cd8f6fa1ec..ca80fcb7bc 100644 --- a/src/frontends/controllers/ControlDocument.h +++ b/src/frontends/controllers/ControlDocument.h @@ -5,6 +5,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. */ @@ -13,8 +14,12 @@ #define CONTROLDOCUMENT_H #include "Dialog.h" +#include "support/FileName.h" +#include "support/filetools.h" #include "support/types.h" #include +#include +#include namespace lyx { @@ -22,9 +27,11 @@ class BufferParams; class TextClass; namespace frontend { - + /// typedef void const * BufferId; +/// +typedef std::map ModuleMap; /** A controller for Document dialogs. */ @@ -54,6 +61,14 @@ public: BufferParams & params() const; /// BufferId id() const; + /// List of available modules + std::vector getModuleNames(); + /// Modules in use in current buffer + std::vector const & getSelectedModules(); + /// + std::string getModuleDescription(std::string modName) const; + /// + std::vector getPackageList(std::string modName) const; /// void setLanguage() const; /// @@ -67,8 +82,12 @@ public: /// does this font provide size adjustment? bool const providesScale(std::string const & font) const; private: + /// + void loadModuleNames(); /// boost::scoped_ptr bp_; + /// List of names of available modules + std::vector moduleNames_; }; } // namespace frontend diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 2fb693eba5..7b3e9e254e 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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. */ @@ -565,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()) { @@ -866,6 +881,44 @@ void GuiDocumentDialog::classChanged() } +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 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 = controller().params().getTextClass(); @@ -970,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; @@ -1153,6 +1213,13 @@ static size_t findPos(std::vector 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 @@ -1252,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( @@ -1272,7 +1340,7 @@ void GuiDocumentDialog::updateParams(BufferParams const & params) // text layout latexModule->classCO->setCurrentIndex(params.getBaseClass()); - + updatePagestyle(controller().textClass().opt_pagestyle(), params.pagestyle); @@ -1283,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()) { @@ -1420,12 +1486,6 @@ void GuiDocumentDialog::applyView() } -void GuiDocumentDialog::updateContents() -{ - updateParams(controller().params()); -} - - void GuiDocumentDialog::saveDocDefault() { // we have to apply the params first @@ -1434,12 +1494,31 @@ void GuiDocumentDialog::saveDocDefault() } +void GuiDocumentDialog::updateContents() +{ + //update list of available modules + QStringList strlist; + vector const modNames = controller().getModuleNames(); + vector::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 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(); updateContents(); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index f94ad62130..bd70aad9db 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -5,6 +5,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. */ @@ -15,6 +16,7 @@ #include "GuiDialog.h" #include "BulletsModule.h" #include "ControlDocument.h" +#include "GuiSelectionManager.h" #include "ui_DocumentUi.h" #include "ui_FontUi.h" @@ -29,6 +31,8 @@ #include "ui_PreambleUi.h" #include +#include +#include #include #include @@ -49,15 +53,12 @@ namespace lyx { namespace frontend { class GuiBranches; -class GuiDocument; class PreambleModule; class GuiDocumentDialog : public GuiDialog, public Ui::DocumentUi { Q_OBJECT public: - friend class GuiDocument; - GuiDocumentDialog(LyXView & lv); void updateParams(BufferParams const & params); @@ -78,6 +79,7 @@ public Q_SLOTS: void useDefaultsClicked(); private Q_SLOTS: + void updateParams(); void setLSpacing(int); void setMargins(bool); void setCustomPapersize(int); @@ -89,7 +91,8 @@ private Q_SLOTS: void enableSkip(bool); void portraitChanged(); void classChanged(); - + void updateModuleInfo(); + private: void closeEvent(QCloseEvent * e); @@ -104,17 +107,23 @@ private: UiWidget *mathsModule; UiWidget *latexModule; PreambleModule *preambleModule; - + GuiBranches *branchesModule; BulletsModule * bulletsModule; FloatPlacement * floatModule; - /// FIXME + GuiSelectionManager * selectionManager; + + // FIXME std::vector lang_; /// parent controller ControlDocument & controller(); + /// Available modules + QStringListModel * availableModel() { return &available_model_; } + /// Selected modules + QStringListModel * selectedModel() { return &selected_model_; } private: /// Apply changes void applyView(); @@ -124,6 +133,12 @@ private: void saveDocDefault(); /// reset to default params void useClassDefaults(); + /// available modules + QStringListModel available_model_; + /// selected modules + QStringListModel selected_model_; + +protected: /// return false if validate_listings_params returns error bool isValid(); }; @@ -158,4 +173,4 @@ private: } // namespace frontend } // namespace lyx -#endif // GUIDOCUMENT_H +#endif // QDOCUMENT_H diff --git a/src/frontends/qt4/ui/LaTeXUi.ui b/src/frontends/qt4/ui/LaTeXUi.ui index 61f3b31942..f13889328f 100644 --- a/src/frontends/qt4/ui/LaTeXUi.ui +++ b/src/frontends/qt4/ui/LaTeXUi.ui @@ -1,12 +1,15 @@ + + + LaTeXUi 0 0 - 307 - 178 + 428 + 465 @@ -19,49 +22,139 @@ 6 - + Qt::Vertical - 20 - 40 + 84 + 41 - + Qt::Horizontal - 40 - 20 + 261 + 22 - + false - - + + - Document &class: + Postscript &driver: - classCO + psdriverCO + + + + + + + Modules + + + + 9 + + + 6 + + + + + Available Modules + + + + + + + Selected Modules + + + + + + + QAbstractItemView::NoEditTriggers + + + + + + + Add + + + + + + + QAbstractItemView::NoEditTriggers + + + + + + + Delete + + + + + + + Up + + + + + + + Down + + + + + + + Qt::Vertical + + + + 80 + 46 + + + + + + + + + + @@ -72,27 +165,32 @@ - - + + + + + - Postscript &driver: + Document &class: - psdriverCO + classCO - - - - - - + classCO optionsLE + availableLV + addPB + deletePB + upPB + downPB + selectedLV + infoML psdriverCO