Esempio n. 1
0
        public OutputWindow(MainWindow mainWindow, string name, IList <RootModel> allRootModels)
        {
            _mainWindow = mainWindow;
            Name        = name;


            var conveyor = ConveyorFactory.CreateNew(name, allRootModels);

            RootModel = conveyor.RootModel;
            conveyor.MessageReceived += HandleMessage;

            _window        = new MainOutputWindow(mainWindow, _rootModel);
            VisibleControl = _window;
        }
        private void ImportProfile(object obj)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.DefaultExt  = ".set";
            fileDialog.Filter      = "Config|*.set|All Files|*.*";
            fileDialog.Multiselect = false;

            var result = fileDialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                if (!File.Exists(fileDialog.FileName))
                {
                    return;
                }

                RootModel rootModel = new RootModel(Profile);
                var       conveyor  = ConveyorFactory.CreateNew(rootModel);
                try
                {
                    using (var stream = new StreamReader(fileDialog.FileName, Encoding.Default, false, 1024))
                    {
                        string line;
                        while ((line = stream.ReadLine()) != null)
                        {
                            //XML не читает символ \x01B
                            //TODO: Need FIX IT
                            if (!line.Contains("\x001B"))
                            {
                                //rootModel.PushCommandToConveyor(new TextCommand(line)).ImportJMC(line, rootModel);
                                conveyor.ImportJMC(line, rootModel);
                            }
                        }
                    }
                }
                catch
                {
                }

                _groupsViewModel = new GroupsViewModel(Profile.Groups, Profile.Name, RootModel.AllActionDescriptions);
                var profile = SettingsHolder.Instance.GetProfile(Profile.Name);
                foreach (var newVar in Profile.Variables)
                {
                    var v = profile.Variables.FirstOrDefault(var => var.Name == newVar.Name);

                    if (v != null)
                    {
                        v.Value = newVar.Value;
                    }
                    else
                    {
                        profile.Variables.Add(new Variable()
                        {
                            Name = newVar.Name, Value = newVar.Value
                        });
                    }
                }

                OnPropertyChanged("AliasesCount");
                OnPropertyChanged("GroupsCount");
                OnPropertyChanged("HighlightsCount");
                OnPropertyChanged("HotkeysCount");
                OnPropertyChanged("SubstitutionsCount");
                OnPropertyChanged("TriggersCount");
            }
        }