diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index 82e6d63..2a7da26 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,8 +2,8 @@ Changelog for Writer2LaTeX version 1.4 -> 1.6 ---------- version 1.5.2 ---------- -[w2l] New BibTeX dialog to insert a bibliographic reference to a BibTeX file. The BibTeX files are located as defined - in the configuration, and the reference is inserted as an ordinary reference mark. +[w2l] Added new BibTeX dialog to insert a bibliographic reference to a BibTeX file. The BibTeX files are located as + defined in the configuration, and the reference is inserted as an ordinary reference mark. [w2l] Various improvements to the log viewer dialog: Reduced height to better accommodate small screen resolutions. Added checkbox to filter the LaTeX log to display only errors. Added help page and long tips. diff --git a/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java b/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java index a9c0412..3f48d9a 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/filter/UNOPublisher.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2014-11-08) + * Version 1.6 (2014-12-27) * */ package org.openoffice.da.comp.w2lcommon.filter; @@ -173,7 +173,7 @@ public class UNOPublisher { String sDocumentUrl = xModel.getURL(); if (sDocumentUrl.length()==0) { // The document has no location MessageBox msgBox = new MessageBox(xContext, xFrame); - msgBox.showMessage(sAppName,"Please save the document before publishing the file"); + msgBox.showMessage(sAppName,"Please save the document first"); return false; } else if (!".odt".equals(Misc.getFileExtension(sDocumentUrl)) && !".fodt".equals(Misc.getFileExtension(sDocumentUrl)) && !".ods".equals(Misc.getFileExtension(sDocumentUrl)) && !".fods".equals(Misc.getFileExtension(sDocumentUrl))) { diff --git a/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogBase.java b/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogBase.java index 8dacc93..7495095 100644 --- a/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogBase.java +++ b/source/java/org/openoffice/da/comp/w2lcommon/helper/DialogBase.java @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * - * Copyright: 2002-2011 by Henrik Just + * Copyright: 2002-2014 by Henrik Just * * All Rights Reserved. * - * Version 1.2 (2011-02-25) + * Version 1.6 (2014-12-16) * */ @@ -392,6 +392,27 @@ public abstract class DialogBase implements } } + 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 + } + } + protected String getFormattedFieldText(String sControlName) { XPropertySet xPropertySet = getControlProperties(sControlName); try { diff --git a/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java b/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java index 696bf54..fdf72f7 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java +++ b/source/java/org/openoffice/da/comp/writer2latex/BibTeXDialog.java @@ -20,21 +20,31 @@ * * All Rights Reserved. * - * Version 1.6 (2014-12-11) + * Version 1.6 (2014-12-27) * */ package org.openoffice.da.comp.writer2latex; +import java.awt.Desktop; +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; import com.sun.star.awt.XDialog; +import com.sun.star.frame.XFrame; +import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; +import org.jbibtex.ParseException; 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; /** This class provides a UNO dialog to insert a BibTeX bibliographic reference */ -public class BibTeXDialog extends DialogBase { - //implements com.sun.star.lang.XInitialization { +public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XInitialization { /** The component will be registered under this name. */ @@ -49,7 +59,19 @@ public class BibTeXDialog extends DialogBase { public String getDialogLibraryName() { return "W4LDialogs"; } - + + // The current frame (passed at initialization) + XFrame xFrame = null; + + // The BibTeX directory (passed at initialization) + File bibTeXDirectory = null; + + // Cache of BibTeX files in the BibTeX directory + File[] files = null; + + // Cache of the current BibTeX file + BibTeXReader currentFile = null; + /** Return the name of the dialog within the library */ public String getDialogName() { @@ -57,6 +79,7 @@ public class BibTeXDialog extends DialogBase { } public void initialize() { + refresh(); } public void endDialog() { @@ -68,19 +91,216 @@ public class BibTeXDialog extends DialogBase { } // Implement com.sun.star.lang.XInitialization - /*public void initialize( Object[] object ) + // We expect to get the current frame and a comma separated list of BibTeX files to use + public void initialize( Object[] objects ) throws com.sun.star.uno.Exception { - }*/ + for (Object object : objects) { + if (object instanceof XFrame) { + xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, object); + } + if (object instanceof String) { + bibTeXDirectory = new File((String) object); + } + } + } // Implement XDialogEventHandler public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) { + if (sMethod.equals("FileChange")) { + fileChange(); + } + else if (sMethod.equals("EntryChange")) { + entryChange(); + } + else if (sMethod.equals("InsertReference")) { + insertReference(); + } + else if (sMethod.equals("Edit")) { + edit(); + } + else if (sMethod.equals("Refresh")) { + refresh(); + } return true; } public String[] getSupportedMethodNames() { - String[] sNames = { }; + String[] sNames = { "FileChange", "EntryChange", "InsertReference", "Edit", "Refresh" }; return sNames; } - - + + // (Re)load the list of BibTeX files + private void refresh() { + // Remember current file selection, if any + String sFile = null; + short nFile = getListBoxSelectedItem("File"); + if (nFile>=0 && files[nFile]!=null) { + sFile = getListBoxStringItemList("File")[nFile]; + } + + if (bibTeXDirectory!=null && bibTeXDirectory.isDirectory()) { + // Populate the file list based on the BibTeX directory + files = bibTeXDirectory.listFiles( + new FilenameFilter() { + public boolean accept(File file, String sName) { return sName!=null && sName.endsWith(".bib"); } + } + ); + int nFileCount = files.length; + String[] sFileNames = new String[nFileCount]; + + // Select either the first or the previous item + nFile = 0; + for (short i=0; i0) { + setControlEnabled("FileLabel",true); + setControlEnabled("File",true); + setControlEnabled("EntryLabel",true); + setControlEnabled("Entry",true); + setControlEnabled("Edit",true); + setControlEnabled("Insert",true); + + fileChange(); + + return; + } + } + + // The directory did not contain any BibTeX files + setControlEnabled("FileLabel",false); + setControlEnabled("File",false); + setControlEnabled("EntryLabel",false); + setControlEnabled("Entry",false); + setControlEnabled("Edit",false); + setControlEnabled("Insert",false); + setLabelText("EntryInformation","No BibTeX files were found"); + } + + // Update the list of entries based on the current selection in the file list + private void fileChange() { + // Remember current entry selection, if any + String sEntry = null; + short nEntry = getListBoxSelectedItem("Entry"); + if (nEntry>=0) { + sEntry = getListBoxStringItemList("Entry")[nEntry]; + } + + // Parse the selected file + int nFile = getListBoxSelectedItem("File"); + if (nFile>=0) { + try { + currentFile = new BibTeXReader(files[nFile]); + } catch (IOException e) { + currentFile = null; + } catch (ParseException e) { + currentFile = null; + } + + if (currentFile!=null) { + // Populate the entry list with the keys from the current file, if any + String[] sCurrentKeys = currentFile.getEntries().keySet().toArray(new String[0]); + setListBoxStringItemList("Entry", sCurrentKeys); + if (sCurrentKeys.length>0) { + // Select either the first or the previous entry + nEntry = 0; + if (sEntry!=null) { + int nEntryCount = sCurrentKeys.length; + for (short i=0; i=0) { + String[] sCurrentKeys = getListBoxStringItemList("Entry"); + String sKey = sCurrentKeys[nEntry]; + bibMark = currentFile.getEntries().get(sKey); + } + return bibMark; + } + + // Edit the current BibTeX file + private void edit() { + int nFile = getListBoxSelectedItem("File"); + if (nFile>=0) { + if (files[nFile].exists()) { + // Open the file in the default application on this system (if any) + if (Desktop.isDesktopSupported()) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.open(files[nFile]); + } catch (IOException e) { + System.err.println(e.getMessage()); + } + } + else if (xFrame!=null) { + MessageBox msgBox = new MessageBox(xContext, xFrame); + msgBox.showMessage("Writer2LaTeX","Error: No BibTeX editor was found"); + } + } + } + } + } \ No newline at end of file diff --git a/source/java/org/openoffice/da/comp/writer2latex/BibTeXReader.java b/source/java/org/openoffice/da/comp/writer2latex/BibTeXReader.java index d9141a4..e85d9bb 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/BibTeXReader.java +++ b/source/java/org/openoffice/da/comp/writer2latex/BibTeXReader.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2014-11-24) + * Version 1.6 (2014-12-27) * */ @@ -55,18 +55,34 @@ import writer2latex.office.BibMark.EntryType; */ public class BibTeXReader { + private File file; private Map entries; - - /** - * Construct a new BibTeXReader based on a file + + /** Construct a new BibTeXReader based on a file * * @param file the file to read * @throws IOException if any error occurs reading the file * @throws ParseException if any error occurs interpreting the contents of the file */ public BibTeXReader(File file) throws IOException, ParseException { + this.file = file; + reload(); + } + + /** Parse the contents of the file, replacing any previous entries in this BibTeXReader + */ + public void reload() throws IOException, ParseException { + entries = new HashMap(); BibTeXDatabase database = parseBibTeX(file); - readEntries(database); + readEntries(database); + } + + /** Get the file associated with this BibTeXReader + * + * @return the file + */ + public File getFile() { + return file; } /** Get the entries of this BibTeX file @@ -77,7 +93,7 @@ public class BibTeXReader { return entries; } - private static BibTeXDatabase parseBibTeX(File file) throws IOException, ParseException { + private static BibTeXDatabase parseBibTeX(File file) throws ParseException, IOException { Reader reader = new FileReader(file); try { BibTeXParser parser = new BibTeXParser() { @@ -102,8 +118,7 @@ public class BibTeXReader { } } - private void readEntries(BibTeXDatabase database) throws IOException { - entries = new HashMap(); + private void readEntries(BibTeXDatabase database) { Map entryMap = database.getEntries(); Collection bibentries = entryMap.values(); @@ -124,7 +139,7 @@ public class BibTeXReader { } } - private static String parseLaTeX(String string) throws IOException { + private static String parseLaTeX(String string) { Reader reader = new StringReader(string); try { LaTeXParser parser = new LaTeXParser(); @@ -134,7 +149,11 @@ public class BibTeXReader { // If parsing fails, return the original string return string; } finally { - reader.close(); + try { + reader.close(); + } catch (IOException e) { + // Reading from a String will not fail :-) + } } } diff --git a/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java b/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java index 56f5adb..1cfdc4c 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java +++ b/source/java/org/openoffice/da/comp/writer2latex/LaTeXUNOPublisher.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2014-11-03) + * Version 1.6 (2014-12-27) * */ package org.openoffice.da.comp.writer2latex; @@ -55,7 +55,26 @@ public class LaTeXUNOPublisher extends UNOPublisher { super(xContext, xFrame, sAppName); } - /** Make a file name LaTeX friendly + /** Get the directory containing the BibTeX files (as defined in the registry) + * + * @return the directory + */ + public File getBibTeXDirectory() { + // Get the BibTeX settings from the registry + RegistryHelper registry = new RegistryHelper(xContext); + Object view; + try { + view = registry.getRegistryView(BibliographyDialog.REGISTRY_PATH, false); + } catch (Exception e) { + // Failed to get registry settings + return null; + } + XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view); + return getDirectory(XPropertySetHelper.getPropertyValueAsShort(xProps, "BibTeXLocation"), + XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir")); + } + + /** Make a file name LaTeX friendly */ @Override protected String filterFileName(String sFileName) { String sResult = ""; @@ -229,31 +248,35 @@ public class LaTeXUNOPublisher extends UNOPublisher { } } - private String getFileList(short nType, String sDirectory) { - File dir; + private File getDirectory(short nType, String sDirectory) { switch (nType) { case 0: // absolute path - dir = new File(sDirectory); - break; + return new File(sDirectory); case 1: // relative path - dir = new File(Misc.urlToFile(getTargetPath()),sDirectory); - break; + return new File(Misc.urlToFile(getTargetPath()),sDirectory); default: // document directory - dir = Misc.urlToFile(getTargetPath()); + return Misc.urlToFile(getTargetPath()); } - - CSVList filelist = new CSVList(","); + } + + private String getFileList(short nType, String sDirectory) { + File dir = getDirectory(nType,sDirectory); + File[] files; if (dir.isDirectory()) { - File[] files = dir.listFiles(); + files = dir.listFiles(); + } + else { + return null; + } + CSVList filelist = new CSVList(","); + if (files!=null) { for (File file : files) { if (file.isFile() && file.getName().endsWith(".bib")) { - //filelist.addValue(file.getAbsolutePath()); filelist.addValue(Misc.removeExtension(file.getName())); } } } - String sFileList = filelist.toString(); - return sFileList.length()>0 ? sFileList : "dummy"; + return filelist.toString(); } } diff --git a/source/java/org/openoffice/da/comp/writer2latex/Writer2LaTeX.java b/source/java/org/openoffice/da/comp/writer2latex/Writer2LaTeX.java index 97e1b45..c1472c6 100644 --- a/source/java/org/openoffice/da/comp/writer2latex/Writer2LaTeX.java +++ b/source/java/org/openoffice/da/comp/writer2latex/Writer2LaTeX.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2014-12-11) + * Version 1.6 (2014-12-27) * */ @@ -175,19 +175,26 @@ public final class Writer2LaTeX extends WeakBase } private void insertBibTeX() { - // Execute the BibTeX dialog - try { - Object dialog = m_xContext.getServiceManager() - .createInstanceWithContext( - "org.openoffice.da.writer2latex.BibTeXDialog", m_xContext); - XExecutableDialog xDialog = (XExecutableDialog) - UnoRuntime.queryInterface(XExecutableDialog.class, dialog); - if (xDialog.execute()==ExecutableDialogResults.OK) { - // Closed with the close button - } - } - catch (com.sun.star.uno.Exception e) { - } + createUNOPublisher(); + if (unoPublisher.documentSaved()) { + // Execute the BibTeX dialog + try { + // The dialog needs the current frame and the path to the BibTeX directory + Object[] args = new Object[2]; + args[0] = m_xFrame; + args[1] = unoPublisher.getBibTeXDirectory().getPath(); + Object dialog = m_xContext.getServiceManager() + .createInstanceWithArgumentsAndContext( + "org.openoffice.da.writer2latex.BibTeXDialog", args, m_xContext); + XExecutableDialog xDialog = (XExecutableDialog) + UnoRuntime.queryInterface(XExecutableDialog.class, dialog); + if (xDialog.execute()==ExecutableDialogResults.OK) { + // Closed with the close button + } + } + catch (com.sun.star.uno.Exception e) { + } + } } private void createUNOPublisher() { diff --git a/source/java/writer2latex/bibtex/BibTeXEntryMap.java b/source/java/writer2latex/bibtex/BibTeXEntryMap.java index e3ebf28..383c2d8 100644 --- a/source/java/writer2latex/bibtex/BibTeXEntryMap.java +++ b/source/java/writer2latex/bibtex/BibTeXEntryMap.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.6 (2014-11-28) + * Version 1.6 (2014-12-16) * */ package writer2latex.bibtex; @@ -104,6 +104,7 @@ public class BibTeXEntryMap { if (bibTeXFields == null) { createMaps(); } + sFieldName = sFieldName.toLowerCase(); return entryTypes.containsKey(sFieldName) ? entryTypes.get(sFieldName) : null; } } diff --git a/source/oxt/writer2latex/W4LDialogs/BibTeXEntry.xdl b/source/oxt/writer2latex/W4LDialogs/BibTeXEntry.xdl index aff8a93..1857c85 100644 --- a/source/oxt/writer2latex/W4LDialogs/BibTeXEntry.xdl +++ b/source/oxt/writer2latex/W4LDialogs/BibTeXEntry.xdl @@ -1,14 +1,26 @@ - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/oxt/writer2latex/help/en/help.tree b/source/oxt/writer2latex/help/en/help.tree index a1548af..179ed87 100644 --- a/source/oxt/writer2latex/help/en/help.tree +++ b/source/oxt/writer2latex/help/en/help.tree @@ -3,6 +3,7 @@ Introduction Menu and toolbar + BibTeX references LaTeX export View log files diff --git a/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibliography.xhp b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibliography.xhp index 54732f9..8153364 100644 --- a/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibliography.xhp +++ b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibliography.xhp @@ -20,18 +20,20 @@ If you use the standard bibliographic tool provided by %PRODUCTNAME, Writer2LaTeX can convert the references to BibTeX if you choose to do so in the export dialog. In this case you should not make any settings on this page. + You may also use the Writer2LaTeX toolbar to insert bibliographic references from + BibTeX files. In this case Writer2LaTeX can be configured to use the original BibTeX files. + To use this feature, you have to define the location of your BibTeX files. + You may also use other tools such as Zotero or JabRef to handle your citations. If you want to use BibTeX to format references inserted by these tools, Writer2LaTeX can convert them for you. In this case you have to define the location of the BibTeX files produced by Zotero or JabRef. Use external BibTeX files for ordinary citations - Check this if the citations in your document refers to one or more external BibTeX files. - (The keys used in the document must match up with the keys in the external BibTeX files.) - This feature is for advanced users that maintain their references in BibTeX. - It enables you to use the original BibTeX files in the LaTeX document rather than converting the inserted - references back into BibTeX. - Check this if your citations refer to external BibTeX file(s) + Check this if you use the Writer2LaTeX toolbar to insert bibliographic references from BibTeX files. + This enables you to use the original BibTeX files in the LaTeX document rather than converting the + inserted references back into BibTeX. + Check this if your citatations are inserted from BibTeX file(s) Convert Zotero citations @@ -122,7 +124,5 @@ Enter any options to the package natbib.sty here. Enter any options to the package natbib.sty here - - \ No newline at end of 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 new file mode 100644 index 0000000..723e8af --- /dev/null +++ b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/bibtex.xhp @@ -0,0 +1,66 @@ + + + + + Insert BibTeX reference + org.openoffice.da.writer2latex.oxt/bibtex.xhp + + + + + Insert BibTeX reference + Insert a bibliographic reference to an item in a BibTeX file. +
+ Click the Bib-button on the toolbar +
+ + BibTeX is the standard database format for bibliographic references in LaTeX. + This 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 biblipography 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. + + + File + Select the BibTeX file to use in this list. + Select the BibTeX file to use + + + Entry + 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 + + + Insert reference + Click this button to insert a bibliographic reference to + the currently selected entry. + Click to insert a reference to the current entry + + + Cancel + Click this button to close the dialog without inserting any references. + Click to close the dialog + + + Edit... + Click this button to edit the currently selected BibTeX file. + The file will open in your default BibTeX editor. If no default BibTeX editor was found on your system, + an error message is displayed. + Click to edit the current file in your BibTeX editor + + + Refresh + Click this button to reload the BibTeX + files. You should do this if you have edited a BibTeX file. + Click to refresh the contents of the lists + +
\ No newline at end of file diff --git a/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/menu.xhp b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/menu.xhp index f352e8f..a541884 100644 --- a/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/menu.xhp +++ b/source/oxt/writer2latex/help/en/org.openoffice.da.writer2latex.oxt/menu.xhp @@ -32,10 +32,11 @@ Writer2LaTeX adds a toolbar in Writer, providing the following commands. - Insert BibTeX reference + Insert BibTeX reference - Insert a reference to an item in a BibTeX file. + Insert a bibliographic reference to an item in a BibTeX file. Insert reference to an item in a BibTeX file