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,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");