-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve update handling between editors
- Ensure GLSP selection is forwarded again if active editor changes - Only update properties if selection of active widget changes - Add additional change reason for better update decision in GLSP
- Loading branch information
1 parent
73aa596
commit 877dcf2
Showing
12 changed files
with
113 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 11 additions & 15 deletions
26
packages/glsp-client/src/browser/crossmodel-selection-data-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
import { GModelRoot, ISelectionListener } from '@eclipse-glsp/client'; | ||
import { GlspSelectionData, GlspSelectionDataService } from '@eclipse-glsp/theia-integration'; | ||
import { GModelElement, GModelRoot } from '@eclipse-glsp/client'; | ||
import { GlspSelectionData } from '@eclipse-glsp/theia-integration'; | ||
import { isDefined } from '@theia/core'; | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { CrossModelSelectionDataService } from './crossmodel-selection-forwarder'; | ||
|
||
@injectable() | ||
export class CrossModelGLSPSelectionDataService extends GlspSelectionDataService implements ISelectionListener { | ||
protected root?: Readonly<GModelRoot>; | ||
|
||
selectionChanged(root: Readonly<GModelRoot>, selectedElements: string[], deselectedElements?: string[] | undefined): void { | ||
this.root = root; | ||
export class CrossModelGLSPSelectionDataService extends CrossModelSelectionDataService { | ||
async getSelectionData(root: Readonly<GModelRoot>, selectedElementIds: string[]): Promise<GlspSelectionData> { | ||
return getSelectionDataFor(selectedElementIds.map(id => root.index.getById(id)).filter(isDefined)); | ||
} | ||
} | ||
|
||
async getSelectionData(selectedElementIds: string[]): Promise<GlspSelectionData> { | ||
const selectionDataMap = new Map<string, string>(); | ||
selectedElementIds | ||
.map(elementId => this.root?.index.getById(elementId)) | ||
.filter(isDefined) | ||
.forEach(element => selectionDataMap.set(element.id, element.type)); | ||
return { selectionDataMap }; | ||
} | ||
export function getSelectionDataFor(selection: GModelElement[]): GlspSelectionData { | ||
const selectionDataMap = new Map<string, string>(); | ||
selection.forEach(element => selectionDataMap.set(element.id, element.type)); | ||
return { selectionDataMap }; | ||
} |
60 changes: 60 additions & 0 deletions
60
packages/glsp-client/src/browser/crossmodel-selection-forwarder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 CrossBreeze. | ||
********************************************************************************/ | ||
|
||
import { GModelRoot } from '@eclipse-glsp/client'; | ||
import { GlspSelection, GlspSelectionData, TheiaGLSPSelectionForwarder, getDiagramWidget } from '@eclipse-glsp/theia-integration'; | ||
import { SelectionService } from '@theia/core'; | ||
import { ApplicationShell } from '@theia/core/lib/browser'; | ||
import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify'; | ||
|
||
@injectable() | ||
export abstract class CrossModelSelectionDataService { | ||
abstract getSelectionData(root: Readonly<GModelRoot>, selectedElementIds: string[]): Promise<GlspSelectionData>; | ||
} | ||
|
||
/** | ||
* Reacts to diagram selection changes and forwards the corresponding {@link GlspSelection} | ||
* to Theia`s {@link SelectionService} | ||
* | ||
* (bound in Diagram child DI container) | ||
*/ | ||
@injectable() | ||
export class CrossModelTheiaGLSPSelectionForwarder extends TheiaGLSPSelectionForwarder { | ||
@inject(CrossModelSelectionDataService) | ||
@optional() | ||
protected readonly dataService?: CrossModelSelectionDataService; | ||
|
||
@inject(ApplicationShell) | ||
protected shell: ApplicationShell; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.shell.onDidChangeActiveWidget(() => { | ||
const activeDiagramWidget = getDiagramWidget(this.shell); | ||
if (activeDiagramWidget) { | ||
// re-store selection from diagram to the global scope | ||
this.selectionChanged( | ||
activeDiagramWidget.editorContext.modelRoot, | ||
activeDiagramWidget.editorContext.selectedElements.map(element => element.id) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
override selectionChanged(root: Readonly<GModelRoot>, selectedElements: string[]): void { | ||
this.handleSelectionChanged(selectedElements, root); | ||
} | ||
|
||
override async handleSelectionChanged(selectedElementsIDs: string[], root?: Readonly<GModelRoot>): Promise<void> { | ||
const sourceUri = await this.getSourceUri(); | ||
const additionalSelectionData = (await this.dataService?.getSelectionData(root!, selectedElementsIDs)) ?? undefined; | ||
const glspSelection: GlspSelection = { | ||
selectedElementsIDs, | ||
additionalSelectionData, | ||
widgetId: this.viewerOptions.baseDiv, | ||
sourceUri: sourceUri | ||
}; | ||
this.theiaSelectionService.selection = glspSelection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters