Hal Vaughan wrote:
A couple file related questions:

1) I'm working on Linux, but I want this to work on Windows as well. When I concatenate a file name I have to use "/" to separate directories. Is there a way I can specify something like Java's "File.separator" that will be translated appropriately depending on the OS?
This uses URLs, and then you can use ConvertFromURL to convert to a regular path based on your system. Also, the file operations, I think will tell you which separator to use. Call getPathSeparator(), I do not remember if it is built-in or if it is in the Tools library.

Sub ExampleGetAFileName
 Dim filterNames(1) As String
 filterNames(0) = "*.txt"
 filterNames(1) = "*.sxw"
 Print GetAFileName(filterNames())
End Sub

Function GetAFileName(Filternames()) As String
 Dim oFileDialog as Object
 Dim iAccept as Integer
 Dim sPath as String
 Dim InitPath as String
 Dim RefControlName as String
 Dim oUcb as object
 'Dim ListAny(0)

 GlobalScope.BasicLibraries.LoadLibrary("Tools")
 'Note: The following services must be called in the following order,
 ' otherwise the FileDialog Service is not removed.
 oFileDialog = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
 oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
 'ListAny(0) = _
 ' com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
 'oFileDialog.initialize(ListAny())
 AddFiltersToDialog(FilterNames(), oFileDialog)

 'Set your initial path here!
 'InitPath = ConvertToUrl(oRefModel.Text)

 If InitPath = "" Then
   InitPath = GetPathSettings("Work")
 End If
 If oUcb.Exists(InitPath) Then
   oFileDialog.SetDisplayDirectory(InitPath)
 End If
 iAccept = oFileDialog.Execute()
 If iAccept = 1 Then
   sPath = oFileDialog.Files(0)
   GetAFileName = sPath
   'If oUcb.Exists(sPath) Then
   '  oRefModel.Text = ConvertFromUrl(sPath)
   'End If
 End If
 oFileDialog.Dispose()
End Function

2) I want to use a FilePicker to specify a file to save to, but it's not possible to specify a file that does not yet exist with the FilePicker, and I've gone through all the interfaces a FilePicker has and look at all the dialogs that seem fitting for this. I want to be able to either pick an existing file or specify a new one, the same way it's possible when saving a document for the first time or when picking "Save As." For now I have to use a FolderPicker, get a folder, then ask for the file name with an InputBox.

Is there some way to get a full path from a FilePicker to a file that will be created but does not exist yet
Set it as a Save dialog. As an open dialog, you should not be able to open a non-existing file

set this immediately after creation...

oFileDialog.Initialize(Array(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE))

Other options for the templates are here:

http://api.openoffice.org/docs/common/ref/com/sun/star/ui/dialogs/TemplateDescription.html


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to