From e4b1f75c5319bb1d6e7f87b6a1d4eedb27947135 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 25 Jan 2022 21:02:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Handle=20errors=20when=20adding?= =?UTF-8?q?=20moved=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon/Domain/SiteList/AddSiteVC.swift | 25 ++++++++++++++++++++++--- phpmon/Domain/SiteList/SiteListWC.swift | 7 +++---- phpmon/Localizable.strings | 12 +++++++++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/phpmon/Domain/SiteList/AddSiteVC.swift b/phpmon/Domain/SiteList/AddSiteVC.swift index dbada92..7aa5fa8 100644 --- a/phpmon/Domain/SiteList/AddSiteVC.swift +++ b/phpmon/Domain/SiteList/AddSiteVC.swift @@ -28,6 +28,11 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate { loadStaticLocalisedStrings() } + private func dismissView(outcome: NSApplication.ModalResponse) { + guard let window = self.view.window, let parent = window.sheetParent else { return } + parent.endSheet(window, returnCode: outcome) + } + // MARK: - Localisation func loadStaticLocalisedStrings() { @@ -42,9 +47,23 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate { let path = self.pathControl.url!.path let name = self.linkName.stringValue - // TODO: Check if the path still exists + if !FileManager.default.fileExists(atPath: path) { + Alert.confirm( + onWindow: self.view.window!, + messageText: "site_list.alert.folder_missing.title".localized, + informativeText: "site_list.alert.folder_missing.desc".localized, + buttonTitle: "site_list.alert.folder_missing.cancel".localized, + secondButtonTitle: "site_list.alert.folder_missing.return".localized, + onFirstButtonPressed: { + self.dismissView(outcome: .cancel) + } + ) + return + } + Shell.run("cd '\(path)' && \(Paths.valet) link '\(name)'", requiresPath: true) - self.view.window!.close() + + self.dismissView(outcome: .OK) // Reset search App.shared.siteListWindowController? @@ -61,7 +80,7 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate { } @IBAction func pressedCancel(_ sender: Any) { - self.view.window!.close() + self.dismissView(outcome: .cancel) } @IBAction func pressedSecure(_ sender: Any) { diff --git a/phpmon/Domain/SiteList/SiteListWC.swift b/phpmon/Domain/SiteList/SiteListWC.swift index ec3f0cc..aba9a57 100644 --- a/phpmon/Domain/SiteList/SiteListWC.swift +++ b/phpmon/Domain/SiteList/SiteListWC.swift @@ -62,16 +62,15 @@ class SiteListWC: PMWindowController, NSSearchFieldDelegate, NSToolbarDelegate { func selectFolder() { let dialog = NSOpenPanel() - dialog.title = "Select a Folder" + dialog.message = "site_list.add.modal_description".localized dialog.showsResizeIndicator = true dialog.showsHiddenFiles = false dialog.allowsMultipleSelection = false dialog.canChooseDirectories = true dialog.canChooseFiles = false - - if (dialog.runModal() == NSApplication.ModalResponse.OK) { + dialog.beginSheetModal(for: self.window!) { response in let result = dialog.url - if (result != nil) { + if (result != nil && response == .OK) { let path: String = result!.path self.showSitePopup(path) } diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 41781f4..6cc17aa 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -67,7 +67,7 @@ "site_list.alerts_status_changed.desc" = "The domain '%@' is now %@."; "site_list.confirm_unlink" = "Are you sure you want to unlink '%@'?"; -"site_link.confirm_link" = "No files will be removed. If needed, the site will need to be relinked via the command line."; +"site_link.confirm_link" = "No files will be removed. You can always link the folder again by clicking on the + button and selecting the original folder."; "site_link.close" = "Close"; "site_link.switch_to_php" = "Switch to PHP %@"; @@ -85,6 +85,16 @@ "site_list.add.errors.empty" = "You must enter a name."; "site_list.add.errors.already_exists" = "A link with that name already exists."; +// ADD SITE ERROR: FOLDER MISSING SINCE SELECTION + +"site_list.alert.folder_missing.desc" = "The folder you chose no longer seems to exist. Do you want to cancel adding this folder? If you moved the folder, you could always put it back and try again."; +"site_list.alert.folder_missing.title" = "Folder missing!"; +"site_list.alert.folder_missing.cancel" = "Cancel Link"; +"site_list.alert.folder_missing.return" = "OK"; + + +"site_list.add.modal_description" = "First, select which folder you would like to link."; + // SITE LIST ACTIONS "site_list.unlink" = "Unlink Directory";