#include "BufferParams.h"
#include "BufferView.h"
#include "Color.h"
+#include "EmbeddedFiles.h"
#include "Encoding.h"
#include "FloatPlacement.h"
-#include "frontend_helpers.h"
#include "FuncRequest.h"
-#include "gettext.h"
+#include "support/gettext.h"
#include "GuiBranches.h"
#include "Language.h"
#include "LaTeXFeatures.h"
#include "TextClassList.h"
#include "Validator.h"
-
-// FIXME: those two headers are needed because of the
-// WorkArea::redraw() call below.
-#include "frontends/LyXView.h"
-#include "frontends/WorkArea.h"
-
#include "insets/InsetListingsParams.h"
+#include "support/FileName.h"
+#include "support/filetools.h"
#include "support/lstrings.h"
#include <boost/bind.hpp>
#include <algorithm>
#include <sstream>
-using std::distance;
-using std::make_pair;
-using std::pair;
-using std::vector;
-using std::string;
-using std::ostringstream;
-using std::sort;
+using namespace std;
+using namespace lyx::support;
///
template<class Pair>
-std::vector<typename Pair::second_type> const
-getSecond(std::vector<Pair> const & pr)
+vector<typename Pair::second_type> const
+getSecond(vector<Pair> const & pr)
{
- std::vector<typename Pair::second_type> tmp(pr.size());
- std::transform(pr.begin(), pr.end(), tmp.begin(),
+ vector<typename Pair::second_type> tmp(pr.size());
+ transform(pr.begin(), pr.end(), tmp.begin(),
boost::bind(&Pair::second, _1));
return tmp;
}
namespace lyx {
namespace frontend {
-using support::token;
-using support::bformat;
-using support::findToken;
-using support::getVectorFromString;
+namespace {
+ vector<string> getRequiredList(string const & modName)
+ {
+ LyXModule const * const mod = moduleList[modName];
+ if (!mod)
+ return vector<string>(); //empty such thing
+ return mod->getRequiredModules();
+ }
+
+
+ vector<string> getExcludedList(string const & modName)
+ {
+ LyXModule const * const mod = moduleList[modName];
+ if (!mod)
+ return vector<string>(); //empty such thing
+ return mod->getExcludedModules();
+ }
+
+
+ docstring getModuleDescription(string const & modName)
+ {
+ LyXModule const * const mod = moduleList[modName];
+ if (!mod)
+ return _("Module not found!");
+ return from_ascii(mod->getDescription());
+ }
+
+
+ vector<string> getPackageList(string const & modName)
+ {
+ LyXModule const * const mod = moduleList[modName];
+ if (!mod)
+ return vector<string>(); //empty such thing
+ return mod->getPackageList();
+ }
+
+
+ bool isModuleAvailable(string const & modName)
+ {
+ LyXModule * mod = moduleList[modName];
+ if (!mod)
+ return false;
+ return mod->isAvailable();
+ }
+} //anonymous namespace
+
+
+ModuleSelMan::ModuleSelMan(
+ QListView * availableLV,
+ QListView * selectedLV,
+ QPushButton * addPB,
+ QPushButton * delPB,
+ QPushButton * upPB,
+ QPushButton * downPB,
+ QStringListModel * availableModel,
+ QStringListModel * selectedModel) :
+GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
+ upPB, downPB, availableModel, selectedModel)
+{}
+
+
+void ModuleSelMan::updateAddPB()
+{
+ int const arows = availableLV->model()->rowCount();
+ QModelIndexList const availSels =
+ availableLV->selectionModel()->selectedIndexes();
+ if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
+ addPB->setEnabled(false);
+ return;
+ }
+
+ QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
+ string const modName = fromqstr(idx.data().toString());
+ vector<string> reqs = getRequiredList(modName);
+ vector<string> excl = getExcludedList(modName);
+
+ if (reqs.empty() && excl.empty()) {
+ addPB->setEnabled(true);
+ return;
+ }
+
+ QStringList const & qsl = selectedModel->stringList();
+
+ //Check whether some required module is available
+ if (!reqs.empty()) {
+ bool foundOne = false;
+ vector<string>::const_iterator it = reqs.begin();
+ vector<string>::const_iterator end = reqs.end();
+ for (; it != end; ++it) {
+ if (qsl.contains(toqstr(*it))) {
+ foundOne = true;
+ break;
+ }
+ }
+ if (!foundOne) {
+ addPB->setEnabled(false);
+ return;
+ }
+ }
+
+ //Check whether any excluded module is being used
+ if (!excl.empty()) {
+ vector<string>::const_iterator it = excl.begin();
+ vector<string>::const_iterator end = excl.end();
+ for (; it != end; ++it) {
+ if (qsl.contains(toqstr(*it))) {
+ addPB->setEnabled(false);
+ return;
+ }
+ }
+ }
+
+ addPB->setEnabled(true);
+}
+
/////////////////////////////////////////////////////////////////////
//
-GuiDocument::GuiDocument(LyXView & lv)
+GuiDocument::GuiDocument(GuiView & lv)
: GuiDialog(lv, "document")
{
setupUi(this);
this, SLOT(classChanged()));
selectionManager =
- new GuiSelectionManager(latexModule->availableLV, latexModule->selectedLV,
+ new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
latexModule->addPB, latexModule->deletePB,
latexModule->upPB, latexModule->downPB,
availableModel(), selectedModel());
connect(bulletsModule, SIGNAL(changed()),
this, SLOT(change_adaptor()));
+ // embedded files
+ embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
+ connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
+ this, SLOT(change_adaptor()));
+ connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+ connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+
// PDF support
pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
this, SLOT(change_adaptor()));
connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
this, SLOT(change_adaptor()));
+ connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
+ this, SLOT(change_adaptor()));
connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
this, SLOT(change_adaptor()));
connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
docPS->addPanel(floatModule, _("Float Placement"));
docPS->addPanel(bulletsModule, _("Bullets"));
docPS->addPanel(branchesModule, _("Branches"));
+ docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
docPS->addPanel(preambleModule, _("LaTeX Preamble"));
docPS->setCurrentPanel(_("Document Class"));
// FIXME: hack to work around resizing bug in Qt >= 4.2
void GuiDocument::classChanged()
{
textclass_type const tc = latexModule->classCO->currentIndex();
- bp_.setJustBaseClass(tc);
+ bp_.setBaseClass(tc);
if (lyxrc.auto_reset_options)
bp_.useClassDefaults();
updateContents();
}
+namespace {
+ //This is an insanely complicated attempt to make this sort of thing
+ //work with RTL languages.
+ docstring formatStrVec(vector<string> const & v, docstring const & s)
+ {
+ //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
+ int const vSize = v.size();
+ if (v.size() == 0)
+ return docstring();
+ else if (v.size() == 1)
+ return from_ascii(v[0]);
+ else if (v.size() == 2) {
+ docstring retval = _("%1$s and %2$s");
+ retval = subst(retval, _("and"), s);
+ return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
+ }
+ //The idea here is to format all but the last two items...
+ docstring t2 = _("%1$s, %2$s");
+ docstring retval = from_ascii(v[0]);
+ for (int i = 1; i < vSize - 2; ++i)
+ retval = bformat(t2, retval, from_ascii(v[i]));
+ //...and then to plug them, and the last two, into this schema
+ docstring t = _("%1$s, %2$s, and %3$s");
+ t = subst(t, _("and"), s);
+ return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
+ }
+}
+
+
void GuiDocument::updateModuleInfo()
{
selectionManager->update();
//Module description
QListView const * const lv = selectionManager->selectedFocused() ?
latexModule->selectedLV :
- latexModule->availableLV;
+ latexModule->availableLV;
if (lv->selectionModel()->selectedIndexes().isEmpty())
latexModule->infoML->document()->clear();
else {
- QModelIndex const idx = lv->selectionModel()->currentIndex();
+ QModelIndex const & idx = lv->selectionModel()->currentIndex();
string const modName = fromqstr(idx.data().toString());
- string desc = getModuleDescription(modName);
+ docstring desc = getModuleDescription(modName);
+
vector<string> pkgList = 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];
+ docstring pkgdesc = formatStrVec(pkgList, _("and"));
+ if (!pkgdesc.empty()) {
+ if (!desc.empty())
+ desc += "\n";
+ desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
+ }
+
+ pkgList = getRequiredList(modName);
+ pkgdesc = formatStrVec(pkgList, _("or"));
+ if (!pkgdesc.empty()) {
+ if (!desc.empty())
+ desc += "\n";
+ desc += bformat(_("Module required: %1$s."), pkgdesc);
+ }
+
+ pkgList = getExcludedList(modName);
+ pkgdesc = formatStrVec(pkgList, _( "and"));
+ if (!pkgdesc.empty()) {
+ if (!desc.empty())
+ desc += "\n";
+ desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
+ }
+
+ if (!isModuleAvailable(modName)) {
+ if (!desc.empty())
+ desc += "\n";
+ desc += _("WARNING: Some packages are unavailable!");
}
- if (!pkgdesc.empty())
- desc += " Requires " + pkgdesc + ".";
latexModule->infoML->document()->setPlainText(toqstr(desc));
}
}
+void GuiDocument::updateEmbeddedFileList()
+{
+ embeddedFilesModule->filesLW->clear();
+ // add current embedded files
+ EmbeddedFileList & files = buffer().embeddedFiles();
+ files.update(buffer());
+ EmbeddedFileList::iterator fit = files.begin();
+ EmbeddedFileList::iterator fit_end = files.end();
+ for (; fit != fit_end; ++fit) {
+ QString label = toqstr(fit->relFilename(buffer().filePath()));
+ if (fit->refCount() > 1)
+ label += " (" + QString::number(fit->refCount()) + ")";
+ QListWidgetItem * item = new QListWidgetItem(label);
+ item->setFlags(item->flags() | Qt::ItemIsSelectable
+ | Qt::ItemIsUserCheckable);
+ if(fit->embedded())
+ item->setCheckState(Qt::Checked);
+ else
+ item->setCheckState(Qt::Unchecked);
+ // index of the currently used ParConstIterator
+ embeddedFilesModule->filesLW->addItem(item);
+ }
+}
+
+
void GuiDocument::updateNumbering()
{
TextClass const & tclass = bp_.getTextClass();
params.graphicsDriver =
tex_graphics[latexModule->psdriverCO->currentIndex()];
+ // text layout
+ params.setBaseClass(latexModule->classCO->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;
} else {
params.use_esint = BufferParams::package_off;
}
- // text layout
- params.setJustBaseClass(latexModule->classCO->currentIndex());
-
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
params.pagestyle = "default";
else {
pageLayoutModule->paperheightUnitCO);
if (pageLayoutModule->facingPagesCB->isChecked())
- params.sides = TextClass::TwoSides;
+ params.sides = TwoSides;
else
- params.sides = TextClass::OneSide;
+ params.sides = OneSide;
if (pageLayoutModule->landscapeRB->isChecked())
params.orientation = ORIENTATION_LANDSCAPE;
pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
+ pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
pdf.backref = pdfSupportModule->backrefCB->isChecked();
pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
else
pdf.pagemode.clear();
pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
- if (pdf.use_hyperref || !pdf.empty())
- pdf.store_options = true;
+
+ // Embedded files
+ // FIXME
}
If not found, return 0.
*/
template<class A>
-static size_t findPos(std::vector<A> const & vec, A const & val)
+static size_t findPos(vector<A> const & vec, A const & val)
{
- typename std::vector<A>::const_iterator it =
- std::find(vec.begin(), vec.end(), val);
+ typename vector<A>::const_iterator it =
+ find(vec.begin(), vec.end(), val);
if (it == vec.end())
return 0;
return distance(vec.begin(), it);
pageLayoutModule->portraitRB->setChecked(!landscape);
pageLayoutModule->facingPagesCB->setChecked(
- params.sides == TextClass::TwoSides);
+ params.sides == TwoSides);
lengthToWidgets(pageLayoutModule->paperwidthLE,
pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
+ pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
pdfSupportModule->backrefCB->setChecked(pdf.backref);
pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
pdfSupportModule->optionsLE->setText(
toqstr(pdf.quoted_options));
+
+ // embedded files
+ updateEmbeddedFileList();
}
it = selMods.begin();
for (; it != selMods.end(); ++it)
strlist2.push_back(toqstr(*it));
+ //FIXME It'd be nice to make sure here that the selected
+ //modules are consistent: That required modules are actually
+ //selected, and that we don't have conflicts. If so, we could
+ //at least pop up a warning.
selected_model_.setStringList(strlist2);
updateParams(bp_);
void GuiDocument::useClassDefaults()
{
- bp_.setJustBaseClass(latexModule->classCO->currentIndex());
+ bp_.setBaseClass(latexModule->classCO->currentIndex());
bp_.useClassDefaults();
updateContents();
}
}
-vector<string> GuiDocument::getModuleNames()
+vector<string> const & GuiDocument::getModuleNames()
{
return moduleNames_;
}
}
-string GuiDocument::getModuleDescription(string const & modName) const
-{
- LyXModule const * const mod = moduleList[modName];
- if (!mod)
- return string("Module unavailable!");
- return mod->description;
-}
-
-
-vector<string>
-GuiDocument::getPackageList(string const & modName) const
-{
- LyXModule const * const mod = moduleList[modName];
- if (!mod)
- return vector<string>(); //empty such thing
- return mod->packageList;
-}
-
-
TextClass const & GuiDocument::textClass() const
{
return textclasslist[bp_.getBaseClass()];
// Apply the BufferParams. Note that this will set the base class
// and then update the buffer's layout.
- //FIXME Could this be done last? Then, I think, we'd get the automatic
- //update mentioned in the next FIXME...
dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
// Generate the colours requested by each new branch.
"assign branch"));
}
// FIXME: If we used an LFUN, we would not need those two lines:
- bufferview()->update();
- lyxview().currentWorkArea()->redraw();
+ bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
}
moduleNames_.clear();
LyXModuleList::const_iterator it = moduleList.begin();
for (; it != moduleList.end(); ++it)
- moduleNames_.push_back(it->name);
+ moduleNames_.push_back(it->getName());
if (!moduleNames_.empty())
sort(moduleNames_.begin(), moduleNames_.end());
}
-Dialog * createGuiDocument(LyXView & lv) { return new GuiDocument(lv); }
+Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
} // namespace frontend