Am Freitag, 22. Dezember 2006 12:14 schrieb Dov Feldstern:

> 3) There's probably a better way than having to manually change the 
> encoding to cp1255. There's probably some way to automatically associate 
> the language with the encoding (I thought that's what "use language's 
> default encoding" is supposed to do, but obviously something's a little 
> off). Georg, can you help with this?

You are right, that is what "use language's default encoding" is supposed 
to do. Don't you have cp1255 for hebrew in lib/languages?

Anyway, here is a patch that gets rid of the encoding list in the 
preferences dialog. It also adds some other encodings I found in my tetex 
installation. Do we still miss some (I know, arabic is missing)?

If nobody objects this patch will go in after christmas.


Georg
Index: src/encoding.h
===================================================================
--- src/encoding.h	(Revision 16375)
+++ src/encoding.h	(Arbeitskopie)
@@ -53,6 +53,8 @@ public:
 	///
 	typedef std::map<std::string, Encoding> EncodingList;
 	///
+	typedef EncodingList::const_iterator const_iterator;
+	///
 	Encodings();
 	///
 	void read(support::FileName const & filename);
@@ -62,6 +64,11 @@ public:
 	Encoding const * getFromLaTeXName(std::string const & name) const;
 
 	///
+	const_iterator begin() const { return encodinglist.begin(); }
+	///
+	const_iterator end() const { return encodinglist.end(); }
+
+	///
 	enum Letter_Form {
 		///
 		FORM_ISOLATED,
Index: src/buffer.C
===================================================================
--- src/buffer.C	(Revision 16375)
+++ src/buffer.C	(Arbeitskopie)
@@ -142,7 +142,7 @@ using std::string;
 
 namespace {
 
-int const LYX_FORMAT = 255;
+int const LYX_FORMAT = 256;
 
 } // namespace anon
 
Index: src/frontends/qt4/QDocumentDialog.C
===================================================================
--- src/frontends/qt4/QDocumentDialog.C	(Revision 16375)
+++ src/frontends/qt4/QDocumentDialog.C	(Arbeitskopie)
@@ -25,6 +25,7 @@
 #include "qt_helpers.h"
 
 #include "bufferparams.h"
+#include "encoding.h"
 #include "gettext.h"
 #include "helper_funcs.h" // getSecond()
 #include "language.h"
@@ -56,18 +57,6 @@ namespace lyx {
 namespace frontend {
 
 
-namespace {
-
-// FIXME: This list is incomplete. It should not be hardcoded but come from
-// the available encodings in src/encodings.C
-char const * encodings[] = { "LaTeX default", "latin1", "latin2",
-	"latin3", "latin4", "latin5", "latin9",
-	"koi8-r", "koi8-u", "cp866", "cp1251",
-	"iso88595", "pt154", "utf8", 0
-};
-
-}
-
 QDocumentDialog::QDocumentDialog(QDocument * form)
 	: form_(form),
 	lang_(getSecond(getLanguageData(false)))
@@ -298,9 +287,17 @@ QDocumentDialog::QDocumentDialog(QDocume
 			toqstr(lit->first));
 	}
 
-	int k = 0;
-	while (encodings[k]) {
-		langModule->encodingCO->addItem(qt_(encodings[k++]));
+	// Always put the default encoding in the first position.
+	// It is special because the displayed text is translated.
+	langModule->encodingCO->addItem(qt_("LaTeX default"));
+	Encodings::const_iterator it = encodings.begin();
+	Encodings::const_iterator const end = encodings.end();
+	for (; it != end; ++it) {
+		string const enc = it->second.latexName();
+		// FIXME We should not have any encodings with unknown latex
+		// name
+		if (enc != "unknown")
+			langModule->encodingCO->addItem(toqstr(enc));
 	}
 
 	langModule->quoteStyleCO->addItem(qt_("``text''"));
@@ -669,11 +666,11 @@ void QDocumentDialog::apply(BufferParams
 		params.inputenc = "auto";
 	} else {
 		int i = langModule->encodingCO->currentIndex();
-		if (i == 0) {
+		if (i == 0)
 			params.inputenc = "default";
-		} else {
-			params.inputenc = encodings[i];
-		}
+		else
+			params.inputenc =
+				fromqstr(langModule->encodingCO->currentText());
 	}
 
 	InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
@@ -956,16 +953,13 @@ void QDocumentDialog::update(BufferParam
 		if (params.inputenc == "default") {
 			langModule->encodingCO->setCurrentIndex(0);
 		} else {
-			int i = 0;
-			while (encodings[i]) {
-				if (encodings[i] == params.inputenc) {
-					langModule->encodingCO->setCurrentIndex(i);
-					break;
-				}
-				++i;
-			}
-			// FIXME: possible data loss because of encodings is
-			// incomplete
+			int const i = langModule->encodingCO->findText(
+					toqstr(params.inputenc));
+			if (i >= 0)
+				langModule->encodingCO->setCurrentIndex(i);
+			else
+				// unknown encoding. Set to default.
+				langModule->encodingCO->setCurrentIndex(0);
 		}
 	}
 
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py	(Revision 16375)
+++ lib/lyx2lyx/LyX.py	(Arbeitskopie)
@@ -73,7 +73,7 @@ format_relation = [("0_06",    [200], ge
                    ("1_2",     [220], generate_minor_versions("1.2" , 4)),
                    ("1_3",     [221], generate_minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), generate_minor_versions("1.4" , 3)),
-                   ("1_5", range(246,256), generate_minor_versions("1.5" , 0))]
+                   ("1_5", range(246,257), generate_minor_versions("1.5" , 0))]
 
 
 def formats_list():
Index: lib/lyx2lyx/lyx_1_5.py
===================================================================
--- lib/lyx2lyx/lyx_1_5.py	(Revision 16375)
+++ lib/lyx2lyx/lyx_1_5.py	(Arbeitskopie)
@@ -646,6 +646,19 @@ def revert_cleardoublepage(document):
     i = i + 1
 
 
+def revert_encodings(document):
+    " Set new encodings to auto. "
+    encodings = ["cp437", "cp437de", "cp850", "cp852", "cp858", "cp865", "cp866", "cp1250", "cp1252", "cp1257"]
+    i = find_token(document.header, "\\inputencoding", 0)
+    if i == -1:
+        document.header.append("\\inputencoding auto")
+    else:
+        inputenc = get_value(document.header, "\\inputencoding", i)
+        if inputenc in encodings:
+            document.header[i] = "\\inputencoding auto"
+    document.inputencoding = get_value(document.header, "\\inputencoding", 0)
+
+
 ##
 # Conversion hub
 #
@@ -660,9 +673,11 @@ convert = [[246, []],
            [252, [convert_commandparams, convert_bibitem]],
            [253, []],
            [254, [convert_esint]],
+           [255, []],
            [255, []]]
 
-revert =  [[254, [revert_clearpage, revert_cleardoublepage]],
+revert =  [[255, [revert_encodings]],
+           [254, [revert_clearpage, revert_cleardoublepage]],
            [253, [revert_esint]],
            [252, [revert_nomenclature, revert_printnomenclature]],
            [251, [revert_commandparams]],
Index: lib/encodings
===================================================================
--- lib/encodings	(Revision 16375)
+++ lib/encodings	(Arbeitskopie)
@@ -39,12 +39,43 @@ End
 Encoding iso8859-15 latin9 ISO-8859-15
 End
 
-Encoding cp1255 cp1255 CP1255
+Encoding cp437 cp437 CP437
+End
+
+# cp437, but on position 225 is sz instead of beta
+Encoding cp437de cp437de CP437
+End
+
+Encoding cp850 cp850 CP850
+End
+
+Encoding cp852 cp852 CP852
+End
+
+Encoding cp858 cp858 CP858
+End
+
+Encoding cp865 cp865 CP865
+End
+
+Encoding cp866 cp866 CP866
+End
+
+Encoding cp1250 cp1250 CP1250
 End
 
 Encoding cp1251 cp1251 CP1251
 End
 
+Encoding cp1252 cp1252 CP1252
+End
+
+Encoding cp1255 cp1255 CP1255
+End
+
+Encoding cp1257 cp1257 CP1257
+End
+
 Encoding koi8 koi8-r KOI8-R
 End
 
Index: development/FORMAT
===================================================================
--- development/FORMAT	(Revision 16375)
+++ development/FORMAT	(Arbeitskopie)
@@ -1,6 +1,11 @@
 LyX file-format changes
 -----------------------ยง
 
+2006-12-22  Georg Baum  <[EMAIL PROTECTED]>
+
+	* format incremented to 256: allow some new inputenc settings.
+	For the complete list, see lib/lyx2lyx/lyx_1_5.py.
+
 2006-11-25  Georg Baum  <[EMAIL PROTECTED]>
 
 	* format incremented to 255: new insets for \clearpage and

Reply via email to