public virtual void Initialize() { this.services = new Mock<IServiceProvider>(); this.configurator = new VsTemplateConfigurator(this.services.Object); this.templateItem = new Item { Parent = new Item { Items = { new Item { Name = "Foo.txt", } }, }, }; }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { Guard.NotNull(() => context, context); Guard.NotNull(() => provider, provider); Guard.NotNull(() => value, value); var uriService = provider.GetService<IUriReferenceService>(); var templateUri = (value is string) ? (string)value : (string)null; tracer.ShieldUI(() => { var componentModel = provider.GetService<SComponentModel, IComponentModel>(); var picker = componentModel.GetService<Func<ISolutionPicker>>()(); picker.Owner = Application.Current.MainWindow; picker.RootItem = provider.GetService<ISolution>(); picker.Title = Properties.Resources.VsTemplateUriEditor_PickerTitle; picker.EmptyItemsMessage = string.Format(CultureInfo.CurrentCulture, Resources.VsTemplateUriEditor_EmptyItemsMessage, FileExtension); picker.Filter.Kind = ItemKind.Solution | ItemKind.SolutionFolder | ItemKind.Project | ItemKind.Folder | ItemKind.Item; picker.Filter.MatchFileExtensions = FileExtension; SetSelectedItem(context, picker, uriService, GetAuthoringTemplateProperty(context)); if (picker.ShowDialog()) { // Create and return the Uri for the template var owner = GetPropertyOwner(context); var configurator = new VsTemplateConfigurator(provider); IItem selectedItem; if (!ExtensionMatches(picker.SelectedItem) || picker.SelectedItem.Parent.Kind == ItemKind.Item) { selectedItem = GetTemplateItemFromTT(picker.SelectedItem); //message telling the user to do his magic on his own var messageService = provider.GetService<IUserMessageService>(); if (messageService != null) { messageService.ShowWarning(Resources.VsTemplateUriEditor_ReferToGuidance); } } else { selectedItem = picker.SelectedItem.As<IItem>(); } // Update the vstemplate var template = configurator.Configure(selectedItem, owner.DisplayName, owner.Description, owner.GetSchemaPathValue()); template.RemoveWizardExtension(TemplateWizardInfo.InstantiationTemplateWizardFullTypeName); template.RemoveWizardExtension(TemplateWizardInfo.ElementReplacementsTemplateWizardFullTypeName); if (context.Instance is ITemplateSettings) { // The editor is being used from the template launchpoint, so we add // the template wizard template.AddWizardExtension(TemplateWizardInfo.InstantiationTemplateWizardFullTypeName); template.SetHidden(!((ITemplateSettings)context.Instance).CreateElementOnUnfold); } else { // The editor is being used from a command, don't show it in Add/Remove Programs template.SetHidden(true); } template.AddWizardExtension(TemplateWizardInfo.ElementReplacementsTemplateWizardFullTypeName); // Set also the authoring URI value. SetAuthoringUri(context, uriService.CreateUri(selectedItem)); templateUri = uriService.CreateUri<IVsTemplate>(template).AbsoluteUri; } }, Resources.VsTemplateUriEditor_FailedToEdit); return templateUri; }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { Guard.NotNull(() => context, context); Guard.NotNull(() => provider, provider); Guard.NotNull(() => value, value); var uriService = provider.GetService <IUriReferenceService>(); var templateUri = (value is string) ? (string)value : (string)null; tracer.ShieldUI(() => { var componentModel = provider.GetService <SComponentModel, IComponentModel>(); var picker = componentModel.GetService <Func <ISolutionPicker> >()(); picker.Owner = Application.Current.MainWindow; picker.RootItem = provider.GetService <ISolution>(); picker.Title = Properties.Resources.VsTemplateUriEditor_PickerTitle; picker.EmptyItemsMessage = string.Format(CultureInfo.CurrentCulture, Resources.VsTemplateUriEditor_EmptyItemsMessage, FileExtension); picker.Filter.Kind = ItemKind.Solution | ItemKind.SolutionFolder | ItemKind.Project | ItemKind.Folder | ItemKind.Item; picker.Filter.MatchFileExtensions = FileExtension; SetSelectedItem(context, picker, uriService, GetAuthoringTemplateProperty(context)); if (picker.ShowDialog()) { // Create and return the Uri for the template var owner = GetPropertyOwner(context); var configurator = new VsTemplateConfigurator(provider); IItem selectedItem; if (!ExtensionMatches(picker.SelectedItem) || picker.SelectedItem.Parent.Kind == ItemKind.Item) { selectedItem = GetTemplateItemFromTT(picker.SelectedItem); //message telling the user to do his magic on his own var messageService = provider.GetService <IUserMessageService>(); if (messageService != null) { messageService.ShowWarning(Resources.VsTemplateUriEditor_ReferToGuidance); } } else { selectedItem = picker.SelectedItem.As <IItem>(); } // Update the vstemplate var template = configurator.Configure(selectedItem, owner.DisplayName, owner.Description, owner.GetSchemaPathValue()); template.RemoveWizardExtension(TemplateWizardInfo.InstantiationTemplateWizardFullTypeName); template.RemoveWizardExtension(TemplateWizardInfo.ElementReplacementsTemplateWizardFullTypeName); if (context.Instance is ITemplateSettings) { // The editor is being used from the template launchpoint, so we add // the template wizard template.AddWizardExtension(TemplateWizardInfo.InstantiationTemplateWizardFullTypeName); template.SetHidden(!((ITemplateSettings)context.Instance).CreateElementOnUnfold); } else { // The editor is being used from a command, don't show it in Add/Remove Programs template.SetHidden(true); } template.AddWizardExtension(TemplateWizardInfo.ElementReplacementsTemplateWizardFullTypeName); // Set also the authoring URI value. SetAuthoringUri(context, uriService.CreateUri(selectedItem)); templateUri = uriService.CreateUri <IVsTemplate>(template).AbsoluteUri; } }, Resources.VsTemplateUriEditor_FailedToEdit); return(templateUri); }