Skip to content

Commit 76bfe43

Browse files
Adapt BringToFront to only support order-agnostic layouts (#436)
Fixes eclipse-glsp/glsp#1554
1 parent ab936c7 commit 76bfe43

File tree

8 files changed

+160
-11
lines changed

8 files changed

+160
-11
lines changed

packages/client/src/default-modules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import {
2727
expandModule,
2828
fadeModule,
2929
modelSourceModule,
30-
resolveContainerConfiguration,
31-
zorderModule
30+
resolveContainerConfiguration
3231
} from '@eclipse-glsp/sprotty';
3332
import { Container } from 'inversify';
3433
import { defaultModule } from './base/default.module';
@@ -62,6 +61,7 @@ import { nodeCreationToolModule } from './features/tools/node-creation/node-crea
6261
import { toolFocusLossModule } from './features/tools/tool-focus-loss-module';
6362
import { markerNavigatorModule, validationModule } from './features/validation/validation-modules';
6463
import { viewportModule } from './features/viewport/viewport-modules';
64+
import { zorderModule } from './features/zorder/zorder-module';
6565

6666
export const DEFAULT_MODULES = [
6767
defaultModule,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 {
18+
LayoutContainer,
19+
LayoutRegistry,
20+
SprottyBringToFrontCommand,
21+
TYPES,
22+
ZOrderElement,
23+
isLayoutContainer
24+
} from '@eclipse-glsp/sprotty';
25+
import { inject, injectable } from 'inversify';
26+
27+
@injectable()
28+
export class BringToFrontCommand extends SprottyBringToFrontCommand {
29+
@inject(TYPES.LayoutRegistry) protected layoutRegistry: LayoutRegistry;
30+
31+
protected getLayoutContainer(zorder: ZOrderElement): LayoutContainer | undefined {
32+
return isLayoutContainer(zorder.element.parent) ? zorder.element.parent : undefined;
33+
}
34+
35+
protected shouldBringToFront(zorder: ZOrderElement): boolean {
36+
// only re-order children if the layout supports it
37+
const layoutContainer = this.getLayoutContainer(zorder);
38+
return !layoutContainer || (this.layoutRegistry.get(layoutContainer.layout)?.orderAgnostic ?? true);
39+
}
40+
41+
protected override bringToFront(zorder: ZOrderElement): void {
42+
if (this.shouldBringToFront(zorder)) {
43+
super.bringToFront(zorder);
44+
}
45+
}
46+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
import { FeatureModule, configureCommand } from '@eclipse-glsp/sprotty';
17+
import { boundsModule } from '../bounds/bounds-module';
18+
import { BringToFrontCommand } from './bring-to-front-command';
19+
20+
export const zorderModule = new FeatureModule(
21+
(bind, _unbind, isBound) => {
22+
const context = { bind, isBound };
23+
configureCommand(context, BringToFrontCommand);
24+
},
25+
{ featureId: Symbol('zorder'), requires: [boundsModule] }
26+
);

packages/client/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ export * from './features/viewport/viewport-key-listener';
226226
export * from './features/viewport/viewport-modules';
227227
export * from './features/viewport/viewport-tool';
228228
export * from './features/viewport/zoom-viewport-action';
229+
export * from './features/zorder/bring-to-front-command';
230+
export * from './features/zorder/zorder-module';
229231
export * from './model';
230232
export * from './re-exports';
231233
export * from './standalone-modules';

packages/glsp-sprotty/src/feature-modules.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2023-2024 EclipseSource and others.
2+
* Copyright (c) 2023-2025 EclipseSource and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -26,7 +26,6 @@ import sprottyFadeModule from 'sprotty/lib/features/fade/di.config';
2626
import sprottyMoveModule from 'sprotty/lib/features/move/di.config';
2727
import sprottyOpenModule from 'sprotty/lib/features/open/di.config';
2828
import sprottyUpdateModule from 'sprotty/lib/features/update/di.config';
29-
import sprottyZorderModule from 'sprotty/lib/features/zorder/di.config';
3029
import sprottyModelSourceModule from 'sprotty/lib/model-source/di.config';
3130

3231
export const buttonModule = new FeatureModule(sprottyButtonModule.registry, { featureId: Symbol('button') });
@@ -39,7 +38,6 @@ export const modelSourceModule = new FeatureModule(sprottyModelSourceModule.regi
3938
export const moveModule = new FeatureModule(sprottyMoveModule.registry, { featureId: Symbol('move') });
4039
export const openModule = new FeatureModule(sprottyOpenModule.registry, { featureId: Symbol('open') });
4140
export const updateModule = new FeatureModule(sprottyUpdateModule.registry, { featureId: Symbol('update') });
42-
export const zorderModule = new FeatureModule(sprottyZorderModule.registry, { featureId: Symbol('zorder') });
4341
export const edgeJunctionModule = new FeatureModule(sprottyEdgeJunctionModule.registry, { featureId: Symbol('edgeJunction') });
4442

4543
export { sprottyDefaultModule };

packages/glsp-sprotty/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (c) 2024 EclipseSource and others.
2+
* Copyright (c) 2024-2025 EclipseSource and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -15,6 +15,7 @@
1515
********************************************************************************/
1616
export * from './api-override';
1717
export * from './feature-modules';
18+
export * from './layout-override';
1819
export * from './re-exports';
1920
export * from './svg-views-override';
2021
export * from './types';
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}

packages/glsp-sprotty/src/re-exports.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ export * from 'sprotty/lib/base/views/vnode-utils';
9595
// export * from 'sprotty/lib/base/types';
9696

9797
// ------------------ Features ------------------
98-
export * from 'sprotty/lib/features/bounds/abstract-layout';
9998
export * from 'sprotty/lib/features/bounds/bounds-manipulation';
100-
export * from 'sprotty/lib/features/bounds/hbox-layout';
99+
export { HBoxLayoutOptions } from 'sprotty/lib/features/bounds/hbox-layout';
101100
export * from 'sprotty/lib/features/bounds/hidden-bounds-updater';
102-
export * from 'sprotty/lib/features/bounds/layout';
101+
export { Layouter, StatefulLayouter } from 'sprotty/lib/features/bounds/layout';
103102
export { AbstractLayoutOptions } from 'sprotty/lib/features/bounds/layout-options';
104103
export {
105104
InternalBoundsAware as BoundsAware,
@@ -122,7 +121,7 @@ export {
122121
} from 'sprotty/lib/features/bounds/model';
123122
// exclude stack layout as its not supported in GLSP
124123
// export * from 'sprotty/lib/features/bounds/stack-layout';
125-
export * from 'sprotty/lib/features/bounds/vbox-layout';
124+
export { VBoxLayoutOptions } from 'sprotty/lib/features/bounds/vbox-layout';
126125
export * from 'sprotty/lib/features/bounds/views';
127126

128127
export { ButtonHandlerRegistry, IButtonHandlerRegistration, configureButtonHandler } from 'sprotty/lib/features/button/button-handler';
@@ -247,7 +246,7 @@ export * from 'sprotty/lib/features/viewport/viewport';
247246
export { ViewportRootElementImpl as GViewportRootElement } from 'sprotty/lib/features/viewport/viewport-root';
248247
export * from 'sprotty/lib/features/viewport/zoom';
249248

250-
export * from 'sprotty/lib/features/zorder/zorder';
249+
export { BringToFrontCommand as SprottyBringToFrontCommand, ZOrderElement } from 'sprotty/lib/features/zorder/zorder';
251250

252251
// ------------------ Graph ------------------
253252
// Alias SModel types

0 commit comments

Comments
 (0)