Beispiel #1
0
        public static TemplateDialogViewModel CreateFrom(IKernel kernel, TemplateDialogViewModel template)
        {
            var vm = kernel.Get <TemplateDialogViewModel>();

            vm.CopyFrom(template);
            return(vm);
        }
Beispiel #2
0
        public void CopyFrom(TemplateDialogViewModel template)
        {
            IsInternal = template.IsInternal;

            Platforms   = new CheckListUserControlViewModel <Platform>(template.Platforms.Items.Select(p => new CheckedItemViewModel <Platform>(p.Value, p.IsChecked)), "All Platforms ");
            FormFactors = new CheckListUserControlViewModel <FormFactor>(template.FormFactors.Items.Select(ff => new CheckedItemViewModel <FormFactor>(ff.Value, ff.IsChecked)), "All Form Factors");

            Framework   = template.Framework;
            Name        = template.Name;
            Description = template.Description;

            // Deep copy fields.
            Fields = new ListCollectionView(new ObservableCollection <FieldDialogViewModel>((ObservableCollection <FieldDialogViewModel>)template.Fields.SourceCollection));

            View = T4UserControlViewModel.Create(Kernel, template.View.Buffer, null, null);
            View.PropertyChanged += T4OnPropertyChanged;

            ViewModelCSharp = T4UserControlViewModel.Create(Kernel, template.ViewModelCSharp.Buffer, null, null);
            ViewModelCSharp.PropertyChanged += T4OnPropertyChanged;
            CodeBehindCSharp = T4UserControlViewModel.Create(Kernel, template.CodeBehindCSharp.Buffer, null, null);
            CodeBehindCSharp.PropertyChanged += T4OnPropertyChanged;

            ViewModelVisualBasic = T4UserControlViewModel.Create(Kernel, template.ViewModelVisualBasic.Buffer, null, null);
            ViewModelVisualBasic.PropertyChanged += T4OnPropertyChanged;
            CodeBehindVisualBasic = T4UserControlViewModel.Create(Kernel, template.CodeBehindVisualBasic.Buffer, null, null);
            CodeBehindVisualBasic.PropertyChanged += T4OnPropertyChanged;
        }
Beispiel #3
0
        public void Add(IEnumerable <string> existingNames)
        {
            _isAdd = true;
            Title  = "New Template";

            _fieldsChanged = false;

            InitPredefinedFieldValues();
            ResetFieldValuesForAllBuffers();

            _unmodifiedValue = Kernel.Get <TemplateDialogViewModel>();
            _unmodifiedValue.CopyFrom(this);

            _existingNames = existingNames;
        }
Beispiel #4
0
        public void Edit(IEnumerable <string> existingNames)
        {
            _isAdd = false;
            Title  = $"Editing \"{Name}\"";

            _existingNames = existingNames.Where(t => !string.Equals(t, Name, StringComparison.OrdinalIgnoreCase)).ToList();

            _fieldsChanged = false;

            InitPredefinedFieldValues();
            ResetFieldValuesForAllBuffers();

            // Save unmodified properties.
            _unmodifiedValue = Kernel.Get <TemplateDialogViewModel>();
            _unmodifiedValue.CopyFrom(this);
        }
        public void ExecuteSelectCommand(TemplateDialogViewModel t)
        {
            PageNumber++;

            // Only do something if user changed the template.  The user
            // might have simply pressed 'Back' and is now going forward
            // without changing to another template.
            if (SelectedTemplate != t)
            {
                SelectedTemplate = t;

                // Template was selected.
                View.Init(SelectedTemplate.View.Buffer);
                CodeBehindCSharp.Init(SelectedTemplate.CodeBehindCSharp.Buffer);
                ViewModelCSharp.Init(SelectedTemplate.ViewModelCSharp.Buffer);
                CodeBehindVisualBasic.Init(SelectedTemplate.CodeBehindVisualBasic.Buffer);
                ViewModelVisualBasic.Init(SelectedTemplate.ViewModelVisualBasic.Buffer);

                FieldValues.Init((ObservableCollection <FieldDialogViewModel>)t.Fields.SourceCollection);
            }
        }
        public void ExecuteAddTemplateCommand()
        {
            try
            {
                var vm = TemplateDialogViewModel.CreateFrom(Kernel);
                vm.Add(_templatesSource.Select(t => t.Name));

                if (DialogService.ShowDialog(vm))
                {
                    _templatesSource.Add(vm);
                    Templates.MoveCurrentTo(vm);

                    _templateService.SaveTemplates(_localTemplateFolder, _templatesSource.Select(t => new Template(t)));
                    RefreshFrameworksFilter();
                }
            }
            catch
            {
                // ignored
            }
        }
        public void ExecuteEditTemplateCommand()
        {
            try
            {
                var vm = (TemplateDialogViewModel)Templates.CurrentItem;

                // Edit a copy so we don't have live updates in our list.
                var copyVm = TemplateDialogViewModel.CreateFrom(Kernel, vm);

                copyVm.Edit(_templatesSource.Select(t => t.Name));
                if (DialogService.ShowDialog(copyVm))
                {
                    // Success, copy fields back into our instance, save, and refresh frameworks (filter combobox).
                    vm.CopyFrom(copyVm);
                    _templateService.SaveTemplates(_localTemplateFolder, _templatesSource.Select(t => new Template(t)));
                    RefreshFrameworksFilter();
                }
            }
            catch
            {
                // ignored
            }
        }
 public bool CanSelectCommand(TemplateDialogViewModel t) => true;
        private void RefreshTemplates()
        {
            try
            {
                var templates = _templateService.LoadTemplates(_localTemplateFolder);

                bool restore  = Templates != null;
                int  savedPos = 0;
                if (restore)
                {
                    Templates.CurrentChanged -= TemplatesOnCurrentChanged;
                    Templates.Filter          = null;

                    // Save state of ListCollectionView to restore later.
                    savedPos = Templates.CurrentPosition;
                }

                _templatesSource = new ObservableCollection <TemplateDialogViewModel>(templates.Select(t => TemplateDialogViewModel.CreateFrom(Kernel, t)));
                Templates        = new ListCollectionView(_templatesSource)
                {
                    Filter = TemplateFilter
                };
                Templates.CurrentChanged += TemplatesOnCurrentChanged;

                if (restore)
                {
                    if (Templates.Count > savedPos)
                    {
                        Templates.MoveCurrentToPosition(savedPos);
                    }
                }
                else if (Templates.Count > 0)
                {
                    Templates.MoveCurrentToPosition(0);
                }

                RefreshFrameworksFilter();
            }
            catch (Exception)
            {
                throw;
            }
        }