From f50bff8e99ef64b37d9a353d1cfce2773e1f0a74 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 4 Apr 2015 17:51:39 +0100 Subject: [PATCH] editor: Add a tooltip popup if you hover over a line with a warning attached --- legacy/elm_code/src/lib/Makefile.am | 1 + legacy/elm_code/src/lib/elm_code_private.h | 7 +++ legacy/elm_code/src/lib/elm_code_widget.c | 14 +++++- .../src/lib/elm_code_widget_tooltip.c | 44 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 legacy/elm_code/src/lib/elm_code_widget_tooltip.c diff --git a/legacy/elm_code/src/lib/Makefile.am b/legacy/elm_code/src/lib/Makefile.am index 9885cbda58..0bd1a4ebf8 100644 --- a/legacy/elm_code/src/lib/Makefile.am +++ b/legacy/elm_code/src/lib/Makefile.am @@ -36,6 +36,7 @@ elm_code_text.c \ elm_code_file.c \ elm_code_parse.c \ elm_code_widget_text.c \ +elm_code_widget_tooltip.c \ elm_code_widget_selection.c \ elm_code_widget.c \ elm_code_diff_widget.c \ diff --git a/legacy/elm_code/src/lib/elm_code_private.h b/legacy/elm_code/src/lib/elm_code_private.h index 260d3ffc2d..57dae7c746 100644 --- a/legacy/elm_code/src/lib/elm_code_private.h +++ b/legacy/elm_code/src/lib/elm_code_private.h @@ -50,6 +50,7 @@ typedef struct Eina_Bool show_whitespace; Elm_Code_Widget_Selection_Data *selection; + Evas_Object *tooltip; } Elm_Code_Widget_Data; /* Private parser callbacks */ @@ -59,3 +60,9 @@ void _elm_code_parse_setup(); void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line *line); void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file); + +/* Private widget methods */ + +void _elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text); + +void _elm_code_widget_tooltip_add(Evas_Object *widget); diff --git a/legacy/elm_code/src/lib/elm_code_widget.c b/legacy/elm_code/src/lib/elm_code_widget.c index 0d131e53ae..a7c6a00691 100644 --- a/legacy/elm_code/src/lib/elm_code_widget.c +++ b/legacy/elm_code/src/lib/elm_code_widget.c @@ -672,19 +672,28 @@ _elm_code_widget_mouse_move_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj { Elm_Code_Widget *widget; Elm_Code_Widget_Data *pd; + Elm_Code_Line *line; Evas_Event_Mouse_Move *event; unsigned int row; int col; + Eina_Bool hasline; widget = (Elm_Code_Widget *)data; pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); event = (Evas_Event_Mouse_Move *)event_info; + hasline = _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); + if (!hasline) + _elm_code_widget_tooltip_text_set(widget, NULL); + else + { + line = elm_code_file_line_get(pd->code->file, row); + _elm_code_widget_tooltip_text_set(widget, line->status_text); + } + if (!pd->editable || !pd->selection || !event->buttons) return; - _elm_code_widget_position_at_coordinates_get(widget, pd, event->cur.canvas.x, event->cur.canvas.y, &row, &col); - elm_code_widget_selection_end(widget, row, col); } @@ -1360,6 +1369,7 @@ _elm_code_widget_evas_object_smart_add(Eo *obj, Elm_Code_Widget_Data *pd) evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(grid); + _elm_code_widget_tooltip_add(obj); elm_object_content_set(scroller, grid); pd->grid = grid; _elm_code_widget_setup_palette(grid); diff --git a/legacy/elm_code/src/lib/elm_code_widget_tooltip.c b/legacy/elm_code/src/lib/elm_code_widget_tooltip.c new file mode 100644 index 0000000000..18bee520e1 --- /dev/null +++ b/legacy/elm_code/src/lib/elm_code_widget_tooltip.c @@ -0,0 +1,44 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include "Elm_Code.h" + +#include "elm_code_private.h" + +void +_elm_code_widget_tooltip_text_set(Evas_Object *widget, const char *text) +{ + Elm_Code_Widget_Data *pd; + + pd = eo_data_scope_get(widget, ELM_CODE_WIDGET_CLASS); + + if (!text) + elm_object_tooltip_hide(widget); + else + elm_object_tooltip_show(widget); + + if (pd->tooltip) // will have been created by the callback below... + elm_object_text_set(pd->tooltip, text); +} + +static Evas_Object * +_elm_code_widget_tooltip_cb(void *data EINA_UNUSED, Evas_Object *obj, Evas_Object *tooltip) +{ + Elm_Code_Widget_Data *pd; + Evas_Object *label; + + pd = eo_data_scope_get(obj, ELM_CODE_WIDGET_CLASS); + + label = elm_label_add(tooltip); + pd->tooltip = label; + + return label; +} + +void +_elm_code_widget_tooltip_add(Evas_Object *widget) +{ + elm_object_tooltip_content_cb_set(widget, _elm_code_widget_tooltip_cb, NULL, NULL); +} +