Subscribe Bookmark RSS Feed

Outline Boxes and Menu Scripts - clearing checked items from submenus

dqr2

Community Trekker

Joined:

Jun 19, 2015

Hi,

 

I have an outline box which has a menu script associated with it. That menu script has several menu items, some of which have submenus.  Many of the submenus contain a set of mutually exclusive options that I want to place a tick by when they are selected, while at the same time unchecking all the alternatives (so for example, if my submenu sets the number of decimal places in a table to 1, 2, 3 or 4, then if I select "2", I will want to check the "2" item, and uncheck the "1", "3" and "4" items).

 

I'm still developing this application, so the actual menu structure is constantly changing as I add new options and/or modify existing ones. I therefore want to avoid having to hard-code the above checking/unchecking process. Instead, I want to automatically identify within which submenu I've just clicked on an item, and then just run a little function that clears all the ticks within the same submenu, and then checks the item I've just clicked.  I can do this with the help of the "<< get submenu" property if I can get my script to tell me which menu item I've just clicked on.

 

I could set up a counting variable for each item (i.e. "M=1" for the first menu item, "M=2" for the second, "M=3" for the third and so on) and then just refer to the value of M to work out which item I've just clicked (as I've done in the little example below which I've cooked up just to illustrate the problem), but I would then have to change all the assignments every time the menu was edited - which rather defeats the object of the exercise.

 

Can this be done? I can't see any property of an outline box that would supply me with this information.

 

Many thanks

 

expr_POD = expr(for(i=1, i<=4, i++, My_OutlineBox << set menu item state(1+i, 0)); My_OutlineBox << set menu item state(1+POD, 1));

expr_Rec = expr(for(i=1, i<=3, i++, My_OutlineBox << set menu item state(6+i, 0)); My_OutlineBox << set menu item state(6+Rec, 1));

expr_Doc = expr(for(i=1, i<=4, i++, My_OutlineBox << set menu item state(10+i, 0)); My_OutlineBox << set menu item state(10+Doc, 1));

 

My_OutlineBox = OutlineBox("My OutlineBox",

textbox("Some stuff in the window"),

<< set menu script(

{

"Decimals", " ",

"1 POD", POD=1; expr_POD,

"2 POD", POD=2; expr_POD,

"3 POD", POD=3; expr_POD,

"4 POD", POD=4; expr_POD,

"Recipient", " ",

"R and D", Rec=1; expr_Rec,

"Marketing", Rec=2; expr_Rec,

"Pre-Sales", Rec=3; expr_Rec,

"Document Format", " ",

"Quarto", Doc=1; expr_Doc,

"Foolscap", Doc=2; expr_Doc,

"A4", Doc=3; expr_Doc,

"Tablet", Doc=4; expr_Doc,

"Email", Doc=5; expr_Doc

}

),

/* Define submenus */

<< set submenu( 1, 4),

<< set submenu( 6, 3),

<< set submenu(10, 5),

/* Set defaults */

<< set menu item state(2, 1),

<< set menu item state(7, 1),

<< set menu item state(11, 1)

);

 

new window("NW",

My_OutlineBox

);

 

1 ACCEPTED SOLUTION

Accepted Solutions
Justin_Chilton

Joined:

Aug 27, 2015

Solution

You are correct, there is not a JSL message for getting the index of the selected menu item, like <<Get Menu Choice for ButtonBox. For this reason, you will need to pass the index of the menu item to whatever method you are using to change the menu item states.

Instead of using three different expressions, as you have above, I would recommend using a function with three parameters. Using a function removes the need for the extraneous variables and also simplifies the process for adding new menu items later on and reduces code duplication. See my example below for details.

 

setMenuChecked = Function(
	{
		startIndexForSubgroup, 	// The index of the first menu item for this subgroup
		endIndexForSubgroup, 	// The index of the last menu item for this subgroup
		indexOfSelectedItem	// The index of the item that was just selected
	},
	{i},
	For( i = startIndexForSubgroup, i <= endIndexForSubgroup, i++,
		My_OutlineBox << set menu item state( i, 0 )
	);
	My_OutlineBox << set menu item state( indexOfSelectedItem, 1 );
);
 
