-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(bootstrap): Lazy register template creator through event
Signed-off-by: Julius Härtl <jus@bitgrid.net>
- Loading branch information
1 parent
502805e
commit 1891ab6
Showing
4 changed files
with
74 additions
and
12 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
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,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> | ||
* | ||
* @author Morris Jobke <hey@morrisjobke.de> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Text\Listeners; | ||
|
||
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; | ||
use OCA\Richdocuments\Listener\RegisterTemplateFileCreatorListener; | ||
use OCA\Text\AppInfo\Application; | ||
use OCA\Text\Service\ConfigService; | ||
use OCA\Text\Service\InitialStateProvider; | ||
use OCP\App\IAppManager; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Template\RegisterTemplateCreatorEvent; | ||
use OCP\Files\Template\TemplateFileCreator; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\Util; | ||
|
||
/** @implements IEventListener<Event|RegisterTemplateCreatorEvent> */ | ||
class RegisterTemplateCreatorListener implements IEventListener { | ||
Check failure on line 43 in lib/Listeners/RegisterTemplateCreatorListener.php GitHub Actions / static-psalm-analysisUndefinedDocblockClass
Check failure on line 43 in lib/Listeners/RegisterTemplateCreatorListener.php GitHub Actions / static-psalm-analysisInvalidTemplateParam
|
||
public function __construct( | ||
private IL10N $l10n, | ||
private ConfigService $configService, | ||
private IAppManager $appManager, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
Check failure on line 51 in lib/Listeners/RegisterTemplateCreatorListener.php GitHub Actions / static-psalm-analysisMoreSpecificImplementedParamType
|
||
if (!$event instanceof RegisterTemplateCreatorEvent) { | ||
Check failure on line 52 in lib/Listeners/RegisterTemplateCreatorListener.php GitHub Actions / static-psalm-analysisUndefinedClass
|
||
return; | ||
} | ||
|
||
$event->getTemplateManager()->registerTemplateFileCreator(function () { | ||
$markdownFile = new TemplateFileCreator(Application::APP_NAME, $this->l10n->t('New text file'), '.' . $this->configService->getDefaultFileExtension()); | ||
$markdownFile->addMimetype('text/markdown'); | ||
$markdownFile->addMimetype('text/plain'); | ||
$markdownFile->setIconSvgInline(file_get_contents($this->appManager->getAppPath('text') . '/img/article.svg')); | ||
$markdownFile->setRatio(1); | ||
$markdownFile->setOrder(10); | ||
$markdownFile->setActionLabel($this->l10n->t('Create new text file')); | ||
return $markdownFile; | ||
}); | ||
|
||
|
||
} | ||
} |