Development/Tutorials/Plasma4/JavaScript/API-FileDialog

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

FileDialog

This Extension provides access to open and save dialog classes: OpenFileDialog and SaveFileDialog. Both are non-modal and run asynchronously, so the signals must be used. Other than the name difference (and resulting UI variance) the API for each is identical:

  • Constructors
    • OpenFileDialog
    • SaveFileDialog
  • Properties
    • Read Only
      • array(Url) urls: the selected file, as a Url object
      • Url baseUrl, the current path (minus filename) as a Url
      • string file: the selected file, as a string
      • array(string) files: selected files (plural), as an array of strings
    • Read/Write
      • Url url: the current Url, can be read from when the user is done or assigned before to set the starting path
      • string filter: a string representing the mimetype filter; e.g. "*.cpp|C++ Source Files\n*.h|Header files" or "*.cpp" or "*.cpp|*h"
      • boolean localOnly: true to show only local files, false if network locations are Ok as well
      • boolean directoriesOnly: true to only allow selection of a directory (not a file)
      • boolean existingOnly: true if only existing files/directories may be selected
  • Functions
    • show(): when called, the dialog will be shown to the user
  • Signals
    • accepted(FileDialogProxy)': emitted when the file dialog has been successfully accepted by the user with one or more files/directories.
    • finished(FileDialogProxy): emitted when the file dialog closes, included when cancelled/closed without being accepted

Examples

This example create a new OpenFileDialog instance, so the user can select a file. If a file has been selected and the "Accept" button is clicked then it will call the "loadFile" function.

 1 function loadFile(fileDialogProxy){
 2   // Here we load the file. We retrieve the user's choice using fileDialogProxy.file
 3   
 4   // fileDialogProxy use the same methods as FileDialog shown before.
 5 }
 6 
 7 function selectFile() {
 8     var fd = new OpenFileDialog();
 9     fd.accepted.connect(loadFile);
10 
11     fd.show();
12 }

Remember that signals are connected using the connect(...) method as explained at Plasma using Javascript: Getting Started


This page was last edited on 22 February 2015, at 19:55. Content is available under Creative Commons License SA 4.0 unless otherwise noted.