Skip to content

Commit

Permalink
Merge pull request #2536 from nextcloud/backport/2527/stable24
Browse files Browse the repository at this point in the history
Backport/2527/stable24
  • Loading branch information
juliusknorr authored Oct 17, 2022
2 parents 92eea60 + e94b130 commit 36a2d5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 50 deletions.
46 changes: 0 additions & 46 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,52 +49,6 @@ const odfViewer = {
excludeMimeFromDefaultOpen: OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen,
hideDownloadMimes: ['image/jpeg', 'image/svg+xml', 'image/cgm', 'image/vnd.dxf', 'image/x-emf', 'image/x-wmf', 'image/x-wpg', 'image/x-freehand', 'image/bmp', 'image/png', 'image/gif', 'image/tiff', 'image/jpg', 'image/jpeg', 'text/plain', 'application/pdf'],

registerFileActions() {
const EDIT_ACTION_NAME = 'Edit with ' + OC.getCapabilities().richdocuments.productName
for (const mime of odfViewer.supportedMimes) {
OCA.Files.fileActions.register(
mime,
EDIT_ACTION_NAME,
OC.PERMISSION_READ,
imagePath('core', 'actions/rename'),
(fileName, context) => {
// Workaround since the new template frontend doesn't pass
// the full context yet nor the filelist contains the element
// at the point when the action is triggered.
// This will be fixed by https://github.com/nextcloud/server/pull/25797
// but this should be kept for backward compatibility for now
if (!context?.$file) {
if (context?.fileList) {
context.fileList.setViewerMode(true)
}
const filePath = (context.dir === '/' ? '/' : context.dir + '/') + fileName
OCA.Files.App.fileList.filesClient.getFileInfo(filePath).then((status, fileInfo) => {
const fileModel = context.fileList.findFile(fileName)
const shareOwnerId = fileModel?.shareOwnerId || fileInfo?.shareOwnerId
context.fileId = fileInfo.id
return this.onEdit(fileName, {
...context,
shareOwnerId,
})
})
return
}

const fileModel = context.fileList.findFile(fileName)
const shareOwnerId = fileModel?.shareOwnerId
return this.onEdit(fileName, {
...context,
shareOwnerId,
})
},
t('richdocuments', 'Edit with {productName}', { productName: OC.getCapabilities().richdocuments.productName }, undefined, { escape: false })
)
if (odfViewer.excludeMimeFromDefaultOpen.indexOf(mime) === -1 || isDownloadHidden) {
OCA.Files.fileActions.setDefault(mime, EDIT_ACTION_NAME)
}
}
},

onEdit(fileName, context) {
let fileDir
let fileId
Expand Down
9 changes: 5 additions & 4 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ if (OCA.Viewer) {
// TODO: Viewer.openWith introduced with https://github.com/nextcloud/viewer/pull/1273
// This check can be replaced with `if(OCA.Viewer)` once NC 24 is EOL.
if (OCA.Viewer.openWith) {
const supportedMimes = OC.getCapabilities().richdocuments.mimetypesNoDefaultOpen
const actionName = 'Edit with ' + OC.getCapabilities().richdocuments.productName
const actionDisplayName = t('richdocuments', 'Edit with {productName}', { productName: OC.getCapabilities().richdocuments.productName }, undefined, { escape: false })
const supportedMimes = getCapabilities().richdocuments.mimetypesNoDefaultOpen
const actionName = 'Edit with ' + getCapabilities().richdocuments.productName
const actionDisplayNameEdit = t('richdocuments', 'Edit with {productName}', { productName: getCapabilities().richdocuments.productName }, undefined, { escape: false })
const actionDisplayNameOpen = t('richdocuments', 'Open with {productName}', { productName: getCapabilities().richdocuments.productName }, undefined, { escape: false })

for (const mime of supportedMimes) {
const action = {
name: actionName,
mime,
permissions: OC.PERMISSION_READ,
iconClass: 'icon-richdocuments',
displayName: actionDisplayName,
displayName: mime === 'application/pdf' ? actionDisplayNameOpen : actionDisplayNameEdit,
actionHandler: (fileName, context) => {
OCA.Viewer.openWith('richdocuments', {
path: context.fileInfoModel.getFullPath()
Expand Down

0 comments on commit 36a2d5e

Please sign in to comment.