Skip to content

Commit c8ef74e

Browse files
authored
Merge pull request #5185 from nextcloud/backport/5059/stable30
[stable30] Refresh files list after exporting a file in a different format
2 parents 70ceb3d + 01eeb0c commit c8ef74e

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

src/mixins/saveAs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { spawnDialog } from '@nextcloud/dialogs'
7+
import { basename } from 'path'
78
import SaveAs from '../components/Modal/SaveAs.vue'
89

910
export default {
@@ -16,7 +17,13 @@ export default {
1617
format,
1718
description: t('richdocuments', 'Save a copy of the file under a new name and continue editing the new file'),
1819
},
19-
(value) => value && this.sendPostMessage('Action_SaveAs', { Filename: value, Notify: true }),
20+
(value) => {
21+
if (value) {
22+
// Track the requested filename for export operations
23+
this.lastSaveAsFilename = basename(value)
24+
this.sendPostMessage('Action_SaveAs', { Filename: value, Notify: true })
25+
}
26+
},
2027
)
2128
},
2229
},

src/view/FilesAppIntegration.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,38 @@ export default {
532532
return this.fileNode
533533
},
534534

535+
/**
536+
* Fetch metadata for a newly created file and emit files:node:created event
537+
* This is used when exporting a document (e.g., DOCX -> PDF) to make the
538+
* new file appear in the files list without manual reload
539+
*
540+
* @param {string} basename - The name of the new file (e.g., "test.pdf")
541+
*/
542+
async createNodeForNewFile(basename) {
543+
if (isPublic) {
544+
return
545+
}
546+
547+
try {
548+
const path = `${this.filePath}/${basename}`
549+
const client = davGetClient()
550+
const results = await client.getDirectoryContents(`${davRootPath}${path}`, {
551+
details: true,
552+
data: davGetDefaultPropfind(),
553+
})
554+
const nodes = results.data.map((result) => davResultToNode(result))
555+
556+
if (nodes[0]) {
557+
console.debug('[FilesAppIntegration] Emitting files:node:created for', basename)
558+
emit('files:node:created', nodes[0])
559+
} else {
560+
console.warn('[FilesAppIntegration] New file not found:', basename)
561+
}
562+
} catch (e) {
563+
console.error('Failed to fetch new file metadata from webdav', e)
564+
}
565+
},
566+
535567
changeFilesRoute(fileId) {
536568
OCP?.Files?.Router?.goToRoute(
537569
OCP.Files.Router.name,

src/view/Office.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ export default {
188188
modified: false,
189189
hasWidgetEditingEnabled: false,
190190
191+
// Track the last requested save-as filename for export operations
192+
lastSaveAsFilename: null,
193+
191194
formData: {
192195
action: null,
193196
accessToken: null,
@@ -417,8 +420,24 @@ export default {
417420
this.saveAs(args.format)
418421
break
419422
case 'Action_Save_Resp':
420-
if (args.fileName !== this.filename) {
421-
FilesAppIntegration.saveAs(args.fileName)
423+
console.debug('[viewer] Received post message Action_Save_Resp', args, this.lastSaveAsFilename)
424+
if (args.success) {
425+
let newFileName = args.fileName
426+
427+
// If no filename is provided for exportas, use the last tracked filename
428+
if (!newFileName && args.result === 'exportas' && this.lastSaveAsFilename) {
429+
newFileName = this.lastSaveAsFilename
430+
}
431+
432+
if (newFileName && newFileName !== this.filename) {
433+
// When exporting (e.g., DOCX -> PDF), a new file is created
434+
// Fetch its metadata and emit files:node:created to show it in the files list
435+
FilesAppIntegration.createNodeForNewFile(newFileName)
436+
} else {
437+
// When saving the current file, update its modification time
438+
FilesAppIntegration.updateFileInfo(undefined, Date.now())
439+
}
440+
this.lastSaveAsFilename = null
422441
}
423442
break
424443
case 'UI_InsertGraphic':

0 commit comments

Comments
 (0)