Permalink
Browse files

Add copy urls & open in browser in playlist context menu

[Localization Changes]
& add zh-Hans & zh-Hant localization
Ref: #2271
  • Loading branch information...
alejx committed Feb 7, 2019
1 parent d549247 commit 1a3bcdfe9094012b6aea639b0ef3d0141fae8139
@@ -238,6 +238,9 @@
"pl_menu.matched_sub" = "Matched %d Subtitle(s)";
"pl_menu.add_sub" = "Add Subtitle…";
"pl_menu.wrong_sub" = "Wrong Subtitle!";
"pl_menu.browser" = "Open in Browser";
"pl_menu.copy_url" = "Copy URL";
"pl_menu.copy_url_multi" = "Copy URLs";

"keymapping.title" = "Key Mapping";
"keymapping.message" = "Press any key to record.";
@@ -664,6 +664,26 @@ class PlaylistViewController: NSViewController, NSTableViewDataSource, NSTableVi

}

@IBAction func contextOpenInBrowser(_ sender: NSMenuItem) {
guard let selectedRows = selectedRows else { return }
selectedRows.forEach { i in
let info = player.info.playlist[i]
if info.isNetworkResource, let url = URL(string: info.filename) {
NSWorkspace.shared.open(url)
}
}
}

@IBAction func contextCopyURL(_ sender: NSMenuItem) {
guard let selectedRows = selectedRows else { return }
let urls = selectedRows.compactMap { i -> String? in
let info = player.info.playlist[i]
return info.isNetworkResource ? info.filename : nil
}
NSPasteboard.general.clearContents()
NSPasteboard.general.writeObjects([urls.joined(separator: "\n") as NSString])
}

private func buildMenu(forRows rows: IndexSet) -> NSMenu {
let result = NSMenu()
let isSingleItem = rows.count == 1
@@ -693,7 +713,12 @@ class PlaylistViewController: NSViewController, NSTableViewDataSource, NSTableVi
}

result.addItem(NSMenuItem.separator())

// network resources related operations
if rows.contains (where: {player.info.playlist[$0].isNetworkResource}) {
result.addItem(withTitle: NSLocalizedString("pl_menu.browser", comment: "Open in Browser"), action: #selector(self.contextOpenInBrowser(_:)))
result.addItem(withTitle: NSLocalizedString(isSingleItem ? "pl_menu.copy_url" : "pl_menu.copy_url_multi", comment: "Copy URL(s)"), action: #selector(self.contextCopyURL(_:)))
result.addItem(NSMenuItem.separator())
}
// file related operations
if rows.contains (where: {!player.info.playlist[$0].isNetworkResource}) {
result.addItem(withTitle: NSLocalizedString(isSingleItem ? "pl_menu.delete" : "pl_menu.delete_multi", comment: "Delete"), action: #selector(self.contextMenuDeleteFile(_:)))
@@ -177,6 +177,9 @@
"pl_menu.reveal_in_finder" = "在 Finder 中显示";
"pl_menu.title_multi" = "%d 个项目";
"pl_menu.wrong_sub" = "错误的字幕!";
"pl_menu.browser" = "在浏览器中打开";
"pl_menu.copy_url" = "复制链接";
"pl_menu.copy_url_multi" = "复制链接";
"playlist.chapter_cap" = "章节";
"playlist.playlist_cap" = "播放列表";
"playlist.total_length" = "总计 %@";
@@ -177,6 +177,9 @@
"pl_menu.reveal_in_finder" = "在 Finder 中打開";
"pl_menu.title_multi" = "%d個檔案";
"pl_menu.wrong_sub" = "錯誤的字幕!";
"pl_menu.browser" = "在瀏覽器中打開";
"pl_menu.copy_url" = "複製鏈接";
"pl_menu.copy_url_multi" = "複製鏈接";
"playlist.chapter_cap" = "章節";
"playlist.playlist_cap" = "播放列表";
"playlist.total_length" = "總計 %@";

1 comment on commit 1a3bcdf

@anohren

This comment has been minimized.

Copy link
Contributor

anohren commented on 1a3bcdf Feb 16, 2019

Thumbs up!

Please sign in to comment.