/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import {Layout} from './layout'; import {Theme} from './theme'; export class Globals { private static layouts: Layout[] = []; private static themes: Theme[] = []; static registerTheme(name: string, styleClass: string): void { if (Globals.themes.some(value => value.name === name)) { console.log(`Theme with name '${name}' already registered; ignoring register request for styleClass '${styleClass}'.`) } else { Globals.themes.push({ name, styleClass }); } } static hasThemes(): boolean { return Globals.themes.length > 0; } static hasMultipleThemes(): boolean { return Globals.themes.length > 1; } static getFirstTheme(): Theme { return Globals.getTheme(0); } static getTheme(index: number): Theme { return Globals.themes[index]; } static getThemes(): Theme[] { return Globals.themes; } static registerLayout(layout: Layout): void { const available = !Globals.layouts.some(element => { if (layout.code === element.code) { if (layout.prettyName !== element.prettyName) { console.error( `Error: Language code '${layout.code}' cannot be registered for layout '${layout.prettyName}' because it is already registered for layout '${element.prettyName}'!` ); } return true; } return false; } ); if (available) { Globals.layouts.push(layout); Globals.layouts.sort((a, b) => a.prettyName.localeCompare(b.prettyName)); } } static hasLayouts(): boolean { return Globals.layouts.length > 0; } static hasMultipleLayouts(): boolean { return Globals.layouts.length > 1; } static getFirstLayout(): Layout { return Globals.layouts[0]; } static getLayouts(): Layout[] { return Globals.layouts; } }