/// <include file='doc\MenuDesigner.uex' path='docs/doc[@for="MenuDesigner.CommitPropertyChange"]/*' /> /// <devdoc> /// This method sets the properites on menu's which are set by VS's Menu Designer. /// </devdoc> private void CommitPropertyChange(IComponent target, PropertyDescriptor prop, object value) { if (target == null || prop == null || value == null) { return; } if (justCreated && value.ToString().Length == 0) { justCreated = false; return; } MenuEditorService menuEdSvc = GetService(typeof(IMenuEditorService)) as MenuEditorService; if (menuEdSvc != null) { menuEdSvc.MenuChangedLocally = true; } if (!(prop.GetValue(target)).Equals(value)) { prop.SetValue(target, value); if (menuEdSvc != null) { menuEdSvc.CommitTransaction(); } } }
/// <include file='doc\MenuDesigner.uex' path='docs/doc[@for="MenuDesigner.OnEditMenuVerb"]/*' /> /// <devdoc> /// Fired when the user invokes the designer verb to edit the menu. /// </devdoc> private void OnEditMenuVerb(object sender, EventArgs e) { MenuEditorService menuEdSvc = GetService(typeof(IMenuEditorService)) as MenuEditorService; Menu m = (Menu)Component; if (menuEdSvc != null) { if (m.MenuItems.Count > 0) { //with a valid count, set selection to 0th item menuEdSvc.SetSelection(m.MenuItems[0]); } else { //otherwise, set our selection to our "unknown" item editor.SelectionChange((IntPtr)UNKNOWN_MENU_ITEM); } } }
/// <include file='doc\MenuDesigner.uex' path='docs/doc[@for="MenuDesigner.IMIGetProp"]/*' /> /// <devdoc> /// This method is called by the IVsMenuEditor when properties of a particular menu /// item need to be retrieved. /// </devdoc> public int IMIGetProp(int propId, out object pObj) { //make sure we can get a component that is a menuitem //so we can get its' properties... IComponent c = Component; if (!(c is MenuItem)) { pObj = null; return(NativeMethods.S_OK); } MenuItem menuItem = (MenuItem)c; switch (propId) { case __VSMEPROPID.VSMEPROPID_NAME: String name = null; PropertyDescriptor pd = TypeDescriptor.GetProperties(menuItem)["Name"]; if (pd != null) { name = pd.GetValue(menuItem).ToString(); } pObj = name; break; case __VSMEPROPID.VSMEPROPID_CAPTION: pObj = TypeDescriptor.GetProperties(menuItem)["Text"].GetValue(menuItem).ToString(); //passing a 0 length string back into the menu editor if it's not //active will not redraw... so here, we force a repaint, by setting the appropriate item. //This case only surfaces if you "undo" a menu item's text and the menu editor is not active. // if (pObj != null && pObj.ToString().Length == 0) { MenuEditorService menuEdSvc = GetService(typeof(IMenuEditorService)) as MenuEditorService; if (menuEdSvc != null && !menuEdSvc.IsActive()) { menuEdSvc.SetSelection(menuItem); } } break; case __VSMEPROPID.VSMEPROPID_CHECKED: pObj = TypeDescriptor.GetProperties(menuItem)["Checked"].GetValue(menuItem); break; case __VSMEPROPID.VSMEPROPID_ENABLED: pObj = TypeDescriptor.GetProperties(menuItem)["Enabled"].GetValue(menuItem); break; case __VSMEPROPID.VSMEPROPID_VISIBLE: pObj = TypeDescriptor.GetProperties(menuItem)["Visible"].GetValue(menuItem); break; case __VSMEPROPID.VSMEPROPID_RADIOCHECK: pObj = TypeDescriptor.GetProperties(menuItem)["RadioCheck"].GetValue(menuItem); break; default: pObj = null; break; } return(NativeMethods.S_OK); }