Use ShareController in ShareOptionsView
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 4 Mar 2024 12:42:52 +0000 (20:42 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 17 Apr 2024 08:38:54 +0000 (16:38 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareOptionsView.swift

index ca197bb30039ff6a86beffa516178afcd01e1afe..d0f75a13c48025cfd40b086bbeacc388ac21a5ec 100644 (file)
@@ -21,19 +21,42 @@ class ShareOptionsView: NSView {
     @IBOutlet private weak var saveButton: NSButton!
     @IBOutlet private weak var deleteButton: NSButton!
 
-    var share: NKShare? {
+    var controller: ShareController? {
         didSet {
-            guard let share = share else { return }
-            labelTextField.stringValue = share.label
-            uploadEditPermissionCheckbox.state = share.canEdit ? .on : .off
-            hideDownloadCheckbox.state = share.hideDownload ? .on : .off
-            passwordProtectCheckbox.state = share.password.isEmpty ? .off : .on
-            passwordSecureField.isHidden = passwordProtectCheckbox.state == .off
-            expirationDateCheckbox.state = share.expirationDate == nil ? .off : .on
-            expirationDatePicker.isHidden = expirationDateCheckbox.state == .off
-            noteForRecipientCheckbox.state = share.note.isEmpty ? .off : .on
-            noteTextField.isHidden = noteForRecipientCheckbox.state == .off
-            deleteButton.isEnabled = share.canDelete
+            update()
+
+        }
+    }
+
+    private func update() {
+        guard let share = controller?.share else {
+            reset()
+            saveButton.isEnabled = false
+            deleteButton.isEnabled = false
+            return
         }
+        labelTextField.stringValue = share.label
+        uploadEditPermissionCheckbox.state = share.canEdit ? .on : .off
+        hideDownloadCheckbox.state = share.hideDownload ? .on : .off
+        passwordProtectCheckbox.state = share.password.isEmpty ? .off : .on
+        passwordSecureField.isHidden = passwordProtectCheckbox.state == .off
+        expirationDateCheckbox.state = share.expirationDate == nil ? .off : .on
+        expirationDatePicker.isHidden = expirationDateCheckbox.state == .off
+        noteForRecipientCheckbox.state = share.note.isEmpty ? .off : .on
+        noteTextField.isHidden = noteForRecipientCheckbox.state == .off
+        deleteButton.isEnabled = share.canDelete
+        saveButton.isEnabled = true
+    }
+
+    func reset() {
+        labelTextField.stringValue = ""
+        uploadEditPermissionCheckbox.state = .off
+        hideDownloadCheckbox.state = .off
+        passwordProtectCheckbox.state = .off
+        passwordSecureField.isHidden = true
+        expirationDateCheckbox.state = .off
+        expirationDatePicker.isHidden = true
+        noteForRecipientCheckbox.state = .off
+        noteTextField.isHidden = true
     }
 }