[code] [textadept] double-click tab bar event handling

From: Gabriel Dubatti <gdubatti.att.gmail.com>
Date: Mon, 04 May 2015 22:40:29 -0300

Hi everyone,

     I made a little change to allow closing a file double-clicking in
its tab.
     I really missed that feature.
     Here it is, in case someone find it useful.

----
     In textadept.c @ line 1860 edit "t_tabbuttonpress" function:
/** Signal for a tabbar mouse click. */
static int t_tabbuttonpress(GtkWidget*_, GdkEventButton *event, void*__) {
*if ((event->type != GDK_BUTTON_PRESS || event->button != 3) && **
**      (event->type != GDK_2BUTTON_PRESS || event->button != 1)) {**
**    return FALSE;**
**  }*
   GtkNotebook *tabs = GTK_NOTEBOOK(tabbar);
   for (int i = 0; i < gtk_notebook_get_n_pages(tabs); i++) {
     GtkWidget *page = gtk_notebook_get_nth_page(tabs, i);
     GtkWidget *label = gtk_notebook_get_tab_label(tabs, page);
     int x0, y0;
     gdk_window_get_origin(gtk_widget_get_window(label), &x0, &y0);
     GtkAllocation allocation;
     gtk_widget_get_allocation(label, &allocation);
     if (event->x_root > x0 + allocation.x + allocation.width) continue;
     gtk_notebook_set_current_page(tabs, i);
*if (event->type == GDK_BUTTON_PRESS) {**
**      //left-click**
**      return (lL_showcontextmenu(lua, (void *)event, 
"tab_context_menu"), TRUE);**
**    }**
**    //double-click**
**    lL_event(lua, "tab_double_click", -1);**
**    return TRUE;*
   }
   return FALSE;
}
(obviously this requires recompiling textadept)
------------
     In core/events.lua @ line 356 add the new event to the list:
local ta_events = {
   'appleevent_odoc', 'buffer_after_switch', 'buffer_before_switch',
   'buffer_deleted', 'buffer_new', 'csi', 'error', 'find', 'focus',
   'initialized', 'keypress', 'menu_clicked', 'mouse', 'quit', 'replace',
   'replace_all', 'reset_after', 'reset_before', 'resume', 'suspend',
*'tab_double_click',*
   'view_after_switch', 'view_before_switch', 'view_new'
}
--------------
     Finally, connect it in your init.lua:
*events.connect(events.TAB_DOUBLE_CLICK, function() io.close_buffer() end)*
--------------
     Mitchell, It would be great if you could add this small changes to 
your code base.
     Thanks in advance.
     Best wishes,
     Gabriel
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 04 May 2015 - 21:40:29 EDT

This archive was generated by hypermail 2.2.0 : Tue 05 May 2015 - 06:44:28 EDT