This is the last of a series of patches that merges the layout modules development in personal/branches/rgheck back into the tree.

Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.

This patch adds the GUI for managing modules.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20282 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2007-09-15 01:55:09 +00:00
parent 6f0703e707
commit 2499fdf7f5
5 changed files with 303 additions and 47 deletions

View 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.
*/
@ -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<string> ControlDocument::getModuleNames()
{
return moduleNames_;
}
vector<string> 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<std::string>
ControlDocument::getPackageList(std::string modName) const {
LyXModule const * const mod = moduleList[modName];
if (!mod)
return std::vector<std::string>(); //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

View File

@ -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 <boost/scoped_ptr.hpp>
#include <map>
#include <vector>
namespace lyx {
@ -22,9 +27,11 @@ class BufferParams;
class TextClass;
namespace frontend {
///
typedef void const * BufferId;
///
typedef std::map<std::string, support::FileName> ModuleMap;
/** A controller for Document dialogs.
*/
@ -54,6 +61,14 @@ public:
BufferParams & params() const;
///
BufferId id() const;
/// List of available modules
std::vector<std::string> getModuleNames();
/// Modules in use in current buffer
std::vector<std::string> const & getSelectedModules();
///
std::string getModuleDescription(std::string modName) const;
///
std::vector<std::string> 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<BufferParams> bp_;
/// List of names of available modules
std::vector<std::string> moduleNames_;
};
} // namespace frontend

View 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.
*/
@ -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<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 = 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<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
@ -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<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();
updateContents();
}

View File

@ -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 <QDialog>
#include <QStringList>
#include <QStringListModel>
#include <vector>
#include <string>
@ -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<Ui::MathsUi> *mathsModule;
UiWidget<Ui::LaTeXUi> *latexModule;
PreambleModule *preambleModule;
GuiBranches *branchesModule;
BulletsModule * bulletsModule;
FloatPlacement * floatModule;
/// FIXME
GuiSelectionManager * selectionManager;
// FIXME
std::vector<std::string> 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

View File

@ -1,12 +1,15 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>LaTeXUi</class>
<widget class="QWidget" name="LaTeXUi" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>307</width>
<height>178</height>
<width>428</width>
<height>465</height>
</rect>
</property>
<property name="windowTitle" >
@ -19,49 +22,139 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="3" column="1" >
<item row="5" column="2" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
<width>84</width>
<height>41</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2" >
<item row="4" column="3" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
<width>261</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" >
<item row="4" column="2" >
<widget class="QComboBox" name="psdriverCO" >
<property name="duplicatesEnabled" >
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="classL" >
<item row="4" column="0" colspan="2" >
<widget class="QLabel" name="psdriverL" >
<property name="text" >
<string>Document &amp;class:</string>
<string>Postscript &amp;driver:</string>
</property>
<property name="buddy" >
<cstring>classCO</cstring>
<cstring>psdriverCO</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4" >
<widget class="QTextBrowser" name="infoML" />
</item>
<item row="2" column="0" colspan="4" >
<widget class="QGroupBox" name="modulesGB" >
<property name="title" >
<string>Modules</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="availmodL" >
<property name="text" >
<string>Available Modules</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QLabel" name="selmodL" >
<property name="text" >
<string>Selected Modules</string>
</property>
</widget>
</item>
<item rowspan="5" row="1" column="0" >
<widget class="QListView" name="availableLV" >
<property name="editTriggers" >
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QPushButton" name="addPB" >
<property name="text" >
<string>Add</string>
</property>
</widget>
</item>
<item rowspan="5" row="1" column="2" >
<widget class="QListView" name="selectedLV" >
<property name="editTriggers" >
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QPushButton" name="deletePB" >
<property name="text" >
<string>Delete</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QPushButton" name="upPB" >
<property name="text" >
<string>Up</string>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QPushButton" name="downPB" >
<property name="text" >
<string>Down</string>
</property>
</widget>
</item>
<item row="5" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>80</width>
<height>46</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="1" column="1" colspan="3" >
<widget class="QLineEdit" name="optionsLE" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="optionsL" >
<property name="text" >
@ -72,27 +165,32 @@
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="psdriverL" >
<item row="0" column="1" colspan="3" >
<widget class="QComboBox" name="classCO" />
</item>
<item row="0" column="0" >
<widget class="QLabel" name="classL" >
<property name="text" >
<string>Postscript &amp;driver:</string>
<string>Document &amp;class:</string>
</property>
<property name="buddy" >
<cstring>psdriverCO</cstring>
<cstring>classCO</cstring>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<widget class="QComboBox" name="classCO" />
</item>
<item row="1" column="1" colspan="2" >
<widget class="QLineEdit" name="optionsLE" />
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<tabstops>
<tabstop>classCO</tabstop>
<tabstop>optionsLE</tabstop>
<tabstop>availableLV</tabstop>
<tabstop>addPB</tabstop>
<tabstop>deletePB</tabstop>
<tabstop>upPB</tabstop>
<tabstop>downPB</tabstop>
<tabstop>selectedLV</tabstop>
<tabstop>infoML</tabstop>
<tabstop>psdriverCO</tabstop>
</tabstops>
<includes>