locked
Opening a specific Property Page RRS feed

  • Question

  • I am looking for a method for opening a specific property page in an isolated shell application.
    The property pages are opened using the Project.Properies command:

        string command = "Project.Properties";
        string args = "";

        var dte = (DTE)Package.GetGlobalService(typeof(DTE));
        dte.ExecuteCommand(command, args);

    This works fine.  However, I want to open a spesific Propery Page. The argument is not used.
    Visual Studio have the commands Project.PublishasWebService  and Project.PackagePublishSettings that implement the functionality I am after.
    The Property Page I want to point to is defined in our application.

    Thanks,

    Lars Kvenild


    Lars Kvenild
    Monday, February 7, 2011 12:37 PM

Answers

  • Looking at what PackagePublishSettings does it looks like you want to do the following

     

    1:  Get the IVsHierarchy for the project whose properties page you want to open.

    2:  Call GetGuidProperty on the IVsHierarchy asking for VSHPROPID2.VSHPROPID_ProjectDesignerEditor (make sure to check that the call succeeded and the returned GUID is not Guid.Empty).

    3:  Cast your IVsHierarchy to IVsProject2 (use an as cast and check for null here).

    4:  Call IVsProject2.ReopenItem passing in ITEMID_ROOT for the first param, the Guid you got in step 2 for the second param, an empty string for the third param (null may also work, I didn't check), an IntPtr whose value is -1 for the fifth param (this is called DOCDATAEXISTING_UNKNOWN in the code I am looking at, but they define that locally, so you would have to too).

    5:  If step 4 succeeded and the IVsWindowFrame returned is non-null then call Show to ensure it is visible.

    6:  Call GetProperty on the IVsWindowFrame asking for VSFPROPID.VSFPROPID_DocView (make sure to check that the call succeeded).

    7:  Cast the object that came back from step 6 as IVsMultiViewDocumentView (use an as cast and make sure it results in a non-null result).

    8:  Call ActivateLogicalView on the IVsMultiViewDocumentView you got in step 7 passing in the GUID identifier of the property page you want to be shown.


    This of course could (and should) be wrapped up in an easy to use helper method as it is kind of gross. Let me know if anything above is unclear or isn't working for you, I have only translated the code from the command handler to the steps above, I haven't actually tried it out. :)

    Ryan

    Edit:  Changed the call in step 2 to GetGuidProperty, not GetProperty, as the property you are fetching is a GUID.

    Monday, February 7, 2011 6:31 PM

All replies

  • Looking at what PackagePublishSettings does it looks like you want to do the following

     

    1:  Get the IVsHierarchy for the project whose properties page you want to open.

    2:  Call GetGuidProperty on the IVsHierarchy asking for VSHPROPID2.VSHPROPID_ProjectDesignerEditor (make sure to check that the call succeeded and the returned GUID is not Guid.Empty).

    3:  Cast your IVsHierarchy to IVsProject2 (use an as cast and check for null here).

    4:  Call IVsProject2.ReopenItem passing in ITEMID_ROOT for the first param, the Guid you got in step 2 for the second param, an empty string for the third param (null may also work, I didn't check), an IntPtr whose value is -1 for the fifth param (this is called DOCDATAEXISTING_UNKNOWN in the code I am looking at, but they define that locally, so you would have to too).

    5:  If step 4 succeeded and the IVsWindowFrame returned is non-null then call Show to ensure it is visible.

    6:  Call GetProperty on the IVsWindowFrame asking for VSFPROPID.VSFPROPID_DocView (make sure to check that the call succeeded).

    7:  Cast the object that came back from step 6 as IVsMultiViewDocumentView (use an as cast and make sure it results in a non-null result).

    8:  Call ActivateLogicalView on the IVsMultiViewDocumentView you got in step 7 passing in the GUID identifier of the property page you want to be shown.


    This of course could (and should) be wrapped up in an easy to use helper method as it is kind of gross. Let me know if anything above is unclear or isn't working for you, I have only translated the code from the command handler to the steps above, I haven't actually tried it out. :)

    Ryan

    Edit:  Changed the call in step 2 to GetGuidProperty, not GetProperty, as the property you are fetching is a GUID.

    Monday, February 7, 2011 6:31 PM

  • Thank you!

    It works!

    Since I am user the default property editor, step 2 is not needed.

    Step 4 can then be like this (where project2 is the variable from step 3) :

                IntPtr ip = (IntPtr)(-1);
                IVsWindowFrame frame = null;
                project2.ReopenItem(VSConstants.VSITEMID_ROOT, VSConstants.GUID_ProjectDesignerEditor, null, new Guid("00000000-0000-0000-0000-000000000000"), ip, out frame);

    Lars

     


    Lars Kvenild
    Tuesday, February 8, 2011 5:42 PM
  • Glad it worked out. I believe you should be able to use Guid.Empty for the GUID argument if you are just creating one that is all 0 as you do above.

    Ryan

    Tuesday, February 8, 2011 6:22 PM
  • Hi LarsKv /Ryan Molden ,

    Can you  please send me the code iam looking for the same code what you  have achieved to open the propert page.

    Thanks & Regards,

    Ellaiyaraja B


    Thanks & Regards, Ellaiyaraja B

    Thursday, May 17, 2012 5:26 AM
  • The explanation is above, this is a help forum not a place where others write code for you. If you have specific questions about the instructions feel free to ask, but a "send me the code" request will likely be ignored.

    Ryan

    Thursday, May 17, 2012 3:01 PM