/******************************************************************** * CreateNewFile Dialog ===================================================================== * Creation date: 20-01-2015 by octazid * Last update: 22-01-2015 by octazid ===================================================================== * Simple dialog to create a new file in a folder ********************************************************************/ //*** CreateNewFile Dialog***// function NewFileDialog(savepath) { var self = this; this.Nfdlg = app.CreateDialog("Create a new File:"); this.Nflay = app.CreateLayout( "Linear", "FillXY" ); this.txtpath = app.CreateText(savepath,0.9,0.02,"Left,Autoscale"); this.txtpath.SetMargins(0,0.01,0,0); this.txtpath.parent = self; this.Nflay.AddChild(this.txtpath); this.Nfedt = app.CreateTextEdit("",0.9,0.05,"Left"); this.Nfedt.SetTextSize(18); this.Nfedt.SetHint("Filename.js"); this.Nfedt.parent = self; this.Nflay.AddChild(this.Nfedt); this.Nfbtnlay = app.CreateLayout( "Linear", "Horizontal,FillXY" ); this.Nfdlgbtn = app.CreateButton("OK", 0.45); this.Nfdlgbtn.parent = self; this.Nfdlgbtn.SetOnTouch(Nfdlgbtn_OnTouch); this.Nfbtnlay.AddChild(this.Nfdlgbtn); this.NfdlgbtnCancel = app.CreateButton("Chancel",0.45); this.NfdlgbtnCancel.parent = self; this.NfdlgbtnCancel.SetOnTouch(Nfdlgbtn_OnTouch); this.Nfbtnlay.AddChild(this.NfdlgbtnCancel); this.Nflay.AddChild(this.Nfbtnlay) this.Nfdlg.AddLayout(this.Nflay); this.Show = function(){self.Nfdlg.Show();} this.Hide = function(){self.Nfdlg.Hide();} }//function NewFileDialog() // Called if a button is touched function Nfdlgbtn_OnTouch() { var par = this.parent; file = par.Nfedt.GetText(); path = par.txtpath.GetText(); if(this.GetText() == "OK") CreateFile(file, path); par.Hide(); }//function dlgbtn_OnTouch // Called if Button Ok is touched function CreateFile(filename, path) { if (filename != "") { //Replace illegal letters filename = filename.replace(/(=|\\|\/|\*|:|,|;|\+|<|>|\"|\[|\]|\?|\|)/g,""); //Replace double Whitespaces filename = filename.replace(/(\s+)/g," "); //Replace Whitespaces at the start and at the end filename = filename.trim(); //Check if File exists. if yes, show a message if (app.FileExists(path + filename)) { app.Alert("Please select another Filename!", "Error - Filename already exists!"); } else { //Create the file app.WriteFile(path + filename); //show a message if creation was ok if (app.FileExists(path + filename)) app.ShowPopup("File Created!"); } } }//function CreateFile