diff --git a/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogAccess.java b/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogAccess.java index 1386dea..2a0c678 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogAccess.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogAccess.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2009-11-02) + * Version 1.2 (2009-11-08) * */ @@ -213,6 +213,27 @@ public class DialogAccess { // nText is an illegal value } } + + public String getLabelText(String sControlName) { + XPropertySet xPropertySet = getControlProperties(sControlName); + try { + return (String) xPropertySet.getPropertyValue("Label"); + } + catch (Exception e) { + // Will fail if the control does not exist or is not a label + return ""; + } + } + + public void setLabelText(String sControlName, String sLabel) { + XPropertySet xPropertySet = getControlProperties(sControlName); + try { + xPropertySet.setPropertyValue("Label",sLabel); + } + catch (Exception e) { + // Will fail if the control does not exist or is not a label + } + } public String getTextFieldText(String sControlName) { XPropertySet xPropertySet = getControlProperties(sControlName); diff --git a/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java b/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java new file mode 100644 index 0000000..32689e5 --- /dev/null +++ b/source/java/org/openoffice/da/comp/w2lcommon/helper/StyleNameProvider.java @@ -0,0 +1,144 @@ +/************************************************************************ + * + * StyleNameProvider.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-08) + * + */ + +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; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.frame.XController; +import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XModel; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +/** This class provides access to the style names and localized style names of the current document + */ +public class StyleNameProvider { + private Map> displayNameCollection; + private Map> internalNameCollection; + + /** Construct a new StyleNameProvider + * + * @param xContext the componemt context to get the desktop from + */ + public StyleNameProvider(XComponentContext xContext) { + displayNameCollection = new HashMap>(); + internalNameCollection = new HashMap>(); + + // Get the model for the current frame + XModel xModel = null; + try { + Object desktop = xContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xContext); + XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop); + XController xController = xDesktop.getCurrentFrame().getController(); + if (xController!=null) { + xModel = xController.getModel(); + } + } + catch (Exception e) { + // do nothing + } + + // Get the styles from the model + if (xModel!=null) { + XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface( + XStyleFamiliesSupplier.class, xModel); + if (xSupplier!=null) { + XNameAccess xFamilies = xSupplier.getStyleFamilies(); + String[] sFamilyNames = xFamilies.getElementNames(); + for (String sFamilyName : sFamilyNames) { + Map displayNames = new HashMap(); + displayNameCollection.put(sFamilyName, displayNames); + Map internalNames = new HashMap(); + internalNameCollection.put(sFamilyName, internalNames); + try { + XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface( + XNameContainer.class, xFamilies.getByName(sFamilyName)); + if (xFamily!=null) { + String[] sStyleNames = xFamily.getElementNames(); + for (String sStyleName : sStyleNames) { + XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet.class, xFamily.getByName(sStyleName)); + if (xProps!=null) { + String sDisplayName = (String) xProps.getPropertyValue("DisplayName"); + displayNames.put(sStyleName, sDisplayName); + internalNames.put(sDisplayName, sStyleName); + } + } + } + } + catch (WrappedTargetException e) { + // ignore + } + catch (NoSuchElementException e) { + // will not happen + } + catch (UnknownPropertyException e) { + // will not happen + } + } + } + } + } + + /** Get the mapping of internal names to display names for a style family + * + * @param sFamily the style family (for text documents this should be CharacterStyles, ParagraphStyles, FrameStyles, PageStyles or NumberingStyles) + * @return a read only map from internal names to display names, or null if the family is not known to the provider + */ + public Map getDisplayNames(String sFamily) { + if (displayNameCollection.containsKey(sFamily)) { + return Collections.unmodifiableMap(displayNameCollection.get(sFamily)); + } + return null; + } + + /** Get the mapping of display names to internal names for a style family + * + * @param sFamily the style family (for text documents this should be CharacterStyles, ParagraphStyles, FrameStyles, PageStyles or NumberingStyles) + * @return a read only map from display names to internal names, or null if the family is not known to the provider + */ + public Map getInternalNames(String sFamily) { + if (internalNameCollection.containsKey(sFamily)) { + return Collections.unmodifiableMap(internalNameCollection.get(sFamily)); + } + return null; + } + + + + +} diff --git a/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java b/source/java/org/openoffice/da/comp/writer2latex/ConfigurationDialog.java index 753e074..1bd4398 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-02) + * Version 1.2 (2009-11-08) * */ @@ -32,6 +32,7 @@ import java.io.OutputStream; import java.text.Collator; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -61,6 +62,7 @@ import writer2latex.api.Config; import writer2latex.api.ConverterFactory; import org.openoffice.da.comp.w2lcommon.helper.DialogAccess; +import org.openoffice.da.comp.w2lcommon.helper.StyleNameProvider; /** This class provides a uno component which implements the configuration * of Writer2LaTeX. The same component is used for all pages - using the @@ -70,6 +72,7 @@ public final class ConfigurationDialog extends WeakBase implements XServiceInfo, XContainerWindowEventHandler { private String[] sFamilyNames = { "text", "paragraph", "paragraph-block", "list", "listitem" }; + private String[] sOOoFamilyNames = { "CharacterStyles", "ParagraphStyles", "ParagraphStyles", "NumberingStyles", "NumberingStyles" }; private String[] sAttributeNames = { "bold", "italics", "small-caps", "superscript", "subscipt" }; private XComponentContext xContext; @@ -91,6 +94,7 @@ public final class ConfigurationDialog extends WeakBase String sCurrentText = null; private String sTitle = null; private DialogAccess dlg = null; + private StyleNameProvider styleNameProvider = null; /** The component will be registered under this name. */ @@ -137,6 +141,8 @@ public final class ConfigurationDialog extends WeakBase headingMap = new ComplexOption(); mathSymbols = new ComplexOption(); stringReplace = new ComplexOption(); + + styleNameProvider = new StyleNameProvider(xContext); } // Implement XContainerWindowEventHandler @@ -183,7 +189,7 @@ public final class ConfigurationDialog extends WeakBase } else if (sMethod.equals("NewStyleClick")) { if (nCurrentFamily>-1) { - String sNewName = appendItem("StyleName"); + String sNewName = appendItem("StyleName",styleNameProvider.getInternalNames(sOOoFamilyNames[nCurrentFamily]).keySet()); if (sNewName!=null) { Map attr = new HashMap(); attr.put("before", ""); @@ -256,7 +262,7 @@ public final class ConfigurationDialog extends WeakBase return true; } else if (sMethod.equals("NewSymbolClick")) { - String sNewName = appendItem("MathSymbolName"); + String sNewName = appendItem("MathSymbolName",new HashSet()); if (sNewName!=null) { Map attr = new HashMap(); attr.put("latex", ""); @@ -279,7 +285,7 @@ public final class ConfigurationDialog extends WeakBase return true; } else if (sMethod.equals("NewTextClick")) { - String sNewName = appendItem("TextInput"); + String sNewName = appendItem("TextInput", new HashSet()); if (sNewName!=null) { Map attr = new HashMap(); attr.put("latex-code", ""); @@ -345,8 +351,16 @@ public final class ConfigurationDialog extends WeakBase loadConfig(); getControls(); for (int i=0; i<5; i++) { - config.getComplexOption(sFamilyNames[i]+"-map").clear(); - config.getComplexOption(sFamilyNames[i]+"-map").copyAll(styleMap[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); @@ -366,8 +380,16 @@ public final class ConfigurationDialog extends WeakBase } 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(); - styleMap[i].copyAll(config.getComplexOption(sFamilyNames[i]+"-map")); + 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")); @@ -404,9 +426,13 @@ public final class ConfigurationDialog extends WeakBase } } - private boolean deleteItem() { + private boolean deleteItem(String sName) { XDialog xDialog=getDialog("W2LDialogs2.DeleteDialog"); if (xDialog!=null) { + DialogAccess ddlg = new DialogAccess(xDialog); + String sLabel = ddlg.getLabelText("DeleteLabel"); + sLabel = sLabel.replaceAll("%s", sName); + ddlg.setLabelText("DeleteLabel", sLabel); boolean bDelete = xDialog.execute()==ExecutableDialogResults.OK; xDialog.endExecute(); return bDelete; @@ -417,7 +443,7 @@ public final class ConfigurationDialog extends WeakBase private boolean deleteCurrentItem(String sListName) { String[] sItems = dlg.getListBoxStringItemList(sListName); short nSelected = dlg.getListBoxSelectedItem(sListName); - if (nSelected>=0 && deleteItem()) { + if (nSelected>=0 && deleteItem(sItems[nSelected])) { int nOldLen = sItems.length; String[] sNewItems = new String[nOldLen-1]; if (nSelected>0) { @@ -434,9 +460,18 @@ public final class ConfigurationDialog extends WeakBase return false; } - private String newItem() { + private String newItem(Set suggestions) { XDialog xDialog=getDialog("W2LDialogs2.NewDialog"); if (xDialog!=null) { + int nCount = suggestions.size(); + String[] sItems = new String[nCount]; + int i=0; + for (String s : suggestions) { + sItems[i++] = s; + } + sortStringArray(sItems); + DialogAccess ndlg = new DialogAccess(xDialog); + ndlg.setListBoxStringItemList("Name", sItems); String sResult = null; if (xDialog.execute()==ExecutableDialogResults.OK) { DialogAccess dlg = new DialogAccess(xDialog); @@ -448,9 +483,9 @@ public final class ConfigurationDialog extends WeakBase return null; } - private String appendItem(String sListName) { + private String appendItem(String sListName, Set suggestions) { String[] sItems = dlg.getListBoxStringItemList(sListName); - String sNewItem = newItem(); + String sNewItem = newItem(suggestions); if (sNewItem!=null) { int nOldLen = sItems.length; for (short i=0; icopy of a the provided attributes. + * If the key already exists, the old value will be replaced + * + * @param sName the name of the key. The name must be non-empty, otherwise the request will be ignored. + * @param attributes + */ + public void copy(String sName, Map attributes) { + if (sName!=null && sName.length()>0) { + Map newAttributes = new HashMap(); + for (String sAttrName : attributes.keySet()) { + newAttributes.put(sAttrName, attributes.get(sAttrName)); + } + put(sName, newAttributes); + } + } + /** Get the value belonging to a key * * @param sName the name of the key @@ -79,12 +95,7 @@ public class ComplexOption { */ public void copyAll(ComplexOption co) { for (String sName : co.keySet()) { - Map attr = co.get(sName); - Map newAttr = new HashMap(); - for (String sAttrName : attr.keySet()) { - newAttr.put(sAttrName, attr.get(sAttrName)); - } - options.put(sName, newAttr); + copy(sName, co.get(sName)); } } diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index 6f1a47a..b0369ea 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-02) + * Version 1.2 (2009-11-08) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.1.1"; - private static final String DATE = "2009-11-02"; + private static final String DATE = "2009-11-08"; /** Return version information * @return the Writer2LaTeX version in the form diff --git a/source/oxt/writer2latex/W2LDialogs2/DeleteDialog.xdl b/source/oxt/writer2latex/W2LDialogs2/DeleteDialog.xdl index b787296..a0d3536 100644 --- a/source/oxt/writer2latex/W2LDialogs2/DeleteDialog.xdl +++ b/source/oxt/writer2latex/W2LDialogs2/DeleteDialog.xdl @@ -2,7 +2,7 @@ - + diff --git a/source/oxt/writer2latex/W2LDialogs2/NewDialog.xdl b/source/oxt/writer2latex/W2LDialogs2/NewDialog.xdl index d44f0e7..2d0a0ba 100644 --- a/source/oxt/writer2latex/W2LDialogs2/NewDialog.xdl +++ b/source/oxt/writer2latex/W2LDialogs2/NewDialog.xdl @@ -3,7 +3,10 @@ - + + + +