From bab3b4181c8a97c1fe495a1d98a67b3b5bccc503 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 19 Mar 2024 20:08:14 +0800 Subject: [PATCH] Fix options view disappearing when clicking create button in share view controller Signed-off-by: Claudio Cambra --- .../FileProviderUIExt/ShareOptionsView.swift | 6 ++--- .../ShareTableViewDataSource.swift | 2 +- .../ShareViewController.swift | 24 +++++++++++++------ .../ShareViewDataSourceUIDelegate.swift | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareOptionsView.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareOptionsView.swift index 4b64d2e08..d8231de28 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareOptionsView.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareOptionsView.swift @@ -274,7 +274,7 @@ class ShareOptionsView: NSView { dataSource.uiDelegate?.showError("Error creating: \(error.errorDescription)") setAllFields(enabled: true) } else { - dataSource.uiDelegate?.hideOptions() + dataSource.uiDelegate?.hideOptions(self) await dataSource.reload() } return @@ -306,7 +306,7 @@ class ShareOptionsView: NSView { dataSource?.uiDelegate?.showError("Error updating share: \(error.errorDescription)") setAllFields(enabled: true) } else { - dataSource?.uiDelegate?.hideOptions() + dataSource?.uiDelegate?.hideOptions(self) await dataSource?.reload() } } @@ -315,7 +315,7 @@ class ShareOptionsView: NSView { @IBAction func delete(_ sender: Any) { Task { @MainActor in guard !createMode else { - dataSource?.uiDelegate?.hideOptions() + dataSource?.uiDelegate?.hideOptions(self) reset() return } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift index a4184e180..312e59cf1 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableViewDataSource.swift @@ -238,7 +238,7 @@ class ShareTableViewDataSource: NSObject, NSTableViewDataSource, NSTableViewDele @objc func tableViewSelectionDidChange(_ notification: Notification) { guard let selectedRow = sharesTableView?.selectedRow, selectedRow >= 0 else { - Task { @MainActor in uiDelegate?.hideOptions() } + Task { @MainActor in uiDelegate?.hideOptions(self) } return } let share = shares[selectedRow] diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift index dd57050f5..d104e3360 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift @@ -57,7 +57,7 @@ class ShareViewController: NSViewController, ShareViewDataSourceUIDelegate { override func viewDidLoad() { dismissError(self) - hideOptions() + hideOptions(self) } @IBAction func closeAction(_ sender: Any) { @@ -111,10 +111,12 @@ class ShareViewController: NSViewController, ShareViewDataSourceUIDelegate { } @IBAction func createShare(_ sender: Any) { - tableView.deselectAll(self) optionsView.createMode = true - splitView.addArrangedSubview(optionsView) - optionsView.isHidden = false + tableView.deselectAll(self) + if !splitView.arrangedSubviews.contains(optionsView) { + splitView.addArrangedSubview(optionsView) + optionsView.isHidden = false + } } func fetchStarted() { @@ -127,16 +129,24 @@ class ShareViewController: NSViewController, ShareViewDataSourceUIDelegate { loadingIndicator.stopAnimation(self) } - func hideOptions() { + func hideOptions(_ sender: Any) { + if sender as? ShareTableViewDataSource == shareDataSource, optionsView.createMode { + // Do not hide options if the table view has had everything deselected when we set the + // options view to be in create mode + return + } splitView.removeArrangedSubview(optionsView) optionsView.isHidden = true + } func showOptions(share: NKShare) { guard let kit = shareDataSource.kit else { return } optionsView.controller = ShareController(share: share, kit: kit) - splitView.addArrangedSubview(optionsView) - optionsView.isHidden = false + if !splitView.arrangedSubviews.contains(optionsView) { + splitView.addArrangedSubview(optionsView) + optionsView.isHidden = false + } } func showError(_ errorString: String) { diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewDataSourceUIDelegate.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewDataSourceUIDelegate.swift index 615de16b4..09bd3f7e4 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewDataSourceUIDelegate.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewDataSourceUIDelegate.swift @@ -11,7 +11,7 @@ import NextcloudKit protocol ShareViewDataSourceUIDelegate { func fetchStarted() func fetchFinished() - func hideOptions() + func hideOptions(_ sender: Any) func showOptions(share: NKShare) func showError(_ errorString: String) }