Class XbpFileDialog() Foundation

Class function of the XbpFileDialog class.


The XbpFileDialog class provides objects that manage dialog windows for selecting files. The file dialog window is a system dialog that allows the user to specify drives and directories to search for particular files. This dialog can be displayed using either the method :open() or the method :saveAs(). Both return a file name including the drive and directory. :open() may also be set up to return a list of files selected.

Class methods
Creates an instance of the XbpFileDialog class.
Life cycle
Requests system resources for the XbpFileDialog object.
Reconfigures the XbpFileDialog object after :create() has been executed.
Releases the system resources of the XbpFileDialog object.
Instance variables
Size of the buffer reserved for file names
Determines whether the file dialog is centered in the parent window.
Default extension of a file selected by the user
Filters to apply to the files browsed in the file dialog
Controls validation techniques applied by the file dialog
Specifies whether files should be opened with write protection
Specifies whether the original current directory should be restored
The title for the file dialog.
Controls validation of paths entered by the user
Activates the file dialog to open a file.
Activates the file dialog for saving a file.
Text editor with file dialog and file menu

// This example shows a text editor that runs in an 
// XbpCrt window. The window has a menu bar that 
// includes a submenu for processing text files. This 
// menu includes the items "New", "Open", "Save" and 
// "Save As". A file dialog is used for these menu 
// options. The actual text editor is provided by an 
// XbpMLE object whose :cargo instance variable contains 
// the file name of the current file. 

#include "" 
#include "" 

#pragma library("XppUi2") 

   LOCAL nEvent, mp1, mp2, oXbp 
   LOCAL oMLE, oFileDlg 


   // Create file dialog with desktop as parent 
   oFileDlg   := XbpFileDialog():new() 
   oFileDlg:create( AppDesktop() ) 

   // Create MLE 
   oMLE       := XbpMLE():new():create( ,, {50,50}, {550,300} ) 
   oMLE:cargo := "" 

   // Default menu for managing text files 
   TextFileMenu( SetAppWindow():menuBar(), oFileDlg, oMLE ) 

   // Event loop 
   nEvent := 0 
   DO WHILE nEvent <> xbeP_Close 
      nEvent := AppEvent( @mp1, @mp2, @oXbp ) 
      oXbp:HandleEvent( nEvent, mp1, mp2 ) 

// ************************************************* 
// This function creates a default menu for opening 
// and saving text files 
FUNCTION TextFileMenu( oMenuBar, oFileDlg, oMLE ) 
   LOCAL oMenu := XbpMenu():new(oMenuBar):create() 

   oMenu:title := "~File" 

   oMenu:addItem( { "~New", ; 
      {|| oMLE:setData(""), oMLE:cargo := "", ; 
          SetAppWindow():setTitle( "No name" ), ; 
          oMenu:disableItem(4) } } ) 
   oMenu:addItem( { "~Open...", ; 
      {|| ReadFile( oFileDlg, oMLE ), ; 
          IIf( Empty(oMLE:cargo), NIL, oMenu:enableItem(4)) } } ) 

   oMenu:addItem( { ,, XBPMENUBAR_MIS_SEPARATOR,0 } ) 

   oMenu:addItem( { "~Save", ; 
      {|| WriteFile( oMLE:cargo, oMLE ) }, ; 

   oMenu:addItem( { "Save ~as...", ; 
      {|| WriteFile( oFileDlg:saveAs( oMLE:cargo ), oMLE ) } } ) 

   oMenuBar:addItem( {oMenu, NIL} ) 

// ******************************************* 
// The procedure activates the file dialog for 
// selecting a file. Reads selected files and 
// copies into MLE. 
PROCEDURE ReadFile( oFileDlg, oMLE ) 
   LOCAL cFile := oFileDlg:open( oMLE:cargo ) 

   IF ! Empty( cFile ) 
      oMLE:cargo := cFile 
      oMLE:setData( MemoRead( cFile ) ) 
      SetAppWindow():setTitle( cFile ) 

// ************************************** 
// Write text buffer of the MLE to file 
PROCEDURE WriteFile( cFile, oMLE ) 
   IF ! Empty( cFile ) 
      oMLE:cargo := cFile 
      MemoWrit( cFile, oMLE:getData() ) 
      SetAppWindow():setTitle( cFile ) 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.