Beispiel #1
0
        public void ExecuteAddViewSuffixCommand()
        {
            try
            {
                var vm = Container.Resolve <StringDialogViewModel>();
                vm.Add(true, "Add View Suffix", "View Suffix:", ViewSuffixes?.Select(s => s.Value),
                       SuffixRegex, SuffixRegexErrorMessage);

                if (DialogService.ShowDialog(vm))
                {
                    var newItem = StringViewModel.CreateFromString(Container, vm.Value);
                    ViewSuffixesView.AddNewItem(newItem);
                    // ReSharper disable once PossibleNullReferenceException
                    ViewSuffixesView.MoveCurrentTo(newItem);
                }
            }
            catch
            {
                // ignored
            }
        }
        public void ExecuteAddChoiceCommand()
        {
            var vm = Container.Resolve <StringDialogViewModel>();

            vm.Add(true, "Add Choice", "Choice:");

            if (DialogService.ShowDialog(vm))
            {
                var newItem = StringViewModel.CreateFromString(Container, vm.Value);
                if (Choices == null)
                {
                    _choicesSource = new ObservableCollection <StringViewModel>();
                    Choices        = new ListCollectionView(_choicesSource);
                }
                _choicesSource.Add(newItem);
                // ReSharper disable once PossibleNullReferenceException
                Choices.MoveCurrentTo(newItem);

                _choicesChanged = true;
                OkCommand.RaiseCanExecuteChanged();
            }
        }
        public void CopyFrom(Field field)
        {
            _name = field.Name;
            if (field.FieldType == FieldType.CheckBox)
            {
                // Try method won't throw exception on failure.
                bool.TryParse(field.Default, out _defaultBoolean);
            }
            else
            {
                _defaultString = field.Default;
            }
            _prompt      = field.Prompt;
            _description = field.Description;

            if (field.Choices == null)
            {
                ChoicesSource = new ObservableCollection <StringViewModel>();
            }
            else
            {
                ChoicesSource = new ObservableCollection <StringViewModel>(field.Choices.Select(s => StringViewModel.CreateFromString(Container, s)));
            }
            _choices = new ListCollectionView(_choicesSource);

            _selectedFieldType = field.FieldType;
        }
Beispiel #4
0
 public void ExecuteRestoreDefaultViewSuffixesCommand()
 {
     try
     {
         ViewSuffixes = new ObservableCollection <StringViewModel>(SettingsService.DefaultViewSuffixes.Select(s => StringViewModel.CreateFromString(Container, s)));
     }
     catch
     {
         // ignored
     }
 }
Beispiel #5
0
        public async Task RevertSettings()
        {
            // If we haven't fully loaded and the user cancels the dialog,
            // _unmodifiedSettings will be null so abort.
            if (_unmodifiedSettings == null)
            {
                return;
            }

            // Reverts properties to the values saved in _unmodifiedSettings.  This
            // is used to cancel changes or to set the properties' initial values.

            // Unsubscribe from solution events on the old solution.
            var oldSolutionVm = ProjectsOptions?.FirstOrDefault();

            if (oldSolutionVm != null)
            {
                oldSolutionVm.PropertyChanging -= SolutionProjectOptionsVmOnPropertyChanging;
                oldSolutionVm.LocationDescriptorForViewModel.PropertyChanging -= LocationDescriptorOnPropertyChanging;
                oldSolutionVm.LocationDescriptorForView.PropertyChanging      -= LocationDescriptorOnPropertyChanging;

                oldSolutionVm.PropertyChanged -= SolutionProjectOptionsVmOnPropertyChanged;
                oldSolutionVm.LocationDescriptorForViewModel.PropertyChanged -= LocationDescriptorForViewModelOnPropertyChanged;
                oldSolutionVm.LocationDescriptorForView.PropertyChanged      -= LocationDescriptorForViewOnPropertyChanged;
            }

            SelectedGoToViewOrViewModelOption = _unmodifiedSettings.GoToViewOrViewModelOption;
            GoToViewOrViewModelSearchSolution = _unmodifiedSettings.GoToViewOrViewModelSearchSolution;
            ViewSuffixes        = new ObservableCollection <StringViewModel>(_unmodifiedSettings.ViewSuffixes.Select(s => StringViewModel.CreateFromString(Container, s)));
            LocalTemplateFolder = _unmodifiedSettings.LocalTemplateFolder;

            // Add solution and other projects.
            var tmp = new List <ProjectOptionsUserControlViewModel>();

            if (_unmodifiedSettings.SolutionOptions != null)
            {
                // Create global vm defaults using the global defaults.
                var solutiondefaultProjectOptionsVm = await CreateProjectOptionsUserControlViewModel(SettingsService.SolutionDefaultProjectOptions, null, false);

                // Use the global defaults in the solution vm.
                var solutionProjectOptionsVm = await CreateProjectOptionsUserControlViewModel(_unmodifiedSettings.SolutionOptions, solutiondefaultProjectOptionsVm, false);

                tmp.Add(solutionProjectOptionsVm);

                // Subscribe to solution PropertyChanging and PropertyChanged events so we can
                // pass them down to the projects.
                solutionProjectOptionsVm.PropertyChanging += SolutionProjectOptionsVmOnPropertyChanging;
                solutionProjectOptionsVm.LocationDescriptorForViewModel.PropertyChanging += LocationDescriptorOnPropertyChanging;
                solutionProjectOptionsVm.LocationDescriptorForView.PropertyChanging      += LocationDescriptorOnPropertyChanging;

                solutionProjectOptionsVm.PropertyChanged += SolutionProjectOptionsVmOnPropertyChanged;
                solutionProjectOptionsVm.LocationDescriptorForViewModel.PropertyChanged += LocationDescriptorForViewModelOnPropertyChanged;
                solutionProjectOptionsVm.LocationDescriptorForView.PropertyChanged      += LocationDescriptorForViewOnPropertyChanged;

                // Use the solution vm as the inherited for all the projects.
                foreach (var po in _unmodifiedSettings.ProjectOptions)
                {
                    tmp.Add(await CreateProjectOptionsUserControlViewModel(po, solutionProjectOptionsVm, true));
                }
            }
            ProjectsOptions = tmp;

            ResetAllToInheritedCommand.RaiseCanExecuteChanged();
        }