Prevent automatic close of context menu

Answered (Verified) This post has 1 verified answer and 3 replies

Not Ranked
Posts: 15
dilbgmbh Posted: Wed Jan 20, 2010 @ 6:23 AM
Hi,

I made a toolbar with a icon where a contextmenu is shown by click. In the contextmenu I have several items. By clicking on one of these items, I want the item to be removed.

function meDoks_OnItemClose(sender,index)
{                
   meDoks.get_items().remove(index);
}   

The remove seems not to work, but when I close the contextmenu and reopen it, the items are removed. To prevent this effect, I modified the code:

function meDoks_OnItemClose(sender,index)
{                
  meDoks.beginUpdate();
  meDoks.get_items().remove(index);
  meDoks.endUpdate();
}   
Now I have another problem. The contextmenu closes automatically and I have to reopen it to remove the next item.

Is ist possible to remove serval items and keep the contextmenu open?

Answered (Verified) Verified Answer

Top 10 Contributor
Posts: 1,454
Answered (Verified) harish Posted: Thu Jan 21, 2010 @ 5:35 AM
Verified by admin

Hello,

 

Thank you for getting back to me.

 

I am glad that you have figure out implementation for your requirement. In case if you have any issue, please refer the attached sample where the similar implementation has been applied using the context menu on tree menu item.

 

Hope it helps you.

 

Thank you

Harish Malhotra

 

All Replies

Top 10 Contributor
Posts: 1,454
harish Posted: Wed Jan 20, 2010 @ 8:41 AM

Hello,

 

Thank you for submitting your query with ComponentArt forum.

 

It seems that you want to make changes to the context menu control using beginUpdate and endUpdate without closing the menu.

 

Unfortunately, this behavior is not supported by the Menu control. In order to show the changes, it is necessary that menu control to redraw itself which is done automatically when you use control’s beginUpdate and endUpdate.

 

However as a workaround you can open the same context menu automatically, by using showContextMenuAtPoint() client side method of the Menu just after your endUpdate().

In case if you are using the ItemSelect client side event of menu to achieve this, you need to cancel this event by using set_cancel on the event argument to restrict the closing of menu.

 

For example:

function Menu_onItemSelect(sender, eventArgs)
{
..
..
sender.beginUpdate();
sender.get_items().remove(itemIndex_to_remove);
sender.endUpdate();

// you need to store the cordinates x,y using as global varibale 
// according to your implementation of opening of context menu

sender.showContextMenuAtPoint(x, y, contextDataNode);
eventArgs.set_cancel(true);
}

Hope it helps you.

Thank you.

Harish Malhotra

 

Not Ranked
Posts: 15
dilbgmbh Posted: Thu Jan 21, 2010 @ 12:20 AM
Thanks for your help. I tried similar solutions, but nothing worked beautiful. In your solution I have problems to get the right cordinates, because I open the menu in this way:
function tbMenu_OnItemSelect(sender, eventArgs)
{        
  var e = eventArgs.get_event();        
  var n = eventArgs.get_item(); 
  if (n.getProperty("conMenu")=="1")
  {
     meDoks.showContextMenu(e,n);
   }
   else
   {
      //Aktion
   }
}
A toolbar items have not the cool getX oder getY proberties like the treeview item. When I use e.screenX or e.screenY in this example to save x and y, the menu doesn't appear on the correct position.

I found a workaround for the problem. When I click on the close-button (it is inside of a client template) only the parent-div-element is set to display none. The real remove of the item is done, when the menu hides.
var close_array = new Array();    

function meDoks_OnItemClose(sender,id)
{                
  sender.parentNode.style.display = "none";
  close_array.push(id);   
} 
function meDoks_OnContextMenuHide(sender,eventArgs)
{
  var collection = meDoks.get_items();
  var id;
  meDoks.beginUpdate();
  while(id = close_array.pop())
  {     
      collection.remove(collection.getItemById(id).get_index());
   }
   meDoks.endUpdate();
}   
Top 10 Contributor
Posts: 1,454
Answered (Verified) harish Posted: Thu Jan 21, 2010 @ 5:35 AM
Verified by admin

Hello,

 

Thank you for getting back to me.

 

I am glad that you have figure out implementation for your requirement. In case if you have any issue, please refer the attached sample where the similar implementation has been applied using the context menu on tree menu item.

 

Hope it helps you.

 

Thank you

Harish Malhotra

 

Page 1 of 1 (4 items)