Author Topic: toolbar-sensitive hotkeys?  (Read 4401 times)

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
toolbar-sensitive hotkeys?
« on: April 03, 2014, 05:54:40 PM »
Hi everyone,

I want to be able to map keys in slick edit to specific commands when a certain tool bar is active. Is this possible somehow?

For example, if the bookmarks toolbar is active (I have mapped to A-T k), I want to be able to create a new bookmark at the current location in the editor by just pressing 'n'.

This would be tremendously useful, not just for my simple example but for various toolbars and their different
options, instead of having to go to the mouse each time I want to click on the particular option I want from
the active toolbar.

Ted

MindprisM

  • Senior Community Member
  • Posts: 127
  • Hero Points: 8
Re: toolbar-sensitive hotkeys?
« Reply #1 on: May 28, 2014, 11:33:00 AM »
You would have to program the toolbar form. So you have to know some slick-c language to do so, but it is possible.

Graeme

  • Senior Community Member
  • Posts: 2827
  • Hero Points: 347
Re: toolbar-sensitive hotkeys?
« Reply #2 on: May 28, 2014, 12:44:17 PM »
In the case of the bookmarks toolwindow, slickedit will "import" your relevant keybindings for you so that if you have say F5 bound to "set-bookmark", then when the bookmarks tool window has focus, F5 will still set a bookmark on the current source window line.
The bookmarks tool window also has some "secret" key bindings  - INS actually does set-bookmark.
Code: [Select]
void ctl_bookmarks_tree.INS()
{
   if (!_no_child_windows()) {
      _mdi.p_child.set_bookmark("-n");
   }
}

You can add your own "hotkeys" either dynamically or statically but you need to check they're not already assigned.

Here's an example from slick source code on how to do it dynamically

Code: [Select]
/**
 * Make the current form respond to the keys to control the preview window
 */
void _MakePreviewWindowShortcuts()
{
   set_eventtab_index(p_eventtab, event2index(C_UP),   find_index("preview_cursor_up",   COMMAND_TYPE));
   set_eventtab_index(p_eventtab, event2index(C_DOWN), find_index("preview_cursor_down", COMMAND_TYPE));
   set_eventtab_index(p_eventtab, event2index(C_PGUP), find_index("preview_page_up",     COMMAND_TYPE));
   set_eventtab_index(p_eventtab, event2index(C_PGDN), find_index("preview_page_down",   COMMAND_TYPE));
}


Then in tags.e it does this
p_active_form._MakePreviewWindowShortcuts();
- this allows the preview window to be scrolled up down using Ctrl-up / down etc when the focus is on another form.

To assign keys statically you can do this kind of thing - this code can go in a slick c file of your own - make sure you #include "slick.sh"

Code: [Select]
 
defeventtab _tbbookmarks_form;
void ctl_bookmarks_tree."n","N"()
{
   if (!_no_child_windows()) {
      _mdi.p_child.set_bookmark('-n');
   }
}

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Re: toolbar-sensitive hotkeys?
« Reply #3 on: August 01, 2014, 08:06:54 PM »
Thanks Graeme that worked nicely. I have only tried assigning the new hotkey statically. It worked well for the bookmarks form, but when I tried to do it for the annotations, I get the following error:

Code: [Select]

This property or method is not allowed on this object
toolbar_sensitive.ex 80 _tbannotations_browser_form._annotation_tree.n()   p_window_id: 262   p_object: OI_TREE_VIEW   p_name: _annotation_tree

This is the Slick-C code I'm trying for annotations
Code: [Select]

defeventtab _tbannotations_browser_form
void _annotation_tree."n","N"()
{
   if (!_no_child_windows()) {
      _mdi.p_child.new_annotation(p_buf_name);
   }
}

« Last Edit: August 01, 2014, 08:41:04 PM by flethuseo »

Graeme

  • Senior Community Member
  • Posts: 2827
  • Hero Points: 347
Re: toolbar-sensitive hotkeys?
« Reply #4 on: August 01, 2014, 10:22:32 PM »
Try this

Code: [Select]
defeventtab _tbannotations_browser_form;
void _annotation_tree."n","N"()
{
   if (!_no_child_windows()) {
      _mdi.p_child.new_annotation(_mdi.p_child.p_buf_name);
   }
}

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Re: toolbar-sensitive hotkeys?
« Reply #5 on: August 04, 2014, 02:40:09 PM »
It worked Graeme, Thank you. Why do I not get context help when typing:
_mdi. OR
_mdi.p_child. ?
« Last Edit: August 04, 2014, 03:28:41 PM by flethuseo »

Graeme

  • Senior Community Member
  • Posts: 2827
  • Hero Points: 347
Re: toolbar-sensitive hotkeys?
« Reply #6 on: August 04, 2014, 10:42:55 PM »
It worked Graeme, Thank you. Why do I not get context help when typing:
_mdi. OR
_mdi.p_child. ?

That's a very good question.  The SlickC parser and interpreter allow integer values to be de-referenced and treat them as window numbers, using some kind of internal numbering.  You can see that _mdi is defined in slick.sh as the value 3.  I guess that Slick C code help doesn't have the ability to determine that "integer expression". should have a type of "window object" and bring up a list of window properties/ methods. 

You can see that p_child is defined in builtins.e - but a comment at the top of the builtins.e file says that the file cannot be compiled by the slick C compiler - it exists only to support context tagging.  So the slick C parser happily compiles _mdi.p_child.whatever ostensibly without knowing what p_child is and leaves it to the interpreter to figure out.  However, if you type p_childs instead of p_child, the compiler complains  - or if you do int x = p_ch; you get "property misspelled or invalid identifier" so it seems to treat p_anything as a potential property ID and checks against a list of internal property names.