From 051de65db9fd788ed34a2fb119be3ea3ae816a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Milde?= Date: Wed, 5 Jun 2019 11:16:25 +0200 Subject: [PATCH] Fix remainder of #11115. Implement GUI suggestions from https://www.lyx.org/trac/ticket/11115#comment:26 --- lib/encodings | 10 +-- src/frontends/qt4/GuiDocument.cpp | 129 +++++++++++++++++------------ src/frontends/qt4/GuiDocument.h | 3 +- src/frontends/qt4/ui/LanguageUi.ui | 85 ++++++++++++++----- 4 files changed, 146 insertions(+), 81 deletions(-) diff --git a/lib/encodings b/lib/encodings index 612be5f813..42f0c10a03 100644 --- a/lib/encodings +++ b/lib/encodings @@ -47,12 +47,12 @@ # and pt254. # inputenc's standard utf8 support: -Encoding utf8 utf8 "Unicode (utf8)" UTF-8 variable inputenc +Encoding utf8 utf8 "utf8 (default)" UTF-8 variable inputenc End # extended utf8 support from the "ucs" package: # Larger set of supported characters but conflicts with some packages. -Encoding utf8x utf8x "Unicode (ucs-extended) (utf8x)" UTF-8 variable inputenc +Encoding utf8x utf8x "utf8 (extended) [ucs] (utf8x)" UTF-8 variable inputenc End # from http://www.ctan.org/pkg/armtex @@ -212,7 +212,7 @@ Encoding euc-kr KS "Korean (EUC-KR)" EUC-KR variable CJK End # The CJK package has yet another name for utf8... -Encoding utf8-cjk UTF8 "Unicode (CJK) (utf8)" UTF-8 variable CJK +Encoding utf8-cjk UTF8 "utf8 [CJK] (Chinese/Japanese/Korean)" UTF-8 variable CJK End # For traditional chinese @@ -233,13 +233,13 @@ Encoding jis-platex jis "Japanese (pLaTeX) (JIS)" ISO-2022-JP variable japanese End Encoding shift-jis-platex sjis "Japanese (pLaTeX) (SJIS)" CP932 variable japanese End -Encoding utf8-platex utf8 "Japanese (pLaTeX) (UTF8)" UTF-8 variable japanese +Encoding utf8-platex utf8 "utf8 [pLaTeX] (Japanese)" UTF-8 variable japanese End # A plain utf8 encoding that does not use the inputenc package # nor the LyX-added conversions in lib/unicodesymbols. # Such an encoding is required for XeTeX and LuaTeX. -Encoding utf8-plain utf8-plain "Unicode (XeTeX) (utf8)" UTF-8 variable none +Encoding utf8-plain utf8-plain "utf8 (pass-through)" UTF-8 variable none End # Pure 7bit ASCII encoding (partially hardcoded in LyX) diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 4cbd9774a3..268fd36b1a 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -865,7 +865,7 @@ GuiDocument::GuiDocument(GuiView & lv) // initialize the length validator bc().addCheckedLineEdit(textLayoutModule->indentLE); bc().addCheckedLineEdit(textLayoutModule->skipLE); - + textLayoutModule->tableStyleCO->addItem(qt_("Default"), toqstr("default")); getTableStyles(); @@ -931,14 +931,18 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(languageChanged(int))); - connect(langModule->encodingCO, SIGNAL(activated(int)), + connect(langModule->unicodeEncodingCO, SIGNAL(activated(int)), + this, SLOT(change_adaptor())); + connect(langModule->autoEncodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); - connect(langModule->encodingCO, SIGNAL(activated(int)), - this, SLOT(encodingSwitched(int))); connect(langModule->customEncodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); - connect(langModule->noInputencCB, SIGNAL(clicked()), - this, SLOT(change_adaptor())); + connect(langModule->autoEncodingRB, SIGNAL(toggled(bool)), + this, SLOT(change_encoding())); + connect(langModule->unicodeEncodingRB, SIGNAL(toggled(bool)), + this, SLOT(change_encoding())); + connect(langModule->customEncodingRB, SIGNAL(toggled(bool)), + this, SLOT(change_encoding())); connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(langModule->languagePackageCO, SIGNAL(activated(int)), @@ -959,15 +963,25 @@ GuiDocument::GuiDocument(GuiView & lv) langModule->languageCO->setModel(language_model); langModule->languageCO->setModelColumn(0); - langModule->encodingCO->addItem(qt_("Unicode (utf8)"), toqstr("utf8")); - langModule->encodingCO->addItem(qt_("Traditional (auto-selected)"), - toqstr("auto-legacy")); - // langModule->encodingCO->addItem(qt_("ASCII"), toqstr("ascii")); - langModule->encodingCO->addItem(qt_("Custom"), toqstr("custom")); + QMap encodingmap_utf8; + for (auto const & encvar : encodings) { + if (!encvar.unsafe() && !encvar.guiName().empty() + && std::string(encvar.name()).find("utf8") == 0) + encodingmap_utf8.insert(qt_(encvar.guiName()), qt_(encvar.name())); + } + QMap::const_iterator it8 = encodingmap_utf8.constBegin(); + while (it8 != encodingmap_utf8.constEnd()) { + langModule->unicodeEncodingCO->addItem(it8.key(), it8.value()); + ++it8; + } + + langModule->autoEncodingCO->addItem(qt_("legacy language default"), toqstr("auto-legacy")); + langModule->autoEncodingCO->addItem(qt_("legacy language default (no inputenc)"), toqstr("auto-legacy-plain")); QMap encodingmap; for (auto const & encvar : encodings) { - if (!encvar.unsafe() && !encvar.guiName().empty()) + if (!encvar.unsafe() && !encvar.guiName().empty() + && std::string(encvar.name()).find("utf8") != 0) encodingmap.insert(qt_(encvar.guiName()), qt_(encvar.name())); } QMap::const_iterator it = encodingmap.constBegin(); @@ -1720,6 +1734,12 @@ void GuiDocument::change_adaptor() changed(); } +void GuiDocument::change_encoding() +{ + encodingSwitched(); + nonModuleChanged_ = true; + changed(); +} void GuiDocument::shellescapeChanged() { @@ -2261,15 +2281,11 @@ void GuiDocument::osFontsChanged(bool nontexfonts) fontModule->font_math = font_math; fontModule->font_sf_scale = font_sf_scale; fontModule->font_tt_scale = font_tt_scale; - - langModule->customEncodingCO->setEnabled(tex_fonts && - langModule->encodingCO->itemData( - langModule->encodingCO->currentIndex()).toString() == "custom"); - langModule->encodingCO->setEnabled(tex_fonts); - langModule->noInputencCB->setEnabled(tex_fonts - && langModule->encodingCO->currentIndex() < 2); - if (!tex_fonts) - langModule->noInputencCB->setChecked(false); + // enable/disable input encoding selection + langModule->unicodeEncodingRB->setEnabled(tex_fonts); + langModule->autoEncodingRB->setEnabled(tex_fonts); + langModule->customEncodingRB->setEnabled(tex_fonts); + encodingSwitched(); fontModule->fontsDefaultCO->setEnabled(tex_fonts); fontModule->fontsDefaultLA->setEnabled(tex_fonts); @@ -2287,16 +2303,15 @@ void GuiDocument::osFontsChanged(bool nontexfonts) } -void GuiDocument::encodingSwitched(int i) +void GuiDocument::encodingSwitched() { - langModule->customEncodingCO->setEnabled( - !fontModule->osFontsCB->isChecked() - && langModule->encodingCO->itemData(i).toString() == "custom"); - langModule->noInputencCB->setEnabled(!fontModule->osFontsCB->isChecked() - && langModule->encodingCO->currentIndex() < 2); - if (!langModule->noInputencCB->isEnabled()) - langModule->noInputencCB->setChecked(false); - + bool const tex_fonts = !fontModule->osFontsCB->isChecked(); + langModule->unicodeEncodingCO->setEnabled(tex_fonts + && langModule->unicodeEncodingRB->isChecked()); + langModule->autoEncodingCO->setEnabled(tex_fonts + && langModule->autoEncodingRB->isChecked()); + langModule->customEncodingCO->setEnabled(tex_fonts + && langModule->customEncodingRB->isChecked()); } @@ -3242,16 +3257,17 @@ void GuiDocument::applyView() indicesModule->apply(bp_); // language & quotes - QString const encoding = langModule->encodingCO->itemData( - langModule->encodingCO->currentIndex()).toString(); - if (encoding != "custom") - bp_.inputenc = fromqstr(encoding); - else + if (langModule->unicodeEncodingRB->isChecked()) + bp_.inputenc = fromqstr(langModule->unicodeEncodingCO->itemData( + langModule->unicodeEncodingCO->currentIndex()).toString()); + else if (langModule->autoEncodingRB->isChecked()) + bp_.inputenc = fromqstr(langModule->autoEncodingCO->itemData( + langModule->autoEncodingCO->currentIndex()).toString()); + else if (langModule->customEncodingRB->isChecked()) bp_.inputenc = fromqstr(langModule->customEncodingCO->itemData( langModule->customEncodingCO->currentIndex()).toString()); - if (langModule->noInputencCB->isChecked() - && (encoding == "auto-legacy" || encoding == "utf8")) - bp_.inputenc += "-plain"; + else // this should never happen + bp_.inputenc = "utf8"; bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData( langModule->quoteStyleCO->currentIndex()).toInt(); @@ -3744,27 +3760,30 @@ void GuiDocument::paramsToDialog() langModule->quoteStyleCO->setCurrentIndex( langModule->quoteStyleCO->findData(bp_.quotes_style)); langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes); - + // LaTeX input encoding QString inputenc = toqstr(bp_.inputenc); - bool plain = false; - if (inputenc.endsWith("-plain")) { - inputenc = inputenc.left(inputenc.lastIndexOf("-plain")); - plain = true; - } - langModule->noInputencCB->setChecked(plain); - int p = langModule->encodingCO->findData(inputenc); - if (p != -1) - langModule->encodingCO->setCurrentIndex(p); - else { - langModule->encodingCO->setCurrentIndex( - langModule->encodingCO->findData("custom")); + int p; + if (inputenc.startsWith("utf8")) { + langModule->unicodeEncodingRB->setChecked(true); + p = langModule->unicodeEncodingCO->findData(inputenc); + if (p != -1) { + langModule->unicodeEncodingCO->setCurrentIndex(p); + } + } else if (inputenc.startsWith("auto")) { + langModule->autoEncodingRB->setChecked(true); + p = langModule->autoEncodingCO->findData(inputenc); + if (p != -1) { + langModule->autoEncodingCO->setCurrentIndex(p); + } + } else { + langModule->customEncodingRB->setChecked(true); p = langModule->customEncodingCO->findData(inputenc); - if (p != -1) + if (p != -1) { langModule->customEncodingCO->setCurrentIndex(p); - else - langModule->encodingCO->setCurrentIndex(0); + } } - + encodingSwitched(); + // language package p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package)); if (p == -1) { langModule->languagePackageCO->setCurrentIndex( diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 999be46f7a..c398375051 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -101,6 +101,7 @@ public Q_SLOTS: private Q_SLOTS: void updateNumbering(); void change_adaptor(); + void change_encoding(); void shellescapeChanged(); void includeonlyClicked(QTreeWidgetItem * item, int); void setListingsMessage(); @@ -152,7 +153,7 @@ private Q_SLOTS: void deleteBoxBackgroundColor(); void languageChanged(int); void osFontsChanged(bool); - void encodingSwitched(int); + void encodingSwitched(); void mathFontChanged(int); void branchesRename(docstring const &, docstring const &); void allPackagesAuto(); diff --git a/src/frontends/qt4/ui/LanguageUi.ui b/src/frontends/qt4/ui/LanguageUi.ui index 470aedba78..686cb5eb48 100644 --- a/src/frontends/qt4/ui/LanguageUi.ui +++ b/src/frontends/qt4/ui/LanguageUi.ui @@ -44,7 +44,11 @@ - + + + Select the default style of Quote insets. + + @@ -80,23 +84,44 @@ + + + false + + + Select Unicode (utf8) variant. + + + + + + + false + + + Specify whether to load the 'inputenc' package + and write input encoding switch commands to the source. + + + + false - If you selected a custom output encoding to the left, yo can specifiy it here + Select encoding - + Select which language package LyX should use - + Language pa&ckage: @@ -111,38 +136,58 @@ &Encoding: + + Encoding of the generated LaTeX source + (LaTeX input encoding). + - encodingCO + unicodeEncodingRB - + true - - Here you might adjust the output encoding (used for LaTeX files) + + Unicode - - false - - - - - - Enter the command to load the language package (default: \usepackage{babel}) + Set input encoding to Unicode (utf8). - - - If this is checked, LyX does not load the inputenc LaTeX package + + + true - Do not load &inputenc + Automatic + + + Use language specific legacy encodings. + + + + + + + true + + + Custom + + + Use custom document-wide encoding. + + + + + + + Enter the command to load the language package (default: \usepackage{babel})