From da9b3a20ca0cfcf7022549acac44f1df94de4e51 Mon Sep 17 00:00:00 2001 From: LianaHus Date: Tue, 31 Mar 2020 00:51:13 +0200 Subject: [PATCH] issue with rename of folder fixed --- src/app/files/file-explorer.js | 29 +++++++++++++++++++++-------- src/app/files/fileManager.js | 4 ++-- src/app/panels/tab-proxy.js | 6 ++++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 2d8f8f7157..8610acbab4 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -177,12 +177,13 @@ function fileExplorer (localRegistry, files, menuItems) { } }, formatSelf: function formatSelf (key, data, li) { - var isRoot = data.path === self.files.type + const isRoot = data.path === self.files.type + const isFolder = !!data.children return yo`
{ if (!files.remove(key)) { tooltip(`failed to remove ${key}. Make sure the directory is empty before removing it.`) @@ -277,7 +278,7 @@ function fileExplorer (localRegistry, files, menuItems) { const currentFilename = extractNameFromKey(key) modalDialogCustom.confirm( - `Delete ${currentFilename} file`, `Are you sure you want to delete ${currentFilename} file?`, + `Delete file`, `Are you sure you want to delete ${currentFilename} file?`, () => { files.remove(key) self.updatePath('browser') @@ -343,7 +344,9 @@ function fileExplorer (localRegistry, files, menuItems) { } function editModeOff (event) { - var label = this + let label = this + + const isFolder = label.className.indexOf('folder') !== -1 function rename () { var newPath = label.dataset.path newPath = newPath.split('/') @@ -370,10 +373,14 @@ function fileExplorer (localRegistry, files, menuItems) { if (event.which === 13) event.preventDefault() if ((event.type === 'blur' || event.which === 13) && label.getAttribute('contenteditable')) { - var isFolder = label.className.indexOf('folder') !== -1 var save = textUnderEdit !== label.innerText if (save) { - modalDialogCustom.confirm('Confirm to rename a file', 'Are you sure you want to rename this file?', () => { rename() }, () => { label.innerText = textUnderEdit }) + modalDialogCustom.confirm( + 'Confirm to rename a ' + (isFolder ? 'folder' : 'file'), + 'Are you sure you want to rename ' + textUnderEdit + '?', + () => { rename() }, + () => { label.innerText = textUnderEdit } + ) } label.removeAttribute('contenteditable') label.classList.remove('bg-light') @@ -653,7 +660,13 @@ fileExplorer.prototype.renderMenuItems = function () { ` } else { return yo` - { event.stopPropagation(); this[ action ]() }} class="newFile ${icon} ${css.newFile}" title=${title}> + { event.stopPropagation(); this[ action ]() }} + class="newFile ${icon} ${css.newFile}" + title=${title}> + ` } }) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index fc04454455..dd8340cf06 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -89,8 +89,8 @@ class FileManager extends Plugin { } } // TODO: Only keep `this.emit` (issue#2210) - this.emit('fileRenamed', oldName, newName) - this.events.emit('fileRenamed', oldName, newName) + this.emit('fileRenamed', oldName, newName, isFolder) + this.events.emit('fileRenamed', oldName, newName, isFolder) } currentFileProvider () { diff --git a/src/app/panels/tab-proxy.js b/src/app/panels/tab-proxy.js index fa42875908..56cd59015f 100644 --- a/src/app/panels/tab-proxy.js +++ b/src/app/panels/tab-proxy.js @@ -43,8 +43,9 @@ export class TabProxy { }) }) - fileManager.events.on('fileRenamed', (oldName, newName) => { - this.removeTab(oldName) + fileManager.events.on('fileRenamed', (oldName, newName, isFolder) => { + if (isFolder) return + // should change the tab title too this.addTab(newName, '', () => { this.fileManager.switchFile(newName) this.event.emit('switchFile', newName) @@ -53,6 +54,7 @@ export class TabProxy { this.fileManager.closeFile(newName) this.event.emit('closeFile', newName) }) + this.removeTab(oldName) }) appManager.event.on('activate', ({ name, location, displayName, icon }) => {