Author Topic: How to change menu items based on file extension  (Read 3667 times)

byates

  • Senior Community Member
  • Posts: 105
  • Hero Points: 8
How to change menu items based on file extension
« on: February 13, 2007, 04:48:16 pm »
Does anyone know how to make a macro that can change the menu items for the 'Right Mouse Button' based on the file extension of the current buffer?  I would like to add (and remove) menu items as the file type changes.

Thanks!

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: How to change menu items based on file extension
« Reply #1 on: February 13, 2007, 06:48:22 pm »
You can configure your own context (right-click) menus for any file extension through Tools > Options > File Extension Setup > Advanced section.  In the Context Menu group, you can assign two menus, one for when you have an active selection and one without an active selection.  New menu resources are created using Macro > Menus..., create a new and assign items there.

byates

  • Senior Community Member
  • Posts: 105
  • Hero Points: 8
Re: How to change menu items based on file extension
« Reply #2 on: February 13, 2007, 07:51:36 pm »
Is there a way to do this programmatically?  I have a setup script (macro) that I use to configure SE each time there is a new version and I would like to make the menu changes part of that.

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: How to change menu items based on file extension
« Reply #3 on: February 13, 2007, 08:53:20 pm »
There is a way do it programmatic, but it falls into the advanced Slick-C programming category, and it's not very well documented part in the Slick-C programming guide (if at all).  If you look in macros\setupext.e, you'll see how a lot of file extension settings are set.  For the menus, in the function _extmenu_form_update_settings on line 3856 you see:

Code: [Select]
   int index=find_index('def-menu-'ext,MISC_TYPE);
   _str menu_name=real_menu_name(_menu_list.p_text,'');
   _str sel_menu_name=real_menu_name(_selection_menu_list.p_text,'S');
   if (index) {
      if (menu_name=='' && sel_menu_name=='') {
         delete_name(index);
      } else {
         set_name_info(index, menu_name','sel_menu_name);
      }
   }else{
      if (menu_name!='' || sel_menu_name!='') {
         index=insert_name('def-menu-'ext,MISC_TYPE,menu_name','sel_menu_name);
      }
   }

where ext is the name of the extension and menu_name and sel_menu_name are the name of the menu resources.

It's not a lot of code, but it can mess up your state file pretty quickly if you use improperly, so I'll add the standard warning of make a backup all your configuration files, use at your own risk, beware of dogs, etc...