summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_code_diff_widget.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-06-02 17:19:08 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-06-02 17:19:08 -0700
commitd384012307881898a2df49f68fa6b46a4cd9972d (patch)
tree31706c65b8c56083a151470721cf36e8bb46939d /src/lib/elementary/elm_code_diff_widget.c
parent9f129a8711f9bb71ee7cf6c13f7965926255c975 (diff)
elementary: merging in elm_code widget.
Theme is not there as it should be manually merged into the elementary default theme.
Diffstat (limited to 'src/lib/elementary/elm_code_diff_widget.c')
-rw-r--r--src/lib/elementary/elm_code_diff_widget.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/lib/elementary/elm_code_diff_widget.c b/src/lib/elementary/elm_code_diff_widget.c
new file mode 100644
index 0000000..c874805
--- /dev/null
+++ b/src/lib/elementary/elm_code_diff_widget.c
@@ -0,0 +1,131 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include "Elementary.h"
6
7#include "elm_code_private.h"
8
9#define _ELM_CODE_DIFF_WIDGET_LEFT "diffwidgetleft"
10#define _ELM_CODE_DIFF_WIDGET_RIGHT "diffwidgetright"
11
12#define _ELM_CODE_DIFF_WIDGET_TYPE_ADDED "added"
13#define _ELM_CODE_DIFF_WIDGET_TYPE_REMOVED "removed"
14#define _ELM_CODE_DIFF_WIDGET_TYPE_CHANGED "changed"
15
16static void
17_elm_code_diff_widget_parse_diff_line(Elm_Code_Line *line, Elm_Code_File *left, Elm_Code_File *right)
18{
19 const char *content;
20 unsigned int length;
21
22 if (line->length < 1)
23 {
24 elm_code_file_line_append(left, "", 0, NULL);
25 elm_code_file_line_append(right, "", 0, NULL);
26 }
27
28 content = elm_code_line_text_get(line, &length);
29 if (content[0] == '+')
30 {
31 elm_code_file_line_append(left, "", 0, NULL);
32 elm_code_file_line_append(right, content, length, NULL);
33 }
34 else if (content[0] == '-')
35 {
36 elm_code_file_line_append(left, content, length, NULL);
37 elm_code_file_line_append(right, "", 0, NULL);
38 }
39 else
40 {
41 elm_code_file_line_append(left, content, length, NULL);
42 elm_code_file_line_append(right, content, length, NULL);
43 }
44}
45
46static void
47_elm_code_diff_widget_parse_diff(Elm_Code_File *diff, Elm_Code_File *left, Elm_Code_File *right)
48{
49 Eina_List *item;
50 Elm_Code_Line *line;
51 const char *content;
52 unsigned int offset, length;
53
54 offset = 0;
55 EINA_LIST_FOREACH(diff->lines, item, line)
56 {
57 content = elm_code_line_text_get(line, &length);
58
59 if (length > 0 && (content[0] == 'd' || content[0] == 'i' || content[0] == 'n'))
60 {
61 offset = 0;
62 elm_code_file_line_append(left, content, length, NULL);
63 elm_code_file_line_append(right, content, length, NULL);
64
65 continue;
66 }
67
68 if (offset == 0)
69 elm_code_file_line_append(left, content, length, NULL);
70 else if (offset == 1)
71 elm_code_file_line_append(right, content, length, NULL);
72 else
73 _elm_code_diff_widget_parse_diff_line(line, left, right);
74
75 offset++;
76 }
77
78 _elm_code_parse_file(left->parent, left);
79 _elm_code_parse_file(right->parent, right);
80}
81
82EAPI Evas_Object *
83elm_code_diff_widget_add(Evas_Object *parent, Elm_Code *code)
84{
85 Elm_Code *wcode1, *wcode2;
86 Elm_Code_Widget *widget_left, *widget_right;
87 Evas_Object *hbox;
88
89 hbox = elm_panes_add(parent);
90 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
91 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
92 elm_panes_horizontal_set(hbox, EINA_FALSE);
93 evas_object_show(hbox);
94
95 // left side of diff
96 wcode1 = elm_code_create();
97 elm_code_parser_standard_add(wcode1, ELM_CODE_PARSER_STANDARD_DIFF);
98 widget_left = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, wcode1));
99
100 evas_object_size_hint_weight_set(widget_left, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101 evas_object_size_hint_align_set(widget_left, EVAS_HINT_FILL, EVAS_HINT_FILL);
102 evas_object_show(widget_left);
103 evas_object_data_set(hbox, _ELM_CODE_DIFF_WIDGET_LEFT, widget_left);
104 elm_object_part_content_set(hbox, "left", widget_left);
105
106 // right side of diff
107 wcode2 = elm_code_create();
108 elm_code_parser_standard_add(wcode2, ELM_CODE_PARSER_STANDARD_DIFF);
109 widget_right = eo_add(ELM_CODE_WIDGET_CLASS, parent, elm_obj_code_widget_code_set(eo_self, wcode2));
110
111 evas_object_size_hint_weight_set(widget_right, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112 evas_object_size_hint_align_set(widget_right, EVAS_HINT_FILL, EVAS_HINT_FILL);
113 evas_object_show(widget_right);
114 evas_object_data_set(hbox, _ELM_CODE_DIFF_WIDGET_RIGHT, widget_right);
115 elm_object_part_content_set(hbox, "right", widget_right);
116
117 _elm_code_diff_widget_parse_diff(code->file, wcode1->file, wcode2->file);
118 return hbox;
119}
120
121EAPI void
122elm_code_diff_widget_font_set(Evas_Object *widget, const char *name, int size)
123{
124 Elm_Code_Widget *child;
125
126 child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_LEFT);
127 elm_obj_code_widget_font_set(child, name, size);
128 child = (Elm_Code_Widget *) evas_object_data_get(widget, _ELM_CODE_DIFF_WIDGET_RIGHT);
129 elm_obj_code_widget_font_set(child, name, size);
130}
131