#include "insets/InsetListingsParams.h"
+#include "support/debug.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/lstrings.h"
using namespace lyx::support;
+namespace {
///
template<class Pair>
vector<typename Pair::second_type> const
vector<pair<string, lyx::docstring> > pagestyles;
+} // anonymous namespace
+
namespace lyx {
+
+namespace {
+// used when sorting the textclass list.
+class less_textclass_avail_desc
+ : public binary_function<string, string, int>
+{
+public:
+ int operator()(string const & lhs, string const & rhs) const
+ {
+ // Ordering criteria:
+ // 1. Availability of text class
+ // 2. Description (lexicographic)
+ LayoutFile const & tc1 = BaseClassList::get()[lhs];
+ LayoutFile const & tc2 = BaseClassList::get()[rhs];
+ return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
+ (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
+ _(tc1.description()) < _(tc2.description()));
+ }
+};
+
+}
+
namespace frontend {
/////////////////////////////////////////////////////////////////////
-
GuiDocument::GuiDocument(GuiView & lv)
: GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
{
latexModule->psdriverCO->addItem(enc);
}
// latex classes
- //FIXME This seems too involved with the kernel. Some of this
- //should be moved to the kernel---which should perhaps just
- //give us a list of entries or something of the sort.
- for (BaseClassList::const_iterator cit = BaseClassList::get().begin();
- cit != BaseClassList::get().end(); ++cit) {
- if (cit->isTeXClassAvailable()) {
- latexModule->classCO->addItem(toqstr(cit->description()));
- } else {
- docstring item =
- bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
- latexModule->classCO->addItem(toqstr(item));
- }
+ latexModule->classCO->setModel(&classes_model_);
+ BaseClassList const & bcl = BaseClassList::get();
+ vector<LayoutFileIndex> classList = bcl.classList();
+ sort(classList.begin(), classList.end(), less_textclass_avail_desc());
+
+ vector<LayoutFileIndex>::const_iterator cit = classList.begin();
+ vector<LayoutFileIndex>::const_iterator cen = classList.end();
+ for (int i = 0; cit != cen; ++cit, ++i) {
+ LayoutFile const & tc = bcl[*cit];
+ docstring item = (tc.isTeXClassAvailable()) ?
+ from_utf8(tc.description()) :
+ bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
+ classes_model_.insertRow(i, toqstr(item), *cit);
}
// branches
void GuiDocument::classChanged()
{
- BaseClassIndex const tc = latexModule->classCO->currentIndex();
- bp_.setBaseClass(tc);
+ int idx = latexModule->classCO->currentIndex();
+ if (idx < 0)
+ return;
+ string const classname = classes_model_.getIDString(idx);
+ // check if this is a local layout file
+ if (prefixIs(classname, BaseClassList::localPrefix)) {
+ int const ret = Alert::prompt(_("Local layout file"),
+ _("The layout file you have selected is a local layout\n"
+ "file, not one in the system or user directory. Your\n"
+ "document may not work with this layout if you do not\n"
+ "keep the layout file in the same directory."),
+ 1, 1, _("&Set Layout"), _("&Cancel"));
+ if (ret == 1) {
+ // try to reset the layout combo
+ setLayoutComboByIDString(bp_.baseClassID());
+ return;
+ }
+ }
+ if (!bp_.setBaseClass(classname)) {
+ Alert::error(_("Error"), _("Unable to set document class."));
+ return;
+ }
if (lyxrc.auto_reset_options) {
if (applyPB->isEnabled()) {
int const ret = Alert::prompt(_("Unapplied changes"),
- _("Some changes in the dialog were not yet applied."
+ _("Some changes in the dialog were not yet applied.\n"
"If you do not apply now, they will be lost after this action."),
1, 1, _("&Apply"), _("&Dismiss"));
if (ret == 0)
}
QModelIndex const & idx = lv->selectionModel()->currentIndex();
GuiIdListModel const & idModel =
- focusOnSelected ? selected_model_ : available_model_;
+ focusOnSelected ? modules_sel_model_ : modules_av_model_;
string const modName = idModel.getIDString(idx.row());
docstring desc = getModuleDescription(modName);
tex_graphics[latexModule->psdriverCO->currentIndex()];
// text layout
- params.setBaseClass(latexModule->classCO->currentIndex());
+ int idx = latexModule->classCO->currentIndex();
+ if (idx >= 0) {
+ string const classname = classes_model_.getIDString(idx);
+ params.setBaseClass(classname);
+ }
// Modules
params.clearLayoutModules();
- int const srows = selected_model_.rowCount();
+ int const srows = modules_sel_model_.rowCount();
vector<string> selModList;
for (int i = 0; i < srows; ++i)
- params.addLayoutModule(selected_model_.getIDString(i));
+ params.addLayoutModule(modules_sel_model_.getIDString(i));
if (mathsModule->amsautoCB->isChecked()) {
params.use_amsmath = BufferParams::package_auto;
langModule->otherencodingRB->setChecked(!default_enc);
// numbering
- int const min_toclevel = textClass().min_toclevel();
- int const max_toclevel = textClass().max_toclevel();
- if (textClass().hasTocLevels()) {
+ int const min_toclevel = documentClass().min_toclevel();
+ int const max_toclevel = documentClass().max_toclevel();
+ if (documentClass().hasTocLevels()) {
numberingModule->setEnabled(true);
numberingModule->depthSL->setMinimum(min_toclevel - 1);
numberingModule->depthSL->setMaximum(max_toclevel);
}
// text layout
- latexModule->classCO->setCurrentIndex(params.baseClass());
-
- updatePagestyle(textClass().opt_pagestyle(),
+ string const & layoutID = params.baseClassID();
+ setLayoutComboByIDString(layoutID);
+
+ updatePagestyle(documentClass().opt_pagestyle(),
params.pagestyle);
textLayoutModule->lspacingCO->setCurrentIndex(nitem);
floatModule->set(params.float_placement);
// Fonts
- updateFontsize(textClass().opt_fontsize(),
+ updateFontsize(documentClass().opt_fontsize(),
params.fontsize);
int n = findToken(tex_fonts_roman, params.fontsRoman);
void GuiDocument::updateAvailableModules()
{
- available_model_.clear();
+ modules_av_model_.clear();
vector<modInfoStruct> const modInfoList = getModuleInfo();
int const mSize = modInfoList.size();
for (int i = 0; i < mSize; ++i) {
modInfoStruct const & modInfo = modInfoList[i];
- available_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
+ modules_av_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
}
}
void GuiDocument::updateSelectedModules()
{
//and selected ones, too
- selected_model_.clear();
+ modules_sel_model_.clear();
vector<modInfoStruct> const selModList = getSelectedModules();
int const sSize = selModList.size();
for (int i = 0; i < sSize; ++i) {
modInfoStruct const & modInfo = selModList[i];
- selected_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
+ modules_sel_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
}
}
applyView();
}
- bp_.setBaseClass(latexModule->classCO->currentIndex());
+ int idx = latexModule->classCO->currentIndex();
+ string const classname = classes_model_.getIDString(idx);
+ if (!bp_.setBaseClass(classname)) {
+ Alert::error(_("Error"), _("Unable to set document class."));
+ return;
+ }
bp_.useClassDefaults();
forceUpdate();
}
+void GuiDocument::setLayoutComboByIDString(std::string const & idString)
+{
+ int idx = classes_model_.findIDString(idString);
+ if (idx < 0)
+ Alert::warning(_("Can't set layout!"),
+ bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
+ else
+ latexModule->classCO->setCurrentIndex(idx);
+}
+
+
bool GuiDocument::isValid()
{
return (validate_listings_params().empty() &&
}
-TextClass const & GuiDocument::textClass() const
+DocumentClass const & GuiDocument::documentClass() const
{
- return BaseClassList::get()[bp_.baseClass()];
+ return bp_.documentClass();
}