Commit 1dc05b9b authored by Christian Persch's avatar Christian Persch

widget: Add function to check for match at event coordinates

This saves the caller from translating from event coordinates to
grid coordinates himself.
parent a0402e6b
......@@ -60,6 +60,7 @@ vte_terminal_match_add_gregex
vte_terminal_match_remove
vte_terminal_match_remove_all
vte_terminal_match_check
vte_terminal_match_check_event
vte_terminal_match_set_cursor
vte_terminal_match_set_cursor_type
vte_terminal_match_set_cursor_name
......
......@@ -216,6 +216,8 @@ if ENABLE_TEST_APPLICATION
bin_PROGRAMS = vte-@VTE_API_MAJOR_VERSION@.@VTE_API_MINOR_VERSION@
vte-@VTE_API_MAJOR_VERSION@.@VTE_API_MINOR_VERSION@: vte-$(VTE_API_VERSION).vapi
vte_@VTE_API_MAJOR_VERSION@_@VTE_API_MINOR_VERSION@_SOURCES = \
app.vala \
config.vapi \
......@@ -229,7 +231,6 @@ vte_@VTE_API_MAJOR_VERSION@_@VTE_API_MINOR_VERSION@_VALAFLAGS = \
--vapidir=. \
--girdir=. \
--pkg=posix \
--pkg=linux \
--pkg=gio-2.0 \
--pkg=gtk+-$(GTK_API_VERSION) \
--pkg=vte-$(VTE_API_VERSION) \
......
......@@ -356,12 +356,7 @@ class Window : Gtk.ApplicationWindow
if (App.Options.no_context_menu)
return false;
var padding = get_style_context().get_padding(get_state_flags());
var char_width = terminal.get_char_width();
var char_height = terminal.get_char_height();
var match = terminal.match_check(((int)event.x - padding.left) / (int)char_width,
((int)event.y - padding.top) / (int)char_height,
null);
var match = terminal.match_check_event(event, null);
var menu = new GLib.Menu();
menu.append("_Copy", "win.copy");
......
......@@ -1709,6 +1709,46 @@ vte_terminal_match_check(VteTerminal *terminal, glong column, glong row,
return ret;
}
/**
* vte_terminal_match_check_event:
* @terminal: a #VteTerminal
* @event: a #GdkEvent
* @tag: (out) (allow-none): a location to store the tag, or %NULL
*
* Checks if the text in and around the position of the event matches any of the
* regular expressions previously set using vte_terminal_match_add(). If a
* match exists, the text string is returned and if @tag is not %NULL, the number
* associated with the matched regular expression will be stored in @tag.
*
* If more than one regular expression has been set with
* vte_terminal_match_add(), then expressions are checked in the order in
* which they were added.
*
* Returns: (transfer full): a newly allocated string which matches one of the previously
* set regular expressions
*/
char *
vte_terminal_match_check_event(VteTerminal *terminal,
GdkEvent *event,
int *tag)
{
double x, y;
long col, row;
g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
if (event == NULL)
return FALSE;
if (((GdkEventAny*)event)->window != gtk_widget_get_window(&terminal->widget))
return FALSE;
if (!gdk_event_get_coords(event, &x, &y))
return FALSE;
if (!_vte_terminal_xy_to_grid(terminal, x, y, &col, &row))
return FALSE;
return vte_terminal_match_check(terminal, col, row, tag);
}
/* Emit an adjustment changed signal on our adjustment object. */
static void
vte_terminal_emit_adjustment_changed(VteTerminal *terminal)
......
......@@ -340,6 +340,9 @@ void vte_terminal_match_remove_all(VteTerminal *terminal);
char *vte_terminal_match_check(VteTerminal *terminal,
glong column, glong row,
int *tag);
char *vte_terminal_match_check_event(VteTerminal *terminal,
GdkEvent *event,
int *tag);
void vte_terminal_search_set_gregex (VteTerminal *terminal,
GRegex *regex,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment