Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mixins/saveAs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
spawnDialog(
SaveAs,
{
path: this.filename,
path: this.activeFilename,
format,
description: t('richdocuments', 'Save a copy of the file under a new name and continue editing the new file'),
},
Expand Down
6 changes: 4 additions & 2 deletions src/view/FilesAppIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,13 @@ export default {
if (nodes[0]) {
console.debug('[FilesAppIntegration] Emitting files:node:created for', basename)
emit('files:node:created', nodes[0])
} else {
console.warn('[FilesAppIntegration] New file not found:', basename)
return nodes[0]
}
console.warn('[FilesAppIntegration] New file not found:', basename)
return null
} catch (e) {
console.error('Failed to fetch new file metadata from webdav', e)
return null
}
},

Expand Down
61 changes: 49 additions & 12 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ export default {
// Track the last requested save-as filename for export operations
lastSaveAsFilename: null,

// Active document identity. The filename/fileid props only carry the
// initially opened document; these are updated when a save-as moves
// the editor session to a new file.
activeFileid: this.fileid,
activeFilename: this.filename,

// Store original favicon for restoration
originalFavicon: null,

Expand Down Expand Up @@ -240,7 +246,7 @@ export default {
return this.loadingMsg
}

return t('richdocuments', 'Loading {filename} …', { filename: basename(this.filename) }, 1, { escape: false })
return t('richdocuments', 'Loading {filename} …', { filename: basename(this.activeFilename) }, 1, { escape: false })
},
debug() {
return !!window.TESTING
Expand Down Expand Up @@ -284,14 +290,14 @@ export default {
return
}

if (this.fileid) {
if (this.activeFileid) {
const fileList = OCA?.Files?.App?.getCurrentFileList?.()
FilesAppIntegration.init({
fileName: basename(this.filename),
fileId: this.fileid,
filePath: dirname(this.filename),
fileName: basename(this.activeFilename),
fileId: this.activeFileid,
filePath: dirname(this.activeFilename),
fileList,
fileModel: fileList?.getModelForFile(basename(this.filename)),
fileModel: fileList?.getModelForFile(basename(this.activeFilename)),
sendPostMessage: (msgId, values) => {
this.postMessage.sendWOPIPostMessage(FRAME_DOCUMENT, msgId, values)
},
Expand Down Expand Up @@ -322,8 +328,8 @@ export default {
},
methods: {
async load() {
const fileid = this.fileid ?? basename(dirname(this.source))
const version = this.fileid ? '0' : basename(this.source)
const fileid = this.activeFileid ?? basename(dirname(this.source))
const version = this.activeFileid ? '0' : basename(this.source)

enableScrollLock()

Expand Down Expand Up @@ -390,6 +396,32 @@ export default {
this.load()
this.$refs.documentFrame.contentWindow.location.replace(this.iframeSrc)
},
async switchToSavedAsFile(newBasename) {
const node = await FilesAppIntegration.createNodeForNewFile(newBasename)
if (!node) {
// New file could not be resolved, avoid reloading into a bad state
return
}
this.activeFilename = node.path
this.activeFileid = node.fileid

// FilesAppIntegration keeps its own copy of the file identity
const fileList = OCA?.Files?.App?.getCurrentFileList?.()
FilesAppIntegration.init({
fileName: node.basename,
fileId: node.fileid,
filePath: node.dirname,
fileList,
fileModel: fileList?.getModelForFile(node.basename),
sendPostMessage: (msgId, values) => {
this.postMessage.sendWOPIPostMessage(FRAME_DOCUMENT, msgId, values)
},
})
FilesAppIntegration.changeFilesRoute(node.fileid)

this.loading = LOADING_STATE.LOADING
await this.load()
},
postMessageHandler({ parsed }) {
const { msgId, args, deprecated } = parsed
console.debug('[viewer] Received post message', msgId, args, deprecated)
Expand Down Expand Up @@ -459,16 +491,21 @@ export default {
if (!newFileName && args.result === 'exportas' && this.lastSaveAsFilename) {
newFileName = this.lastSaveAsFilename
}
this.lastSaveAsFilename = null

if (newFileName && newFileName !== this.filename) {
// When exporting (e.g., DOCX -> PDF), a new file is created
// Fetch its metadata and emit files:node:created to show it in the files list
if (newFileName && args.result === 'exportas') {
// Exporting (e.g. DOCX -> PDF) creates a new file but the
// editor keeps editing the original, so only surface the
// new file in the files list.
FilesAppIntegration.createNodeForNewFile(newFileName)
} else if (newFileName && newFileName !== basename(this.activeFilename)) {
// A real save-as: Collabora has switched to a new file, so
// the editor session has to be re-initialised for it.
this.switchToSavedAsFile(newFileName)
} else {
// When saving the current file, update its modification time
FilesAppIntegration.updateFileInfo(undefined, Date.now())
}
this.lastSaveAsFilename = null
}
break
case 'UI_InsertGraphic':
Expand Down
Loading