|
76 | 76 | @click="showSidebar"> |
77 | 77 | {{ t('viewer', 'Open sidebar') }} |
78 | 78 | </NcActionButton> |
79 | | - <NcActionLink v-if="canDownload" |
80 | | - :download="currentFile.basename" |
| 79 | + <NcActionButton v-if="canDownload" |
81 | 80 | :close-after-click="true" |
82 | | - :href="downloadPath"> |
| 81 | + @click="onDownload"> |
83 | 82 | <template #icon> |
84 | 83 | <Download :size="20" /> |
85 | 84 | </template> |
86 | 85 | {{ t('viewer', 'Download') }} |
87 | | - </NcActionLink> |
| 86 | + </NcActionButton> |
88 | 87 | <NcActionButton v-if="canDelete" |
89 | 88 | :close-after-click="true" |
90 | 89 | @click="onDelete"> |
@@ -1006,12 +1005,7 @@ export default defineComponent({ |
1006 | 1005 | if (event.key === 's' && event.ctrlKey === true) { |
1007 | 1006 | event.preventDefault() |
1008 | 1007 | if (this.canDownload) { |
1009 | | - const a = document.createElement('a') |
1010 | | - a.href = this.currentFile.source ?? this.currentFile.davPath |
1011 | | - a.download = this.currentFile.basename |
1012 | | - document.body.appendChild(a) |
1013 | | - a.click() |
1014 | | - document.body.removeChild(a) |
| 1008 | + this.onDownload() |
1015 | 1009 | } |
1016 | 1010 | } |
1017 | 1011 | }, |
@@ -1196,6 +1190,49 @@ export default defineComponent({ |
1196 | 1190 | this.toggleEditor(true) |
1197 | 1191 | }, |
1198 | 1192 |
|
| 1193 | + /** |
| 1194 | + * Save active Text editors before downloading |
| 1195 | + */ |
| 1196 | + async onDownload() { |
| 1197 | + if (!this.canDownload) { |
| 1198 | + return |
| 1199 | + } |
| 1200 | +
|
| 1201 | + // Check if Text app is available and has active editor components |
| 1202 | + if (window.OCA?.Text?.editorComponents) { |
| 1203 | + try { |
| 1204 | + logger.debug('Text app detected, attempting to save before download') |
| 1205 | +
|
| 1206 | + const editorComponents = window.OCA.Text.editorComponents |
| 1207 | +
|
| 1208 | + // Text app uses a Set to store editor components |
| 1209 | + if (editorComponents instanceof Set) { |
| 1210 | + for (const component of editorComponents) { |
| 1211 | + if (component && typeof component.save === 'function') { |
| 1212 | + logger.debug('Calling save on Text editor component') |
| 1213 | + await component.save() |
| 1214 | + } |
| 1215 | + } |
| 1216 | + } |
| 1217 | + } catch (error) { |
| 1218 | + logger.warn('Failed to save Text editor before download', { error }) |
| 1219 | + // Continue with download anyway |
| 1220 | + } |
| 1221 | + } |
| 1222 | +
|
| 1223 | + this.performDownload() |
| 1224 | + }, |
| 1225 | +
|
| 1226 | + performDownload() { |
| 1227 | + logger.debug('Performing download', { file: this.currentFile }) |
| 1228 | + const a = document.createElement('a') |
| 1229 | + a.href = this.currentFile.source ?? this.currentFile.davPath |
| 1230 | + a.download = this.currentFile.basename |
| 1231 | + document.body.appendChild(a) |
| 1232 | + a.click() |
| 1233 | + document.body.removeChild(a) |
| 1234 | + }, |
| 1235 | +
|
1199 | 1236 | handleTrapElementsChange(element) { |
1200 | 1237 | this.trapElements.push(element) |
1201 | 1238 | }, |
|
0 commit comments