2014-05-15 14:40:19 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
#include <Eina.h>
|
2014-05-15 15:25:25 -07:00
|
|
|
#include <Elementary.h>
|
2014-05-15 14:40:19 -07:00
|
|
|
|
|
|
|
#include "edi_editor.h"
|
|
|
|
|
2014-10-08 16:06:55 -07:00
|
|
|
#define CLANG_DEBUG 0
|
|
|
|
#if CLANG_DEBUG
|
|
|
|
#include "clang_debug.h"
|
|
|
|
#endif
|
|
|
|
|
2014-09-13 08:48:16 -07:00
|
|
|
#include "mainview/edi_mainview.h"
|
2014-12-01 14:54:17 -08:00
|
|
|
#include "edi_config.h"
|
2014-05-15 14:40:19 -07:00
|
|
|
|
|
|
|
#include "edi_private.h"
|
|
|
|
|
2015-02-15 09:53:00 -08:00
|
|
|
#if HAVE_LIBCLANG
|
|
|
|
|
2014-10-08 16:06:55 -07:00
|
|
|
#define Edi_Color const char *
|
|
|
|
|
2014-10-21 06:26:01 -07:00
|
|
|
static Edi_Color EDI_COLOR_FOREGROUND = "<color=#ffffff>";
|
|
|
|
static Edi_Color EDI_COLOR_COMMENT = "<color=#3399ff>";
|
2014-11-13 13:35:58 -08:00
|
|
|
static Edi_Color EDI_COLOR_STRING = "<color=#ff5a35>";
|
2014-10-21 06:26:01 -07:00
|
|
|
static Edi_Color EDI_COLOR_NUMBER = "<color=#D4D42A>";// font_weight=Bold";
|
|
|
|
static Edi_Color EDI_COLOR_BRACE = "<color=#656565>";
|
|
|
|
static Edi_Color EDI_COLOR_TYPE = "<color=#3399ff>";
|
|
|
|
static Edi_Color EDI_COLOR_CLASS = "<color=#72AAD4>";// font_weight=Bold";
|
|
|
|
static Edi_Color EDI_COLOR_FUNCTION = "<color=#72AAD4>";// font_weight=Bold";
|
2014-10-22 12:08:57 -07:00
|
|
|
//static Edi_Color EDI_COLOR_PARAM = "<color=#ffffff>";
|
2014-10-21 06:26:01 -07:00
|
|
|
static Edi_Color EDI_COLOR_KEYWORD = "<color=#ff9900>";// font_weight=Bold";
|
|
|
|
static Edi_Color EDI_COLOR_PREPROCESSOR = "<color=#00B000>";
|
|
|
|
|
2014-10-22 14:43:32 -07:00
|
|
|
static Edi_Color EDI_COLOR_BACKGROUND = "<backing_color=#000000>";
|
2014-10-21 06:26:01 -07:00
|
|
|
static Edi_Color EDI_COLOR_SEVIRITY_IGNORED = "<backing_color=#000000>";
|
|
|
|
static Edi_Color EDI_COLOR_SEVIRITY_NOTE = "<backing_color=#ff9900>";
|
|
|
|
static Edi_Color EDI_COLOR_SEVIRITY_WARNING = "<backing_color=#ff9900>";
|
2014-10-10 05:43:54 -07:00
|
|
|
|
2015-02-15 09:53:00 -08:00
|
|
|
#endif
|
|
|
|
|
2014-12-01 14:54:17 -08:00
|
|
|
static char *_default_font;
|
|
|
|
|
2014-10-08 16:06:55 -07:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned int line;
|
|
|
|
unsigned int col;
|
|
|
|
} Edi_Location;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
Edi_Location start;
|
|
|
|
Edi_Location end;
|
|
|
|
} Edi_Range;
|
|
|
|
|
2014-06-15 14:54:08 -07:00
|
|
|
static void
|
|
|
|
_update_lines(Edi_Editor *editor);
|
|
|
|
|
2014-11-30 08:25:11 -08:00
|
|
|
static void
|
|
|
|
_update_highlight(Edi_Editor *editor);
|
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
static void
|
|
|
|
_reset_highlight(Edi_Editor *editor);
|
|
|
|
|
2015-02-08 15:21:27 -08:00
|
|
|
void
|
|
|
|
edi_editor_save(Edi_Editor *editor)
|
|
|
|
{
|
2015-02-14 15:55:05 -08:00
|
|
|
if (!editor->modified)
|
|
|
|
return;
|
|
|
|
|
|
|
|
editor->save_time = time(NULL);
|
2015-02-08 15:21:27 -08:00
|
|
|
edi_mainview_save();
|
|
|
|
_reset_highlight(editor);
|
|
|
|
|
|
|
|
editor->modified = EINA_FALSE;
|
|
|
|
|
|
|
|
ecore_timer_del(editor->save_timer);
|
|
|
|
editor->save_timer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_edi_editor_autosave_cb(void *data)
|
|
|
|
{
|
|
|
|
Edi_Editor *editor;
|
|
|
|
|
|
|
|
editor = (Edi_Editor *)data;
|
|
|
|
|
|
|
|
edi_editor_save(editor);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-01 14:54:17 -08:00
|
|
|
static const char *
|
|
|
|
_edi_editor_font_get()
|
|
|
|
{
|
|
|
|
char *format;
|
|
|
|
|
|
|
|
if (_default_font)
|
|
|
|
return _default_font;
|
|
|
|
|
|
|
|
format = "DEFAULT='font=Monospace font_size=%d'";
|
|
|
|
|
|
|
|
_default_font = malloc(sizeof(char) * (strlen(format) + 4));
|
|
|
|
snprintf(_default_font, strlen(format) + 4, format, _edi_cfg->font.size);
|
|
|
|
return _default_font;
|
|
|
|
}
|
|
|
|
|
2014-05-15 15:25:25 -07:00
|
|
|
static void
|
|
|
|
_undo_do(Edi_Editor *editor, Elm_Entry_Change_Info *inf)
|
|
|
|
{
|
|
|
|
if (inf->insert)
|
|
|
|
{
|
|
|
|
const Evas_Object *tb = elm_entry_textblock_get(editor->entry);
|
|
|
|
Evas_Textblock_Cursor *mcur, *end;
|
|
|
|
mcur = (Evas_Textblock_Cursor *) evas_object_textblock_cursor_get(tb);
|
|
|
|
end = evas_object_textblock_cursor_new(tb);
|
|
|
|
|
|
|
|
if (inf->insert)
|
|
|
|
{
|
|
|
|
elm_entry_cursor_pos_set(editor->entry, inf->change.insert.pos);
|
|
|
|
evas_textblock_cursor_pos_set(end, inf->change.insert.pos +
|
|
|
|
inf->change.insert.plain_length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
elm_entry_cursor_pos_set(editor->entry, inf->change.del.start);
|
|
|
|
evas_textblock_cursor_pos_set(end, inf->change.del.end);
|
|
|
|
}
|
|
|
|
|
|
|
|
evas_textblock_cursor_range_delete(mcur, end);
|
|
|
|
evas_textblock_cursor_free(end);
|
|
|
|
elm_entry_calc_force(editor->entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (inf->insert)
|
|
|
|
{
|
|
|
|
elm_entry_cursor_pos_set(editor->entry, inf->change.insert.pos);
|
|
|
|
elm_entry_entry_insert(editor->entry, inf->change.insert.content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t start;
|
|
|
|
start = (inf->change.del.start < inf->change.del.end) ?
|
|
|
|
inf->change.del.start : inf->change.del.end;
|
|
|
|
|
|
|
|
elm_entry_cursor_pos_set(editor->entry, start);
|
|
|
|
elm_entry_entry_insert(editor->entry, inf->change.insert.content);
|
|
|
|
elm_entry_cursor_pos_set(editor->entry, inf->change.del.end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_undo_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Elm_Entry_Change_Info *change;
|
|
|
|
Edi_Editor *editor = data;
|
|
|
|
|
|
|
|
if (!eina_list_next(editor->undo_stack))
|
|
|
|
return;
|
|
|
|
|
|
|
|
change = eina_list_data_get(editor->undo_stack);
|
|
|
|
_undo_do(editor, change);
|
|
|
|
editor->undo_stack = eina_list_next(editor->undo_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
|
|
|
|
{
|
|
|
|
Elm_Entry_Change_Info *change;
|
|
|
|
Edi_Editor *editor = data;
|
|
|
|
|
|
|
|
change = calloc(1, sizeof(*change));
|
|
|
|
memcpy(change, event_info, sizeof(*change));
|
|
|
|
if (change->insert)
|
|
|
|
{
|
|
|
|
eina_stringshare_ref(change->change.insert.content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eina_stringshare_ref(change->change.del.content);
|
|
|
|
}
|
|
|
|
|
|
|
|
editor->undo_stack = eina_list_prepend(editor->undo_stack, change);
|
2015-02-08 15:21:27 -08:00
|
|
|
editor->modified = EINA_TRUE;
|
|
|
|
|
|
|
|
if (editor->save_timer)
|
|
|
|
ecore_timer_reset(editor->save_timer);
|
|
|
|
else
|
|
|
|
editor->save_timer = ecore_timer_add(EDI_CONTENT_SAVE_TIMEOUT, _edi_editor_autosave_cb, editor);
|
|
|
|
|
2014-06-15 14:54:08 -07:00
|
|
|
_update_lines(editor);
|
2014-05-15 15:25:25 -07:00
|
|
|
}
|
|
|
|
|
2014-05-15 14:40:19 -07:00
|
|
|
static void
|
2014-11-29 12:13:18 -08:00
|
|
|
_smart_cb_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
|
2014-05-15 14:40:19 -07:00
|
|
|
Evas_Object *obj EINA_UNUSED, void *event)
|
|
|
|
{
|
2014-11-29 12:13:18 -08:00
|
|
|
Edi_Mainview_Item *item;
|
|
|
|
Edi_Editor *editor;
|
|
|
|
Evas_Object *content;
|
2014-05-15 14:40:19 -07:00
|
|
|
Eina_Bool ctrl, alt, shift;
|
|
|
|
Evas_Event_Key_Down *ev = event;
|
|
|
|
|
|
|
|
ctrl = evas_key_modifier_is_set(ev->modifiers, "Control");
|
|
|
|
alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
|
|
|
|
shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
|
|
|
|
|
2014-11-29 12:13:18 -08:00
|
|
|
item = edi_mainview_item_current_get();
|
2015-02-01 08:09:25 -08:00
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2014-11-29 12:13:18 -08:00
|
|
|
content = elm_object_item_content_get(item->view);
|
|
|
|
editor = (Edi_Editor *)evas_object_data_get(content, "editor");
|
|
|
|
|
2014-05-15 14:40:19 -07:00
|
|
|
if ((!alt) && (ctrl) && (!shift))
|
|
|
|
{
|
|
|
|
if (!strcmp(ev->key, "Prior"))
|
|
|
|
{
|
|
|
|
edi_mainview_item_prev();
|
|
|
|
}
|
|
|
|
else if (!strcmp(ev->key, "Next"))
|
|
|
|
{
|
|
|
|
edi_mainview_item_next();
|
|
|
|
}
|
|
|
|
else if (!strcmp(ev->key, "s"))
|
|
|
|
{
|
2015-02-08 15:21:27 -08:00
|
|
|
edi_editor_save(editor);
|
2014-05-15 14:40:19 -07:00
|
|
|
}
|
|
|
|
else if (!strcmp(ev->key, "f"))
|
|
|
|
{
|
|
|
|
edi_mainview_search();
|
|
|
|
}
|
2014-05-15 15:25:25 -07:00
|
|
|
else if (!strcmp(ev->key, "z"))
|
|
|
|
{
|
2014-11-29 12:13:18 -08:00
|
|
|
_undo_cb(editor, obj, event);
|
2014-05-15 15:25:25 -07:00
|
|
|
}
|
2014-05-15 14:40:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-15 14:54:08 -07:00
|
|
|
static int
|
|
|
|
_get_lines_in_textblock(Evas_Object *textblock)
|
2014-06-07 13:50:14 -07:00
|
|
|
{
|
2014-06-15 14:54:08 -07:00
|
|
|
int lines;
|
|
|
|
Evas_Textblock_Cursor *cursor;
|
|
|
|
|
|
|
|
cursor = evas_object_textblock_cursor_new(textblock);
|
|
|
|
evas_textblock_cursor_paragraph_last(cursor);
|
|
|
|
lines = evas_textblock_cursor_geometry_get(cursor, NULL, NULL, NULL, NULL, NULL, EVAS_TEXTBLOCK_CURSOR_BEFORE);
|
|
|
|
|
|
|
|
evas_textblock_cursor_free(cursor);
|
|
|
|
return lines + 1;
|
2014-06-07 13:50:14 -07:00
|
|
|
}
|
|
|
|
|
2014-06-15 14:54:08 -07:00
|
|
|
static void
|
|
|
|
_update_lines(Edi_Editor *editor)
|
2014-06-07 13:50:14 -07:00
|
|
|
{
|
|
|
|
Eina_Strbuf *content;
|
2014-06-15 14:54:08 -07:00
|
|
|
int lines, i;
|
|
|
|
|
|
|
|
lines = _get_lines_in_textblock(elm_entry_textblock_get(editor->entry));
|
2014-06-07 13:50:14 -07:00
|
|
|
|
|
|
|
content = eina_strbuf_new();
|
|
|
|
eina_strbuf_append(content, "<align=right>");
|
2014-06-15 14:54:08 -07:00
|
|
|
for (i = 1; i <= lines; i++)
|
2014-06-07 13:50:14 -07:00
|
|
|
{
|
|
|
|
eina_strbuf_append_printf(content, "%d<br>", i);
|
|
|
|
}
|
2014-06-15 14:54:08 -07:00
|
|
|
eina_strbuf_append(content, "<br><br></align>");
|
|
|
|
elm_object_text_set(editor->lines, eina_strbuf_string_get(content));
|
2014-06-07 13:50:14 -07:00
|
|
|
eina_strbuf_free(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_scroll_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Edi_Editor *editor = data;
|
|
|
|
Evas_Coord y, h;
|
2015-01-31 11:24:25 -08:00
|
|
|
static Evas_Coord _edi_global_y;
|
2014-06-07 13:50:14 -07:00
|
|
|
|
2014-06-15 14:54:08 -07:00
|
|
|
elm_scroller_region_get(editor->entry, NULL, &y, NULL, NULL);
|
2014-06-07 15:29:03 -07:00
|
|
|
elm_scroller_region_get(editor->lines, NULL, NULL, NULL, &h);
|
2014-06-15 14:54:08 -07:00
|
|
|
elm_scroller_region_show(editor->lines, 0, y, 10, h);
|
2014-12-04 16:12:56 -08:00
|
|
|
|
2015-02-02 12:30:56 -08:00
|
|
|
// Don't update highlighting on h scroll, only y
|
2015-01-31 11:24:25 -08:00
|
|
|
if (_edi_global_y != y)
|
|
|
|
{
|
|
|
|
_update_highlight(editor);
|
|
|
|
_edi_global_y = y;
|
|
|
|
}
|
2014-12-04 16:12:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_resize_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Edi_Editor *editor = data;
|
|
|
|
|
|
|
|
_update_highlight(editor);
|
2014-06-07 13:50:14 -07:00
|
|
|
}
|
|
|
|
|
2030-07-09 16:03:26 -07:00
|
|
|
static void
|
|
|
|
_edit_cursor_moved(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
char buf[30];
|
|
|
|
int line;
|
|
|
|
int col;
|
|
|
|
Evas_Object *tb;
|
|
|
|
Evas_Textblock_Cursor *cur1, *cur2;
|
|
|
|
|
|
|
|
tb = elm_entry_textblock_get(obj);
|
|
|
|
|
|
|
|
cur1 = evas_object_textblock_cursor_get(tb);
|
|
|
|
cur2 = evas_object_textblock_cursor_new(tb);
|
|
|
|
line = evas_textblock_cursor_line_geometry_get(cur1, NULL, NULL, NULL, NULL) + 1;
|
|
|
|
evas_textblock_cursor_copy(cur1, cur2);
|
|
|
|
evas_textblock_cursor_line_char_first(cur2);
|
|
|
|
col = evas_textblock_cursor_pos_get(cur1) -
|
|
|
|
evas_textblock_cursor_pos_get(cur2) + 1;
|
|
|
|
evas_textblock_cursor_free(cur2);
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "Line:%d, Column:%d", line, col);
|
|
|
|
elm_object_text_set((Evas_Object *)data, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_editor_statusbar_add(Evas_Object *panel, Edi_Editor *editor, Edi_Mainview_Item *item)
|
2030-07-09 16:03:26 -07:00
|
|
|
{
|
2014-09-13 08:48:16 -07:00
|
|
|
Evas_Object *position, *mime;
|
|
|
|
|
|
|
|
elm_box_horizontal_set(panel, EINA_TRUE);
|
|
|
|
|
|
|
|
mime = elm_label_add(panel);
|
|
|
|
if (item->mimetype)
|
|
|
|
{
|
|
|
|
elm_object_text_set(mime, item->mimetype);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
elm_object_text_set(mime, item->editortype);
|
|
|
|
}
|
|
|
|
evas_object_size_hint_align_set(mime, 0.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(mime, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
elm_box_pack_end(panel, mime);
|
|
|
|
evas_object_show(mime);
|
|
|
|
elm_object_disabled_set(mime, EINA_TRUE);
|
2030-07-09 16:03:26 -07:00
|
|
|
|
|
|
|
position = elm_label_add(panel);
|
|
|
|
evas_object_size_hint_align_set(position, 1.0, 0.5);
|
|
|
|
evas_object_size_hint_weight_set(position, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
elm_box_pack_end(panel, position);
|
|
|
|
evas_object_show(position);
|
|
|
|
elm_object_disabled_set(position, EINA_TRUE);
|
|
|
|
|
|
|
|
_edit_cursor_moved(position, editor->entry, NULL);
|
|
|
|
evas_object_smart_callback_add(editor->entry, "cursor,changed", _edit_cursor_moved, position);
|
|
|
|
}
|
|
|
|
|
2014-10-16 12:47:57 -07:00
|
|
|
#if HAVE_LIBCLANG
|
2014-12-06 13:23:32 -08:00
|
|
|
// TODO on any refresh heck mtime - then re-run clang if changed - it should be fast enough now...
|
2014-10-08 16:06:55 -07:00
|
|
|
static void
|
2014-12-08 13:03:06 -08:00
|
|
|
_edi_line_color_remove(Edi_Editor *editor, unsigned int line)
|
2014-12-06 13:23:32 -08:00
|
|
|
{
|
|
|
|
Eina_List *formats;
|
|
|
|
Evas_Object *textblock;
|
|
|
|
Evas_Textblock_Cursor *start, *end;
|
|
|
|
Evas_Object_Textblock_Node_Format *format;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
textblock = elm_entry_textblock_get(editor->entry);
|
|
|
|
start = evas_object_textblock_cursor_new(textblock);
|
2014-12-08 13:03:06 -08:00
|
|
|
evas_textblock_cursor_line_set(start, line);
|
|
|
|
evas_textblock_cursor_pos_set(start, evas_textblock_cursor_pos_get(start));
|
2014-12-06 13:23:32 -08:00
|
|
|
end = evas_object_textblock_cursor_new(textblock);
|
2014-12-08 13:03:06 -08:00
|
|
|
evas_textblock_cursor_line_set(end, line);
|
|
|
|
evas_textblock_cursor_pos_set(end, evas_textblock_cursor_pos_get(end) - 1);
|
2014-12-06 13:23:32 -08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
formats = evas_textblock_cursor_range_formats_get(start, end);
|
|
|
|
while (eina_list_count(formats) > i)
|
|
|
|
{
|
|
|
|
format = eina_list_nth(formats, i);
|
|
|
|
|
|
|
|
if (!strncmp("+ color", evas_textblock_node_format_text_get(format), 7))
|
|
|
|
evas_textblock_node_format_remove_pair(textblock, format);
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
|
|
|
|
formats = evas_textblock_cursor_range_formats_get(start, end);
|
|
|
|
}
|
2014-12-08 13:03:06 -08:00
|
|
|
|
2014-12-06 13:23:32 -08:00
|
|
|
evas_textblock_cursor_free(start);
|
|
|
|
evas_textblock_cursor_free(end);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_edi_range_color_set(Edi_Editor *editor, Edi_Range range, Edi_Color color)
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
2014-12-04 16:12:56 -08:00
|
|
|
Evas_Textblock *textblock;
|
|
|
|
Evas_Textblock_Cursor *cursor;
|
|
|
|
|
2014-11-30 08:25:11 -08:00
|
|
|
ecore_thread_main_loop_begin();
|
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
if (!((Evas_Coord)range.start.line > editor->format_end || (Evas_Coord)range.end.line < editor->format_start))
|
|
|
|
{
|
2014-12-06 13:23:32 -08:00
|
|
|
textblock = elm_entry_textblock_get(editor->entry);
|
2014-12-08 13:03:06 -08:00
|
|
|
|
|
|
|
if (editor->format_line == -1)
|
|
|
|
editor->format_line = range.start.line - 1;
|
|
|
|
while (editor->format_line < (int) range.end.line)
|
|
|
|
{
|
|
|
|
_edi_line_color_remove(editor, ++editor->format_line);
|
|
|
|
}
|
|
|
|
|
2014-12-06 13:23:32 -08:00
|
|
|
cursor = evas_object_textblock_cursor_new(textblock);
|
|
|
|
evas_textblock_cursor_line_set(cursor, range.start.line - 1);
|
|
|
|
evas_textblock_cursor_pos_set(cursor, evas_textblock_cursor_pos_get(cursor) + range.start.col - 1);
|
|
|
|
evas_textblock_cursor_format_prepend(cursor, color);
|
2014-10-10 05:43:54 -07:00
|
|
|
|
2014-12-06 13:23:32 -08:00
|
|
|
evas_textblock_cursor_line_set(cursor, range.end.line - 1);
|
|
|
|
evas_textblock_cursor_pos_set(cursor, evas_textblock_cursor_pos_get(cursor) + range.end.col - 1);
|
2014-12-08 13:03:06 -08:00
|
|
|
evas_textblock_cursor_format_prepend(cursor, "</color>");
|
2014-11-30 08:25:11 -08:00
|
|
|
|
2014-12-06 13:23:32 -08:00
|
|
|
evas_textblock_cursor_free(cursor);
|
2014-12-04 16:12:56 -08:00
|
|
|
}
|
2014-11-30 08:25:11 -08:00
|
|
|
ecore_thread_main_loop_end();
|
2014-10-08 16:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_clang_load_highlighting(const char *path, Edi_Editor *editor)
|
|
|
|
{
|
|
|
|
CXFile cfile = clang_getFile(editor->tx_unit, path);
|
2014-12-01 11:11:29 -08:00
|
|
|
|
2014-10-08 16:06:55 -07:00
|
|
|
CXSourceRange range = clang_getRange(
|
|
|
|
clang_getLocationForOffset(editor->tx_unit, cfile, 0),
|
|
|
|
clang_getLocationForOffset(editor->tx_unit, cfile, eina_file_size_get(eina_file_open(path, EINA_FALSE))));
|
2014-12-01 11:11:29 -08:00
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
clang_tokenize(editor->tx_unit, range, &editor->tokens, &editor->token_count);
|
2014-10-08 16:06:55 -07:00
|
|
|
/* FIXME: We should use annotate tokens and then use a lot more
|
|
|
|
* color classes. I don't know why it's broken ATM... :( */
|
2014-12-04 16:12:56 -08:00
|
|
|
editor->cursors = (CXCursor *) malloc(editor->token_count * sizeof(CXCursor));
|
|
|
|
clang_annotateTokens(editor->tx_unit, editor->tokens, editor->token_count, editor->cursors);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
_clang_show_highlighting(void *data)
|
|
|
|
{
|
|
|
|
Edi_Editor *editor;
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
editor = (Edi_Editor *)data;
|
2014-12-08 13:03:06 -08:00
|
|
|
editor->format_line = -1;
|
2014-12-04 16:12:56 -08:00
|
|
|
for (i = 0 ; i < editor->token_count ; i++)
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
|
|
|
Edi_Range range;
|
2014-10-10 05:43:54 -07:00
|
|
|
Edi_Color color = EDI_COLOR_FOREGROUND;
|
2014-10-08 16:06:55 -07:00
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
CXSourceRange tkrange = clang_getTokenExtent(editor->tx_unit, editor->tokens[i]);
|
2014-10-08 16:06:55 -07:00
|
|
|
clang_getSpellingLocation(clang_getRangeStart(tkrange), NULL,
|
|
|
|
&range.start.line, &range.start.col, NULL);
|
|
|
|
clang_getSpellingLocation(clang_getRangeEnd(tkrange), NULL,
|
|
|
|
&range.end.line, &range.end.col, NULL);
|
|
|
|
/* FIXME: Should probably do something fancier, this is only a limited
|
|
|
|
* number of types. */
|
2014-12-04 16:12:56 -08:00
|
|
|
switch (clang_getTokenKind(editor->tokens[i]))
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
|
|
|
case CXToken_Punctuation:
|
2014-12-04 16:12:56 -08:00
|
|
|
if (i < editor->token_count - 1 && range.start.col == 1 &&
|
|
|
|
(clang_getTokenKind(editor->tokens[i + 1]) == CXToken_Identifier && (editor->cursors[i + 1].kind == CXCursor_MacroDefinition ||
|
|
|
|
editor->cursors[i + 1].kind == CXCursor_InclusionDirective || editor->cursors[i + 1].kind == CXCursor_PreprocessingDirective)))
|
2014-10-12 05:34:41 -07:00
|
|
|
color = EDI_COLOR_PREPROCESSOR;
|
|
|
|
else
|
|
|
|
color = EDI_COLOR_BRACE;
|
2014-10-10 05:43:54 -07:00
|
|
|
break;
|
2014-10-08 16:06:55 -07:00
|
|
|
case CXToken_Identifier:
|
2014-12-04 16:12:56 -08:00
|
|
|
if (editor->cursors[i].kind < CXCursor_FirstRef)
|
2014-10-10 05:43:54 -07:00
|
|
|
{
|
|
|
|
color = EDI_COLOR_CLASS;
|
|
|
|
break;
|
|
|
|
}
|
2014-12-04 16:12:56 -08:00
|
|
|
switch (editor->cursors[i].kind)
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
|
|
|
case CXCursor_DeclRefExpr:
|
|
|
|
/* Handle different ref kinds */
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_FUNCTION;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXCursor_MacroDefinition:
|
|
|
|
case CXCursor_InclusionDirective:
|
|
|
|
case CXCursor_PreprocessingDirective:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_PREPROCESSOR;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXCursor_TypeRef:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_TYPE;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXCursor_MacroExpansion:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_PREPROCESSOR;//_MACRO_EXPANSION;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
default:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_FOREGROUND;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CXToken_Keyword:
|
2014-12-04 16:12:56 -08:00
|
|
|
switch (editor->cursors[i].kind)
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
|
|
|
case CXCursor_PreprocessingDirective:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_PREPROCESSOR;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXCursor_CaseStmt:
|
|
|
|
case CXCursor_DefaultStmt:
|
|
|
|
case CXCursor_IfStmt:
|
|
|
|
case CXCursor_SwitchStmt:
|
|
|
|
case CXCursor_WhileStmt:
|
|
|
|
case CXCursor_DoStmt:
|
|
|
|
case CXCursor_ForStmt:
|
|
|
|
case CXCursor_GotoStmt:
|
|
|
|
case CXCursor_IndirectGotoStmt:
|
|
|
|
case CXCursor_ContinueStmt:
|
|
|
|
case CXCursor_BreakStmt:
|
|
|
|
case CXCursor_ReturnStmt:
|
|
|
|
case CXCursor_AsmStmt:
|
|
|
|
case CXCursor_ObjCAtTryStmt:
|
|
|
|
case CXCursor_ObjCAtCatchStmt:
|
|
|
|
case CXCursor_ObjCAtFinallyStmt:
|
|
|
|
case CXCursor_ObjCAtThrowStmt:
|
|
|
|
case CXCursor_ObjCAtSynchronizedStmt:
|
|
|
|
case CXCursor_ObjCAutoreleasePoolStmt:
|
|
|
|
case CXCursor_ObjCForCollectionStmt:
|
|
|
|
case CXCursor_CXXCatchStmt:
|
|
|
|
case CXCursor_CXXTryStmt:
|
|
|
|
case CXCursor_CXXForRangeStmt:
|
|
|
|
case CXCursor_SEHTryStmt:
|
|
|
|
case CXCursor_SEHExceptStmt:
|
|
|
|
case CXCursor_SEHFinallyStmt:
|
2014-10-10 05:43:54 -07:00
|
|
|
// color = EDI_COLOR_KEYWORD_STMT;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
default:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_KEYWORD;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CXToken_Literal:
|
2014-12-04 16:12:56 -08:00
|
|
|
if (editor->cursors[i].kind == CXCursor_StringLiteral || editor->cursors[i].kind == CXCursor_CharacterLiteral)
|
2014-11-13 13:35:58 -08:00
|
|
|
color = EDI_COLOR_STRING;
|
|
|
|
else
|
|
|
|
color = EDI_COLOR_NUMBER;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXToken_Comment:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_COMMENT;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_edi_range_color_set(editor, range, color);
|
|
|
|
|
2015-02-15 09:53:00 -08:00
|
|
|
# if CLANG_DEBUG
|
2014-10-08 16:06:55 -07:00
|
|
|
const char *kind = NULL;
|
2014-12-04 16:12:56 -08:00
|
|
|
switch (clang_getTokenKind(editor->tokens[i])) {
|
2014-10-08 16:06:55 -07:00
|
|
|
case CXToken_Punctuation: kind = "Punctuation"; break;
|
|
|
|
case CXToken_Keyword: kind = "Keyword"; break;
|
|
|
|
case CXToken_Identifier: kind = "Identifier"; break;
|
|
|
|
case CXToken_Literal: kind = "Literal"; break;
|
|
|
|
case CXToken_Comment: kind = "Comment"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s ", kind);
|
2014-12-04 16:12:56 -08:00
|
|
|
PrintToken(editor->tx_unit, editor->tokens[i]);
|
2014-10-08 16:06:55 -07:00
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
if (!clang_isInvalid(editor->cursors[i].kind)) {
|
2014-10-08 16:06:55 -07:00
|
|
|
printf(" ");
|
2014-12-04 16:12:56 -08:00
|
|
|
PrintCursor(editor->cursors[i]);
|
2014-10-08 16:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
2015-02-15 09:53:00 -08:00
|
|
|
# endif
|
2014-10-08 16:06:55 -07:00
|
|
|
}
|
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
// TODO clear these when we reset next time
|
|
|
|
// free(editor->cursors);
|
|
|
|
// clang_disposeTokens(editor->tx_unit, editor->tokens, editor->token_count);
|
|
|
|
|
|
|
|
return NULL;
|
2014-10-08 16:06:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-10-22 12:08:57 -07:00
|
|
|
_clang_load_errors(const char *path EINA_UNUSED, Edi_Editor *editor)
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
|
|
|
unsigned n = clang_getNumDiagnostics(editor->tx_unit);
|
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
for(i = 0, n = clang_getNumDiagnostics(editor->tx_unit); i != n; ++i)
|
|
|
|
{
|
|
|
|
CXDiagnostic diag = clang_getDiagnostic(editor->tx_unit, i);
|
|
|
|
Edi_Range range;
|
|
|
|
|
|
|
|
clang_getSpellingLocation(clang_getDiagnosticLocation(diag), NULL, &range.start.line, &range.start.col, NULL);
|
|
|
|
range.end = range.start;
|
|
|
|
|
|
|
|
/* FIXME: Also handle ranges and fix suggestions. */
|
|
|
|
|
2014-10-10 05:43:54 -07:00
|
|
|
Edi_Color color = EDI_COLOR_BACKGROUND;
|
2014-10-08 16:06:55 -07:00
|
|
|
|
|
|
|
switch (clang_getDiagnosticSeverity(diag))
|
|
|
|
{
|
|
|
|
case CXDiagnostic_Ignored:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_SEVIRITY_IGNORED;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXDiagnostic_Note:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_SEVIRITY_NOTE;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXDiagnostic_Warning:
|
2014-10-10 05:43:54 -07:00
|
|
|
color = EDI_COLOR_SEVIRITY_WARNING;
|
2014-10-08 16:06:55 -07:00
|
|
|
break;
|
|
|
|
case CXDiagnostic_Error:
|
|
|
|
// color = EDI_COLOR_BACKGROUND_SEVIRITY_ERROR;
|
|
|
|
break;
|
|
|
|
case CXDiagnostic_Fatal:
|
|
|
|
// color = EDI_COLOR_BACKGROUND_SEVIRITY_FATAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_edi_range_color_set(editor, range, color);
|
|
|
|
|
2015-02-15 09:53:00 -08:00
|
|
|
# if CLANG_DEBUG
|
2014-10-08 16:06:55 -07:00
|
|
|
CXString str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
|
|
|
|
printf("DEBUG: Diag:%s\n", clang_getCString(str));
|
|
|
|
clang_disposeString(str);
|
2015-02-15 09:53:00 -08:00
|
|
|
# endif
|
2014-10-08 16:06:55 -07:00
|
|
|
|
|
|
|
clang_disposeDiagnostic(diag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_edi_clang_render(void *data)
|
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_t thread_id;
|
|
|
|
|
|
|
|
if (pthread_attr_init(&attr) != 0)
|
|
|
|
perror("pthread_attr_init");
|
|
|
|
if (pthread_create(&thread_id, &attr, _clang_show_highlighting, data) != 0)
|
|
|
|
perror("pthread_create");
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
2014-11-30 08:25:11 -08:00
|
|
|
static void *
|
|
|
|
_edi_clang_setup(void *data)
|
2014-10-08 16:06:55 -07:00
|
|
|
{
|
2014-11-30 08:25:11 -08:00
|
|
|
Edi_Editor *editor;
|
2014-10-23 13:14:46 -07:00
|
|
|
const char *path;
|
|
|
|
|
2014-11-30 08:25:11 -08:00
|
|
|
editor = (Edi_Editor *)data;
|
2014-10-23 13:14:46 -07:00
|
|
|
elm_entry_file_get(editor->entry, &path, NULL);
|
2014-10-16 12:47:57 -07:00
|
|
|
|
2014-10-08 16:06:55 -07:00
|
|
|
/* Clang */
|
|
|
|
/* FIXME: index should probably be global. */
|
2015-02-07 16:55:51 -08:00
|
|
|
const char *clang_argv[] = {"-I/usr/lib/clang/3.1/include/", "-Wall", "-Wextra"};
|
2014-10-08 16:06:55 -07:00
|
|
|
int clang_argc = sizeof(clang_argv) / sizeof(*clang_argv);
|
|
|
|
|
|
|
|
editor->idx = clang_createIndex(0, 0);
|
|
|
|
|
|
|
|
/* FIXME: Possibly activate more options? */
|
|
|
|
editor->tx_unit = clang_parseTranslationUnit(editor->idx, path, clang_argv, clang_argc, NULL, 0, clang_defaultEditingTranslationUnitOptions() | CXTranslationUnit_DetailedPreprocessingRecord);
|
|
|
|
|
|
|
|
_clang_load_errors(path, editor);
|
|
|
|
_clang_load_highlighting(path, editor);
|
2014-12-04 16:12:56 -08:00
|
|
|
|
|
|
|
_edi_clang_render(editor);
|
2014-11-30 08:25:11 -08:00
|
|
|
|
|
|
|
return NULL;
|
2014-10-08 16:06:55 -07:00
|
|
|
}
|
|
|
|
|
2014-10-22 12:08:57 -07:00
|
|
|
/*
|
2014-12-04 16:12:56 -08:00
|
|
|
TODO - USE ME!
|
2014-10-08 16:06:55 -07:00
|
|
|
static void
|
|
|
|
_edi_clang_dispose(Edi_Editor *editor)
|
|
|
|
{
|
|
|
|
clang_disposeTranslationUnit(editor->tx_unit);
|
|
|
|
clang_disposeIndex(editor->idx);
|
|
|
|
}
|
2014-10-22 12:08:57 -07:00
|
|
|
*/
|
2014-10-08 16:06:55 -07:00
|
|
|
#endif
|
|
|
|
|
2014-10-23 13:14:46 -07:00
|
|
|
static void
|
2014-12-04 16:12:56 -08:00
|
|
|
_update_highlight_window(Edi_Editor *editor)
|
2014-10-23 13:14:46 -07:00
|
|
|
{
|
2014-12-04 16:12:56 -08:00
|
|
|
Evas_Object *textblock;
|
|
|
|
Evas_Textblock_Cursor *begin, *limit;
|
|
|
|
|
|
|
|
textblock = elm_entry_textblock_get(editor->entry);
|
|
|
|
|
|
|
|
begin = evas_object_textblock_cursor_new(textblock);
|
|
|
|
limit = evas_object_textblock_cursor_new(textblock);
|
|
|
|
evas_textblock_cursor_visible_range_get(begin, limit);
|
|
|
|
|
|
|
|
editor->format_start = evas_textblock_cursor_line_geometry_get(begin, NULL, NULL, NULL, NULL);
|
|
|
|
editor->format_end = evas_textblock_cursor_line_geometry_get(limit, NULL, NULL, NULL, NULL);
|
|
|
|
evas_textblock_cursor_free(begin);
|
|
|
|
evas_textblock_cursor_free(limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_reset_highlight(Edi_Editor *editor)
|
|
|
|
{
|
2015-02-06 06:16:26 -08:00
|
|
|
if (!editor->show_highlight)
|
|
|
|
return;
|
2015-02-14 15:55:05 -08:00
|
|
|
if (editor->highlight_time != 0 && editor->save_time <= editor->highlight_time)
|
|
|
|
return;
|
2015-02-06 06:16:26 -08:00
|
|
|
|
2015-02-14 15:55:05 -08:00
|
|
|
editor->highlight_time = time(NULL);
|
2014-12-04 16:12:56 -08:00
|
|
|
_update_highlight_window(editor);
|
|
|
|
|
2014-10-23 13:14:46 -07:00
|
|
|
#if HAVE_LIBCLANG
|
2014-11-30 08:25:11 -08:00
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_t thread_id;
|
|
|
|
|
|
|
|
if (pthread_attr_init(&attr) != 0)
|
|
|
|
perror("pthread_attr_init");
|
|
|
|
if (pthread_create(&thread_id, &attr, _edi_clang_setup, editor) != 0)
|
|
|
|
perror("pthread_create");
|
2014-10-23 13:14:46 -07:00
|
|
|
#endif
|
2014-11-30 08:25:11 -08:00
|
|
|
}
|
2014-10-23 13:14:46 -07:00
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
static void
|
|
|
|
_update_highlight(Edi_Editor *editor)
|
|
|
|
{
|
2015-02-06 06:16:26 -08:00
|
|
|
if (!editor->show_highlight)
|
|
|
|
return;
|
|
|
|
|
2014-12-04 16:12:56 -08:00
|
|
|
_update_highlight_window(editor);
|
|
|
|
|
|
|
|
#if HAVE_LIBCLANG
|
|
|
|
if (editor->delay_highlight)
|
|
|
|
ecore_timer_del(editor->delay_highlight);
|
|
|
|
|
|
|
|
editor->delay_highlight = ecore_timer_add(0.25, _edi_clang_render, editor);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-11-30 08:25:11 -08:00
|
|
|
static void
|
|
|
|
_text_set_done(void *data, Evas_Object *obj EINA_UNUSED, void *source EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Edi_Editor *editor = (Edi_Editor *) data;
|
|
|
|
|
|
|
|
_update_lines(editor);
|
2014-12-04 16:12:56 -08:00
|
|
|
_reset_highlight(editor);
|
2014-10-23 13:14:46 -07:00
|
|
|
}
|
|
|
|
|
2015-02-11 14:39:25 -08:00
|
|
|
static void
|
|
|
|
_unfocused_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Edi_Editor *editor;
|
|
|
|
|
|
|
|
editor = (Edi_Editor *)data;
|
|
|
|
|
|
|
|
edi_editor_save(editor);
|
|
|
|
}
|
|
|
|
|
2015-02-08 15:21:27 -08:00
|
|
|
Evas_Object *
|
|
|
|
edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item)
|
2014-05-15 14:40:19 -07:00
|
|
|
{
|
2030-07-12 13:12:05 -07:00
|
|
|
Evas_Object *txt, *lines, *vbox, *box, *searchbar, *statusbar;
|
2014-05-15 14:40:19 -07:00
|
|
|
Evas_Modifier_Mask ctrl, shift, alt;
|
|
|
|
Evas *e;
|
2014-05-15 15:25:25 -07:00
|
|
|
Edi_Editor *editor;
|
2014-05-15 14:40:19 -07:00
|
|
|
|
2030-07-09 16:03:26 -07:00
|
|
|
vbox = elm_box_add(parent);
|
2030-07-12 19:06:54 -07:00
|
|
|
evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(vbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
2030-07-09 16:03:26 -07:00
|
|
|
evas_object_show(vbox);
|
|
|
|
|
2030-07-12 13:12:05 -07:00
|
|
|
searchbar = elm_box_add(vbox);
|
|
|
|
evas_object_size_hint_weight_set(searchbar, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(searchbar, EVAS_HINT_FILL, 0.0);
|
|
|
|
elm_box_pack_end(vbox, searchbar);
|
|
|
|
|
2030-07-09 16:03:26 -07:00
|
|
|
box = elm_box_add(vbox);
|
2014-06-07 13:50:14 -07:00
|
|
|
elm_box_horizontal_set(box, EINA_TRUE);
|
2030-07-09 16:03:26 -07:00
|
|
|
evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
elm_box_pack_end(vbox, box);
|
2014-06-07 13:50:14 -07:00
|
|
|
evas_object_show(box);
|
|
|
|
|
2030-07-09 16:03:26 -07:00
|
|
|
statusbar = elm_box_add(vbox);
|
|
|
|
evas_object_size_hint_weight_set(statusbar, EVAS_HINT_EXPAND, 0.0);
|
|
|
|
evas_object_size_hint_align_set(statusbar, EVAS_HINT_FILL, 0.0);
|
|
|
|
elm_box_pack_end(vbox, statusbar);
|
|
|
|
evas_object_show(statusbar);
|
|
|
|
|
2014-06-07 13:50:14 -07:00
|
|
|
lines = elm_entry_add(box);
|
|
|
|
elm_entry_scrollable_set(lines, EINA_TRUE);
|
|
|
|
elm_scroller_policy_set(lines, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
|
|
|
|
elm_entry_editable_set(lines, EINA_FALSE);
|
|
|
|
|
2014-12-01 14:54:17 -08:00
|
|
|
elm_entry_text_style_user_push(lines, _edi_editor_font_get());
|
2014-06-07 13:50:14 -07:00
|
|
|
evas_object_color_set(lines, 127, 127, 127, 255);
|
|
|
|
|
|
|
|
evas_object_size_hint_weight_set(lines, 0.052, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(lines, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
elm_box_pack_end(box, lines);
|
|
|
|
evas_object_show(lines);
|
|
|
|
|
|
|
|
txt = elm_entry_add(box);
|
2014-05-15 14:40:19 -07:00
|
|
|
elm_entry_editable_set(txt, EINA_TRUE);
|
|
|
|
elm_entry_scrollable_set(txt, EINA_TRUE);
|
|
|
|
elm_entry_line_wrap_set(txt, EINA_FALSE);
|
2014-12-01 14:54:17 -08:00
|
|
|
elm_entry_text_style_user_push(txt, _edi_editor_font_get());
|
2014-05-15 14:40:19 -07:00
|
|
|
|
2014-05-15 15:25:25 -07:00
|
|
|
editor = calloc(1, sizeof(*editor));
|
|
|
|
editor->entry = txt;
|
2014-06-07 13:50:14 -07:00
|
|
|
editor->lines = lines;
|
2015-02-06 06:16:26 -08:00
|
|
|
editor->show_highlight = !strcmp(item->editortype, "code");
|
2014-05-15 14:40:19 -07:00
|
|
|
evas_object_event_callback_add(txt, EVAS_CALLBACK_KEY_DOWN,
|
2014-05-15 15:25:25 -07:00
|
|
|
_smart_cb_key_down, editor);
|
|
|
|
evas_object_smart_callback_add(txt, "changed,user", _changed_cb, editor);
|
2014-06-07 13:50:14 -07:00
|
|
|
evas_object_smart_callback_add(txt, "scroll", _scroll_cb, editor);
|
2014-12-04 16:12:56 -08:00
|
|
|
evas_object_smart_callback_add(txt, "resize", _resize_cb, editor);
|
2014-05-15 15:25:25 -07:00
|
|
|
evas_object_smart_callback_add(txt, "undo,request", _undo_cb, editor);
|
2014-10-23 13:14:46 -07:00
|
|
|
evas_object_smart_callback_add(txt, "text,set,done", _text_set_done, editor);
|
2015-02-11 14:39:25 -08:00
|
|
|
evas_object_smart_callback_add(txt, "unfocused", _unfocused_cb, editor);
|
2014-10-23 13:14:46 -07:00
|
|
|
|
|
|
|
elm_entry_file_set(txt, item->path, ELM_TEXT_FORMAT_PLAIN_UTF8);
|
|
|
|
|
2015-02-08 15:21:27 -08:00
|
|
|
elm_entry_autosave_set(txt, EINA_FALSE);
|
2014-10-23 13:14:46 -07:00
|
|
|
evas_object_size_hint_weight_set(txt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(txt);
|
|
|
|
elm_box_pack_end(box, txt);
|
|
|
|
|
2015-02-08 15:21:27 -08:00
|
|
|
edi_editor_search_add(searchbar, editor);
|
2014-09-13 08:48:16 -07:00
|
|
|
_edi_editor_statusbar_add(statusbar, editor, item);
|
2030-07-09 16:03:26 -07:00
|
|
|
|
2014-05-15 14:40:19 -07:00
|
|
|
e = evas_object_evas_get(txt);
|
|
|
|
ctrl = evas_key_modifier_mask_get(e, "Control");
|
|
|
|
alt = evas_key_modifier_mask_get(e, "Alt");
|
|
|
|
shift = evas_key_modifier_mask_get(e, "Shift");
|
|
|
|
|
2014-05-18 14:59:17 -07:00
|
|
|
(void)!evas_object_key_grab(txt, "Prior", ctrl, shift | alt, 1);
|
|
|
|
(void)!evas_object_key_grab(txt, "Next", ctrl, shift | alt, 1);
|
|
|
|
(void)!evas_object_key_grab(txt, "s", ctrl, shift | alt, 1);
|
|
|
|
(void)!evas_object_key_grab(txt, "f", ctrl, shift | alt, 1);
|
|
|
|
(void)!evas_object_key_grab(txt, "z", ctrl, shift | alt, 1);
|
2014-05-15 14:40:19 -07:00
|
|
|
|
2030-07-12 13:12:05 -07:00
|
|
|
evas_object_data_set(vbox, "editor", editor);
|
2014-10-08 16:06:55 -07:00
|
|
|
|
2030-07-09 16:03:26 -07:00
|
|
|
return vbox;
|
2014-05-15 14:40:19 -07:00
|
|
|
}
|