Unverified Commit 2c1aed4e authored by bunsenstraat's avatar bunsenstraat Committed by GitHub

Rntabs (#893)

This addresses an issue when you rename a folder which has files which are open in tabs. It would recreate the current opened file because it is current and saved when another file opened. You'd get duplicate files. Also tabs from the old folder would still be visible. Now the behavior should be: tabs that belong to the folder renamed will be closed and replaced. No file will be focused. Please test.
parent 06beece3
...@@ -300,20 +300,16 @@ class FileManager extends Plugin { ...@@ -300,20 +300,16 @@ class FileManager extends Plugin {
} }
this.openFile(newName) this.openFile(newName)
} else { } else {
var newFocus
for (var k in this.openedFiles) { for (var k in this.openedFiles) {
if (k.indexOf(oldName + '/') === 0) { if (k.indexOf(oldName + '/') === 0) {
var newAbsolutePath = k.replace(oldName, newName) var newAbsolutePath = k.replace(oldName, newName)
this.openedFiles[newAbsolutePath] = newAbsolutePath this.openedFiles[newAbsolutePath] = newAbsolutePath
delete this.openedFiles[k] delete this.openedFiles[k]
if (this._deps.config.get('currentFile') === k) { if (this._deps.config.get('currentFile') === k) {
newFocus = newAbsolutePath this._deps.config.set('currentFile', '')
} }
} }
} }
if (newFocus) {
this.openFile(newFocus)
}
} }
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
this.emit('fileRenamed', oldName, newName, isFolder) this.emit('fileRenamed', oldName, newName, isFolder)
......
...@@ -60,17 +60,17 @@ export class TabProxy extends Plugin { ...@@ -60,17 +60,17 @@ export class TabProxy extends Plugin {
}) })
fileManager.events.on('fileRenamed', (oldName, newName, isFolder) => { fileManager.events.on('fileRenamed', (oldName, newName, isFolder) => {
if (isFolder) return if (isFolder) {
for (const tab of this.loadedTabs) {
if (tab.name.indexOf(oldName + '/') === 0) {
const newTabName = newName + tab.name.slice(oldName.length, tab.name.length)
this.renameTab(tab.name, newTabName)
}
}
return
}
// should change the tab title too // should change the tab title too
this.addTab(newName, '', () => { this.renameTab(oldName, newName)
this.fileManager.open(newName)
this.event.emit('openFile', newName)
},
() => {
this.fileManager.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 }) => {
...@@ -144,6 +144,18 @@ export class TabProxy extends Plugin { ...@@ -144,6 +144,18 @@ export class TabProxy extends Plugin {
} }
} }
renameTab (oldName, newName) {
this.addTab(newName, '', () => {
this.fileManager.open(newName)
this.event.emit('openFile', newName)
},
() => {
this.fileManager.closeFile(newName)
this.event.emit('closeFile', newName)
})
this.removeTab(oldName)
}
addTab (name, title, switchTo, close, icon) { addTab (name, title, switchTo, close, icon) {
if (this._handlers[name]) return if (this._handlers[name]) return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment