Skip to content

Commit

Permalink
Allow changing primary file extensions for text editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Jun 30, 2022
1 parent 5a01307 commit 06d8d6e
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Option to block file extensions from text-editor app

We've added support to block certain file extensions from the text-editor app with additional config. See https://owncloud.dev/clients/web/deployments/oc10-app/#additional-configuration-for-certain-core-apps

https://github.com/owncloud/web/issues/6661
https://github.com/owncloud/web/pull/7174
28 changes: 26 additions & 2 deletions docs/deployments/oc10-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,37 @@ In case the backend has additional preview providers configured there is no mech
"mimeTypes": ["image/tiff", "image/webp"]
}
}
],
]
```

If you already have an `"external_apps"` section, just add the preview app to the list. Please adjust the `"mimeTypes"` list according to your additional preview providers. See https://github.com/owncloud/files_mediaviewer#supporting-more-media-types for advise on how to add preview providers to the backend.

### Text-Editor app
The `text-editor` app provides a list of file extensions that the app is associated with, both for opening files and for creating new files.
By default, only `.txt` and `.md` files appear in the file creation menu and offer the text-editor as default app on a left mouse click
in the file list. For other file types the text-editor app only appears in the right mouse click context menu. In case you want to change this
default set of primary file extensions for the text-editor you can overwrite it as follows:
1. Remove the `"text-editor"` string from the `"apps"` section in your `config.json` file
2. Add the following config to your `config.json` file:
```json
"external_apps": [
{
"id": "text-editor",
"path": "web-app-text-editor",
"config": {
"primaryExtensions": ["txt", "yaml"]
}
}
]
```
With the above example config the text editor will offer creation of new files for `.txt` and `.yaml` files instead of `.txt` and `.md` files.
Also, a left mouse click on any `.txt` or `.yaml` file will open the respective file in the text-editor app. In this example, `.md` files would
not be opened in the text-editor by default anymore, but the text-editor will would appear in the context menu for the file as alternative app.

If you already have an `"external_apps"` section, just add the preview app to the list. Please adjust the `"mimeTypes"` list according to your additional preview providers. See https://github.com/owncloud/files_mediaviewer#supporting-more-media-types for advise on how to add preview providers to the backend.

{{< hint info >}}
The reason why the `preview` app needs to be ported from the `apps` section to the `external_apps` section is that only the `external_apps` support additional configuration. There are plans to change the configuration of apps to give you a coherent admin experience in that regard.
The reason why the app needs to be ported from the `apps` section to the `external_apps` section is that only the `external_apps` support additional configuration. There are plans to change the configuration of apps to give you a coherent admin experience in that regard.
{{< /hint >}}

## Accessing ownCloud Web
Expand Down
87 changes: 62 additions & 25 deletions packages/web-app-text-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function $gettext(msg) {
return msg
}

const appId = 'text-editor'

const routes = [
{
path: '/:filePath*',
Expand All @@ -19,41 +21,76 @@ const routes = [
}
]

const fileExtensionConfig = {
canBeDefault: true
}

const appInfo = {
name: $gettext('Text Editor'),
id: 'text-editor',
icon: 'file-text',
isFileEditor: true,
extensions: [
const fileExtensions = () => {
const extensions = [
{
extension: 'txt',
newFileMenu: {
menuTitle($gettext) {
return $gettext('Plain text file')
}
},
...fileExtensionConfig
label: $gettext('Plain text file')
},
{
extension: 'md',
newFileMenu: {
label: $gettext('Markdown file')
},
{
extension: 'js',
label: $gettext('JavaScript file')
},
{
extension: 'json',
label: $gettext('JSON file')
},
{
extension: 'xml',
label: $gettext('XML file')
},
{
extension: 'py',
label: $gettext('Python file')
},
{
extension: 'php',
label: $gettext('PHP file')
},
{
extension: 'yaml',
label: $gettext('YAML file')
}
]

let primaryExtensions = window.Vue.$store.getters.extensionConfigByAppId(appId)
.primaryExtensions || ['txt', 'md']
if (typeof primaryExtensions === 'string') {
primaryExtensions = [primaryExtensions]
}
return extensions.reduce((acc, extensionItem) => {
if (primaryExtensions.includes(extensionItem.extension)) {
extensionItem.canBeDefault = true
extensionItem.newFileMenu = {
menuTitle($gettext) {
return $gettext('Markdown file')
return $gettext(extensionItem.label)
}
},
...fileExtensionConfig
}
}
]
acc.push(extensionItem)
return acc
}, [])
}

for (const ext of ['js', 'json', 'xml', 'py', 'php', 'yaml']) {
appInfo.extensions.push({
extension: ext,
...fileExtensionConfig
const appInfo = {
name: $gettext('Text Editor'),
id: appId,
icon: 'file-text',
isFileEditor: true,
extensions: fileExtensions().map((extensionItem) => {
return {
extension: extensionItem.extension,
...(Object.prototype.hasOwnProperty.call(extensionItem, 'newFileMenu') && {
newFileMenu: extensionItem.newFileMenu
}),
...(Object.prototype.hasOwnProperty.call(extensionItem, 'canBeDefault') && {
canBeDefault: extensionItem.canBeDefault
})
}
})
}

Expand Down

0 comments on commit 06d8d6e

Please sign in to comment.