-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: file action for opening pdf files with richdocuments
Signed-off-by: Elizabeth Danzberger <[email protected]>
- Loading branch information
Showing
7 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace OCA\Richdocuments\Listener; | ||
|
||
use OCA\Richdocuments\AppInfo\Application; | ||
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Util; | ||
|
||
/** @template-implements IEventListener<LoadAdditionalScriptsEvent> */ | ||
class LoadAdditionalListener implements IEventListener { | ||
public function handle(Event $event): void { | ||
// If not a LoadAdditionalScriptsEvent, we should do nothing | ||
if (!($event instanceof LoadAdditionalScriptsEvent)) { | ||
return; | ||
} | ||
|
||
// If we can add an init script, we add the file-actions script | ||
if (method_exists(Util::class, 'addInitScript')) { | ||
Util::addInitScript(Application::APPNAME, 'richdocuments-fileActions'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { registerFileAction, FileAction } from '@nextcloud/files' | ||
import { getCapabilities } from '@nextcloud/capabilities' | ||
import { translate as t } from '@nextcloud/l10n' | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
import appIcon from '../img/app.svg?raw' | ||
|
||
const richdocuments = getCapabilities().richdocuments | ||
|
||
const openPdf = new FileAction({ | ||
id: 'office-open-pdf', | ||
|
||
iconSvgInline: () => { | ||
// Make sure the icon is the correct color | ||
return appIcon.replaceAll(/#(fff|0{6})/g, 'currentColor') | ||
}, | ||
|
||
displayName: () => { | ||
return t('richdocuments', | ||
'Edit with {productName}', | ||
{ productName: richdocuments.productName }) | ||
}, | ||
|
||
enabled: () => { | ||
// Only enable the file action when files_pdfviewer is enabled | ||
const optionalMimetypes = richdocuments.mimetypesNoDefaultOpen | ||
return optionalMimetypes.includes('application/pdf') | ||
}, | ||
|
||
exec: (file) => { | ||
// If no viewer API, we can't open the document | ||
if (!OCA.Viewer) { | ||
return | ||
} | ||
|
||
OCA.Viewer.openWith('richdocuments', { path: file.path }) | ||
}, | ||
}) | ||
|
||
registerFileAction(openPdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters