Skip to content

Commit

Permalink
Ensure keyboard and mouse activation is consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Mar 31, 2023
1 parent 6d2c507 commit 14f1816
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions Bonsai.Editor/GraphView/WorkflowGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,26 @@ private bool HasDefaultEditor(ExpressionBuilder builder)
return false;
}

private void LaunchDefaultEditor(GraphNode node)
private static bool IsAnnotation(GraphNode node)
{
var builder = WorkflowEditor.GetGraphNodeBuilder(node);
if (builder is AnnotationBuilder annotationBuilder)
return node != null && node.IsAnnotation;
}

private void LaunchDefaultAction(GraphNode node)
{
if (!editorState.WorkflowRunning && !IsAnnotation(node) || ModifierKeys == Keys.Control)
{
if (EditorControl.WebViewInitialized)
{
var html = MarkdownConvert.ToHtml(Font, annotationBuilder.Text);
EditorControl.WebView.NavigateToString(html);
EditorControl.WebView.Tag = builder;
EditorControl.ExpandWebView();
}
LaunchDefaultEditor(node);
}
else
{
LaunchVisualizer(node);
}
}

private void LaunchDefaultEditor(GraphNode node)
{
var builder = WorkflowEditor.GetGraphNodeBuilder(node);
var disableBuilder = builder as DisableBuilder;
var workflowBuilder = (disableBuilder != null ? disableBuilder.Builder : builder) as IWorkflowExpressionBuilder;
if (workflowBuilder != null && workflowBuilder.Workflow != null)
Expand Down Expand Up @@ -473,6 +479,17 @@ private void LaunchDefaultEditor(GraphNode node)

private void LaunchVisualizer(GraphNode node)
{
if (IsAnnotation(node) &&
EditorControl.WebViewInitialized &&
WorkflowEditor.GetGraphNodeBuilder(node) is AnnotationBuilder annotationBuilder)
{
var html = MarkdownConvert.ToHtml(Font, annotationBuilder.Text);
EditorControl.WebView.NavigateToString(html);
EditorControl.WebView.Tag = annotationBuilder;
EditorControl.ExpandWebView();
return;
}

var visualizerLauncher = GetVisualizerDialogLauncher(node);
if (visualizerLauncher != null)
{
Expand Down Expand Up @@ -1078,16 +1095,9 @@ private void graphView_KeyDown(object sender, KeyEventArgs e)
LaunchDefinition(graphView.SelectedNode);
}

if (e.KeyCode == Keys.Return && editorState.WorkflowRunning)
if (e.KeyCode == Keys.Return && !CanEdit)
{
if (e.Modifiers == Keys.Control)
{
LaunchDefaultEditor(graphView.SelectedNode);
}
else
{
LaunchVisualizer(graphView.SelectedNode);
}
LaunchDefaultAction(graphView.SelectedNode);
}

if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control)
Expand Down Expand Up @@ -1147,7 +1157,7 @@ private void graphView_KeyDown(object sender, KeyEventArgs e)
else Editor.ConnectGraphNodes(graphView.SelectedNodes, graphView.CursorNode);
}
}
else LaunchDefaultEditor(graphView.SelectedNode);
else LaunchDefaultAction(graphView.SelectedNode);
}

if (e.KeyCode == Keys.Delete)
Expand Down Expand Up @@ -1199,14 +1209,7 @@ private void graphView_SelectedNodeChanged(object sender, EventArgs e)

private void graphView_NodeMouseDoubleClick(object sender, GraphNodeMouseEventArgs e)
{
if (!editorState.WorkflowRunning || Control.ModifierKeys == Keys.Control)
{
LaunchDefaultEditor(e.Node);
}
else
{
LaunchVisualizer(e.Node);
}
LaunchDefaultAction(e.Node);
}

private void graphView_MouseDown(object sender, MouseEventArgs e)
Expand Down

0 comments on commit 14f1816

Please sign in to comment.