|
| 1 | +/******************************************************************************** |
| 2 | + * Copyright (c) 2025 EclipseSource and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * This Source Code may also be made available under the following Secondary |
| 9 | + * Licenses when the conditions for such availability set forth in the Eclipse |
| 10 | + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 |
| 11 | + * with the GNU Classpath Exception which is available at |
| 12 | + * https://www.gnu.org/software/classpath/license.html. |
| 13 | + * |
| 14 | + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | + ********************************************************************************/ |
| 16 | + |
| 17 | +import { inject, injectable, interfaces, multiInject, optional } from 'inversify'; |
| 18 | +import { |
| 19 | + ILogger, |
| 20 | + InstanceRegistry, |
| 21 | + HBoxLayouter as SHBoxLayouter, |
| 22 | + ILayout as SLayout, |
| 23 | + LayoutRegistration as SLayoutRegistration, |
| 24 | + VBoxLayouter as SVBoxLayouter, |
| 25 | + TYPES, |
| 26 | + configureLayout as sconfigureLayout |
| 27 | +} from 'sprotty'; |
| 28 | +import { AbstractLayout as SAbstractLayout } from 'sprotty/lib/features/bounds/abstract-layout'; |
| 29 | +import { AbstractLayoutOptions } from './re-exports'; |
| 30 | + |
| 31 | +export interface ILayout extends SLayout { |
| 32 | + /** Flag to indicate whether the layouting of the children is independant from their order. */ |
| 33 | + orderAgnostic?: boolean; |
| 34 | +} |
| 35 | + |
| 36 | +export interface LayoutRegistration extends SLayoutRegistration { |
| 37 | + factory: () => ILayout; |
| 38 | +} |
| 39 | + |
| 40 | +@injectable() |
| 41 | +export class LayoutRegistry extends InstanceRegistry<ILayout> { |
| 42 | + @inject(TYPES.ILogger) logger: ILogger; |
| 43 | + |
| 44 | + constructor(@multiInject(TYPES.LayoutRegistration) @optional() layouts: LayoutRegistration[] = []) { |
| 45 | + super(); |
| 46 | + layouts.forEach(layout => { |
| 47 | + if (this.hasKey(layout.layoutKind)) { |
| 48 | + this.logger.warn('Layout kind is already defined: ', layout.layoutKind); |
| 49 | + } else { |
| 50 | + this.register(layout.layoutKind, layout.factory()); |
| 51 | + } |
| 52 | + }); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +export function configureLayout( |
| 57 | + context: { bind: interfaces.Bind; isBound: interfaces.IsBound }, |
| 58 | + kind: string, |
| 59 | + constr: interfaces.ServiceIdentifier<ILayout> |
| 60 | +): void { |
| 61 | + return sconfigureLayout(context, kind, constr); |
| 62 | +} |
| 63 | + |
| 64 | +@injectable() |
| 65 | +export abstract class AbstractLayout<T extends AbstractLayoutOptions> extends SAbstractLayout<T> implements ILayout { |
| 66 | + orderAgnostic?: boolean = true; |
| 67 | +} |
| 68 | + |
| 69 | +@injectable() |
| 70 | +export class VBoxLayouter extends SVBoxLayouter implements ILayout { |
| 71 | + orderAgnostic?: boolean = false; |
| 72 | +} |
| 73 | + |
| 74 | +@injectable() |
| 75 | +export class HBoxLayouter extends SHBoxLayouter implements ILayout { |
| 76 | + orderAgnostic?: boolean = false; |
| 77 | +} |
0 commit comments