2016-06-02 17:19:08 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
2015-02-14 15:14:06 -08:00
|
|
|
#endif
|
|
|
|
|
2016-06-02 17:19:08 -07:00
|
|
|
#include "Elementary.h"
|
2015-02-14 15:14:06 -08:00
|
|
|
|
|
|
|
#include "elm_code_private.h"
|
|
|
|
|
2015-03-08 03:15:31 -07:00
|
|
|
EAPI void
|
|
|
|
elm_code_line_free(Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
if (!line)
|
|
|
|
return;
|
|
|
|
|
2015-03-27 16:54:28 -07:00
|
|
|
if (line->status_text)
|
|
|
|
free((char *)line->status_text);
|
2015-03-08 03:15:31 -07:00
|
|
|
if (line->modified)
|
|
|
|
free(line->modified);
|
|
|
|
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
|
2015-09-20 02:39:33 -07:00
|
|
|
static void
|
|
|
|
_elm_code_line_tokens_split_at(Elm_Code_Line *oldline, Elm_Code_Line *newline,
|
|
|
|
Eina_List *tokens, int position)
|
|
|
|
{
|
|
|
|
Eina_List *item, *next;
|
|
|
|
Elm_Code_Token *token, *newtoken;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH_SAFE(tokens, item, next, token)
|
|
|
|
{
|
|
|
|
if (!token->continues && token->end < position)
|
|
|
|
{
|
|
|
|
oldline->tokens = eina_list_append(oldline->tokens, token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (token->start >= position)
|
|
|
|
{
|
|
|
|
token->start -= position;
|
|
|
|
token->end -= position;
|
|
|
|
newline->tokens = eina_list_append(newline->tokens, token);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token->continues)
|
|
|
|
elm_code_line_token_add(newline, 0, token->end, 1, token->type);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
elm_code_line_token_add(newline, 0, token->end - position, 1, token->type);
|
|
|
|
token->end = position - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
newtoken = eina_list_data_get(newline->tokens);
|
|
|
|
newtoken->continues = token->continues;
|
|
|
|
token->continues = EINA_TRUE;
|
|
|
|
oldline->tokens = eina_list_append(oldline->tokens, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
elm_code_callback_fire(oldline->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, oldline);
|
|
|
|
elm_code_callback_fire(newline->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, newline);
|
|
|
|
}
|
|
|
|
|
2015-04-19 07:00:10 -07:00
|
|
|
EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *newline;
|
2015-09-20 02:39:33 -07:00
|
|
|
Elm_Code_Token *token EINA_UNUSED;
|
|
|
|
Eina_List *tokens;
|
2015-04-19 07:00:10 -07:00
|
|
|
char *content;
|
|
|
|
unsigned int length;
|
|
|
|
|
2017-07-30 20:00:45 -07:00
|
|
|
content = (char *) elm_code_line_text_get(line, &length);
|
|
|
|
if (!content) return;
|
|
|
|
content = strndup(content, length);
|
|
|
|
if (!content) return;
|
2015-04-19 07:00:10 -07:00
|
|
|
elm_code_file_line_insert(line->file, line->number + 1, "", 0, NULL);
|
|
|
|
newline = elm_code_file_line_get(line->file, line->number + 1);
|
|
|
|
|
2015-09-20 02:39:33 -07:00
|
|
|
tokens = line->tokens;
|
|
|
|
line->tokens = NULL;
|
2015-04-19 07:00:10 -07:00
|
|
|
elm_code_line_text_set(newline, content + position, length - position);
|
|
|
|
elm_code_line_text_set(line, content, position);
|
2015-09-20 02:39:33 -07:00
|
|
|
_elm_code_line_tokens_split_at(line, newline, tokens, position);
|
2015-04-19 07:00:10 -07:00
|
|
|
|
2015-09-20 02:39:33 -07:00
|
|
|
EINA_LIST_FREE(tokens, token) {} // don't free tokens, we re-used them
|
2015-04-19 07:00:10 -07:00
|
|
|
free(content);
|
|
|
|
}
|
|
|
|
|
2015-09-20 02:59:52 -07:00
|
|
|
static void
|
|
|
|
_elm_code_line_merge_into(Elm_Code_Line *line1, Elm_Code_Line *line2)
|
|
|
|
{
|
|
|
|
Eina_List *tokens1, *tokens2;
|
|
|
|
Elm_Code_Token *token;
|
|
|
|
const char *text1, *text2;
|
|
|
|
char *newtext;
|
|
|
|
unsigned int length1, length2;
|
|
|
|
|
|
|
|
text1 = elm_code_line_text_get(line1, &length1);
|
|
|
|
text2 = elm_code_line_text_get(line2, &length2);
|
|
|
|
|
|
|
|
newtext = malloc(sizeof(char) * (length1 + length2 + 1));
|
2017-04-05 15:59:23 -07:00
|
|
|
if (length1 > 0)
|
|
|
|
snprintf(newtext, length1 + 1, "%s", text1);
|
|
|
|
if (length2 > 0)
|
|
|
|
snprintf(newtext + length1, length2 + 1, "%s", text2);
|
2015-09-20 02:59:52 -07:00
|
|
|
|
|
|
|
tokens1 = line1->tokens;
|
|
|
|
line1->tokens = NULL;
|
|
|
|
tokens2 = line2->tokens;
|
|
|
|
line2->tokens = NULL;
|
|
|
|
elm_code_file_line_remove(line2->file, line2->number);
|
|
|
|
elm_code_line_text_set(line1, newtext, length1 + length2);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(tokens1, token)
|
|
|
|
{
|
|
|
|
token->continues = EINA_FALSE;
|
|
|
|
line1->tokens = eina_list_append(line1->tokens, token);
|
|
|
|
}
|
|
|
|
EINA_LIST_FREE(tokens2, token)
|
|
|
|
{
|
|
|
|
token->start += length1;
|
|
|
|
token->end += length1;
|
|
|
|
|
|
|
|
line1->tokens = eina_list_append(line1->tokens, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
elm_code_callback_fire(line1->file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line1);
|
|
|
|
free(newtext);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_line_merge_up(Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *other;
|
|
|
|
|
|
|
|
other = elm_code_file_line_get(line->file, line->number - 1);
|
|
|
|
|
|
|
|
if (other)
|
|
|
|
_elm_code_line_merge_into(other, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_code_line_merge_down(Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
Elm_Code_Line *other;
|
|
|
|
|
|
|
|
other = elm_code_file_line_get(line->file, line->number + 1);
|
|
|
|
|
|
|
|
if (other)
|
|
|
|
_elm_code_line_merge_into(line, other);
|
|
|
|
}
|
|
|
|
|
2015-02-14 15:14:06 -08:00
|
|
|
EAPI void elm_code_line_status_set(Elm_Code_Line *line, Elm_Code_Status_Type status)
|
|
|
|
{
|
|
|
|
if (!line)
|
|
|
|
return;
|
|
|
|
|
|
|
|
line->status = status;
|
|
|
|
}
|
|
|
|
|
2015-04-12 15:04:46 -07:00
|
|
|
EAPI void elm_code_line_status_text_set(Elm_Code_Line *line, const char *text)
|
|
|
|
{
|
|
|
|
if (line->status_text)
|
|
|
|
free(line->status_text);
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
line->status_text = strdup(text);
|
|
|
|
else
|
|
|
|
line->status_text = NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-21 10:24:17 -08:00
|
|
|
EAPI void elm_code_line_token_add(Elm_Code_Line *line, int start, int end, int lines,
|
|
|
|
Elm_Code_Token_Type type)
|
2015-02-14 15:14:06 -08:00
|
|
|
{
|
|
|
|
Elm_Code_Token *tok;
|
2015-02-21 10:24:17 -08:00
|
|
|
Elm_Code_Line *next_line;
|
2015-02-14 15:14:06 -08:00
|
|
|
|
|
|
|
if (!line)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tok = calloc(1, sizeof(Elm_Code_Token));
|
|
|
|
|
|
|
|
tok->start = start;
|
|
|
|
tok->end = end;
|
2015-09-20 02:39:33 -07:00
|
|
|
tok->continues = lines > 1;
|
2015-02-14 15:14:06 -08:00
|
|
|
tok->type = type;
|
|
|
|
|
|
|
|
line->tokens = eina_list_append(line->tokens, tok);
|
|
|
|
|
2015-09-20 02:39:33 -07:00
|
|
|
if (lines > 1)
|
2015-02-21 10:24:17 -08:00
|
|
|
{
|
|
|
|
next_line = elm_code_file_line_get(line->file, line->number + 1);
|
2015-06-03 13:29:31 -07:00
|
|
|
elm_code_line_token_add(next_line, 0, end, lines - 1, type);
|
2015-02-21 10:24:17 -08:00
|
|
|
}
|
|
|
|
}
|
2015-04-12 09:25:20 -07:00
|
|
|
|
|
|
|
EAPI void elm_code_line_tokens_clear(Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
Elm_Code_Token *token;
|
|
|
|
|
2015-09-20 02:39:33 -07:00
|
|
|
if (!line->tokens)
|
|
|
|
return;
|
|
|
|
|
2015-04-12 09:25:20 -07:00
|
|
|
EINA_LIST_FREE(line->tokens, token)
|
|
|
|
free(token);
|
|
|
|
line->tokens = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-12 15:04:46 -07:00
|
|
|
EAPI void elm_code_line_status_clear(Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
line->status = ELM_CODE_STATUS_TYPE_DEFAULT;
|
|
|
|
if (line->status_text)
|
|
|
|
{
|
|
|
|
free((char *)line->status_text);
|
|
|
|
line->status_text = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 06:11:40 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_code_line_contains_widget_cursor(Elm_Code_Line *line)
|
|
|
|
{
|
|
|
|
Elm_Code *code = line->file->parent;
|
|
|
|
Eina_List *item;
|
|
|
|
Eo *widget;
|
|
|
|
unsigned int col, number;
|
|
|
|
|
|
|
|
if (!code)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(code->widgets, item, widget)
|
|
|
|
{
|
2016-12-12 00:29:51 -08:00
|
|
|
elm_code_widget_cursor_position_get(widget, &number, &col);
|
2015-08-29 06:11:40 -07:00
|
|
|
|
|
|
|
if (number == line->number)
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|