/// <summary> /// /// </summary> /// <param name="profile"></param> public ProfileOptionsViewModel(ProfileHolder profile) { _groupsViewModel = new GroupsViewModel(profile.Groups, profile.Name, RootModel.AllActionDescriptions); Profile = profile; EditOptionsCommand = new DelegateCommand(EditProfile, true); ImportProfileCommand = new DelegateCommand(ImportProfile, true); }
/// <summary> /// This constructor is supposed for creating global profile. /// Global profile cannot be imported for now /// </summary> /// <param name="name">Name of the profile (e.g. "Global")</param> /// <param name="groups">List of profile groups</param> public ProfileOptionsViewModel(string name, List <Group> groups) { _groupsViewModel = new GroupsViewModel(groups, name, RootModel.AllActionDescriptions); Profile = null; EditOptionsCommand = new DelegateCommand(EditProfile, true); ImportProfileCommand = new DelegateCommand(ImportProfile, true); }
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"); } }