locked
plug-in creation RRS feed

  • Question

  • Hi,

    I am looking to find out if it is possible to create a plug-in or something else that will integrate into the IDE and be able to capture dropping a control on the webform page. I would like to be able to intercept this and be able to create an array of items which would like to a table that we store controls locations/names/properties in. Some back round - We use this type of functionality to create dynamic web forms (runtime) for our users pages. But this means that we need to go into the DB in order to setup manual fields that will go into every form. I am looking to automate this by allowing a developer or someone to drop controls on a web form page within the IDE and press a button that will go out and create the DB entries for each of the controls on the form.

     

    Any ideas on plug-in' creation and how to intercept those specific events (I know a plugin can intercept source code repository events and file open/close events)?

    Thanks

    • Moved by CoolDadTx Wednesday, February 1, 2012 4:25 AM Extensibility related (From:Visual C# IDE)
    Tuesday, January 31, 2012 8:55 PM

Answers

  • Just to follow up on this.

    The webform designer doesn't have any events for toolbox insertion, but you could add a context menu to the designer via add-i or package that could enumerate all the controls via IDesignerHost.Container.Components. This would actually probably be a better solution, because you'll ensure you can account for controls added/removed via copy/paste and delete operations as well.

    The tricky part is figuring out how to get the IDesignerHost for a given webform. The following is a simple add-in for VS 2010, that illustrates how this can be done, with a little assistance from the Visual Studio SDK:

    using System;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.ComponentModel.Design;
    using Extensibility;
    using EnvDTE;
    using EnvDTE80;
    using Microsoft.VisualStudio.CommandBars;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;
    using Microsoft.VisualStudio.OLE.Interop;
    using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
     
    namespace WebFormDH
    {
        public class Connect : IDTExtensibility2
        {
            private DTE2 applicationObject;
            private AddIn addInInstance;
            private CommandBarButton cmdBarButton;
     
            private void OnCmdBarButtonClick(CommandBarButton Ctrl, ref bool CancelDefault)
            {
                DesignSurfaceManager manager = Package.GetGlobalService(typeof(DesignSurfaceManager)) as DesignSurfaceManager;
                if (manager != null)
                {
                    DesignSurface surface = manager.ActiveDesignSurface;
                    if (surface != null)
                    {
                        IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
                        if (host != null)
                        {
                            foreach (var comp in host.Container.Components)
                            {
                                System.Diagnostics.Debug.WriteLine(comp.GetType().ToString());
                            }
                        }
                    }
                }
            }
     
            public Connect() {}
     
            #region IDTExtensibility2
     
            public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
            {
                applicationObject = (DTE2)application;
                addInInstance = (AddIn)addInInst;
     
                // Add a command to the outline group in code context menu. See
                // http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-ivsproffercommands-to-retrieve-a-visual-studio-commandbar.aspx
                // http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx
                // for details.
     
                // Ensure CommandBars colection has been property initialized, before
                // attempting to use IVsProfferCommands.
                CommandBar menuBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];
     
                // Get IVsProfferCommands service
                IVsProfferCommands vsProfferCmds = (IVsProfferCommands)Package.GetGlobalService(typeof(IVsProfferCommands));
     
                // Retrieve webform designers' context menu as a CommandBar
                Guid cmdGroup = new Guid("D7E8C5E1-BDB8-11D0-9C88-0000F8040A53");
                uint menuId = 48;
     
                // Add a custom menu item to the code editors' context menu
                CommandBar ctxMenu = (CommandBar)vsProfferCmds.FindCommandBar(IntPtr.Zero, ref cmdGroup, menuId);
                cmdBarButton = (CommandBarButton)ctxMenu.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
                cmdBarButton.Caption = "Enum Controls";
                cmdBarButton.Style = MsoButtonStyle.msoButtonCaption;
                cmdBarButton.Click += new _CommandBarButtonEvents_ClickEventHandler(OnCmdBarButtonClick);   
            }
     
            public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
            {
                if (cmdBarButton != null)
                {
                    cmdBarButton.Click -= new _CommandBarButtonEvents_ClickEventHandler(OnCmdBarButtonClick);
                    cmdBarButton.Delete(true);
                    cmdBarButton = null;
                }
            }
     
            public void OnAddInsUpdate(ref Array custom) {}
            public void OnStartupComplete(ref Array custom) {}
            public void OnBeginShutdown(ref Array custom) { }
     
            #endregion
        }
    }

    Sincerely,


    Ed Dore

    Thursday, April 26, 2012 10:00 PM

