mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 06:02:29 -06:00
Merge pull request #13995 from glassez/rename-files
Improve content file/folder names handling
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<script src="scripts/lib/mootools-1.2-core-yc.js"></script>
|
||||
<script src="scripts/lib/mootools-1.2-more.js"></script>
|
||||
<script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
|
||||
<script src="scripts/filesystem.js?v=${CACHEID}"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
@@ -31,14 +32,15 @@
|
||||
|
||||
window.addEvent('domready', function() {
|
||||
const hash = new URI().getData('hash');
|
||||
const name = new URI().getData('name');
|
||||
const id = new URI().getData('id');
|
||||
if (!hash || !name || !id) return;
|
||||
const path = new URI().getData('path');
|
||||
const isFolder = ((new URI().getData('isFolder')) === 'true');
|
||||
|
||||
const decodedName = decodeURIComponent(name);
|
||||
$('rename').value = decodedName;
|
||||
const oldPath = decodeURIComponent(path);
|
||||
const oldName = window.qBittorrent.Filesystem.fileName(oldPath);
|
||||
$('rename').value = oldName;
|
||||
$('rename').focus();
|
||||
$('rename').setSelectionRange(0, decodedName.lastIndexOf('.'));
|
||||
if (!isFolder)
|
||||
$('rename').setSelectionRange(0, oldName.lastIndexOf('.'));
|
||||
|
||||
$('renameButton').addEvent('click', function(e) {
|
||||
new Event(e).stop();
|
||||
@@ -49,20 +51,24 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (newName === name) {
|
||||
if (newName === oldName) {
|
||||
alert('QBT_TR(Name is unchanged)QBT_TR[CONTEXT=HttpServer]');
|
||||
return;
|
||||
}
|
||||
|
||||
$('renameButton').disabled = true;
|
||||
|
||||
const parentPath = window.qBittorrent.Filesystem.folderName(oldPath)
|
||||
const newPath = parentPath
|
||||
? parentPath + window.qBittorrent.Filesystem.PathSeparator + newName
|
||||
: newName;
|
||||
new Request({
|
||||
url: 'api/v2/torrents/renameFile',
|
||||
url: isFolder ? 'api/v2/torrents/renameFolder' : 'api/v2/torrents/renameFile',
|
||||
method: 'post',
|
||||
data: {
|
||||
hash: hash,
|
||||
id: id,
|
||||
name: newName
|
||||
oldPath: oldPath,
|
||||
newPath: newPath
|
||||
},
|
||||
onSuccess: function() {
|
||||
window.parent.closeWindows();
|
||||
|
||||
@@ -117,6 +117,7 @@ window.qBittorrent.FileTree = (function() {
|
||||
|
||||
const FileNode = new Class({
|
||||
name: "",
|
||||
path: "",
|
||||
rowId: null,
|
||||
size: 0,
|
||||
checked: TriState.Unchecked,
|
||||
|
||||
@@ -70,7 +70,7 @@ window.qBittorrent.Filesystem = (function() {
|
||||
const folderName = function(filepath) {
|
||||
const slashIndex = filepath.lastIndexOf(PathSeparator);
|
||||
if (slashIndex === -1)
|
||||
return filepath;
|
||||
return '';
|
||||
return filepath.substring(0, slashIndex);
|
||||
};
|
||||
|
||||
|
||||
@@ -423,9 +423,9 @@ window.qBittorrent.PropFiles = (function() {
|
||||
|
||||
rows.forEach(function(row) {
|
||||
let parent = rootNode;
|
||||
const pathFolders = row.fileName.split(window.qBittorrent.Filesystem.PathSeparator);
|
||||
pathFolders.pop();
|
||||
pathFolders.forEach(function(folderName) {
|
||||
let folderPath = window.qBittorrent.Filesystem.folderName(row.fileName);
|
||||
while (folderPath) {
|
||||
const folderName = window.qBittorrent.Filesystem.fileName(folderPath);
|
||||
if (folderName === '.unwanted')
|
||||
return;
|
||||
|
||||
@@ -439,8 +439,10 @@ window.qBittorrent.PropFiles = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parentNode === null) {
|
||||
parentNode = new window.qBittorrent.FileTree.FolderNode();
|
||||
parentNode.path = folderPath;
|
||||
parentNode.name = folderName;
|
||||
parentNode.rowId = rowId;
|
||||
parentNode.root = parent;
|
||||
@@ -450,12 +452,14 @@ window.qBittorrent.PropFiles = (function() {
|
||||
}
|
||||
|
||||
parent = parentNode;
|
||||
});
|
||||
folderPath = window.qBittorrent.Filesystem.folderName(folderPath);
|
||||
}
|
||||
|
||||
const isChecked = row.checked ? TriState.Checked : TriState.Unchecked;
|
||||
const remaining = (row.priority === FilePriority.Ignored) ? 0 : row.remaining;
|
||||
const childNode = new window.qBittorrent.FileTree.FileNode();
|
||||
childNode.name = row.name;
|
||||
childNode.path = row.fileName;
|
||||
childNode.rowId = rowId;
|
||||
childNode.size = row.size;
|
||||
childNode.checked = isChecked;
|
||||
@@ -527,17 +531,16 @@ window.qBittorrent.PropFiles = (function() {
|
||||
if (rowId === undefined) return;
|
||||
const row = torrentFilesTable.rows[rowId];
|
||||
if (!row) return;
|
||||
const node = torrentFilesTable.getNode(rowId);
|
||||
if (node.isFolder) return;
|
||||
|
||||
const name = row.full_data.name;
|
||||
const fileId = row.full_data.fileId;
|
||||
const node = torrentFilesTable.getNode(rowId);
|
||||
const path = node.path;
|
||||
|
||||
new MochaUI.Window({
|
||||
id: 'renamePage',
|
||||
title: "QBT_TR(Renaming)QBT_TR[CONTEXT=TorrentContentTreeView]",
|
||||
loadMethod: 'iframe',
|
||||
contentURL: 'rename_file.html?hash=' + hash + '&id=' + fileId + '&name=' + encodeURIComponent(name),
|
||||
contentURL: 'rename_file.html?hash=' + hash + '&isFolder=' + node.isFolder
|
||||
+ '&path=' + encodeURIComponent(path),
|
||||
scrollbars: false,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
@@ -570,13 +573,6 @@ window.qBittorrent.PropFiles = (function() {
|
||||
this.hideItem('FilePrio');
|
||||
else
|
||||
this.showItem('FilePrio');
|
||||
|
||||
const rowId = torrentFilesTable.selectedRowsIds()[0];
|
||||
const node = torrentFilesTable.getNode(rowId);
|
||||
if (node.isFolder)
|
||||
this.hideItem('Rename');
|
||||
else
|
||||
this.showItem('Rename');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user