Lazy register the navigation

This makes sure that we do not translate unneeded strings on for example
webdav requests.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2020-07-09 09:48:09 +02:00 committed by Morris Jobke
parent f3768e2a2a
commit 1cf3280c8e
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
2 changed files with 84 additions and 75 deletions

View File

@ -153,28 +153,34 @@ class Application extends App implements IBootstrap {
private function registerNavigation(IBootContext $context): void { private function registerNavigation(IBootContext $context): void {
/** @var IL10N $l10n */ /** @var IL10N $l10n */
$l10n = $context->getAppContainer()->query(IL10N::class); $l10n = $context->getAppContainer()->query(IL10N::class);
\OCA\Files\App::getNavigationManager()->add([ \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
return [
'id' => 'files', 'id' => 'files',
'appname' => 'files', 'appname' => 'files',
'script' => 'list.php', 'script' => 'list.php',
'order' => 0, 'order' => 0,
'name' => $l10n->t('All files') 'name' => $l10n->t('All files')
]); ];
\OCA\Files\App::getNavigationManager()->add([ });
\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
return [
'id' => 'recent', 'id' => 'recent',
'appname' => 'files', 'appname' => 'files',
'script' => 'recentlist.php', 'script' => 'recentlist.php',
'order' => 2, 'order' => 2,
'name' => $l10n->t('Recent') 'name' => $l10n->t('Recent')
]); ];
\OCA\Files\App::getNavigationManager()->add([ });
\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
return [
'id' => 'favorites', 'id' => 'favorites',
'appname' => 'files', 'appname' => 'files',
'script' => 'simplelist.php', 'script' => 'simplelist.php',
'order' => 5, 'order' => 5,
'name' => $l10n->t('Favorites'), 'name' => $l10n->t('Favorites'),
'expandedState' => 'show_Quick_Access' 'expandedState' => 'show_Quick_Access'
]); ];
});
} }
private function registerHooks(): void { private function registerHooks(): void {

View File

@ -161,64 +161,66 @@ class Application extends App {
protected function setupSharingMenus() { protected function setupSharingMenus() {
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$l = \OC::$server->getL10N('files_sharing');
if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { if ($config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
return; return;
} }
// show_Quick_Access stored as string
\OCA\Files\App::getNavigationManager()->add(function () {
$config = \OC::$server->getConfig();
$l = \OC::$server->getL10N('files_sharing');
$sharingSublistArray = []; $sharingSublistArray = [];
if (\OCP\Util::isSharingDisabledForUser() === false) { if (\OCP\Util::isSharingDisabledForUser() === false) {
array_push($sharingSublistArray, [ $sharingSublistArray[] = [
'id' => 'sharingout', 'id' => 'sharingout',
'appname' => 'files_sharing', 'appname' => 'files_sharing',
'script' => 'list.php', 'script' => 'list.php',
'order' => 16, 'order' => 16,
'name' => $l->t('Shared with others'), 'name' => $l->t('Shared with others'),
]); ];
} }
array_push($sharingSublistArray, [ $sharingSublistArray[] = [
'id' => 'sharingin', 'id' => 'sharingin',
'appname' => 'files_sharing', 'appname' => 'files_sharing',
'script' => 'list.php', 'script' => 'list.php',
'order' => 15, 'order' => 15,
'name' => $l->t('Shared with you'), 'name' => $l->t('Shared with you'),
]); ];
if (\OCP\Util::isSharingDisabledForUser() === false) { if (\OCP\Util::isSharingDisabledForUser() === false) {
// Check if sharing by link is enabled // Check if sharing by link is enabled
if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') { if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
array_push($sharingSublistArray, [ $sharingSublistArray[] = [
'id' => 'sharinglinks', 'id' => 'sharinglinks',
'appname' => 'files_sharing', 'appname' => 'files_sharing',
'script' => 'list.php', 'script' => 'list.php',
'order' => 17, 'order' => 17,
'name' => $l->t('Shared by link'), 'name' => $l->t('Shared by link'),
]); ];
} }
} }
array_push($sharingSublistArray, [ $sharingSublistArray[] = [
'id' => 'deletedshares', 'id' => 'deletedshares',
'appname' => 'files_sharing', 'appname' => 'files_sharing',
'script' => 'list.php', 'script' => 'list.php',
'order' => 19, 'order' => 19,
'name' => $l->t('Deleted shares'), 'name' => $l->t('Deleted shares'),
]); ];
array_push($sharingSublistArray, [ $sharingSublistArray[] = [
'id' => 'pendingshares', 'id' => 'pendingshares',
'appname' => 'files_sharing', 'appname' => 'files_sharing',
'script' => 'list.php', 'script' => 'list.php',
'order' => 19, 'order' => 19,
'name' => $l->t('Pending shares'), 'name' => $l->t('Pending shares'),
]); ];
return [
// show_Quick_Access stored as string
\OCA\Files\App::getNavigationManager()->add([
'id' => 'shareoverview', 'id' => 'shareoverview',
'appname' => 'files_sharing', 'appname' => 'files_sharing',
'script' => 'list.php', 'script' => 'list.php',
@ -227,6 +229,7 @@ class Application extends App {
'classes' => 'collapsible', 'classes' => 'collapsible',
'sublist' => $sharingSublistArray, 'sublist' => $sharingSublistArray,
'expandedState' => 'show_sharing_menu' 'expandedState' => 'show_sharing_menu'
]); ];
});
} }
} }