Add "Show in Folder" to context menu
Based on @watson's PR #463. Differences: - Remove the "Open Folder" link from expanded torrent view. - Use showItemInFolder instead of openItem electron API - Add a separator - Use IPC to invoke electron.shell.showItemInFolder from main process
This commit is contained in:
@@ -70,10 +70,15 @@ function init () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('openItem', function (e, path) {
|
ipcMain.on('openItem', function (e, path) {
|
||||||
log('opening file or folder: ' + path)
|
log('open item: ' + path)
|
||||||
electron.shell.openItem(path)
|
electron.shell.openItem(path)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('showItemInFolder', function (e, path) {
|
||||||
|
log('show item in folder: ' + path)
|
||||||
|
electron.shell.showItemInFolder(path)
|
||||||
|
})
|
||||||
|
|
||||||
ipcMain.on('blockPowerSave', blockPowerSave)
|
ipcMain.on('blockPowerSave', blockPowerSave)
|
||||||
|
|
||||||
ipcMain.on('unblockPowerSave', unblockPowerSave)
|
ipcMain.on('unblockPowerSave', unblockPowerSave)
|
||||||
|
|||||||
@@ -226,9 +226,6 @@ function dispatch (action, ...args) {
|
|||||||
if (action === 'openFile') {
|
if (action === 'openFile') {
|
||||||
openFile(args[0] /* infoHash */, args[1] /* index */)
|
openFile(args[0] /* infoHash */, args[1] /* index */)
|
||||||
}
|
}
|
||||||
if (action === 'openFolder') {
|
|
||||||
openFolder(args[0] /* infoHash */)
|
|
||||||
}
|
|
||||||
if (action === 'toggleTorrent') {
|
if (action === 'toggleTorrent') {
|
||||||
toggleTorrent(args[0] /* infoHash */)
|
toggleTorrent(args[0] /* infoHash */)
|
||||||
}
|
}
|
||||||
@@ -956,17 +953,6 @@ function openFile (infoHash, index) {
|
|||||||
ipcRenderer.send('openItem', filePath)
|
ipcRenderer.send('openItem', filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
function openFolder (infoHash) {
|
|
||||||
var torrentSummary = getTorrentSummary(infoHash)
|
|
||||||
|
|
||||||
var firstFilePath = path.join(
|
|
||||||
torrentSummary.path,
|
|
||||||
torrentSummary.files[0].path)
|
|
||||||
var folderPath = path.dirname(firstFilePath)
|
|
||||||
|
|
||||||
ipcRenderer.send('openItem', folderPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: use torrentKey, not infoHash
|
// TODO: use torrentKey, not infoHash
|
||||||
function toggleTorrent (infoHash) {
|
function toggleTorrent (infoHash) {
|
||||||
var torrentSummary = getTorrentSummary(infoHash)
|
var torrentSummary = getTorrentSummary(infoHash)
|
||||||
@@ -1001,9 +987,20 @@ function toggleSelectTorrent (infoHash) {
|
|||||||
function openTorrentContextMenu (infoHash) {
|
function openTorrentContextMenu (infoHash) {
|
||||||
var torrentSummary = getTorrentSummary(infoHash)
|
var torrentSummary = getTorrentSummary(infoHash)
|
||||||
var menu = new Menu()
|
var menu = new Menu()
|
||||||
|
|
||||||
|
if (torrentSummary.files) {
|
||||||
|
menu.append(new MenuItem({
|
||||||
|
label: process.platform === 'darwin' ? 'Show in Finder' : 'Show in Folder',
|
||||||
|
click: () => showItemInFolder(torrentSummary)
|
||||||
|
}))
|
||||||
|
menu.append(new MenuItem({
|
||||||
|
type: 'separator'
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
label: 'Save Torrent File As...',
|
label: 'Copy Magnet Link to Clipboard',
|
||||||
click: () => saveTorrentFileAs(torrentSummary)
|
click: () => clipboard.writeText(torrentSummary.magnetURI)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
@@ -1012,13 +1009,21 @@ function openTorrentContextMenu (infoHash) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
menu.append(new MenuItem({
|
menu.append(new MenuItem({
|
||||||
label: 'Copy Magnet Link to Clipboard',
|
label: 'Save Torrent File As...',
|
||||||
click: () => clipboard.writeText(torrentSummary.magnetURI)
|
click: () => saveTorrentFileAs(torrentSummary)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
menu.popup(remote.getCurrentWindow())
|
menu.popup(remote.getCurrentWindow())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showItemInFolder (torrentSummary) {
|
||||||
|
var itemPath = path.join(torrentSummary.path, torrentSummary.files[0].path)
|
||||||
|
if (torrentSummary.files.length > 1) {
|
||||||
|
itemPath = path.dirname(itemPath)
|
||||||
|
}
|
||||||
|
ipcRenderer.send('showItemInFolder', itemPath)
|
||||||
|
}
|
||||||
|
|
||||||
function saveTorrentFileAs (torrentSummary) {
|
function saveTorrentFileAs (torrentSummary) {
|
||||||
var newFileName = `${path.parse(torrentSummary.name).name}.torrent`
|
var newFileName = `${path.parse(torrentSummary.name).name}.torrent`
|
||||||
var opts = {
|
var opts = {
|
||||||
|
|||||||
@@ -167,7 +167,6 @@ function TorrentList (state) {
|
|||||||
|
|
||||||
// Show files, per-file download status and play buttons, and so on
|
// Show files, per-file download status and play buttons, and so on
|
||||||
function renderTorrentDetails (torrentSummary) {
|
function renderTorrentDetails (torrentSummary) {
|
||||||
var infoHash = torrentSummary.infoHash
|
|
||||||
var filesElement
|
var filesElement
|
||||||
if (!torrentSummary.files) {
|
if (!torrentSummary.files) {
|
||||||
// We don't know what files this torrent contains
|
// We don't know what files this torrent contains
|
||||||
@@ -182,10 +181,6 @@ function TorrentList (state) {
|
|||||||
filesElement = hx`
|
filesElement = hx`
|
||||||
<div class='files'>
|
<div class='files'>
|
||||||
<strong>Files</strong>
|
<strong>Files</strong>
|
||||||
<span class='open-folder'
|
|
||||||
onclick=${dispatcher('openFolder', infoHash)}>
|
|
||||||
Open folder
|
|
||||||
</span>
|
|
||||||
<table>
|
<table>
|
||||||
${fileRows}
|
${fileRows}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user