Exemplo n.º 1
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(Container, template.View.Buffer, null, null);
            View.PropertyChanged += T4OnPropertyChanged;

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

            ViewModelVisualBasic = T4UserControlViewModel.Create(Container, template.ViewModelVisualBasic.Buffer, null, null);
            ViewModelVisualBasic.PropertyChanged += T4OnPropertyChanged;
            CodeBehindVisualBasic = T4UserControlViewModel.Create(Container, template.CodeBehindVisualBasic.Buffer, null, null);
            CodeBehindVisualBasic.PropertyChanged += T4OnPropertyChanged;
        }
Exemplo n.º 2
0
        public static TemplateDialogViewModel CreateFrom(IUnityContainer container, TemplateDialogViewModel template)
        {
            var vm = container.Resolve <TemplateDialogViewModel>();

            vm.CopyFrom(template);
            return(vm);
        }
Exemplo n.º 3
0
        public void Add(IEnumerable <string> existingNames)
        {
            _isAdd = true;
            Title  = "New Template";

            _fieldsChanged = false;

            InitPredefinedFieldValues();
            ResetFieldValuesForAllBuffers();

            _unmodifiedValue = Container.Resolve <TemplateDialogViewModel>();
            _unmodifiedValue.CopyFrom(this);

            _existingNames = existingNames;
        }
Exemplo n.º 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 = Container.Resolve <TemplateDialogViewModel>();
            _unmodifiedValue.CopyFrom(this);
        }
Exemplo n.º 5
0
        public void ExecuteAddTemplateCommand()
        {
            try
            {
                var vm = TemplateDialogViewModel.CreateFrom(Container);
                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 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);
            }
        }
Exemplo n.º 7
0
        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(Container, 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
            }
        }
Exemplo n.º 8
0
        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(Container, 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;
            }
        }
 public bool CanSelectCommand(TemplateDialogViewModel t) => true;