OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Folder Picker and File Picker

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon Jun 14, 2004 6:43 am    Post subject: Folder Picker and File Picker Reply with quote

Need to prompt the user to pick a folder?
Code:
Sub Main
   cFolder = PickFolder( "C:\Documents and Settings\dbrewer\Desktop" )
   MsgBox( cFolder )
End Sub


Function PickFolder( cFolder )
   oFolderPickerDlg = createUnoService( "com.sun.star.ui.dialogs.FolderPicker" )

   If Len( cFolder ) > 0 Then
      oFolderPickerDlg.setDisplayDirectory( ConvertToURL( cFolder ) )
   EndIf
      
   oFolderPickerDlg.execute()
   
   cPickedFolder = oFolderPickerDlg.getDirectory()
   
   PickFolder = ConvertFromURL( cPickedFolder )
End Function



Need to prompt the user to pick a file?
Code:
Sub Main
   cFile = PickFileName( "C:\Documents and Settings\dbrewer\Desktop", "MyFile.sxc" )
   MsgBox( cFile )
End Sub


Function PickFileName( cFolder, cFileName )
   oFilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )

   ' Unnecessary, the dialog defaults to having multi-select turned off.   
'   oFilePickerDlg.setMultiSelectionMode( False )

   If Len( cFolder ) > 0 Then
      oFilePickerDlg.setDisplayDirectory( ConvertToURL( cFolder ) )
   EndIf
   
   If Len( cFileName ) > 0 Then
      oFilePickerDlg.setDefaultName( cFileName )
   EndIf
   
   oFilePickerDlg.appendFilter( "OpenOffice.org Calc (SXC)", "sxc" )
   oFilePickerDlg.appendFilter( "Microsoft Excel (XLS)", "xls" )
   
   ' Change the Open button to say "Save".
   ' (this does not appear to work so well.  OOo needs to offer a Save dialog.)
'   oFilePickerDlg.setLabel( com.sun.star.ui.dialogs.CommonFilePickerElementIds.PUSHBUTTON_OK, "Save" )
   
   oFilePickerDlg.execute()
   
   ' Get an array of the files that the user picked.
   ' There is only one item in the array since we did not
   '  turn on the Multi-Selection feature of the dialog box.
   oFiles = oFilePickerDlg.getFiles()
   
   If UBound( oFiles ) - LBound( oFiles ) + 1 > 0 Then
      PickFileName() = ConvertFromURL( oFiles(0) )
   Else
      PickFileName() = ""
   EndIf   
End Function



The major missing related element from OOo seems to be the lack of a service to display a "Save" dialog.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Dec 10, 2004 7:37 am    Post subject: Reply with quote

Just adding a cross reference.....

Linking File Selection field
http://www.oooforum.org/forum/viewtopic.php?t=14871
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
newvision
General User
General User


Joined: 19 Apr 2006
Posts: 41

PostPosted: Mon Jan 22, 2007 5:11 am    Post subject: Reply with quote

Danny,
Thanks for your code and quick reply!

I copied your code and opened up my db. I went to Tools. Macros/ Organize/OpenOffice.org/Basic, clicked on My Macros, hit organiser button and selected new. I then pasted your code into the box, deleted the extra Sub Main and Sub End, saved and closed the Macro dialog.

I then went to my form in design view, right clicked in my text box to bring up the Control. I selected 'When receiving focus, I clicked on the Macro button and scrolled to the FilePicker from your code and got the following.'
A red arrow pointed just above this line which was highlighted,

f Len( cFolder ) > 0 Then

with the following error message: Basic Runtime error. Argument is not optional.

I also had a question. In your code where there is re writing, do I put my own stuff in it? : Example

cFile = PickFileName( "C:\Documents and Settings\dbrewer\Desktop", "MyFile.sxc" )

Thanks
Back to top
View user's profile Send private message
9point9
Moderator
Moderator


Joined: 31 Aug 2004
Posts: 3875
Location: UK

PostPosted: Mon Jan 22, 2007 6:25 am    Post subject: Reply with quote

loupylou wrote:
Thanks for your code and quick reply!

Have a look at the date of those posts, it's several years ago. DannyB no longer frequents these forums so is unlikely to see your post to reply.

You are correct in your assumption that you need to replace Danny's paths with your own.
_________________
Arch Linux
OOo 3.2.0

OOoSVN, change control for OOo documents:
http://sourceforge.net/projects/ooosvn/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group