aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/ProcedureDesignerView.xaml.cs
blob: a8c37cc1033361c6cbd9c12b953ff42bc436e186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.FSE.Procedures.Contracts;
using Tango.FSE.Procedures.ViewModels;
using Tango.Scripting.Basic;
using Tango.Scripting.Editors;

namespace Tango.FSE.Procedures.Views
{
    /// <summary>
    /// Interaction logic for ProcedureDesignerView.xaml
    /// </summary>
    public partial class ProcedureDesignerView : UserControl, IProcedureDesignerView
    {
        private ProcedureDesignerViewVM _vm;

        public ProcedureDesignerView()
        {
            InitializeComponent();
            this.Register<IProcedureDesignerView>();
            Loaded += (_, __) => _vm = DataContext as ProcedureDesignerViewVM;
        }

        private void OnScriptItemDoubleClick(object sender, MouseButtonEventArgs e)
        {
            _vm.OpenScript((sender as FrameworkElement).DataContext as Script);
        }

        private ScriptEditor GetCurrentEditor()
        {
            var editor = tabControl.FindVisualChildren<ScriptEditor>().FirstOrDefault(x => x.IsVisible);
            return editor;
        }

        public void FormatCode()
        {
            GetCurrentEditor()?.FormatCode();
        }

        public void HighlightCode(int position, int length, int line)
        {
            GetCurrentEditor()?.Highlight(position, length, line);
        }

        public void InsertCode(string code)
        {
            GetCurrentEditor()?.InsertCode(code);
        }

        public void InvalidateHighlighting()
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                foreach (var editor in tabControl.FindVisualChildren<ScriptEditor>())
                {
                    editor.InvalidateHighlighting();
                }
            }));
        }
    }
}