From ab99fb80dfc78c31b1e6cf8d5e4a8458978f4ddc Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 7 Dec 2017 17:42:02 +0200 Subject: Added Tango.Scripting Stubs.UI scripting works.. Implemented ScriptEditorControl. --- .../Controls/ScriptEditorControl.xaml.cs | 116 ++++++++++++++------- 1 file changed, 79 insertions(+), 37 deletions(-) (limited to 'Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs') diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs index 1f9eeb1aa..d3adf4d78 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/ScriptEditorControl.xaml.cs @@ -3,6 +3,7 @@ using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Editing; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Reflection; using System.Text; @@ -19,6 +20,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; +using Tango.Core.Commands; using Tango.SharedUI; namespace Tango.SharedUI.Controls @@ -76,8 +78,11 @@ namespace Tango.SharedUI.Controls public partial class ScriptEditorControl : UserControl { private CompletionWindow completionWindow; + private bool textChanged; public ScriptEditorControl() { + HighlightTypes = new ObservableCollection(); + InitializeComponent(); textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(); @@ -109,10 +114,16 @@ namespace Tango.SharedUI.Controls types.Add(new KeyValuePair("TimeSpan", typeof(TimeSpan))); types.Add(new KeyValuePair("Dispatcher", typeof(Dispatcher))); types.Add(new KeyValuePair("Task", typeof(Task))); - types.Add(new KeyValuePair("list", typeof(IList))); + types.Add(new KeyValuePair("List", typeof(IList))); types.Add(new KeyValuePair("int", typeof(Int32))); types.Add(new KeyValuePair("double", typeof(Double))); types.Add(new KeyValuePair("String", typeof(String))); + types.Add(new KeyValuePair("string", typeof(String))); + + foreach (var t in HighlightTypes) + { + types.Add(new KeyValuePair(t.Name, t)); + } var type = types.SingleOrDefault(x => x.Key == keyword); if (type.Key != null) @@ -146,42 +157,6 @@ namespace Tango.SharedUI.Controls } } - private async void btnStart_Click(object sender, RoutedEventArgs e) - { - btnStart.IsEnabled = false; - btnStop.IsEnabled = true; - gridExecuting.Visibility = Visibility.Visible; - //engine = new ScriptEngine(); - //try - //{ - // await engine.Run(CanvasItem, textEditor.Text); - //} - //catch (Exception ex) - //{ - // txtError.Text = ex.Message; - // gridError.Visibility = Visibility.Visible; - //} - - gridExecuting.Visibility = Visibility.Hidden; - btnStart.IsEnabled = true; - btnStop.IsEnabled = false; - } - - private void btnStop_Click(object sender, RoutedEventArgs e) - { - //engine.Stop(); - } - - private void btnOK_Click(object sender, RoutedEventArgs e) - { - gridError.Visibility = Visibility.Hidden; - } - - private void Save(object sender, RoutedEventArgs e) - { - //CanvasItem.Script = textEditor.Text; - } - private void FillType(Type type, IList data) { List items = new List(); @@ -224,6 +199,73 @@ namespace Tango.SharedUI.Controls } } + #region Properties + + + + public String Text + { + get { return (String)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + public static readonly DependencyProperty TextProperty = + DependencyProperty.Register("Text", typeof(String), typeof(ScriptEditorControl), new PropertyMetadata(null, (d, e) => (d as ScriptEditorControl).OnTextChanged())); + + private void OnTextChanged() + { + if (!textChanged) + { + textEditor.Text = Text; + textChanged = true; + } + } + + + + public ObservableCollection HighlightTypes + { + get { return (ObservableCollection)GetValue(HighlightTypesProperty); } + set { SetValue(HighlightTypesProperty, value); } + } + public static readonly DependencyProperty HighlightTypesProperty = + DependencyProperty.Register("HighlightTypes", typeof(ObservableCollection), typeof(ScriptEditorControl), new PropertyMetadata(null)); + + + + #endregion + + #region Commands + + public RelayCommand RunCommand + { + get { return (RelayCommand)GetValue(RunCommandProperty); } + set { SetValue(RunCommandProperty, value); } + } + public static readonly DependencyProperty RunCommandProperty = + DependencyProperty.Register("RunCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null)); + + public RelayCommand StopCommand + { + get { return (RelayCommand)GetValue(StopCommandProperty); } + set { SetValue(StopCommandProperty, value); } + } + public static readonly DependencyProperty StopCommandProperty = + DependencyProperty.Register("StopCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null)); + + public RelayCommand SaveCommand + { + get { return (RelayCommand)GetValue(SaveCommandProperty); } + set { SetValue(SaveCommandProperty, value); } + } + public static readonly DependencyProperty SaveCommandProperty = + DependencyProperty.Register("SaveCommand", typeof(RelayCommand), typeof(ScriptEditorControl), new PropertyMetadata(null)); + + #endregion + + private void textEditor_TextChanged(object sender, EventArgs e) + { + Text = textEditor.Text; + } } internal static class DocumentUtils -- cgit v1.3.1