This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
sample_code:file_picker [2014/11/22 14:38] stevegarman update status |
sample_code:file_picker [2015/01/25 13:26] octazid [The code] Display as colored code |
||
---|---|---|---|
Line 5: | Line 5: | ||
Thanks to Tony Jones for testing it on DroidScript v1.12 and confirming that it works. | Thanks to Tony Jones for testing it on DroidScript v1.12 and confirming that it works. | ||
+ | |||
+ | See also [[sample_code: | ||
===== The code ===== | ===== The code ===== | ||
- | < | + | < |
- | + | //Called when application is started | |
- | //Called when application is started | + | function |
- | function | + | |
- | | + | |
- | | + | |
- | + | ||
- | //Create a text label and add it to layout. | + | |
- | btn = app.CreateButton( " | + | |
- | lay.AddChild( btn ); | + | |
- | btn.SetOnTouch(btn_OnTouch); | + | |
- | + | ||
- | //Add layout to app. | + | |
- | app.AddLayout( lay ); | + | |
- | }//function Onstart() | + | |
+ | // | ||
+ | |||
+ | btn = app.CreateButton( " | ||
+ | lay.AddChild( btn ); | ||
+ | btn.SetOnTouch(btn_OnTouch); | ||
+ | pick = new FilePicker(mycallback); | ||
+ | |||
+ | pick.SetHideFiles(true); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } // | ||
- | function | + | function |
- | pick = new FilePicker(mycallback); | + | |
- | pick.SetFolder("/ | + | pick.SetFolder("/ |
- | pick.Show(); | + | pick.Show(); |
- | }//function btn_OnTouch() | + | } //function btn_OnTouch() |
- | function | + | function |
- | app.Alert(" | + | |
- | }//function mycallback() | + | app.Alert(" |
+ | } //function mycallback() | ||
- | function | + | function |
- | var self = this; | + | |
- | this.basePath | + | var self |
- | this.callback | + | this.basePath |
- | this.FolderPath | + | this.callback |
- | this.dlg = app.CreateDialog(this.basePath); | + | this.FolderPath |
- | this.lay = app.CreateLayout( " | + | this.hideHiddenFiles |
- | this.lstFolds | + | this.dlg = app.CreateDialog(this.basePath); |
- | this.lstFolds.parent | + | this.lay = app.CreateLayout( " |
- | this.lstFolds.SetOnTouch(FilePicker_NewFolder); | + | this.lstFolds |
- | this.lay.AddChild(this.lstFolds); | + | this.lstFolds.parent |
- | this.lstFiles | + | this.lstFolds.SetOnTouch(FilePicker_NewFolder); |
- | this.lstFiles.parent | + | this.lay.AddChild(this.lstFolds); |
- | this.lstFiles.SetOnTouch(FilePicker_NewFile); | + | this.lstFiles |
- | this.lay.AddChild(this.lstFiles); | + | this.lstFiles.parent |
- | this.dlg.AddLayout(this.lay); | + | this.lstFiles.SetOnTouch(FilePicker_NewFile); |
+ | this.lay.AddChild(this.lstFiles); | ||
+ | this.dlg.AddLayout(this.lay); | ||
- | | + | |
- | self.dlg.Show(); | + | |
- | } | + | |
- | this.Hide = function(){ | + | |
- | self.dlg.Hide(); | + | } |
- | } | + | this.SetHideFiles |
- | this.SetFilter | + | |
- | self.fileFilter | + | if (val == undefined) val = true; |
- | } | + | self.hideHiddenFiles = val; |
- | this.GetFolder | + | |
- | | + | this.Hide = function() |
- | } | + | { |
- | this.SetFolder | + | |
- | self.FolderPath | + | } |
- | self.dlg.SetTitle(folderPath); | + | this.SetFilter |
- | app.ShowProgress( " | + | |
- | var lst = app.ListFolder(folderPath); | + | self.fileFilter |
- | lst.sort(function(x, | + | } |
- | var dirlist=[]; | + | this.GetFolder |
- | if( self.FolderPath | + | |
- | var fillist = []; | + | return |
- | var ths = lst.shift(); | + | } |
- | | + | this.SetFolder |
- | | + | |
- | | + | |
- | | + | self.dlg.SetTitle(folderPath); |
- | | + | app.ShowProgress( " |
- | | + | var lst = app.ListFolder(folderPath); |
- | | + | lst.sort(function(x, |
- | } | + | |
- | | + | return |
- | self.lstFiles.SetList(fillist); | + | |
- | | + | |
- | } | + | |
- | }//function FilePicker() | + | var ths = lst.shift(); |
+ | self.lstFolds.SetList("" | ||
+ | | ||
+ | self.lstFiles.SetList("" | ||
+ | | ||
+ | | ||
+ | if ((! self.hideHiddenFiles) || (ths.indexOf(" | ||
+ | { | ||
+ | var pth = folderPath | ||
+ | | ||
+ | | ||
+ | | ||
+ | ths = lst.shift(); | ||
+ | } | ||
+ | app.HideProgress(); | ||
+ | } | ||
+ | } //function FilePicker() | ||
- | function | + | function |
- | var par = this.parent; | + | |
- | var pth = par.GetFolder(); | + | var par = this.parent; |
- | | + | var pth = par.GetFolder(); |
- | | + | |
- | } | + | |
- | else{ | + | |
- | | + | } |
- | | + | else |
- | return; | + | |
- | | + | if ( pth == par.basePath |
- | var tst = pth.split("/" | + | |
- | tmp = tst.pop(); | + | par.Hide() |
- | pth = (tst.join("/" | + | } |
- | } | + | var tst = pth.split("/" |
- | + | | |
- | this.parent.SetFolder(pth); | + | |
- | }//function FilePicker_NewFolder() | + | } |
+ | par.SetFolder(pth); | ||
+ | } //function FilePicker_NewFolder() | ||
- | function | + | function |
- | | + | |
- | var pth = par.GetFolder(); | + | var par = this.parent; |
- | par.Hide(); | + | var pth = par.GetFolder(); |
- | par.callback(pth += "/" | + | par.Hide(); |
- | }//function FilePicker_NewFile() | + | par.callback(pth += "/" |
+ | } //function FilePicker_NewFile() | ||
</ | </ |