From ca25dea2d826d1dad8d1db29cabe0cdb413eee00 Mon Sep 17 00:00:00 2001 From: Al Poole Date: Sun, 18 Mar 2018 11:29:10 +0000 Subject: [PATCH] statusbar: undo recursive dependency. Refactor and sanify the statusbar changes. --- src/bin/edi_content.c | 59 +++++++++-------- src/bin/edi_content.h | 13 +++- src/bin/editor/edi_editor.c | 96 +++++++++++++++++----------- src/bin/mainview/edi_mainview_item.h | 1 + 4 files changed, 106 insertions(+), 63 deletions(-) diff --git a/src/bin/edi_content.c b/src/bin/edi_content.c index 8ec31fb..aa86982 100644 --- a/src/bin/edi_content.c +++ b/src/bin/edi_content.c @@ -5,6 +5,7 @@ #include "language/edi_language_provider.h" #include "editor/edi_editor.h" #include "edi_content.h" +#include "mainview/edi_mainview.h" #include "edi_config.h" #include "edi_private.h" @@ -40,7 +41,6 @@ Evas_Object * edi_content_image_add(Evas_Object *parent, Edi_Mainview_Item *item) { Evas_Object *vbox, *box, *searchbar, *statusbar, *scroll, *img; - Edi_Editor *editor; vbox = elm_box_add(parent); evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -76,45 +76,52 @@ edi_content_image_add(Evas_Object *parent, Edi_Mainview_Item *item) evas_object_show(img); elm_box_pack_end(box, scroll); - editor = calloc(1, sizeof(*editor)); - editor->mimetype = item->mimetype; - edi_content_statusbar_add(statusbar, editor, item); + edi_content_statusbar_add(statusbar, item); + edi_content_statusbar_position_set(item->pos, 0, 0); return vbox; } -static void -_edit_cursor_moved(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) +void +edi_content_statusbar_position_set(Evas_Object *position, unsigned int line, unsigned int col) { - Elm_Code_Widget *widget; - char buf[30]; - unsigned int line; - unsigned int col; + char buf[64]; + char text[128]; + int i; - widget = (Elm_Code_Widget *)obj; - if (widget) + if (!position) return; + + if (line && col) { - elm_code_widget_cursor_position_get(widget, &line, &col); + snprintf(buf, sizeof(buf), _("Line: %d, Column: %d"), line, col); } else { - line = 0; col = 0; + buf[0] = 0x00; } - snprintf(buf, sizeof(buf), _("Line:%6d, Column:%4d"), line, col); + text[0] = 0x00; - elm_object_text_set((Evas_Object *)data, buf); + for (i = strlen(buf); i < 24; i++) + { + strcat(text, " "); + } + + strcat(text, buf); + + elm_object_text_set(position, text); } void -edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item) +edi_content_statusbar_add(Evas_Object *panel, Edi_Mainview_Item *item) { Edi_Language_Provider *provider; Evas_Object *table, *rect, *tb, *position, *mime; Elm_Code *code; char text[256]; const char *format, *spaces = " "; + const char *mimename = NULL; elm_box_horizontal_set(panel, EINA_TRUE); @@ -124,7 +131,8 @@ edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I evas_object_show(table); elm_box_pack_end(panel, table); - code = elm_code_widget_code_get(editor->entry); + code = elm_code_create(); + code->file = elm_code_file_open(code, item->path); if (code) { if (elm_code_file_line_ending_get(code->file) == ELM_CODE_FILE_LINE_ENDING_WINDOWS) @@ -137,6 +145,8 @@ edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I format = ""; } + elm_code_free(code); + mime = elm_entry_add(panel); elm_entry_editable_set(mime, EINA_FALSE); elm_entry_scrollable_set(mime, EINA_FALSE); @@ -144,10 +154,12 @@ edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I if (item->mimetype) { - provider = edi_language_provider_get(editor); - if (provider && provider->mime_name(item->mimetype)) + provider = edi_language_provider_for_mime_get(item->mimetype); + if (provider) + mimename = provider->mime_name(item->mimetype); + if (provider && mimename) { - snprintf(text, sizeof(text), "%s (%s)%s%s", provider->mime_name(item->mimetype), item->mimetype, spaces, format); + snprintf(text, sizeof(text), "%s (%s)%s%s", mimename, item->mimetype, spaces, format); } else { @@ -177,7 +189,7 @@ edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I elm_table_pack(table, tb, 0, 0, 1, 1); elm_table_pack(table, rect, 0, 0, 1, 1); - position = elm_entry_add(panel); + item->pos = position = elm_entry_add(panel); elm_entry_single_line_set(position, EINA_TRUE); elm_entry_text_style_user_push(position, "DEFAULT='font=Mono')"); elm_entry_editable_set(position, EINA_FALSE); @@ -185,8 +197,5 @@ edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_I evas_object_size_hint_weight_set(position, EVAS_HINT_EXPAND, 0.0); elm_table_pack(table, position, 1, 0, 1, 1); evas_object_show(position); - - _edit_cursor_moved(position, editor->entry, NULL); - evas_object_smart_callback_add(editor->entry, "cursor,changed", _edit_cursor_moved, position); } diff --git a/src/bin/edi_content.h b/src/bin/edi_content.h index ea5e620..50cac32 100644 --- a/src/bin/edi_content.h +++ b/src/bin/edi_content.h @@ -51,13 +51,22 @@ Evas_Object *edi_content_diff_add(Evas_Object *parent, Edi_Mainview_Item *item); * Add a statusbar to the panel for displaying statistics about loaded content. * * @param panel the panel in which the content resides and into which the statusbar is shown. - * @param editor the editor object. * @param item the item containing information about the file's content. * * @ingroup Content */ -void edi_content_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item); +void edi_content_statusbar_add(Evas_Object *panel, Edi_Mainview_Item *item); +/** + * Set the statusbar line information. + * + * @param position the object to render the statistics within the statusbar. + * @param line the line number to displsy. + * @param col the column position to display. + * + * @ingroup Content + */ +void edi_content_statusbar_position_set(Evas_Object *position, unsigned int line, unsigned int col); /** * @} */ diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c index 576dedc..a4c0c74 100644 --- a/src/bin/editor/edi_editor.c +++ b/src/bin/editor/edi_editor.c @@ -857,41 +857,6 @@ _smart_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, } } -static void -_edit_file_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - Edi_Editor *editor; - Edi_Language_Provider *provider; - char *word; - const char *snippet; - - ecore_event_add(EDI_EVENT_FILE_CHANGED, NULL, NULL, NULL); - - editor = (Edi_Editor *)data; - - _suggest_hint_hide(editor); - if (evas_object_visible_get(editor->suggest_bg)) - return; - - provider = edi_language_provider_get(editor); - if (!provider) - return; - - word = _edi_editor_current_word_get(editor); - - if (word && strlen(word) > 1) - { - snippet = provider->snippet_get(word); - if (snippet) - _suggest_hint_show_snippet(editor, word); - else if (strlen(word) >= 3) - _suggest_hint_show_match(editor, word); - } - - free(word); -} - - #if HAVE_LIBCLANG static void _edi_range_color_set(Edi_Editor *editor, Edi_Range range, Elm_Code_Token_Type type) @@ -1293,6 +1258,63 @@ edi_editor_reload(Edi_Editor *editor) ecore_thread_main_loop_end(); } +static void +_edit_cursor_moved(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) + { + Edi_Mainview_Item *item; + Elm_Code_Widget *widget; + unsigned int line; + unsigned int col; + + widget = (Elm_Code_Widget *)obj; + if (widget) + { + elm_code_widget_cursor_position_get(widget, &line, &col); + } + else + { + line = 0; col = 0; + } + + item = data; + + edi_content_statusbar_position_set(item->pos, line, col); +} + +static void +_edit_file_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Edi_Editor *editor; + Edi_Language_Provider *provider; + char *word; + const char *snippet; + + ecore_event_add(EDI_EVENT_FILE_CHANGED, NULL, NULL, NULL); + + editor = (Edi_Editor *)data; + + _suggest_hint_hide(editor); + if (evas_object_visible_get(editor->suggest_bg)) + return; + + provider = edi_language_provider_get(editor); + if (!provider) + return; + + word = _edi_editor_current_word_get(editor); + + if (word && strlen(word) > 1) + { + snippet = provider->snippet_get(word); + if (snippet) + _suggest_hint_show_snippet(editor, word); + else if (strlen(word) >= 3) + _suggest_hint_show_match(editor, word); + } + + free(word); +} + Evas_Object * edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) { @@ -1368,8 +1390,8 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) evas_object_show(widget); elm_box_pack_end(box, widget); + edi_content_statusbar_add(statusbar, item); edi_editor_search_add(searchbar, editor); - edi_content_statusbar_add(statusbar, editor, item); e = evas_object_evas_get(widget); ctrl = evas_key_modifier_mask_get(e, "Control"); @@ -1387,7 +1409,9 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item) ev_handler = ecore_event_handler_add(EDI_EVENT_CONFIG_CHANGED, _edi_editor_config_changed, widget); evas_object_event_callback_add(item->view, EVAS_CALLBACK_DEL, _editor_del_cb, ev_handler); + _edit_cursor_moved(item, editor->entry, NULL); evas_object_smart_callback_add(editor->entry, "changed,user", _edit_file_changed, editor); + evas_object_smart_callback_add(editor->entry, "cursor,changed", _edit_cursor_moved, item); if (edi_language_provider_has(editor)) { diff --git a/src/bin/mainview/edi_mainview_item.h b/src/bin/mainview/edi_mainview_item.h index 2d289c8..e752ac8 100644 --- a/src/bin/mainview/edi_mainview_item.h +++ b/src/bin/mainview/edi_mainview_item.h @@ -33,6 +33,7 @@ typedef struct _Edi_Mainview_Item /* Private */ Evas_Object *container; /**< The visual container that the item will display within */ + Evas_Object *pos; /**< The object pointing to the item's statusbar in the editor */ Eina_Bool loaded; } Edi_Mainview_Item;