2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "BaseClassList.h"
17 #include "BranchList.h"
18 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
23 #include "EmbeddedFiles.h"
25 #include "FloatPlacement.h"
26 #include "FuncRequest.h"
27 #include "support/gettext.h"
28 #include "GuiBranches.h"
30 #include "LaTeXFeatures.h"
31 #include "LaTeXHighlighter.h"
33 #include "LengthCombo.h"
34 #include "LyXRC.h" // defaultUnit
35 #include "ModuleList.h"
36 #include "OutputParams.h"
37 #include "PanelStack.h"
38 #include "PDFOptions.h"
39 #include "qt_helpers.h"
41 #include "Validator.h"
43 #include "insets/InsetListingsParams.h"
45 #include "support/FileName.h"
46 #include "support/filetools.h"
47 #include "support/lstrings.h"
49 #include "frontends/alert.h"
51 #include <boost/bind.hpp>
53 #include <QCloseEvent>
55 #include <QTextCursor>
61 using namespace lyx::support;
66 vector<typename Pair::second_type> const
67 getSecond(vector<Pair> const & pr)
69 vector<typename Pair::second_type> tmp(pr.size());
70 transform(pr.begin(), pr.end(), tmp.begin(),
71 boost::bind(&Pair::second, _1));
76 char const * const tex_graphics[] =
78 "default", "dvips", "dvitops", "emtex",
79 "ln", "oztex", "textures", "none", ""
83 char const * const tex_graphics_gui[] =
85 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
86 "LN", "OzTeX", "Textures", N_("None"), ""
90 char const * const tex_fonts_roman[] =
92 "default", "cmr", "lmodern", "ae", "times", "palatino",
93 "charter", "newcent", "bookman", "utopia", "beraserif",
94 "ccfonts", "chancery", ""
98 char const * tex_fonts_roman_gui[] =
100 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
101 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
102 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
103 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
108 char const * const tex_fonts_sans[] =
110 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
114 char const * tex_fonts_sans_gui[] =
116 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
117 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
121 char const * const tex_fonts_monospaced[] =
123 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
127 char const * tex_fonts_monospaced_gui[] =
129 N_("Default"), N_("Computer Modern Typewriter"),
130 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
131 N_("LuxiMono"), N_("CM Typewriter Light"), ""
135 vector<pair<string, lyx::docstring> > pagestyles;
143 QModelIndex getSelectedIndex(QListView * lv)
145 QModelIndex retval = QModelIndex();
146 QModelIndexList selIdx =
147 lv->selectionModel()->selectedIndexes();
149 retval = selIdx.first();
155 vector<string> getRequiredList(string const & modName)
157 LyXModule const * const mod = moduleList[modName];
159 return vector<string>(); //empty such thing
160 return mod->getRequiredModules();
164 vector<string> getExcludedList(string const & modName)
166 LyXModule const * const mod = moduleList[modName];
168 return vector<string>(); //empty such thing
169 return mod->getExcludedModules();
173 docstring getModuleDescription(string const & modName)
175 LyXModule const * const mod = moduleList[modName];
177 return _("Module not found!");
178 return _(mod->getDescription());
182 vector<string> getPackageList(string const & modName)
184 LyXModule const * const mod = moduleList[modName];
186 return vector<string>(); //empty such thing
187 return mod->getPackageList();
191 bool isModuleAvailable(string const & modName)
193 LyXModule * mod = moduleList[modName];
196 return mod->isAvailable();
198 } //anonymous namespace
201 ModuleSelMan::ModuleSelMan(
202 QListView * availableLV,
203 QListView * selectedLV,
207 QPushButton * downPB,
208 GuiIdListModel * availableModel,
209 GuiIdListModel * selectedModel) :
210 GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
211 upPB, downPB, availableModel, selectedModel)
215 void ModuleSelMan::updateAddPB()
217 int const arows = availableModel->rowCount();
218 QModelIndexList const availSels =
219 availableLV->selectionModel()->selectedIndexes();
220 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
221 addPB->setEnabled(false);
225 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
226 string const modName = getAvailableModel()->getIDString(idx.row());
227 vector<string> reqs = getRequiredList(modName);
228 vector<string> excl = getExcludedList(modName);
230 if (reqs.empty() && excl.empty()) {
231 addPB->setEnabled(true);
235 int const srows = selectedModel->rowCount();
236 vector<string> selModList;
237 for (int i = 0; i < srows; ++i)
238 selModList.push_back(getSelectedModel()->getIDString(i));
240 vector<string>::const_iterator selModStart = selModList.begin();
241 vector<string>::const_iterator selModEnd = selModList.end();
243 //Check whether some required module is available
245 bool foundOne = false;
246 vector<string>::const_iterator it = reqs.begin();
247 vector<string>::const_iterator end = reqs.end();
248 for (; it != end; ++it) {
249 if (find(selModStart, selModEnd, *it) != selModEnd) {
255 addPB->setEnabled(false);
260 //Check whether any excluded module is being used
262 vector<string>::const_iterator it = excl.begin();
263 vector<string>::const_iterator end = excl.end();
264 for (; it != end; ++it) {
265 if (find(selModStart, selModEnd, *it) != selModEnd) {
266 addPB->setEnabled(false);
272 addPB->setEnabled(true);
276 void ModuleSelMan::updateDownPB()
278 int const srows = selectedModel->rowCount();
280 downPB->setEnabled(false);
283 QModelIndexList const selSels =
284 selectedLV->selectionModel()->selectedIndexes();
285 //disable if empty or last item is selected
286 if (selSels.empty() || selSels.first().row() == srows - 1) {
287 downPB->setEnabled(false);
290 //determine whether immediately succeding element requires this one
291 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
292 int curRow = curIdx.row();
293 if (curRow < 0 || curRow >= srows - 1) { //this shouldn't happen...
294 downPB->setEnabled(false);
297 string const curModName = getSelectedModel()->getIDString(curRow);
298 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
300 vector<string> reqs = getRequiredList(nextModName);
302 //if it doesn't require anything....
304 downPB->setEnabled(true);
308 //FIXME This should perhaps be more flexible and check whether, even
309 //if this one is required, there is also an earlier one that is required.
310 //enable it if this module isn't required
312 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
315 void ModuleSelMan::updateUpPB()
317 int const srows = selectedModel->rowCount();
319 upPB->setEnabled(false);
322 QModelIndexList const selSels =
323 selectedLV->selectionModel()->selectedIndexes();
324 //disable if empty or first item is selected
325 if (selSels.empty() || selSels.first().row() == 0) {
326 upPB->setEnabled(false);
330 //determine whether immediately preceding element is required by this one
331 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
332 int curRow = curIdx.row();
333 if (curRow <= -1 || curRow > srows - 1) { //sanity check
334 downPB->setEnabled(false);
337 string const curModName = getSelectedModel()->getIDString(curRow);
338 vector<string> reqs = getRequiredList(curModName);
340 //if this one doesn't require anything....
342 upPB->setEnabled(true);
346 string preModName = getSelectedModel()->getIDString(curRow - 1);
348 //NOTE This is less flexible than it might be. You could check whether, even
349 //if this one is required, there is also an earlier one that is required.
350 //enable it if the preceding module isn't required
351 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
354 void ModuleSelMan::updateDelPB()
356 int const srows = selectedModel->rowCount();
358 deletePB->setEnabled(false);
361 QModelIndexList const selSels =
362 selectedLV->selectionModel()->selectedIndexes();
363 if (selSels.empty() || selSels.first().row() < 0) {
364 deletePB->setEnabled(false);
368 //determine whether some LATER module requires this one
369 //NOTE Things are arranged so that this is the only way there
370 //can be a problem. At least, we hope so.
371 QModelIndex const & curIdx =
372 selectedLV->selectionModel()->currentIndex();
373 int const curRow = curIdx.row();
374 if (curRow < 0 || curRow >= srows) { //this shouldn't happen
375 deletePB->setEnabled(false);
379 QString const curModName = curIdx.data().toString();
381 //We're looking here for a reason NOT to enable the button. If we
382 //find one, we disable it and return. If we don't, we'll end up at
383 //the end of the function, and then we enable it.
384 for (int i = curRow + 1; i < srows; ++i) {
385 string const thisMod = getSelectedModel()->getIDString(i);
386 vector<string> reqs = getRequiredList(thisMod);
387 //does this one require us?
388 if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
392 //OK, so this module requires us
393 //is there an EARLIER module that also satisfies the require?
394 //NOTE We demand that it be earlier to keep the list of modules
395 //consistent with the rule that a module must be proceeded by a
396 //required module. There would be more flexible ways to proceed,
397 //but that would be a lot more complicated, and the logic here is
398 //already complicated. (That's why I've left the debugging code.)
399 //lyxerr << "Testing " << thisMod << std::endl;
400 bool foundOne = false;
401 for (int j = 0; j < curRow; ++j) {
402 string const mod = getSelectedModel()->getIDString(j);
403 //lyxerr << "In loop: Testing " << mod << std::endl;
404 //do we satisfy the require?
405 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
406 //lyxerr << mod << " does the trick." << std::endl;
411 //did we find a module to satisfy the require?
413 //lyxerr << "No matching module found." << std::endl;
414 deletePB->setEnabled(false);
418 //lyxerr << "All's well that ends well." << std::endl;
419 deletePB->setEnabled(true);
423 /////////////////////////////////////////////////////////////////////
427 /////////////////////////////////////////////////////////////////////
429 PreambleModule::PreambleModule(): current_id_(0)
431 // This is not a memory leak. The object will be destroyed
433 (void) new LaTeXHighlighter(preambleTE->document());
434 setFocusProxy(preambleTE);
435 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
439 void PreambleModule::update(BufferParams const & params, BufferId id)
441 QString preamble = toqstr(params.preamble);
442 // Nothing to do if the params and preamble are unchanged.
443 if (id == current_id_
444 && preamble == preambleTE->document()->toPlainText())
447 QTextCursor cur = preambleTE->textCursor();
448 // Save the coords before switching to the new one.
449 preamble_coords_[current_id_] =
450 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
452 // Save the params address for further use.
454 preambleTE->document()->setPlainText(preamble);
455 Coords::const_iterator it = preamble_coords_.find(current_id_);
456 if (it == preamble_coords_.end())
457 // First time we open this one.
458 preamble_coords_[current_id_] = make_pair(0,0);
460 // Restore saved coords.
461 QTextCursor cur = preambleTE->textCursor();
462 cur.setPosition(it->second.first);
463 preambleTE->setTextCursor(cur);
464 preambleTE->verticalScrollBar()->setValue(it->second.second);
469 void PreambleModule::apply(BufferParams & params)
471 params.preamble = fromqstr(preambleTE->document()->toPlainText());
475 void PreambleModule::closeEvent(QCloseEvent * e)
477 // Save the coords before closing.
478 QTextCursor cur = preambleTE->textCursor();
479 preamble_coords_[current_id_] =
480 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
485 /////////////////////////////////////////////////////////////////////
489 /////////////////////////////////////////////////////////////////////
493 GuiDocument::GuiDocument(GuiView & lv)
494 : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
498 lang_ = getSecond(getLanguageData(false));
500 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
501 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
502 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
503 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
505 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
506 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
508 // Manage the restore, ok, apply, restore and cancel/close buttons
509 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
511 bc().setApply(applyPB);
512 bc().setCancel(closePB);
513 bc().setRestore(restorePB);
515 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
517 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
518 this, SLOT(change_adaptor()));
519 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
520 this, SLOT(setLSpacing(int)));
521 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
522 this, SLOT(change_adaptor()));
523 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
524 this, SLOT(change_adaptor()));
525 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
526 this, SLOT(change_adaptor()));
527 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
528 this, SLOT(change_adaptor()));
529 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
530 this, SLOT(change_adaptor()));
531 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
532 this, SLOT(change_adaptor()));
533 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
534 this, SLOT(setSkip(int)));
535 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
536 this, SLOT(enableSkip(bool)));
537 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
538 this, SLOT(change_adaptor()));
539 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
540 this, SLOT(setColSep()));
541 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
542 this, SLOT(change_adaptor()));
543 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
544 this, SLOT(change_adaptor()));
545 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
546 this, SLOT(set_listings_msg()));
547 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
548 this, SLOT(set_listings_msg()));
549 textLayoutModule->listingsTB->setPlainText(
550 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
551 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
552 textLayoutModule->lspacingLE));
553 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
554 textLayoutModule->skipLE));
556 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
557 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
558 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
559 textLayoutModule->skipCO->addItem(qt_("Length"));
560 // remove the %-items from the unit choice
561 textLayoutModule->skipLengthCO->noPercents();
562 textLayoutModule->lspacingCO->insertItem(
563 Spacing::Single, qt_("Single"));
564 textLayoutModule->lspacingCO->insertItem(
565 Spacing::Onehalf, qt_("OneHalf"));
566 textLayoutModule->lspacingCO->insertItem(
567 Spacing::Double, qt_("Double"));
568 textLayoutModule->lspacingCO->insertItem(
569 Spacing::Other, qt_("Custom"));
571 // initialize the length validator
572 bc().addCheckedLineEdit(textLayoutModule->skipLE);
574 fontModule = new UiWidget<Ui::FontUi>;
576 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
577 this, SLOT(change_adaptor()));
578 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
579 this, SLOT(romanChanged(int)));
580 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
581 this, SLOT(change_adaptor()));
582 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
583 this, SLOT(sansChanged(int)));
584 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
585 this, SLOT(change_adaptor()));
586 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
587 this, SLOT(ttChanged(int)));
588 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
589 this, SLOT(change_adaptor()));
590 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
591 this, SLOT(change_adaptor()));
592 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
593 this, SLOT(change_adaptor()));
594 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
595 this, SLOT(change_adaptor()));
596 connect(fontModule->fontScCB, SIGNAL(clicked()),
597 this, SLOT(change_adaptor()));
598 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
599 this, SLOT(change_adaptor()));
601 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
602 QString font = qt_(tex_fonts_roman_gui[n]);
603 if (!isFontAvailable(tex_fonts_roman[n]))
604 font += qt_(" (not installed)");
605 fontModule->fontsRomanCO->addItem(font);
607 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
608 QString font = qt_(tex_fonts_sans_gui[n]);
609 if (!isFontAvailable(tex_fonts_sans[n]))
610 font += qt_(" (not installed)");
611 fontModule->fontsSansCO->addItem(font);
613 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
614 QString font = qt_(tex_fonts_monospaced_gui[n]);
615 if (!isFontAvailable(tex_fonts_monospaced[n]))
616 font += qt_(" (not installed)");
617 fontModule->fontsTypewriterCO->addItem(font);
620 fontModule->fontsizeCO->addItem(qt_("Default"));
621 fontModule->fontsizeCO->addItem(qt_("10"));
622 fontModule->fontsizeCO->addItem(qt_("11"));
623 fontModule->fontsizeCO->addItem(qt_("12"));
625 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
626 fontModule->fontsDefaultCO->addItem(
627 qt_(GuiDocument::fontfamilies_gui[n]));
630 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
632 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
633 this, SLOT(setCustomPapersize(int)));
634 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
635 this, SLOT(setCustomPapersize(int)));
636 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
637 this, SLOT(portraitChanged()));
638 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
639 this, SLOT(change_adaptor()));
640 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
641 this, SLOT(change_adaptor()));
642 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
643 this, SLOT(change_adaptor()));
644 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
645 this, SLOT(change_adaptor()));
646 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
647 this, SLOT(change_adaptor()));
648 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
649 this, SLOT(change_adaptor()));
650 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
651 this, SLOT(change_adaptor()));
652 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
653 this, SLOT(change_adaptor()));
654 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
655 this, SLOT(change_adaptor()));
657 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
658 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
659 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
660 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
661 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
662 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
663 pageLayoutModule->paperheightL);
664 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
665 pageLayoutModule->paperwidthL);
668 QComboBox * cb = pageLayoutModule->papersizeCO;
669 cb->addItem(qt_("Default"));
670 cb->addItem(qt_("Custom"));
671 cb->addItem(qt_("US letter"));
672 cb->addItem(qt_("US legal"));
673 cb->addItem(qt_("US executive"));
674 cb->addItem(qt_("A3"));
675 cb->addItem(qt_("A4"));
676 cb->addItem(qt_("A5"));
677 cb->addItem(qt_("B3"));
678 cb->addItem(qt_("B4"));
679 cb->addItem(qt_("B5"));
680 // remove the %-items from the unit choice
681 pageLayoutModule->paperwidthUnitCO->noPercents();
682 pageLayoutModule->paperheightUnitCO->noPercents();
683 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
684 pageLayoutModule->paperheightLE));
685 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
686 pageLayoutModule->paperwidthLE));
689 marginsModule = new UiWidget<Ui::MarginsUi>;
691 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
692 this, SLOT(setCustomMargins(bool)));
693 connect(marginsModule->marginCB, SIGNAL(clicked()),
694 this, SLOT(change_adaptor()));
695 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
696 this, SLOT(change_adaptor()));
697 connect(marginsModule->topUnit, SIGNAL(activated(int)),
698 this, SLOT(change_adaptor()));
699 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
700 this, SLOT(change_adaptor()));
701 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
702 this, SLOT(change_adaptor()));
703 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
704 this, SLOT(change_adaptor()));
705 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
706 this, SLOT(change_adaptor()));
707 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
708 this, SLOT(change_adaptor()));
709 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
710 this, SLOT(change_adaptor()));
711 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
712 this, SLOT(change_adaptor()));
713 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
714 this, SLOT(change_adaptor()));
715 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
716 this, SLOT(change_adaptor()));
717 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
718 this, SLOT(change_adaptor()));
719 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
720 this, SLOT(change_adaptor()));
721 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
722 this, SLOT(change_adaptor()));
723 connect(marginsModule->columnsepLE, SIGNAL(textChanged(const QString&)),
724 this, SLOT(change_adaptor()));
725 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
726 this, SLOT(change_adaptor()));
727 marginsModule->topLE->setValidator(unsignedLengthValidator(
728 marginsModule->topLE));
729 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
730 marginsModule->bottomLE));
731 marginsModule->innerLE->setValidator(unsignedLengthValidator(
732 marginsModule->innerLE));
733 marginsModule->outerLE->setValidator(unsignedLengthValidator(
734 marginsModule->outerLE));
735 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
736 marginsModule->headsepLE));
737 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
738 marginsModule->headheightLE));
739 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
740 marginsModule->footskipLE));
741 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
742 marginsModule->columnsepLE));
744 bc().addCheckedLineEdit(marginsModule->topLE,
745 marginsModule->topL);
746 bc().addCheckedLineEdit(marginsModule->bottomLE,
747 marginsModule->bottomL);
748 bc().addCheckedLineEdit(marginsModule->innerLE,
749 marginsModule->innerL);
750 bc().addCheckedLineEdit(marginsModule->outerLE,
751 marginsModule->outerL);
752 bc().addCheckedLineEdit(marginsModule->headsepLE,
753 marginsModule->headsepL);
754 bc().addCheckedLineEdit(marginsModule->headheightLE,
755 marginsModule->headheightL);
756 bc().addCheckedLineEdit(marginsModule->footskipLE,
757 marginsModule->footskipL);
758 bc().addCheckedLineEdit(marginsModule->columnsepLE,
759 marginsModule->columnsepL);
762 langModule = new UiWidget<Ui::LanguageUi>;
764 connect(langModule->languageCO, SIGNAL(activated(int)),
765 this, SLOT(change_adaptor()));
766 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
767 this, SLOT(change_adaptor()));
768 connect(langModule->otherencodingRB, SIGNAL(clicked()),
769 this, SLOT(change_adaptor()));
770 connect(langModule->encodingCO, SIGNAL(activated(int)),
771 this, SLOT(change_adaptor()));
772 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
773 this, SLOT(change_adaptor()));
775 vector<LanguagePair> const langs = getLanguageData(false);
776 vector<LanguagePair>::const_iterator lit = langs.begin();
777 vector<LanguagePair>::const_iterator lend = langs.end();
778 for (; lit != lend; ++lit) {
779 langModule->languageCO->addItem(toqstr(lit->first));
782 // Always put the default encoding in the first position.
783 // It is special because the displayed text is translated.
784 langModule->encodingCO->addItem(qt_("LaTeX default"));
785 Encodings::const_iterator it = encodings.begin();
786 Encodings::const_iterator const end = encodings.end();
787 for (; it != end; ++it)
788 langModule->encodingCO->addItem(toqstr(it->latexName()));
790 langModule->quoteStyleCO->addItem(qt_("``text''"));
791 langModule->quoteStyleCO->addItem(qt_("''text''"));
792 langModule->quoteStyleCO->addItem(qt_(",,text``"));
793 langModule->quoteStyleCO->addItem(qt_(",,text''"));
794 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
795 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
799 numberingModule = new UiWidget<Ui::NumberingUi>;
801 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
802 this, SLOT(change_adaptor()));
803 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
804 this, SLOT(change_adaptor()));
805 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
806 this, SLOT(updateNumbering()));
807 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
808 this, SLOT(updateNumbering()));
809 numberingModule->tocTW->setColumnCount(3);
810 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
811 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
812 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
815 biblioModule = new UiWidget<Ui::BiblioUi>;
816 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
817 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
818 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
819 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
821 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
822 this, SLOT(change_adaptor()));
823 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
824 this, SLOT(change_adaptor()));
825 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
826 this, SLOT(change_adaptor()));
827 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
828 this, SLOT(change_adaptor()));
829 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
830 this, SLOT(change_adaptor()));
832 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
833 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
834 biblioModule->citeStyleCO->setCurrentIndex(0);
837 mathsModule = new UiWidget<Ui::MathsUi>;
838 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
839 mathsModule->amsCB, SLOT(setDisabled(bool)));
840 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
841 mathsModule->esintCB, SLOT(setDisabled(bool)));
843 connect(mathsModule->amsCB, SIGNAL(clicked()),
844 this, SLOT(change_adaptor()));
845 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
846 this, SLOT(change_adaptor()));
847 connect(mathsModule->esintCB, SIGNAL(clicked()),
848 this, SLOT(change_adaptor()));
849 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
850 this, SLOT(change_adaptor()));
852 latexModule = new UiWidget<Ui::LaTeXUi>;
854 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
855 this, SLOT(change_adaptor()));
856 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
857 this, SLOT(change_adaptor()));
858 connect(latexModule->classCO, SIGNAL(activated(int)),
859 this, SLOT(classChanged()));
860 connect(latexModule->classCO, SIGNAL(activated(int)),
861 this, SLOT(change_adaptor()));
864 new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
865 latexModule->addPB, latexModule->deletePB,
866 latexModule->upPB, latexModule->downPB,
867 availableModel(), selectedModel());
868 connect(selectionManager, SIGNAL(updateHook()),
869 this, SLOT(updateModuleInfo()));
870 connect(selectionManager, SIGNAL(updateHook()),
871 this, SLOT(change_adaptor()));
873 // postscript drivers
874 for (int n = 0; tex_graphics[n][0]; ++n) {
875 QString enc = qt_(tex_graphics_gui[n]);
876 latexModule->psdriverCO->addItem(enc);
879 //FIXME This seems too involved with the kernel. Some of this
880 //should be moved to the kernel---which should perhaps just
881 //give us a list of entries or something of the sort.
882 for (BaseClassList::const_iterator cit = baseclasslist.begin();
883 cit != baseclasslist.end(); ++cit) {
884 if (cit->isTeXClassAvailable()) {
885 latexModule->classCO->addItem(toqstr(cit->description()));
888 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
889 latexModule->classCO->addItem(toqstr(item));
894 branchesModule = new GuiBranches;
895 connect(branchesModule, SIGNAL(changed()),
896 this, SLOT(change_adaptor()));
899 preambleModule = new PreambleModule;
900 connect(preambleModule, SIGNAL(changed()),
901 this, SLOT(change_adaptor()));
904 bulletsModule = new BulletsModule;
905 connect(bulletsModule, SIGNAL(changed()),
906 this, SLOT(change_adaptor()));
909 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
910 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
911 this, SLOT(change_adaptor()));
912 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
913 this, SLOT(change_adaptor()));
914 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
915 this, SLOT(change_adaptor()));
918 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
920 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
921 this, SLOT(change_adaptor()));
922 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
923 this, SLOT(change_adaptor()));
924 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
925 this, SLOT(change_adaptor()));
926 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
927 this, SLOT(change_adaptor()));
928 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
929 this, SLOT(change_adaptor()));
930 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
931 this, SLOT(change_adaptor()));
932 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
933 this, SLOT(change_adaptor()));
934 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
935 this, SLOT(change_adaptor()));
936 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
937 this, SLOT(change_adaptor()));
938 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
939 this, SLOT(change_adaptor()));
940 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
941 this, SLOT(change_adaptor()));
942 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
943 this, SLOT(change_adaptor()));
944 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
945 this, SLOT(change_adaptor()));
946 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
947 this, SLOT(change_adaptor()));
948 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
949 this, SLOT(change_adaptor()));
950 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
951 this, SLOT(change_adaptor()));
952 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
953 this, SLOT(change_adaptor()));
956 floatModule = new FloatPlacement;
957 connect(floatModule, SIGNAL(changed()),
958 this, SLOT(change_adaptor()));
960 docPS->addPanel(latexModule, _("Document Class"));
961 docPS->addPanel(fontModule, _("Fonts"));
962 docPS->addPanel(textLayoutModule, _("Text Layout"));
963 docPS->addPanel(pageLayoutModule, _("Page Layout"));
964 docPS->addPanel(marginsModule, _("Page Margins"));
965 docPS->addPanel(langModule, _("Language"));
966 docPS->addPanel(numberingModule, _("Numbering & TOC"));
967 docPS->addPanel(biblioModule, _("Bibliography"));
968 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
969 docPS->addPanel(mathsModule, _("Math Options"));
970 docPS->addPanel(floatModule, _("Float Placement"));
971 docPS->addPanel(bulletsModule, _("Bullets"));
972 docPS->addPanel(branchesModule, _("Branches"));
973 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
974 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
975 docPS->setCurrentPanel(_("Document Class"));
976 // FIXME: hack to work around resizing bug in Qt >= 4.2
977 // bug verified with Qt 4.2.{0-3} (JSpitzm)
978 #if QT_VERSION >= 0x040200
979 docPS->updateGeometry();
984 void GuiDocument::showPreamble()
986 docPS->setCurrentPanel(_("LaTeX Preamble"));
990 void GuiDocument::saveDefaultClicked()
996 void GuiDocument::useDefaultsClicked()
1002 void GuiDocument::change_adaptor()
1008 docstring GuiDocument::validate_listings_params()
1010 // use a cache here to avoid repeated validation
1011 // of the same parameters
1012 static string param_cache = string();
1013 static docstring msg_cache = docstring();
1015 if (textLayoutModule->bypassCB->isChecked())
1018 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1019 if (params != param_cache) {
1020 param_cache = params;
1021 msg_cache = InsetListingsParams(params).validate();
1027 void GuiDocument::set_listings_msg()
1029 static bool isOK = true;
1030 docstring msg = validate_listings_params();
1035 // listingsTB->setTextColor("black");
1036 textLayoutModule->listingsTB->setPlainText(
1037 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
1040 // listingsTB->setTextColor("red");
1041 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
1046 void GuiDocument::setLSpacing(int item)
1048 textLayoutModule->lspacingLE->setEnabled(item == 3);
1052 void GuiDocument::setSkip(int item)
1054 bool const enable = (item == 3);
1055 textLayoutModule->skipLE->setEnabled(enable);
1056 textLayoutModule->skipLengthCO->setEnabled(enable);
1060 void GuiDocument::enableSkip(bool skip)
1062 textLayoutModule->skipCO->setEnabled(skip);
1063 textLayoutModule->skipLE->setEnabled(skip);
1064 textLayoutModule->skipLengthCO->setEnabled(skip);
1066 setSkip(textLayoutModule->skipCO->currentIndex());
1069 void GuiDocument::portraitChanged()
1071 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1074 void GuiDocument::setMargins(bool custom)
1076 marginsModule->marginCB->setChecked(custom);
1077 setCustomMargins(custom);
1081 void GuiDocument::setCustomPapersize(int papersize)
1083 bool const custom = (papersize == 1);
1085 pageLayoutModule->paperwidthL->setEnabled(custom);
1086 pageLayoutModule->paperwidthLE->setEnabled(custom);
1087 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1088 pageLayoutModule->paperheightL->setEnabled(custom);
1089 pageLayoutModule->paperheightLE->setEnabled(custom);
1090 pageLayoutModule->paperheightLE->setFocus();
1091 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1095 void GuiDocument::setColSep()
1097 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1101 void GuiDocument::setCustomMargins(bool custom)
1103 marginsModule->topL->setEnabled(!custom);
1104 marginsModule->topLE->setEnabled(!custom);
1105 marginsModule->topUnit->setEnabled(!custom);
1107 marginsModule->bottomL->setEnabled(!custom);
1108 marginsModule->bottomLE->setEnabled(!custom);
1109 marginsModule->bottomUnit->setEnabled(!custom);
1111 marginsModule->innerL->setEnabled(!custom);
1112 marginsModule->innerLE->setEnabled(!custom);
1113 marginsModule->innerUnit->setEnabled(!custom);
1115 marginsModule->outerL->setEnabled(!custom);
1116 marginsModule->outerLE->setEnabled(!custom);
1117 marginsModule->outerUnit->setEnabled(!custom);
1119 marginsModule->headheightL->setEnabled(!custom);
1120 marginsModule->headheightLE->setEnabled(!custom);
1121 marginsModule->headheightUnit->setEnabled(!custom);
1123 marginsModule->headsepL->setEnabled(!custom);
1124 marginsModule->headsepLE->setEnabled(!custom);
1125 marginsModule->headsepUnit->setEnabled(!custom);
1127 marginsModule->footskipL->setEnabled(!custom);
1128 marginsModule->footskipLE->setEnabled(!custom);
1129 marginsModule->footskipUnit->setEnabled(!custom);
1131 bool const enableColSep = !custom &&
1132 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1133 marginsModule->columnsepL->setEnabled(enableColSep);
1134 marginsModule->columnsepLE->setEnabled(enableColSep);
1135 marginsModule->columnsepUnit->setEnabled(enableColSep);
1139 void GuiDocument::updateFontsize(string const & items, string const & sel)
1141 fontModule->fontsizeCO->clear();
1142 fontModule->fontsizeCO->addItem(qt_("Default"));
1144 for (int n = 0; !token(items,'|',n).empty(); ++n)
1145 fontModule->fontsizeCO->
1146 addItem(toqstr(token(items,'|',n)));
1148 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1149 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1150 fontModule->fontsizeCO->setCurrentIndex(n);
1157 void GuiDocument::romanChanged(int item)
1159 string const font = tex_fonts_roman[item];
1160 fontModule->fontScCB->setEnabled(providesSC(font));
1161 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1165 void GuiDocument::sansChanged(int item)
1167 string const font = tex_fonts_sans[item];
1168 bool scaleable = providesScale(font);
1169 fontModule->scaleSansSB->setEnabled(scaleable);
1170 fontModule->scaleSansLA->setEnabled(scaleable);
1174 void GuiDocument::ttChanged(int item)
1176 string const font = tex_fonts_monospaced[item];
1177 bool scaleable = providesScale(font);
1178 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1179 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1183 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1186 pageLayoutModule->pagestyleCO->clear();
1187 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1189 for (int n = 0; !token(items,'|',n).empty(); ++n) {
1190 string style = token(items, '|', n);
1191 docstring style_gui = _(style);
1192 pagestyles.push_back(pair<string, docstring>(style, style_gui));
1193 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
1196 if (sel == "default") {
1197 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1203 for (size_t i = 0; i < pagestyles.size(); ++i)
1204 if (pagestyles[i].first == sel)
1205 nn = pageLayoutModule->pagestyleCO->findText(
1206 toqstr(pagestyles[i].second));
1209 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1213 void GuiDocument::classChanged()
1215 BaseClassIndex const tc = latexModule->classCO->currentIndex();
1216 bp_.setBaseClass(tc);
1217 if (lyxrc.auto_reset_options) {
1218 if (applyPB->isEnabled()) {
1219 int const ret = Alert::prompt(_("Unapplied changes"),
1220 _("Some changes in the dialog were not yet applied."
1221 "If you do not apply now, they will be lost after this action."),
1222 1, 1, _("&Apply"), _("&Dismiss"));
1226 bp_.useClassDefaults();
1233 // This is an insanely complicated attempt to make this sort of thing
1234 // work with RTL languages.
1235 docstring formatStrVec(vector<string> const & v, docstring const & s)
1237 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1238 int const vSize = v.size();
1241 else if (v.size() == 1)
1242 return from_ascii(v[0]);
1243 else if (v.size() == 2) {
1244 docstring retval = _("%1$s and %2$s");
1245 retval = subst(retval, _("and"), s);
1246 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1248 //The idea here is to format all but the last two items...
1249 docstring t2 = _("%1$s, %2$s");
1250 docstring retval = from_ascii(v[0]);
1251 for (int i = 1; i < vSize - 2; ++i)
1252 retval = bformat(t2, retval, from_ascii(v[i]));
1253 //...and then to plug them, and the last two, into this schema
1254 docstring t = _("%1$s, %2$s, and %3$s");
1255 t = subst(t, _("and"), s);
1256 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1259 vector<string> idsToNames(vector<string> const & idList)
1261 vector<string> retval;
1262 vector<string>::const_iterator it = idList.begin();
1263 vector<string>::const_iterator end = idList.end();
1264 for (; it != end; ++it) {
1265 LyXModule const * const mod = moduleList[*it];
1267 retval.push_back(*it + " (Unavailable)");
1269 retval.push_back(mod->getName());
1276 void GuiDocument::updateModuleInfo()
1278 selectionManager->update();
1280 //Module description
1281 bool const focusOnSelected = selectionManager->selectedFocused();
1282 QListView const * const lv =
1283 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1284 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1285 latexModule->infoML->document()->clear();
1288 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1289 GuiIdListModel const & idModel =
1290 focusOnSelected ? selected_model_ : available_model_;
1291 string const modName = idModel.getIDString(idx.row());
1292 docstring desc = getModuleDescription(modName);
1294 vector<string> pkgList = getPackageList(modName);
1295 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1296 if (!pkgdesc.empty()) {
1299 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1302 pkgList = getRequiredList(modName);
1303 if (!pkgList.empty()) {
1304 vector<string> const reqDescs = idsToNames(pkgList);
1305 pkgdesc = formatStrVec(reqDescs, _("or"));
1308 desc += bformat(_("Module required: %1$s."), pkgdesc);
1311 pkgList = getExcludedList(modName);
1312 if (!pkgList.empty()) {
1313 vector<string> const reqDescs = idsToNames(pkgList);
1314 pkgdesc = formatStrVec(reqDescs, _( "and"));
1317 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1320 if (!isModuleAvailable(modName)) {
1323 desc += _("WARNING: Some packages are unavailable!");
1326 latexModule->infoML->document()->setPlainText(toqstr(desc));
1330 void GuiDocument::updateEmbeddedFileList()
1332 embeddedFilesModule->filesLW->clear();
1333 // add current embedded files
1334 EmbeddedFileList & files = buffer().embeddedFiles();
1335 files.update(buffer());
1336 EmbeddedFileList::iterator fit = files.begin();
1337 EmbeddedFileList::iterator fit_end = files.end();
1338 for (; fit != fit_end; ++fit) {
1339 QString label = toqstr(fit->relFilename(buffer().filePath()));
1340 if (fit->refCount() > 1)
1341 label += " (" + QString::number(fit->refCount()) + ")";
1342 QListWidgetItem * item = new QListWidgetItem(label);
1343 item->setFlags(item->flags() | Qt::ItemIsSelectable
1344 | Qt::ItemIsUserCheckable);
1346 item->setCheckState(Qt::Checked);
1348 item->setCheckState(Qt::Unchecked);
1349 // index of the currently used ParConstIterator
1350 embeddedFilesModule->filesLW->addItem(item);
1355 void GuiDocument::updateNumbering()
1357 DocumentClass const & tclass = bp_.documentClass();
1359 numberingModule->tocTW->setUpdatesEnabled(false);
1360 numberingModule->tocTW->clear();
1362 int const depth = numberingModule->depthSL->value();
1363 int const toc = numberingModule->tocSL->value();
1364 QString const no = qt_("No");
1365 QString const yes = qt_("Yes");
1366 QTreeWidgetItem * item = 0;
1367 for (size_t i = 0; i != tclass.layoutCount(); ++i) {
1368 Layout const & lt = *tclass.layout(i);
1369 int const toclevel = lt.toclevel;
1370 if (toclevel != Layout::NOT_IN_TOC && lt.labeltype == LABEL_COUNTER) {
1371 item = new QTreeWidgetItem(numberingModule->tocTW);
1372 item->setText(0, toqstr(translateIfPossible(lt.name())));
1373 item->setText(1, (toclevel <= depth) ? yes : no);
1374 item->setText(2, (toclevel <= toc) ? yes : no);
1378 numberingModule->tocTW->setUpdatesEnabled(true);
1379 numberingModule->tocTW->update();
1383 void GuiDocument::apply(BufferParams & params)
1386 preambleModule->apply(params);
1389 params.setCiteEngine(biblio::ENGINE_BASIC);
1391 if (biblioModule->citeNatbibRB->isChecked()) {
1392 bool const use_numerical_citations =
1393 biblioModule->citeStyleCO->currentIndex();
1394 if (use_numerical_citations)
1395 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1397 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1399 } else if (biblioModule->citeJurabibRB->isChecked())
1400 params.setCiteEngine(biblio::ENGINE_JURABIB);
1402 params.use_bibtopic =
1403 biblioModule->bibtopicCB->isChecked();
1405 // language & quotes
1406 if (langModule->defaultencodingRB->isChecked()) {
1407 params.inputenc = "auto";
1409 int i = langModule->encodingCO->currentIndex();
1411 params.inputenc = "default";
1414 fromqstr(langModule->encodingCO->currentText());
1417 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1418 switch (langModule->quoteStyleCO->currentIndex()) {
1420 lga = InsetQuotes::EnglishQ;
1423 lga = InsetQuotes::SwedishQ;
1426 lga = InsetQuotes::GermanQ;
1429 lga = InsetQuotes::PolishQ;
1432 lga = InsetQuotes::FrenchQ;
1435 lga = InsetQuotes::DanishQ;
1438 params.quotes_language = lga;
1440 int const pos = langModule->languageCO->currentIndex();
1441 params.language = lyx::languages.getLanguage(lang_[pos]);
1444 if (params.documentClass().hasTocLevels()) {
1445 params.tocdepth = numberingModule->tocSL->value();
1446 params.secnumdepth = numberingModule->depthSL->value();
1450 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1451 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1452 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1453 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1456 params.graphicsDriver =
1457 tex_graphics[latexModule->psdriverCO->currentIndex()];
1460 params.setBaseClass(latexModule->classCO->currentIndex());
1463 params.clearLayoutModules();
1464 int const srows = selected_model_.rowCount();
1465 vector<string> selModList;
1466 for (int i = 0; i < srows; ++i)
1467 params.addLayoutModule(selected_model_.getIDString(i));
1469 if (mathsModule->amsautoCB->isChecked()) {
1470 params.use_amsmath = BufferParams::package_auto;
1472 if (mathsModule->amsCB->isChecked())
1473 params.use_amsmath = BufferParams::package_on;
1475 params.use_amsmath = BufferParams::package_off;
1478 if (mathsModule->esintautoCB->isChecked())
1479 params.use_esint = BufferParams::package_auto;
1481 if (mathsModule->esintCB->isChecked())
1482 params.use_esint = BufferParams::package_on;
1484 params.use_esint = BufferParams::package_off;
1487 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1488 params.pagestyle = "default";
1490 docstring style_gui =
1491 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1492 for (size_t i = 0; i < pagestyles.size(); ++i)
1493 if (pagestyles[i].second == style_gui)
1494 params.pagestyle = pagestyles[i].first;
1497 switch (textLayoutModule->lspacingCO->currentIndex()) {
1499 params.spacing().set(Spacing::Single);
1502 params.spacing().set(Spacing::Onehalf);
1505 params.spacing().set(Spacing::Double);
1508 params.spacing().set(Spacing::Other,
1509 fromqstr(textLayoutModule->lspacingLE->text()));
1513 if (textLayoutModule->twoColumnCB->isChecked())
1518 // text should have passed validation
1519 params.listings_params =
1520 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1522 if (textLayoutModule->indentRB->isChecked())
1523 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1525 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1527 switch (textLayoutModule->skipCO->currentIndex()) {
1529 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1532 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1535 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1540 widgetsToLength(textLayoutModule->skipLE,
1541 textLayoutModule->skipLengthCO)
1543 params.setDefSkip(vs);
1547 // DocumentDefskipCB assures that this never happens
1548 // so Assert then !!! - jbl
1549 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1554 fromqstr(latexModule->optionsLE->text());
1556 params.float_placement = floatModule->get();
1560 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1563 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1565 params.fontsTypewriter =
1566 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1568 params.fontsSansScale = fontModule->scaleSansSB->value();
1570 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1572 params.fontsSC = fontModule->fontScCB->isChecked();
1574 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1576 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1577 fontModule->fontsDefaultCO->currentIndex()];
1579 if (fontModule->fontsizeCO->currentIndex() == 0)
1580 params.fontsize = "default";
1583 fromqstr(fontModule->fontsizeCO->currentText());
1586 params.papersize = PAPER_SIZE(
1587 pageLayoutModule->papersizeCO->currentIndex());
1589 // custom, A3, B3 and B4 paper sizes need geometry
1590 int psize = pageLayoutModule->papersizeCO->currentIndex();
1591 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1593 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1594 pageLayoutModule->paperwidthUnitCO);
1596 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1597 pageLayoutModule->paperheightUnitCO);
1599 if (pageLayoutModule->facingPagesCB->isChecked())
1600 params.sides = TwoSides;
1602 params.sides = OneSide;
1604 if (pageLayoutModule->landscapeRB->isChecked())
1605 params.orientation = ORIENTATION_LANDSCAPE;
1607 params.orientation = ORIENTATION_PORTRAIT;
1610 params.use_geometry =
1611 (!marginsModule->marginCB->isChecked()
1614 Ui::MarginsUi const * m(marginsModule);
1616 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1617 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1618 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1619 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1620 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1621 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1622 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1623 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1625 branchesModule->apply(params);
1628 PDFOptions & pdf = params.pdfoptions();
1629 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1630 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1631 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1632 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1633 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1635 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1636 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1637 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1638 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1640 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1641 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1642 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1643 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1644 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1645 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1646 if (pdfSupportModule->fullscreenCB->isChecked())
1647 pdf.pagemode = pdf.pagemode_fullscreen;
1649 pdf.pagemode.clear();
1650 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1657 /** Return the position of val in the vector if found.
1658 If not found, return 0.
1661 static size_t findPos(vector<A> const & vec, A const & val)
1663 typename vector<A>::const_iterator it =
1664 find(vec.begin(), vec.end(), val);
1665 if (it == vec.end())
1667 return distance(vec.begin(), it);
1671 void GuiDocument::updateParams()
1677 void GuiDocument::updateParams(BufferParams const & params)
1679 // set the default unit
1680 Length::UNIT defaultUnit = Length::CM;
1681 switch (lyxrc.default_papersize) {
1682 case PAPER_DEFAULT: break;
1684 case PAPER_USLETTER:
1686 case PAPER_USEXECUTIVE:
1687 defaultUnit = Length::IN;
1696 defaultUnit = Length::CM;
1703 preambleModule->update(params, id());
1706 biblioModule->citeDefaultRB->setChecked(
1707 params.getEngine() == biblio::ENGINE_BASIC);
1709 biblioModule->citeNatbibRB->setChecked(
1710 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1711 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1713 biblioModule->citeStyleCO->setCurrentIndex(
1714 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1716 biblioModule->citeJurabibRB->setChecked(
1717 params.getEngine() == biblio::ENGINE_JURABIB);
1719 biblioModule->bibtopicCB->setChecked(
1720 params.use_bibtopic);
1722 // language & quotes
1723 int const pos = int(findPos(lang_,
1724 params.language->lang()));
1725 langModule->languageCO->setCurrentIndex(pos);
1727 langModule->quoteStyleCO->setCurrentIndex(
1728 params.quotes_language);
1730 bool default_enc = true;
1731 if (params.inputenc != "auto") {
1732 default_enc = false;
1733 if (params.inputenc == "default") {
1734 langModule->encodingCO->setCurrentIndex(0);
1736 int const i = langModule->encodingCO->findText(
1737 toqstr(params.inputenc));
1739 langModule->encodingCO->setCurrentIndex(i);
1741 // unknown encoding. Set to default.
1745 langModule->defaultencodingRB->setChecked(default_enc);
1746 langModule->otherencodingRB->setChecked(!default_enc);
1749 int const min_toclevel = textClass().min_toclevel();
1750 int const max_toclevel = textClass().max_toclevel();
1751 if (textClass().hasTocLevels()) {
1752 numberingModule->setEnabled(true);
1753 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1754 numberingModule->depthSL->setMaximum(max_toclevel);
1755 numberingModule->depthSL->setValue(params.secnumdepth);
1756 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1757 numberingModule->tocSL->setMaximum(max_toclevel);
1758 numberingModule->tocSL->setValue(params.tocdepth);
1761 numberingModule->setEnabled(false);
1762 numberingModule->tocTW->clear();
1766 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1767 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1768 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1769 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1770 bulletsModule->init();
1773 int nitem = findToken(tex_graphics, params.graphicsDriver);
1775 latexModule->psdriverCO->setCurrentIndex(nitem);
1778 mathsModule->amsCB->setChecked(
1779 params.use_amsmath == BufferParams::package_on);
1780 mathsModule->amsautoCB->setChecked(
1781 params.use_amsmath == BufferParams::package_auto);
1783 mathsModule->esintCB->setChecked(
1784 params.use_esint == BufferParams::package_on);
1785 mathsModule->esintautoCB->setChecked(
1786 params.use_esint == BufferParams::package_auto);
1788 switch (params.spacing().getSpace()) {
1789 case Spacing::Other: nitem = 3; break;
1790 case Spacing::Double: nitem = 2; break;
1791 case Spacing::Onehalf: nitem = 1; break;
1792 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1796 latexModule->classCO->setCurrentIndex(params.baseClass());
1798 updatePagestyle(textClass().opt_pagestyle(),
1801 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1802 if (params.spacing().getSpace() == Spacing::Other) {
1803 textLayoutModule->lspacingLE->setText(
1804 toqstr(params.spacing().getValueAsString()));
1808 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1809 textLayoutModule->indentRB->setChecked(true);
1811 textLayoutModule->skipRB->setChecked(true);
1814 switch (params.getDefSkip().kind()) {
1815 case VSpace::SMALLSKIP:
1818 case VSpace::MEDSKIP:
1821 case VSpace::BIGSKIP:
1824 case VSpace::LENGTH:
1827 string const length = params.getDefSkip().asLyXCommand();
1828 lengthToWidgets(textLayoutModule->skipLE,
1829 textLayoutModule->skipLengthCO,
1830 length, defaultUnit);
1837 textLayoutModule->skipCO->setCurrentIndex(skip);
1840 textLayoutModule->twoColumnCB->setChecked(
1841 params.columns == 2);
1843 // break listings_params to multiple lines
1845 InsetListingsParams(params.listings_params).separatedParams();
1846 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1848 if (!params.options.empty()) {
1849 latexModule->optionsLE->setText(
1850 toqstr(params.options));
1852 latexModule->optionsLE->setText(QString());
1855 floatModule->set(params.float_placement);
1858 updateFontsize(textClass().opt_fontsize(),
1861 int n = findToken(tex_fonts_roman, params.fontsRoman);
1863 fontModule->fontsRomanCO->setCurrentIndex(n);
1867 n = findToken(tex_fonts_sans, params.fontsSans);
1869 fontModule->fontsSansCO->setCurrentIndex(n);
1873 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1875 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1879 fontModule->fontScCB->setChecked(params.fontsSC);
1880 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1881 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1882 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1883 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1885 fontModule->fontsDefaultCO->setCurrentIndex(n);
1888 int const psize = params.papersize;
1889 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1890 setCustomPapersize(psize);
1892 bool const landscape =
1893 params.orientation == ORIENTATION_LANDSCAPE;
1894 pageLayoutModule->landscapeRB->setChecked(landscape);
1895 pageLayoutModule->portraitRB->setChecked(!landscape);
1897 pageLayoutModule->facingPagesCB->setChecked(
1898 params.sides == TwoSides);
1901 lengthToWidgets(pageLayoutModule->paperwidthLE,
1902 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1904 lengthToWidgets(pageLayoutModule->paperheightLE,
1905 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1908 Ui::MarginsUi * m = marginsModule;
1910 setMargins(!params.use_geometry);
1912 lengthToWidgets(m->topLE, m->topUnit,
1913 params.topmargin, defaultUnit);
1915 lengthToWidgets(m->bottomLE, m->bottomUnit,
1916 params.bottommargin, defaultUnit);
1918 lengthToWidgets(m->innerLE, m->innerUnit,
1919 params.leftmargin, defaultUnit);
1921 lengthToWidgets(m->outerLE, m->outerUnit,
1922 params.rightmargin, defaultUnit);
1924 lengthToWidgets(m->headheightLE, m->headheightUnit,
1925 params.headheight, defaultUnit);
1927 lengthToWidgets(m->headsepLE, m->headsepUnit,
1928 params.headsep, defaultUnit);
1930 lengthToWidgets(m->footskipLE, m->footskipUnit,
1931 params.footskip, defaultUnit);
1933 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
1934 params.columnsep, defaultUnit);
1936 branchesModule->update(params);
1939 PDFOptions const & pdf = params.pdfoptions();
1940 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1941 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1942 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1943 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1944 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1946 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1947 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1948 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1950 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1952 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1953 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1954 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1955 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1956 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1957 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1958 pdfSupportModule->fullscreenCB->setChecked
1959 (pdf.pagemode == pdf.pagemode_fullscreen);
1961 pdfSupportModule->optionsLE->setText(
1962 toqstr(pdf.quoted_options));
1965 updateEmbeddedFileList();
1969 void GuiDocument::applyView()
1975 void GuiDocument::saveDocDefault()
1977 // we have to apply the params first
1983 void GuiDocument::updateAvailableModules()
1985 available_model_.clear();
1986 vector<modInfoStruct> const modInfoList = getModuleInfo();
1987 int const mSize = modInfoList.size();
1988 for (int i = 0; i < mSize; ++i) {
1989 modInfoStruct const & modInfo = modInfoList[i];
1990 available_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
1995 void GuiDocument::updateSelectedModules()
1997 //and selected ones, too
1998 selected_model_.clear();
1999 vector<modInfoStruct> const selModList = getSelectedModules();
2000 int const sSize = selModList.size();
2001 for (int i = 0; i < sSize; ++i) {
2002 modInfoStruct const & modInfo = selModList[i];
2003 selected_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
2008 void GuiDocument::updateContents()
2010 if (id() == current_id_)
2013 updateAvailableModules();
2014 updateSelectedModules();
2016 //FIXME It'd be nice to make sure here that the selected
2017 //modules are consistent: That required modules are actually
2018 //selected, and that we don't have conflicts. If so, we could
2019 //at least pop up a warning.
2025 void GuiDocument::forceUpdate()
2027 // reset to force dialog update
2033 void GuiDocument::useClassDefaults()
2035 if (applyPB->isEnabled()) {
2036 int const ret = Alert::prompt(_("Unapplied changes"),
2037 _("Some changes in the dialog were not yet applied."
2038 "If you do not apply now, they will be lost after this action."),
2039 1, 1, _("&Apply"), _("&Dismiss"));
2044 bp_.setBaseClass(latexModule->classCO->currentIndex());
2045 bp_.useClassDefaults();
2050 bool GuiDocument::isValid()
2052 return (validate_listings_params().empty() &&
2053 (textLayoutModule->skipCO->currentIndex() != 3 ||
2054 !textLayoutModule->skipLE->text().isEmpty()));
2058 char const * const GuiDocument::fontfamilies[5] = {
2059 "default", "rmdefault", "sfdefault", "ttdefault", ""
2063 char const * GuiDocument::fontfamilies_gui[5] = {
2064 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2068 bool GuiDocument::initialiseParams(string const &)
2070 bp_ = buffer().params();
2076 void GuiDocument::clearParams()
2078 bp_ = BufferParams();
2082 BufferId GuiDocument::id() const
2088 vector<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2090 return moduleNames_;
2094 vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2096 vector<string> const & mods = params().getModules();
2097 vector<string>::const_iterator it = mods.begin();
2098 vector<string>::const_iterator end = mods.end();
2099 vector<modInfoStruct> mInfo;
2100 for (; it != end; ++it) {
2103 LyXModule * mod = moduleList[*it];
2105 m.name = mod->getName();
2107 m.name = *it + " (Not Found)";
2114 TextClass const & GuiDocument::textClass() const
2116 return baseclasslist[bp_.baseClass()];
2120 static void dispatch_bufferparams(Dialog const & dialog,
2121 BufferParams const & bp, kb_action lfun)
2124 ss << "\\begin_header\n";
2126 ss << "\\end_header\n";
2127 dialog.dispatch(FuncRequest(lfun, ss.str()));
2131 void GuiDocument::dispatchParams()
2133 // This must come first so that a language change is correctly noticed
2136 // Apply the BufferParams. Note that this will set the base class
2137 // and then update the buffer's layout.
2138 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2140 // Generate the colours requested by each new branch.
2141 BranchList & branchlist = params().branchlist();
2142 if (!branchlist.empty()) {
2143 BranchList::const_iterator it = branchlist.begin();
2144 BranchList::const_iterator const end = branchlist.end();
2145 for (; it != end; ++it) {
2146 docstring const & current_branch = it->getBranch();
2147 Branch const * branch = branchlist.find(current_branch);
2148 string const x11hexname = X11hexname(branch->getColor());
2149 // display the new color
2150 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2151 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2154 // Open insets of selected branches, close deselected ones
2155 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2158 // FIXME: If we used an LFUN, we would not need those two lines:
2159 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
2163 void GuiDocument::setLanguage() const
2165 Language const * const newL = bp_.language;
2166 if (buffer().params().language == newL)
2169 string const & lang_name = newL->lang();
2170 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2174 void GuiDocument::saveAsDefault() const
2176 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2180 bool GuiDocument::isFontAvailable(string const & font) const
2182 if (font == "default" || font == "cmr"
2183 || font == "cmss" || font == "cmtt")
2184 // these are standard
2186 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2187 return LaTeXFeatures::isAvailable("lmodern");
2188 if (font == "times" || font == "palatino"
2189 || font == "helvet" || font == "courier")
2190 return LaTeXFeatures::isAvailable("psnfss");
2191 if (font == "cmbr" || font == "cmtl")
2192 return LaTeXFeatures::isAvailable("cmbright");
2193 if (font == "utopia")
2194 return LaTeXFeatures::isAvailable("utopia")
2195 || LaTeXFeatures::isAvailable("fourier");
2196 if (font == "beraserif" || font == "berasans"
2197 || font == "beramono")
2198 return LaTeXFeatures::isAvailable("bera");
2199 return LaTeXFeatures::isAvailable(font);
2203 bool GuiDocument::providesOSF(string const & font) const
2206 return isFontAvailable("eco");
2207 if (font == "palatino")
2208 return isFontAvailable("mathpazo");
2213 bool GuiDocument::providesSC(string const & font) const
2215 if (font == "palatino")
2216 return isFontAvailable("mathpazo");
2217 if (font == "utopia")
2218 return isFontAvailable("fourier");
2223 bool GuiDocument::providesScale(string const & font) const
2225 return font == "helvet" || font == "luximono"
2226 || font == "berasans" || font == "beramono";
2230 void GuiDocument::loadModuleInfo()
2232 moduleNames_.clear();
2233 LyXModuleList::const_iterator it = moduleList.begin();
2234 LyXModuleList::const_iterator end = moduleList.end();
2235 for (; it != end; ++it) {
2238 m.name = it->getName();
2239 moduleNames_.push_back(m);
2244 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2247 } // namespace frontend
2250 #include "GuiDocument_moc.cpp"