Author Topic: In timer callback, p_buf_name is ".command"  (Read 1913 times)

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
In timer callback, p_buf_name is ".command"
« on: October 06, 2018, 06:26:34 PM »
When I try to get the current active buffer (by saving p_buf_name) in a timer callback, it returns ".command".

This is not helpful because in the timer callback, I sometimes activate a tool window (Output window), but then I want to restore focus to the active buffer that is under edit. So before activating the tool window, I save p_bufname (origBuf = p_bufname), then activate the tool window, then when I call "edit(origBuf)" I end up seeing the .command buffer instead of the real active buffer.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: In timer callback, p_buf_name is ".command"
« Reply #1 on: October 06, 2018, 08:54:57 PM »
Try _mdi.p_child.p_buf_name
Also call _no_child_windows to check if there is at least one buffer.

Also see this tip from Clark
https://community.slickedit.com/index.php/topic,15962.msg61149.html#msg61149

Another thing to consider is killing the timer when the module is loaded e.g.

Code: [Select]
void _on_load_module_xretrace(_str module_name)
{
   _str sm = strip(module_name, "B", "\'\"");
   if (strip_filename(sm, 'PD') == 'xretrace.e') {
      xretrace_kill_timer();
      xretrace_clear_all_markers();
   }
}

static void retrace_timer_callback2()
{
   if (!_use_timers || retrace_timer_handle < 0)
      return;
// ...

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
Re: In timer callback, p_buf_name is ".command"
« Reply #2 on: October 07, 2018, 03:34:38 PM »
Thanks Graeme! _mdi.p_child.p_buf_name worked!

I'd like to get an explanation from SlickTeam why p_buf_name doesn't work here while _mdi.p_child.p_buf_name  does.

As far as killing a timer on module load, in my case I'm not starting a timer on module load so that is a moot point for me. My timer only gets started when I invoke a macro.

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: In timer callback, p_buf_name is ".command"
« Reply #3 on: October 07, 2018, 07:44:27 PM »
The reason that unqualified p_buf_name doesn't work is that the active window at the point you call it is not an edit buffer.  _mdi is a constant but slick manages to resolve it to the main window.  If you have any floating edit buffers, slick stll manages to resolve _mdi.p_child.p_buf_name to the active edit buffer whether it's floating or in the main window.