From e16d5edd12213300a0e5042058879163e07e9ce4 Mon Sep 17 00:00:00 2001 From: henrikjust Date: Mon, 16 Feb 2015 14:48:25 +0000 Subject: [PATCH] BibTeX support git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@229 f0f2a975-2e09-46c8-9428-3b39399b9f3c --- source/distro/changelog.txt | 5 + .../da/comp/w2lcommon/helper/MessageBox.java | 6 +- .../da/comp/writer2latex/BibTeXDialog.java | 277 ++++++++++++------ .../comp/writer2latex/LaTeXUNOPublisher.java | 83 +----- source/java/writer2latex/util/Misc.java | 90 +++++- .../bibtex.xhp | 34 +-- 6 files changed, 306 insertions(+), 189 deletions(-) diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index 94f01a5..ca5925a 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -4,6 +4,11 @@ Changelog for Writer2LaTeX version 1.4 -> 1.6 Items marked with * are work in progress +[all] The position of message boxes has changed from (0,0) to (200,100) + +[w2l] Implementation detail: The dialog library W4LDialogs are now merged into W2LDialogs2. This avoids conflicts with + the old Writer4LaTeX extension if this happens to be installed. + [all] *Document the use of soffice --headless --convert-to [w2x] *Added EPUB 3 as export format and changed the toolbar to export to EPUB 3 diff --git a/source/java/org/openoffice/da/comp/w2lcommon/helper/MessageBox.java b/source/java/org/openoffice/da/comp/w2lcommon/helper/MessageBox.java index 44e63c5..5cdf420 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/helper/MessageBox.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/helper/MessageBox.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2008 by Henrik Just + * Copyright: 2002-2015 by Henrik Just * * All Rights Reserved. * - * Version 1.0 (2008-07-21) + * Version 1.6 (2015-02-16) * */ @@ -83,7 +83,7 @@ public class MessageBox { descriptor.ParentIndex = -1; descriptor.Parent = (XWindowPeer) UnoRuntime.queryInterface( XWindowPeer.class,xFrame.getContainerWindow()); - descriptor.Bounds = new Rectangle(0,0,300,200); + descriptor.Bounds = new Rectangle(200,100,300,200); descriptor.WindowAttributes = WindowAttribute.BORDER | WindowAttribute.MOVEABLE | WindowAttribute.CLOSEABLE; XWindowPeer xPeer = xToolkit.createWindow(descriptor); diff --git a/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java b/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java index 77026fe..d311f3b 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java +++ b/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2015-02-10) + * Version 1.6 (2015-02-15) * */ @@ -30,25 +30,43 @@ import java.awt.Desktop; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + import com.sun.star.awt.XDialog; +import com.sun.star.awt.XDialogProvider2; import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.UnknownPropertyException; import com.sun.star.beans.XPropertySet; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XEnumerationAccess; import com.sun.star.frame.XFrame; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.text.XDependentTextField; import com.sun.star.text.XText; import com.sun.star.text.XTextDocument; +import com.sun.star.text.XTextField; +import com.sun.star.text.XTextFieldsSupplier; import com.sun.star.text.XTextViewCursor; import com.sun.star.text.XTextViewCursorSupplier; +import com.sun.star.ui.dialogs.ExecutableDialogResults; +import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import org.jbibtex.ParseException; +import org.openoffice.da.comp.w2lcommon.helper.DialogAccess; import org.openoffice.da.comp.w2lcommon.helper.DialogBase; import org.openoffice.da.comp.w2lcommon.helper.MessageBox; import writer2latex.office.BibMark; import writer2latex.office.BibMark.EntryType; +import writer2latex.util.Misc; /** This class provides a UNO dialog to insert a BibTeX bibliographic reference */ @@ -85,7 +103,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti throws com.sun.star.uno.Exception { for (Object object : objects) { if (object instanceof XFrame) { - xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, object); + xFrame = UnoRuntime.queryInterface(XFrame.class, object); } if (object instanceof String) { bibTeXDirectory = new File((String) object); @@ -113,7 +131,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti } @Override public void initialize() { - refresh(); + refreshDialog(null); } @Override public void endDialog() { @@ -123,22 +141,29 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti @Override public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) { if (sMethod.equals("FileChange")) { + // The user has selected another BibTeX file fileChange(); } else if (sMethod.equals("EntryChange")) { + // The user has selected another BibTeX entry entryChange(); } else if (sMethod.equals("InsertReference")) { + // Insert a reference to the current BibTeX entry insertReference(); } else if (sMethod.equals("New")) { + // Create a new BibTeX file newFile(); } else if (sMethod.equals("Edit")) { + // Edit the current BibTeX file edit(); } else if (sMethod.equals("Refresh")) { - refresh(); + // Refresh the dialog and update all bibliographic references + refreshDialog(null); + refreshReferences(); } return true; } @@ -151,12 +176,18 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti // **** Implement the UI functions // (Re)load the list of BibTeX files - private void refresh() { - // Remember current file selection, if any + private void refreshDialog(String sSelectedFileName) { String sFile = null; - short nFile = getListBoxSelectedItem("File"); - if (nFile>=0 && files[nFile]!=null) { - sFile = getListBoxStringItemList("File")[nFile]; + if (sSelectedFileName!=null) { + // Select a new file name + sFile = sSelectedFileName; + } + else { + // Remember the previous selection, if any + short nSelectedFile = getListBoxSelectedItem("File"); + if (nSelectedFile>=0 && files[nSelectedFile]!=null) { + sFile = getListBoxStringItemList("File")[nSelectedFile]; + } } if (bibTeXDirectory!=null && bibTeXDirectory.isDirectory()) { @@ -170,7 +201,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti String[] sFileNames = new String[nFileCount]; // Select either the first or the previous item - nFile = 0; + short nFile = 0; for (short i=0; i notUpdated = new HashSet(); + + // Traverse all text fields + XTextFieldsSupplier xSupplier = (XTextFieldsSupplier) UnoRuntime.queryInterface( + XTextFieldsSupplier.class, xFrame.getController().getModel()); + XEnumerationAccess fields = xSupplier.getTextFields(); + XEnumeration enumeration = fields.createEnumeration(); + while (enumeration.hasMoreElements()) { + try { + Object elm = enumeration.nextElement(); + if (AnyConverter.isObject(elm)) { + XTextField xTextField = (XTextField) AnyConverter.toObject(XTextField.class, elm); + if (xTextField!=null) { + String sId = updateTextField(xTextField, readers); + if (sId!=null) { + notUpdated.add(sId); + } + } + } + } catch (NoSuchElementException e) { + } catch (WrappedTargetException e) { + } + } + + // Inform the user about the result + if (xFrame!=null) { + MessageBox msgBox = new MessageBox(xContext, xFrame); + if (notUpdated.isEmpty()) { + msgBox.showMessage("Writer2LaTeX","All bibliography fields were updated"); + } + else { + msgBox.showMessage("Writer2LaTeX","The following bibliography fields were not updated:\n"+notUpdated.toString()); + } + } + } + } + + private BibTeXReader[] parseAllBibTeXFiles() { + int nFiles = files.length; + BibTeXReader[] readers = new BibTeXReader[nFiles]; + for (int i=0; i"+(String)prop.Value); - } - else if (prop.Value instanceof Short) { - System.out.println("Short "+prop.Name+"=>"+(Short)prop.Value); - } - else { - System.out.println("Other "+prop.Name+"=>"+prop.Value.getClass().getName()); - } - } - } - else { - System.out.println("Unexpected type of fields"); - } - } catch (UnknownPropertyException e) { - System.out.println("Unknown property?"); - } - } - else { - System.out.println("No properties"); - } - } - else { - System.out.println("Found something unexpected"); - } - } - else { - System.out.println("Found nothing"); - } - } catch (NoSuchElementException e) { - e.printStackTrace(); - } catch (WrappedTargetException e) { - e.printStackTrace(); - } - } -} -*/ \ No newline at end of file diff --git a/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java b/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java index 1cfdc4c..a437227 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java +++ b/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2014 by Henrik Just + * Copyright: 2002-2015 by Henrik Just * * All Rights Reserved. * - * Version 1.6 (2014-12-27) + * Version 1.6 (2015-02-16) * */ package org.openoffice.da.comp.writer2latex; @@ -77,84 +77,7 @@ public class LaTeXUNOPublisher extends UNOPublisher { /** Make a file name LaTeX friendly */ @Override protected String filterFileName(String sFileName) { - String sResult = ""; - for (int i=0; i='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) { - sResult += Character.toString(c); - } - else { - switch (c) { - case '.': sResult += "."; break; - case '-': sResult += "-"; break; - case ' ' : sResult += "-"; break; - case '_' : sResult += "-"; break; - // Replace accented and national characters - case '\u00c0' : sResult += "A"; break; - case '\u00c1' : sResult += "A"; break; - case '\u00c2' : sResult += "A"; break; - case '\u00c3' : sResult += "A"; break; - case '\u00c4' : sResult += "AE"; break; - case '\u00c5' : sResult += "AA"; break; - case '\u00c6' : sResult += "AE"; break; - case '\u00c7' : sResult += "C"; break; - case '\u00c8' : sResult += "E"; break; - case '\u00c9' : sResult += "E"; break; - case '\u00ca' : sResult += "E"; break; - case '\u00cb' : sResult += "E"; break; - case '\u00cc' : sResult += "I"; break; - case '\u00cd' : sResult += "I"; break; - case '\u00ce' : sResult += "I"; break; - case '\u00cf' : sResult += "I"; break; - case '\u00d0' : sResult += "D"; break; - case '\u00d1' : sResult += "N"; break; - case '\u00d2' : sResult += "O"; break; - case '\u00d3' : sResult += "O"; break; - case '\u00d4' : sResult += "O"; break; - case '\u00d5' : sResult += "O"; break; - case '\u00d6' : sResult += "OE"; break; - case '\u00d8' : sResult += "OE"; break; - case '\u00d9' : sResult += "U"; break; - case '\u00da' : sResult += "U"; break; - case '\u00db' : sResult += "U"; break; - case '\u00dc' : sResult += "UE"; break; - case '\u00dd' : sResult += "Y"; break; - case '\u00df' : sResult += "sz"; break; - case '\u00e0' : sResult += "a"; break; - case '\u00e1' : sResult += "a"; break; - case '\u00e2' : sResult += "a"; break; - case '\u00e3' : sResult += "a"; break; - case '\u00e4' : sResult += "ae"; break; - case '\u00e5' : sResult += "aa"; break; - case '\u00e6' : sResult += "ae"; break; - case '\u00e7' : sResult += "c"; break; - case '\u00e8' : sResult += "e"; break; - case '\u00e9' : sResult += "e"; break; - case '\u00ea' : sResult += "e"; break; - case '\u00eb' : sResult += "e"; break; - case '\u00ec' : sResult += "i"; break; - case '\u00ed' : sResult += "i"; break; - case '\u00ee' : sResult += "i"; break; - case '\u00ef' : sResult += "i"; break; - case '\u00f0' : sResult += "d"; break; - case '\u00f1' : sResult += "n"; break; - case '\u00f2' : sResult += "o"; break; - case '\u00f3' : sResult += "o"; break; - case '\u00f4' : sResult += "o"; break; - case '\u00f5' : sResult += "o"; break; - case '\u00f6' : sResult += "oe"; break; - case '\u00f8' : sResult += "oe"; break; - case '\u00f9' : sResult += "u"; break; - case '\u00fa' : sResult += "u"; break; - case '\u00fb' : sResult += "u"; break; - case '\u00fc' : sResult += "ue"; break; - case '\u00fd' : sResult += "y"; break; - case '\u00ff' : sResult += "y"; break; - } - } - } - if (sResult.length()==0) { return "writer2latex"; } - else { return sResult; } + return Misc.makeTeXFriendly(sFileName,"writer2latex"); } /** Post process the filter data: Set bibliography options and diff --git a/source/java/writer2latex/util/Misc.java b/source/java/writer2latex/util/Misc.java index d5a9338..d424418 100644 --- a/source/java/writer2latex/util/Misc.java +++ b/source/java/writer2latex/util/Misc.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2014 by Henrik Just + * Copyright: 2002-2015 by Henrik Just * * All Rights Reserved. * - * Version 1.6 (2014-11-03) + * Version 1.6 (2015-02-16) * */ @@ -277,6 +277,92 @@ public class Misc{ public static String abs(String sLength) { return sLength.startsWith("-") ? sLength.substring(1) : sLength; } + + /** Make a file name TeX friendly, replacing offending characters + * + * @param sFileName the file name + * @param sDefault a default name to use if no characters remains after filtering + * @return the modified file name + */ + public static String makeTeXFriendly(String sFileName, String sDefault) { + StringBuilder builder = new StringBuilder(); + for (int i=0; i='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) { + builder.append(c); + } + else { + switch (c) { + case '.': builder.append('.'); break; + case '-': builder.append('-'); break; + case ' ' : builder.append('-'); break; + case '_' : builder.append('-'); break; + // Replace accented and national characters + case '\u00c0' : builder.append('A'); break; + case '\u00c1' : builder.append('A'); break; + case '\u00c2' : builder.append('A'); break; + case '\u00c3' : builder.append('A'); break; + case '\u00c4' : builder.append("AE"); break; + case '\u00c5' : builder.append("AA"); break; + case '\u00c6' : builder.append("AE"); break; + case '\u00c7' : builder.append('C'); break; + case '\u00c8' : builder.append('E'); break; + case '\u00c9' : builder.append('E'); break; + case '\u00ca' : builder.append('E'); break; + case '\u00cb' : builder.append('E'); break; + case '\u00cc' : builder.append('I'); break; + case '\u00cd' : builder.append('I'); break; + case '\u00ce' : builder.append('I'); break; + case '\u00cf' : builder.append('I'); break; + case '\u00d0' : builder.append('D'); break; + case '\u00d1' : builder.append('N'); break; + case '\u00d2' : builder.append('O'); break; + case '\u00d3' : builder.append('O'); break; + case '\u00d4' : builder.append('O'); break; + case '\u00d5' : builder.append('O'); break; + case '\u00d6' : builder.append("OE"); break; + case '\u00d8' : builder.append("OE"); break; + case '\u00d9' : builder.append('U'); break; + case '\u00da' : builder.append('U'); break; + case '\u00db' : builder.append('U'); break; + case '\u00dc' : builder.append("UE"); break; + case '\u00dd' : builder.append('Y'); break; + case '\u00df' : builder.append("sz"); break; + case '\u00e0' : builder.append('a'); break; + case '\u00e1' : builder.append('a'); break; + case '\u00e2' : builder.append('a'); break; + case '\u00e3' : builder.append('a'); break; + case '\u00e4' : builder.append("ae"); break; + case '\u00e5' : builder.append("aa"); break; + case '\u00e6' : builder.append("ae"); break; + case '\u00e7' : builder.append('c'); break; + case '\u00e8' : builder.append('e'); break; + case '\u00e9' : builder.append('e'); break; + case '\u00ea' : builder.append('e'); break; + case '\u00eb' : builder.append('e'); break; + case '\u00ec' : builder.append('i'); break; + case '\u00ed' : builder.append('i'); break; + case '\u00ee' : builder.append('i'); break; + case '\u00ef' : builder.append('i'); break; + case '\u00f0' : builder.append('d'); break; + case '\u00f1' : builder.append('n'); break; + case '\u00f2' : builder.append('o'); break; + case '\u00f3' : builder.append('o'); break; + case '\u00f4' : builder.append('o'); break; + case '\u00f5' : builder.append('o'); break; + case '\u00f6' : builder.append("oe"); break; + case '\u00f8' : builder.append("oe"); break; + case '\u00f9' : builder.append('u'); break; + case '\u00fa' : builder.append('u'); break; + case '\u00fb' : builder.append('u'); break; + case '\u00fc' : builder.append("ue"); break; + case '\u00fd' : builder.append('y'); break; + case '\u00ff' : builder.append('y'); break; + } + } + } + return builder.length()>0 ? builder.toString() : sDefault; + } /* * Utility method to make sure the document name is stripped of any file diff --git a/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibtex.xhp b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibtex.xhp index 15fdc6a..fa42c62 100644 --- a/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibtex.xhp +++ b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibtex.xhp @@ -2,30 +2,28 @@ - Insert BibTeX reference + Insert BibTeX references org.openoffice.da.writer2latex.oxt/bibtex.xhp - Insert BibTeX reference - Insert a bibliographic reference to an item in a BibTeX file. + Manage BibTeX reference + BibTeX is the standard database format for bibliographic references + in LaTeX. + This dialog is used to insert bibliographic references in %PRODUCTNAME Writer from BibTeX files. + This enables you to maintain your references in BibTeX, rather that using the bibliography database + in %PRODUCTNAME Writer. +
Click the Bib-button on the toolbar
- BibTeX is the standard database format for bibliographic references in LaTeX. - This dialog is used to insert bibliographic references in %PRODUCTNAME Writer from BibTeX files. - This enables you to maintain your references in BibTeX, rather that using the bibliography database in %PRODUCTNAME Writer. - - The dialog presents a list of BibTeX files from a specific folder. The folder to search is configured in the bibliography settings. - Inserting BibTeX references - To insert a bibliographic reference, select an item and - click the Insert reference button. + Using the dialog BibTeX file @@ -34,8 +32,8 @@ BibTeX entry - Select the entry to use in this list. The list contains the keys of all entries - in the selected BibTeX file. + Select the entry to use in this list. The list contains the keys of + all entries in the selected BibTeX file. Basic information about the entry is displayed in the field below the list. Select the entry to use @@ -48,16 +46,16 @@ Refresh Click this button to reload the BibTeX - files and update all references. You should do this if you have edited a BibTeX file. - Click to refresh the contents of all references + files and update all references. You should do this if you have edited a BibTeX file. This will ensure that + the content of all references is in sync with the current content of the BibTeX files. + Writer2LaTeX will display an message to confirm the result. + Click to refresh the dialog and all references Close - Click this button to close the dialog + Click this button to close the dialog. Click to close the dialog - Managing BibTeX files - New Click this button create a new BibTeX file in the configured