Rewrite it in TypeScript; I have no idea if that works. It's still a work-in-progress.
This commit is contained in:
parent
079bda7fb0
commit
5420f9c817
14 changed files with 3420 additions and 47 deletions
87
src/domain/globals.ts
Normal file
87
src/domain/globals.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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(langCode: string, layout: Layout): void {
|
||||
const available = Globals.layouts.some(element => {
|
||||
if (langCode === element.code) {
|
||||
console.error(
|
||||
`Error: Language code '${langCode}' cannot be registered for layout '${layout.prettyName}'
|
||||
because it is already registered for layout '${element.prettyName}'!`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
);
|
||||
if (available) {
|
||||
layout.code = langCode;
|
||||
Globals.layouts.push(layout);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue