import { injectable , inject } from 'inversify' ; import { CommandContribution , CommandRegistry , MenuContribution , MenuModelRegistry } from '@theia/core/lib/common' ; import { KeybindingContribution , KeybindingRegistry , ApplicationShell , KeybindingContext , Keybinding } from '@theia/core/lib/browser' ; import { DiagramMenus , DiagramWidget } from 'sprotty-theia' ; import { DepGraphModelSource } from '../graph/model-source' ; import { DepGraphWidget } from './diagram-widget' ; import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution' ; import { ColorRegistry , Color } from '@theia/core/lib/browser/color-registry' ; export const RESOLVE_GRAPH = 'diagram.resolveGraph' ; @ injectable ( ) export class DepgraphKeybindingContext implements KeybindingContext { @ inject ( ApplicationShell ) protected readonly shell ! : ApplicationShell ; id = 'depgraph-navigator.keybinding.context' ; isEnabled ( arg ? ) { const widget = this . shell . currentWidget ; return widget instanceof DepGraphWidget && widget . diagramType === 'dependency-graph' ; } } @ injectable ( ) export class DiagramFrontendContribution implements CommandContribution , KeybindingContribution , MenuContribution , ColorContribution { @ inject ( ApplicationShell ) protected readonly shell ! : ApplicationShell ; @ inject ( DepgraphKeybindingContext ) protected readonly keybindingContext ! : DepgraphKeybindingContext ; registerCommands ( registry ) { const checkCurrentWidget = ( ) => { const widget = this . shell . currentWidget ; return widget instanceof DepGraphWidget && widget . diagramType === 'dependency-graph' ; } ; registry . registerCommand ( { id : RESOLVE_GRAPH , label : 'Resolve All Dependencies' } , { execute : ( ) => { const widget = this . shell . currentWidget as DiagramWidget ; const modelSource = widget . modelSource as DepGraphModelSource ; modelSource . resolveGraph ( ) ; } , isEnabled : checkCurrentWidget , isVisible : checkCurrentWidget } ) ; } registerKeybindings ( registry ) { registry . registerKeybinding ( { command : RESOLVE_GRAPH , context : this . keybindingContext . id , keybinding : 'ctrlcmd+shift+a' } ) ; } registerMenus ( registry ) { registry . registerMenuAction ( DiagramMenus . DIAGRAM , { commandId : RESOLVE_GRAPH } ) ; } registerColors ( colors ) { colors . register ( { id : 'sprotty.nodeBackground' , defaults : { dark : '#99aa99' , light : '#22cc22' , hc : '#ccffcc' } , description : 'The background color of a diagramm node.' } , { id : 'sprotty.nodeBackgroundHover' , defaults : { dark : '#aabbaa' , light : '#33dd33' , hc : '#eeffee' } , description : 'The background color of a diagramm node.' } , { id : 'sprotty.nodeForeground' , defaults : { dark : Color . white , light : Color . black , hc : Color . black } , description : 'The foreground color of a diagramm node.' } , { id : 'sprotty.nodeBorder' , defaults : { dark : '#339933' , light : '#00aa00' , hc : '#66dd66' } , description : 'The border color of a diagramm node.' } ) ; } }