mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
89 lines
3.2 KiB
Swift
89 lines
3.2 KiB
Swift
//
|
|
// ShareOptionsView.swift
|
|
// FileProviderUIExt
|
|
//
|
|
// Created by Claudio Cambra on 28/2/24.
|
|
//
|
|
|
|
import AppKit
|
|
import Combine
|
|
import NextcloudKit
|
|
|
|
class ShareOptionsView: NSView {
|
|
@IBOutlet private weak var labelTextField: NSTextField!
|
|
@IBOutlet private weak var uploadEditPermissionCheckbox: NSButton!
|
|
@IBOutlet private weak var hideDownloadCheckbox: NSButton!
|
|
@IBOutlet private weak var passwordProtectCheckbox: NSButton!
|
|
@IBOutlet private weak var passwordSecureField: NSSecureTextField!
|
|
@IBOutlet private weak var expirationDateCheckbox: NSButton!
|
|
@IBOutlet private weak var expirationDatePicker: NSDatePicker!
|
|
@IBOutlet private weak var noteForRecipientCheckbox: NSButton!
|
|
@IBOutlet private weak var noteTextField: NSTextField!
|
|
@IBOutlet private weak var saveButton: NSButton!
|
|
@IBOutlet private weak var deleteButton: NSButton!
|
|
|
|
var controller: ShareController? {
|
|
didSet {
|
|
cancellable?.cancel()
|
|
update()
|
|
cancellable = controller.publisher.sink { _ in self.update() }
|
|
}
|
|
}
|
|
private var cancellable: AnyCancellable?
|
|
|
|
private func update() {
|
|
guard let share = controller?.share else {
|
|
reset()
|
|
setAllFields(enabled: false)
|
|
saveButton.isEnabled = false
|
|
deleteButton.isEnabled = false
|
|
return
|
|
}
|
|
|
|
deleteButton.isEnabled = share.canDelete
|
|
saveButton.isEnabled = share.canEdit
|
|
|
|
if share.canEdit {
|
|
setAllFields(enabled: true)
|
|
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
|
|
} else {
|
|
setAllFields(enabled: false)
|
|
reset()
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func setAllFields(enabled: Bool) {
|
|
labelTextField.isEnabled = enabled
|
|
uploadEditPermissionCheckbox.isEnabled = enabled
|
|
hideDownloadCheckbox.isEnabled = enabled
|
|
passwordProtectCheckbox.isEnabled = enabled
|
|
passwordSecureField.isEnabled = enabled
|
|
expirationDateCheckbox.isEnabled = enabled
|
|
expirationDatePicker.isEnabled = enabled
|
|
noteForRecipientCheckbox.isEnabled = enabled
|
|
noteTextField.isEnabled = enabled
|
|
saveButton.isEnabled = enabled
|
|
deleteButton.isEnabled = enabled
|
|
}
|
|
}
|