From 3c983dbfa82681a2771cb9c86cfd343108b3ef5e Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Fri, 12 Jul 2024 11:55:21 +0600 Subject: [PATCH] Add Open in new Fire Window link option --- DuckDuckGo/Common/Localizables/UserText.swift | 1 + DuckDuckGo/Localizable.xcstrings | 14 ++++++++- .../TabExtensions/ContextMenuManager.swift | 30 +++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/DuckDuckGo/Common/Localizables/UserText.swift b/DuckDuckGo/Common/Localizables/UserText.swift index e048abe74a..6c92796d0b 100644 --- a/DuckDuckGo/Common/Localizables/UserText.swift +++ b/DuckDuckGo/Common/Localizables/UserText.swift @@ -295,6 +295,7 @@ struct UserText { static let openLinkInNewTab = NSLocalizedString("open.link.in.new.tab", value: "Open Link in New Tab", comment: "Context menu item") static let openLinkInNewBurnerTab = NSLocalizedString("open.link.in.new.burner.tab", value: "Open Link in New Fire Tab", comment: "Context menu item") + static let openLinkInNewBurnerWindow = NSLocalizedString("open.link.in.new.burner.window", value: "Open Link in New Fire Window", comment: "Context menu item") static let openImageInNewTab = NSLocalizedString("open.image.in.new.tab", value: "Open Image in New Tab", comment: "Context menu item") static let openImageInNewBurnerTab = NSLocalizedString("open.image.in.new.burner.tab", value: "Open Image in New Fire Tab", comment: "Context menu item") static let copyImageAddress = NSLocalizedString("copy.image.address", value: "Copy Image Address", comment: "Context menu item") diff --git a/DuckDuckGo/Localizable.xcstrings b/DuckDuckGo/Localizable.xcstrings index 467de64434..2604d71a52 100644 --- a/DuckDuckGo/Localizable.xcstrings +++ b/DuckDuckGo/Localizable.xcstrings @@ -34486,6 +34486,18 @@ } } }, + "open.link.in.new.burner.window" : { + "comment" : "Context menu item", + "extractionState" : "extracted_with_value", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "new", + "value" : "Open Link in New Fire Window" + } + } + } + }, "open.link.in.new.tab" : { "comment" : "Context menu item", "extractionState" : "extracted_with_value", @@ -56082,4 +56094,4 @@ } }, "version" : "1.0" -} \ No newline at end of file +} diff --git a/DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift b/DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift index 57174a6ec7..c21b04bbb1 100644 --- a/DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift +++ b/DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift @@ -127,7 +127,10 @@ extension ContextMenuManager { if isCurrentWindowBurner || !isWebViewSupportedScheme { menu.removeItem(at: index) } else { - menu.replaceItem(at: index, with: self.openLinkInNewWindowMenuItem(from: item)) + let newWindowItem = self.openLinkInNewWindowMenuItem(from: item) + let newFireWindowItem = self.openLinkInNewFireWindowMenuItem(from: item, alternate: true) + menu.replaceItem(at: index, with: newWindowItem) + menu.insertItem(newFireWindowItem, at: index + 1) } } @@ -255,6 +258,15 @@ private extension ContextMenuManager { makeMenuItem(withTitle: item.title, action: #selector(openLinkInNewWindow), from: item, with: .openLinkInNewWindow) } + func openLinkInNewFireWindowMenuItem(from item: NSMenuItem, alternate: Bool) -> NSMenuItem { + let menuItem = makeMenuItem(withTitle: UserText.openLinkInNewBurnerWindow, action: #selector(openLinkInNewFireWindow), from: item, with: .openLinkInNewWindow) + if alternate { + menuItem.isAlternate = alternate + menuItem.keyEquivalentModifierMask = .option + } + return menuItem + } + func openFrameInNewWindowMenuItem(from item: NSMenuItem) -> NSMenuItem { makeMenuItem(withTitle: item.title, action: #selector(openFrameInNewWindow), from: item, with: .openFrameInNewWindow) } @@ -381,6 +393,13 @@ private extension ContextMenuManager { } func openLinkInNewWindow(_ sender: NSMenuItem) { + openLinkInNewWindowCommon(sender, burner: false) + } + func openLinkInNewFireWindow(_ sender: NSMenuItem) { + openLinkInNewWindowCommon(sender, burner: true) + } + + func openLinkInNewWindowCommon(_ sender: NSMenuItem, burner: Bool) { guard let originalItem = sender.representedObject as? NSMenuItem, let identifier = originalItem.identifier.map(WKMenuItemIdentifier.init), identifier == .openLinkInNewWindow, @@ -390,8 +409,13 @@ private extension ContextMenuManager { return } - onNewWindow = { _ in - .allow(.window(active: true, burner: false)) + onNewWindow = { navigationAction in + if burner { + WindowsManager.openNewWindow(with: navigationAction?.request.url ?? .blankPage, source: .link, isBurner: true) + return .cancel + } else { + return .allow(.window(active: true, burner: false)) + } } NSApp.sendAction(action, to: originalItem.target, from: originalItem) }