#include "BufferView.h"
#include "Color.h"
#include "ColorCache.h"
+#include "Converter.h"
#include "Cursor.h"
#include "Encoding.h"
#include "FloatPlacement.h"
#include <QCloseEvent>
#include <QFontDatabase>
#include <QScrollBar>
+#include <QTextBoundaryFinder>
#include <QTextCursor>
#include <sstream>
{
// This is not a memory leak. The object will be destroyed
// with this.
- (void) new LaTeXHighlighter(preambleTE->document());
+ // @ is letter in the LyX user preamble
+ (void) new LaTeXHighlighter(preambleTE->document(), true);
preambleTE->setFont(guiApp->typewriterSystemFont());
preambleTE->setWordWrapMode(QTextOption::NoWrap);
setFocusProxy(preambleTE);
void PreambleModule::apply(BufferParams & params)
{
- params.preamble = fromqstr(preambleTE->document()->toPlainText());
+ params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
}
void LocalLayout::apply(BufferParams & params)
{
- string const layout = fromqstr(locallayoutTE->document()->toPlainText());
+ docstring const layout =
+ qstring_to_ucs4(locallayoutTE->document()->toPlainText());
params.setLocalLayout(layout, false);
}
+void LocalLayout::hideConvert()
+{
+ convertPB->setEnabled(false);
+ convertLB->setText("");
+ convertPB->hide();
+ convertLB->hide();
+}
+
+
void LocalLayout::textChanged()
{
static const QString message =
validated_ = true;
validatePB->setEnabled(false);
validLB->setText("");
- convertPB->hide();
- convertLB->hide();
+ hideConvert();
changed();
} else if (!validatePB->isEnabled()) {
// if that's already enabled, we shouldn't need to do anything.
validated_ = false;
validLB->setText(message);
validatePB->setEnabled(true);
- convertPB->setEnabled(false);
+ hideConvert();
changed();
}
}
string const layout =
fromqstr(locallayoutTE->document()->toPlainText().trimmed());
string const newlayout = TextClass::convert(layout);
- LYXERR0(newlayout);
- if (newlayout.empty()) {
- Alert::error(_("Conversion Failed!"),
- _("Failed to convert local layout to current format."));
- } else {
+ if (!newlayout.empty())
locallayoutTE->setPlainText(toqstr(newlayout));
- }
validate();
}
void LocalLayout::convertPressed() {
convert();
+ hideConvert();
changed();
}
void LocalLayout::validate() {
- static const QString valid = qt_("Layout is valid!");
- static const QString vtext =
- toqstr("<p style=\"font-weight: bold; \">")
- + valid + toqstr("</p>");
- static const QString invalid = qt_("Layout is invalid!");
- static const QString ivtext =
- toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
- + invalid + toqstr("</p>");
-
+ // Bold text
+ static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
+ // Flashy red bold text
+ static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
+ "%1</p>");
string const layout =
fromqstr(locallayoutTE->document()->toPlainText().trimmed());
if (!layout.empty()) {
TextClass::ReturnValues const ret = TextClass::validate(layout);
validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
validatePB->setEnabled(false);
- validLB->setText(validated_ ? vtext : ivtext);
+ validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
+ : ivpar.arg(qt_("Layout is invalid!")));
if (ret == TextClass::OK_OLDFORMAT) {
convertPB->show();
- convertPB->setEnabled(true);
- convertLB->setText(qt_("Convert to current format"));
+ // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
+ // already.
+ if (TextClass::convert(layout).empty()) {
+ // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
+ // then maybe the layout is still valid, but its format is more
+ // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
+ // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
+ convertPB->setEnabled(false);
+ const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
+ ? ivpar.arg(qt_("Conversion to current format impossible!"))
+ : vpar.arg(qt_("Conversion to current stable format "
+ "impossible."));
+ convertLB->setText(text);
+ } else {
+ convertPB->setEnabled(true);
+ convertLB->setText(qt_("Convert to current format"));
+ }
convertLB->show();
} else {
convertPB->hide();
GuiDocument::GuiDocument(GuiView & lv)
: GuiDialog(lv, "document", qt_("Document Settings")),
- nonModuleChanged_(false)
+ biblioChanged_(false), nonModuleChanged_(false)
{
setupUi(this);
masterChildModule->childrenTW->resizeColumnToContents(2);
- // output
+ // Formats
outputModule = new UiWidget<Ui::OutputUi>;
connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
outputModule->synccustomCB->setValidator(new NoNewLineValidator(
outputModule->synccustomCB));
+ connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
+
// fonts
fontModule = new FontModule;
connect(fontModule->osFontsCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
this, SLOT(languagePackageChanged(int)));
+ connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
+ this, SLOT(change_adaptor()));
langModule->languagePackageLE->setValidator(new NoNewLineValidator(
langModule->languagePackageLE));
encodinglist.sort();
langModule->encodingCO->addItems(encodinglist);
- langModule->quoteStyleCO->addItem(
- qt_("``text''"),InsetQuotes::EnglishQuotes);
- langModule->quoteStyleCO->addItem(
- qt_("''text''"), InsetQuotes::SwedishQuotes);
- langModule->quoteStyleCO->addItem
- (qt_(",,text``"), InsetQuotes::GermanQuotes);
- langModule->quoteStyleCO->addItem(
- qt_(",,text''"), InsetQuotes::PolishQuotes);
- langModule->quoteStyleCO->addItem(
- qt_("<<text>>"), InsetQuotes::FrenchQuotes);
- langModule->quoteStyleCO->addItem(
- qt_(">>text<<"), InsetQuotes::DanishQuotes);
-
langModule->languagePackageCO->addItem(
qt_("Default"), toqstr("default"));
langModule->languagePackageCO->addItem(
QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
if (!available) {
docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
- tooltip += '\n' + toqstr(wrap(bformat(_("Class not found by LyX. "
+ tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
"Please check if you have the matching %1$s class "
"and all required packages (%2$s) installed."),
- output_type, from_utf8(tc.prerequisites(", ")))));
+ output_type, from_utf8(tc.prerequisites(", "))));
}
latexModule->classCO->addItemSort(toqstr(tc.name()),
toqstr(guiname),
docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
docPS->addPanel(bulletsModule, N_("Bullets"));
docPS->addPanel(branchesModule, N_("Branches"));
- docPS->addPanel(outputModule, N_("Output"));
+ docPS->addPanel(outputModule, N_("Formats[[output]]"));
docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
docPS->setCurrentPanel("Document Class");
// FIXME: hack to work around resizing bug in Qt >= 4.2
}
+void GuiDocument::onBufferViewChanged()
+{
+ if (isVisibleView())
+ initialiseParams("");
+}
+
+
void GuiDocument::saveDefaultClicked()
{
saveDocDefault();
QString GuiDocument::validateListingsParameters()
{
- // use a cache here to avoid repeated validation
- // of the same parameters
- // FIXME THREAD
- static string param_cache;
- static QString msg_cache;
-
if (listingsModule->bypassCB->isChecked())
return QString();
-
string params = fromqstr(listingsModule->listingsED->toPlainText());
- if (params != param_cache) {
- param_cache = params;
- msg_cache = toqstr(InsetListingsParams(params).validate());
- }
- return msg_cache;
+ return toqstr(InsetListingsParams(params).validate());
}
}
+void GuiDocument::updateQuoteStyles(bool const set)
+{
+ Language const * lang = lyx::languages.getLanguage(
+ fromqstr(langModule->languageCO->itemData(
+ langModule->languageCO->currentIndex()).toString()));
+
+ InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
+
+ langModule->quoteStyleCO->clear();
+
+ bool has_default = false;
+ for (int i = 0; i < quoteparams.stylescount(); ++i) {
+ InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
+ if (qs == InsetQuotesParams::DynamicQuotes)
+ continue;
+ bool const langdef = (qs == def);
+ if (langdef) {
+ // add the default style on top
+ langModule->quoteStyleCO->insertItem(0,
+ toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
+ has_default = true;
+ }
+ else
+ langModule->quoteStyleCO->addItem(
+ toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
+ }
+ if (set && has_default)
+ // (re)set to the default style
+ langModule->quoteStyleCO->setCurrentIndex(0);
+}
+
+
void GuiDocument::languageChanged(int i)
{
- // some languages only work with polyglossia/XeTeX
+ // some languages only work with polyglossia
Language const * lang = lyx::languages.getLanguage(
fromqstr(langModule->languageCO->itemData(i).toString()));
if (lang->babel().empty() && !lang->polyglossia().empty()) {
}
// set appropriate quotation mark style
- if (!lang->quoteStyle().empty()) {
- langModule->quoteStyleCO->setCurrentIndex(
- bp_.getQuoteStyle(lang->quoteStyle()));
- }
+ updateQuoteStyles(true);
}
outputModule->defaultFormatCO->clear();
outputModule->defaultFormatCO->addItem(qt_("Default"),
QVariant(QString("default")));
- typedef vector<Format const *> Formats;
- Formats formats = param_copy.exportableFormats(true);
- sort(formats.begin(), formats.end(), Format::formatSorter);
- Formats::const_iterator cit = formats.begin();
- Formats::const_iterator end = formats.end();
- for (; cit != end; ++cit)
- outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
- QVariant(toqstr((*cit)->name())));
+ FormatList const & formats =
+ param_copy.exportableFormats(true);
+ for (Format const * f : formats)
+ outputModule->defaultFormatCO->addItem
+ (toqstr(translateIfPossible(f->prettyname())),
+ QVariant(toqstr(f->name())));
outputModule->defaultFormatCO->blockSignals(false);
}
}
}
- bp_.quotes_language = (InsetQuotes::QuoteLanguage) langModule->quoteStyleCO->itemData(
+ bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
langModule->quoteStyleCO->currentIndex()).toInt();
+ bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
QString const langname = langModule->languageCO->itemData(
langModule->languageCO->currentIndex()).toString();
bp_.listings_params =
InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
- // output
+ // Formats
bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
outputModule->defaultFormatCO->currentIndex()).toString());
bp_.html_math_img_scale = outputModule->mathimgSB->value();
bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
+ bp_.save_transient_properties =
+ outputModule->saveTransientPropertiesCB->isChecked();
+
// fonts
bp_.fonts_roman[nontexfonts] =
fromqstr(fontModule->fontsRomanCO->
bp_.language->lang()));
langModule->languageCO->setCurrentIndex(pos);
+ updateQuoteStyles();
+
langModule->quoteStyleCO->setCurrentIndex(
- bp_.quotes_language);
+ langModule->quoteStyleCO->findData(bp_.quotes_style));
+ langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
bool default_enc = true;
if (bp_.inputenc != "auto") {
fontModule->fontencLE->setText(toqstr(bp_.fontenc));
}
- // Output
+ // Formats
// This must be set _after_ fonts since updateDefaultFormat()
// checks osFontsCB settings.
// update combobox with formats
outputModule->strictCB->setChecked(bp_.html_be_strict);
outputModule->cssCB->setChecked(bp_.html_css_as_file);
+ outputModule->saveTransientPropertiesCB
+ ->setChecked(bp_.save_transient_properties);
+
// paper
bool const extern_geometry =
documentClass().provides("geometry");
void GuiDocument::updateAvailableModules()
{
modules_av_model_.clear();
- list<modInfoStruct> const & modInfoList = getModuleInfo();
- list<modInfoStruct>::const_iterator mit = modInfoList.begin();
- list<modInfoStruct>::const_iterator men = modInfoList.end();
- for (int i = 0; mit != men; ++mit, ++i)
- modules_av_model_.insertRow(i, mit->name, mit->id,
- mit->description);
+ list<modInfoStruct> modInfoList = getModuleInfo();
+ // Sort names according to the locale
+ modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
+ return 0 < b.name.localeAwareCompare(a.name);
+ });
+ int i = 0;
+ for (modInfoStruct const & m : modInfoList) {
+ modules_av_model_.insertRow(i, m.name, m.id, m.description);
+ ++i;
+ }
}
{
modules_sel_model_.clear();
list<modInfoStruct> const selModList = getSelectedModules();
- list<modInfoStruct>::const_iterator mit = selModList.begin();
- list<modInfoStruct>::const_iterator men = selModList.end();
- for (int i = 0; mit != men; ++mit, ++i)
- modules_sel_model_.insertRow(i, mit->name, mit->id,
- mit->description);
+ int i = 0;
+ for (modInfoStruct const & m : selModList) {
+ modules_sel_model_.insertRow(i, m.name, m.id, m.description);
+ ++i;
+ }
}
list<GuiDocument::modInfoStruct> const
- GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
+GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
{
- LayoutModuleList::const_iterator it = mods.begin();
- LayoutModuleList::const_iterator end = mods.end();
list<modInfoStruct> mInfo;
- for (; it != end; ++it) {
+ for (string const & name : mods) {
modInfoStruct m;
- m.id = *it;
- LyXModule const * const mod = theModuleList[*it];
+ LyXModule const * const mod = theModuleList[name];
if (mod)
- // FIXME Unicode
- m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
- else
- m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
+ m = modInfo(*mod);
+ else {
+ m.id = name;
+ m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
+ }
mInfo.push_back(m);
}
return mInfo;
}
+//static
+GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
+{
+ // FIXME Unicode: docstrings would be better for these parameters but this
+ // change requires a lot of others
+ modInfoStruct m;
+ m.id = mod.getID();
+ m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
+ QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
+ // Find the first sentence of the description
+ QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
+ int pos = bf.toNextBoundary();
+ if (pos > 0)
+ desc.truncate(pos);
+ QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
+ // Tooltip is the desc followed by the module name
+ m.description = QString("%1<i>%2</i>")
+ .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
+ modulename);
+ return m;
+}
+
+
void GuiDocument::loadModuleInfo()
{
moduleNames_.clear();
- LyXModuleList::const_iterator it = theModuleList.begin();
- LyXModuleList::const_iterator end = theModuleList.end();
- for (; it != end; ++it) {
- modInfoStruct m;
- m.id = it->getID();
- // FIXME Unicode
- m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
- // this is supposed to give us the first sentence of the description
- // FIXME Unicode
- QString desc =
- toqstr(translateIfPossible(from_utf8(it->getDescription())));
- int const pos = desc.indexOf(".");
- if (pos > 0)
- desc.truncate(pos + 1);
- m.description = desc;
- if (it->category().substr(0, 8) != "Citation")
- moduleNames_.push_back(m);
- }
+ for (LyXModule const & mod : theModuleList)
+ if (mod.category().substr(0, 8) != "Citation")
+ moduleNames_.push_back(modInfo(mod));
}