aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml.cs
blob: 1e894f3f24f0db43009f95f8925711e3a7649713 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.MachineStudio.Common.Modules;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.UI.Modules;
using Tango.MachineStudio.UI.Notifications;
using Tango.MachineStudio.UI.SupervisingController;
using Tango.SharedUI;
using Tango.SharedUI.Controls;
using Tango.MachineStudio.Common;
using System.Threading;
using Tango.Core.Helpers;
using Tango.SharedUI.Helpers;
using Tango.Logging;
using static Tango.SharedUI.Controls.NavigationControl;
using Tango.Core.DI;

namespace Tango.MachineStudio.UI.Views
{
    /// <summary>
    /// Interaction logic for MainView.xaml
    /// </summary>
    public partial class MainView : View, IMainView
    {
        private DefaultStudioModuleLoader _loader;

        public MainView() : base()
        {
            InitializeComponent();

            _loader = TangoIOC.Default.GetInstance<IStudioModuleLoader>() as DefaultStudioModuleLoader;
            _loader.ModulesLoaded += Loader_ModulesLoaded;
        }

        private void Loader_ModulesLoaded(object sender, EventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                LogManager.Default.Log("Loading modules views...");

                var item = TangoIOC.Default.GetInstance<INotificationProvider>().PushTaskItem("Loading Modules...");

                var modules = _loader.UserModules.ToList();

                ThreadsHelper.InvokeUINow(() =>
                {
                    _loader.UserModules.Clear();
                });

                Thread.Sleep(1500);

                foreach (var module in modules)
                {
                    LogManager.Default.Log("Loading module view '" + module.Name + "'...");

                    ThreadsHelper.InvokeUI(() =>
                    {
                        if (!TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType))
                        {
                            FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement;
                            NavigationControl.SetNavigationName(view, module.Name);
                            TransitionControl.Elements.Add(view);
                        }

                        _loader.UserModules.Add(module);
                    });

                    UIHelper.DoEvents();

                    Thread.Sleep(100);
                }

                item.Pop();
            });
        }
    }
}
class="p">) { this.context = context; this.targetSnippetElement = targetSnippetElement; this.boundElement = boundElement; this.segment = segment; } public void OnInsertionCompleted() { targetElement = context.GetActiveElement(targetSnippetElement) as IReplaceableActiveElement; if (targetElement != null) { targetElement.TextChanged += targetElement_TextChanged; } } void targetElement_TextChanged(object sender, EventArgs e) { // Don't copy text if the segments overlap (we would get an endless loop). // This can happen if the user deletes the text between the replaceable element and the bound element. if (segment.GetOverlap(targetElement.Segment) == SimpleSegment.Invalid) { int offset = segment.Offset; int length = segment.Length; string text = boundElement.ConvertText(targetElement.Text); if (length != text.Length || text != context.Document.GetText(offset, length)) { // Call replace only if we're actually changing something. // Without this check, we would generate an empty undo group when the user pressed undo. context.Document.Replace(offset, length, text); if (length == 0) { // replacing an empty anchor segment with text won't enlarge it, so we have to recreate it segment = new AnchorSegment(context.Document, offset, text.Length); } } } } public void Deactivate(SnippetEventArgs e) { } public bool IsEditable { get { return false; } } public ISegment Segment { get { return segment; } } } }