Appcelerator Titanium enables you to show a dialog box to select files which you would like to save or open.
To open a SaveAs dialog box, we first set up the options object, and then call the function to open the dialog, passing it the callback function to call once it is closed.
var options = {
title: "Save file as...",
types: ['*'],
typesDescription: "All files",
path: Titanium.Filesystem.getUserDirectory()
}
Titanium.UI.openSaveAsDialog(callbackFunc, options);
In types we put the file types filter, for example ['doc', 'txt]. The path is the default path to point the dialog to.
Next in the callback function, we can reference the filename which is returned as an array, which when saving a file is always going to be one element, but may be multiple filenames for an Open dialog.
callbackFunc = function(filenames){
var fileSelected = filenames[0];
}
Creating a file chooser dialog is very similar. This dialog allows multiple files to be selected.
var options = {
multiple: true,
title: "Select files to open...",
types: ['doc', 'txt'],
typesDescription: "Documents",
path: Titanium.Filesystem.getUserDirectory()
}
Titanium.UI.openFileChooserDialog(callbackFunc, options);
In the callback function, the only difference is that the array of filenames may have more than 1 filenames in it.
callbackFunc = function(filenames) {
var firstFileSelected = filenames[0];
var secondFileSelected = filenames[1];
}
That is all there is to showing and processing file dialogs.
I would point you to the Titanium API documention at this point, but have found no reference to the dialogs in the 0.4 documentation.
Related posts:
- Titanium Tutorial: Browsing folder contents programmatically A very useful feature of desktop applications is being able...
- Titanium Tutorial: Accessing files on the local system Out of all the features included in Appcelerator Titanium which...
- Titanium Tutorial: How to upload a file to a server During the last several weeks I have been making considerable...
- Titanium Tutorial: Calling the Titanium API from a remote file Appcelerator Titanium is pretty free with what it allows you...
- Titanium Tutorial: Window management Appcelerator Titanium has a rich set of Window management methods...
Related posts brought to you by Yet Another Related Posts Plugin.
Serge Meunier is a software developer living in Cape Town, South Africa. He loves programming, fencing, philosophy, feeding his internet addiction, and, of course, dogs.
Comments