コード例 #1
0
        public void Delete(EarTrumpetActionViewModel earTrumpetActionViewModel, bool promptOverride = false)
        {
            Action doRemove = () =>
            {
                var actions = EarTrumpetActionsAddon.Current.Actions.ToList();
                if (actions.Any(a => a.Id == earTrumpetActionViewModel.Id))
                {
                    actions.Remove(item => item.Id == earTrumpetActionViewModel.Id);
                }
                EarTrumpetActionsAddon.Current.Actions = actions.ToArray();

                if (Pages.Any(a => a == earTrumpetActionViewModel))
                {
                    Pages.Remove(earTrumpetActionViewModel);
                }
            };

            if (earTrumpetActionViewModel.IsPersisted && !promptOverride)
            {
                _parent.ShowDialog(Properties.Resources.DeleteActionDialogTitle, Properties.Resources.DeleteActionDialogText,
                                   Properties.Resources.DeleteActionDialogYesText, Properties.Resources.DeleteActionDialogNoText, doRemove, () => { });
            }
            else
            {
                doRemove();
            }
        }
コード例 #2
0
        public void Save(EarTrumpetActionViewModel earTrumpetActionViewModel)
        {
            var actions = EarTrumpetActionsAddon.Current.Actions.ToList();

            if (actions.Any(a => a.Id == earTrumpetActionViewModel.Id))
            {
                actions.Remove(item => item.Id == earTrumpetActionViewModel.Id);
            }
            actions.Insert(0, earTrumpetActionViewModel.GetAction());
            EarTrumpetActionsAddon.Current.Actions = actions.ToArray();
            earTrumpetActionViewModel.IsWorkSaved  = true;

            if (Pages.Any(a => a == earTrumpetActionViewModel))
            {
                Pages.Remove(earTrumpetActionViewModel);
            }
            Pages.Insert(0, earTrumpetActionViewModel);
            Selected = Pages[0];
        }
コード例 #3
0
        public ActionsCategoryViewModel()
            : base(Properties.Resources.MyActionsText, "\xE950", Properties.Resources.AddonDescriptionText, EarTrumpetActionsAddon.Current.Manifest.Id, new ObservableCollection <SettingsPageViewModel>())
        {
            // Get a 'fresh' copy so that we can edit the objects and still go back later.
            var actions = EarTrumpetActionsAddon.Current.Actions;

            EarTrumpetActionsAddon.Current.Actions = EarTrumpetActionsAddon.Current.Actions;

            Pages.AddRange(actions.Select(a => new EarTrumpetActionViewModel(this, a)));
            Pages.Add(new ImportExportPageViewModel(this));

            Toolbar = new ToolbarItemViewModel[] { new ToolbarItemViewModel {
                                                       Command = new RelayCommand(() =>
                    {
                        var vm = new EarTrumpetActionViewModel(this, new EarTrumpetAction {
                            DisplayName = Properties.Resources.NewActionText
                        });
                        vm.IsWorkSaved = false;
                        vm.IsPersisted = false;

                        vm.PropertyChanged += (_, e) =>
                        {
                            if (e.PropertyName == nameof(vm.IsSelected) &&
                                vm.IsSelected && !Pages.Contains(vm))
                            {
                                Pages.Insert(0, vm);
                            }
                        };

                        Selected = vm;
                    }),
                                                       DisplayName   = Properties.Resources.NewActionText,
                                                       Glyph         = "\xE948",
                                                       GlyphFontSize = 15,
                                                   } };

            if (Pages.Count == 2)
            {
                Toolbar[0].Command.Execute(null);
            }
        }