Skip to content

Commit

Permalink
Merge pull request #1352 from nextcloud/enh/file-templates
Browse files Browse the repository at this point in the history
Implement support for creating files from templates
  • Loading branch information
ChristophWurst authored Jan 28, 2021
2 parents 43ec1cf + c7f0b4a commit 122908a
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions js/editor-rich.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\DirectEditing\RegisterDirectEditorEvent;
use OCP\Files\Template\ITemplateManager;
use OCP\Files\Template\TemplateFileCreator;
use OCP\IL10N;

class Application extends App implements IBootstrap {
public const APP_NAME = 'text';
Expand All @@ -53,5 +56,16 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {
$context->injectFn(function (ITemplateManager $templateManager, IL10N $l) {
$templateManager->registerTemplateFileCreator(function () use ($l) {
$markdownFile = new TemplateFileCreator(Application::APP_NAME, $l->t('New text document'), '.md');
$markdownFile->addMimetype('text/markdown');
$markdownFile->addMimetype('text/plain');
$markdownFile->setIconClass('icon-filetype-text');
$markdownFile->setRatio(1);
$markdownFile->setOrder(10);
return $markdownFile;
});
});
}
}
4 changes: 1 addition & 3 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

import Vue from 'vue'
import { registerFileActionFallback, registerFileCreate, FilesWorkspacePlugin } from './helpers/files'
import { registerFileActionFallback, FilesWorkspacePlugin } from './helpers/files'
import FilesSettings from './views/FilesSettings'
import { loadState } from '@nextcloud/initial-state'
import { linkTo } from '@nextcloud/router'
Expand All @@ -33,8 +33,6 @@ __webpack_public_path__ = linkTo('text', 'js/') // eslint-disable-line
const workspaceAvailable = loadState('text', 'workspace_available')
const workspaceEnabled = loadState('text', 'workspace_enabled')

registerFileCreate()

document.addEventListener('DOMContentLoaded', () => {
if (typeof OCA.Viewer === 'undefined') {
console.error('Viewer app is not installed')
Expand Down
3 changes: 2 additions & 1 deletion tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.3.1@2feba22a005a18bf31d4c7b9bdb9252c73897476">
<file src="lib/AppInfo/Application.php">
<UndefinedClass occurrences="3">
<UndefinedClass occurrences="4">
<code>BeforeTemplateRenderedEvent</code>
<code>ITemplateManager</code>
<code>LoadAdditionalScriptsEvent</code>
<code>LoadViewer</code>
</UndefinedClass>
Expand Down

0 comments on commit 122908a

Please sign in to comment.