locked
Dialog page in VS MPF framework RRS feed

  • Question

  • Hi ,
              I implemented a new package using MPF. I have a automation object which is not dialog page. For example, I have below interface as my automation object.

    public interface IDialogPageData
    {
     public String Data1{get;}
     int Data2{get;}
     bool Data3{get;} 
    }
    

    When above object is stored, all are stored as string in registry. I want Data1 to be stored as string, Data2 as DWORD (max is 15), and Data3 as a DWORD exist or not. Is there any way to do it other than overriding public virtual void SaveSettingsToStorage()? Can I say enviroment that these are the formats for the options?

    My other question is on accessing these from DTE object. My hierarchy is "A B\XYZ\General". Notice that there is space in between A and B.
    I provide it by
    [ProvideOptionPage(typeof(BuildGeneralPage), "A B\XYZ", "General", 17, 12, true)]

    I tried to access the object as

    EnvDTE.DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
    EnvDTE.Properties props = dte.get_Properties(@"A B\XYZ", "General");
    

    It throws me Bad_Index Error. Am I doing something wrong ? I tried as dte.get_Properties("A B", "XYZ - General"). Even that failed. I can see the entries in Automation property.

    Any help is much appreciated.

    Thanks & Regards
    VV

    Thursday, July 1, 2010 6:20 AM

All replies

  • Hello, VV

    1.    For your first question, if you want to save the settings to your custom locations, you have to override SaveSettingsToStorage method. Note: your Option page must inherit from DialogPage class.

    2.    Bad index means, it could not find the property value, so open your regedit, and check whether your automation page is exist in HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0Exp\Configuration\AutomationProperties

    To access the properties using automation, you have to implement the EnvDTE.Properties and EnvDTE.Property, and return the Properties object in DialogPage.AutomationObject Property

     see the following sample

    //Implementation of EnvDTE.Properties

        class PropertiesClass : EnvDTE.Properties

        {

            private ArrayList arrList;

            public EnvDTE.DTE dte;

            public PropertiesClass(ArrayList myArray)

            {

                arrList = myArray;

                dte = Package.GetGlobalService(typeof(SDTE)) as DTE;

            }

            #region Properties Members

     

            object Properties.Application

            {

                get { return null; }

            }

     

            int Properties.Count

            {

                get { return arrList.Count; }

            }

     

            DTE Properties.DTE

            {

                get { return dte; }

            }

     

            System.Collections.IEnumerator Properties.GetEnumerator()

            {

                return arrList.GetEnumerator();

            }

     

            Property Properties.Item(object index)

            {

                if (index is int)

                {

                    int indexNum = (int)index;

                    return (Property)arrList[indexNum - 1];

                }

                else

                    throw new Exception("string index is not supported");

            }

     

            object Properties.Parent

            {

                get { return null; }

            }

     

            #endregion

     

            #region IEnumerable Members

     

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()

            {

                return arrList.GetEnumerator();

            }

     

            #endregion

    }

    //Implementation of EnvDTE.Property

       class PropertyClass:EnvDTE.Property

        {

            string PropName;

            object PropValue;

           public PropertyClass(string name, object value)

            {

                this.PropName = name;

                this.PropValue = value;

            }

            #region Property Members

     

            public object Application

            {

                get { return null; }

            }

     

            public EnvDTE.Properties Collection

            {

                get { return BuildGeneralPage.AutomationProperties; }

            }

     

            public EnvDTE.DTE DTE

            {

               

                get {

                     EnvDTE.DTE dte = Package.GetGlobalService(typeof(SDTE)) as DTE;

                     return dte;

                }

            }

     

            public string Name

            {

                get { return PropName; }

            }

     

            public short NumIndices

            {

                get { throw new NotImplementedException(); }

            }

     

            public new object Object

            {

                get

                {

                    throw new NotImplementedException();

                }

                set

                {

                    throw new NotImplementedException();

                }

            }

     

            public EnvDTE.Properties Parent

            {

                get { return null; }

            }

     

            public object Value

            {

                get

                {

                    return PropValue;

                }

                set

                {

                    this.PropValue = value;

                }

            }

     

            public object get_IndexedValue(object Index1, object Index2, object Index3, object Index4)

            {

                throw new NotImplementedException();

            }

     

            public void let_Value(object lppvReturn)

            {

                throw new NotImplementedException();

            }

     

            public void set_IndexedValue(object Index1, object Index2, object Index3, object Index4, object Val)

            {

                throw new NotImplementedException();

            }

     

            #endregion

        }

     

    //My own Option Page

        class BuildGeneralPage : DialogPage

        {

            private int optionValue = 256;

            [Category("My Options CS")]

            [DisplayName("My Option Integer CS")]

            [Description("My integer option CS")]

            public int OptionInteger

            {

                get { return optionValue; }

                set { optionValue = value; }

            }

            public static EnvDTE.Properties AutomationProperties

            {

                get {

                    PropertyClass propClass = new PropertyClass("OptionInteger",256);

                    ArrayList arrList = new ArrayList();

                    arrList.Add(propClass);

                    PropertiesClass propsClass = new PropertiesClass(arrList);

                    return (EnvDTE.Properties)propsClass;

                    }

            }

            public override object AutomationObject

            {

                get

                {

                    object obj = base.AutomationObject;

                    return BuildGeneralPage.AutomationProperties;

                }

            }

        }

    The code is just a sample, it is not properly implementated, you need to implement your self.

    Thanks

    Chao

    • Marked as answer by Chao Kuo Friday, July 9, 2010 1:52 AM
    • Unmarked as answer by Chao Kuo Thursday, July 29, 2010 6:17 AM
    Monday, July 5, 2010 3:18 PM
  • Thanks Chao. I will try this and let you know. Your help is much appreciated. By the way, I register my package without RANU. So I should be looking at HKLM for automation page and property.

    Thanks & Regards

    VV

    Friday, July 9, 2010 6:49 AM
  • Hi Chao,

      There is a API in package class which returns the dialog object. Then get Automation object :

    public abstract class Package : IVsPackage, IServiceProvider, IOleCommandTarget, IVsPersistSolutionOpts, IServiceContainer, System.IServiceProvider, IVsUserSettings, IVsUserSettingsMigration, IVsToolWindowFactory
    {
      protected DialogPage GetDialogPage(Type dialogPageType);
    }
    

    I believe this returns the same instance. Strangely, Pages which are sub divided can be accessed using DTE without implementating Properties and Property class...

     

    Thanks Once Again

    VV

    Saturday, July 10, 2010 7:35 AM