Author Topic: Menu Customization Issue  (Read 13173 times)

bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Menu Customization Issue
« on: May 05, 2008, 07:02:15 PM »
Ryan,

    I am having some trouble adding items to a customizable menu. I am able to do this through the IDE, but would like to automate additions for our users here. Here is what I am trying to do following the example you pointed me to from bufftabs.e. But this code is not altering the menu as expected. Is there something, like a _menu_save command that I am missing? Here is the code:

Code: [Select]
   
#import "setupext.e"
_command void test_menu_add()
{
   //load the SELECT MENU
   int index=find_index(SEL_MENU,oi2type(OI_MENU));
   //return if menu not found
   if (!index) {
      _message_box("cannot find: " SEL_MENU);
         return;
   }   
   int menu_hndl =  p_active_form._menu_load(index);
   int foundpos, edit_handle, edit_handle_pos;
   _menu_find(menu_hndl, "open-menu _ext_menu_default_sel", edit_handle, edit_handle_pos, "M");
   _message_box(menu_hndl " : " edit_handle);
   _menu_insert(menu_hndl,23,0,'-');
   _message_box(edit_handle_pos);
   _menu_show(menu_hndl);
   _menu_destroy(menu_hndl);
}

Thanks,
Rob

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Menu Customization Issue
« Reply #1 on: May 06, 2008, 02:13:35 PM »
Code: [Select]
_command void test_menu_add()
{
   //load the SELECT MENU
   int index=find_index(SEL_MENU,oi2type(OI_MENU));
   //return if menu not found
   if (!index) {
      say("cannot find: " SEL_MENU);
      return;
   }
   int menu_hndl=p_active_form._menu_load(index,'P');
   int foundpos, edit_handle, edit_handle_pos;
   _menu_find(menu_hndl, "open-menu _ext_menu_default_sel", edit_handle, edit_handle_pos, "M");
   _menu_insert(menu_hndl,edit_handle_pos,0,'HERE I AM');
   int x,y;
   mou_get_xy(x,y);
   _menu_show(menu_hndl,VPM_RIGHTBUTTON,x-1,y-1);
   _menu_destroy(menu_hndl);
}

The only things I changed were to show the menu at a more appropriate place (near the mouse :)), not hardcode the value for menu_pos in the call to _menu_insert, and change the modification to be something a little more obvious than a separator :).  This works for me...the menu displays with my modification.

Is this not working for you?

Now, just to be clear, this is only modifying this particular menu for the menu handle that you have created...once that menu is destroyed these modifications go away.  This is why, when you do your customizations (outside of this testing function) you want to do them in an _on_popup event or in some rbutton_up handler, so that they are done dynamically.

Does this make sense?

- Ryan

bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Re: Menu Customization Issue
« Reply #2 on: May 07, 2008, 03:36:26 PM »
Ryan,

   The code works great, thanks! Now, what I would like to do is persist these menu changes, just like the functionality of the Edit this Menu...[\b] option does. What's the process to do that?

Thanks,
Rob

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Menu Customization Issue
« Reply #3 on: May 07, 2008, 03:43:35 PM »
You need to modify the menu dynamically, as it is shown.  As previously stated, you can do this with an _on_popup_MENUNAME function or an rbutton_up event for the form in which the menu will be shown.

Check out _on_popup_ext_menu_default...it's how we remove the version control items from the context menu in the editor.  Should give you a good start.

- Ryan

bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Re: Menu Customization Issue
« Reply #4 on: May 07, 2008, 04:20:55 PM »
Alright, I guess I didn't understand you completely the first time. So am I right to assume that when i do the menu update through the GUI that it updates the the rbutton_up handler somewhere and I can re-use some of that code? Also, is there a way to update the rbutton_up command based on the mode, or is that something I will have to implement using some kind of conditional/test?

Thanks,
Rob

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Menu Customization Issue
« Reply #5 on: May 07, 2008, 06:06:59 PM »
Actually, that's another mechanism :).  When you edit via the GUI with "Edit This Menu", your menu customizations get stored as full menu definitions in vusrsXXX.e in your config directory.  If you open up that file, you will see what I mean.

Quote
Also, is there a way to update the rbutton_up command based on the mode, or is that something I will have to implement using some kind of conditional/test?

Are you asking if there is a way to have a different context menu based on the language mode?  Like, a different menu for a different language?  That option is in File Extension Options under Advanced, for the language you are interested in.  If you define a menu it should be in the combo box under "Context menus."  Does this help?

- Ryan

bercikr

  • Community Member
  • Posts: 45
  • Hero Points: 2
Re: Menu Customization Issue
« Reply #6 on: May 07, 2008, 06:17:03 PM »
Yeah, it does help quite a bit. I had an idea that these menus were written to files so that's why I was asking about persisting my changes earlier. Is it possible to just edit those files using Slick-c and then reload the menus? This would be useful for 'global' commands i would like to share between languages. Also for language specific menus, is there a command to update those via Slick-C or will that need to be done via the GUI?

thanks,
Rob

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 986
  • Hero Points: 77
Re: Menu Customization Issue
« Reply #7 on: May 07, 2008, 06:56:58 PM »
If you just wanted to define your menus in SlickC I would just use the GUI.  Use Macro > Menus > New to define a new one (which will get saved in vusrobjs.e).  Only the modifications to existing menus get saved in vusrsXXXX.e, and you can use the GUI for these, too.

I'm not sure if editting vusrsXXXX.e manually will work out because SlickEdit is writing the entire menu definition to that file, not just a delta.

- Ryan