void HandleRenameRequested(DocumentReference docRef, object arg2) { var name = docRef.Name; var dir = Path.GetDirectoryName(docRef.File.Path); var c = new TextInputController { Title = "Rename " + (docRef.File.IsDirectory ? "Folder" : DocumentAppDelegate.Shared.App.DocumentBaseName), InputText = name, ValidateFunc = n => DocumentAppDelegate.ValidateNewName(dir, n, docRef.Name), }; var nc = new UINavigationController(c); nc.NavigationBar.BarStyle = DocumentAppDelegate.Shared.Theme.NavigationBarStyle; nc.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; var presenter = this; c.Cancelled += (ss, ee) => presenter.DismissViewController(true, null); c.Done += async(ss, ee) => { presenter.DismissViewController(true, null); if (!string.IsNullOrWhiteSpace(c.InputText) && c.InputText != name) { await Rename(docRef, c.InputText); } }; presenter.PresentViewController(nc, true, null); }
void HandleTitleTap(object sender, EventArgs e) { if (IsRoot) { return; } var name = DirectoryName; var dir = Path.GetDirectoryName(this.Directory); var c = new TextInputController { Title = "Rename", InputText = name, ValidateFunc = n => DocumentAppDelegate.ValidateNewName(dir, n, name), }; var nc = new UINavigationController(c); nc.NavigationBar.BarStyle = DocumentAppDelegate.Shared.Theme.NavigationBarStyle; nc.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; c.Cancelled += (ss, ee) => nc.DismissViewController(true, null); c.Done += async(ss, ee) => { nc.DismissViewController(true, null); if (c.InputText != name) { try { var FileSystem = FileSystemManager.Shared.ActiveFileSystem; var newDir = Path.Combine(Path.GetDirectoryName(Directory), c.InputText); if (await FileSystem.Move(Directory, newDir)) { Directory = newDir; SetTitle(); DocumentAppDelegate.Shared.Settings.SetWorkingDirectory(FileSystem, Directory); } else { var alert = new UIAlertView("Rename Error", FileSystem.Id + " did not allow the folder to be renamed.", null, "OK"); alert.Show(); } } catch (Exception ex) { Debug.WriteLine(ex); } } }; PresentViewController(nc, true, null); }