mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
feat: inline delete prompt in remove dialog (#7000)
Co-authored-by: Yat Ho <lagoho7@gmail.com>
This commit is contained in:
@@ -31,7 +31,10 @@ export class ActionManager extends EventTarget {
|
||||
enabled: false,
|
||||
text: 'Ask tracker for more peers',
|
||||
},
|
||||
'remove-selected-torrents': { enabled: false, text: 'Remove from list…' },
|
||||
'remove-selected-torrents': {
|
||||
enabled: false,
|
||||
text: 'Remove selected torrents',
|
||||
},
|
||||
'resume-selected-torrents': {
|
||||
enabled: false,
|
||||
shortcut: 'R',
|
||||
@@ -79,10 +82,6 @@ export class ActionManager extends EventTarget {
|
||||
'start-all-torrents': { enabled: false, text: 'Start all' },
|
||||
'toggle-compact-rows': { enabled: true, text: 'Compact rows' },
|
||||
'toggle-contrast': { enabled: true, text: 'High contrast UI' },
|
||||
'trash-selected-torrents': {
|
||||
enabled: false,
|
||||
text: 'Trash data and remove from list…',
|
||||
},
|
||||
'verify-selected-torrents': {
|
||||
enabled: false,
|
||||
shortcut: 'V',
|
||||
@@ -199,7 +198,6 @@ export class ActionManager extends EventTarget {
|
||||
'show-inspector',
|
||||
'show-labels-dialog',
|
||||
'show-move-dialog',
|
||||
'trash-selected-torrents',
|
||||
'verify-selected-torrents',
|
||||
]);
|
||||
|
||||
|
||||
@@ -169,7 +169,6 @@ export class ContextMenu extends EventTarget {
|
||||
),
|
||||
new_separator(),
|
||||
new_item('remove-selected-torrents', true),
|
||||
new_item('trash-selected-torrents', true),
|
||||
new_separator(),
|
||||
new_item('verify-selected-torrents'),
|
||||
new_item('show-move-dialog'),
|
||||
|
||||
@@ -9,8 +9,9 @@ export class RemoveDialog extends EventTarget {
|
||||
constructor(options) {
|
||||
super();
|
||||
|
||||
// options: remote, torrents, trash
|
||||
// options: remote, torrents
|
||||
this.options = options;
|
||||
this.options.trash = false;
|
||||
this.elements = RemoveDialog._create(options);
|
||||
this.elements.dismiss.addEventListener('click', () => this._onDismiss());
|
||||
this.elements.confirm.addEventListener('click', () => this._onConfirm());
|
||||
@@ -43,38 +44,50 @@ export class RemoveDialog extends EventTarget {
|
||||
}
|
||||
|
||||
static _create(options) {
|
||||
const { trash } = options;
|
||||
const { heading, message } = RemoveDialog._createMessage(options);
|
||||
|
||||
const { torrents } = options;
|
||||
const elements = createDialogContainer('remove-dialog');
|
||||
elements.heading.textContent = heading;
|
||||
elements.message.textContent = message;
|
||||
elements.confirm.textContent = trash ? 'Trash' : 'Remove';
|
||||
const { confirm, heading, message, workarea } = elements;
|
||||
|
||||
heading.textContent =
|
||||
torrents.length === 1
|
||||
? `Remove ${torrents[0].getName()}?`
|
||||
: `Remove ${torrents.length} transfers?`;
|
||||
|
||||
const check = document.createElement('input');
|
||||
check.id = 'delete-local-data-check';
|
||||
check.type = 'checkbox';
|
||||
check.checked = false;
|
||||
message.append(check);
|
||||
|
||||
const label = document.createElement('label');
|
||||
label.id = 'delete-local-data-label';
|
||||
label.setAttribute('for', check.id);
|
||||
label.textContent = 'Delete downloaded data';
|
||||
message.append(label);
|
||||
|
||||
const body = document.createElement('div');
|
||||
const rewrite = (checked) => {
|
||||
if (checked && torrents.length === 1) {
|
||||
body.textContent =
|
||||
'All data downloaded for this torrent will be deleted. Are you sure you want to remove it?';
|
||||
} else if (checked) {
|
||||
body.textContent =
|
||||
'All data downloaded for these torrents will be deleted. Are you sure you want to remove them?';
|
||||
} else if (torrents.length === 1) {
|
||||
body.textContent =
|
||||
'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?';
|
||||
} else {
|
||||
body.textContent =
|
||||
'Once removed, continuing the transfers will require the torrent files. Are you sure you want to remove them?';
|
||||
}
|
||||
confirm.textContent = checked ? 'Delete' : 'Remove';
|
||||
};
|
||||
rewrite(check.checked);
|
||||
check.addEventListener('click', () => {
|
||||
options.trash = check.checked;
|
||||
rewrite(check.checked);
|
||||
});
|
||||
workarea.append(body);
|
||||
return elements;
|
||||
}
|
||||
|
||||
static _createMessage(options) {
|
||||
let heading = null;
|
||||
let message = null;
|
||||
const { torrents, trash } = options;
|
||||
const [torrent] = torrents;
|
||||
if (trash && torrents.length === 1) {
|
||||
heading = `Remove ${torrent.getName()} and delete data?`;
|
||||
message =
|
||||
'All data downloaded for this torrent will be deleted. Are you sure you want to remove it?';
|
||||
} else if (trash) {
|
||||
heading = `Remove ${torrents.length} transfers and delete data?`;
|
||||
message =
|
||||
'All data downloaded for these torrents will be deleted. Are you sure you want to remove them?';
|
||||
} else if (torrents.length === 1) {
|
||||
heading = `Remove ${torrent.getName()}?`;
|
||||
message =
|
||||
'Once removed, continuing the transfer will require the torrent file. Are you sure you want to remove it?';
|
||||
} else {
|
||||
heading = `Remove ${torrents.length} transfers?`;
|
||||
message =
|
||||
'Once removed, continuing the transfers will require the torrent files. Are you sure you want to remove them?';
|
||||
}
|
||||
return { heading, message };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ export class Transmission extends EventTarget {
|
||||
this._reannounceTorrents(this.getSelectedTorrents());
|
||||
break;
|
||||
case 'remove-selected-torrents':
|
||||
this._removeSelectedTorrents(false);
|
||||
this._removeSelectedTorrents();
|
||||
break;
|
||||
case 'resume-selected-torrents':
|
||||
this._startSelectedTorrents(false);
|
||||
@@ -209,9 +209,6 @@ export class Transmission extends EventTarget {
|
||||
? Prefs.DisplayFull
|
||||
: Prefs.DisplayCompact;
|
||||
break;
|
||||
case 'trash-selected-torrents':
|
||||
this._removeSelectedTorrents(true);
|
||||
break;
|
||||
case 'verify-selected-torrents':
|
||||
this._verifyTorrents(this.getSelectedTorrents());
|
||||
break;
|
||||
@@ -928,12 +925,10 @@ TODO: fix this when notifications get fixed
|
||||
}
|
||||
}
|
||||
|
||||
_removeSelectedTorrents(trash) {
|
||||
_removeSelectedTorrents() {
|
||||
const torrents = this.getSelectedTorrents();
|
||||
if (torrents.length > 0) {
|
||||
this.setCurrentPopup(
|
||||
new RemoveDialog({ remote: this.remote, torrents, trash }),
|
||||
);
|
||||
this.setCurrentPopup(new RemoveDialog({ remote: this.remote, torrents }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user