Skip to content
This repository has been archived by the owner on Feb 24, 2025. It is now read-only.

Add Open in new Fire Window link option #2967

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 13 additions & 1 deletion DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -56082,4 +56094,4 @@
}
},
"version" : "1.0"
}
}
30 changes: 27 additions & 3 deletions DuckDuckGo/Tab/TabExtensions/ContextMenuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
Loading