Support EPUB style resources - a few bugfixes and improvements
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@109 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
ef05312e21
commit
8e07ca2338
6 changed files with 97 additions and 45 deletions
|
@ -16,16 +16,17 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-04-12)
|
||||
* Version 1.2 (2010-06-11)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
|
@ -35,7 +36,10 @@ import com.sun.star.uno.XComponentContext;
|
|||
|
||||
public class FilePicker {
|
||||
|
||||
private XComponentContext xContext;
|
||||
private XComponentContext xContext;
|
||||
|
||||
// The default directory for the dialog
|
||||
private String sDirectoryURL;
|
||||
|
||||
/** Convenience wrapper class for the UNO file picker service
|
||||
*
|
||||
|
@ -43,41 +47,81 @@ public class FilePicker {
|
|||
*/
|
||||
public FilePicker(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
sDirectoryURL = null;
|
||||
}
|
||||
|
||||
/** Get one or more user selected paths with a file picker
|
||||
*
|
||||
* Warning: This does not work on all platforms when using native file pickers
|
||||
* (but always when using Office file pickers)
|
||||
*
|
||||
* @return array containing the path URLs or null if the dialog is canceled
|
||||
*/
|
||||
public String[] getPaths() {
|
||||
return getPaths(true);
|
||||
}
|
||||
|
||||
/** Get a user selected path with a file picker
|
||||
*
|
||||
* @return the path or null if the dialog is canceled
|
||||
* @return the path URL or null if the dialog is canceled
|
||||
*/
|
||||
public String getPath() {
|
||||
String[] sPaths = getPaths(false);
|
||||
if (sPaths!=null && sPaths.length>0) {
|
||||
return sPaths[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String[] getPaths(boolean bAllowMultiSelection) {
|
||||
// Create FilePicker
|
||||
Object filePicker = null;
|
||||
try {
|
||||
// Note: Could be changed for OfficeFilePicker to always use internal file pickers
|
||||
filePicker = xContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FilePicker", xContext);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Display the FilePicker
|
||||
// Get the required interfaces
|
||||
XFilePicker xFilePicker = (XFilePicker) UnoRuntime.queryInterface(XFilePicker.class, filePicker);
|
||||
XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, xFilePicker);
|
||||
|
||||
// Get the path
|
||||
String sPath = null;
|
||||
|
||||
// Configure the file picker
|
||||
xFilePicker.setMultiSelectionMode(bAllowMultiSelection);
|
||||
if (sDirectoryURL!=null) {
|
||||
try {
|
||||
xFilePicker.setDisplayDirectory(sDirectoryURL);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the paths
|
||||
String[] sPaths = null;
|
||||
if (xExecutable.execute() == ExecutableDialogResults.OK) {
|
||||
sDirectoryURL = xFilePicker.getDisplayDirectory();
|
||||
String[] sPathList = xFilePicker.getFiles();
|
||||
if (sPathList.length > 0) {
|
||||
sPath = sPathList[0];
|
||||
}
|
||||
int nCount = sPathList.length;
|
||||
if (nCount>1) {
|
||||
// According to the spec, the first entry is the path and remaining entries are file names
|
||||
sPaths = new String[nCount-1];
|
||||
for (int i=1; i<nCount; i++) {
|
||||
sPaths[i-1]=sPathList[0] + sPathList[i];
|
||||
System.out.println("File "+sPaths[i-1]);
|
||||
}
|
||||
}
|
||||
else if (nCount==1) {
|
||||
sPaths = sPathList;
|
||||
}
|
||||
}
|
||||
|
||||
// Dispose the file picker
|
||||
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xFilePicker);
|
||||
xComponent.dispose();
|
||||
|
||||
return sPath;
|
||||
return sPaths;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue