1 Reply Latest reply on Sep 13, 2016 12:43 PM by Matthew Elgie

    GetGroupDataFromRegistry Fails if CommandGroup contains multiple MenuToolbarOption

    Andrew Johnson

      I have noticed that GetGroupDataFromRegistry always fails if I have CommandItems in my CommandGroup that have different MenuToolBarOptions.

       

      For example, I have 3 CommandItems. The first two use a MenuTBOption to be shown in the menu and toolbar. The third item is only shown in the menu, not toolbar. In this configuration, GetGroupDataFromRegistry always returns false, and registryIDs is null.

       

      If I change the code so that all three CommandItems use the same MenuTBOption, GetGroupDataFromRegistry returns true and registryIDs is set to the correct array.

       

      This seems to be a bug. The workaround forces me to show buttons on a toolbar that I don't want to be there. Not the end of the world, but not ideal. Has anyone else experienced this, or can confirm this behavior?

       

      Thanks

       

      Example Code (Results in GetGroupDataFromRegistry = false)

      const string title = "My Command Group";
      const string toolTip = "My Command Group";
      
      const int MainCommandGroupID = 83;
      const int MainItemID1 = 831;
      const int MainItemID2 = 832;
      const int MainItemID3 = 833;
      const int menuOnlyOption = (int)swCommandItemType_e.swMenuItem;
      const int menuToolbarOption = (int) (swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
      
      var cmdGroupErr = 0;
      var ignorePrevious = false;
      object registryIDs;
      var getDataResult = CmdMgr.GetGroupDataFromRegistry(MainCommandGroupID, out registryIDs);
      var knownIDs = new[] {MainItemID1, MainItemID2, MainItemID3};
      
      if (getDataResult)
      {
          if (!CompareIDs((int[]) registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup
          {
              ignorePrevious = true;
          }
      }
      
      MainCommandGroup = CmdMgr.CreateCommandGroup2(MainCommandGroupID, title, toolTip, "", -1, ignorePrevious, cmdGroupErr);
      
      MainCommandGroup.AddCommandItem2("DoSomethingA", -1, "", "", 0, nameof(DoSomethingA), "", MainItemID1, menuToolbarOption);
      MainCommandGroup.AddCommandItem2("DoSomethingB", -1, "", "", 2, nameof(DoSomethingB), "", MainItemID2, menuToolbarOption);
      MainCommandGroup.AddCommandItem2("DoSomethingC", -1, "", "", 1, nameof(DoSomethingC), "", MainItemID3, menuOnlyOption);
      

       

      Example Code (Results in GetGroupDataFromRegistry = true)

      const string title = "My Command Group";
      const string toolTip = "My Command Group";
      
      const int MainCommandGroupID = 83;
      const int MainItemID1 = 831;
      const int MainItemID2 = 832;
      const int MainItemID3 = 833;
      const int menuToolbarOption = (int) (swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
      
      var cmdGroupErr = 0;
      var ignorePrevious = false;
      
      object registryIDs;
      var knownIDs = new[] {MainItemID1, MainItemID2, MainItemID3};
      var getDataResult = CmdMgr.GetGroupDataFromRegistry(MainCommandGroupID, out registryIDs);
      if (getDataResult)
      {
          if (!CompareIDs((int[]) registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup
          {
              ignorePrevious = true;
          }
      }
      
      MainCommandGroup = CmdMgr.CreateCommandGroup2(MainCommandGroupID, title, toolTip, "", -1, ignorePrevious, cmdGroupErr);
      
      MainCommandGroup.AddCommandItem2("DoSomethingA", -1, "", "", 0, nameof(DoSomethingA), "", MainItemID1, menuToolbarOption);
      MainCommandGroup.AddCommandItem2("DoSomethingB", -1, "", "", 2, nameof(DoSomethingB), "", MainItemID2, menuToolbarOption);
      MainCommandGroup.AddCommandItem2("DoSomethingC", -1, "", "", 1, nameof(DoSomethingC), "", MainItemID3, menuToolbarOption);