BibTeX support

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@232 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2015-03-12 11:46:52 +00:00
parent e16d5edd12
commit 9afccba92a
9 changed files with 242 additions and 163 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-02-15)
* Version 1.6 (2015-02-18)
*
*/
@ -131,7 +131,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
}
@Override public void initialize() {
refreshDialog(null);
reload(null);
}
@Override public void endDialog() {
@ -148,10 +148,6 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
// 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();
@ -160,23 +156,30 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
// Edit the current BibTeX file
edit();
}
else if (sMethod.equals("Refresh")) {
// Refresh the dialog and update all bibliographic references
refreshDialog(null);
refreshReferences();
else if (sMethod.equals("Reload")) {
// Reload the BibTeX files in the dialog
reload(null);
}
else if (sMethod.equals("InsertReference")) {
// Insert a reference to the current BibTeX entry
insertReference();
}
else if (sMethod.equals("Update")) {
// Update all reference in the document
update();
}
return true;
}
@Override public String[] getSupportedMethodNames() {
String[] sNames = { "FileChange", "EntryChange", "InsertReference", "Edit", "Refresh" };
String[] sNames = { "FileChange", "EntryChange", "New", "Edit", "Reload", "InsertReference", "Update" };
return sNames;
}
// **** Implement the UI functions
// (Re)load the list of BibTeX files
private void refreshDialog(String sSelectedFileName) {
private void reload(String sSelectedFileName) {
String sFile = null;
if (sSelectedFileName!=null) {
// Select a new file name
@ -217,6 +220,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
setControlEnabled("Entry",true);
setControlEnabled("Edit",true);
setControlEnabled("Insert",true);
setControlEnabled("Update",true);
fileChange();
@ -231,6 +235,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
setControlEnabled("Entry",false);
setControlEnabled("Edit",false);
setControlEnabled("Insert",false);
setControlEnabled("Update",false);
setLabelText("EntryInformation","No BibTeX files were found");
}
@ -251,6 +256,7 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
} catch (IOException e) {
currentFile = null;
} catch (ParseException e) {
System.out.println(e.getMessage());
currentFile = null;
}
@ -322,15 +328,21 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
private void newFile() {
String sFileName = getFileName();
if (sFileName!=null) {
File file = new File(bibTeXDirectory,sFileName);
try {
if (!file.createNewFile() && xFrame!=null) {
MessageBox msgBox = new MessageBox(xContext, xFrame);
msgBox.showMessage("Writer2LaTeX","The file "+sFileName+" already exists");
}
refreshDialog(sFileName);
} catch (IOException e) {
}
if (!sFileName.equals(".bib")) {
File file = new File(bibTeXDirectory,sFileName);
try {
if (!file.createNewFile() && xFrame!=null) {
MessageBox msgBox = new MessageBox(xContext, xFrame);
msgBox.showMessage("Writer2LaTeX","The file "+sFileName+" already exists");
}
reload(sFileName);
} catch (IOException e) {
}
}
else if (xFrame!=null) {
MessageBox msgBox = new MessageBox(xContext, xFrame);
msgBox.showMessage("Writer2LaTeX","The file name is empty");
}
}
}
@ -412,8 +424,8 @@ public class BibTeXDialog extends DialogBase implements com.sun.star.lang.XIniti
}
}
// Refresh all bibliographic fields in the document
private void refreshReferences() {
// Update all bibliographic fields in the document
private void update() {
if (xFrame!=null) {
BibTeXReader[] readers = parseAllBibTeXFiles();

View file

@ -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-10-29)
* Version 1.6 (2015-02-18)
*
*/
@ -254,16 +254,18 @@ public final class BibliographyDialog
}
private void enableBibTeXSettings(DialogAccess dlg) {
boolean bConvertZoteroJabRef = dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations")
boolean bEnableSettings = dlg.getCheckBoxStateAsBoolean("UseExternalBibTeXFiles");
boolean bEnableOriginalCitations = dlg.getCheckBoxStateAsBoolean("ConvertZoteroCitations")
|| dlg.getCheckBoxStateAsBoolean("ConvertJabRefCitations");
boolean bEnableLocation = dlg.getCheckBoxStateAsBoolean("UseExternalBibTeXFiles") || bConvertZoteroJabRef;
boolean bEnableDir = dlg.getListBoxSelectedItem("BibTeXLocation")<2;
dlg.setControlEnabled("IncludeOriginalCitations", bConvertZoteroJabRef);
dlg.setControlEnabled("BibTeXLocationLabel", bEnableLocation);
dlg.setControlEnabled("BibTeXLocation", bEnableLocation);
dlg.setControlEnabled("BibTeXDirLabel", bEnableLocation && bEnableDir);
dlg.setControlEnabled("BibTeXDir", bEnableLocation && bEnableDir);
dlg.setControlEnabled("BibTeXDirButton", bEnableLocation && bEnableDir);
dlg.setControlEnabled("BibTeXLocationLabel", bEnableSettings);
dlg.setControlEnabled("BibTeXLocation", bEnableSettings);
dlg.setControlEnabled("BibTeXDirLabel", bEnableSettings && bEnableDir);
dlg.setControlEnabled("BibTeXDir", bEnableSettings && bEnableDir);
dlg.setControlEnabled("BibTeXDirButton", bEnableSettings && bEnableDir);
dlg.setControlEnabled("ConvertZoteroCitations", bEnableSettings);
dlg.setControlEnabled("ConvertJabRefCitations", bEnableSettings);
dlg.setControlEnabled("IncludeOriginalCitations", bEnableSettings && bEnableOriginalCitations);
}
private String getDocumentDirURL() {

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-02-16)
* Version 1.6 (2015-02-18)
*
*/
package org.openoffice.da.comp.writer2latex;
@ -105,14 +105,14 @@ public class LaTeXUNOPublisher extends UNOPublisher {
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
String sBibTeXFiles = getFileList(XPropertySetHelper.getPropertyValueAsShort(xProps, "BibTeXLocation"),
XPropertySetHelper.getPropertyValueAsString(xProps, "BibTeXDir"));
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations")) {
filterHelper.put("zotero_bibtex_files", sBibTeXFiles);
}
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertJabRefCitations")) {
filterHelper.put("jabref_bibtex_files", sBibTeXFiles);
}
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseExternalBibTeXFiles")) {
filterHelper.put("external_bibtex_files", sBibTeXFiles);
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertZoteroCitations")) {
filterHelper.put("zotero_bibtex_files", sBibTeXFiles);
}
if (XPropertySetHelper.getPropertyValueAsBoolean(xProps, "ConvertJabRefCitations")) {
filterHelper.put("jabref_bibtex_files", sBibTeXFiles);
}
}
filterHelper.put("include_original_citations",
Boolean.toString(XPropertySetHelper.getPropertyValueAsBoolean(xProps, "IncludeOriginalCitations")));

