From 3b5dfb38ec17324443ee9d0f63614b7e64d1afdb Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Mon, 2 Nov 2020 11:08:54 +0800 Subject: [PATCH 1/2] Explainer text for accounts and extensions Explainer text will display when no account/extension is selected. --- .../AccountsPreferencesViewController.swift | 17 ++++++++++- ...ensionPointPreferencesViewController.swift | 30 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index 2153f13d3..ab2393748 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -226,7 +226,7 @@ private extension AccountsPreferencesViewController { func showController(_ controller: NSViewController) { hideController() - + addChild(controller) controller.view.translatesAutoresizingMaskIntoConstraints = false detailView.addSubview(controller.view) @@ -239,6 +239,21 @@ private extension AccountsPreferencesViewController { children.removeAll() controller.view.removeFromSuperview() } + + if tableView.selectedRow == -1 { + var helpText = "" + if sortedAccounts.count == 0 { + helpText = NSLocalizedString("Add an account by clicking the + button.", comment: "Add Account Explainer") + } else { + helpText = NSLocalizedString("Select an account or add a new account by clicking the + button.", comment: "Add Account Explainer") + } + + let textHostingController = NSHostingController(rootView: Text(helpText).multilineTextAlignment(.center)) + addChild(textHostingController) + textHostingController.view.translatesAutoresizingMaskIntoConstraints = false + detailView.addSubview(textHostingController.view) + detailView.addFullSizeConstraints(forSubview: textHostingController.view) + } } } diff --git a/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift b/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift index d07249fba..eca8dc36a 100644 --- a/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift +++ b/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift @@ -179,6 +179,21 @@ private extension ExtensionPointPreferencesViewController { func showDefaultView() { activeExtensionPoints = Array(ExtensionPointManager.shared.activeExtensionPoints.values).sorted(by: { $0.title < $1.title }) tableView.reloadData() + + if tableView.selectedRow == -1 { + var helpText = "" + if activeExtensionPoints.count == 0 { + helpText = NSLocalizedString("Add an extension point by clicking the + button.", comment: "Extension Explainer") + } else { + helpText = NSLocalizedString("Select an extension point or add a new extension point by clicking the + button.", comment: "Extension Explainer") + } + + let textHostingController = NSHostingController(rootView: Text(helpText).multilineTextAlignment(.center)) + addChild(textHostingController) + textHostingController.view.translatesAutoresizingMaskIntoConstraints = false + detailView.addSubview(textHostingController.view) + detailView.addFullSizeConstraints(forSubview: textHostingController.view) + } } func showController(_ controller: NSViewController) { @@ -195,6 +210,21 @@ private extension ExtensionPointPreferencesViewController { children.removeAll() controller.view.removeFromSuperview() } + + if tableView.selectedRow == -1 { + var helpText = "" + if activeExtensionPoints.count == 0 { + helpText = NSLocalizedString("Add an extension point by clicking the + button.", comment: "Extension Explainer") + } else { + helpText = NSLocalizedString("Select an extension point or add a new extension point by clicking the + button.", comment: "Extension Explainer") + } + + let textHostingController = NSHostingController(rootView: Text(helpText).multilineTextAlignment(.center)) + addChild(textHostingController) + textHostingController.view.translatesAutoresizingMaskIntoConstraints = false + detailView.addSubview(textHostingController.view) + detailView.addFullSizeConstraints(forSubview: textHostingController.view) + } } func enableOauth1(_ provider: OAuth1SwiftProvider.Type, extensionPointType: ExtensionPoint.Type) { From 3580739b8d6e66162238d6f9d2a34eec3d3b2662 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Tue, 3 Nov 2020 09:41:34 +0800 Subject: [PATCH 2/2] Amends contsraints on HostingControllers This has the effect of pushing the explainer text up to the centre alignment of the tableviews. --- .../Accounts/AccountsPreferencesViewController.swift | 8 ++++++-- .../ExtensionPointPreferencesViewController.swift | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index ab2393748..d28ff36e7 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -231,7 +231,6 @@ private extension AccountsPreferencesViewController { controller.view.translatesAutoresizingMaskIntoConstraints = false detailView.addSubview(controller.view) detailView.addFullSizeConstraints(forSubview: controller.view) - } func hideController() { @@ -252,7 +251,12 @@ private extension AccountsPreferencesViewController { addChild(textHostingController) textHostingController.view.translatesAutoresizingMaskIntoConstraints = false detailView.addSubview(textHostingController.view) - detailView.addFullSizeConstraints(forSubview: textHostingController.view) + detailView.addConstraints([ + NSLayoutConstraint(item: textHostingController.view, attribute: .top, relatedBy: .equal, toItem: detailView, attribute: .top, multiplier: 1, constant: 1), + NSLayoutConstraint(item: textHostingController.view, attribute: .bottom, relatedBy: .equal, toItem: detailView, attribute: .bottom, multiplier: 1, constant: -deleteButton.frame.height), + NSLayoutConstraint(item: textHostingController.view, attribute: .width, relatedBy: .equal, toItem: detailView, attribute: .width, multiplier: 1, constant: 1) + ]) + } } diff --git a/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift b/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift index eca8dc36a..8250a185a 100644 --- a/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift +++ b/Mac/Preferences/ExtensionPoints/ExtensionPointPreferencesViewController.swift @@ -192,7 +192,11 @@ private extension ExtensionPointPreferencesViewController { addChild(textHostingController) textHostingController.view.translatesAutoresizingMaskIntoConstraints = false detailView.addSubview(textHostingController.view) - detailView.addFullSizeConstraints(forSubview: textHostingController.view) + detailView.addConstraints([ + NSLayoutConstraint(item: textHostingController.view, attribute: .top, relatedBy: .equal, toItem: detailView, attribute: .top, multiplier: 1, constant: 1), + NSLayoutConstraint(item: textHostingController.view, attribute: .bottom, relatedBy: .equal, toItem: detailView, attribute: .bottom, multiplier: 1, constant: -deleteButton.frame.height), + NSLayoutConstraint(item: textHostingController.view, attribute: .width, relatedBy: .equal, toItem: detailView, attribute: .width, multiplier: 1, constant: 1) + ]) } }