On 07/09/2011 2:09 PM, Julien Rioux wrote:
On 06/09/2011 2:57 AM, Richard Heck wrote:
If you make the extensions_ member a vector<string> or list<string>, it
will make looping and such a lot easier. You might then just have:
string extension() { return extensions_[0]; }

I guess we need to keep extensions_ from being an empty vector<string>
then.


Patch version 2.
The patch for 6340 should be applied on top of the patch for 4798.

--
Julien
commit ef9b9cb604ac054f033ca8cf9a3c2c12e83982ef
Author: Julien Rioux <jri...@lyx.org>
Date:   Sun Sep 4 03:38:06 2011 +0200

    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.

diff --git a/lib/configure.py b/lib/configure.py
index 908c211..095357e 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -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"	""
@@ -1306,7 +1306,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 = ''
diff --git a/lib/scripts/prefs2prefs_prefs.py b/lib/scripts/prefs2prefs_prefs.py
index 7a2cdd6..47ec155 100644
--- a/lib/scripts/prefs2prefs_prefs.py
+++ b/lib/scripts/prefs2prefs_prefs.py
@@ -108,4 +108,5 @@ conversions = [
 		language_use_babel,
 		language_package
 	] # end conversions for format 0
+	,[]
 ]
diff --git a/src/Format.cpp b/src/Format.cpp
index cd2d238..768affe 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -69,7 +69,7 @@ public:
 		: extension_(extension) {}
 	bool operator()(Format const & f) const
 	{
-		return f.extension() == extension_;
+		return f.hasExtension(extension_);
 	}
 private:
 	string extension_;
@@ -90,9 +90,13 @@ 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, ",");
+	if (extension_list_.empty())
+		extension_list_.push_back("");
+}
 
 
 bool Format::dummy() const
@@ -101,6 +105,20 @@ bool Format::dummy() const
 }
 
 
+bool Format::hasExtension(string const & e) const
+{
+	if (extension().empty())
+		return false;
+	std::vector<string>::const_iterator it  = extension_list_.begin();
+	std::vector<string>::const_iterator end = extension_list_.end();
+	for (; it != end; ++it) {
+		if ((*it) == e)
+			return true;
+	}
+	return false;
+}
+
+
 bool Format::isChildFormat() const
 {
 	if (name_.empty())
@@ -115,6 +133,15 @@ string const Format::parentFormat() const
 }
 
 
+void Format::setExtensions(string const & e)
+{
+	extensions_ = e;
+	extension_list_ = getVectorFromString(e, ",");
+	if (extension_list_.empty())
+		extension_list_.push_back("");
+}
+
+
 // 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
@@ -207,7 +234,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)
@@ -216,10 +243,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);
 }
 
@@ -416,6 +443,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;
 
diff --git a/src/Format.h b/src/Format.h
index 682f8c5..36da00d 100644
--- a/src/Format.h
+++ b/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,11 @@ public:
 	///
 	void setName(std::string const & v) { name_ = v; }
 	///
-	std::string const & extension() const { return extension_; }
+	std::string const & extension() const { return 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 +89,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 +143,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 +166,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(); }
diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp
index 4211685..ffe1aff 100644
--- a/src/LyXRC.cpp
+++ b/src/LyXRC.cpp
@@ -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()) << "\" \""
diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp
index 16be7bc..86b7963 100644
--- a/src/frontends/qt4/GuiPrefs.cpp
+++ b/src/frontends/qt4/GuiPrefs.cpp
@@ -1953,7 +1953,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()));
@@ -1988,12 +1988,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));
diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h
index d567ca6..571cb9c 100644
--- a/src/frontends/qt4/GuiPrefs.h
+++ b/src/frontends/qt4/GuiPrefs.h
@@ -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 &);
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index fee9f9c..4f55834 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -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;
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 076681c..103e024 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -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;
 
diff --git a/src/frontends/qt4/ui/PrefFileformatsUi.ui b/src/frontends/qt4/ui/PrefFileformatsUi.ui
index f62dcdf..a63c150 100644
--- a/src/frontends/qt4/ui/PrefFileformatsUi.ui
+++ b/src/frontends/qt4/ui/PrefFileformatsUi.ui
@@ -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&amp;xtension:</string>
+      <string>E&amp;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" >
@@ -232,7 +232,7 @@
   <tabstop>documentCB</tabstop>
   <tabstop>vectorCB</tabstop>
   <tabstop>formatED</tabstop>
-  <tabstop>extensionED</tabstop>
+  <tabstop>extensionsED</tabstop>
   <tabstop>shortcutED</tabstop>
   <tabstop>editorED</tabstop>
   <tabstop>viewerED</tabstop>
commit f15e077116a4620bc108200eaac70c618cc5f42f
Author: Julien Rioux <jri...@lyx.org>
Date:   Sun Sep 4 03:42:14 2011 +0200

    Show .htm files in HTML import file dialog (#6340).
    
      - Add "htm" as a known extension for HTML.
    
      - Use all the extensions of a format as file filter,
        instead of using only the default extension.

diff --git a/lib/configure.py b/lib/configure.py
index 095357e..09f1521 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -571,7 +571,7 @@ def checkFormatEntries(dtl_tools):
         addToRC(r'\Format dvi2       dvi     DraftDVI               ""	""	""	"vector"')
     #
     checkViewer('an HTML previewer', ['firefox', 'mozilla file://$$p$$i', 'netscape'],
-        rc_entry = [r'\Format html       html    HTML                   H  "%%"	""	"document,menu=export"'])
+        rc_entry = [r'\Format html      "html, htm" HTML                H  "%%"	""	"document,menu=export"'])
     #
     checkViewerEditor('Noteedit', ['noteedit'],
         rc_entry = [r'\Format noteedit   not     Noteedit               "" "%%"	"%%"	"vector"'])
@@ -605,7 +605,7 @@ def checkFormatEntries(dtl_tools):
 \Format pstex      pstex_t PSTEX                  "" ""	""	""
 \Format wmf        wmf    "Windows Metafile"      "" ""	""	"vector"
 \Format emf        emf    "Enhanced Metafile"     "" ""	""	"vector"
-\Format wordhtml   html   "HTML (MS Word)"        "" "" ""	"document"
+\Format wordhtml  "html, htm" "HTML (MS Word)"    "" "" ""	"document"
 ''')
 
 
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 4f55834..225033b 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -2066,10 +2066,10 @@ void GuiView::importDocument(string const & argument)
 			toqstr(addPath(package().system_support().absFileName(), "examples")));
 
 		docstring filter = formats.prettyName(format);
-		filter += " (*.";
+		filter += " (*.{";
 		// FIXME UNICODE
-		filter += from_utf8(formats.extension(format));
-		filter += ')';
+		filter += from_utf8(formats.extensions(format));
+		filter += "})";
 
 		FileDialog::Result result =
 			dlg.open(toqstr(initpath), fileFilters(toqstr(filter)));

Reply via email to