Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2022-07-15 00:14:56 +0300
committernextcloud-command <nextcloud-command@users.noreply.github.com>2022-07-19 09:23:37 +0300
commit09c9489befce3d566ac23d74ec2f9d66aa1364c8 (patch)
treec9431031514557f499ecc730f1027d3ce65ef453 /lib
parent52a82ad602c8ebfde2891cea19df3a5cd2920aa4 (diff)
Add option to set default file extension and disable rich editing
Signed-off-by: Julius Härtl <jus@bitgrid.net> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php7
-rw-r--r--lib/Listeners/FilesLoadAdditionalScriptsListener.php29
-rw-r--r--lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php22
-rw-r--r--lib/Listeners/LoadViewerListener.php12
-rw-r--r--lib/Service/ConfigService.php33
-rw-r--r--lib/Service/InitialStateProvider.php39
6 files changed, 99 insertions, 43 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index aaa39fd18..672cc8810 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -34,6 +34,7 @@ use OCA\Text\Listeners\FilesLoadAdditionalScriptsListener;
use OCA\Text\Listeners\FilesSharingLoadAdditionalScriptsListener;
use OCA\Text\Listeners\LoadViewerListener;
use OCA\Text\Listeners\RegisterDirectEditorEventListener;
+use OCA\Text\Service\ConfigService;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -66,9 +67,9 @@ class Application extends App implements IBootstrap {
}
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 file'), '.md');
+ $context->injectFn(function (ITemplateManager $templateManager, IL10N $l, ConfigService $configService) {
+ $templateManager->registerTemplateFileCreator(function () use ($l, $configService) {
+ $markdownFile = new TemplateFileCreator(Application::APP_NAME, $l->t('New text file'), '.' . $configService->getDefaultFileExtension());
$markdownFile->addMimetype('text/markdown');
$markdownFile->addMimetype('text/plain');
$markdownFile->setIconClass('icon-filetype-text');
diff --git a/lib/Listeners/FilesLoadAdditionalScriptsListener.php b/lib/Listeners/FilesLoadAdditionalScriptsListener.php
index 6ebceca58..ae822cb81 100644
--- a/lib/Listeners/FilesLoadAdditionalScriptsListener.php
+++ b/lib/Listeners/FilesLoadAdditionalScriptsListener.php
@@ -26,28 +26,18 @@ declare(strict_types=1);
namespace OCA\Text\Listeners;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
-use OCA\Text\AppInfo\Application;
+use OCA\Text\Service\InitialStateProvider;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
-use OCP\IConfig;
-use OCP\IInitialStateService;
-use OCP\IUserSession;
/**
* @implements IEventListener<Event>
*/
class FilesLoadAdditionalScriptsListener implements IEventListener {
- /** @var IConfig */
- protected $config;
- /** @var IInitialStateService */
- protected $initialStateService;
- /** @var IUserSession */
- protected $userSession;
+ private InitialStateProvider $initialStateProvider;
- public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) {
- $this->config = $config;
- $this->initialStateService = $initialStateService;
- $this->userSession = $userSession;
+ public function __construct(InitialStateProvider $initialStateProvider) {
+ $this->initialStateProvider = $initialStateProvider;
}
public function handle(Event $event): void {
@@ -57,15 +47,6 @@ class FilesLoadAdditionalScriptsListener implements IEventListener {
\OCP\Util::addScript('text', 'text-files');
- $this->initialStateService->provideInitialState(
- Application::APP_NAME,
- 'workspace_available',
- $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'
- );
- $this->initialStateService->provideInitialState(
- Application::APP_NAME,
- 'workspace_enabled',
- $this->config->getUserValue($this->userSession->getUser()->getUID(), Application::APP_NAME, 'workspace_enabled', '1') === '1'
- );
+ $this->initialStateProvider->provideState();
}
}
diff --git a/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php
index 3ba381d92..660d8cf6c 100644
--- a/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php
+++ b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php
@@ -25,31 +25,23 @@ declare(strict_types=1);
namespace OCA\Text\Listeners;
-use OCA\Text\AppInfo\Application;
+use OCA\Text\Service\InitialStateProvider;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
-use OCP\IInitialStateService;
+use OCP\Util;
/** @implements IEventListener<Event> */
class FilesSharingLoadAdditionalScriptsListener implements IEventListener {
- /** @var IConfig */
- protected $config;
- /** @var IInitialStateService */
- protected $initialStateService;
+ protected InitialStateProvider $initialStateProvider;
- public function __construct(IConfig $config, IInitialStateService $initialStateService) {
- $this->config = $config;
- $this->initialStateService = $initialStateService;
+ public function __construct(IConfig $config, InitialStateProvider $initialStateProvider) {
+ $this->initialStateProvider = $initialStateProvider;
}
public function handle(Event $event): void {
- \OCP\Util::addScript('text', 'text-public');
+ Util::addScript('text', 'text-public');
- $this->initialStateService->provideInitialState(
- Application::APP_NAME,
- 'workspace_available',
- $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'
- );
+ $this->initialStateProvider->provideState();
}
}
diff --git a/lib/Listeners/LoadViewerListener.php b/lib/Listeners/LoadViewerListener.php
index 48c1b38d2..163173b13 100644
--- a/lib/Listeners/LoadViewerListener.php
+++ b/lib/Listeners/LoadViewerListener.php
@@ -25,16 +25,26 @@ declare(strict_types=1);
namespace OCA\Text\Listeners;
+use OCA\Text\Service\InitialStateProvider;
use OCA\Viewer\Event\LoadViewer;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
+use OCP\Util;
/** @implements IEventListener<Event> */
class LoadViewerListener implements IEventListener {
+ private InitialStateProvider $initialStateProvider;
+
+ public function __construct(InitialStateProvider $initialStateProvider) {
+ $this->initialStateProvider = $initialStateProvider;
+ }
+
public function handle(Event $event): void {
if (!$event instanceof LoadViewer) {
return;
}
- \OCP\Util::addScript('text', 'text-viewer', 'viewer');
+ Util::addScript('text', 'text-viewer', 'viewer');
+
+ $this->initialStateProvider->provideState();
}
}
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
new file mode 100644
index 000000000..1ab6e65ae
--- /dev/null
+++ b/lib/Service/ConfigService.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace OCA\Text\Service;
+
+use OCA\Text\AppInfo\Application;
+use OCP\IConfig;
+
+class ConfigService {
+ private IConfig $config;
+
+ public function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
+ public function getDefaultFileExtension(): string {
+ return $this->config->getAppValue(Application::APP_NAME, 'default_file_extension', 'md');
+ }
+
+ public function isRichEditingEnabled(): bool {
+ return ($this->config->getAppValue(Application::APP_NAME, 'rich_editing_enabled', '1') === '1');
+ }
+
+ public function isRichWorkspaceAvailable(): bool {
+ return $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1';
+ }
+
+ public function isRichWorkspaceEnabledForUser(?string $userId): bool {
+ if ($userId === null) {
+ return true;
+ }
+ return $this->config->getUserValue($userId, Application::APP_NAME, 'workspace_enabled', '1') === '1';
+ }
+}
diff --git a/lib/Service/InitialStateProvider.php b/lib/Service/InitialStateProvider.php
new file mode 100644
index 000000000..3acd782b8
--- /dev/null
+++ b/lib/Service/InitialStateProvider.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace OCA\Text\Service;
+
+use OCP\AppFramework\Services\IInitialState;
+
+class InitialStateProvider {
+ private IInitialState $initialState;
+ private ConfigService $configService;
+ private ?string $userId;
+
+ public function __construct(IInitialState $initialState, ConfigService $configService, ?string $userId) {
+ $this->initialState = $initialState;
+ $this->configService = $configService;
+ $this->userId = $userId;
+ }
+
+ public function provideState(): void {
+ $this->initialState->provideInitialState(
+ 'workspace_available',
+ $this->configService->isRichWorkspaceAvailable()
+ );
+
+ $this->initialState->provideInitialState(
+ 'workspace_enabled',
+ $this->configService->isRichWorkspaceEnabledForUser($this->userId)
+ );
+
+ $this->initialState->provideInitialState(
+ 'default_file_extension',
+ $this->configService->getDefaultFileExtension()
+ );
+
+ $this->initialState->provideInitialState(
+ 'rich_editing_enabled',
+ $this->configService->isRichEditingEnabled()
+ );
+ }
+}