bool Format::formatSorter(Format const * lhs, Format const * rhs)
{
- return compare_locale(_(lhs->prettyname()), _(rhs->prettyname())) < 0;
+ return compare_locale(translateIfPossible(lhs->prettyname()),
+ translateIfPossible(rhs->prettyname())) < 0;
}
bool operator<(Format const & a, Format const & b)
{
- return compare_locale(_(a.prettyname()), _(b.prettyname())) < 0;
+ return compare_locale(translateIfPossible(a.prettyname()),
+ translateIfPossible(b.prettyname())) < 0;
}
-Format::Format(string const & n, string const & e, string const & p,
+Format::Format(string const & n, string const & e, docstring const & p,
string const & s, string const & v, string const & ed,
string const & m, int flags)
: name_(n), prettyname_(p), shortcut_(s), viewer_(v),
void Formats::add(string const & name)
{
if (!getFormat(name))
- add(name, name, name, string(), string(), string(),
+ add(name, name, from_utf8(name), string(), string(), string(),
string(), Format::document);
}
void Formats::add(string const & name, string const & extensions,
- string const & prettyname, string const & shortcut,
+ docstring const & prettyname, string const & shortcut,
string const & viewer, string const & editor,
string const & mime, int flags)
{
{
Format const * format = getFormat(name);
if (format)
- return from_utf8(format->prettyname());
+ return format->prettyname();
else
return from_utf8(name);
}
zipped_native = 8
};
///
- Format(std::string const & n, std::string const & e, std::string const & p,
+ Format(std::string const & n, std::string const & e, docstring const & p,
std::string const & s, std::string const & v, std::string const & ed,
std::string const & m, int);
///
///
void setExtensions(std::string const & v);
///
- std::string const prettyname() const { return prettyname_; }
+ docstring const prettyname() const { return prettyname_; }
///
- void setPrettyname(std::string const & v) { prettyname_ = v; }
+ void setPrettyname(docstring const & v) { prettyname_ = v; }
///
std::string const shortcut() const { return shortcut_; }
///
/// Filename extensions, the first one being the default
std::vector<std::string> extension_list_;
/// Name presented to the user. Needs to be unique.
- trivstring prettyname_;
+ trivdocstring prettyname_;
/// Keyboard shortcut for the View and Export menu.
trivstring shortcut_;
/*!
void add(std::string const & name);
///
void add(std::string const & name, std::string const & extensions,
- std::string const & prettyname, std::string const & shortcut,
+ docstring const & prettyname, std::string const & shortcut,
std::string const & viewer, std::string const & editor,
std::string const & mime, int flags);
///
}
case RC_FILEFORMAT: {
bool ok = true;
- string format, extensions, prettyname, shortcut;
+ string format, extensions, shortcut;
+ docstring prettyname;
if (!(lexrc >> format >> extensions))
ok = false;
if (ok && lexrc.next(true))
- prettyname = lexrc.getString();
+ prettyname = lexrc.getDocString();
else
ok = false;
if (ok)
format->mime() != cit->mime()) {
os << "\\format \"" << cit->name() << "\" \""
<< cit->extensions() << "\" \""
- << cit->prettyname() << "\" \""
+ << to_utf8(cit->prettyname()) << "\" \""
<< cit->shortcut() << "\" \""
<< escapeCommand(cit->viewer()) << "\" \""
<< escapeCommand(cit->editor()) << "\" \"";
outputModule->defaultFormatCO->clear();
outputModule->defaultFormatCO->addItem(qt_("Default"),
QVariant(QString("default")));
- typedef vector<Format const *> Formats;
- Formats formats = param_copy.exportableFormats(true);
+ vector<Format const *> 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())));
+ for (Format const * f : formats)
+ outputModule->defaultFormatCO->addItem
+ (toqstr(translateIfPossible(f->prettyname())),
+ QVariant(toqstr(f->name())));
outputModule->defaultFormatCO->blockSignals(false);
}
void PrefConverters::updateGui()
{
+ QString const pattern("%1 -> %2");
form_->formats().sort();
form_->converters().update(form_->formats());
// save current selection
- QString current = converterFromCO->currentText()
- + " -> " + converterToCO->currentText();
+ QString current =
+ pattern
+ .arg(converterFromCO->currentText())
+ .arg(converterToCO->currentText());
converterFromCO->clear();
converterToCO->clear();
- Formats::const_iterator cit = form_->formats().begin();
- Formats::const_iterator end = form_->formats().end();
- for (; cit != end; ++cit) {
- converterFromCO->addItem(qt_(cit->prettyname()));
- converterToCO->addItem(qt_(cit->prettyname()));
+ for (Format const & f : form_->formats()) {
+ QString const name = toqstr(translateIfPossible(f.prettyname()));
+ converterFromCO->addItem(name);
+ converterToCO->addItem(name);
}
// currentRowChanged(int) is also triggered when updating the listwidget
convertersLW->blockSignals(true);
convertersLW->clear();
- Converters::const_iterator ccit = form_->converters().begin();
- Converters::const_iterator cend = form_->converters().end();
- for (; ccit != cend; ++ccit) {
+ for (Converter const & c : form_->converters()) {
QString const name =
- qt_(ccit->From()->prettyname()) + " -> " + qt_(ccit->To()->prettyname());
- int type = form_->converters().getNumber(ccit->From()->name(), ccit->To()->name());
+ pattern
+ .arg(toqstr(translateIfPossible(c.From()->prettyname())))
+ .arg(toqstr(translateIfPossible(c.To()->prettyname())));
+ int type = form_->converters().getNumber(c.From()->name(),
+ c.To()->name());
new QListWidgetItem(name, convertersLW, type);
}
convertersLW->sortItems(Qt::AscendingOrder);
convertersLW->blockSignals(false);
// restore selection
- if (!current.isEmpty()) {
+ if (current != pattern.arg(QString()).arg(QString())) {
QList<QListWidgetItem *> const item =
convertersLW->findItems(current, Qt::MatchExactly);
if (!item.isEmpty())
private:
QString toString(Format const & format) const
{
- return qt_(format.prettyname());
+ return toqstr(translateIfPossible(format.prettyname()));
}
};
namespace {
-string const l10n_shortcut(string const & prettyname, string const & shortcut)
+string const l10n_shortcut(docstring const & prettyname, string const & shortcut)
{
if (shortcut.empty())
return string();
string l10n_format =
- to_utf8(_(prettyname + '|' + shortcut));
+ to_utf8(_(to_utf8(prettyname) + '|' + shortcut));
return split(l10n_format, '|');
}
defaultFormatCB->clear();
defaultOTFFormatCB->clear();
form_->formats().sort();
- Formats::const_iterator cit = form_->formats().begin();
- Formats::const_iterator end = form_->formats().end();
- for (; cit != end; ++cit) {
- formatsCB->addItem(qt_(cit->prettyname()),
- QVariant(form_->formats().getNumber(cit->name())));
- if (cit->viewer().empty())
+ for (Format const & f : formats) {
+ QString const prettyname = toqstr(translateIfPossible(f.prettyname()));
+ formatsCB->addItem(prettyname,
+ QVariant(form_->formats().getNumber(f.name())));
+ if (f.viewer().empty())
continue;
- if (form_->converters().isReachable("xhtml", cit->name())
- || form_->converters().isReachable("dviluatex", cit->name())
- || form_->converters().isReachable("luatex", cit->name())
- || form_->converters().isReachable("xetex", cit->name())) {
- defaultFormatCB->addItem(qt_(cit->prettyname()),
- QVariant(toqstr(cit->name())));
- defaultOTFFormatCB->addItem(qt_(cit->prettyname()),
- QVariant(toqstr(cit->name())));
- } else if (form_->converters().isReachable("latex", cit->name())
- || form_->converters().isReachable("pdflatex", cit->name()))
- defaultFormatCB->addItem(qt_(cit->prettyname()),
- QVariant(toqstr(cit->name())));
+ if (form_->converters().isReachable("xhtml", f.name())
+ || form_->converters().isReachable("dviluatex", f.name())
+ || form_->converters().isReachable("luatex", f.name())
+ || form_->converters().isReachable("xetex", f.name())) {
+ defaultFormatCB->addItem(prettyname,
+ QVariant(toqstr(f.name())));
+ defaultOTFFormatCB->addItem(prettyname,
+ QVariant(toqstr(f.name())));
+ } else if (form_->converters().isReachable("latex", f.name())
+ || form_->converters().isReachable("pdflatex", f.name()))
+ defaultFormatCB->addItem(prettyname,
+ QVariant(toqstr(f.name())));
}
// restore selections
void PrefFileformats::updatePrettyname()
{
QString const newname = formatsCB->currentText();
- if (newname == qt_(currentFormat().prettyname()))
+ if (newname == toqstr(translateIfPossible(currentFormat().prettyname())))
return;
- currentFormat().setPrettyname(fromqstr(newname));
+ currentFormat().setPrettyname(qstring_to_ucs4(newname));
formatsChanged();
updateView();
changed();
void PrefFileformats::on_formatNewPB_clicked()
{
- form_->formats().add("", "", "", "", "", "", "", Format::none);
+ form_->formats().add("", "", docstring(), "", "", "", "", Format::none);
updateView();
formatsCB->setCurrentIndex(0);
formatsCB->setFocus(Qt::OtherFocusReason);
{
all_formats_ = buffer().params().exportableFormats(false);
sort(all_formats_.begin(), all_formats_.end(), Format::formatSorter);
-
// Save the current selection if any
- Format const * current_format = 0;
+ Format const * current_format = nullptr;
int const line = formatLW->currentRow();
- if (line >= 0 && line <= formatLW->count()
+ if (line >= 0 && static_cast<unsigned int>(line) < all_formats_.size()
&& formatLW->selectedItems().size() > 0)
current_format = all_formats_[line];
-
- // Check whether the current contents of the browser will be
- // changed by loading the contents of formats
- vector<string> keys;
- keys.resize(all_formats_.size());
-
- vector<string>::iterator result = keys.begin();
- vector<Format const *>::const_iterator it = all_formats_.begin();
- vector<Format const *>::const_iterator end = all_formats_.end();
-
- int current_line = -1;
- for (int ln = 0; it != end; ++it, ++result, ++ln) {
- *result = (*it)->prettyname();
- if (current_format
- && (*it)->prettyname() == current_format->prettyname())
- current_line = ln;
- }
-
- // Reload the browser
+ // Reset the list widget
formatLW->clear();
-
- for (vector<string>::const_iterator it = keys.begin();
- it != keys.end(); ++it) {
- formatLW->addItem(qt_(*it));
+ for (Format const * f : all_formats_) {
+ formatLW->addItem(toqstr(translateIfPossible(f->prettyname())));
+ // Restore the selection
+ if (current_format && f->prettyname() == current_format->prettyname())
+ formatLW->setCurrentRow(formatLW->count() - 1);
}
-
- // Restore the selection
- if (current_line > -1)
- formatLW->setCurrentItem(formatLW->item(current_line));
}
QStringList types;
QString const anyformat = qt_("Guess from extension (*.*)");
types << anyformat;
- Formats::const_iterator it = formats.begin();
+
vector<Format const *> export_formats;
- for (; it != formats.end(); ++it)
- if (it->documentFormat())
- export_formats.push_back(&(*it));
- sort(export_formats.begin(), export_formats.end(),
- [](Format const *first, Format const *second) {
- QString name1 = qt_(first->prettyname());
- QString name2 = qt_(second->prettyname());
- return 0 < name2.localeAwareCompare(name1);
- });
- vector<Format const *>::const_iterator fit = export_formats.begin();
+ for (Format const & f : formats)
+ if (f.documentFormat())
+ export_formats.push_back(&f);
+ sort(export_formats.begin(), export_formats.end(), Format::formatSorter);
map<QString, string> fmap;
QString filter;
string ext;
- for (; fit != export_formats.end(); ++fit) {
- docstring const loc_prettyname =
- translateIfPossible(from_utf8((*fit)->prettyname()));
+ for (Format const * f : export_formats) {
+ docstring const loc_prettyname = translateIfPossible(f->prettyname());
QString const loc_filter = toqstr(bformat(from_ascii("%1$s (*.%2$s)"),
loc_prettyname,
- from_ascii((*fit)->extension())));
+ from_ascii(f->extension())));
types << loc_filter;
- fmap[loc_filter] = (*fit)->name();
- if (from_ascii((*fit)->name()) == iformat) {
+ fmap[loc_filter] = f->name();
+ if (from_ascii(f->name()) == iformat) {
filter = loc_filter;
- ext = (*fit)->extension();
+ ext = f->extension();
}
}
string ofname = fname.onlyFileName();
continue;
}
- QString const pretty = qt_(fmt->prettyname());
+ QString const pretty = toqstr(translateIfPossible(fmt->prettyname()));
QString const qformat = toqstr(format);
outputFormatCO->addItem(pretty, QVariant(qformat));
if (qformat == view_format_)
MenuItem item(MenuItem::Submenu, smenue);
item.setSubmenu(MenuDefinition(smenue));
- Formats::const_iterator fit = formats.begin();
- Formats::const_iterator end = formats.end();
- for (; fit != end ; ++fit) {
- if ((*fit)->dummy())
+ for (Format const * f : formats) {
+ if (f->dummy())
continue;
- docstring lab = from_utf8((*fit)->prettyname());
- docstring const scut = from_utf8((*fit)->shortcut());
+ docstring lab = f->prettyname();
+ docstring const scut = from_utf8(f->shortcut());
docstring const tmplab = lab;
if (!scut.empty())
break;
case MenuItem::ViewFormats:
case MenuItem::UpdateFormats:
- if ((*fit)->name() == buf->params().getDefaultOutputFormat()) {
+ if (f->name() == buf->params().getDefaultOutputFormat()) {
docstring lbl = (kind == MenuItem::ViewFormats
? bformat(_("View [%1$s]|V"), label)
: bformat(_("Update [%1$s]|U"), label));
}
// fall through
case MenuItem::ExportFormats:
- if (!(*fit)->inExportMenu())
+ if (!f->inExportMenu())
continue;
break;
default:
// note that at this point, we know that buf is not null
LATTEST(buf);
item.submenu().addWithStatusCheck(MenuItem(MenuItem::Command,
- toqstr(label), FuncRequest(action, (*fit)->name())));
+ toqstr(label), FuncRequest(action, f->name())));
} else {
if (buf)
addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label),
- FuncRequest(action, (*fit)->name())));
+ FuncRequest(action, f->name())));
else
add(MenuItem(MenuItem::Command, toqstr(label),
- FuncRequest(action, (*fit)->name())));
+ FuncRequest(action, f->name())));
}
}
if (view_update)
case TO_VIEWFORMATS: {
vector<Format const *> formats = (code == TO_IMPORTFORMATS) ?
theConverters().importableFormats() :
- theConverters().exportableFormats(code != TO_EXPORTFORMATS);
+ theConverters().exportableFormats(true);
sort(formats.begin(), formats.end());
- vector<Format const *>::const_iterator fit = formats.begin();
- vector<Format const *>::const_iterator end = formats.end();
- for (; fit != end ; ++fit) {
- if ((*fit)->dummy())
+ for (Format const * f : formats) {
+ if (f->dummy())
continue;
if (code != TO_IMPORTFORMATS &&
- !(*fit)->documentFormat())
+ !f->documentFormat())
continue;
- docstring const prettyname =
- from_utf8((*fit)->prettyname());
+ docstring const prettyname = f->prettyname();
docstring tooltip;
FuncCode lfun = LFUN_NOACTION;
switch (code) {
tooltip = _("View %1$s");
break;
}
- FuncRequest func(lfun, (*fit)->name(),
+ FuncRequest func(lfun, f->name(),
FuncRequest::TOOLBAR);
add(ToolbarItem(ToolbarItem::COMMAND, func,
bformat(tooltip, prettyname)));