View file

@ -20,20 +20,25 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-02-09)
* Version 1.6 (2015-02-18)
*
*/
package org.openoffice.da.comp.writer2latex;
import com.sun.star.beans.XPropertySet;
import com.sun.star.frame.XFrame;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.ui.dialogs.ExecutableDialogResults;
import com.sun.star.ui.dialogs.XExecutableDialog;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher.TargetFormat;
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
/** This class implements the ui (dispatch) commands provided by the Writer2LaTeX toolbar.
* The actual processing is done by the core classes <code>UNOPublisher</code>,
@ -175,28 +180,48 @@ public final class Writer2LaTeX extends WeakBase
}
private void insertBibTeX() {
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) {
}
}
if (useExternalBibTeXFiles()) {
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) {
}
}
}
else {
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
msgBox.showMessage("Writer2LaTeX","Writer2LaTeX is not configured to use external BibTeX files for citations");
}
}
private boolean useExternalBibTeXFiles() {
// Get the BibTeX settings from the registry
RegistryHelper registry = new RegistryHelper(m_xContext);
Object view;
try {
view = registry.getRegistryView(BibliographyDialog.REGISTRY_PATH, false);
} catch (Exception e) {
// Failed to get registry settings
return false;
}
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
return XPropertySetHelper.getPropertyValueAsBoolean(xProps, "UseExternalBibTeXFiles");
}
private void createUNOPublisher() {
if (unoPublisher==null) {
unoPublisher = new LaTeXUNOPublisher(m_xContext,m_xFrame,"Writer2LaTeX");