My_OutlineBox = Outline Box( "My OutlineBox",
	Text Box( "Some stuff in the window" ),
	<<set menu script(
		{
		"Decimals", " ",
		"1 POD", setMenuChecked( 2, 5, 2 ),
		"2 POD", setMenuChecked( 2, 5, 3 ),
		"3 POD", setMenuChecked( 2, 5, 4 ),
		"4 POD", setMenuChecked( 2, 5, 5 ),
		"Recipient", " ",
		"R and D", setMenuChecked( 7, 9, 7 ),
		"Marketing", setMenuChecked( 7, 9, 8 ),
		"Pre-Sales", setMenuChecked( 7, 9, 9 ),
		"Document Format", " ",
		"Quarto", setMenuChecked( 11, 15, 11 ),
		"Foolscap", setMenuChecked( 11, 15, 12 ),
		"A4", setMenuChecked( 11, 15, 13 ),
		"Tablet", setMenuChecked( 11, 15, 14 ),
		"Email", setMenuChecked( 11, 15, 15 )
		}
	), 
/* Define submenus */
	<<set submenu( 1, 4 ),
	<<set submenu( 6, 3 ),
	<<set submenu( 10, 5 ), 
/* Set defaults */
	<<set menu item state( 2, 1 ),
	<<set menu item state( 7, 1 ),
	<<set menu item state( 11, 1 )
);
 
New Window( "NW", My_OutlineBox );
Justin
2 REPLIES
Justin_Chilton

Joined:

Aug 27, 2015

Solution

You are correct, there is not a JSL message for getting the index of the selected menu item, like <<Get Menu Choice for ButtonBox. For this reason, you will need to pass the index of the menu item to whatever method you are using to change the menu item states.

Instead of using three different expressions, as you have above, I would recommend using a function with three parameters. Using a function removes the need for the extraneous variables and also simplifies the process for adding new menu items later on and reduces code duplication. See my example below for details.

 

setMenuChecked = Function(
	{
		startIndexForSubgroup, 	// The index of the first menu item for this subgroup
		endIndexForSubgroup, 	// The index of the last menu item for this subgroup
		indexOfSelectedItem	// The index of the item that was just selected
	},
	{i},
	For( i = startIndexForSubgroup, i <= endIndexForSubgroup, i++,
		My_OutlineBox << set menu item state( i, 0 )
	);
	My_OutlineBox << set menu item state( indexOfSelectedItem, 1 );
);
 
My_OutlineBox = Outline Box( "My OutlineBox",
	Text Box( "Some stuff in the window" ),
	<<set menu script(
		{
		"Decimals", " ",
		"1 POD", setMenuChecked( 2, 5, 2 ),
		"2 POD", setMenuChecked( 2, 5, 3 ),
		"3 POD", setMenuChecked( 2, 5, 4 ),
		"4 POD", setMenuChecked( 2, 5, 5 ),
		"Recipient", " ",
		"R and D", setMenuChecked( 7, 9, 7 ),
		"Marketing", setMenuChecked( 7, 9, 8 ),
		"Pre-Sales", setMenuChecked( 7, 9, 9 ),
		"Document Format", " ",
		"Quarto", setMenuChecked( 11, 15, 11 ),
		"Foolscap", setMenuChecked( 11, 15, 12 ),
		"A4", setMenuChecked( 11, 15, 13 ),
		"Tablet", setMenuChecked( 11, 15, 14 ),
		"Email", setMenuChecked( 11, 15, 15 )
		}
	), 
/* Define submenus */
	<<set submenu( 1, 4 ),
	<<set submenu( 6, 3 ),
	<<set submenu( 10, 5 ), 
/* Set defaults */
	<<set menu item state( 2, 1 ),
	<<set menu item state( 7, 1 ),
	<<set menu item state( 11, 1 )
);
 
New Window( "NW", My_OutlineBox );
Justin
dqr2

Community Trekker

Joined:

Jun 19, 2015

Thanks Justin - I'll do that.  I've discovered a few times in the past that I've overlooked a property which resolves the issue, just because I didn't appreciate its relevance to the problem in hand - so it's good to know that I haven't missed something obvious on this occasion.

 

Many thanks for your help