/// <summary> /// Adds specified meta-feature to the store. /// </summary> /// <param name="featureType">Type of feature to add.</param> public void AddMetaFeature(Type featureType) { if (featureType == null) { throw new ArgumentNullException("featureType"); } FeatureAttribute attribute = ReflectionHelper.GetAttribute <FeatureAttribute>(featureType); if (attribute == null) { throw new ArgumentException("featureType must have a FeatureAttribute or derived applied to it."); } Type metaFeatureType = attribute.MetaFeature; Debug.Assert(metaFeatureType != null); ConstructorInfo constructor = metaFeatureType.GetConstructor(new Type[] { typeof(MetaFeatureStore), typeof(Type) }); if (constructor == null) { throw new ArgumentException("MetaFeature type must have a constructor taking MetaFeatureStore and Type arguments."); } MetaFeature metaFeature = constructor.Invoke(new object[] { this, featureType }) as MetaFeature; Debug.Assert(!m_metaFeatures.ContainsKey(metaFeature.FeatureType)); if (!m_metaFeatures.ContainsKey(metaFeature.FeatureType)) { Debug.WriteLine("MetaFeatureStore: Adding meta-feature to the store: " + metaFeature.ToString()); m_metaFeatures[metaFeature.FeatureType] = metaFeature; m_relationshipsDirty = true; } }
/// <summary> /// Finds or if not found, creates an feature of specified type from the meta-store. /// </summary> /// <param name="featureType">Type of the feature to load.</param> /// <returns>Created feature.</returns> public virtual object CreateFeature(Type featureType) { if (m_features == null) { m_features = new Dictionary <MetaFeature, IDisposable>(); } MetaFeature metaFeature = MetaFeature.Store.FindMetaFeature(featureType); if (metaFeature == null) { throw new ArgumentException("Meta-feature corrsponding to " + featureType + " was not found in the store."); } if (!metaFeature.Enabled) { return(null); } IDisposable feature; if (m_features.TryGetValue(metaFeature, out feature)) { return(feature); } else { feature = metaFeature.CreateFeature(this); } m_features[metaFeature] = feature; Debug.Assert(feature != null); return(feature); }
/// <summary> /// Gets meta-features on the opposite side of relationship. /// </summary> /// <param name="metaFeature">MetaFeature end of relationship.</param> /// <param name="role">The role of returned meta-features with regards to the given meta-feature.</param> /// <returns>List of opposite role players.</returns> public IList <MetaFeature> GetRolePlayers(MetaFeature metaFeature, MetaRelationshipKind role) { if (metaFeature == null) { throw new ArgumentNullException("feature"); } if (this.m_relationshipsDirty) { RebuildRelationships(); } Dictionary <MetaFeature, List <MetaFeature> > s1; if (!m_relationships.TryGetValue(role, out s1)) { return(new List <MetaFeature>()); } List <MetaFeature> result; if (!s1.TryGetValue(metaFeature, out result)) { return(new List <MetaFeature>()); } return(result); }
private void OnDocumentOpened(object sender, DocumentEventArgs args) { if (args != null && IsDocDataSupported(args.DocData)) { if (m_designerContext == null) { m_designerContext = CreateDesignerContext(); } DiagramContext diagramContext; if (this.DiagramContexts.TryGetValue(args.DocCookie, out diagramContext)) { Debug.Fail("Diagram context already existed - disposing it."); this.DiagramContexts.Remove(args.DocCookie); diagramContext.Dispose(); } diagramContext = CreateDiagramContext(args.DocData); Debug.Assert(diagramContext != null); if (diagramContext != null) { MetaFeature diagramMetaFeature = this.MetaFeature.Store.FindMetaFeature(diagramContext.GetType()); if (diagramMetaFeature != null) { diagramContext.DiagramDocView = ((ModelingDocData)args.DocData).DocViews[0] as DiagramDocView; diagramContext.Associate(diagramMetaFeature, this.ServiceProvider); this.DiagramContexts[args.DocCookie] = diagramContext; } else { diagramContext.Dispose(); } } } }
public void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider) { if (m_metaCommand != null || m_serviceProvider != null) { throw new InvalidOperationException("Associate should only be called once on a IFeature instance."); } if (metaFeature == null) { throw new ArgumentNullException("metaFeature"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } m_metaCommand = metaFeature as MetaCommand; m_serviceProvider = serviceProvider; IMenuCommandService menuService = m_serviceProvider.GetService <IMenuCommandService>(); Debug.Assert(menuService != null); if (menuService != null) { menuService.AddCommand(this); } }
protected virtual void Dispose(bool disposing) { // This could happen: when user disconnects add-in // Debug.Assert(disposing, "Finalizing " + this.GetType().Name + " without disposing."); m_serviceProvider = null; m_metaFeature = null; Debug.WriteLine("Disposed feature of type: " + m_metaFeature); }
/// <summary> /// Called on a feature object right after it has been created from the /// meta-feature information. /// </summary> /// <param name="metaFeature">Corresponding MetaFeature which created the feature.</param> /// <param name="serviceProvider">Feature context (service provider).</param> public void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider) { Debug.Assert(!m_disposed); if (metaFeature == null) { throw new ArgumentNullException("metaFeature"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } m_metaFeature = metaFeature; m_serviceProvider = serviceProvider; VsShell.IVsUIShell vsUIShell = m_serviceProvider.GetService <VsShell.IVsUIShell>(); Debug.Assert(vsUIShell != null); if (vsUIShell != null) { Guid toolWindowID = this.GetType().GUID; int[] position = new int[1]; VsShell.IVsWindowFrame frame; Guid emptyGuid = Guid.Empty; int hr = vsUIShell.CreateToolWindow( (int)VsShell.__VSCREATETOOLWIN.CTW_fInitNew, 0, this, ref emptyGuid, ref toolWindowID, ref emptyGuid, null, m_metaFeature.Name, position, out frame); // If the add-in is reloaded, the CreateToolWindow method may fail because // previous tool window may not be destroyed correctly. We try to create // tool window again. if (ErrorHandler.Failed(hr)) { ErrorHandler.ThrowOnFailure(vsUIShell.CreateToolWindow( (int)VsShell.__VSCREATETOOLWIN.CTW_fInitNew, 0, this, ref emptyGuid, ref toolWindowID, ref emptyGuid, null, m_metaFeature.Name, position, out frame)); } } }
public override void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider) { base.Associate(metaFeature, serviceProvider); m_monitorDocumentsService = serviceProvider.GetService <IMonitorDocumentsService>(); Debug.Assert(m_monitorDocumentsService != null); if (m_monitorDocumentsService != null) { m_monitorDocumentsService.ForAllOpenedDocuments(delegate(DocumentEventArgs args) { OnDocumentOpened(m_monitorDocumentsService, args); }); m_monitorDocumentsService.DocumentOpened += OnDocumentOpened; m_monitorDocumentsService.DocumentClosed += OnDocumentClosed; } }
private void AddOneSideRelationship(MetaFeature feature1, MetaRelationshipKind kind, MetaFeature feature2) { Dictionary <MetaFeature, List <MetaFeature> > s1; if (!m_relationships.TryGetValue(kind, out s1)) { s1 = new Dictionary <MetaFeature, List <MetaFeature> >(); m_relationships[kind] = s1; } List <MetaFeature> s2; if (!s1.TryGetValue(feature1, out s2)) { s2 = new List <MetaFeature>(); s1[feature1] = s2; } s2.Add(feature2); }
/// <summary> /// Searches for a feature of specified type in the current context only /// without looking up the context chain. /// </summary> /// <param name="featureType">Type of the feature to find.</param> /// <returns>Feature instance of found and null otherwise.</returns> public virtual object FindFeature(Type featureType) { if (m_features != null) { MetaFeature metaFeature = MetaFeature.Store.FindMetaFeature(featureType); if (metaFeature == null) { throw new ArgumentException("Meta-feature corrsponding to " + featureType + " was not found in the store."); } IDisposable feature; if (m_features.TryGetValue(metaFeature, out feature)) { return(feature); } } return(null); }
/// <summary> /// Called on a feature object right after it has been created from the /// meta-feature information. /// </summary> /// <param name="metaFeature">Corresponding MetaFeature which created the feature.</param> /// <param name="serviceProvider">Feature context (service provider).</param> public override void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider) { base.Associate(metaFeature, serviceProvider); IList <MetaFeature> children = metaFeature.Store.GetRolePlayers(metaFeature, MetaRelationshipKind.Child); Debug.Assert(children != null); if (children != null) { foreach (MetaFeature childMetaFeature in children) { if (childMetaFeature.Enabled) { this.CreateFeature(childMetaFeature.FeatureType); } } } }
/// <summary> /// Called on a feature object right after it has been created from the /// meta-feature information. /// </summary> /// <param name="metaFeature">Corresponding MetaFeature which created the feature.</param> /// <param name="serviceProvider">Feature context (service provider).</param> public virtual void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider) { if (m_metaFeature != null || m_serviceProvider != null) { throw new InvalidOperationException(); } if (metaFeature == null) { throw new ArgumentNullException("metaFeature"); } m_metaFeature = metaFeature; // We do allow global context to have no parent context which is expected. if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } m_serviceProvider = serviceProvider; }
/// <summary> /// Uninstalls specified command from the product. /// </summary> /// <param name="metaFeature">MetaCommand to uninstall.</param> public void Uninstall(MetaFeature metaFeature) { MetaCommand metaCommand = metaFeature as MetaCommand; Debug.Assert(metaCommand != null); if (metaCommand != null && metaCommand.IsCustomCommand) { string canonicalName = m_commandService.GetCanonicalName(metaCommand.Name); if (metaCommand.CustomCommandId == null) { metaCommand.CustomCommandId = m_commandService.FindCommandId(canonicalName); } if (metaCommand.CustomCommandId != null) { m_commandService.DeleteCommand(canonicalName); metaCommand.CustomCommandId = null; } } }
private void AddMetaRelationship(MetaFeature feature1, MetaRelationshipKind kind, MetaFeature feature2) { if (feature1 == null) { throw new ArgumentNullException("feature1"); } if (feature2 == null) { throw new ArgumentNullException("feature2"); } if (feature1 == feature2) { throw new InvalidOperationException(); } AddOneSideRelationship(feature1, kind, feature2); switch (kind) { case MetaRelationshipKind.Child: kind = MetaRelationshipKind.Parent; break; case MetaRelationshipKind.Dependants: kind = MetaRelationshipKind.Depends; break; case MetaRelationshipKind.Depends: kind = MetaRelationshipKind.Dependants; break; case MetaRelationshipKind.Parent: kind = MetaRelationshipKind.Child; break; default: throw new InvalidOperationException(); } AddOneSideRelationship(feature2, kind, feature1); }
/// <summary> /// Checks whether given command is already installed. /// </summary> /// <param name="metaFeature">MetaCommand.</param> /// <returns>True if installed and false otherwise.</returns> public bool IsInstalled(MetaFeature metaFeature) { MetaCommand metaCommand = metaFeature as MetaCommand; Debug.Assert(metaCommand != null); if (metaCommand != null) { if (metaCommand.IsCustomCommand) { if (metaCommand.CustomCommandId == null) { metaCommand.CustomCommandId = m_commandService.FindCommandId(m_commandService.GetCanonicalName(metaCommand.Name)); } return(metaCommand.CustomCommandId != null); } else { return(true); } } return(false); }
/// <summary> /// Installs the command into the product. /// </summary> /// <param name="metaFeature">MetaCommand to install.</param> public void Install(MetaFeature metaFeature) { MetaCommand metaCommand = metaFeature as MetaCommand; Debug.Assert(metaCommand != null && !IsInstalled(metaCommand)); if (metaCommand != null && metaCommand.IsCustomCommand) { string canonicalName = m_commandService.GetCanonicalName(metaCommand.Name); if (metaCommand.CustomCommandId == null) { metaCommand.CustomCommandId = m_commandService.FindCommandId(canonicalName); if (metaCommand.CustomCommandId == null) { metaCommand.CustomCommandId = m_commandService.CreateCommand(canonicalName, metaCommand.Name, metaCommand.Description); } } foreach (CommandPlacementAttribute attr in ReflectionHelper.GetAttributes <CommandPlacementAttribute>(metaCommand.FeatureType)) { m_commandService.PlaceCommand(canonicalName, attr.CommandBarPath); } } }
public void Install(MetaFeature metaFeature) { Debug.Assert(metaFeature != null); Debug.Assert(!this.IsInstalled(metaFeature)); }
public override void Associate(MetaFeature metaFeature, ITypedServiceProvider serviceProvider) { if (metaFeature == null) { throw new ArgumentNullException("metaFeature"); } if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } base.Associate(metaFeature, serviceProvider); Debug.Assert(m_scrollPanel == null); if (m_scrollPanel == null) { DiagramContext diagramContext = serviceProvider.GetService <IFeatureContext>() as DiagramContext; Debug.Assert(diagramContext != null && diagramContext.DiagramView != null); if (diagramContext != null && diagramContext.DiagramView != null) { // Create and show a thumbnail form. DiagramView diagramView = diagramContext.DiagramView; m_scrollPanel = new Panel(); m_scrollPanel.BackgroundImage = new Bitmap(typeof(ThumbnailViewForm), @"ThumbnailView.bmp"); m_scrollPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; m_scrollPanel.BackgroundImageLayout = ImageLayout.Center; diagramView.Invoke(new EventHandler(delegate(object sender, EventArgs e) { diagramView.Controls.Add(m_scrollPanel); })); m_scrollPanel.Width = diagramView.Controls[1].Width; m_scrollPanel.Height = diagramView.Controls[2].Height; m_scrollPanel.Left = diagramView.Width - m_scrollPanel.Width; m_scrollPanel.Top = diagramView.Height - m_scrollPanel.Height; m_scrollPanel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; m_scrollPanel.BringToFront(); m_scrollPanel.MouseDown += delegate(object sender, MouseEventArgs args) { // Right-click on the thumbnail icon brings pan/zoom tool window. Debug.Assert(args != null); if (args != null && args.Button == MouseButtons.Right) { IFeatureContext featureContext = this.ServiceProvider.GetService <IFeatureContext>(); Debug.Assert(featureContext != null); if (featureContext != null) { PanZoomWindow toolWindow = featureContext.CreateFeature <PanZoomWindow>(); Debug.Assert(toolWindow != null); if (toolWindow != null) { toolWindow.Show(); } } } else { // Any other click on thumbnail icon displays the thumbnail form. new ThumbnailViewForm(m_scrollPanel, diagramView.DiagramClientView).ShowDialog(); } }; } } }
public bool IsInstalled(MetaFeature metaFeature) { Debug.Assert(metaFeature != null); return(true); }
public void Uninstall(MetaFeature metaFeature) { Debug.Assert(metaFeature != null); }