-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support rendering of ghost element when creating elements (#301)
* Support rendering of ghost element when creating elements - Introduce new element template module -- Adding new elements to the diagram based on templates -- Removing templates again - Support local bounds calculation for client-only added elements -- Must trigger RequestBounds for hidden view calculation -- Must not modify main view until ComputedBounds response is handled -- Mark ResizeHandles as not to be considered for bounds calculation -- Fix positioning of decorations for hidden view calculation - Add ghost element extension to tool palette -- Optional ghost element field in the trigger node creation action -- Ghost element is added as feedback to the mouse cursor -- If ghost element is dynamic, templates (palette items) are reloaded - Bonus: Re-calculate local bounds for resize behavior Fixes eclipse-glsp/glsp#1159
- Loading branch information
1 parent
0c22eb6
commit 545a20c
Showing
29 changed files
with
730 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
.ghost-element { | ||
/* we are a true ghost so we do not want to be used as a target for any mouse event */ | ||
pointer-events: none; | ||
opacity: 0.8; | ||
} | ||
|
||
.ghost-element.hidden { | ||
display: none; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { | ||
Action, | ||
ActionDispatcher, | ||
Command, | ||
CommandExecutionContext, | ||
CommandResult, | ||
CommandReturn, | ||
ComputedBoundsAction, | ||
ComputedBoundsApplicator, | ||
GModelRoot, | ||
GModelRootSchema, | ||
RequestBoundsAction, | ||
TYPES | ||
} from '@eclipse-glsp/sprotty'; | ||
import { inject, injectable } from 'inversify'; | ||
import { ServerAction } from '../../base/model/glsp-model-source'; | ||
|
||
export namespace LocalRequestBoundsAction { | ||
export function is(object: unknown): object is RequestBoundsAction { | ||
return RequestBoundsAction.is(object) && !ServerAction.is(object); | ||
} | ||
|
||
export function fromCommand(context: CommandExecutionContext, actionDispatcher: ActionDispatcher, cause?: Action): CommandResult { | ||
// do not modify the main model (modelChanged = false) but request local bounds calculation on hidden model | ||
actionDispatcher.dispatch(RequestBoundsAction.create(context.root as unknown as GModelRootSchema)); | ||
return { | ||
model: context.root, | ||
modelChanged: false, | ||
cause | ||
}; | ||
} | ||
} | ||
|
||
export namespace LocalComputedBoundsAction { | ||
export function is(object: unknown): object is RequestBoundsAction { | ||
return ComputedBoundsAction.is(object) && ServerAction.is(object); | ||
} | ||
|
||
export function mark(action: ComputedBoundsAction): ComputedBoundsAction { | ||
// mimic: we mark the computed bounds action as coming from the server so it is not sent to the server and handled locally | ||
ServerAction.mark(action); | ||
return action; | ||
} | ||
} | ||
|
||
@injectable() | ||
export class LocalComputedBoundsCommand extends Command { | ||
static readonly KIND: string = ComputedBoundsAction.KIND; | ||
|
||
@inject(ComputedBoundsApplicator) protected readonly computedBoundsApplicator: ComputedBoundsApplicator; | ||
|
||
constructor(@inject(TYPES.Action) readonly action: ComputedBoundsAction) { | ||
super(); | ||
} | ||
|
||
override execute(context: CommandExecutionContext): GModelRoot | CommandResult { | ||
if (LocalComputedBoundsAction.is(this.action)) { | ||
// apply computed bounds from the hidden model and return updated model to render new main model | ||
this.computedBoundsApplicator.apply(context.root as unknown as GModelRootSchema, this.action); | ||
return context.root; | ||
} | ||
// computed bounds action from server -> we do not care and do not trigger any update of the main model | ||
return { | ||
model: context.root, | ||
modelChanged: false | ||
}; | ||
} | ||
|
||
override undo(context: CommandExecutionContext): CommandReturn { | ||
return context.root; | ||
} | ||
|
||
override redo(context: CommandExecutionContext): CommandReturn { | ||
return context.root; | ||
} | ||
} |
Oops, something went wrong.