Pages: 1
Print
Author Topic: After adding items to a builtin menu, the items remain disabled  (Read 3596 times)
dcramer
Member

Posts: 120


« on: March 29, 2010, 09:25:06 AM »

Using XMetaL 4.6. With the following in a test macro, when I run the macro it adds the cvs menu and two menu items to the file menu in the appropriate location. However, the menu items "cvs commit" and "open in wincvs" are disabled even though the macros exist. Note that if I add an entirely new top level menu and some menu items on it, everything is fine. I only have this problem when I add items to a builtin menu:

Code:
// Get the CommandBars object
var cmdBars = Application.CommandBars;
// Get a single command bar (the main menu bar)
var menuBar = cmdBars.item("Menu bar");
// Get all of the menu bar's controls (all of the menus)
var menuBarCtrls = menuBar.Controls;

var currentTopMenu;
var currentTopMenuCtrls;

currentTopMenu = menuBarCtrls.item(1);
currentTopMenuCtrls = currentTopMenu.Controls;

newSubItem = currentTopMenuCtrls.Add(5,1,8);
newSubItem.Caption = 'c&vs';

newSubItem.BeginGroup = false;
newSubItem.OnAction = "";
newSubItemMenuCtrls = newSubItem.Controls;

newSubItem = newSubItemMenuCtrls.Add(5,1,1);
newSubItem.Caption = "c&vs commit";
newSubItem.BeginGroup = true;
newSubItem.OnAction = "cvs commit";
newSubItem.Enabled = true;
 
newSubItem = newSubItemMenuCtrls.Add(5,1,2);
newSubItem.Caption = "Open file in &Wincvs";
newSubItem.BeginGroup = false;
newSubItem.OnAction = "open_document_wincvs";
newSubItem.Enabled = true;

What am I doing wrong?

Thanks,
David
Logged

David Cramer
Technical Writer
Motive, an Alcatel-Lucent Company
XMetaLOldTimer
Administrator
Member

Posts: 57


« Reply #1 on: April 14, 2010, 03:35:18 PM »

Please be sure that you only adjust menus and toolbars during one of  the following event macros:


On_Default_CommandBars_Complete

  - must be in Startup mcr file, called to modify global/built-in toolbars used across all document types
  - macros bound via OnAction property assignment must also be inside the Startup mcr file

On_CommandBars_Load_Complete
  - can be in Startup or document-level mcr, called when toolbar is first loaded.
  - Check Application.CommandBars.Name to determine if global/built-in or dtd-specific toolbar collection
  - macros bound via OnAction property assignment must be inside corresponding mcr file with On_CommandBars_Load_Complete



Regards,
Addam

P.S. The CommandBarControl.Enabled property doesn't effect enable/disable state property...it is a long standing bug.  Instead, be sure to call Application.DisableMacro() during On_Update_UI if you need to grey out a menu item or toolbar button of your making.


Logged

Addam Smith, XMetaL Project Lead & Architect
JustSystems Canada Inc.
dcramer
Member

Posts: 120


« Reply #2 on: April 14, 2010, 03:56:24 PM »

That must be it. For testing, I was doing it as part of a normal macro. I'll move them to one of those macros and try again.

Thanks,
David
Logged

David Cramer
Technical Writer
Motive, an Alcatel-Lucent Company
Pages: 1
Print
Jump to: