issue with rename of folder fixed

pull/5370/head
LianaHus 5 years ago
parent 8507e41c70
commit 1606aff030
  1. 29
      src/app/files/file-explorer.js
  2. 4
      src/app/files/fileManager.js
  3. 6
      src/app/panels/tab-proxy.js

@ -177,12 +177,13 @@ function fileExplorer (localRegistry, files, menuItems) {
} }
}, },
formatSelf: function formatSelf (key, data, li) { 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` return yo`
<div class="${css.items}"> <div class="${css.items}">
<span <span
title="${data.path}" title="${data.path}"
class="${css.label} ${!isRoot ? css.leaf : ''}" class="${css.label} ${!isRoot ? !isFolder ? css.leaf : css.folder : ''}"
data-path="${data.path}" data-path="${data.path}"
style="${isRoot ? 'font-weight:bold;' : ''}" style="${isRoot ? 'font-weight:bold;' : ''}"
onkeydown=${editModeOff} onkeydown=${editModeOff}
@ -236,7 +237,7 @@ function fileExplorer (localRegistry, files, menuItems) {
if (self.files.isReadOnly(key)) { return tooltip('cannot delete folder. ' + self.files.type + ' is a read only explorer') } if (self.files.isReadOnly(key)) { return tooltip('cannot delete folder. ' + self.files.type + ' is a read only explorer') }
const currentFoldername = extractNameFromKey(key) const currentFoldername = extractNameFromKey(key)
modalDialogCustom.confirm(`Confirm to delete ${currentFoldername} folder`, `Are you sure you want to delete ${currentFoldername} folder?`, modalDialogCustom.confirm(`Confirm to delete folder`, `Are you sure you want to delete ${currentFoldername} folder?`,
() => { () => {
if (!files.remove(key)) { if (!files.remove(key)) {
tooltip(`failed to remove ${key}. Make sure the directory is empty before removing it.`) 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) const currentFilename = extractNameFromKey(key)
modalDialogCustom.confirm( 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) files.remove(key)
self.updatePath('browser') self.updatePath('browser')
@ -343,7 +344,9 @@ function fileExplorer (localRegistry, files, menuItems) {
} }
function editModeOff (event) { function editModeOff (event) {
var label = this let label = this
const isFolder = label.className.indexOf('folder') !== -1
function rename () { function rename () {
var newPath = label.dataset.path var newPath = label.dataset.path
newPath = newPath.split('/') newPath = newPath.split('/')
@ -370,10 +373,14 @@ function fileExplorer (localRegistry, files, menuItems) {
if (event.which === 13) event.preventDefault() if (event.which === 13) event.preventDefault()
if ((event.type === 'blur' || event.which === 13) && label.getAttribute('contenteditable')) { if ((event.type === 'blur' || event.which === 13) && label.getAttribute('contenteditable')) {
var isFolder = label.className.indexOf('folder') !== -1
var save = textUnderEdit !== label.innerText var save = textUnderEdit !== label.innerText
if (save) { 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.removeAttribute('contenteditable')
label.classList.remove('bg-light') label.classList.remove('bg-light')
@ -653,7 +660,13 @@ fileExplorer.prototype.renderMenuItems = function () {
` `
} else { } else {
return yo` return yo`
<span id=${action} data-id="fileExplorerNewFile${action}" onclick=${(event) => { event.stopPropagation(); this[ action ]() }} class="newFile ${icon} ${css.newFile}" title=${title}></span> <span
id=${action}
data-id="fileExplorerNewFile${action}"
onclick=${(event) => { event.stopPropagation(); this[ action ]() }}
class="newFile ${icon} ${css.newFile}"
title=${title}>
</span>
` `
} }
}) })

@ -89,8 +89,8 @@ class FileManager extends Plugin {
} }
} }
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
this.emit('fileRenamed', oldName, newName) this.emit('fileRenamed', oldName, newName, isFolder)
this.events.emit('fileRenamed', oldName, newName) this.events.emit('fileRenamed', oldName, newName, isFolder)
} }
currentFileProvider () { currentFileProvider () {

@ -43,8 +43,9 @@ export class TabProxy {
}) })
}) })
fileManager.events.on('fileRenamed', (oldName, newName) => { fileManager.events.on('fileRenamed', (oldName, newName, isFolder) => {
this.removeTab(oldName) if (isFolder) return
// should change the tab title too
this.addTab(newName, '', () => { this.addTab(newName, '', () => {
this.fileManager.switchFile(newName) this.fileManager.switchFile(newName)
this.event.emit('switchFile', newName) this.event.emit('switchFile', newName)
@ -53,6 +54,7 @@ export class TabProxy {
this.fileManager.closeFile(newName) this.fileManager.closeFile(newName)
this.event.emit('closeFile', newName) this.event.emit('closeFile', newName)
}) })
this.removeTab(oldName)
}) })
appManager.event.on('activate', ({ name, location, displayName, icon }) => { appManager.event.on('activate', ({ name, location, displayName, icon }) => {

Loading…
Cancel
Save