mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Allow to assign several extension to a given file format (#4798).
Additionnal extensions are separated by commas (,) in lyxrc preference files, while spaces are ignored, e.g. "jpg, jpeg". Preference lyxrc file format incremented to 2. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39670 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9ffc42d216
commit
a55ef8346a
@ -476,7 +476,7 @@ def checkFormatEntries(dtl_tools):
|
||||
path, iv = checkViewerNoRC('a raster image viewer', ['xv', 'kview', 'gimp-remote', 'gimp'],
|
||||
rc_entry = [r'''\Format bmp bmp BMP "" "%s" "%s" ""
|
||||
\Format gif gif GIF "" "%s" "%s" ""
|
||||
\Format jpg jpg JPEG "" "%s" "%s" ""
|
||||
\Format jpg "jpg, jpeg" JPEG "" "%s" "%s" ""
|
||||
\Format pbm pbm PBM "" "%s" "%s" ""
|
||||
\Format pgm pgm PGM "" "%s" "%s" ""
|
||||
\Format png png PNG "" "%s" "%s" ""
|
||||
@ -487,7 +487,7 @@ def checkFormatEntries(dtl_tools):
|
||||
path, ie = checkEditorNoRC('a raster image editor', ['gimp-remote', 'gimp'],
|
||||
rc_entry = [r'''\Format bmp bmp BMP "" "%s" "%s" ""
|
||||
\Format gif gif GIF "" "%s" "%s" ""
|
||||
\Format jpg jpg JPEG "" "%s" "%s" ""
|
||||
\Format jpg "jpg, jpeg" JPEG "" "%s" "%s" ""
|
||||
\Format pbm pbm PBM "" "%s" "%s" ""
|
||||
\Format pgm pgm PGM "" "%s" "%s" ""
|
||||
\Format png png PNG "" "%s" "%s" ""
|
||||
@ -497,7 +497,7 @@ def checkFormatEntries(dtl_tools):
|
||||
\Format xpm xpm XPM "" "%s" "%s" ""'''])
|
||||
addToRC(r'''\Format bmp bmp BMP "" "%s" "%s" ""
|
||||
\Format gif gif GIF "" "%s" "%s" ""
|
||||
\Format jpg jpg JPEG "" "%s" "%s" ""
|
||||
\Format jpg "jpg, jpeg" JPEG "" "%s" "%s" ""
|
||||
\Format pbm pbm PBM "" "%s" "%s" ""
|
||||
\Format pgm pgm PGM "" "%s" "%s" ""
|
||||
\Format png png PNG "" "%s" "%s" ""
|
||||
@ -1297,7 +1297,7 @@ def removeTempFiles():
|
||||
if __name__ == '__main__':
|
||||
lyx_check_config = True
|
||||
outfile = 'lyxrc.defaults'
|
||||
lyxrc_fileformat = 1
|
||||
lyxrc_fileformat = 2
|
||||
rc_entries = ''
|
||||
lyx_keep_temps = False
|
||||
version_suffix = ''
|
||||
|
@ -16,6 +16,10 @@
|
||||
# where the Bool says if we've modified anything and the NewLine is
|
||||
# the new line, if so, which will be used to replace the old line.
|
||||
|
||||
# Incremented to format 2, r39670 by jrioux
|
||||
# Support for multiple file extensions per format.
|
||||
# No conversion necessary.
|
||||
|
||||
import re
|
||||
|
||||
|
||||
@ -108,4 +112,5 @@ conversions = [
|
||||
language_use_babel,
|
||||
language_package
|
||||
]],
|
||||
[ 2, []],
|
||||
]
|
||||
|
@ -69,7 +69,7 @@ public:
|
||||
: extension_(extension) {}
|
||||
bool operator()(Format const & f) const
|
||||
{
|
||||
return f.extension() == extension_;
|
||||
return f.hasExtension(extension_);
|
||||
}
|
||||
private:
|
||||
string extension_;
|
||||
@ -91,9 +91,11 @@ bool operator<(Format const & a, Format const & b)
|
||||
Format::Format(string const & n, string const & e, string const & p,
|
||||
string const & s, string const & v, string const & ed,
|
||||
int flags)
|
||||
: name_(n), extension_(e), prettyname_(p), shortcut_(s), viewer_(v),
|
||||
: name_(n), extensions_(e), prettyname_(p), shortcut_(s), viewer_(v),
|
||||
editor_(ed), flags_(flags)
|
||||
{}
|
||||
{
|
||||
extension_list_ = getVectorFromString(e, ",");
|
||||
}
|
||||
|
||||
|
||||
bool Format::dummy() const
|
||||
@ -102,6 +104,13 @@ bool Format::dummy() const
|
||||
}
|
||||
|
||||
|
||||
bool Format::hasExtension(string const & e) const
|
||||
{
|
||||
return (find(extension_list_.begin(), extension_list_.end(), e)
|
||||
!= extension_list_.end());
|
||||
}
|
||||
|
||||
|
||||
bool Format::isChildFormat() const
|
||||
{
|
||||
if (name_.empty())
|
||||
@ -116,6 +125,13 @@ string const Format::parentFormat() const
|
||||
}
|
||||
|
||||
|
||||
void Format::setExtensions(string const & e)
|
||||
{
|
||||
extensions_ = e;
|
||||
extension_list_ = getVectorFromString(e, ",");
|
||||
}
|
||||
|
||||
|
||||
// This method should return a reference, and throw an exception
|
||||
// if the format named name cannot be found (Lgb)
|
||||
Format const * Formats::getFormat(string const & name) const
|
||||
@ -208,7 +224,7 @@ void Formats::add(string const & name)
|
||||
}
|
||||
|
||||
|
||||
void Formats::add(string const & name, string const & extension,
|
||||
void Formats::add(string const & name, string const & extensions,
|
||||
string const & prettyname, string const & shortcut,
|
||||
string const & viewer, string const & editor,
|
||||
int flags)
|
||||
@ -217,10 +233,10 @@ void Formats::add(string const & name, string const & extension,
|
||||
find_if(formatlist.begin(), formatlist.end(),
|
||||
FormatNamesEqual(name));
|
||||
if (it == formatlist.end())
|
||||
formatlist.push_back(Format(name, extension, prettyname,
|
||||
formatlist.push_back(Format(name, extensions, prettyname,
|
||||
shortcut, viewer, editor, flags));
|
||||
else
|
||||
*it = Format(name, extension, prettyname, shortcut, viewer,
|
||||
*it = Format(name, extensions, prettyname, shortcut, viewer,
|
||||
editor, flags);
|
||||
}
|
||||
|
||||
@ -417,6 +433,16 @@ string const Formats::extension(string const & name) const
|
||||
}
|
||||
|
||||
|
||||
string const Formats::extensions(string const & name) const
|
||||
{
|
||||
Format const * format = getFormat(name);
|
||||
if (format)
|
||||
return format->extensions();
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
typedef Translator<OutputParams::FLAVOR, string> FlavorTranslator;
|
||||
|
||||
|
21
src/Format.h
21
src/Format.h
@ -45,6 +45,8 @@ public:
|
||||
int);
|
||||
///
|
||||
bool dummy() const;
|
||||
/// Is \p ext a valid filename extension for this format?
|
||||
bool hasExtension(std::string const & ext) const;
|
||||
/// Tell whether this format is a child format.
|
||||
/// Child formats inherit settings like the viewer from their parent.
|
||||
bool isChildFormat() const;
|
||||
@ -55,9 +57,14 @@ public:
|
||||
///
|
||||
void setName(std::string const & v) { name_ = v; }
|
||||
///
|
||||
std::string const & extension() const { return extension_; }
|
||||
std::string const & extension() const
|
||||
{
|
||||
return extension_list_.empty() ? empty_string() : extension_list_[0];
|
||||
}
|
||||
///
|
||||
void setExtension(std::string const & v) { extension_ = v; }
|
||||
std::string const & extensions() const { return extensions_; }
|
||||
///
|
||||
void setExtensions(std::string const & v);
|
||||
///
|
||||
std::string const & prettyname() const { return prettyname_; }
|
||||
///
|
||||
@ -85,8 +92,10 @@ public:
|
||||
private:
|
||||
/// Internal name. Needs to be unique.
|
||||
std::string name_;
|
||||
/// Filename extension
|
||||
std::string extension_;
|
||||
/// Filename extensions, the first one being the default
|
||||
mutable std::vector<std::string> extension_list_;
|
||||
/// All filename extensions
|
||||
std::string extensions_;
|
||||
/// Name presented to the user. Needs to be unique.
|
||||
std::string prettyname_;
|
||||
/// Keyboard shortcut for the View and Export menu.
|
||||
@ -137,7 +146,7 @@ public:
|
||||
///
|
||||
void add(std::string const & name);
|
||||
///
|
||||
void add(std::string const & name, std::string const & extension,
|
||||
void add(std::string const & name, std::string const & extensions,
|
||||
std::string const & prettyname, std::string const & shortcut,
|
||||
std::string const & viewer, std::string const & editor,
|
||||
int flags);
|
||||
@ -160,6 +169,8 @@ public:
|
||||
///
|
||||
std::string const extension(std::string const & name) const;
|
||||
///
|
||||
std::string const extensions(std::string const & name) const;
|
||||
///
|
||||
const_iterator begin() const { return formatlist.begin(); }
|
||||
///
|
||||
const_iterator end() const { return formatlist.end(); }
|
||||
|
@ -55,7 +55,7 @@ namespace os = support::os;
|
||||
|
||||
namespace {
|
||||
|
||||
static unsigned int const LYXRC_FILEFORMAT = 1;
|
||||
static unsigned int const LYXRC_FILEFORMAT = 2;
|
||||
|
||||
// when adding something to this array keep it sorted!
|
||||
LexerKeyword lyxrcTags[] = {
|
||||
@ -1088,8 +1088,8 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
|
||||
break;
|
||||
}
|
||||
case RC_FILEFORMAT: {
|
||||
string format, extension, prettyname, shortcut;
|
||||
lexrc >> format >> extension >> prettyname >> shortcut;
|
||||
string format, extensions, prettyname, shortcut;
|
||||
lexrc >> format >> extensions >> prettyname >> shortcut;
|
||||
string viewer, editor;
|
||||
if (lexrc.next(true))
|
||||
viewer = lexrc.getString();
|
||||
@ -1131,7 +1131,7 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
|
||||
else
|
||||
formats.erase(format);
|
||||
} else {
|
||||
formats.add(format, extension, prettyname,
|
||||
formats.add(format, extensions, prettyname,
|
||||
shortcut, viewer, editor, flgs);
|
||||
}
|
||||
break;
|
||||
@ -2731,7 +2731,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
|
||||
Format const * format =
|
||||
system_formats.getFormat(cit->name());
|
||||
if (!format ||
|
||||
format->extension() != cit->extension() ||
|
||||
format->extensions() != cit->extensions() ||
|
||||
format->prettyname() != cit->prettyname() ||
|
||||
format->shortcut() != cit->shortcut() ||
|
||||
format->viewer() != cit->viewer() ||
|
||||
@ -2740,7 +2740,7 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
|
||||
format->vectorFormat() != cit->vectorFormat() ||
|
||||
format->inExportMenu() != cit->inExportMenu()) {
|
||||
os << "\\format \"" << cit->name() << "\" \""
|
||||
<< cit->extension() << "\" \""
|
||||
<< cit->extensions() << "\" \""
|
||||
<< cit->prettyname() << "\" \""
|
||||
<< cit->shortcut() << "\" \""
|
||||
<< escapeCommand(cit->viewer()) << "\" \""
|
||||
|
@ -1903,7 +1903,7 @@ PrefFileformats::PrefFileformats(GuiPreferences * form)
|
||||
|
||||
formatED->setValidator(new FormatNameValidator(formatsCB, form_->formats()));
|
||||
formatsCB->setValidator(new FormatPrettynameValidator(formatsCB, form_->formats()));
|
||||
extensionED->setValidator(new NoNewLineValidator(extensionED));
|
||||
extensionsED->setValidator(new NoNewLineValidator(extensionsED));
|
||||
shortcutED->setValidator(new NoNewLineValidator(shortcutED));
|
||||
editorED->setValidator(new NoNewLineValidator(editorED));
|
||||
viewerED->setValidator(new NoNewLineValidator(viewerED));
|
||||
@ -2010,7 +2010,7 @@ void PrefFileformats::on_formatsCB_currentIndexChanged(int i)
|
||||
|
||||
formatED->setText(toqstr(f.name()));
|
||||
copierED->setText(toqstr(form_->movers().command(f.name())));
|
||||
extensionED->setText(toqstr(f.extension()));
|
||||
extensionsED->setText(toqstr(f.extensions()));
|
||||
shortcutED->setText(
|
||||
toqstr(l10n_shortcut(f.prettyname(), f.shortcut())));
|
||||
documentCB->setChecked((f.documentFormat()));
|
||||
@ -2045,12 +2045,13 @@ void PrefFileformats::on_copierED_textEdited(const QString & s)
|
||||
}
|
||||
|
||||
|
||||
void PrefFileformats::on_extensionED_textEdited(const QString & s)
|
||||
void PrefFileformats::on_extensionsED_textEdited(const QString & s)
|
||||
{
|
||||
currentFormat().setExtension(fromqstr(s));
|
||||
currentFormat().setExtensions(fromqstr(s));
|
||||
changed();
|
||||
}
|
||||
|
||||
|
||||
void PrefFileformats::on_viewerED_textEdited(const QString & s)
|
||||
{
|
||||
currentFormat().setViewer(fromqstr(s));
|
||||
|
@ -360,7 +360,7 @@ Q_SIGNALS:
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_copierED_textEdited(const QString & s);
|
||||
void on_extensionED_textEdited(const QString &);
|
||||
void on_extensionsED_textEdited(const QString &);
|
||||
void on_viewerED_textEdited(const QString &);
|
||||
void on_editorED_textEdited(const QString &);
|
||||
void on_shortcutED_textEdited(const QString &);
|
||||
|
@ -897,7 +897,7 @@ void GuiView::dropEvent(QDropEvent * event)
|
||||
= theConverters().importableFormats();
|
||||
vector<const Format *>::const_iterator it = import_formats.begin();
|
||||
for (; it != import_formats.end(); ++it)
|
||||
if ((*it)->extension() == ext)
|
||||
if ((*it)->hasExtension(ext))
|
||||
found_formats.push_back(*it);
|
||||
|
||||
FuncRequest cmd;
|
||||
|
@ -347,10 +347,11 @@ QString makeAbsPath(QString const & relpath, QString const & base)
|
||||
static string const convert_brace_glob(string const & glob)
|
||||
{
|
||||
// Matches " *.{abc,def,ghi}", storing "*." as group 1 and
|
||||
// "abc,def,ghi" as group 2.
|
||||
static lyx::regex const glob_re(" *([^ {]*)\\{([^ }]+)\\}");
|
||||
// Matches "abc" and "abc,", storing "abc" as group 1.
|
||||
static lyx::regex const block_re("([^,}]+),?");
|
||||
// "abc,def,ghi" as group 2, while allowing spaces in group 2.
|
||||
static lyx::regex const glob_re(" *([^ {]*)\\{([^}]+)\\}");
|
||||
// Matches "abc" and "abc,", storing "abc" as group 1,
|
||||
// while ignoring surrounding spaces.
|
||||
static lyx::regex const block_re(" *([^ ,}]+) *,? *");
|
||||
|
||||
string pattern;
|
||||
|
||||
|
@ -91,17 +91,17 @@
|
||||
<widget class="QLineEdit" name="formatED" />
|
||||
</item>
|
||||
<item row="5" column="0" >
|
||||
<widget class="QLabel" name="extensionLA" >
|
||||
<widget class="QLabel" name="extensionsLA" >
|
||||
<property name="text" >
|
||||
<string>E&xtension:</string>
|
||||
<string>E&xtensions:</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>extensionED</cstring>
|
||||
<cstring>extensionsED</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="2" >
|
||||
<widget class="QLineEdit" name="extensionED" />
|
||||
<widget class="QLineEdit" name="extensionsED" />
|
||||
</item>
|
||||
<item row="7" column="0" >
|
||||
<widget class="QLabel" name="shortcutLA" >
|
||||
@ -233,7 +233,7 @@
|
||||
<tabstop>exportMenuCB</tabstop>
|
||||
<tabstop>vectorCB</tabstop>
|
||||
<tabstop>formatED</tabstop>
|
||||
<tabstop>extensionED</tabstop>
|
||||
<tabstop>extensionsED</tabstop>
|
||||
<tabstop>shortcutED</tabstop>
|
||||
<tabstop>editorCO</tabstop>
|
||||
<tabstop>editorED</tabstop>
|
||||
|
Loading…
Reference in New Issue
Block a user