All replies

  • Hi mhamill,

    Thank you for your question.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, February 2, 2012 5:32 AM
  • Either a package or add-in would be appropriate if the webform designer in question actually had some sort of extensibility point that would allow for this. Sadly, I don't believe there is one.

    I'll ask around though, and post back on this thread.

    Sincerely,


    Ed Dore
    Monday, February 6, 2012 10:56 PM
  • Just to follow up on this.

    The webform designer doesn't have any events for toolbox insertion, but you could add a context menu to the designer via add-i or package that could enumerate all the controls via IDesignerHost.Container.Components. This would actually probably be a better solution, because you'll ensure you can account for controls added/removed via copy/paste and delete operations as well.

    The tricky part is figuring out how to get the IDesignerHost for a given webform. The following is a simple add-in for VS 2010, that illustrates how this can be done, with a little assistance from the Visual Studio SDK:

    using System;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.ComponentModel.Design;
    using Extensibility;
    using EnvDTE;
    using EnvDTE80;
    using Microsoft.VisualStudio.CommandBars;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;
    using Microsoft.VisualStudio.OLE.Interop;
    using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
     
    namespace WebFormDH
    {
        public class Connect : IDTExtensibility2
        {
            private DTE2 applicationObject;
            private AddIn addInInstance;
            private CommandBarButton cmdBarButton;
     
            private void OnCmdBarButtonClick(CommandBarButton Ctrl, ref bool CancelDefault)
            {
                DesignSurfaceManager manager = Package.GetGlobalService(typeof(DesignSurfaceManager)) as DesignSurfaceManager;
                if (manager != null)
                {
                    DesignSurface surface = manager.ActiveDesignSurface;
                    if (surface != null)
                    {
                        IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
                        if (host != null)
                        {
                            foreach (var comp in host.Container.Components)
                            {
                                System.Diagnostics.Debug.WriteLine(comp.GetType().ToString());
                            }
                        }
                    }
                }
            }
     
            public Connect() {}
     
            #region IDTExtensibility2
     
            public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
            {
                applicationObject = (DTE2)application;
                addInInstance = (AddIn)addInInst;
     
                // Add a command to the outline group in code context menu. See
                // http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-ivsproffercommands-to-retrieve-a-visual-studio-commandbar.aspx
                // http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx
                // for details.
     
                // Ensure CommandBars colection has been property initialized, before
                // attempting to use IVsProfferCommands.
                CommandBar menuBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];
     
                // Get IVsProfferCommands service
                IVsProfferCommands vsProfferCmds = (IVsProfferCommands)Package.GetGlobalService(typeof(IVsProfferCommands));
     
                // Retrieve webform designers' context menu as a CommandBar
                Guid cmdGroup = new Guid("D7E8C5E1-BDB8-11D0-9C88-0000F8040A53");
                uint menuId = 48;
     
                // Add a custom menu item to the code editors' context menu
                CommandBar ctxMenu = (CommandBar)vsProfferCmds.FindCommandBar(IntPtr.Zero, ref cmdGroup, menuId);
                cmdBarButton = (CommandBarButton)ctxMenu.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, 1, true);
                cmdBarButton.Caption = "Enum Controls";
                cmdBarButton.Style = MsoButtonStyle.msoButtonCaption;
                cmdBarButton.Click += new _CommandBarButtonEvents_ClickEventHandler(OnCmdBarButtonClick);   
            }
     
            public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
            {
                if (cmdBarButton != null)
                {
                    cmdBarButton.Click -= new _CommandBarButtonEvents_ClickEventHandler(OnCmdBarButtonClick);
                    cmdBarButton.Delete(true);
                    cmdBarButton = null;
                }
            }
     
            public void OnAddInsUpdate(ref Array custom) {}
            public void OnStartupComplete(ref Array custom) {}
            public void OnBeginShutdown(ref Array custom) { }
     
            #endregion
        }
    }

    Sincerely,


    Ed Dore

    Thursday, April 26, 2012 10:00 PM