======New Folder Dialog====== Sometimes you have to create new folder in a path.\\ Its easy with if you use a dialog.\\ \\ (look for the example to [[sample_code:new_file|create a new file]] too)\\ \\ {{:pics:newfolder.png?400|}} Save the **DlgNewFolder.js** in the Droidscriptfolder where you need the file.\\ You can call the dialog after you load the Script into your app at the OnStart() Event. /******************************************************************** * CreateNewFolder Dialog ===================================================================== * Creation date: 23-01-2015 by octazid * Last update: 23-01-2015 by octazid ===================================================================== * Simple dialog to create a new folder ********************************************************************/ //*** CreateNewFolder Dialog***// function NewFolderDialog(savepath) { var self = this; this.Fdlg = app.CreateDialog("Create a new Folder:"); this.Flay = app.CreateLayout( "Linear", "FillXY" ); this.Ftxtpath = app.CreateText(savepath,0.9,0.02,"Left,Autoscale"); this.Ftxtpath.SetMargins(0,0.01,0,0); this.Ftxtpath.parent = self; this.Flay.AddChild(this.Ftxtpath); this.Fedt = app.CreateTextEdit("",0.9,0.05,"Left"); this.Fedt.SetTextSize(18); this.Fedt.SetHint("Foldername"); this.Fedt.parent = self; this.Flay.AddChild(this.Fedt); this.Fbtnlay = app.CreateLayout( "Linear", "Horizontal,FillXY" ); this.Fdlgbtn = app.CreateButton("OK", 0.45); this.Fdlgbtn.parent = self; this.Fdlgbtn.SetOnTouch(Fdlgbtn_OnTouch); this.Fbtnlay.AddChild(this.Fdlgbtn); this.FdlgbtnCancel = app.CreateButton("Chancel",0.45); this.FdlgbtnCancel.parent = self; this.FdlgbtnCancel.SetOnTouch(Fdlgbtn_OnTouch); this.Fbtnlay.AddChild(this.FdlgbtnCancel); this.Flay.AddChild(this.Fbtnlay) this.Fdlg.AddLayout(this.Flay); this.Show = function(){self.Fdlg.Show();} this.Hide = function(){self.Fdlg.Hide();} }//function NewFolderDialog() // Called if a button is touched function Fdlgbtn_OnTouch() { var par = this.parent; folder = par.Fedt.GetText(); path = par.Ftxtpath.GetText(); if(this.GetText() == "OK") CreateFolder(folder, path); par.Hide(); }//function Fdlgbtn_OnTouch // Called if Button Ok is touched function CreateFolder(foldername, path) { if (foldername != "") { //Replace illegal letters foldername = foldername.replace(/(=|\\|\/|\*|:|,|;|\+|<|>|\"|\[|\]|\?|\|)/g,""); //Replace double Whitespaces foldername = foldername.replace(/(\s+)/g," "); //Replace Whitespaces at the start and at the end foldername = foldername.trim(); //Check if Folder exists. If yes, show a message if (app.FolderExists(path + foldername)) { app.Alert("Please select another Foldername!", "Error - Folder already exists!"); } else { //Create the folder app.MakeFolder(path + foldername); //show a message if creation was ok if (app.FolderExists(path + foldername)) app.ShowPopup("Folder Created!"); } } }//function CreateFolder In your app you have to do just three things,\\ \\ 1. Load the Script with app.LoadScript("DlgNewFolder.js") 2. Create a Button to call the Dialog and add it to the layout btn = app.CreateButton( "Create a new Folder", 0.3, 0.1, "Alum" ); btn.SetOnTouch(CreateNewFolder); lay.AddChild( btn ); 3. Write a function to call the Dialog //Create a new Dialog function CreateNewFolder() { // Change the path if you need DlgNewFolder = new NewFolderDialog("/mnt/sdcard/"); DlgNewFolder.Show(); } Or you can use this Example. //Called when application is started. function OnStart() { app.LoadScript("DlgNewFolder.js") lay = app.CreateLayout( "Linear", "VCenter,FillXY" ); btn = app.CreateButton( "Create a new Folder", 0.3, 0.1, "Alum" ); btn.SetOnTouch(CreateNewFolder); lay.AddChild( btn ); app.AddLayout( lay ); } //Create a new Dialog function CreateNewFolder() { // Change the path if you need DlgNewFolder = new NewFolderDialog("/mnt/sdcard/"); DlgNewFolder.Show(); }