On Thursday 17 July 2008, Andrew Douglas Pitonyak wrote:
> 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.
I was thinking about using just "/" in file names then, if they weren't
in URL format, use ConvertToURL, then ConvertFromURL, but at this
moment I don't have a Windows machine to test it on (to be sure
ConvertToURL will take a "/" as a separator on Windows), so I hadn't
been able to test it out.
> 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
I was toying with adding an extension on to the exported macro save file
but hadn't looked into using filters yet, so this is a help!
> > 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.TemplateDescript
>ion.FILESAVE_SIMPLE))
>
> Other options for the templates are here:
>
> http://api.openoffice.org/docs/common/ref/com/sun/star/ui/dialogs/Tem
>plateDescription.html
Okay -- that makes sense. I had gone through looking at dialogs and
searching the API index under different letters that might have a
different FilePicker or FileSavePicker or SaveFilePicker or anything
like that and just couldn't find a darned thing!
It works just fine!
Thanks, Andrew.
Hal
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]