Merge pull request #1582 from dsernst/feature/sort-file-alphanumerically-1185
Context menu option to sort files by name
This commit is contained in:
@@ -291,6 +291,16 @@ module.exports = class TorrentListController {
|
|||||||
enabled: torrentSummary.torrentFileName != null
|
enabled: torrentSummary.torrentFileName != null
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
menu.append(new electron.remote.MenuItem({
|
||||||
|
type: 'separator'
|
||||||
|
}))
|
||||||
|
|
||||||
|
const sortedByName = this.state.saved.prefs.sortByName
|
||||||
|
menu.append(new electron.remote.MenuItem({
|
||||||
|
label: `${sortedByName ? '✓ ' : ''}Sort by Name`,
|
||||||
|
click: () => dispatch('updatePreferences', 'sortByName', !sortedByName)
|
||||||
|
}))
|
||||||
|
|
||||||
menu.popup({ window: electron.remote.getCurrentWindow() })
|
menu.popup({ window: electron.remote.getCurrentWindow() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -284,10 +284,17 @@ module.exports = class TorrentList extends React.Component {
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// We do know the files. List them and show download stats for each one
|
// We do know the files. List them and show download stats for each one
|
||||||
const fileRows = torrentSummary.files
|
const sortByName = this.props.state.saved.prefs.sortByName
|
||||||
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
|
||||||
|
let fileRows = torrentSummary.files
|
||||||
.filter((file) => !file.path.includes('/.____padding_file/'))
|
.filter((file) => !file.path.includes('/.____padding_file/'))
|
||||||
.map((file, index) => ({ file, index }))
|
.map((file, index) => ({ file, index }))
|
||||||
.map((object) => this.renderFileRow(torrentSummary, object.file, object.index))
|
|
||||||
|
if (sortByName) {
|
||||||
|
fileRows = fileRows.sort((a, b) => collator.compare(a.file.name, b.file.name))
|
||||||
|
}
|
||||||
|
|
||||||
|
fileRows = fileRows.map((obj) => this.renderFileRow(torrentSummary, obj.file, obj.index))
|
||||||
|
|
||||||
filesElement = (
|
filesElement = (
|
||||||
<div key='files' className='files'>
|
<div key='files' className='files'>
|
||||||
|
|||||||
Reference in New Issue
Block a user