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); } }
/// <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 virtual T GetService <T>() where T : class { T service = _services?.GetService <T>() ?? FlexServiceProvider.Services.GetService <T>(); if (service != null) { return(service); } if (typeof(T) == typeof(ILoggers)) { return((T)GetDefaultLoggers()); } return(null); }
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; } }
protected virtual void Dispose(bool disposing) { Debug.Assert(disposing, "Finalizing CustomCommand without disposing."); if (disposing) { if (m_serviceProvider != null) { IMenuCommandService menuService = m_serviceProvider.GetService <IMenuCommandService>(); if (menuService != null) { menuService.RemoveCommand(this); } m_serviceProvider = null; } } m_metaCommand = null; m_selection = null; Debug.WriteLine("Unloaded and disposed command " + m_metaCommand); }
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(); } }; } } }