void AddNewItem(object sender, EventArgs args) { var editScriptViewController = EditScriptViewController.Create(OnAddNewFile); var nav = new UINavigationController(editScriptViewController); nav.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; PresentViewController(nav, true, null); }
public override void AccessoryButtonTapped(UITableView tableView, NSIndexPath indexPath) { string fileName = scripts[indexPath.Row]; var editScriptViewController = EditScriptViewController.Create((edit, newName) => OnRenameScript(edit, fileName, newName), fileName); var nav = new UINavigationController(editScriptViewController); nav.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; controller.PresentViewController(nav, true, null); }
void OnAddNewFile(EditScriptViewController editScriptViewController, string name) { name = ScriptStore.FixName(name); if (!dataSource.Exists(name)) { WriteNewFileAndReloadList(name); editScriptViewController.Dismiss(); PerformSegue("showDetail", this); return; } ConfirmFileReplace(editScriptViewController, name, Replace_AddNew_Dismissed); }
public void ConfirmFileReplace(EditScriptViewController editScriptViewController, string name, Action <EditScriptViewController, string> confirm) { var alert = new UIAlertController(); string message = NSBundle.MainBundle.GetLocalizedString("Replace_Message", "\"{0}\" already exists. Do you want to replace it?"); alert.Title = string.Format(message, name); var cancel = UIAlertAction.Create(NSBundle.MainBundle.GetLocalizedString("Cancel", "Cancel"), UIAlertActionStyle.Cancel, null); var replace = UIAlertAction.Create(NSBundle.MainBundle.GetLocalizedString("Replace", "Replace"), UIAlertActionStyle.Destructive, (obj) => confirm(editScriptViewController, name)); alert.AddAction(replace); alert.AddAction(cancel); editScriptViewController.PresentViewController(alert, true, null); }
public static EditScriptViewController Create(Action <EditScriptViewController, string> onDone, string fileName) { UIStoryboard mainStoryboard = UIStoryboard.FromName("Main", null); EditScriptViewController viewController = (EditScriptViewController)mainStoryboard.InstantiateViewController("EditScriptViewController"); if (string.IsNullOrEmpty(fileName)) { viewController.Title = NSBundle.MainBundle.GetLocalizedString("New_Script", "New Script"); } else { viewController.Title = NSBundle.MainBundle.GetLocalizedString("Edit_Script", "Edit Script"); } viewController.DoneAction = onDone; viewController.initialScriptName = fileName; return(viewController); }
void OnRenameScript(EditScriptViewController editViewController, string oldName, string newName) { newName = ScriptStore.FixName(newName); // No-op if (oldName == newName) { editViewController.Dismiss(); return; } string existingFile = scripts.FirstOrDefault(s => s.Equals(newName, StringComparison.OrdinalIgnoreCase)); existingFile = existingFile ?? newName; if (oldName.Equals(newName, StringComparison.OrdinalIgnoreCase) || !Exists(newName)) { Store.RenameFile(oldName, newName, existingFile); editViewController.Dismiss(); Reload(); controller.TableView.ReloadData(); if (controller.ScriptViewController?.ScriptName == oldName) { controller.ScriptViewController.SetScript(newName); } return; } controller.ConfirmFileReplace(editViewController, newName, (edit, n) => { Store.RenameFile(oldName, newName, existingFile); edit.Dismiss(); Reload(); controller.TableView.ReloadData(); if (controller.ScriptViewController?.ScriptName == oldName) { controller.ScriptViewController.SetScript(newName); } }); }
void Replace_AddNew_Dismissed(EditScriptViewController editScriptViewController, string name) { WriteNewFileAndReloadList(name); editScriptViewController.Dismiss(); PerformSegue("showDetail", this); }