1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-08 04:20:07 +02:00

👌 Handle errors when adding moved folder

This commit is contained in:
2022-01-25 21:02:21 +01:00
parent 338a87d503
commit e4b1f75c53
3 changed files with 36 additions and 8 deletions

View File

@ -28,6 +28,11 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate {
loadStaticLocalisedStrings() 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 // MARK: - Localisation
func loadStaticLocalisedStrings() { func loadStaticLocalisedStrings() {
@ -42,9 +47,23 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate {
let path = self.pathControl.url!.path let path = self.pathControl.url!.path
let name = self.linkName.stringValue 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) Shell.run("cd '\(path)' && \(Paths.valet) link '\(name)'", requiresPath: true)
self.view.window!.close()
self.dismissView(outcome: .OK)
// Reset search // Reset search
App.shared.siteListWindowController? App.shared.siteListWindowController?
@ -61,7 +80,7 @@ class AddSiteVC: NSViewController, NSTextFieldDelegate {
} }
@IBAction func pressedCancel(_ sender: Any) { @IBAction func pressedCancel(_ sender: Any) {
self.view.window!.close() self.dismissView(outcome: .cancel)
} }
@IBAction func pressedSecure(_ sender: Any) { @IBAction func pressedSecure(_ sender: Any) {

View File

@ -62,16 +62,15 @@ class SiteListWC: PMWindowController, NSSearchFieldDelegate, NSToolbarDelegate {
func selectFolder() { func selectFolder() {
let dialog = NSOpenPanel() let dialog = NSOpenPanel()
dialog.title = "Select a Folder" dialog.message = "site_list.add.modal_description".localized
dialog.showsResizeIndicator = true dialog.showsResizeIndicator = true
dialog.showsHiddenFiles = false dialog.showsHiddenFiles = false
dialog.allowsMultipleSelection = false dialog.allowsMultipleSelection = false
dialog.canChooseDirectories = true dialog.canChooseDirectories = true
dialog.canChooseFiles = false dialog.canChooseFiles = false
dialog.beginSheetModal(for: self.window!) { response in
if (dialog.runModal() == NSApplication.ModalResponse.OK) {
let result = dialog.url let result = dialog.url
if (result != nil) { if (result != nil && response == .OK) {
let path: String = result!.path let path: String = result!.path
self.showSitePopup(path) self.showSitePopup(path)
} }

View File

@ -67,7 +67,7 @@
"site_list.alerts_status_changed.desc" = "The domain '%@' is now %@."; "site_list.alerts_status_changed.desc" = "The domain '%@' is now %@.";
"site_list.confirm_unlink" = "Are you sure you want to unlink '%@'?"; "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.close" = "Close";
"site_link.switch_to_php" = "Switch to PHP %@"; "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.empty" = "You must enter a name.";
"site_list.add.errors.already_exists" = "A link with that name already exists."; "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 ACTIONS
"site_list.unlink" = "Unlink Directory"; "site_list.unlink" = "Unlink Directory";