Config ui + Writer4LaTeX

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@41 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-11-23 20:47:45 +00:00
parent 97144ad818
commit 04ed9dae7a
23 changed files with 886 additions and 239 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-06-19)
* Version 1.2 (2009-11-19)
*
*/
@ -35,9 +35,12 @@ import com.sun.star.awt.XControl;
import com.sun.star.awt.XControlContainer;
import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XContainerWindowEventHandler;
import com.sun.star.awt.XDialog;
import com.sun.star.awt.XDialogProvider2;
import com.sun.star.awt.XWindow;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.ui.dialogs.ExecutableDialogResults;
import com.sun.star.ui.dialogs.XExecutableDialog;
@ -48,6 +51,8 @@ import com.sun.star.uno.XComponentContext;
import com.sun.star.lib.uno.helper.WeakBase;
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
/** This class provides a uno component which implements the configuration
* of Writer4LaTeX
*/
@ -247,12 +252,30 @@ public final class ConfigurationDialog
}
}
// Unix: Configure a certain application, reporting the availability
private boolean configureApp(String sName, String sAppName, String sArguments, StringBuffer info) {
if (hasApp(sAppName)) {
externalApps.setApplication(sName, sAppName, sArguments);
info.append("Found "+sAppName+" - OK\n");
return true;
}
else {
externalApps.setApplication(sName, "???", "???");
info.append("Failed to find "+sAppName+"\n");
return false;
}
}
// Unix: Configure a certain application testing the availability
// This variant uses an array of potential apps
private boolean configureApp(String sName, String[] sAppNames, String sArguments) {
private boolean configureApp(String sName, String[] sAppNames, String sArguments, StringBuffer info) {
for (String sAppName : sAppNames) {
if (configureApp(sName, sAppName, sArguments)) { return true; }
if (configureApp(sName, sAppName, sArguments)) {
info.append("Found "+sName+": "+sAppName+" - OK\n");
return true;
}
}
info.append("Failed to find "+sName+"\n");
return false;
}
@ -273,23 +296,28 @@ public final class ConfigurationDialog
// And assume gsview for pdf and ps
// gsview32 may not be in the path, but at least this helps a bit
externalApps.setApplication(ExternalApps.PDFVIEWER, "gsview32.exe", "-e \"%s\"");
externalApps.setApplication(ExternalApps.POSTSCRIPTVIEWER, "gsview32.exe", "-e \"%s\"");
externalApps.setApplication(ExternalApps.POSTSCRIPTVIEWER, "gsview32.exe", "-e \"%s\"");
displayAutoConfigInfo("Configured for MikTeX...");
}
else { // Assume a unix-like system supporting the "which" command
configureApp(ExternalApps.LATEX, "latex", "--interaction=batchmode %s");
configureApp(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s");
configureApp(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s");
configureApp(ExternalApps.DVIPS, "dvips", "%s");
configureApp(ExternalApps.BIBTEX, "bibtex", "%s");
configureApp(ExternalApps.MAKEINDEX, "makeindex", "%s");
configureApp(ExternalApps.MK4HT, "mk4ht", "%c %s");
StringBuffer info = new StringBuffer();
info.append("Results of configuration:\n\n");
configureApp(ExternalApps.LATEX, "latex", "--interaction=batchmode %s",info);
configureApp(ExternalApps.PDFLATEX, "pdflatex", "--interaction=batchmode %s",info);
configureApp(ExternalApps.XELATEX, "xelatex", "--interaction=batchmode %s",info);
configureApp(ExternalApps.DVIPS, "dvips", "%s",info);
configureApp(ExternalApps.BIBTEX, "bibtex", "%s",info);
configureApp(ExternalApps.MAKEINDEX, "makeindex", "%s",info);
configureApp(ExternalApps.MK4HT, "mk4ht", "%c %s",info);
// We have several possible viewers
String[] sDviViewers = {"evince", "okular", "xdvi"};
configureApp(ExternalApps.DVIVIEWER, sDviViewers, "%s");
configureApp(ExternalApps.DVIVIEWER, sDviViewers, "%s",info);
String[] sPdfViewers = {"evince", "okular", "xpdf"};
configureApp(ExternalApps.PDFVIEWER, sPdfViewers, "%s");
configureApp(ExternalApps.PDFVIEWER, sPdfViewers, "%s",info);
String[] sPsViewers = {"evince", "okular", "ghostview"};
configureApp(ExternalApps.POSTSCRIPTVIEWER, sPsViewers, "%s");
configureApp(ExternalApps.POSTSCRIPTVIEWER, sPsViewers, "%s",info);
displayAutoConfigInfo(info.toString());
}
changeApplication(xWindow);
return true;
@ -313,6 +341,32 @@ public final class ConfigurationDialog
return "???";
}
private XDialog getDialog(String sDialogName) {
XMultiComponentFactory xMCF = xContext.getServiceManager();
try {
Object provider = xMCF.createInstanceWithContext(
"com.sun.star.awt.DialogProvider2", xContext);
XDialogProvider2 xDialogProvider = (XDialogProvider2)
UnoRuntime.queryInterface(XDialogProvider2.class, provider);
String sDialogUrl = "vnd.sun.star.script:"+sDialogName+"?location=application";
return xDialogProvider.createDialogWithHandler(sDialogUrl, this);
}
catch (Exception e) {
return null;
}
}
private void displayAutoConfigInfo(String sText) {
XDialog xDialog = getDialog("W4LDialogs.AutoConfigInfo");
if (xDialog!=null) {
DialogAccess info = new DialogAccess(xDialog);
info.setTextFieldText("Info", sText);
xDialog.execute();
xDialog.endExecute();
}
}
// Some helpers copied from DialogBase
private XPropertySet getControlProperties(XWindow xWindow, String sControlName) {
XControlContainer xContainer = (XControlContainer)

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-06-19)
* Version 1.2 (2009-11-19)
*
*/

View file

@ -77,8 +77,9 @@ public final class TeXify {
* @param nBackend the desired backend format (generic, dvips, pdftex)
* @param bView set the true if the result should be displayed in the viewer
* @throws IOException if the document cannot be read
* @return true if the first LaTeX run was succesful
*/
public void process(File file, short nBackend, boolean bView) throws IOException {
public boolean process(File file, short nBackend, boolean bView) throws IOException {
// Remove extension from file
if (file.getName().endsWith(".tex")) {
file = new File(file.getParentFile(),
@ -89,8 +90,10 @@ public final class TeXify {
externalApps.load();
// Process LaTeX document
boolean bResult = false;
if (nBackend==GENERIC) {
doTeXify(genericTexify, file);
bResult = doTeXify(genericTexify, file);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.DVIVIEWER,
new File(file.getParentFile(),file.getName()+".dvi").getPath(),
file.getParentFile(), false)>0) {
@ -98,7 +101,8 @@ public final class TeXify {
}
}
else if (nBackend==PDFTEX) {
doTeXify(pdfTexify, file);
bResult = doTeXify(pdfTexify, file);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.PDFVIEWER,
new File(file.getParentFile(),file.getName()+".pdf").getPath(),
file.getParentFile(), false)>0) {
@ -106,7 +110,8 @@ public final class TeXify {
}
}
else if (nBackend==DVIPS) {
doTeXify(dvipsTexify, file);
bResult = doTeXify(dvipsTexify, file);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.POSTSCRIPTVIEWER,
new File(file.getParentFile(),file.getName()+".ps").getPath(),
file.getParentFile(), false)>0) {
@ -114,25 +119,30 @@ public final class TeXify {
}
}
else if (nBackend==XETEX) {
doTeXify(xeTexify, file);
bResult = doTeXify(xeTexify, file);
if (!bResult) return false;
if (externalApps.execute(ExternalApps.PDFVIEWER,
new File(file.getParentFile(),file.getName()+".pdf").getPath(),
file.getParentFile(), false)>0) {
throw new IOException("Error executing pdf viewer");
}
}
return bResult;
}
private void doTeXify(String[] sAppList, File file) throws IOException {
private boolean doTeXify(String[] sAppList, File file) throws IOException {
for (int i=0; i<sAppList.length; i++) {
// Execute external application
int nReturnCode = externalApps.execute(
sAppList[i], file.getName(), file.getParentFile(), true);
if (nReturnCode>0) {
System.out.println("Return code from "+sAppList[i]+": "+nReturnCode);
if (i==0 && nReturnCode>0) {
return false;
//throw new IOException("Error executing "+sAppList[i]);
}
}
return true;
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2009-06-19)
* Version 1.2 (2009-11-19)
*
*/
@ -223,27 +223,35 @@ public final class Writer4LaTeX extends WeakBase
if (texify==null) { texify = new TeXify(m_xContext); }
File file = new File(urlToFile(sBasePath),sBaseFileName);
boolean bResult = true;
try {
if (sBackend=="pdftex") {
texify.process(file, TeXify.PDFTEX, true);
bResult = texify.process(file, TeXify.PDFTEX, true);
}
else if (sBackend=="dvips") {
texify.process(file, TeXify.DVIPS, true);
bResult = texify.process(file, TeXify.DVIPS, true);
}
else if (sBackend=="xetex") {
texify.process(file, TeXify.XETEX, true);
bResult = texify.process(file, TeXify.XETEX, true);
}
else if (sBackend=="generic") {
texify.process(file, TeXify.GENERIC, true);
bResult = texify.process(file, TeXify.GENERIC, true);
}
}
catch (IOException e) {
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
msgBox.showMessage("Writer4LaTeX Error",e.getMessage());
}
xStatus.setValue(10); // The user will not really see this...
xStatus.setValue(10); // The user will usually not see this...
if (!bResult) {
MessageBox msgBox = new MessageBox(m_xContext, m_xFrame);
msgBox.showMessage("Writer4LaTeX Error","Failed to execute LaTeX - see log for details");
}
xStatus.end();
}