From f00241e73e00d17bfccd1021a22d9c075c5bf3c3 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Wed, 24 Feb 2021 07:47:52 +0800 Subject: [PATCH] revised context menu code --- iOS/MasterFeed/MasterFeedViewController.swift | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index acf0a10bb..c2f719e6e 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -589,40 +589,50 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { @objc func configureContextMenu(_: Any? = nil) { if #available(iOS 14.0, *) { + + /* + Context Menu Order: + 1. Add Web Feed + 2. Add Reddit Feed + 3. Add Twitter Feed + 4. Add Folder + */ + + var menuItems: [UIAction] = [] + let addWebFeedActionTitle = NSLocalizedString("Add Web Feed", comment: "Add Web Feed") - let addWebFeedAction = UIAction(title: addWebFeedActionTitle, image: AppAssets.faviconTemplateImage.withRenderingMode(.alwaysOriginal).withTintColor(.secondaryLabel)) { _ in + let addWebFeedAction = UIAction(title: addWebFeedActionTitle, image: AppAssets.plus) { _ in self.coordinator.showAddWebFeed() } - - let addRedditFeedActionTitle = NSLocalizedString("Add Reddit Feed", comment: "Add Reddit Feed") - let addRedditFeedAction = UIAction(title: addRedditFeedActionTitle, image: AppAssets.redditOriginal) { _ in - self.coordinator.showAddRedditFeed() - } - - let addTwitterFeedActionTitle = NSLocalizedString("Add Twitter Feed", comment: "Add Twitter Feed") - let addTwitterFeedAction = UIAction(title: addTwitterFeedActionTitle, image: AppAssets.twitterOriginal) { _ in - self.coordinator.showAddTwitterFeed() - } - - let addWebFolderdActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder") - let addWebFolderAction = UIAction(title: addWebFolderdActionTitle, image: AppAssets.masterFolderImageNonIcon) { _ in - self.coordinator.showAddFolder() - } - - var children = [addWebFolderAction, addWebFeedAction] - + menuItems.append(addWebFeedAction) if AccountManager.shared.activeAccounts.contains(where: { $0.type == .onMyMac || $0.type == .cloudKit }) { if ExtensionPointManager.shared.isRedditEnabled { - children.insert(addRedditFeedAction, at: 0) + let addRedditFeedActionTitle = NSLocalizedString("Add Reddit Feed", comment: "Add Reddit Feed") + let addRedditFeedAction = UIAction(title: addRedditFeedActionTitle, image: AppAssets.contextMenuReddit.tinted(color: .label)) { _ in + self.coordinator.showAddRedditFeed() + } + menuItems.append(addRedditFeedAction) } if ExtensionPointManager.shared.isTwitterEnabled { - children.insert(addTwitterFeedAction, at: 0) + let addTwitterFeedActionTitle = NSLocalizedString("Add Twitter Feed", comment: "Add Twitter Feed") + let addTwitterFeedAction = UIAction(title: addTwitterFeedActionTitle, image: AppAssets.contextMenuTwitter.tinted(color: .label)) { _ in + self.coordinator.showAddTwitterFeed() + } + menuItems.append(addTwitterFeedAction) } } - let menu = UIMenu(title: "Add Item", image: nil, identifier: nil, options: [], children: children) + + let addWebFolderActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder") + let addWebFolderAction = UIAction(title: addWebFolderActionTitle, image: AppAssets.folderOutlinePlus) { _ in + self.coordinator.showAddFolder() + } - self.addNewItemButton.menu = menu + menuItems.append(addWebFolderAction) + + let contextMenu = UIMenu(title: NSLocalizedString("Add Item", comment: "Add Item"), image: nil, identifier: nil, options: [], children: menuItems.reversed()) + + self.addNewItemButton.menu = contextMenu } }