From 04ed9dae7a45a706648fcf449639ea677f759eaf Mon Sep 17 00:00:00 2001 From: henrikjust Date: Mon, 23 Nov 2009 20:47:45 +0000 Subject: [PATCH] Config ui + Writer4LaTeX git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@41 f0f2a975-2e09-46c8-9428-3b39399b9f3c --- build.xml | 9 +- .../com/sun/star/lib/loader/win/unowinreg.dll | Bin 0 -> 6144 bytes .../com/sun/star/lib/loader/WinRegKey.java | 203 +++++++ .../star/lib/loader/WinRegKeyException.java | 54 ++ .../w2lcommon/helper/StyleNameProvider.java | 1 - .../comp/w2lcommon/tex/tokenizer/Mouth.java | 2 +- .../writer2latex/ConfigurationDialog.java | 536 ++++++++++++------ .../CustomSymbolNameProvider.java | 86 +++ .../writer4latex/ConfigurationDialog.java | 82 ++- .../da/comp/writer4latex/ExternalApps.java | 2 +- .../da/comp/writer4latex/TeXify.java | 24 +- .../da/comp/writer4latex/Writer4LaTeX.java | 22 +- .../java/writer2latex/api/ComplexOption.java | 11 +- .../writer2latex/api/ConverterFactory.java | 4 +- .../W2LDialogs2/ConfigurationRoot.xdl | 4 +- .../oxt/writer2latex/W2LDialogs2/Headings.xdl | 4 +- .../writer2latex/W2LDialogs2/LoadDefaults.xdl | 10 + .../oxt/writer2latex/W2LDialogs2/Styles.xdl | 33 +- .../oxt/writer2latex/W2LDialogs2/dialog.xlb | 1 + .../W4LDialogs/AutoConfigInfo.xdl | 8 + source/oxt/writer4latex/W4LDialogs/dialog.xlb | 1 + source/oxt/writer4latex/w4l_filters.xcu | 3 +- source/readme-source.txt | 25 +- 23 files changed, 886 insertions(+), 239 deletions(-) create mode 100644 source/dll/com/sun/star/lib/loader/win/unowinreg.dll create mode 100644 source/java/com/sun/star/lib/loader/WinRegKey.java create mode 100644 source/java/com/sun/star/lib/loader/WinRegKeyException.java create mode 100644 source/java/org/openoffice/da/comp/writer2latex/CustomSymbolNameProvider.java create mode 100644 source/oxt/writer2latex/W2LDialogs2/LoadDefaults.xdl create mode 100644 source/oxt/writer4latex/W4LDialogs/AutoConfigInfo.xdl diff --git a/build.xml b/build.xml index d5f9133..c3637f9 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,7 @@ ############################################################################ # This is the Ant build file for writer2latex # Original: Sep 2004 (mgn) - # version 1.2 (2009-03-30) + # version 1.2 (2009-11-23) ############################################################################ --> @@ -46,6 +46,7 @@ + @@ -196,8 +197,14 @@ + + + + + + diff --git a/source/dll/com/sun/star/lib/loader/win/unowinreg.dll b/source/dll/com/sun/star/lib/loader/win/unowinreg.dll new file mode 100644 index 0000000000000000000000000000000000000000..f2ecf02ad220b79850ec4182575ec926b75f6f96 GIT binary patch literal 6144 zcmeHLU1$_n6h0f*{Me}5YHZpDoY(|{+GX|!O+;{GvenqcO|qI4O}b7tlij78nJ}~4 zs7PsP72{Hf4=rf>AjOBa52b~+NU4w}P+O>_lu~Sck)rq_GzA|51*hM+`;*PO4Z2kj z$%V7$o}c^8Ip?04xjS74CTSTF*+G^?bOD@)Py8%U$_UsPSLzhLXUT)!_G zGo>*@j~L3R6jn4%Pe?Ema=Ih~~s2QHmH zA>@mv-vodE`{vVc3%(=6of+Pg;V%f@8w*DnBO7tIpQzKeoMzVF?8xe_QCa;Hwko1> z4m_=$bbvESLUxFG8PRef&T~2h1&XxwC*pcxhDF)6%rThFN<=rXejj)fWG>`kE^y)K zCTfOGl8EXGZHvk9U%QCinNSZWV1J!Almp^id7d{UqC-w&SV<^E8`uVg@LK_%H++cR znRcTstd~K^P2jSe89t&Zr(qgl$RbxL#5JD+&l^6*Gt{^aN2H(rVZ3!L%nu*Y&UtBR z_Ao1OVY@_*nf<9-R4M)E!2KgRC}$cb~az@VBG37G~YXe)75F{ ze1jun@J#vA=AK|*Dp{E-@Aq5{T1m&rL95T2WZcwTfAkr&VK5j)VcxK6s*%C*sigfo zzhz662m9d-R|Y)gw?eNR{NdgKao0asK-+@`L;)UbgeX&~fVJsO;da3m)urZA<(WO| zPVW$J#e~1IaEqX>g(Ei<_6v=H#RWT7%N@e|?!Ic(;Q7QGTy|&X)Xc%bX$RZhx>dcP zLH;`yphyTp#KzqUxnaVe7ps+=oABR87@~Eo8vBBNS|nHz{2bsBJU6zG0n|{CjFb+z zu2{g_(TFI&c=-Wm%nJgBy$J#5iVb=5gnu?CzteTSr`t--PWW+CBb+%nRQ3mhU=FLM zazS>SGVcZ7ErolLpI*+Mm!7cCBAER3xa8)7^qc5MtC4R~tC4roYUBc2jU33se6lTJ z-%AC~NkpH5ra_aSVk3KoLaWjq(3R&wD>0GDQ4OjE)qx~X6X=)(TW0(wVZu~o6ub6; zvR*Y37*n;E)Fb}Gt+bKlwzzJpP*8-Wo}_9V=~LoKl^saQ={mF#9bVA2w)eGmcX-^+ z;duP+3up5=R!?MunU6h8wUB+FD2RLW49+j_f!_o*KS{I+@&x!Fppi91UqU_w-!q_J zLF+aU9RPg*x&nF*b?OJb2jVN0;UQti$+Da(sFJEEsp;b}%}^sE%w1}tPc_V#u5li; zM|n*Nh4s;pnbbmNLNP+|*ib00E5oW0>W^tC1ab|f0Ya|)D&7B5E_hp9F-_I%)%8RP z7Z(Ug!%($Eo34$-BL5F#zo{A}B8bK*ac!p_R^nYsI2zN`5+OKpvxK#xt1}&3>hjD@ z!QIvyY!7yCINty6=XJZ!CN9};-}rO24f?>gfj}VOamfQXuMg3!y`36x8Br;lHW0pi5Y> zG#w24<5+*Ph`tKn8P4U9vJ)Gz{D%f89x+9+pA6jkMEzhp_VJ z54)&EMilH5c-erLAcJD0Q3Pl)ijxXtjYdd^*9qYxlNX1ptspOA;E49p(^%UEpHb9Z zf&UTc6iBMT4pI_2iMoIo2EI-vJWO0mg^x*_VdJZW$tnCd;v8bjUB3@r2E1ZerwO|U zelm&20;;(Rz5x++L`1G2>TK*zh-gsD*ylh literal 0 HcmV?d00001 diff --git a/source/java/com/sun/star/lib/loader/WinRegKey.java b/source/java/com/sun/star/lib/loader/WinRegKey.java new file mode 100644 index 0000000..0d49f38 --- /dev/null +++ b/source/java/com/sun/star/lib/loader/WinRegKey.java @@ -0,0 +1,203 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: WinRegKey.java,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.lib.loader; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; + + +/** + * This class provides functionality for reading string values from the + * Windows Registry. It requires the native library unowinreg.dll. + */ +final class WinRegKey { + + private String m_rootKeyName; + private String m_subKeyName; + + // native methods to access the windows registry + private static native boolean winreg_RegOpenClassesRoot( long[] hkresult ); + private static native boolean winreg_RegOpenCurrentConfig( + long[] hkresult ); + private static native boolean winreg_RegOpenCurrentUser( long[] hkresult ); + private static native boolean winreg_RegOpenLocalMachine( long[] hkresult ); + private static native boolean winreg_RegOpenUsers( long[] hkresult ); + private static native boolean winreg_RegOpenKeyEx( long parent, String name, + long[] hkresult ); + private static native boolean winreg_RegCloseKey( long hkey ); + private static native boolean winreg_RegQueryValueEx( + long hkey, String value, long[] type, + byte[] data, long[] size ); + private static native boolean winreg_RegQueryInfoKey( + long hkey, long[] subkeys, long[] maxSubkeyLen, + long[] values, long[] maxValueNameLen, + long[] maxValueLen, long[] secDescriptor ); + + // load the native library unowinreg.dll + static { + try { + ClassLoader cl = WinRegKey.class.getClassLoader(); + InputStream is = cl.getResourceAsStream( "win/unowinreg.dll" ); + if ( is != null ) { + // generate a temporary name for lib file and write to temp + // location + BufferedInputStream istream = new BufferedInputStream( is ); + File libfile = File.createTempFile( "unowinreg", ".dll" ); + libfile.deleteOnExit(); // ensure deletion + BufferedOutputStream ostream = new BufferedOutputStream( + new FileOutputStream( libfile ) ); + int bsize = 2048; int n = 0; + byte[] buffer = new byte[bsize]; + while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) { + ostream.write( buffer, 0, n ); + } + istream.close(); + ostream.close(); + // load library + System.load( libfile.getPath() ); + } else { + // If the library cannot be found as a class loader resource, + // try the global System.loadLibrary(). The JVM will look for + // it in the java.library.path. + System.loadLibrary( "unowinreg" ); + } + } catch ( java.lang.Exception e ) { + System.err.println( "com.sun.star.lib.loader.WinRegKey: " + + "loading of native library failed!" + e ); + } + } + + /** + * Constructs a WinRegKey. + */ + public WinRegKey( String rootKeyName, String subKeyName ) { + m_rootKeyName = rootKeyName; + m_subKeyName = subKeyName; + } + + /** + * Reads a string value for the specified value name. + */ + public String getStringValue( String valueName ) throws WinRegKeyException { + byte[] data = getValue( valueName ); + // remove terminating null character + return new String( data, 0, data.length - 1 ); + } + + /** + * Reads a value for the specified value name. + */ + private byte[] getValue( String valueName ) throws WinRegKeyException { + + byte[] result = null; + long[] hkey = {0}; + + // open the specified registry key + boolean bRet = false; + long[] hroot = {0}; + if ( m_rootKeyName.equals( "HKEY_CLASSES_ROOT" ) ) { + bRet = winreg_RegOpenClassesRoot( hroot ); + } else if ( m_rootKeyName.equals( "HKEY_CURRENT_CONFIG" ) ) { + bRet = winreg_RegOpenCurrentConfig( hroot ); + } else if ( m_rootKeyName.equals( "HKEY_CURRENT_USER" ) ) { + bRet = winreg_RegOpenCurrentUser( hroot ); + } else if ( m_rootKeyName.equals( "HKEY_LOCAL_MACHINE" ) ) { + bRet = winreg_RegOpenLocalMachine( hroot ); + } else if ( m_rootKeyName.equals( "HKEY_USERS" ) ) { + bRet = winreg_RegOpenUsers( hroot ); + } else { + throw new WinRegKeyException( "unknown root registry key!"); + } + if ( !bRet ) { + throw new WinRegKeyException( "opening root registry key " + + "failed!" ); + } + if ( !winreg_RegOpenKeyEx( hroot[0], m_subKeyName, hkey ) ) { + if ( !winreg_RegCloseKey( hroot[0] ) ) { + throw new WinRegKeyException( "opening registry key and " + + "releasing root registry key handle failed!" ); + } + throw new WinRegKeyException( "opening registry key failed!" ); + } + + // get the size of the longest data component among the key's values + long[] subkeys = {0}; + long[] maxSubkeyLen = {0}; + long[] values = {0}; + long[] maxValueNameLen = {0}; + long[] maxValueLen = {0}; + long[] secDescriptor = {0}; + if ( !winreg_RegQueryInfoKey( hkey[0], subkeys, maxSubkeyLen, + values, maxValueNameLen, maxValueLen, secDescriptor ) ) { + if ( !winreg_RegCloseKey( hkey[0] ) || + !winreg_RegCloseKey( hroot[0] ) ) { + throw new WinRegKeyException( "retrieving information about " + + "the registry key and releasing registry key handles " + + "failed!" ); + } + throw new WinRegKeyException( "retrieving information about " + + "the registry key failed!" ); + } + + // get the data for the specified value name + byte[] buffer = new byte[ (int) maxValueLen[0] ]; + long[] size = new long[1]; + size[0] = buffer.length; + long[] type = new long[1]; + type[0] = 0; + if ( !winreg_RegQueryValueEx( hkey[0], valueName, type, buffer, + size ) ) { + if ( !winreg_RegCloseKey( hkey[0] ) || + !winreg_RegCloseKey( hroot[0] ) ) { + throw new WinRegKeyException( "retrieving data for the " + + "specified value name and releasing registry key handles " + + "failed!" ); + } + throw new WinRegKeyException( "retrieving data for the " + + "specified value name failed!" ); + } + + // release registry key handles + if ( !winreg_RegCloseKey( hkey[0] ) || + !winreg_RegCloseKey( hroot[0] ) ) { + throw new WinRegKeyException( "releasing registry key handles " + + "failed!" ); + } + + result = new byte[ (int) size[0] ]; + System.arraycopy( buffer, 0, result, 0, (int)size[0] ); + + return result; + } +} \ No newline at end of file diff --git a/source/java/com/sun/star/lib/loader/WinRegKeyException.java b/source/java/com/sun/star/lib/loader/WinRegKeyException.java new file mode 100644 index 0000000..4f80b09 --- /dev/null +++ b/source/java/com/sun/star/lib/loader/WinRegKeyException.java @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: WinRegKeyException.java,v $ + * $Revision: 1.4 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.lib.loader; + +/** + * WinRegKeyException is a checked exception. + */ +final class WinRegKeyException extends java.lang.Exception { + + /** + * Constructs a WinRegKeyException. + */ + public WinRegKeyException() { + super(); + } + + /** + * Constructs a WinRegKeyException with the specified + * detail message. + * + * @param message the detail message + */ + public WinRegKeyException( String message ) { + super( message ); + } +} \ No newline at end of file diff --git a/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java b/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java index 32689e5..232a38e 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java @@ -29,7 +29,6 @@ package org.openoffice.da.comp.w2lcommon.helper; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Set; import com.sun.star.beans.UnknownPropertyException; import com.sun.star.beans.XPropertySet; diff --git a/source/java/org/openoffice/da/comp/w2lcommon/tex/tokenizer/Mouth.java b/source/java/org/openoffice/da/comp/w2lcommon/tex/tokenizer/Mouth.java index c427400..584de2f 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/tex/tokenizer/Mouth.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/tex/tokenizer/Mouth.java @@ -73,7 +73,7 @@ public class Mouth { } private class Eyes { - private BufferedReader br; // The inpuy + private BufferedReader br; // The input private String sLine; // The current line private int nLen; // The length of the current line private int nIndex; // The current index in the current line diff --git a/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java b/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java index 1bd4398..d54463e 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java +++ b/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2009-11-08) + * Version 1.2 (2009-11-19) * */ @@ -88,13 +88,13 @@ public final class ConfigurationDialog extends WeakBase short nCurrentFamily = -1; String sCurrentStyleName = null; short nCurrentAttribute = -1; - short nCurrentMaxLevel = -1; short nCurrentWriterLevel = 0; String sCurrentMathSymbol = null; String sCurrentText = null; private String sTitle = null; private DialogAccess dlg = null; private StyleNameProvider styleNameProvider = null; + private CustomSymbolNameProvider customSymbolNameProvider = null; /** The component will be registered under this name. */ @@ -143,6 +143,7 @@ public final class ConfigurationDialog extends WeakBase stringReplace = new ComplexOption(); styleNameProvider = new StyleNameProvider(xContext); + customSymbolNameProvider = new CustomSymbolNameProvider(xContext); } // Implement XContainerWindowEventHandler @@ -163,12 +164,10 @@ public final class ConfigurationDialog extends WeakBase } // Headings page else if (sMethod.equals("MaxLevelChange")) { - saveHeadings(); updateHeadingsControls(); return true; } else if (sMethod.equals("WriterLevelChange")) { - saveHeadings(); updateHeadingsControls(); return true; } @@ -178,39 +177,31 @@ public final class ConfigurationDialog extends WeakBase } // Styles page else if (sMethod.equals("StyleFamilyChange")) { - saveStyles(); updateStylesControls(); return true; } else if (sMethod.equals("StyleNameChange")) { - saveStyles(); updateStylesControls(); return true; } else if (sMethod.equals("NewStyleClick")) { - if (nCurrentFamily>-1) { - String sNewName = appendItem("StyleName",styleNameProvider.getInternalNames(sOOoFamilyNames[nCurrentFamily]).keySet()); - if (sNewName!=null) { - Map attr = new HashMap(); - attr.put("before", ""); - attr.put("after", ""); - attr.put("after", ""); - attr.put("verbatim", ""); - attr.put("line-break",""); - styleMap[nCurrentFamily].put(sNewName, attr); - } - saveStyles(); - updateStylesControls(); - } + newStyleClick(); return true; } else if (sMethod.equals("DeleteStyleClick")) { - if (nCurrentFamily>-1 && sCurrentStyleName!=null) { - if (deleteCurrentItem("StyleName")) { - styleMap[nCurrentFamily].remove(sCurrentStyleName); - updateStylesControls(); - } - } + deleteStyleClick(); + return true; + } + else if (sMethod.equals("AddNextClick")) { + addNextClick(); + return true; + } + else if (sMethod.equals("RemoveNextClick")) { + removeNextClick(); + return true; + } + else if (sMethod.equals("LoadDefaultsClick")) { + loadDefaultsClick(); return true; } // Characters page @@ -219,7 +210,6 @@ public final class ConfigurationDialog extends WeakBase return true; } else if (sMethod.equals("FormattingAttributeChange")) { - saveCharacters(); updateCharactersControls(); return true; } @@ -257,50 +247,27 @@ public final class ConfigurationDialog extends WeakBase } // Text and math page else if (sMethod.equals("MathSymbolNameChange")) { - saveTextAndMath(); updateTextAndMathControls(); return true; } else if (sMethod.equals("NewSymbolClick")) { - String sNewName = appendItem("MathSymbolName",new HashSet()); - if (sNewName!=null) { - Map attr = new HashMap(); - attr.put("latex", ""); - mathSymbols.put(sNewName, attr); - } - saveTextAndMath(); - updateTextAndMathControls(); + newSymbolClick(); return true; } else if (sMethod.equals("DeleteSymbolClick")) { - if (deleteCurrentItem("MathSymbolName")) { - mathSymbols.remove(sCurrentMathSymbol); - updateTextAndMathControls(); - } + deleteSymbolClick(); return true; } else if (sMethod.equals("TextInputChange")) { - saveTextAndMath(); updateTextAndMathControls(); return true; } else if (sMethod.equals("NewTextClick")) { - String sNewName = appendItem("TextInput", new HashSet()); - if (sNewName!=null) { - Map attr = new HashMap(); - attr.put("latex-code", ""); - attr.put("fontenc", "any"); - stringReplace.put(sNewName, attr); - } - saveTextAndMath(); - updateTextAndMathControls(); + newTextClick(); return true; } else if (sMethod.equals("DeleteTextClick")) { - if (deleteCurrentItem("TextInput")) { - stringReplace.remove(sCurrentText); - updateTextAndMathControls(); - } + deleteTextClick(); return true; } } @@ -317,7 +284,7 @@ public final class ConfigurationDialog extends WeakBase String[] sNames = { "external_event", "NoPreambleChange", // Documentclass "MaxLevelChange", "WriterLevelChange", "NoIndexChange", // Headings - "StyleFamilyChange", "StyleNameChange", "NewStyleClick", "DeleteStyleClick", // Styles + "StyleFamilyChange", "StyleNameChange", "NewStyleClick", "DeleteStyleClick", "AddNextClick", "RemoveNextClick", "LoadDefaultsClick", // Styles "UseSoulChange", "FormattingAttributeChange", "CustomAttributeChange", // Characters "ExportGeometryChange", "ExportHeaderAndFooterChange", // Pages "NoTablesChange", "UseSupertabularChange", "UseLongtableChange", // Tables @@ -342,7 +309,7 @@ public final class ConfigurationDialog extends WeakBase return sSupportedServiceNames; } - // Private stuff + // Private stuff private boolean handleExternalEvent(Object aEventObject) throws com.sun.star.uno.Exception { try { @@ -350,55 +317,11 @@ public final class ConfigurationDialog extends WeakBase if (sMethod.equals("ok")) { loadConfig(); getControls(); - for (int i=0; i<5; i++) { - ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map"); - configMap.clear(); - Map internalNames = styleNameProvider.getInternalNames(sOOoFamilyNames[i]); - for (String sDisplayName : styleMap[i].keySet()) { - String sName = sDisplayName; - if (internalNames!=null && internalNames.containsKey(sDisplayName)) { - sName = internalNames.get(sDisplayName); - } - configMap.copy(sName, styleMap[i].get(sDisplayName)); - } - } - config.getComplexOption("text-attribute-map").clear(); - config.getComplexOption("text-attribute-map").copyAll(attributeMap); - if (nCurrentMaxLevel>-1) { - for (int i=nCurrentMaxLevel+1; i<11; i++) { - headingMap.remove(Integer.toString(i)); - } - } - config.getComplexOption("heading-map").clear(); - config.getComplexOption("heading-map").copyAll(headingMap); - config.getComplexOption("math-symbol-map").clear(); - config.getComplexOption("math-symbol-map").copyAll(mathSymbols); - config.getComplexOption("string-replace").clear(); - config.getComplexOption("string-replace").copyAll(stringReplace); saveConfig(); return true; - } else if (sMethod.equals("back") || sMethod.equals("initialize")) { + } + else if (sMethod.equals("back") || sMethod.equals("initialize")) { loadConfig(); - for (int i=0; i<5; i++) { - ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map"); - styleMap[i].clear(); - Map displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]); - for (String sName : configMap.keySet()) { - String sDisplayName = sName; - if (displayNames!=null && displayNames.containsKey(sName)) { - sDisplayName = displayNames.get(sName); - } - styleMap[i].copy(sDisplayName, configMap.get(sName)); - } - } - attributeMap.clear(); - attributeMap.copyAll(config.getComplexOption("text-attribute-map")); - headingMap.clear(); - headingMap.copyAll(config.getComplexOption("heading-map")); - mathSymbols.clear(); - mathSymbols.copyAll(config.getComplexOption("math-symbol-map")); - stringReplace.clear(); - stringReplace.copyAll(config.getComplexOption("string-replace")); setControls(); return true; } @@ -657,13 +580,17 @@ public final class ConfigurationDialog extends WeakBase // This page handles the heading map as well as the options no_index, use_titlesec and use_titletoc private void loadHeadings() { + // Load heading map from config + headingMap.clear(); + headingMap.copyAll(config.getComplexOption("heading-map")); + nCurrentWriterLevel = -1; + // Determine the max level (from 0 to 10) - Set writerLevels = headingMap.keySet(); - nCurrentMaxLevel = 0; - while(nCurrentMaxLevel<10 && writerLevels.contains(Integer.toString(nCurrentMaxLevel+1))) { - nCurrentMaxLevel++; + short nMaxLevel = 0; + while(nMaxLevel<10 && headingMap.containsKey(Integer.toString(nMaxLevel+1))) { + nMaxLevel++; } - dlg.setListBoxSelectedItem("MaxLevel", nCurrentMaxLevel); + dlg.setListBoxSelectedItem("MaxLevel", nMaxLevel); dlg.setCheckBoxStateAsBoolean("UseTitlesec","true".equals(config.getOption("use_titlesec"))); dlg.setCheckBoxStateAsBoolean("NoIndex","true".equals(config.getOption("no_index"))); @@ -673,6 +600,23 @@ public final class ConfigurationDialog extends WeakBase } private void saveHeadings() { + updateHeadingMap(); + + // Save heading map to config + config.getComplexOption("heading-map").clear(); + int nMaxLevel = dlg.getListBoxSelectedItem("MaxLevel"); + for (int i=1; i<=nMaxLevel; i++) { + String sLevel = Integer.toString(i); + config.getComplexOption("heading-map").copy(sLevel,headingMap.get(sLevel)); + } + + // Save other controls to config + config.setOption("use_titlesec", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTitlesec"))); + config.setOption("no_index", Boolean.toString(dlg.getCheckBoxStateAsBoolean("NoIndex"))); + config.setOption("use_titletoc", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTitletoc"))); + } + + private void updateHeadingMap() { // Save the current writer level in our cache if (nCurrentWriterLevel>-1) { Map attr = new HashMap(); @@ -680,32 +624,30 @@ public final class ConfigurationDialog extends WeakBase attr.put("level", dlg.getComboBoxText("LaTeXLevel")); headingMap.put(Integer.toString(nCurrentWriterLevel+1), attr); } - - config.setOption("use_titlesec", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTitlesec"))); - config.setOption("no_index", Boolean.toString(dlg.getCheckBoxStateAsBoolean("NoIndex"))); - config.setOption("use_titletoc", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseTitletoc"))); } private void updateHeadingsControls() { + updateHeadingMap(); + // Adjust the presented writer levels to the max level - nCurrentMaxLevel = dlg.getListBoxSelectedItem("MaxLevel"); + int nMaxLevel = dlg.getListBoxSelectedItem("MaxLevel"); nCurrentWriterLevel = dlg.getListBoxSelectedItem("WriterLevel"); - String[] sWriterLevels = new String[nCurrentMaxLevel]; - for (int i=0; inCurrentMaxLevel) { nCurrentWriterLevel = (short)(nCurrentMaxLevel-1); } - else if (nCurrentWriterLevel<0 && nCurrentMaxLevel>0) { nCurrentWriterLevel=0; } + if (nCurrentWriterLevel+1>nMaxLevel) { nCurrentWriterLevel = (short)(nMaxLevel-1); } + else if (nCurrentWriterLevel<0 && nMaxLevel>0) { nCurrentWriterLevel=0; } dlg.setListBoxSelectedItem("WriterLevel", nCurrentWriterLevel); // Load the values for the current level if (nCurrentWriterLevel>-1) { String sLevel = Integer.toString(nCurrentWriterLevel+1); - if (headingMap.keySet().contains(sLevel)) { + if (headingMap.containsKey(sLevel)) { Map attr = headingMap.get(sLevel); - dlg.setComboBoxText("LaTeXLevel", attr.get("level")); - dlg.setComboBoxText("LaTeXName", attr.get("name")); + dlg.setComboBoxText("LaTeXLevel", attr.containsKey("level") ? attr.get("level") : ""); + dlg.setComboBoxText("LaTeXName", attr.containsKey("name") ? attr.get("name") : ""); } else { dlg.setListBoxSelectedItem("LaTeXLevel", (short)2); @@ -728,14 +670,36 @@ public final class ConfigurationDialog extends WeakBase dlg.setControlEnabled("UseTitletoc", false); //boolean bNoIndex = dlg.getCheckBoxStateAsBoolean("NoIndex"); //dlg.setControlEnabled("UseTitletoc", !bNoIndex); - } // The page "Styles" // This page handles the various style maps as well as the options other_styles and formatting + // Limitation: Cannot handle the values "error" and "warning" for other_styles private void loadStyles() { - String sFormatting = config.getOption("formatting"); + // Display paragraph maps first + dlg.setListBoxSelectedItem("StyleFamily", (short)1); + nCurrentFamily = -1; + sCurrentStyleName = null; + + // Load style maps from config (translating keys to display names) + for (int i=0; i<5; i++) { + ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map"); + styleMap[i].clear(); + Map displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]); + copyStyles(configMap, styleMap[i], displayNames); + } + + // Load other controls from config + String sOtherStyles = config.getOption("other_styles"); + if ("accept".equals(sOtherStyles)) { + dlg.setListBoxSelectedItem("OtherStyles", (short)1); + } + else { + dlg.setListBoxSelectedItem("OtherStyles", (short)0); + } + + String sFormatting = config.getOption("formatting"); if ("ignore_all".equals(sFormatting)) { dlg.setListBoxSelectedItem("Formatting", (short)0); } @@ -756,13 +720,46 @@ public final class ConfigurationDialog extends WeakBase } private void saveStyles() { + updateStyleMaps(); + + // Save style maps to config (translating keys back to internal names) + for (int i=0; i<5; i++) { + ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map"); + configMap.clear(); + Map internalNames = styleNameProvider.getInternalNames(sOOoFamilyNames[i]); + copyStyles(styleMap[i], configMap, internalNames); + } + + // Save other controls to config + switch (dlg.getListBoxSelectedItem("OtherStyles")) { + case 0: config.setOption("other_styles", "ignore"); break; + case 1: config.setOption("other_styles", "accept"); + } + + switch (dlg.getListBoxSelectedItem("Formatting")) { + case 0: config.setOption("formatting", "ignore_all"); break; + case 1: config.setOption("formatting", "ignore_most"); break; + case 2: config.setOption("formatting", "convert_basic"); break; + case 3: config.setOption("formatting", "convert_most"); break; + case 4: config.setOption("formatting", "convert_all"); + } + } + + private void updateStyleMaps() { // Save the current style map, if any if (nCurrentFamily>-1 && sCurrentStyleName!=null) { Map attr=new HashMap(); attr.put("before", dlg.getTextFieldText("Before")); attr.put("after", dlg.getTextFieldText("After")); if (dlg.getControlEnabled("Next")) { - attr.put("next", dlg.getTextFieldText("Next")); + String[] sNextItems = dlg.getListBoxStringItemList("Next"); + int nCount = sNextItems.length; + String sList = ""; + for (int i=0; i0) sList+=";"; + sList+=sNextItems[i]; + } + attr.put("next", sList); } if (dlg.getControlEnabled("LineBreak")) { attr.put("line-break", Boolean.toString(dlg.getCheckBoxStateAsBoolean("LineBreak"))); @@ -772,18 +769,11 @@ public final class ConfigurationDialog extends WeakBase } styleMap[nCurrentFamily].put(sCurrentStyleName, attr); } - - switch (dlg.getListBoxSelectedItem("Formatting")) { - case 0: config.setOption("formatting", "ignore_all"); break; - case 1: config.setOption("formatting", "ignore_most"); break; - case 2: config.setOption("formatting", "convert_basic"); break; - case 3: config.setOption("formatting", "convert_most"); break; - case 4: config.setOption("formatting", "convert_all"); - } - } private void updateStylesControls() { + updateStyleMaps(); + short nNewFamily = dlg.getListBoxSelectedItem("StyleFamily"); if (nNewFamily>-1 && nNewFamily!=nCurrentFamily) { // The user has changed the family; load and display the corresponding style names @@ -798,6 +788,8 @@ public final class ConfigurationDialog extends WeakBase dlg.setListBoxSelectedItem("StyleName", (short)Math.min(sStyleNames.length-1, 0)); dlg.setControlEnabled("NextLabel", nNewFamily==2); dlg.setControlEnabled("Next", nNewFamily==2); + dlg.setControlEnabled("AddNextButton", nNewFamily==2); + dlg.setControlEnabled("RemoveNextButton", nNewFamily==2); dlg.setControlEnabled("Verbatim", nNewFamily<2); dlg.setControlEnabled("LineBreak", nNewFamily==1); nCurrentFamily = nNewFamily; @@ -810,17 +802,27 @@ public final class ConfigurationDialog extends WeakBase Map attr = styleMap[nCurrentFamily].get(sCurrentStyleName); dlg.setTextFieldText("Before", attr.containsKey("before") ? attr.get("before") : ""); - dlg.setTextFieldText("After", attr.containsKey("after") ? attr.get("before") : ""); - dlg.setTextFieldText("Next", attr.containsKey("next") ? attr.get("next") : ""); - dlg.setTextFieldText("Verbatim", attr.containsKey("verbatim") ? attr.get("verbatim") : ""); - dlg.setTextFieldText("LineBreak", attr.containsKey("line-break") ? attr.get("line-break") : ""); + dlg.setTextFieldText("After", attr.containsKey("after") ? attr.get("after") : ""); + String[] sNextItems; + if (attr.containsKey("next")) { + sNextItems = attr.get("next").split(";"); + } + else { + sNextItems = new String[0]; + } + dlg.setListBoxStringItemList("Next", sNextItems); + dlg.setListBoxSelectedItem("Next", (short)Math.min(sNextItems.length-1, 0)); + dlg.setCheckBoxStateAsBoolean("Verbatim", + attr.containsKey("verbatim") ? "true".equals(attr.get("verbatim")) : false); + dlg.setCheckBoxStateAsBoolean("LineBreak", + attr.containsKey("line-break") ? "true".equals(attr.get("line-break")) : false); dlg.setControlEnabled("DeleteStyleButton", true); } else { sCurrentStyleName = null; dlg.setTextFieldText("Before", ""); dlg.setTextFieldText("After", ""); - dlg.setTextFieldText("Next", ""); + dlg.setListBoxStringItemList("Next", new String[0]); dlg.setCheckBoxStateAsBoolean("Verbatim", false); dlg.setCheckBoxStateAsBoolean("LineBreak", false); dlg.setControlEnabled("DeleteStyleButton", false); @@ -828,11 +830,114 @@ public final class ConfigurationDialog extends WeakBase } } + private void newStyleClick() { + if (nCurrentFamily>-1) { + String sNewName = appendItem("StyleName",styleNameProvider.getInternalNames(sOOoFamilyNames[nCurrentFamily]).keySet()); + if (sNewName!=null) { + Map attr = new HashMap(); + attr.put("before", ""); + attr.put("after", ""); + attr.put("after", ""); + attr.put("verbatim", ""); + attr.put("line-break",""); + styleMap[nCurrentFamily].put(sNewName, attr); + } + saveStyles(); + updateStylesControls(); + } + } + + private void deleteStyleClick() { + if (nCurrentFamily>-1 && sCurrentStyleName!=null) { + if (deleteCurrentItem("StyleName")) { + styleMap[nCurrentFamily].remove(sCurrentStyleName); + sCurrentStyleName = null; + updateStylesControls(); + } + } + } + + private void addNextClick() { + appendItem("Next",styleNameProvider.getInternalNames(sOOoFamilyNames[nCurrentFamily]).keySet()); + saveStyles(); + updateStylesControls(); + } + + private void removeNextClick() { + deleteCurrentItem("Next"); + updateStylesControls(); + } + + private void loadDefaultsClick() { + saveStyles(); + // Force update of the ui + nCurrentFamily = -1; + sCurrentStyleName = null; + + // Count styles that we will overwrite + Config clean = ConverterFactory.createConverter("application/x-latex").getConfig(); + clean.readDefaultConfig("clean.xml"); + + int nCount = 0; + for (int i=0; i<5; i++) { + ComplexOption cleanMap = clean.getComplexOption(sFamilyNames[i]+"-map"); + Map displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]); + for (String sName : cleanMap.keySet()) { + String sDisplayName = (displayNames!=null && displayNames.containsKey(sName)) ? displayNames.get(sName) : ""; + if (styleMap[i].containsKey(sDisplayName)) { nCount++; } + } + } + + // Display confirmation dialog + boolean bConfirm = false; + XDialog xDialog=getDialog("W2LDialogs2.LoadDefaults"); + if (xDialog!=null) { + DialogAccess ldlg = new DialogAccess(xDialog); + if (nCount>0) { + String sLabel = ldlg.getLabelText("OverwriteLabel"); + sLabel = sLabel.replaceAll("%s", Integer.toString(nCount)); + ldlg.setLabelText("OverwriteLabel", sLabel); + } + else { + ldlg.setLabelText("OverwriteLabel", ""); + } + bConfirm = xDialog.execute()==ExecutableDialogResults.OK; + xDialog.endExecute(); + } + + // Do the replacement + if (bConfirm) { + for (int i=0; i<5; i++) { + ComplexOption cleanMap = clean.getComplexOption(sFamilyNames[i]+"-map"); + Map displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]); + copyStyles(cleanMap, styleMap[i], displayNames); + } + } + updateStylesControls(); + } + + private void copyStyles(ComplexOption source, ComplexOption target, Map nameTranslation) { + for (String sName : source.keySet()) { + String sNewName = sName; + if (nameTranslation!=null && nameTranslation.containsKey(sName)) { + sNewName = nameTranslation.get(sName); + } + target.copy(sNewName, source.get(sName)); + } + } + // The page "Characters" // This page handles the options use_color, use_soul, use_ulem and use_hyperref // In addition it handles style maps for formatting attributes private void loadCharacters() { + // Load attribute style map from config + attributeMap.clear(); + attributeMap.copyAll(config.getComplexOption("text-attribute-map")); + nCurrentAttribute = -1; + dlg.setListBoxSelectedItem("FormattingAttribute", (short)0); + + // Load other controls from config dlg.setCheckBoxStateAsBoolean("UseHyperref","true".equals(config.getOption("use_hyperref"))); dlg.setCheckBoxStateAsBoolean("UseColor","true".equals(config.getOption("use_color"))); dlg.setCheckBoxStateAsBoolean("UseSoul","true".equals(config.getOption("use_soul"))); @@ -842,35 +947,48 @@ public final class ConfigurationDialog extends WeakBase } private void saveCharacters() { - // Save the current attribute map, if any - if (nCurrentAttribute>-1) { - if (dlg.getCheckBoxStateAsBoolean("CustomAttribute")) { - HashMap attr = new HashMap(); - attr.put("before", dlg.getTextFieldText("Before")); - attr.put("after", dlg.getTextFieldText("After")); - attributeMap.put(sAttributeNames[nCurrentAttribute], attr); - } - else { - attributeMap.remove(sAttributeNames[nCurrentAttribute]); + updateCharactersMap(); + + // Save the attribute style map to config + config.getComplexOption("text-attribute-map").clear(); + for (String s : attributeMap.keySet()) { + if (!attributeMap.get(s).containsKey("deleted")) { + config.getComplexOption("text-attribute-map").copy(s, attributeMap.get(s)); } } - + + // Save other controls to config config.setOption("use_hyperref", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseHyperref"))); config.setOption("use_color", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseColor"))); config.setOption("use_soul", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseSoul"))); config.setOption("use_ulem", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseUlem"))); } + private void updateCharactersMap() { + // Save the current attribute map, if any + if (nCurrentAttribute>-1) { + HashMap attr = new HashMap(); + if (!dlg.getCheckBoxStateAsBoolean("CustomAttribute")) { + // don't delete the map now, but defer this to the dialog is closed + attr.put("deleted", "true"); + } + attr.put("before", dlg.getTextFieldText("Before")); + attr.put("after", dlg.getTextFieldText("After")); + attributeMap.put(sAttributeNames[nCurrentAttribute], attr); + } + } + private void updateCharactersControls() { + updateCharactersMap(); + short nNewAttribute = dlg.getListBoxSelectedItem("FormattingAttribute"); if (nNewAttribute>-1 && nCurrentAttribute!=nNewAttribute) { String sName = sAttributeNames[nNewAttribute]; - if (attributeMap.keySet().contains(sName)) { - dlg.setCheckBoxStateAsBoolean("CustomAttribute", true); - dlg.setTextFieldText("Before", - attributeMap.get(sName).containsKey("before") ? attributeMap.get(sName).get("before") : ""); - dlg.setTextFieldText("After", - attributeMap.get(sName).containsKey("after") ? attributeMap.get(sName).get("after") : ""); + if (attributeMap.containsKey(sName)) { + Map attr = attributeMap.get(sName); + dlg.setCheckBoxStateAsBoolean("CustomAttribute", !attr.containsKey("deleted")); + dlg.setTextFieldText("Before", attr.containsKey("before") ? attr.get("before") : ""); + dlg.setTextFieldText("After", attr.containsKey("after") ? attr.get("after") : ""); } else { dlg.setCheckBoxStateAsBoolean("CustomAttribute", false); @@ -1036,7 +1154,6 @@ public final class ConfigurationDialog extends WeakBase dlg.setControlEnabled("TableLastFootStyle", !bNoTables && (bSupertabular || bLongtable)); dlg.setControlEnabled("TableSequenceLabel", !bNoTables); dlg.setControlEnabled("TableSequenceName", !bNoTables); - } // The page "Figures" @@ -1075,45 +1192,53 @@ public final class ConfigurationDialog extends WeakBase // text replacements and math symbol definitions private void loadTextAndMath() { + // Get math symbols from config + if (mathSymbols!=null) { mathSymbols.clear(); } + else { mathSymbols = new ComplexOption(); } + mathSymbols.copyAll(config.getComplexOption("math-symbol-map")); + sCurrentMathSymbol = null; + dlg.setListBoxStringItemList("MathSymbolName", sortStringSet(mathSymbols.keySet())); + dlg.setListBoxSelectedItem("MathSymbolName", (short)Math.min(0,mathSymbols.keySet().size()-1)); + + // Get string replace from config + if (stringReplace!=null) { stringReplace.clear(); } + else { stringReplace = new ComplexOption(); } + stringReplace.copyAll(config.getComplexOption("string-replace")); + sCurrentText = null; + dlg.setListBoxStringItemList("TextInput", sortStringSet(stringReplace.keySet())); + dlg.setListBoxSelectedItem("TextInput", (short)Math.min(0,stringReplace.keySet().size()-1)); + + // Get other options from config dlg.setCheckBoxStateAsBoolean("UseOoomath","true".equals(config.getOption("use_ooomath"))); - - Set symbolnames = config.getComplexOption("math-symbol-map").keySet(); - String[] sSymbolNames = new String[symbolnames.size()]; - int i=0; - for (String s : symbolnames) { - sSymbolNames[i++] = s; - } - sortStringArray(sSymbolNames); - dlg.setListBoxStringItemList("MathSymbolName", sSymbolNames); - dlg.setListBoxSelectedItem("MathSymbolName", (short)0); - //sCurrentMathSymbol = symbolnames.size()>0 ? sSymbolNames[0] : null; - - Set names = config.getComplexOption("string-replace").keySet(); - String[] sNames = new String[names.size()]; - int j=0; - for (String s : names) { - sNames[j++] = s; - } - sortStringArray(sNames); - dlg.setListBoxStringItemList("TextInput", sNames); - dlg.setListBoxSelectedItem("TextInput", (short)0); - //sCurrentText = sNames[0]; - dlg.setTextFieldText("TabStopLaTeX", config.getOption("tabstop")); updateTextAndMathControls(); } private void saveTextAndMath() { - config.setOption("use_ooomath", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseOoomath"))); + updateTextAndMathMaps(); + // Save math symbols to config + config.getComplexOption("math-symbol-map").clear(); + config.getComplexOption("math-symbol-map").copyAll(mathSymbols); + + // Save string replace to config + config.getComplexOption("string-replace").clear(); + config.getComplexOption("string-replace").copyAll(stringReplace); + + // Save other options to config + config.setOption("use_ooomath", Boolean.toString(dlg.getCheckBoxStateAsBoolean("UseOoomath"))); + config.setOption("tabstop", dlg.getTextFieldText("TabStopLaTeX")); + } + + private void updateTextAndMathMaps() { // Save the current math symbol in our cache if (sCurrentMathSymbol!=null) { Map attr = new HashMap(); attr.put("latex", dlg.getTextFieldText("MathLaTeX")); mathSymbols.put(sCurrentMathSymbol, attr); } - + // Save the current string replace in our cache if (sCurrentText!=null) { Map attr = new HashMap(); @@ -1121,11 +1246,11 @@ public final class ConfigurationDialog extends WeakBase attr.put("fontenc", "any"); stringReplace.put(sCurrentText, attr); } - - config.setOption("tabstop", dlg.getTextFieldText("TabStopLaTeX")); } private void updateTextAndMathControls() { + updateTextAndMathMaps(); + // Get the current math symbol, if any short nSymbolItem = dlg.getListBoxSelectedItem("MathSymbolName"); if (nSymbolItem>=0) { @@ -1163,7 +1288,56 @@ public final class ConfigurationDialog extends WeakBase } + private void newSymbolClick() { + String sNewName = appendItem("MathSymbolName",customSymbolNameProvider.getNames()); + if (sNewName!=null) { + Map attr = new HashMap(); + attr.put("latex", ""); + mathSymbols.put(sNewName, attr); + } + saveTextAndMath(); + updateTextAndMathControls(); + } + + private void deleteSymbolClick() { + if (deleteCurrentItem("MathSymbolName")) { + mathSymbols.remove(sCurrentMathSymbol); + sCurrentMathSymbol = null; + updateTextAndMathControls(); + } + } + + private void newTextClick() { + String sNewName = appendItem("TextInput", new HashSet()); + if (sNewName!=null) { + Map attr = new HashMap(); + attr.put("latex-code", ""); + attr.put("fontenc", "any"); + stringReplace.put(sNewName, attr); + } + saveTextAndMath(); + updateTextAndMathControls(); + } + + private void deleteTextClick() { + if (deleteCurrentItem("TextInput")) { + stringReplace.remove(sCurrentText); + sCurrentText = null; + updateTextAndMathControls(); + } + } + // Utilities + private String[] sortStringSet(Set theSet) { + String[] theArray = new String[theSet.size()]; + int i=0; + for (String s : theSet) { + theArray[i++] = s; + } + sortStringArray(theArray); + return theArray; + } + private void sortStringArray(String[] theArray) { // TODO: Get locale from OOo rather than the system Collator collator = Collator.getInstance(); diff --git a/source/java/org/openoffice/da/comp/writer2latex/CustomSymbolNameProvider.java b/source/java/org/openoffice/da/comp/writer2latex/CustomSymbolNameProvider.java new file mode 100644 index 0000000..342a036 --- /dev/null +++ b/source/java/org/openoffice/da/comp/writer2latex/CustomSymbolNameProvider.java @@ -0,0 +1,86 @@ +/** + * CustomSymbolNameProvider.java + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * Copyright: 2002-2009 by Henrik Just + * + * All Rights Reserved. + * + * Version 1.2 (2009-11-09) + * + */ +package org.openoffice.da.comp.writer2latex; + +import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper; +import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** This class provides access to the names of all user defined symbols in math + * + */ +public class CustomSymbolNameProvider { + Set names; + + /** Construct a new CustomSymbolNameProvider + * + * @param xContext the component context providing access to the api + */ + public CustomSymbolNameProvider(XComponentContext xContext) { + names = new HashSet(); + + RegistryHelper registry = new RegistryHelper(xContext); + try { + // Prepare registry view + Object view = registry.getRegistryView("/org.openoffice.Office.Math/",false); + XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view); + + // Get the list of symbols + Object symbols = XPropertySetHelper.getPropertyValue(xProps,"SymbolList"); + XNameAccess xSymbols = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,symbols); + String[] sNames = xSymbols.getElementNames(); + int nCount = sNames.length; + for (int i=0; i getNames() { + return Collections.unmodifiableSet(names); + } + +} diff --git a/source/java/org/openoffice/da/comp/writer4latex/ConfigurationDialog.java b/source/java/org/openoffice/da/comp/writer4latex/ConfigurationDialog.java index 190c21d..9df5d3e 100644 --- a/source/java/org/openoffice/da/comp/writer4latex/ConfigurationDialog.java +++ b/source/java/org/openoffice/da/comp/writer4latex/ConfigurationDialog.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2009-06-19) + * Version 1.2 (2009-11-19) * */ @@ -35,9 +35,12 @@ import com.sun.star.awt.XControl; import com.sun.star.awt.XControlContainer; import com.sun.star.awt.XControlModel; import com.sun.star.awt.XContainerWindowEventHandler; +import com.sun.star.awt.XDialog; +import com.sun.star.awt.XDialogProvider2; import com.sun.star.awt.XWindow; import com.sun.star.beans.XPropertySet; import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XServiceInfo; import com.sun.star.ui.dialogs.ExecutableDialogResults; import com.sun.star.ui.dialogs.XExecutableDialog; @@ -48,6 +51,8 @@ import com.sun.star.uno.XComponentContext; import com.sun.star.lib.uno.helper.WeakBase; +import org.openoffice.da.comp.w2lcommon.helper.DialogAccess; + /** This class provides a uno component which implements the configuration * of Writer4LaTeX */ @@ -247,12 +252,30 @@ public final class ConfigurationDialog } } + // Unix: Configure a certain application, reporting the availability + private boolean configureApp(String sName, String sAppName, String sArguments, StringBuffer info) { + if (hasApp(sAppName)) { + externalApps.setApplication(sName, sAppName, sArguments); + info.append("Found "+sAppName+" - OK\n"); + return true; + } + else { + externalApps.setApplication(sName, "???", "???"); + info.append("Failed to find "+sAppName+"\n"); + return false; + } + } + // Unix: Configure a certain application testing the availability // This variant uses an array of potential apps - private boolean configureApp(String sName, String[] sAppNames, String sArguments) { + private boolean configureApp(String sName, String[] sAppNames, String sArguments, StringBuffer info) { for (String sAppName : sAppNames) { - if (configureApp(sName, sAppName, sArguments)) { return true; } + if (configureApp(sName, sAppName, sArguments)) { + info.append("Found "+sName+": "+sAppName+" - OK\n"); + return true; + } } + info.append("Failed to find "+sName+"\n"); return false; } @@ -273,23 +296,28 @@ public final class ConfigurationDialog // And assume gsview for pdf and ps // gsview32 may not be in the path, but at least this helps a bit externalApps.setApplication(ExternalApps.PDFVIEWER, "gsview32.exe", "-e \"%s\""); - externalApps.setApplication(ExternalApps.POSTSCRIPTVIEWER, "gsview32.exe", "-e \"%s\""); + externalApps.setApplication(ExternalApps.POSTSCRIPTVIEWER, "gsview32.exe", "-e \"%s\""); + displayAutoConfigInfo("Configured for MikTeX..."); } else { // Assume a unix-like system supporting the "which" command - configureApp(ExternalApps.LATEX, "latex", "--interaction=batchmode %s"); - configureApp(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s"); - configureApp(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s"); - configureApp(ExternalApps.DVIPS, "dvips", "%s"); - configureApp(ExternalApps.BIBTEX, "bibtex", "%s"); - configureApp(ExternalApps.MAKEINDEX, "makeindex", "%s"); - configureApp(ExternalApps.MK4HT, "mk4ht", "%c %s"); + StringBuffer info = new StringBuffer(); + info.append("Results of configuration:\n\n"); + configureApp(ExternalApps.LATEX, "latex", "--interaction=batchmode %s",info); + configureApp(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s",info); + configureApp(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s",info); + configureApp(ExternalApps.DVIPS, "dvips", "%s",info); + configureApp(ExternalApps.BIBTEX, "bibtex", "%s",info); + configureApp(ExternalApps.MAKEINDEX, "makeindex", "%s",info); + configureApp(ExternalApps.MK4HT, "mk4ht", "%c %s",info); // We have several possible viewers String[] sDviViewers = {"evince", "okular", "xdvi"}; - configureApp(ExternalApps.DVIVIEWER, sDviViewers, "%s"); + configureApp(ExternalApps.DVIVIEWER, sDviViewers, "%s",info); String[] sPdfViewers = {"evince", "okular", "xpdf"}; - configureApp(ExternalApps.PDFVIEWER, sPdfViewers, "%s"); + configureApp(ExternalApps.PDFVIEWER, sPdfViewers, "%s",info); String[] sPsViewers = {"evince", "okular", "ghostview"}; - configureApp(ExternalApps.POSTSCRIPTVIEWER, sPsViewers, "%s"); + configureApp(ExternalApps.POSTSCRIPTVIEWER, sPsViewers, "%s",info); + + displayAutoConfigInfo(info.toString()); } changeApplication(xWindow); return true; @@ -313,6 +341,32 @@ public final class ConfigurationDialog return "???"; } + private XDialog getDialog(String sDialogName) { + XMultiComponentFactory xMCF = xContext.getServiceManager(); + try { + Object provider = xMCF.createInstanceWithContext( + "com.sun.star.awt.DialogProvider2", xContext); + XDialogProvider2 xDialogProvider = (XDialogProvider2) + UnoRuntime.queryInterface(XDialogProvider2.class, provider); + String sDialogUrl = "vnd.sun.star.script:"+sDialogName+"?location=application"; + return xDialogProvider.createDialogWithHandler(sDialogUrl, this); + } + catch (Exception e) { + return null; + } + } + + + private void displayAutoConfigInfo(String sText) { + XDialog xDialog = getDialog("W4LDialogs.AutoConfigInfo"); + if (xDialog!=null) { + DialogAccess info = new DialogAccess(xDialog); + info.setTextFieldText("Info", sText); + xDialog.execute(); + xDialog.endExecute(); + } + } + // Some helpers copied from DialogBase private XPropertySet getControlProperties(XWindow xWindow, String sControlName) { XControlContainer xContainer = (XControlContainer) diff --git a/source/java/org/openoffice/da/comp/writer4latex/ExternalApps.java b/source/java/org/openoffice/da/comp/writer4latex/ExternalApps.java index b9204d1..1110d3b 100644 --- a/source/java/org/openoffice/da/comp/writer4latex/ExternalApps.java +++ b/source/java/org/openoffice/da/comp/writer4latex/ExternalApps.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2009-06-19) + * Version 1.2 (2009-11-19) * */ diff --git a/source/java/org/openoffice/da/comp/writer4latex/TeXify.java b/source/java/org/openoffice/da/comp/writer4latex/TeXify.java index d26fdbf..3dcaa2b 100644 --- a/source/java/org/openoffice/da/comp/writer4latex/TeXify.java +++ b/source/java/org/openoffice/da/comp/writer4latex/TeXify.java @@ -77,8 +77,9 @@ public final class TeXify { * @param nBackend the desired backend format (generic, dvips, pdftex) * @param bView set the true if the result should be displayed in the viewer * @throws IOException if the document cannot be read + * @return true if the first LaTeX run was succesful */ - public void process(File file, short nBackend, boolean bView) throws IOException { + public boolean process(File file, short nBackend, boolean bView) throws IOException { // Remove extension from file if (file.getName().endsWith(".tex")) { file = new File(file.getParentFile(), @@ -89,8 +90,10 @@ public final class TeXify { externalApps.load(); // Process LaTeX document + boolean bResult = false; if (nBackend==GENERIC) { - doTeXify(genericTexify, file); + bResult = doTeXify(genericTexify, file); + if (!bResult) return false; if (externalApps.execute(ExternalApps.DVIVIEWER, new File(file.getParentFile(),file.getName()+".dvi").getPath(), file.getParentFile(), false)>0) { @@ -98,7 +101,8 @@ public final class TeXify { } } else if (nBackend==PDFTEX) { - doTeXify(pdfTexify, file); + bResult = doTeXify(pdfTexify, file); + if (!bResult) return false; if (externalApps.execute(ExternalApps.PDFVIEWER, new File(file.getParentFile(),file.getName()+".pdf").getPath(), file.getParentFile(), false)>0) { @@ -106,7 +110,8 @@ public final class TeXify { } } else if (nBackend==DVIPS) { - doTeXify(dvipsTexify, file); + bResult = doTeXify(dvipsTexify, file); + if (!bResult) return false; if (externalApps.execute(ExternalApps.POSTSCRIPTVIEWER, new File(file.getParentFile(),file.getName()+".ps").getPath(), file.getParentFile(), false)>0) { @@ -114,25 +119,30 @@ public final class TeXify { } } else if (nBackend==XETEX) { - doTeXify(xeTexify, file); + bResult = doTeXify(xeTexify, file); + if (!bResult) return false; if (externalApps.execute(ExternalApps.PDFVIEWER, new File(file.getParentFile(),file.getName()+".pdf").getPath(), file.getParentFile(), false)>0) { throw new IOException("Error executing pdf viewer"); } } + return bResult; } - private void doTeXify(String[] sAppList, File file) throws IOException { + private boolean doTeXify(String[] sAppList, File file) throws IOException { for (int i=0; i0) { + System.out.println("Return code from "+sAppList[i]+": "+nReturnCode); + if (i==0 && nReturnCode>0) { + return false; //throw new IOException("Error executing "+sAppList[i]); } } + return true; } } \ No newline at end of file diff --git a/source/java/org/openoffice/da/comp/writer4latex/Writer4LaTeX.java b/source/java/org/openoffice/da/comp/writer4latex/Writer4LaTeX.java index 1820a5c..a7d9ffc 100644 --- a/source/java/org/openoffice/da/comp/writer4latex/Writer4LaTeX.java +++ b/source/java/org/openoffice/da/comp/writer4latex/Writer4LaTeX.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2009-06-19) + * Version 1.2 (2009-11-19) * */ @@ -223,27 +223,35 @@ public final class Writer4LaTeX extends WeakBase if (texify==null) { texify = new TeXify(m_xContext); } File file = new File(urlToFile(sBasePath),sBaseFileName); + + boolean bResult = true; try { if (sBackend=="pdftex") { - texify.process(file, TeXify.PDFTEX, true); + bResult = texify.process(file, TeXify.PDFTEX, true); } else if (sBackend=="dvips") { - texify.process(file, TeXify.DVIPS, true); + bResult = texify.process(file, TeXify.DVIPS, true); } else if (sBackend=="xetex") { - texify.process(file, TeXify.XETEX, true); + bResult = texify.process(file, TeXify.XETEX, true); } else if (sBackend=="generic") { - texify.process(file, TeXify.GENERIC, true); + bResult = texify.process(file, TeXify.GENERIC, true); } } catch (IOException e) { MessageBox msgBox = new MessageBox(m_xContext, m_xFrame); msgBox.showMessage("Writer4LaTeX Error",e.getMessage()); } - - xStatus.setValue(10); // The user will not really see this... + + xStatus.setValue(10); // The user will usually not see this... + + if (!bResult) { + MessageBox msgBox = new MessageBox(m_xContext, m_xFrame); + msgBox.showMessage("Writer4LaTeX Error","Failed to execute LaTeX - see log for details"); + } + xStatus.end(); } diff --git a/source/java/writer2latex/api/ComplexOption.java b/source/java/writer2latex/api/ComplexOption.java index db38063..2949083 100644 --- a/source/java/writer2latex/api/ComplexOption.java +++ b/source/java/writer2latex/api/ComplexOption.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2009-11-08) + * Version 1.2 (2009-11-19) * */ @@ -107,6 +107,15 @@ public class ComplexOption { return options.keySet(); } + /** Test if this complex options contains a specific option name + * + * @param sName the name to test + * @return true if the name exists + */ + public boolean containsKey(String sName) { + return options.containsKey(sName); + } + } diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index b0369ea..ac7b35a 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 (2009-11-08) + * Version 1.2 (2009-11-23) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.1.1"; - private static final String DATE = "2009-11-08"; + private static final String DATE = "2009-11-23"; /** Return version information * @return the Writer2LaTeX version in the form diff --git a/source/oxt/writer2latex/W2LDialogs2/ConfigurationRoot.xdl b/source/oxt/writer2latex/W2LDialogs2/ConfigurationRoot.xdl index 817f307..d747f25 100644 --- a/source/oxt/writer2latex/W2LDialogs2/ConfigurationRoot.xdl +++ b/source/oxt/writer2latex/W2LDialogs2/ConfigurationRoot.xdl @@ -7,9 +7,9 @@ - + - + \ No newline at end of file diff --git a/source/oxt/writer2latex/W2LDialogs2/Headings.xdl b/source/oxt/writer2latex/W2LDialogs2/Headings.xdl index db1b920..e365355 100644 --- a/source/oxt/writer2latex/W2LDialogs2/Headings.xdl +++ b/source/oxt/writer2latex/W2LDialogs2/Headings.xdl @@ -36,7 +36,7 @@ - + @@ -48,7 +48,7 @@ - + diff --git a/source/oxt/writer2latex/W2LDialogs2/LoadDefaults.xdl b/source/oxt/writer2latex/W2LDialogs2/LoadDefaults.xdl new file mode 100644 index 0000000..836ba5d --- /dev/null +++ b/source/oxt/writer2latex/W2LDialogs2/LoadDefaults.xdl @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/source/oxt/writer2latex/W2LDialogs2/Styles.xdl b/source/oxt/writer2latex/W2LDialogs2/Styles.xdl index 9a94730..1f9cdcb 100644 --- a/source/oxt/writer2latex/W2LDialogs2/Styles.xdl +++ b/source/oxt/writer2latex/W2LDialogs2/Styles.xdl @@ -13,32 +13,38 @@ - - + + - + - + - - - - - + + + + + + + + + + + - - + + @@ -47,6 +53,9 @@ - + + + + \ No newline at end of file diff --git a/source/oxt/writer2latex/W2LDialogs2/dialog.xlb b/source/oxt/writer2latex/W2LDialogs2/dialog.xlb index ff99ab9..d474ee9 100644 --- a/source/oxt/writer2latex/W2LDialogs2/dialog.xlb +++ b/source/oxt/writer2latex/W2LDialogs2/dialog.xlb @@ -13,4 +13,5 @@ + \ No newline at end of file diff --git a/source/oxt/writer4latex/W4LDialogs/AutoConfigInfo.xdl b/source/oxt/writer4latex/W4LDialogs/AutoConfigInfo.xdl new file mode 100644 index 0000000..3642770 --- /dev/null +++ b/source/oxt/writer4latex/W4LDialogs/AutoConfigInfo.xdl @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/source/oxt/writer4latex/W4LDialogs/dialog.xlb b/source/oxt/writer4latex/W4LDialogs/dialog.xlb index 719e888..3fc1e83 100644 --- a/source/oxt/writer4latex/W4LDialogs/dialog.xlb +++ b/source/oxt/writer4latex/W4LDialogs/dialog.xlb @@ -3,4 +3,5 @@ + \ No newline at end of file diff --git a/source/oxt/writer4latex/w4l_filters.xcu b/source/oxt/writer4latex/w4l_filters.xcu index aecbcca..1688582 100644 --- a/source/oxt/writer4latex/w4l_filters.xcu +++ b/source/oxt/writer4latex/w4l_filters.xcu @@ -3,6 +3,7 @@ + diff --git a/source/readme-source.txt b/source/readme-source.txt index f0f62d8..8d5212b 100644 --- a/source/readme-source.txt +++ b/source/readme-source.txt @@ -22,6 +22,20 @@ The source of Writer2LaTeX consists of three major parts: Currently parts of the source for Writer2LaTeX are somewhat messy and undocumented. This situation is improving from time to time :-) +Third-party software +-------------------- + +Writer2LaTeX includes some classes from the OpenOffice.org project +* com.sun.star.lib.loader.* are part of the SDK for OOo +* writer2latex.xmerge.* contains some classes which are part of the xmerge + project within OOo (some of the classes are slightly modified) +See copyright notices within the source files + +Also, the windows DLL file unowinreg.dll is part of the SDK for OOo, +the source can be found at http://svn.services.openoffice.org/ + +Finally, writer2latex.util.Base64 is Harald Harders public domain Base64 class + Building Writer2LaTeX --------------------- @@ -35,11 +49,10 @@ these are jurt.jar, unoil.jar, ridl.jar and juh.jar. To make these files available for the compiler, edit the file build.xml in the writer2latex09 directory as follows: -The line - -should be edited to contain the path to your OOo installation, e.g. - - +The lines + + +should be modified to point to your OOo installation To build, open a command shell, navigate to the writer2latex09 directory and type @@ -61,7 +74,7 @@ In addition to oxt, the build file supports the following targets: clean -Henrik Just, September 2009 +Henrik Just, November 2009 Thanks to Michael Niedermair for writing the original ant build file