diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/js/filelist.js | 60 | ||||
-rw-r--r-- | apps/files/js/navigation.js | 7 |
2 files changed, 63 insertions, 4 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 047837cd9d7..bcecdb697fe 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -653,8 +653,13 @@ */ _onShow: function(e) { if (this.shown) { - this._setCurrentDir('/', false); - this.reload(); + if (e.itemId === this.id) { + this._setCurrentDir('/', false); + } + // Only reload if we don't navigate to a different directory + if (typeof e.dir === 'undefined' || e.dir === this.getCurrentDirectory()) { + this.reload(); + } } this.shown = true; }, @@ -2308,7 +2313,55 @@ // not overwrite it targetPath = targetPath + '/'; } - self.filesClient.copy(dir + fileName, targetPath + fileName) + var targetPathAndName = targetPath + fileName; + if ((dir + fileName) === targetPathAndName) { + var dotIndex = targetPathAndName.indexOf("."); + if ( dotIndex > 1) { + var leftPartOfName = targetPathAndName.substr(0, dotIndex); + var fileNumber = leftPartOfName.match(/\d+/); + // TRANSLATORS name that is appended to copied files with the same name, will be put in parenthesis and appened with a number if it is the second+ copy + var copyNameLocalized = t('files', 'copy'); + if (isNaN(fileNumber) ) { + fileNumber++; + targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, " (" + copyNameLocalized + " " + fileNumber + ")"); + } + else { + // Check if we have other files with 'copy X' and the same name + var maxNum = 1; + if (self.files !== null) { + leftPartOfName = leftPartOfName.replace("/", ""); + leftPartOfName = leftPartOfName.replace(new RegExp("\\(" + copyNameLocalized + "( \\d+)?\\)"),""); + // find the last file with the number extension and add one to the new name + for (var j = 0; j < self.files.length; j++) { + var cName = self.files[j].name; + if (cName.indexOf(leftPartOfName) > -1) { + if (cName.indexOf("(" + copyNameLocalized + ")") > 0) { + targetPathAndName = targetPathAndName.replace(new RegExp(" \\(" + copyNameLocalized + "\\)"),""); + if (maxNum == 1) { + maxNum = 2; + } + } + else { + var cFileNumber = cName.match(new RegExp("\\(" + copyNameLocalized + " (\\d+)\\)")); + if (cFileNumber && parseInt(cFileNumber[1]) >= maxNum) { + maxNum = parseInt(cFileNumber[1]) + 1; + } + } + } + } + targetPathAndName = targetPathAndName.replace(new RegExp(" \\(" + copyNameLocalized + " \\d+\\)"),""); + } + // Create the new file name with _x at the end + // Start from 2 per a special request of the 'standard' + var extensionName = " (" + copyNameLocalized + " " + maxNum +")"; + if (maxNum == 1) { + extensionName = " (" + copyNameLocalized + ")"; + } + targetPathAndName = targetPathAndName.replace(/(?=\.[^.]+$)/g, extensionName); + } + } + } + self.filesClient.copy(dir + fileName, targetPathAndName) .done(function () { filesToNotify.push(fileName); @@ -2322,6 +2375,7 @@ oldFile.data('size', newSize); oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize)); } + self.reload(); }) .fail(function(status) { if (status === 412) { diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js index b3648fedc6c..02a0af2b369 100644 --- a/apps/files/js/navigation.js +++ b/apps/files/js/navigation.js @@ -154,7 +154,12 @@ this.$currentContent = $('#app-content-' + (typeof itemView === 'string' && itemView !== '' ? itemView : itemId)); this.$currentContent.removeClass('hidden'); if (!options || !options.silent) { - this.$currentContent.trigger(jQuery.Event('show')); + this.$currentContent.trigger(jQuery.Event('show', { + itemId: itemId, + previousItemId: oldItemId, + dir: itemDir, + view: itemView + })); this.$el.trigger( new $.Event('itemChanged', { itemId: itemId, |