diff --git a/main/dialog.js b/main/dialog.js index b37329e7..177e1ecc 100644 --- a/main/dialog.js +++ b/main/dialog.js @@ -3,7 +3,7 @@ module.exports = { openSeedDirectory, openTorrentFile, openTorrentAddress, - openAddFiles + openFiles } var electron = require('electron') @@ -55,6 +55,30 @@ function openSeedDirectory () { }) } +/* + * Show flexible open dialog that supports selecting .torrent files to add, or + * a file or folder to create a single-file or single-directory torrent. + */ +function openFiles () { + if (!windows.main.win) return + log('openFiles') + var opts = process.platform === 'darwin' + ? { + title: 'Select a file or folder to add.', + properties: [ 'openFile', 'openDirectory' ] + } + : { + title: 'Select a file to add.', + properties: [ 'openFile' ] + } + setTitle(opts.title) + electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) { + resetTitle() + if (!Array.isArray(selectedPaths)) return + windows.main.dispatch('onOpen', selectedPaths) + }) +} + /* * Show open dialog to open a .torrent file. */ @@ -62,7 +86,7 @@ function openTorrentFile () { if (!windows.main.win) return log('openTorrentFile') var opts = { - title: 'Select a .torrent file to open.', + title: 'Select a .torrent file.', filters: [{ name: 'Torrent Files', extensions: ['torrent'] }], properties: [ 'openFile', 'multiSelections' ] } @@ -84,24 +108,6 @@ function openTorrentAddress () { windows.main.dispatch('openTorrentAddress') } -/* - * Show open dialog for all file types (.torrent, files to seed) - */ -function openAddFiles () { - if (!windows.main.win) return - log('openAddFiles') - var opts = { - title: 'Select a .torrent file to open or start seeding files.', - properties: [ 'openFile', 'multiSelections' ] - } - setTitle(opts.title) - electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) { - resetTitle() - if (!Array.isArray(selectedPaths)) return - windows.main.dispatch('onOpen', selectedPaths) - }) -} - /** * Dialogs on do not show a title on OS X, so the window title is used instead. */ diff --git a/main/ipc.js b/main/ipc.js index fd598118..479e00e4 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -46,7 +46,7 @@ function init () { */ ipc.on('openTorrentFile', () => dialog.openTorrentFile()) - ipc.on('openAddFiles', () => dialog.openAddFiles()) + ipc.on('openFiles', () => dialog.openFiles()) /** * Dock diff --git a/renderer/main.js b/renderer/main.js index 441287d1..e0620efb 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -227,8 +227,8 @@ function dispatch (action, ...args) { if (action === 'openTorrentFile') { ipcRenderer.send('openTorrentFile') /* open torrent file */ } - if (action === 'openAddFiles') { - ipcRenderer.send('openAddFiles') /* add files with dialog */ + if (action === 'openFiles') { + ipcRenderer.send('openFiles') /* add files with dialog */ } if (action === 'showCreateTorrent') { showCreateTorrent(args[0] /* paths */) @@ -240,8 +240,8 @@ function dispatch (action, ...args) { if (action === 'createTorrent') { createTorrent(args[0] /* options */) } - if (action === 'openFile') { - openFile(args[0] /* infoHash */, args[1] /* index */) + if (action === 'openItem') { + openItem(args[0] /* infoHash */, args[1] /* index */) } if (action === 'toggleTorrent') { toggleTorrent(args[0] /* infoHash */) @@ -1157,7 +1157,7 @@ function closePlayer (cb) { cb() } -function openFile (infoHash, index) { +function openItem (infoHash, index) { var torrentSummary = getTorrentSummary(infoHash) var filePath = path.join( torrentSummary.path, diff --git a/renderer/views/header.js b/renderer/views/header.js index 11e3c398..21b9f0c7 100644 --- a/renderer/views/header.js +++ b/renderer/views/header.js @@ -39,7 +39,7 @@ function Header (state) { + onclick=${dispatcher('openFiles')}> add ` diff --git a/renderer/views/home.js b/renderer/views/home.js index 3c9e5262..2d405424 100644 --- a/renderer/views/home.js +++ b/renderer/views/home.js @@ -244,7 +244,7 @@ function TorrentList (state) { handleClick = dispatcher('play', infoHash, index) } else { icon = 'description' /* file icon, opens in OS default app */ - handleClick = dispatcher('openFile', infoHash, index) + handleClick = dispatcher('openItem', infoHash, index) } var rowClass = '' if (!isSelected) rowClass = 'disabled' // File deselected, not being torrented