From 2adc68ed46e6477c7c37ab24116d3c5785386160 Mon Sep 17 00:00:00 2001
From: henrikjust <henrikjust@f0f2a975-2e09-46c8-9428-3b39399b9f3c>
Date: Tue, 20 Sep 2011 10:54:26 +0000
Subject: [PATCH] Bugfixes for the "Text and Math" options page (w2l)

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@126 f0f2a975-2e09-46c8-9428-3b39399b9f3c
---
 source/distro/changelog.txt                   |  2 ++
 .../writer2latex/ConfigurationDialog.java     | 30 +++++++++++--------
 .../writer2latex/api/ConverterFactory.java    |  4 +--
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt
index 3e1546c..8e1e45c 100644
--- a/source/distro/changelog.txt
+++ b/source/distro/changelog.txt
@@ -2,6 +2,8 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2
 
 ---------- version 1.1.9 ----------
 
+[w2l] Fixed bugs on the "Text and Math" options page (controls were not updated correctly leading to erratic behavior)
+
 [w2l] Added support for the font "Greek"
 
 ---------- version 1.1.8 ----------
diff --git a/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java b/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java
index ce4afae..8a39bbc 100644
--- a/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java
+++ b/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java
@@ -16,11 +16,11 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *  MA  02111-1307  USA
  *
- *  Copyright: 2002-2010 by Henrik Just
+ *  Copyright: 2002-2011 by Henrik Just
  *
  *  All Rights Reserved.
  * 
- *  Version 1.2 (2010-12-21)
+ *  Version 1.2 (2011-09-20)
  *
  */ 
  
@@ -179,7 +179,6 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
         	// Save heading map to config
         	config.getComplexOption("heading-map").clear();
         	int nMaxLevel = dlg.getListBoxSelectedItem("MaxLevel");
-        	System.out.println("Using current max level of "+nMaxLevel);
     		for (int i=1; i<=nMaxLevel; i++) {
     			String sLevel = Integer.toString(i);
     			config.getComplexOption("heading-map").copy(sLevel,headingMap.get(sLevel));
@@ -283,7 +282,6 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
         private void updateHeadingMap(DialogAccess dlg) {
         	// Save the current writer level in our cache
         	if (nCurrentWriterLevel>-1) {
-        		System.out.println("Updating current definition for writer level "+nCurrentWriterLevel+ " from ui");
         		Map<String,String> attr = new HashMap<String,String>();
         		attr.put("name", dlg.getComboBoxText("LaTeXName"));
         		attr.put("level", dlg.getComboBoxText("LaTeXLevel"));
@@ -616,7 +614,7 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
         	checkBoxFromConfig(dlg,"UseLastpage", "use_lastpage");
         	checkBoxFromConfig(dlg,"UseEndnotes", "use_endnotes");
 
-        	// Trigger change events (this is not done by the setters above)
+        	// Trigger change events
 			exportGeometryChange(dlg);
 			exportHeaderAndFooterChange(dlg);
     	}
@@ -827,8 +825,9 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
     		mathSymbols.copyAll(config.getComplexOption("math-symbol-map"));
     		sCurrentMathSymbol = null;
         	dlg.setListBoxStringItemList("MathSymbolName", Misc.sortStringSet(mathSymbols.keySet()));
-        	// This triggers an onchange event
         	dlg.setListBoxSelectedItem("MathSymbolName", (short)Math.min(0,mathSymbols.keySet().size()-1));
+        	// Trigger change event (on some versions of OOo this is automatic due to a bug)
+        	mathSymbolNameChange(dlg);
 
         	// Get string replace from config
         	if (stringReplace!=null) { stringReplace.clear(); }
@@ -836,8 +835,9 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
     		stringReplace.copyAll(config.getComplexOption("string-replace"));
     		sCurrentText = null;
         	dlg.setListBoxStringItemList("TextInput", Misc.sortStringSet(stringReplace.keySet()));
-        	// This triggers an onchange event
         	dlg.setListBoxSelectedItem("TextInput", (short)Math.min(0,stringReplace.keySet().size()-1));
+        	// Trigger change event (on some versions of OOo this is automatic due to a bug)
+        	textInputChange(dlg);
         	    	
         	// Get other options from config
         	checkBoxFromConfig(dlg,"UseOoomath","use_ooomath");
@@ -894,16 +894,19 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
     	}
     	
     	private void newSymbolClick(DialogAccess dlg) {
-    		// This triggers an onchange event
         	appendItem(dlg,"MathSymbolName",customSymbolNameProvider.getNames());
+        	// Trigger change event (on some versions of OOo this is automatic due to a bug)
+        	mathSymbolNameChange(dlg);
     	}
     	
     	private void deleteSymbolClick(DialogAccess dlg) {
     		String sMathSymbol = sCurrentMathSymbol; 
-    		// This triggers an onchange event
         	if (deleteCurrentItem(dlg,"MathSymbolName")) {
         		mathSymbols.remove(sMathSymbol);
+        		sCurrentMathSymbol=null; // invalidate current symbol
         	}    		
+        	// Trigger change event (on some versions of OOo this is automatic due to a bug)
+        	mathSymbolNameChange(dlg);
     	}
     	
     	private void updateSymbol(DialogAccess dlg) {
@@ -947,16 +950,19 @@ public final class ConfigurationDialog extends ConfigurationDialogBase implement
     	}
     	
     	private void newTextClick(DialogAccess dlg) {
-    		// This triggers an onchange event
         	appendItem(dlg, "TextInput", new HashSet<String>());
+        	// Trigger change event (on some versions of OOo this is automatic due to a bug)
+        	textInputChange(dlg);
     	}
     	
     	private void deleteTextClick(DialogAccess dlg) {
-    		String sText = sCurrentText; 
-    		// This triggers an onchange event
+    		String sText = sCurrentText;
     		if (deleteCurrentItem(dlg, "TextInput")) {
         		stringReplace.remove(sText);
+        		sCurrentText = null; // Invalidate current string replace
         	}
+        	// Trigger change event (on some versions of OOo this is automatic due to a bug)
+    		textInputChange(dlg);
     	}
     	
     	private void updateText(DialogAccess dlg) {
diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java
index 11b0c82..432fbc7 100644
--- a/source/java/writer2latex/api/ConverterFactory.java
+++ b/source/java/writer2latex/api/ConverterFactory.java
@@ -20,7 +20,7 @@
  *
  *  All Rights Reserved.
  * 
- *  Version 1.2 (2011-09-13)
+ *  Version 1.2 (2011-09-20)
  *
  */
  
@@ -33,7 +33,7 @@ public class ConverterFactory {
 
     // Version information
     private static final String VERSION = "1.1.9";
-    private static final String DATE = "2011-09-13";
+    private static final String DATE = "2011-09-20";
 	
     /** Return the Writer2LaTeX version in the form
      *  (major version).(minor version).(patch level)<br/>