style cleanup: text editor

This commit is contained in:
Campbell Barton
2012-03-31 04:24:02 +00:00
parent 21ac9ae461
commit cbf9c1eb48
5 changed files with 1298 additions and 1295 deletions

View File

@@ -60,7 +60,7 @@
#include "RNA_access.h"
#include "text_intern.h" // own include
#include "text_intern.h" // own include
/* ******************** default callbacks for text space ***************** */
@@ -69,25 +69,25 @@ static SpaceLink *text_new(const bContext *UNUSED(C))
ARegion *ar;
SpaceText *stext;
stext= MEM_callocN(sizeof(SpaceText), "inittext");
stext->spacetype= SPACE_TEXT;
stext = MEM_callocN(sizeof(SpaceText), "inittext");
stext->spacetype = SPACE_TEXT;
stext->lheight= 12;
stext->tabnumber= 4;
stext->margin_column= 80;
stext->lheight = 12;
stext->tabnumber = 4;
stext->margin_column = 80;
/* header */
ar= MEM_callocN(sizeof(ARegion), "header for text");
ar = MEM_callocN(sizeof(ARegion), "header for text");
BLI_addtail(&stext->regionbase, ar);
ar->regiontype= RGN_TYPE_HEADER;
ar->alignment= RGN_ALIGN_BOTTOM;
ar->regiontype = RGN_TYPE_HEADER;
ar->alignment = RGN_ALIGN_BOTTOM;
/* main area */
ar= MEM_callocN(sizeof(ARegion), "main area for text");
ar = MEM_callocN(sizeof(ARegion), "main area for text");
BLI_addtail(&stext->regionbase, ar);
ar->regiontype= RGN_TYPE_WINDOW;
ar->regiontype = RGN_TYPE_WINDOW;
return (SpaceLink *)stext;
}
@@ -95,9 +95,9 @@ static SpaceLink *text_new(const bContext *UNUSED(C))
/* not spacelink itself */
static void text_free(SpaceLink *sl)
{
SpaceText *stext= (SpaceText*) sl;
SpaceText *stext = (SpaceText *) sl;
stext->text= NULL;
stext->text = NULL;
text_free_caches(stext);
}
@@ -110,21 +110,21 @@ static void text_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
static SpaceLink *text_duplicate(SpaceLink *sl)
{
SpaceText *stextn= MEM_dupallocN(sl);
SpaceText *stextn = MEM_dupallocN(sl);
/* clear or remove stuff from old */
stextn->drawcache= NULL; /* space need it's own cache */
stextn->drawcache = NULL; /* space need it's own cache */
return (SpaceLink *)stextn;
}
static void text_listener(ScrArea *sa, wmNotifier *wmn)
{
SpaceText *st= sa->spacedata.first;
SpaceText *st = sa->spacedata.first;
/* context changes */
switch(wmn->category) {
switch (wmn->category) {
case NC_TEXT:
/* check if active text was changed, no need to redraw if text isn't active
* reference==NULL means text was unlinked, should update anyway for this
@@ -132,7 +132,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
if (wmn->reference && wmn->reference != st->text)
break;
switch(wmn->data) {
switch (wmn->data) {
case ND_DISPLAY:
ED_area_tag_redraw(sa);
break;
@@ -144,7 +144,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
break;
}
switch(wmn->action) {
switch (wmn->action) {
case NA_EDITED:
if (st->text) {
text_drawcache_tag_update(st, 1);
@@ -152,7 +152,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
}
ED_area_tag_redraw(sa);
/* no break -- fall down to tag redraw */
/* no break -- fall down to tag redraw */
case NA_ADDED:
case NA_REMOVED:
ED_area_tag_redraw(sa);
@@ -245,17 +245,17 @@ static void text_keymap(struct wmKeyConfig *keyconf)
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", UPARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", FILE_TOP);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", DOWNARROWKEY, KM_PRESS, KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "type", PREV_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0)->ptr, "type", NEXT_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", FILE_TOP);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0)->ptr, "type", LINE_BEGIN);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0)->ptr, "type", PREV_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0)->ptr, "type", NEXT_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0)->ptr, "type", FILE_TOP);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0)->ptr, "type", FILE_BOTTOM);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_ALT, 0)->ptr, "type", DEL_PREV_WORD);
WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT|KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT | KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT | KM_SHIFT | KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
@@ -263,7 +263,7 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_find_set_selected", EKEY, KM_PRESS, KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_find", GKEY, KM_PRESS, KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_OSKEY, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0);
#endif
kmi = WM_keymap_add_item(keymap, "WM_OT_context_cycle_int", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
@@ -286,7 +286,7 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_save_as", SKEY, KM_PRESS, KM_ALT | KM_SHIFT | KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_run_script", PKEY, KM_PRESS, KM_ALT, 0);
@@ -315,19 +315,19 @@ static void text_keymap(struct wmKeyConfig *keyconf)
RNA_boolean_set(kmi->ptr, "split_lines", TRUE);
WM_keymap_add_item(keymap, "TEXT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_line", AKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_select_word", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_indent", TABKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "TEXT_OT_unindent", TABKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
WM_keymap_add_item(keymap, "TEXT_OT_uncomment", DKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", HOMEKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_BEGIN);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", ENDKEY, KM_PRESS, 0, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", EKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", RIGHTARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move", LEFTARROWKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", PREV_WORD);
@@ -343,14 +343,14 @@ static void text_keymap(struct wmKeyConfig *keyconf)
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", LINE_END);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", PREV_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", NEXT_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", LEFTARROWKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", PREV_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", RIGHTARROWKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", NEXT_WORD);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", UPARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_LINE);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", DOWNARROWKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_LINE);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", PREV_PAGE);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", NEXT_PAGE);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_TOP);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", FILE_BOTTOM);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", HOMEKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", FILE_TOP);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", FILE_BOTTOM);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR);
RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR);
@@ -386,7 +386,7 @@ const char *text_context_dir[] = {"edit_text", NULL};
static int text_context(const bContext *C, const char *member, bContextDataResult *result)
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
if (CTX_data_dir(member)) {
CTX_data_dir_set(result, text_context_dir);
@@ -423,7 +423,7 @@ static void text_main_area_init(wmWindowManager *wm, ARegion *ar)
static void text_main_area_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
//View2D *v2d= &ar->v2d;
/* clear and setup matrix */
@@ -452,8 +452,8 @@ static void text_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar))
static int text_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
{
if (drag->type==WM_DRAG_PATH)
if (ELEM(drag->icon, ICON_FILE_SCRIPT, ICON_FILE_BLANK)) /* rule might not work? */
if (drag->type == WM_DRAG_PATH)
if (ELEM(drag->icon, ICON_FILE_SCRIPT, ICON_FILE_BLANK)) /* rule might not work? */
return 1;
return 0;
}
@@ -467,7 +467,7 @@ static void text_drop_copy(wmDrag *drag, wmDropBox *drop)
/* this region dropbox definition */
static void text_dropboxes(void)
{
ListBase *lb= WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
ListBase *lb = WM_dropboxmap_find("Text", SPACE_TEXT, RGN_TYPE_WINDOW);
WM_dropbox_add(lb, "TEXT_OT_open", text_drop_poll, text_drop_copy);
@@ -507,49 +507,49 @@ static void text_properties_area_draw(const bContext *C, ARegion *ar)
/* only called once, from space/spacetypes.c */
void ED_spacetype_text(void)
{
SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype text");
SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype text");
ARegionType *art;
st->spaceid= SPACE_TEXT;
st->spaceid = SPACE_TEXT;
strncpy(st->name, "Text", BKE_ST_MAXNAME);
st->new= text_new;
st->free= text_free;
st->init= text_init;
st->duplicate= text_duplicate;
st->operatortypes= text_operatortypes;
st->keymap= text_keymap;
st->listener= text_listener;
st->context= text_context;
st->new = text_new;
st->free = text_free;
st->init = text_init;
st->duplicate = text_duplicate;
st->operatortypes = text_operatortypes;
st->keymap = text_keymap;
st->listener = text_listener;
st->context = text_context;
st->dropboxes = text_dropboxes;
/* regions: main window */
art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art->regionid = RGN_TYPE_WINDOW;
art->init= text_main_area_init;
art->draw= text_main_area_draw;
art->cursor= text_cursor;
art->init = text_main_area_init;
art->draw = text_main_area_draw;
art->cursor = text_cursor;
BLI_addhead(&st->regiontypes, art);
/* regions: properties */
art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art->regionid = RGN_TYPE_UI;
art->prefsizex= UI_COMPACT_PANEL_WIDTH;
art->keymapflag= ED_KEYMAP_UI;
art->prefsizex = UI_COMPACT_PANEL_WIDTH;
art->keymapflag = ED_KEYMAP_UI;
art->init= text_properties_area_init;
art->draw= text_properties_area_draw;
art->init = text_properties_area_init;
art->draw = text_properties_area_draw;
BLI_addhead(&st->regiontypes, art);
/* regions: header */
art= MEM_callocN(sizeof(ARegionType), "spacetype text region");
art = MEM_callocN(sizeof(ARegionType), "spacetype text region");
art->regionid = RGN_TYPE_HEADER;
art->prefsizey= HEADERY;
art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_HEADER;
art->prefsizey = HEADERY;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
art->init= text_header_area_init;
art->draw= text_header_area_draw;
art->init = text_header_area_init;
art->draw = text_header_area_draw;
BLI_addhead(&st->regiontypes, art);

View File

@@ -83,8 +83,8 @@ static int text_font_draw(SpaceText *UNUSED(st), int x, int y, const char *str)
static int text_font_draw_character(SpaceText *st, int x, int y, char c)
{
char str[2];
str[0]= c;
str[1]= '\0';
str[0] = c;
str[1] = '\0';
BLF_position(mono, x, y, 0);
BLF_draw(mono, str, 1);
@@ -94,10 +94,10 @@ static int text_font_draw_character(SpaceText *st, int x, int y, char c)
static int text_font_draw_character_utf8(SpaceText *st, int x, int y, const char *c)
{
char str[BLI_UTF8_MAX+1];
char str[BLI_UTF8_MAX + 1];
size_t len = BLI_str_utf8_size(c);
memcpy(str, c, len);
str[len]= '\0';
str[len] = '\0';
BLF_position(mono, x, y, 0);
BLF_draw(mono, str, len);
@@ -111,12 +111,12 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
{
int i;
if (fs->pos+len > fs->len) {
if (fs->pos + len > fs->len) {
char *nbuf; int *naccum;
fs->len*= 2;
fs->len *= 2;
nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf");
naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum");
nbuf = MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf");
naccum = MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum");
memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf));
memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum));
@@ -126,17 +126,17 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
MEM_freeN(fs->accum);
}
fs->buf= nbuf;
fs->accum= naccum;
fs->buf = nbuf;
fs->accum = naccum;
}
for (i = 0; i < len; i++)
{
fs->buf[fs->pos+i]= c[i];
fs->accum[fs->pos+i]= accum;
fs->buf[fs->pos + i] = c[i];
fs->accum[fs->pos + i] = accum;
}
fs->pos+= len;
fs->pos += len;
}
int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
@@ -144,14 +144,14 @@ int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
int r, i, total = 0;
memset(fs, 0, sizeof(FlattenString));
fs->buf= fs->fixedbuf;
fs->accum= fs->fixedaccum;
fs->buf = fs->fixedbuf;
fs->accum = fs->fixedaccum;
fs->len = sizeof(fs->fixedbuf);
for (r = 0, i = 0; *in; r++) {
if (*in=='\t') {
i= st->tabnumber - (total%st->tabnumber);
total+= i;
if (*in == '\t') {
i = st->tabnumber - (total % st->tabnumber);
total += i;
while (i--)
flatten_string_append(fs, " ", r, 1);
@@ -159,7 +159,7 @@ int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
in++;
}
else {
size_t len= BLI_str_utf8_size(in);
size_t len = BLI_str_utf8_size(in);
flatten_string_append(fs, in, r, len);
in += len;
total++;
@@ -190,30 +190,30 @@ static int find_builtinfunc(char *string)
{
int a, i;
char builtinfuncs[][9] = {"and", "as", "assert", "break", "class", "continue", "def",
"del", "elif", "else", "except", "exec", "finally",
"for", "from", "global", "if", "import", "in",
"is", "lambda", "not", "or", "pass", "print",
"raise", "return", "try", "while", "yield", "with"};
"del", "elif", "else", "except", "exec", "finally",
"for", "from", "global", "if", "import", "in",
"is", "lambda", "not", "or", "pass", "print",
"raise", "return", "try", "while", "yield", "with"};
for (a=0; a < sizeof(builtinfuncs)/sizeof(builtinfuncs[0]); a++) {
for (a = 0; a < sizeof(builtinfuncs) / sizeof(builtinfuncs[0]); a++) {
i = 0;
while (1) {
/* If we hit the end of a keyword... (eg. "def") */
if (builtinfuncs[a][i]=='\0') {
if (builtinfuncs[a][i] == '\0') {
/* If we still have identifier chars in the source (eg. "definate") */
if (text_check_identifier(string[i]))
i = -1; /* No match */
i = -1; /* No match */
break; /* Next keyword if no match, otherwise we're done */
/* If chars mismatch, move on to next keyword */
/* If chars mismatch, move on to next keyword */
}
else if (string[i]!=builtinfuncs[a][i]) {
else if (string[i] != builtinfuncs[a][i]) {
i = -1;
break; /* Break inner loop, start next keyword */
}
i++;
}
if (i>0) break; /* If we have a match, we're done */
if (i > 0) break; /* If we have a match, we're done */
}
return i;
}
@@ -229,13 +229,13 @@ static int find_specialvar(char *string)
{
int i = 0;
/* Check for "def" */
if (string[0]=='d' && string[1]=='e' && string[2]=='f')
if (string[0] == 'd' && string[1] == 'e' && string[2] == 'f')
i = 3;
/* Check for "class" */
else if (string[0]=='c' && string[1]=='l' && string[2]=='a' && string[3]=='s' && string[4]=='s')
else if (string[0] == 'c' && string[1] == 'l' && string[2] == 'a' && string[3] == 's' && string[4] == 's')
i = 5;
/* If next source char is an identifier (eg. 'i' in "definate") no match */
if (i==0 || text_check_identifier(string[i]))
if (i == 0 || text_check_identifier(string[i]))
return -1;
return i;
}
@@ -256,16 +256,16 @@ static int find_bool(char *string)
{
int i = 0;
/* Check for "False" */
if (string[0]=='F' && string[1]=='a' && string[2]=='l' && string[3]=='s' && string[4]=='e')
if (string[0] == 'F' && string[1] == 'a' && string[2] == 'l' && string[3] == 's' && string[4] == 'e')
i = 5;
/* Check for "True" */
else if (string[0]=='T' && string[1]=='r' && string[2]=='u' && string[3]=='e')
else if (string[0] == 'T' && string[1] == 'r' && string[2] == 'u' && string[3] == 'e')
i = 4;
/* Check for "None" */
else if (string[0]=='N' && string[1]=='o' && string[2]=='n' && string[3]=='e')
else if (string[0] == 'N' && string[1] == 'o' && string[2] == 'n' && string[3] == 'e')
i = 4;
/* If next source char is an identifier (eg. 'i' in "definate") no match */
if (i==0 || text_check_identifier(string[i]))
if (i == 0 || text_check_identifier(string[i]))
return -1;
return i;
}
@@ -277,12 +277,12 @@ static int text_check_format_len(TextLine *line, unsigned int len)
if (line->format) {
if (strlen(line->format) < len) {
MEM_freeN(line->format);
line->format = MEM_mallocN(len+2, "SyntaxFormat");
line->format = MEM_mallocN(len + 2, "SyntaxFormat");
if (!line->format) return 0;
}
}
else {
line->format = MEM_mallocN(len+2, "SyntaxFormat");
line->format = MEM_mallocN(len + 2, "SyntaxFormat");
if (!line->format) return 0;
}
@@ -311,15 +311,15 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
fmt= line->prev->format;
cont = fmt[strlen(fmt)+1]; /* Just after the null-terminator */
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
}
else cont = 0;
/* Get original continuation from this line */
if (line->format != NULL) {
fmt= line->format;
orig = fmt[strlen(fmt)+1]; /* Just after the null-terminator */
fmt = line->format;
orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
}
else orig = 0xFF;
@@ -344,12 +344,12 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
/* Triple strings ("""...""" or '''...''') */
if (cont & TXT_TRISTR) {
find = (cont & TXT_DBLQUOTSTR) ? '"' : '\'';
if (*str==find && *(str+1)==find && *(str+2)==find) {
if (*str == find && *(str + 1) == find && *(str + 2) == find) {
*fmt = 'l'; fmt++; str++;
*fmt = 'l'; fmt++; str++;
cont = 0;
}
/* Handle other strings */
/* Handle other strings */
}
else {
find = (cont & TXT_DBLQUOTSTR) ? '"' : '\'';
@@ -369,8 +369,8 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
else if (*str == '"' || *str == '\'') {
/* Strings */
find = *str;
cont = (*str== '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
if (*(str+1) == find && *(str+2) == find) {
cont = (*str == '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
if (*(str + 1) == find && *(str + 2) == find) {
*fmt = 'l'; fmt++; str++;
*fmt = 'l'; fmt++; str++;
cont |= TXT_TRISTR;
@@ -381,12 +381,12 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
else if (*str == ' ')
*fmt = '_';
/* Numbers (digits not part of an identifier and periods followed by digits) */
else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str+1))))
else if ((prev != 'q' && text_check_digit(*str)) || (*str == '.' && text_check_digit(*(str + 1))))
*fmt = 'n';
/* Booleans */
else if (prev != 'q' && (i=find_bool(str)) != -1)
if (i>0) {
while (i>1) {
else if (prev != 'q' && (i = find_bool(str)) != -1)
if (i > 0) {
while (i > 1) {
*fmt = 'n'; fmt++; str++;
i--;
}
@@ -407,14 +407,14 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
/* Not ws, a digit, punct, or continuing text. Must be new, check for special words */
else {
/* Special vars(v) or built-in keywords(b) */
if ((i=find_specialvar(str)) != -1)
if ((i = find_specialvar(str)) != -1)
prev = 'v';
else if ((i=find_builtinfunc(str)) != -1)
else if ((i = find_builtinfunc(str)) != -1)
prev = 'b';
else if ((i=find_decorator(str)) != -1)
prev = 'v'; /* could have a new color for this */
if (i>0) {
while (i>1) {
else if ((i = find_decorator(str)) != -1)
prev = 'v'; /* could have a new color for this */
if (i > 0) {
while (i > 1) {
*fmt = prev; fmt++; str++;
i--;
}
@@ -436,7 +436,7 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
*fmt = cont;
/* If continuation has changed and we're allowed, process the next line */
if (cont!=orig && do_next && line->next) {
if (cont != orig && do_next && line->next) {
txt_format_line(st, line->next, do_next);
}
@@ -451,7 +451,7 @@ static void txt_format_text(SpaceText *st)
if (!st->text) return;
for (linep=st->text->lines.first; linep; linep=linep->next)
for (linep = st->text->lines.first; linep; linep = linep->next)
txt_format_line(st, linep, 0);
}
#endif
@@ -515,12 +515,12 @@ static void format_draw_color(char formatchar)
int wrap_width(SpaceText *st, ARegion *ar)
{
int winx= ar->winx - TXT_SCROLL_WIDTH;
int winx = ar->winx - TXT_SCROLL_WIDTH;
int x, max;
x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
max= st->cwidth ? (winx-x)/st->cwidth : 0;
return max>8 ? max : 8;
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
max = st->cwidth ? (winx - x) / st->cwidth : 0;
return max > 8 ? max : 8;
}
/* Sets (offl, offc) for transforming (line, curs) to its wrapped position */
@@ -531,18 +531,18 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
int i, j, start, end, max, chop;
char ch;
*offl= *offc= 0;
*offl = *offc = 0;
if (!st->text) return;
if (!st->wordwrap) return;
text= st->text;
text = st->text;
/* Move pointer to first visible line (top) */
linep= text->lines.first;
i= st->top;
while (i>0 && linep) {
int lines= text_get_visible_lines(st, ar, linep->line);
linep = text->lines.first;
i = st->top;
while (i > 0 && linep) {
int lines = text_get_visible_lines(st, ar, linep->line);
/* Line before top */
if (linep == linein) {
@@ -551,67 +551,67 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
return;
}
if (i-lines<0) {
if (i - lines < 0) {
break;
}
else {
linep= linep->next;
(*offl)+= lines-1;
i-= lines;
linep = linep->next;
(*offl) += lines - 1;
i -= lines;
}
}
max= wrap_width(st, ar);
max = wrap_width(st, ar);
cursin = txt_utf8_offset_to_index(linein->line, cursin);
while (linep) {
start= 0;
end= max;
chop= 1;
*offc= 0;
for (i=0, j=0; linep->line[j]; j+=BLI_str_utf8_size(linep->line+j)) {
start = 0;
end = max;
chop = 1;
*offc = 0;
for (i = 0, j = 0; linep->line[j]; j += BLI_str_utf8_size(linep->line + j)) {
int chars;
/* Mimic replacement of tabs */
ch= linep->line[j];
if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
if (linep==linein && i<cursin) cursin += chars-1;
ch= ' ';
ch = linep->line[j];
if (ch == '\t') {
chars = st->tabnumber - i % st->tabnumber;
if (linep == linein && i < cursin) cursin += chars - 1;
ch = ' ';
}
else {
chars= 1;
chars = 1;
}
while (chars--) {
if (i-start>=max) {
if (chop && linep==linein && i >= cursin) {
if (i==cursin) {
if (i - start >= max) {
if (chop && linep == linein && i >= cursin) {
if (i == cursin) {
(*offl)++;
*offc -= end-start;
*offc -= end - start;
}
return;
}
(*offl)++;
*offc -= end-start;
*offc -= end - start;
start= end;
start = end;
end += max;
chop= 1;
chop = 1;
}
else if (ch==' ' || ch=='-') {
end = i+1;
chop= 0;
if (linep==linein && i >= cursin)
else if (ch == ' ' || ch == '-') {
end = i + 1;
chop = 0;
if (linep == linein && i >= cursin)
return;
}
i++;
}
}
if (linep==linein) break;
linep= linep->next;
if (linep == linein) break;
linep = linep->next;
}
}
@@ -621,52 +621,52 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
int i, j, start, end, chars, max, chop;
char ch;
*offl= *offc= 0;
*offl = *offc = 0;
if (!st->text) return;
if (!st->wordwrap) return;
max= wrap_width(st, ar);
max = wrap_width(st, ar);
start= 0;
end= max;
chop= 1;
*offc= 0;
start = 0;
end = max;
chop = 1;
*offc = 0;
cursin = txt_utf8_offset_to_index(linein->line, cursin);
for (i=0, j=0; linein->line[j]; j += BLI_str_utf8_size(linein->line + j)) {
for (i = 0, j = 0; linein->line[j]; j += BLI_str_utf8_size(linein->line + j)) {
/* Mimic replacement of tabs */
ch= linein->line[j];
if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
if (i<cursin) cursin += chars-1;
ch= ' ';
ch = linein->line[j];
if (ch == '\t') {
chars = st->tabnumber - i % st->tabnumber;
if (i < cursin) cursin += chars - 1;
ch = ' ';
}
else
chars= 1;
chars = 1;
while (chars--) {
if (i-start>=max) {
if (i - start >= max) {
if (chop && i >= cursin) {
if (i==cursin) {
if (i == cursin) {
(*offl)++;
*offc -= end-start;
*offc -= end - start;
}
return;
}
(*offl)++;
*offc -= end-start;
*offc -= end - start;
start= end;
start = end;
end += max;
chop= 1;
chop = 1;
}
else if (ch==' ' || ch=='-') {
end = i+1;
chop= 0;
else if (ch == ' ' || ch == '-') {
end = i + 1;
chop = 0;
if (i >= cursin)
return;
}
@@ -677,11 +677,11 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
int text_get_char_pos(SpaceText *st, const char *line, int cur)
{
int a=0, i;
int a = 0, i;
for (i=0; i<cur && line[i]; i += BLI_str_utf8_size(line + i)) {
if (line[i]=='\t')
a += st->tabnumber-a%st->tabnumber;
for (i = 0; i < cur && line[i]; i += BLI_str_utf8_size(line + i)) {
if (line[i] == '\t')
a += st->tabnumber - a % st->tabnumber;
else
a++;
}
@@ -690,9 +690,9 @@ int text_get_char_pos(SpaceText *st, const char *line, int cur)
static const char *txt_utf8_get_nth(const char *str, int n)
{
int pos= 0;
int pos = 0;
while (str[pos] && n--) {
pos+= BLI_str_utf8_size(str + pos);
pos += BLI_str_utf8_size(str + pos);
}
return str + pos;
}
@@ -704,49 +704,49 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w
int mi, ma, mstart, mend; /* mem */
flatten_string(st, &fs, str);
str= fs.buf;
max= w/st->cwidth;
if (max<8) max= 8;
basex= x;
lines= 1;
str = fs.buf;
max = w / st->cwidth;
if (max < 8) max = 8;
basex = x;
lines = 1;
start= 0; mstart= 0;
end= max; mend= txt_utf8_get_nth(str, max) - str;
start = 0; mstart = 0;
end = max; mend = txt_utf8_get_nth(str, max) - str;
for (i=0, mi=0; str[mi]; i++, mi+=BLI_str_utf8_size(str+mi)) {
if (i-start >= max) {
for (i = 0, mi = 0; str[mi]; i++, mi += BLI_str_utf8_size(str + mi)) {
if (i - start >= max) {
/* skip hidden part of line */
if (skip) {
skip--;
start= end; mstart= mend;
end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
start = end; mstart = mend;
end += max; mend = txt_utf8_get_nth(str + mend, max) - str;
continue;
}
/* Draw the visible portion of text on the overshot line */
for (a=start, ma=mstart; a<end; a++, ma+=BLI_str_utf8_size(str+ma)) {
for (a = start, ma = mstart; a < end; a++, ma += BLI_str_utf8_size(str + ma)) {
if (st->showsyntax && format) format_draw_color(format[a]);
x += text_font_draw_character_utf8(st, x, y, str + ma);
}
y -= st->lheight;
x= basex;
x = basex;
lines++;
start= end; mstart= mend;
end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
start = end; mstart = mend;
end += max; mend = txt_utf8_get_nth(str + mend, max) - str;
if (y<=0) break;
if (y <= 0) break;
}
else if (str[mi]==' ' || str[mi]=='-') {
end = i+1; mend = mi+1;
else if (str[mi] == ' ' || str[mi] == '-') {
end = i + 1; mend = mi + 1;
}
}
/* Draw the remaining text */
for (a=start, ma=mstart; str[ma] && y > 0; a++, ma+=BLI_str_utf8_size(str+ma)) {
for (a = start, ma = mstart; str[ma] && y > 0; a++, ma += BLI_str_utf8_size(str + ma)) {
if (st->showsyntax && format)
format_draw_color(format[a]);
x += text_font_draw_character_utf8(st, x, y, str+ma);
x += text_font_draw_character_utf8(st, x, y, str + ma);
}
flatten_string_free(&fs);
@@ -757,25 +757,25 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w
static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int draw, int x, int y, const char *format)
{
FlattenString fs;
int *acc, r=0;
int *acc, r = 0;
const char *in;
int w= flatten_string(st, &fs, str);
int w = flatten_string(st, &fs, str);
if (w < cshift) {
flatten_string_free(&fs);
return 0; /* String is shorter than shift */
}
in= txt_utf8_get_nth(fs.buf, cshift);
acc= fs.accum+cshift;
w= w-cshift;
in = txt_utf8_get_nth(fs.buf, cshift);
acc = fs.accum + cshift;
w = w - cshift;
if (draw) {
int amount = maxwidth ? MIN2(w, maxwidth) : w;
if (st->showsyntax && format) {
int a, str_shift= 0;
format = format+cshift;
int a, str_shift = 0;
format = format + cshift;
for (a = 0; a < amount; a++) {
format_draw_color(format[a]);
@@ -787,17 +787,17 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
}
else {
while (w-- && *acc++ < maxwidth)
r+= st->cwidth;
r += st->cwidth;
}
flatten_string_free(&fs);
if (cshift && r==0)
if (cshift && r == 0)
return 0;
else if (st->showlinenrs)
return r+TXT_OFFSET+TEXTXLOC;
return r + TXT_OFFSET + TEXTXLOC;
else
return r+TXT_OFFSET;
return r + TXT_OFFSET;
}
/************************ cache utilities *****************************/
@@ -819,36 +819,36 @@ typedef struct DrawCache {
static void text_drawcache_init(SpaceText *st)
{
DrawCache *drawcache= MEM_callocN(sizeof (DrawCache), "text draw cache");
DrawCache *drawcache = MEM_callocN(sizeof (DrawCache), "text draw cache");
drawcache->winx= -1;
drawcache->nlines= BLI_countlist(&st->text->lines);
drawcache->text_id[0]= '\0';
drawcache->winx = -1;
drawcache->nlines = BLI_countlist(&st->text->lines);
drawcache->text_id[0] = '\0';
st->drawcache= drawcache;
st->drawcache = drawcache;
}
static void text_update_drawcache(SpaceText *st, ARegion *ar)
{
DrawCache *drawcache;
int full_update= 0, nlines= 0;
Text *txt= st->text;
int full_update = 0, nlines = 0;
Text *txt = st->text;
if (!st->drawcache) text_drawcache_init(st);
text_update_character_width(st);
drawcache= (DrawCache *)st->drawcache;
nlines= drawcache->nlines;
drawcache = (DrawCache *)st->drawcache;
nlines = drawcache->nlines;
/* check if full cache update is needed */
full_update|= drawcache->winx != ar->winx; /* area was resized */
full_update|= drawcache->wordwrap != st->wordwrap; /* word-wrapping option was toggled */
full_update|= drawcache->showlinenrs != st->showlinenrs; /* word-wrapping option was toggled */
full_update|= drawcache->tabnumber != st->tabnumber; /* word-wrapping option was toggled */
full_update|= drawcache->lheight != st->lheight; /* word-wrapping option was toggled */
full_update|= drawcache->cwidth != st->cwidth; /* word-wrapping option was toggled */
full_update|= strncmp(drawcache->text_id, txt->id.name, MAX_ID_NAME); /* text datablock was changed */
full_update |= drawcache->winx != ar->winx; /* area was resized */
full_update |= drawcache->wordwrap != st->wordwrap; /* word-wrapping option was toggled */
full_update |= drawcache->showlinenrs != st->showlinenrs; /* word-wrapping option was toggled */
full_update |= drawcache->tabnumber != st->tabnumber; /* word-wrapping option was toggled */
full_update |= drawcache->lheight != st->lheight; /* word-wrapping option was toggled */
full_update |= drawcache->cwidth != st->cwidth; /* word-wrapping option was toggled */
full_update |= strncmp(drawcache->text_id, txt->id.name, MAX_ID_NAME); /* text datablock was changed */
if (st->wordwrap) {
/* update line heights */
@@ -859,65 +859,65 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
}
if (drawcache->update_flag) {
TextLine *line= st->text->lines.first;
int lineno= 0, size, lines_count;
int *fp= drawcache->line_height, *new_tail, *old_tail;
TextLine *line = st->text->lines.first;
int lineno = 0, size, lines_count;
int *fp = drawcache->line_height, *new_tail, *old_tail;
nlines= BLI_countlist(&txt->lines);
size= sizeof(int)*nlines;
nlines = BLI_countlist(&txt->lines);
size = sizeof(int) * nlines;
if (fp) fp= MEM_reallocN(fp, size);
else fp= MEM_callocN(size, "text drawcache line_height");
if (fp) fp = MEM_reallocN(fp, size);
else fp = MEM_callocN(size, "text drawcache line_height");
drawcache->valid_tail= drawcache->valid_head= 0;
old_tail= fp + drawcache->nlines - drawcache->valid_tail;
new_tail= fp + nlines - drawcache->valid_tail;
drawcache->valid_tail = drawcache->valid_head = 0;
old_tail = fp + drawcache->nlines - drawcache->valid_tail;
new_tail = fp + nlines - drawcache->valid_tail;
memmove(new_tail, old_tail, drawcache->valid_tail);
drawcache->total_lines= 0;
drawcache->total_lines = 0;
if (st->showlinenrs)
st->linenrs_tot= (int)floor(log10((float)nlines)) + 1;
st->linenrs_tot = (int)floor(log10((float)nlines)) + 1;
while (line) {
if (drawcache->valid_head) { /* we're inside valid head lines */
lines_count= fp[lineno];
lines_count = fp[lineno];
drawcache->valid_head--;
}
else if (lineno > new_tail - fp) { /* we-re inside valid tail lines */
lines_count= fp[lineno];
lines_count = fp[lineno];
}
else {
lines_count= text_get_visible_lines(st, ar, line->line);
lines_count = text_get_visible_lines(st, ar, line->line);
}
fp[lineno]= lines_count;
fp[lineno] = lines_count;
line= line->next;
line = line->next;
lineno++;
drawcache->total_lines+= lines_count;
drawcache->total_lines += lines_count;
}
drawcache->line_height= fp;
drawcache->line_height = fp;
}
}
else {
if (drawcache->line_height) {
MEM_freeN(drawcache->line_height);
drawcache->line_height= NULL;
drawcache->line_height = NULL;
}
if (full_update || drawcache->update_flag) {
nlines= BLI_countlist(&txt->lines);
nlines = BLI_countlist(&txt->lines);
if (st->showlinenrs)
st->linenrs_tot= (int)floor(log10((float)nlines)) + 1;
st->linenrs_tot = (int)floor(log10((float)nlines)) + 1;
}
drawcache->total_lines= nlines;
drawcache->total_lines = nlines;
}
drawcache->nlines= nlines;
drawcache->nlines = nlines;
/* store settings */
drawcache->winx = ar->winx;
@@ -942,8 +942,8 @@ void text_drawcache_tag_update(SpaceText *st, int full)
return;
if (st->drawcache) {
DrawCache *drawcache= (DrawCache *)st->drawcache;
Text *txt= st->text;
DrawCache *drawcache = (DrawCache *)st->drawcache;
Text *txt = st->text;
if (drawcache->update_flag) {
/* happens when tagging update from space listener */
@@ -952,36 +952,36 @@ void text_drawcache_tag_update(SpaceText *st, int full)
}
if (!full) {
int sellno= BLI_findindex(&txt->lines, txt->sell);
int curlno= BLI_findindex(&txt->lines, txt->curl);
int sellno = BLI_findindex(&txt->lines, txt->sell);
int curlno = BLI_findindex(&txt->lines, txt->curl);
if (curlno < sellno) {
drawcache->valid_head= curlno;
drawcache->valid_tail= drawcache->nlines - sellno - 1;
drawcache->valid_head = curlno;
drawcache->valid_tail = drawcache->nlines - sellno - 1;
}
else {
drawcache->valid_head= sellno;
drawcache->valid_tail= drawcache->nlines - curlno - 1;
drawcache->valid_head = sellno;
drawcache->valid_tail = drawcache->nlines - curlno - 1;
}
/* quick cache recalculation is also used in delete operator,
* which could merge lines which are adjacent to current selection lines
* expand recalculate area to this lines */
if (drawcache->valid_head>0) drawcache->valid_head--;
if (drawcache->valid_tail>0) drawcache->valid_tail--;
if (drawcache->valid_head > 0) drawcache->valid_head--;
if (drawcache->valid_tail > 0) drawcache->valid_tail--;
}
else {
drawcache->valid_head= 0;
drawcache->valid_tail= 0;
drawcache->valid_head = 0;
drawcache->valid_tail = 0;
}
drawcache->update_flag= 1;
drawcache->update_flag = 1;
}
}
void text_free_caches(SpaceText *st)
{
DrawCache *drawcache= (DrawCache *)st->drawcache;
DrawCache *drawcache = (DrawCache *)st->drawcache;
if (drawcache) {
if (drawcache->line_height)
@@ -996,7 +996,7 @@ void text_free_caches(SpaceText *st)
/* cache should be updated in caller */
static int text_get_visible_lines_no(SpaceText *st, int lineno)
{
DrawCache *drawcache= (DrawCache *)st->drawcache;
DrawCache *drawcache = (DrawCache *)st->drawcache;
return drawcache->line_height[lineno];
}
@@ -1006,27 +1006,27 @@ int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
int i, j, start, end, max, lines, chars;
char ch;
max= wrap_width(st, ar);
lines= 1;
start= 0;
end= max;
for (i= 0, j= 0; str[j]; j+=BLI_str_utf8_size(str+j)) {
max = wrap_width(st, ar);
lines = 1;
start = 0;
end = max;
for (i = 0, j = 0; str[j]; j += BLI_str_utf8_size(str + j)) {
/* Mimic replacement of tabs */
ch= str[j];
if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
ch = str[j];
if (ch == '\t') {
chars = st->tabnumber - i % st->tabnumber;
ch = ' ';
}
else chars= 1;
else chars = 1;
while (chars--) {
if (i-start >= max) {
if (i - start >= max) {
lines++;
start= end;
start = end;
end += max;
}
else if (ch==' ' || ch=='-') {
end= i+1;
else if (ch == ' ' || ch == '-') {
end = i + 1;
}
i++;
@@ -1039,14 +1039,14 @@ int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
int text_get_span_wrap(SpaceText *st, ARegion *ar, TextLine *from, TextLine *to)
{
if (st->wordwrap) {
int ret=0;
TextLine *tmp= from;
int ret = 0;
TextLine *tmp = from;
/* Look forwards */
while (tmp) {
if (tmp == to) return ret;
ret+= text_get_visible_lines(st, ar, tmp->line);
tmp= tmp->next;
ret += text_get_visible_lines(st, ar, tmp->line);
tmp = tmp->next;
}
return ret;
@@ -1059,7 +1059,7 @@ int text_get_total_lines(SpaceText *st, ARegion *ar)
DrawCache *drawcache;
text_update_drawcache(st, ar);
drawcache= (DrawCache *)st->drawcache;
drawcache = (DrawCache *)st->drawcache;
return drawcache->total_lines;
}
@@ -1067,32 +1067,32 @@ int text_get_total_lines(SpaceText *st, ARegion *ar)
/* Move pointer to first visible line (top) */
static TextLine *first_visible_line(SpaceText *st, ARegion *ar, int *wrap_top)
{
Text *text= st->text;
TextLine* pline= text->lines.first;
int i= st->top, lineno= 0;
Text *text = st->text;
TextLine *pline = text->lines.first;
int i = st->top, lineno = 0;
text_update_drawcache(st, ar);
if (wrap_top) *wrap_top= 0;
if (wrap_top) *wrap_top = 0;
if (st->wordwrap) {
while (i>0 && pline) {
int lines= text_get_visible_lines_no(st, lineno);
while (i > 0 && pline) {
int lines = text_get_visible_lines_no(st, lineno);
if (i-lines<0) {
if (wrap_top) *wrap_top= i;
if (i - lines < 0) {
if (wrap_top) *wrap_top = i;
break;
}
else {
pline= pline->next;
i-= lines;
pline = pline->next;
i -= lines;
lineno++;
}
}
}
else {
for (i=st->top; pline->next && i>0; i--)
pline= pline->next;
for (i = st->top; pline->next && i > 0; i--)
pline = pline->next;
}
return pline;
@@ -1109,11 +1109,11 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
pix_top_margin = 8;
pix_bottom_margin = 4;
pix_available = ar->winy - pix_top_margin - pix_bottom_margin;
ltexth= text_get_total_lines(st, ar);
ltexth = text_get_total_lines(st, ar);
blank_lines = st->viewlines / 2;
/* nicer code: use scroll rect for entire bar */
back->xmin = ar->winx -18;
back->xmin = ar->winx - 18;
back->xmax = ar->winx;
back->ymin = 0;
back->ymax = ar->winy;
@@ -1121,7 +1121,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
scroll->xmin = ar->winx - 17;
scroll->xmax = ar->winx - 5;
scroll->ymin = 4;
scroll->ymax = 4+pix_available;
scroll->ymax = 4 + pix_available;
/* when re-sizing a view-port with the bar at the bottom to a greater height more blank lines will be added */
if (ltexth + blank_lines < st->top + st->viewlines) {
@@ -1130,32 +1130,32 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
ltexth += blank_lines;
barheight = (ltexth > 0)? (st->viewlines*pix_available)/ltexth: 0;
barheight = (ltexth > 0) ? (st->viewlines * pix_available) / ltexth : 0;
pix_bardiff = 0;
if (barheight < 20) {
pix_bardiff = 20 - barheight; /* take into account the now non-linear sizing of the bar */
barheight = 20;
}
barstart = (ltexth > 0)? ((pix_available - pix_bardiff) * st->top)/ltexth: 0;
barstart = (ltexth > 0) ? ((pix_available - pix_bardiff) * st->top) / ltexth : 0;
st->txtbar= *scroll;
st->txtbar = *scroll;
st->txtbar.ymax -= barstart;
st->txtbar.ymin = st->txtbar.ymax - barheight;
CLAMP(st->txtbar.ymin, pix_bottom_margin, ar->winy - pix_top_margin);
CLAMP(st->txtbar.ymax, pix_bottom_margin, ar->winy - pix_top_margin);
st->pix_per_line= (pix_available > 0)? (float) ltexth/pix_available: 0;
if (st->pix_per_line < 0.1f) st->pix_per_line=0.1f;
st->pix_per_line = (pix_available > 0) ? (float) ltexth / pix_available : 0;
if (st->pix_per_line < 0.1f) st->pix_per_line = 0.1f;
curl_off= text_get_span_wrap(st, ar, st->text->lines.first, st->text->curl);
sell_off= text_get_span_wrap(st, ar, st->text->lines.first, st->text->sell);
curl_off = text_get_span_wrap(st, ar, st->text->lines.first, st->text->curl);
sell_off = text_get_span_wrap(st, ar, st->text->lines.first, st->text->sell);
lhlstart = MIN2(curl_off, sell_off);
lhlend = MAX2(curl_off, sell_off);
if (ltexth > 0) {
hlstart = (lhlstart * pix_available)/ltexth;
hlend = (lhlend * pix_available)/ltexth;
hlstart = (lhlstart * pix_available) / ltexth;
hlend = (lhlend * pix_available) / ltexth;
/* the scrollbar is non-linear sized */
if (pix_bardiff > 0) {
@@ -1180,7 +1180,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
/* the end of the highlight is in the current viewport */
if (ltexth && st->viewlines && lhlend >= st->top && lhlend <= st->top + st->viewlines) {
/* speed the progresion of the end of the highlight through the scrollbar */
hlend = (((pix_available - pix_bardiff )*lhlend)/ltexth) + (pix_bardiff * (lhlend - st->top)/st->viewlines);
hlend = (((pix_available - pix_bardiff) * lhlend) / ltexth) + (pix_bardiff * (lhlend - st->top) / st->viewlines);
}
else if (lhlend < st->top && hlend >= barstart - 2 && hlend < barstart + barheight) {
/* push hl end up */
@@ -1205,7 +1205,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
hlend = hlstart + 2;
}
st->txtscroll= *scroll;
st->txtscroll = *scroll;
st->txtscroll.ymax = ar->winy - pix_top_margin - hlstart;
st->txtscroll.ymin = ar->winy - pix_top_margin - hlend;
@@ -1215,23 +1215,23 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
static void draw_textscroll(SpaceText *st, rcti *scroll, rcti *back)
{
bTheme *btheme= UI_GetTheme();
uiWidgetColors wcol= btheme->tui.wcol_scroll;
bTheme *btheme = UI_GetTheme();
uiWidgetColors wcol = btheme->tui.wcol_scroll;
unsigned char col[4];
float rad;
UI_ThemeColor(TH_BACK);
glRecti(back->xmin, back->ymin, back->xmax, back->ymax);
uiWidgetScrollDraw(&wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT)?UI_SCROLL_PRESSED:0);
uiWidgetScrollDraw(&wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT) ? UI_SCROLL_PRESSED : 0);
uiSetRoundBox(UI_CNR_ALL);
rad= 0.4f*MIN2(st->txtscroll.xmax - st->txtscroll.xmin, st->txtscroll.ymax - st->txtscroll.ymin);
rad = 0.4f * MIN2(st->txtscroll.xmax - st->txtscroll.xmin, st->txtscroll.ymax - st->txtscroll.ymin);
UI_GetThemeColor3ubv(TH_HILITE, col);
col[3]= 48;
col[3] = 48;
glColor4ubv(col);
glEnable(GL_BLEND);
uiRoundBox(st->txtscroll.xmin+1, st->txtscroll.ymin, st->txtscroll.xmax-1, st->txtscroll.ymax, rad);
uiRoundBox(st->txtscroll.xmin + 1, st->txtscroll.ymin, st->txtscroll.xmax - 1, st->txtscroll.ymax, rad);
glDisable(GL_BLEND);
}
@@ -1239,28 +1239,28 @@ static void draw_textscroll(SpaceText *st, rcti *scroll, rcti *back)
static void draw_markers(SpaceText *st, ARegion *ar)
{
Text *text= st->text;
Text *text = st->text;
TextMarker *marker, *next;
TextLine *top, *line;
int offl, offc, i, x1, x2, y1, y2, x, y;
int topi, topy;
/* Move pointer to first visible line (top) */
top= first_visible_line(st, ar, NULL);
topi= BLI_findindex(&text->lines, top);
top = first_visible_line(st, ar, NULL);
topi = BLI_findindex(&text->lines, top);
topy= txt_get_span(text->lines.first, top);
topy = txt_get_span(text->lines.first, top);
for (marker= text->markers.first; marker; marker= next) {
next= marker->next;
for (marker = text->markers.first; marker; marker = next) {
next = marker->next;
/* invisible line (before top) */
if (marker->lineno<topi) continue;
if (marker->lineno < topi) continue;
line= BLI_findlink(&text->lines, marker->lineno);
line = BLI_findlink(&text->lines, marker->lineno);
/* Remove broken markers */
if (marker->end>line->len || marker->start>marker->end) {
if (marker->end > line->len || marker->start > marker->end) {
BLI_freelinkN(&text->markers, marker);
continue;
}
@@ -1274,46 +1274,46 @@ static void draw_markers(SpaceText *st, ARegion *ar)
x2 = text_get_char_pos(st, line->line, marker->end) - st->left + offc;
/* invisible part of line (before top, after last visible line) */
if (y2 < 0 || y1 > st->top+st->viewlines) continue;
if (y2 < 0 || y1 > st->top + st->viewlines) continue;
glColor3ubv(marker->color);
x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y= ar->winy-3;
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y = ar->winy - 3;
if (y1==y2) {
y -= y1*st->lheight;
if (y1 == y2) {
y -= y1 * st->lheight;
glBegin(GL_LINE_LOOP);
glVertex2i(x+x2*st->cwidth+1, y);
glVertex2i(x+x1*st->cwidth-2, y);
glVertex2i(x+x1*st->cwidth-2, y-st->lheight);
glVertex2i(x+x2*st->cwidth+1, y-st->lheight);
glVertex2i(x + x2 * st->cwidth + 1, y);
glVertex2i(x + x1 * st->cwidth - 2, y);
glVertex2i(x + x1 * st->cwidth - 2, y - st->lheight);
glVertex2i(x + x2 * st->cwidth + 1, y - st->lheight);
glEnd();
}
else {
y -= y1*st->lheight;
y -= y1 * st->lheight;
glBegin(GL_LINE_STRIP);
glVertex2i(ar->winx, y);
glVertex2i(x+x1*st->cwidth-2, y);
glVertex2i(x+x1*st->cwidth-2, y-st->lheight);
glVertex2i(ar->winx, y-st->lheight);
glVertex2i(x + x1 * st->cwidth - 2, y);
glVertex2i(x + x1 * st->cwidth - 2, y - st->lheight);
glVertex2i(ar->winx, y - st->lheight);
glEnd();
y-=st->lheight;
y -= st->lheight;
for (i=y1+1; i<y2; i++) {
for (i = y1 + 1; i < y2; i++) {
glBegin(GL_LINES);
glVertex2i(x, y);
glVertex2i(ar->winx, y);
glVertex2i(x, y-st->lheight);
glVertex2i(ar->winx, y-st->lheight);
glVertex2i(x, y - st->lheight);
glVertex2i(ar->winx, y - st->lheight);
glEnd();
y-=st->lheight;
y -= st->lheight;
}
glBegin(GL_LINE_STRIP);
glVertex2i(x, y);
glVertex2i(x+x2*st->cwidth+1, y);
glVertex2i(x+x2*st->cwidth+1, y-st->lheight);
glVertex2i(x, y-st->lheight);
glVertex2i(x + x2 * st->cwidth + 1, y);
glVertex2i(x + x2 * st->cwidth + 1, y - st->lheight);
glVertex2i(x, y - st->lheight);
glEnd();
}
}
@@ -1324,7 +1324,7 @@ static void draw_markers(SpaceText *st, ARegion *ar)
static void draw_documentation(SpaceText *st, ARegion *ar)
{
TextLine *tmp;
char *docs, buf[DOC_WIDTH+1], *p;
char *docs, buf[DOC_WIDTH + 1], *p;
int i, br, lines;
int boxw, boxh, l, x, y /* , top */ /* UNUSED */;
@@ -1336,67 +1336,67 @@ static void draw_documentation(SpaceText *st, ARegion *ar)
if (!docs) return;
/* Count the visible lines to the cursor */
for (tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
if (l<0) return;
for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) ;
if (l < 0) return;
if (st->showlinenrs) {
x= st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
x= st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
}
if (texttool_suggest_first()) {
x += SUGG_LIST_WIDTH*st->cwidth + 50;
x += SUGG_LIST_WIDTH * st->cwidth + 50;
}
/* top= */ /* UNUSED */ y= ar->winy - st->lheight*l - 2;
boxw= DOC_WIDTH*st->cwidth + 20;
boxh= (DOC_HEIGHT+1)*st->lheight;
/* top= */ /* UNUSED */ y = ar->winy - st->lheight * l - 2;
boxw = DOC_WIDTH * st->cwidth + 20;
boxh = (DOC_HEIGHT + 1) * st->lheight;
/* Draw panel */
UI_ThemeColor(TH_BACK);
glRecti(x, y, x+boxw, y-boxh);
glRecti(x, y, x + boxw, y - boxh);
UI_ThemeColor(TH_SHADE1);
glBegin(GL_LINE_LOOP);
glVertex2i(x, y);
glVertex2i(x+boxw, y);
glVertex2i(x+boxw, y-boxh);
glVertex2i(x, y-boxh);
glVertex2i(x + boxw, y);
glVertex2i(x + boxw, y - boxh);
glVertex2i(x, y - boxh);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(x+boxw-10, y-7);
glVertex2i(x+boxw-4, y-7);
glVertex2i(x+boxw-7, y-2);
glVertex2i(x + boxw - 10, y - 7);
glVertex2i(x + boxw - 4, y - 7);
glVertex2i(x + boxw - 7, y - 2);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2i(x+boxw-10, y-boxh+7);
glVertex2i(x+boxw-4, y-boxh+7);
glVertex2i(x+boxw-7, y-boxh+2);
glVertex2i(x + boxw - 10, y - boxh + 7);
glVertex2i(x + boxw - 4, y - boxh + 7);
glVertex2i(x + boxw - 7, y - boxh + 2);
glEnd();
UI_ThemeColor(TH_TEXT);
i= 0; br= DOC_WIDTH; lines= 0; // XXX -doc_scroll;
for (p=docs; *p; p++) {
if (*p == '\r' && *(++p) != '\n') *(--p)= '\n'; /* Fix line endings */
i = 0; br = DOC_WIDTH; lines = 0; // XXX -doc_scroll;
for (p = docs; *p; p++) {
if (*p == '\r' && *(++p) != '\n') *(--p) = '\n'; /* Fix line endings */
if (*p == ' ' || *p == '\t')
br= i;
br = i;
else if (*p == '\n') {
buf[i]= '\0';
if (lines>=0) {
buf[i] = '\0';
if (lines >= 0) {
y -= st->lheight;
text_draw(st, buf, 0, 0, 1, x+4, y-3, NULL);
text_draw(st, buf, 0, 0, 1, x + 4, y - 3, NULL);
}
i= 0; br= DOC_WIDTH; lines++;
i = 0; br = DOC_WIDTH; lines++;
}
buf[i++]= *p;
buf[i++] = *p;
if (i == DOC_WIDTH) { /* Reached the width, go to last break and wrap there */
buf[br]= '\0';
if (lines>=0) {
buf[br] = '\0';
if (lines >= 0) {
y -= st->lheight;
text_draw(st, buf, 0, 0, 1, x+4, y-3, NULL);
text_draw(st, buf, 0, 0, 1, x + 4, y - 3, NULL);
}
p -= i-br-1; /* Rewind pointer to last break */
i= 0; br= DOC_WIDTH; lines++;
p -= i - br - 1; /* Rewind pointer to last break */
i = 0; br = DOC_WIDTH; lines++;
}
if (lines >= DOC_HEIGHT) break;
}
@@ -1413,8 +1413,8 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
{
SuggItem *item, *first, *last, *sel;
TextLine *tmp;
char str[SUGG_LIST_WIDTH+1];
int w, boxw=0, boxh, i, l, x, y, b, *top;
char str[SUGG_LIST_WIDTH + 1];
int w, boxw = 0, boxh, i, l, x, y, b, *top;
if (!st || !st->text) return;
if (!texttool_text_is_active(st->text)) return;
@@ -1429,29 +1429,29 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
top = texttool_suggest_top();
/* Count the visible lines to the cursor */
for (tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
if (l<0) return;
for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) ;
if (l < 0) return;
if (st->showlinenrs) {
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
}
y = ar->winy - st->lheight*l - 2;
y = ar->winy - st->lheight * l - 2;
boxw = SUGG_LIST_WIDTH*st->cwidth + 20;
boxh = SUGG_LIST_SIZE*st->lheight + 8;
boxw = SUGG_LIST_WIDTH * st->cwidth + 20;
boxh = SUGG_LIST_SIZE * st->lheight + 8;
UI_ThemeColor(TH_SHADE1);
glRecti(x-1, y+1, x+boxw+1, y-boxh-1);
glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1);
UI_ThemeColor(TH_BACK);
glRecti(x, y, x+boxw, y-boxh);
glRecti(x, y, x + boxw, y - boxh);
/* Set the top 'item' of the visible list */
for (i=0, item=first; i<*top && item->next; i++, item=item->next);
for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;
for (i=0; i<SUGG_LIST_SIZE && item; i++, item=item->next) {
for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
y -= st->lheight;
@@ -1461,21 +1461,21 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
if (item == sel) {
UI_ThemeColor(TH_SHADE2);
glRecti(x+16, y-3, x+16+w, y+st->lheight-3);
glRecti(x + 16, y - 3, x + 16 + w, y + st->lheight - 3);
}
b=1; /* b=1 color block, text is default. b=0 no block, color text */
b = 1; /* b=1 color block, text is default. b=0 no block, color text */
switch (item->type) {
case 'k': UI_ThemeColor(TH_SYNTAX_B); b=0; break;
case 'k': UI_ThemeColor(TH_SYNTAX_B); b = 0; break;
case 'm': UI_ThemeColor(TH_TEXT); break;
case 'f': UI_ThemeColor(TH_SYNTAX_L); break;
case 'v': UI_ThemeColor(TH_SYNTAX_N); break;
case '?': UI_ThemeColor(TH_TEXT); b=0; break;
case '?': UI_ThemeColor(TH_TEXT); b = 0; break;
}
if (b) {
glRecti(x+8, y+2, x+11, y+5);
glRecti(x + 8, y + 2, x + 11, y + 5);
UI_ThemeColor(TH_TEXT);
}
text_draw(st, str, 0, 0, 1, x+16, y-1, NULL);
text_draw(st, str, 0, 0, 1, x + 16, y - 1, NULL);
if (item == last) break;
}
@@ -1485,12 +1485,12 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
static void draw_cursor(SpaceText *st, ARegion *ar)
{
Text *text= st->text;
int vcurl, vcurc, vsell, vselc, hidden=0;
Text *text = st->text;
int vcurl, vcurc, vsell, vselc, hidden = 0;
int x, y, w, i;
/* Draw the selection */
if (text->curl!=text->sell || text->curc!=text->selc) {
if (text->curl != text->sell || text->curc != text->selc) {
int offl, offc;
/* Convert all to view space character coordinates */
wrap_offset(st, ar, text->curl, text->curc, &offl, &offc);
@@ -1500,38 +1500,38 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
if (vcurc<0) vcurc=0;
if (vselc<0) vselc=0, hidden=1;
if (vcurc < 0) vcurc = 0;
if (vselc < 0) vselc = 0, hidden = 1;
UI_ThemeColor(TH_SHADE2);
x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y= ar->winy-2;
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y = ar->winy - 2;
if (vcurl==vsell) {
y -= vcurl*st->lheight;
if (vcurl == vsell) {
y -= vcurl * st->lheight;
if (vcurc < vselc)
glRecti(x+vcurc*st->cwidth-1, y, x+vselc*st->cwidth, y-st->lheight);
glRecti(x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - st->lheight);
else
glRecti(x+vselc*st->cwidth-1, y, x+vcurc*st->cwidth, y-st->lheight);
glRecti(x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - st->lheight);
}
else {
int froml, fromc, tol, toc;
if (vcurl < vsell) {
froml= vcurl; tol= vsell;
fromc= vcurc; toc= vselc;
froml = vcurl; tol = vsell;
fromc = vcurc; toc = vselc;
}
else {
froml= vsell; tol= vcurl;
fromc= vselc; toc= vcurc;
froml = vsell; tol = vcurl;
fromc = vselc; toc = vcurc;
}
y -= froml*st->lheight;
glRecti(x+fromc*st->cwidth-1, y, ar->winx, y-st->lheight); y-=st->lheight;
for (i=froml+1; i<tol; i++)
glRecti(x-4, y, ar->winx, y-st->lheight), y-=st->lheight;
y -= froml * st->lheight;
glRecti(x + fromc * st->cwidth - 1, y, ar->winx, y - st->lheight); y -= st->lheight;
for (i = froml + 1; i < tol; i++)
glRecti(x - 4, y, ar->winx, y - st->lheight), y -= st->lheight;
glRecti(x-4, y, x+toc*st->cwidth, y-st->lheight); y-=st->lheight;
glRecti(x - 4, y, x + toc * st->cwidth, y - st->lheight); y -= st->lheight;
}
}
else {
@@ -1540,9 +1540,9 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
if (vselc<0) {
vselc= 0;
hidden= 1;
if (vselc < 0) {
vselc = 0;
hidden = 1;
}
}
@@ -1555,45 +1555,45 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
wrap_offset_in_line(st, ar, text->sell, text->selc, &offl, &offc);
y1= ar->winy-2 - (vsell-offl)*st->lheight;
y2= y1-st->lheight*visible_lines+1;
y1 = ar->winy - 2 - (vsell - offl) * st->lheight;
y2 = y1 - st->lheight * visible_lines + 1;
}
else {
y1= ar->winy-2 - vsell*st->lheight;
y2= y1-st->lheight+1;
y1 = ar->winy - 2 - vsell * st->lheight;
y2 = y1 - st->lheight + 1;
}
if (!(y1<0 || y2 > ar->winy)) { /* check we need to draw */
x1= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x2= x1 + ar->winx;
if (!(y1 < 0 || y2 > ar->winy)) { /* check we need to draw */
x1 = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x2 = x1 + ar->winx;
glColor4ub(255, 255, 255, 32);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glRecti(x1-4, y1, x2, y2);
glRecti(x1 - 4, y1, x2, y2);
glDisable(GL_BLEND);
}
}
if (!hidden) {
/* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */
x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x += vselc*st->cwidth;
y= ar->winy-2 - vsell*st->lheight;
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x += vselc * st->cwidth;
y = ar->winy - 2 - vsell * st->lheight;
if (st->overwrite) {
char ch= text->sell->line[text->selc];
char ch = text->sell->line[text->selc];
w= st->cwidth;
if (ch=='\t') w*= st->tabnumber-(vselc+st->left)%st->tabnumber;
w = st->cwidth;
if (ch == '\t') w *= st->tabnumber - (vselc + st->left) % st->tabnumber;
UI_ThemeColor(TH_HILITE);
glRecti(x, y-st->lheight-1, x+w, y-st->lheight+1);
glRecti(x, y - st->lheight - 1, x + w, y - st->lheight + 1);
}
else {
UI_ThemeColor(TH_HILITE);
glRecti(x-1, y, x+1, y-st->lheight);
glRecti(x - 1, y, x + 1, y - st->lheight);
}
}
}
@@ -1612,116 +1612,116 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
// showsyntax must be on or else the format string will be null
if (!text->curl || !st->showsyntax) return;
startl= text->curl;
startc= text->curc;
b= text_check_bracket(startl->line[startc]);
if (b==0 && startc>0) b = text_check_bracket(startl->line[--startc]);
if (b==0) return;
linep= startl;
c= startc;
fc= txt_utf8_offset_to_index(linep->line, startc);
endl= NULL;
endc= -1;
find= -b;
stack= 0;
startl = text->curl;
startc = text->curc;
b = text_check_bracket(startl->line[startc]);
if (b == 0 && startc > 0) b = text_check_bracket(startl->line[--startc]);
if (b == 0) return;
linep = startl;
c = startc;
fc = txt_utf8_offset_to_index(linep->line, startc);
endl = NULL;
endc = -1;
find = -b;
stack = 0;
/* Don't highlight backets if syntax HL is off or bracket in string or comment. */
if (!linep->format || linep->format[fc] == 'l' || linep->format[fc] == '#')
return;
if (b>0) {
if (b > 0) {
/* opening bracket, search forward for close */
fc++;
c+= BLI_str_utf8_size(linep->line+c);
c += BLI_str_utf8_size(linep->line + c);
while (linep) {
while (c<linep->len) {
while (c < linep->len) {
if (linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
b= text_check_bracket(linep->line[c]);
if (b==find) {
if (stack==0) {
endl= linep;
endc= c;
b = text_check_bracket(linep->line[c]);
if (b == find) {
if (stack == 0) {
endl = linep;
endc = c;
break;
}
stack--;
}
else if (b==-find) {
else if (b == -find) {
stack++;
}
}
fc++;
c+= BLI_str_utf8_size(linep->line+c);
c += BLI_str_utf8_size(linep->line + c);
}
if (endl) break;
linep= linep->next;
c= 0;
fc= 0;
linep = linep->next;
c = 0;
fc = 0;
}
}
else {
/* closing bracket, search backward for open */
fc--;
if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
if (c > 0) c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c);
while (linep) {
while (fc>=0) {
while (fc >= 0) {
if (linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
b= text_check_bracket(linep->line[c]);
if (b==find) {
if (stack==0) {
endl= linep;
endc= c;
b = text_check_bracket(linep->line[c]);
if (b == find) {
if (stack == 0) {
endl = linep;
endc = c;
break;
}
stack--;
}
else if (b==-find) {
else if (b == -find) {
stack++;
}
}
fc--;
if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
if (c > 0) c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c);
}
if (endl) break;
linep= linep->prev;
linep = linep->prev;
if (linep) {
if (linep->format) fc= strlen(linep->format)-1;
else fc= -1;
if (linep->len) c= BLI_str_prev_char_utf8(linep->line+linep->len)-linep->line;
else fc= -1;
if (linep->format) fc = strlen(linep->format) - 1;
else fc = -1;
if (linep->len) c = BLI_str_prev_char_utf8(linep->line + linep->len) - linep->line;
else fc = -1;
}
}
}
if (!endl || endc==-1)
if (!endl || endc == -1)
return;
UI_ThemeColor(TH_HILITE);
x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y= ar->winy - st->lheight;
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y = ar->winy - st->lheight;
/* draw opening bracket */
ch= startl->line[startc];
ch = startl->line[startc];
wrap_offset(st, ar, startl, startc, &offl, &offc);
viewc= text_get_char_pos(st, startl->line, startc) - st->left + offc;
viewc = text_get_char_pos(st, startl->line, startc) - st->left + offc;
if (viewc >= 0) {
viewl= txt_get_span(text->lines.first, startl) - st->top + offl;
viewl = txt_get_span(text->lines.first, startl) - st->top + offl;
text_font_draw_character(st, x+viewc*st->cwidth, y-viewl*st->lheight, ch);
text_font_draw_character(st, x+viewc*st->cwidth+1, y-viewl*st->lheight, ch);
text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * st->lheight, ch);
text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * st->lheight, ch);
}
/* draw closing bracket */
ch= endl->line[endc];
ch = endl->line[endc];
wrap_offset(st, ar, endl, endc, &offl, &offc);
viewc= text_get_char_pos(st, endl->line, endc) - st->left + offc;
viewc = text_get_char_pos(st, endl->line, endc) - st->left + offc;
if (viewc >= 0) {
viewl= txt_get_span(text->lines.first, endl) - st->top + offl;
viewl = txt_get_span(text->lines.first, endl) - st->top + offl;
text_font_draw_character(st, x+viewc*st->cwidth, y-viewl*st->lheight, ch);
text_font_draw_character(st, x+viewc*st->cwidth+1, y-viewl*st->lheight, ch);
text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * st->lheight, ch);
text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * st->lheight, ch);
}
}
@@ -1729,15 +1729,15 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
void draw_text_main(SpaceText *st, ARegion *ar)
{
Text *text= st->text;
Text *text = st->text;
TextLine *tmp;
rcti scroll, back;
char linenr[12];
int i, x, y, winx, linecount= 0, lineno= 0;
int wraplinecount= 0, wrap_skip= 0;
int i, x, y, winx, linecount = 0, lineno = 0;
int wraplinecount = 0, wrap_skip = 0;
if (st->lheight) st->viewlines= (int)ar->winy/st->lheight;
else st->viewlines= 0;
if (st->lheight) st->viewlines = (int)ar->winy / st->lheight;
else st->viewlines = 0;
/* if no text, nothing to do */
if (!text)
@@ -1750,30 +1750,30 @@ void draw_text_main(SpaceText *st, ARegion *ar)
txt_clean_text(text);
/* update rects for scroll */
calc_text_rcts(st, ar, &scroll, &back); /* scroll will hold the entire bar size */
calc_text_rcts(st, ar, &scroll, &back); /* scroll will hold the entire bar size */
/* update syntax formatting if needed */
tmp= text->lines.first;
lineno= 0;
for (i= 0; i<st->top && tmp; i++) {
tmp = text->lines.first;
lineno = 0;
for (i = 0; i < st->top && tmp; i++) {
if (st->showsyntax && !tmp->format)
txt_format_line(st, tmp, 0);
if (st->wordwrap) {
int lines= text_get_visible_lines_no(st, lineno);
int lines = text_get_visible_lines_no(st, lineno);
if (wraplinecount+lines>st->top) {
wrap_skip= st->top-wraplinecount;
if (wraplinecount + lines > st->top) {
wrap_skip = st->top - wraplinecount;
break;
}
else {
wraplinecount+= lines;
tmp= tmp->next;
wraplinecount += lines;
tmp = tmp->next;
linecount++;
}
}
else {
tmp= tmp->next;
tmp = tmp->next;
linecount++;
}
@@ -1781,22 +1781,22 @@ void draw_text_main(SpaceText *st, ARegion *ar)
}
text_font_begin(st);
st->cwidth= BLF_fixed_width(mono);
st->cwidth= MAX2(st->cwidth, 1);
st->cwidth = BLF_fixed_width(mono);
st->cwidth = MAX2(st->cwidth, 1);
/* draw line numbers background */
if (st->showlinenrs) {
x= TXT_OFFSET + TEXTXLOC;
x = TXT_OFFSET + TEXTXLOC;
UI_ThemeColor(TH_GRID);
glRecti((TXT_OFFSET-12), 0, (TXT_OFFSET-5) + TEXTXLOC, ar->winy - 2);
glRecti((TXT_OFFSET - 12), 0, (TXT_OFFSET - 5) + TEXTXLOC, ar->winy - 2);
}
else {
st->linenrs_tot= 0; /* not used */
x= TXT_OFFSET;
st->linenrs_tot = 0; /* not used */
x = TXT_OFFSET;
}
y= ar->winy-st->lheight;
winx= ar->winx - TXT_SCROLL_WIDTH;
y = ar->winy - st->lheight;
winx = ar->winx - TXT_SCROLL_WIDTH;
/* draw cursor */
draw_cursor(st, ar);
@@ -1804,7 +1804,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
/* draw the text */
UI_ThemeColor(TH_TEXT);
for (i=0; y>0 && i<st->viewlines && tmp; i++, tmp= tmp->next) {
for (i = 0; y > 0 && i < st->viewlines && tmp; i++, tmp = tmp->next) {
if (st->showsyntax && !tmp->format)
txt_format_line(st, tmp, 0);
@@ -1824,24 +1824,24 @@ void draw_text_main(SpaceText *st, ARegion *ar)
if (st->wordwrap) {
/* draw word wrapped text */
int lines = text_draw_wrapped(st, tmp->line, x, y, winx-x, tmp->format, wrap_skip);
y -= lines*st->lheight;
int lines = text_draw_wrapped(st, tmp->line, x, y, winx - x, tmp->format, wrap_skip);
y -= lines * st->lheight;
}
else {
/* draw unwrapped text */
text_draw(st, tmp->line, st->left, ar->winx/st->cwidth, 1, x, y, tmp->format);
text_draw(st, tmp->line, st->left, ar->winx / st->cwidth, 1, x, y, tmp->format);
y -= st->lheight;
}
wrap_skip= 0;
wrap_skip = 0;
}
if (st->flags&ST_SHOW_MARGIN) {
if (st->flags & ST_SHOW_MARGIN) {
UI_ThemeColor(TH_HILITE);
glBegin(GL_LINES);
glVertex2i(x+st->cwidth*st->margin_column, 0);
glVertex2i(x+st->cwidth*st->margin_column, ar->winy - 2);
glVertex2i(x + st->cwidth * st->margin_column, 0);
glVertex2i(x + st->cwidth * st->margin_column, ar->winy - 2);
glEnd();
}
@@ -1861,8 +1861,8 @@ void draw_text_main(SpaceText *st, ARegion *ar)
void text_update_character_width(SpaceText *st)
{
text_font_begin(st);
st->cwidth= BLF_fixed_width(mono);
st->cwidth= MAX2(st->cwidth, 1);
st->cwidth = BLF_fixed_width(mono);
st->cwidth = MAX2(st->cwidth, 1);
text_font_end(st);
}
@@ -1871,16 +1871,16 @@ void text_update_character_width(SpaceText *st)
void text_scroll_to_cursor(SpaceText *st, ScrArea *sa)
{
Text *text;
ARegion *ar= NULL;
int i, x, winx= 0;
ARegion *ar = NULL;
int i, x, winx = 0;
if (ELEM3(NULL, st, st->text, st->text->curl)) return;
text= st->text;
text = st->text;
for (ar=sa->regionbase.first; ar; ar= ar->next)
if (ar->regiontype==RGN_TYPE_WINDOW) {
winx= ar->winx;
for (ar = sa->regionbase.first; ar; ar = ar->next)
if (ar->regiontype == RGN_TYPE_WINDOW) {
winx = ar->winx;
break;
}
@@ -1888,34 +1888,34 @@ void text_scroll_to_cursor(SpaceText *st, ScrArea *sa)
text_update_character_width(st);
i= txt_get_span(text->lines.first, text->sell);
i = txt_get_span(text->lines.first, text->sell);
if (st->wordwrap) {
int offl, offc;
wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
i+= offl;
i += offl;
}
if (st->top+st->viewlines <= i || st->top > i)
st->top= i - st->viewlines/2;
if (st->top + st->viewlines <= i || st->top > i)
st->top = i - st->viewlines / 2;
if (st->wordwrap) {
st->left= 0;
st->left = 0;
}
else {
x= text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL);
x = text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL);
if (x==0 || x>winx)
st->left= text->curc-0.5*winx/st->cwidth;
if (x == 0 || x > winx)
st->left = text->curc - 0.5 * winx / st->cwidth;
}
if (st->top < 0) st->top= 0;
if (st->left <0) st->left= 0;
if (st->top < 0) st->top = 0;
if (st->left < 0) st->left = 0;
}
void text_update_cursor_moved(bContext *C)
{
ScrArea *sa= CTX_wm_area(C);
SpaceText *st= CTX_wm_space_text(C);
ScrArea *sa = CTX_wm_area(C);
SpaceText *st = CTX_wm_space_text(C);
text_scroll_to_cursor(st, sa);
}

View File

@@ -68,7 +68,7 @@
#include "text_intern.h"
#define HEADER_PATH_MAX 260
#define HEADER_PATH_MAX 260
/* ************************ header area region *********************** */
@@ -78,20 +78,20 @@ static ARegion *text_has_properties_region(ScrArea *sa)
{
ARegion *ar, *arnew;
ar= BKE_area_find_region_type(sa, RGN_TYPE_UI);
ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
if (ar) return ar;
/* add subdiv level; after header */
ar= BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
/* is error! */
if (ar==NULL) return NULL;
if (ar == NULL) return NULL;
arnew= MEM_callocN(sizeof(ARegion), "properties region");
arnew = MEM_callocN(sizeof(ARegion), "properties region");
BLI_insertlinkafter(&sa->regionbase, ar, arnew);
arnew->regiontype= RGN_TYPE_UI;
arnew->alignment= RGN_ALIGN_LEFT;
arnew->regiontype = RGN_TYPE_UI;
arnew->alignment = RGN_ALIGN_LEFT;
arnew->flag = RGN_FLAG_HIDDEN;
@@ -105,8 +105,8 @@ static int text_properties_poll(bContext *C)
static int text_properties_exec(bContext *C, wmOperator *UNUSED(op))
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= text_has_properties_region(sa);
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = text_has_properties_region(sa);
if (ar)
ED_region_toggle_hidden(C, ar);
@@ -135,7 +135,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPopupMenu *pup;
if (text) {
pup= uiPupMenuBegin(C, "Text", ICON_NONE);
pup = uiPupMenuBegin(C, "Text", ICON_NONE);
if (txt_has_sel(text)) {
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
@@ -149,7 +149,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPupMenuEnd(C, pup);
}
else {
pup= uiPupMenuBegin(C, "File", ICON_NONE);
pup = uiPupMenuBegin(C, "File", ICON_NONE);
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
uiPupMenuEnd(C, pup);
@@ -161,7 +161,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPopupMenu *pup;
pup= uiPupMenuBegin(C, "Edit", ICON_NONE);
pup = uiPupMenuBegin(C, "Edit", ICON_NONE);
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_paste");
@@ -174,7 +174,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPopupMenu *pup;
if (text) {
pup= uiPupMenuBegin(C, "Text", ICON_NONE);
pup = uiPupMenuBegin(C, "Text", ICON_NONE);
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_save");
@@ -183,7 +183,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPupMenuEnd(C, pup);
}
else {
pup= uiPupMenuBegin(C, "File", ICON_NONE);
pup = uiPupMenuBegin(C, "File", ICON_NONE);
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
uiPupMenuEnd(C, pup);
@@ -195,7 +195,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPopupMenu *pup;
pup= uiPupMenuBegin(C, "Text", ICON_NONE);
pup = uiPupMenuBegin(C, "Text", ICON_NONE);
uiItemEnumO(layout, "TEXT_OT_move", "Top of File", 0, "type", FILE_TOP);
uiItemEnumO(layout, "TEXT_OT_move", "Bottom of File", 0, "type", FILE_BOTTOM);
uiItemEnumO(layout, "TEXT_OT_move", "Page Up", 0, "type", PREV_PAGE);

View File

@@ -87,7 +87,7 @@ static int text_new_poll(bContext *UNUSED(C))
static int text_edit_poll(bContext *C)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (!text)
return 0;
@@ -102,8 +102,8 @@ static int text_edit_poll(bContext *C)
static int text_space_edit_poll(bContext *C)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
if (!st || !text)
return 0;
@@ -118,9 +118,9 @@ static int text_space_edit_poll(bContext *C)
static int text_region_edit_poll(bContext *C)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
ARegion *ar= CTX_wm_region(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
ARegion *ar = CTX_wm_region(C);
if (!st || !text)
return 0;
@@ -146,7 +146,7 @@ void text_update_line_edited(TextLine *line)
/* we just free format here, and let it rebuild during draw */
if (line->format) {
MEM_freeN(line->format);
line->format= NULL;
line->format = NULL;
}
}
@@ -154,7 +154,7 @@ void text_update_edited(Text *text)
{
TextLine *line;
for (line=text->lines.first; line; line=line->next)
for (line = text->lines.first; line; line = line->next)
text_update_line_edited(line);
}
@@ -162,12 +162,12 @@ void text_update_edited(Text *text)
static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text;
PointerRNA ptr, idptr;
PropertyRNA *prop;
text= add_empty_text("Text");
text = add_empty_text("Text");
/* hook into UI */
uiIDContextProperty(C, &ptr, &prop);
@@ -176,7 +176,7 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
/* when creating new ID blocks, use is already 1, but RNA
* pointer se also increases user, so this compensates it */
/* doesnt always seem to happen... (ton) */
if (text->id.us>1)
if (text->id.us > 1)
text->id.us--;
RNA_id_pointer_create(&text->id, &idptr);
@@ -184,12 +184,12 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
RNA_property_update(C, &ptr, prop);
}
else if (st) {
st->text= text;
st->top= 0;
st->text = text;
st->top = 0;
text_drawcache_tag_update(st, 1);
}
WM_event_add_notifier(C, NC_TEXT|NA_ADDED, text);
WM_event_add_notifier(C, NC_TEXT | NA_ADDED, text);
return OPERATOR_FINISHED;
}
@@ -215,7 +215,7 @@ static void text_open_init(bContext *C, wmOperator *op)
{
PropertyPointerRNA *pprop;
op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
op->customdata = pprop = MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
}
@@ -227,7 +227,7 @@ static int text_open_cancel(bContext *UNUSED(C), wmOperator *op)
static int text_open_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text;
PropertyPointerRNA *pprop;
PointerRNA idptr;
@@ -236,7 +236,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "filepath", str);
text= add_text(str, G.main->name);
text = add_text(str, G.main->name);
if (!text) {
if (op->customdata) MEM_freeN(op->customdata);
@@ -247,7 +247,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
text_open_init(C, op);
/* hook into UI */
pprop= op->customdata;
pprop = op->customdata;
if (pprop->prop) {
/* when creating new ID blocks, use is already 1, but RNA
@@ -259,8 +259,8 @@ static int text_open_exec(bContext *C, wmOperator *op)
RNA_property_update(C, &pprop->ptr, pprop->prop);
}
else if (st) {
st->text= text;
st->top= 0;
st->text = text;
st->top = 0;
}
if (internal) {
@@ -271,7 +271,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
}
text_drawcache_tag_update(st, 1);
WM_event_add_notifier(C, NC_TEXT|NA_ADDED, text);
WM_event_add_notifier(C, NC_TEXT | NA_ADDED, text);
MEM_freeN(op->customdata);
@@ -280,8 +280,8 @@ static int text_open_exec(bContext *C, wmOperator *op)
static int text_open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
Text *text= CTX_data_edit_text(C);
char *path= (text && text->name)? text->name: G.main->name;
Text *text = CTX_data_edit_text(C);
char *path = (text && text->name) ? text->name : G.main->name;
if (RNA_struct_property_is_set(op->ptr, "filepath"))
return text_open_exec(C, op);
@@ -310,7 +310,7 @@ void TEXT_OT_open(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
/* properties */
WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE|PYSCRIPTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path
WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE | PYSCRIPTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path
RNA_def_boolean(ot->srna, "internal", 0, "Make internal", "Make text file internal after loading");
}
@@ -318,7 +318,7 @@ void TEXT_OT_open(wmOperatorType *ot)
static int text_reload_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (!reopen_text(text)) {
BKE_report(op->reports, RPT_ERROR, "Could not reopen file");
@@ -333,7 +333,7 @@ static int text_reload_exec(bContext *C, wmOperator *op)
text_update_edited(text);
text_update_cursor_moved(C);
text_drawcache_tag_update(CTX_wm_space_text(C), 1);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -361,21 +361,21 @@ static int text_unlink_poll(bContext *C)
static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain= CTX_data_main(C);
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
Main *bmain = CTX_data_main(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
/* make the previous text active, if its not there make the next text active */
if (st) {
if (text->id.prev) {
st->text = text->id.prev;
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
else if (text->id.next) {
st->text = text->id.next;
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
}
@@ -383,7 +383,7 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
free_libblock(&bmain->text, text);
text_drawcache_tag_update(st, 1);
WM_event_add_notifier(C, NC_TEXT|NA_REMOVED, NULL);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, NULL);
return OPERATOR_FINISHED;
}
@@ -408,17 +408,17 @@ void TEXT_OT_unlink(wmOperatorType *ot)
static int text_make_internal_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
text->flags |= TXT_ISMEM | TXT_ISDIRTY;
if (text->name) {
MEM_freeN(text->name);
text->name= NULL;
text->name = NULL;
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -442,7 +442,7 @@ void TEXT_OT_make_internal(wmOperatorType *ot)
static int text_save_poll(bContext *C)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (!text_edit_poll(C))
return 0;
@@ -460,27 +460,27 @@ static void txt_write_file(Text *text, ReportList *reports)
BLI_strncpy(filepath, text->name, FILE_MAX);
BLI_path_abs(filepath, G.main->name);
fp= BLI_fopen(filepath, "w");
if (fp==NULL) {
fp = BLI_fopen(filepath, "w");
if (fp == NULL) {
BKE_reportf(reports, RPT_ERROR, "Unable to save \"%s\": %s", filepath, errno ? strerror(errno) : "Unknown error writing file");
return;
}
tmp= text->lines.first;
tmp = text->lines.first;
while (tmp) {
if (tmp->next) fprintf(fp, "%s\n", tmp->line);
else fprintf(fp, "%s", tmp->line);
tmp= tmp->next;
tmp = tmp->next;
}
fclose (fp);
fclose(fp);
if (stat(filepath, &st) == 0) {
text->mtime= st.st_mtime;
text->mtime = st.st_mtime;
}
else {
text->mtime= 0;
text->mtime = 0;
BKE_reportf(reports, RPT_WARNING, "Unable to stat \"%s\": %s", filepath, errno ? strerror(errno) : "Unknown error starrng file");
}
@@ -490,12 +490,12 @@ static void txt_write_file(Text *text, ReportList *reports)
static int text_save_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
txt_write_file(text, op->reports);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -516,7 +516,7 @@ void TEXT_OT_save(wmOperatorType *ot)
static int text_save_as_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
char str[FILE_MAX];
if (!text)
@@ -525,31 +525,31 @@ static int text_save_as_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "filepath", str);
if (text->name) MEM_freeN(text->name);
text->name= BLI_strdup(str);
text->name = BLI_strdup(str);
text->flags &= ~TXT_ISMEM;
txt_write_file(text, op->reports);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
static int text_save_as_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
char *str;
if (RNA_struct_property_is_set(op->ptr, "filepath"))
return text_save_as_exec(C, op);
if (text->name)
str= text->name;
str = text->name;
else if (text->flags & TXT_ISMEM)
str= text->id.name+2;
str = text->id.name + 2;
else
str= G.main->name;
str = G.main->name;
RNA_string_set(op->ptr, "filepath", str);
WM_event_add_fileselect(C, op);
@@ -570,7 +570,7 @@ void TEXT_OT_save_as(wmOperatorType *ot)
ot->poll = text_edit_poll;
/* properties */
WM_operator_properties_filesel(ot, FOLDERFILE|TEXTFILE|PYSCRIPTFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path
WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE | PYSCRIPTFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path
}
/******************* run script operator *********************/
@@ -583,17 +583,17 @@ static int text_run_script_poll(bContext *C)
static int text_run_script(bContext *C, ReportList *reports)
{
#ifdef WITH_PYTHON
Text *text= CTX_data_edit_text(C);
const short is_live= (reports == NULL);
Text *text = CTX_data_edit_text(C);
const short is_live = (reports == NULL);
/* only for comparison */
void *curl_prev= text->curl;
int curc_prev= text->curc;
void *curl_prev = text->curl;
int curc_prev = text->curc;
if (BPY_text_exec(C, text, reports, !is_live)) {
if (is_live) {
/* for nice live updates */
WM_event_add_notifier(C, NC_WINDOW|NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
}
return OPERATOR_FINISHED;
}
@@ -602,7 +602,7 @@ static int text_run_script(bContext *C, ReportList *reports)
if (!is_live) {
if (text->curl != curl_prev || curc_prev != text->curc) {
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
}
BKE_report(reports, RPT_ERROR, "Python script fail, look in the console for now...");
@@ -639,7 +639,7 @@ void TEXT_OT_run_script(wmOperatorType *ot)
ot->exec = text_run_script_exec;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/******************* refresh pyconstraints operator *********************/
@@ -648,31 +648,31 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS
{
#ifdef WITH_PYTHON
#if 0
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
Object *ob;
bConstraint *con;
short update;
/* check all pyconstraints */
for (ob= CTX_data_main(C)->object.first; ob; ob= ob->id.next) {
for (ob = CTX_data_main(C)->object.first; ob; ob = ob->id.next) {
update = 0;
if (ob->type==OB_ARMATURE && ob->pose) {
if (ob->type == OB_ARMATURE && ob->pose) {
bPoseChannel *pchan;
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
for (con = pchan->constraints.first; con; con= con->next) {
if (con->type==CONSTRAINT_TYPE_PYTHON) {
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
for (con = pchan->constraints.first; con; con = con->next) {
if (con->type == CONSTRAINT_TYPE_PYTHON) {
bPythonConstraint *data = con->data;
if (data->text==text) BPY_pyconstraint_update(ob, con);
if (data->text == text) BPY_pyconstraint_update(ob, con);
update = 1;
}
}
}
}
for (con = ob->constraints.first; con; con= con->next) {
if (con->type==CONSTRAINT_TYPE_PYTHON) {
for (con = ob->constraints.first; con; con = con->next) {
if (con->type == CONSTRAINT_TYPE_PYTHON) {
bPythonConstraint *data = con->data;
if (data->text==text) BPY_pyconstraint_update(ob, con);
if (data->text == text) BPY_pyconstraint_update(ob, con);
update = 1;
}
}
@@ -704,8 +704,8 @@ void TEXT_OT_refresh_pyconstraints(wmOperatorType *ot)
static char *txt_copy_selected(Text *text)
{
TextLine *tmp, *linef, *linel;
char *buf= NULL;
int charf, charl, length= 0;
char *buf = NULL;
int charf, charl, length = 0;
if (!text) return NULL;
if (!text->curl) return NULL;
@@ -713,71 +713,71 @@ static char *txt_copy_selected(Text *text)
if (!txt_has_sel(text)) return NULL;
if (text->curl==text->sell) {
linef= linel= text->curl;
if (text->curl == text->sell) {
linef = linel = text->curl;
if (text->curc < text->selc) {
charf= text->curc;
charl= text->selc;
charf = text->curc;
charl = text->selc;
}
else {
charf= text->selc;
charl= text->curc;
charf = text->selc;
charl = text->curc;
}
}
else if (txt_get_span(text->curl, text->sell)<0) {
linef= text->sell;
linel= text->curl;
else if (txt_get_span(text->curl, text->sell) < 0) {
linef = text->sell;
linel = text->curl;
charf= text->selc;
charl= text->curc;
charf = text->selc;
charl = text->curc;
}
else {
linef= text->curl;
linel= text->sell;
linef = text->curl;
linel = text->sell;
charf= text->curc;
charl= text->selc;
charf = text->curc;
charl = text->selc;
}
if (linef == linel) {
length= charl-charf;
length = charl - charf;
buf= MEM_callocN(length+1, "cut buffera");
buf = MEM_callocN(length + 1, "cut buffera");
BLI_strncpy(buf, linef->line + charf, length+1);
BLI_strncpy(buf, linef->line + charf, length + 1);
}
else {
length+= linef->len - charf;
length+= charl;
length += linef->len - charf;
length += charl;
length++; /* For the '\n' */
tmp= linef->next;
while (tmp && tmp!= linel) {
length+= tmp->len+1;
tmp= tmp->next;
tmp = linef->next;
while (tmp && tmp != linel) {
length += tmp->len + 1;
tmp = tmp->next;
}
buf= MEM_callocN(length+1, "cut bufferb");
buf = MEM_callocN(length + 1, "cut bufferb");
strncpy(buf, linef->line+ charf, linef->len-charf);
length= linef->len-charf;
strncpy(buf, linef->line + charf, linef->len - charf);
length = linef->len - charf;
buf[length++]='\n';
buf[length++] = '\n';
tmp= linef->next;
while (tmp && tmp!=linel) {
strncpy(buf+length, tmp->line, tmp->len);
length+= tmp->len;
tmp = linef->next;
while (tmp && tmp != linel) {
strncpy(buf + length, tmp->line, tmp->len);
length += tmp->len;
buf[length++]='\n';
buf[length++] = '\n';
tmp= tmp->next;
tmp = tmp->next;
}
strncpy(buf+length, linel->line, charl);
length+= charl;
strncpy(buf + length, linel->line, charl);
length += charl;
buf[length]=0;
buf[length] = 0;
}
return buf;
@@ -785,11 +785,11 @@ static char *txt_copy_selected(Text *text)
static int text_paste_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
char *buf;
int selection= RNA_boolean_get(op->ptr, "selection");
int selection = RNA_boolean_get(op->ptr, "selection");
buf= WM_clipboard_text_get(selection);
buf = WM_clipboard_text_get(selection);
if (!buf)
return OPERATOR_CANCELLED;
@@ -802,7 +802,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
MEM_freeN(buf);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit)
@@ -832,7 +832,7 @@ static void txt_copy_clipboard(Text *text)
{
char *buf;
buf= txt_copy_selected(text);
buf = txt_copy_selected(text);
if (buf) {
WM_clipboard_text_set(buf, 0);
@@ -842,7 +842,7 @@ static void txt_copy_clipboard(Text *text)
static int text_copy_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
txt_copy_clipboard(text);
@@ -865,7 +865,7 @@ void TEXT_OT_copy(wmOperatorType *ot)
static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -873,7 +873,7 @@ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
txt_delete_selected(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit)
@@ -898,7 +898,7 @@ void TEXT_OT_cut(wmOperatorType *ot)
static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -912,7 +912,7 @@ static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
text_update_edited(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -933,7 +933,7 @@ void TEXT_OT_indent(wmOperatorType *ot)
static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -944,7 +944,7 @@ static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
text_update_edited(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -968,18 +968,18 @@ void TEXT_OT_unindent(wmOperatorType *ot)
static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
int a, curts;
int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1;
text_drawcache_tag_update(st, 0);
// double check tabs/spaces before splitting the line
curts= setcurr_tab_spaces(text, space);
curts = setcurr_tab_spaces(text, space);
txt_split_curline(text);
for (a=0; a < curts; a++) {
for (a = 0; a < curts; a++) {
if (text->flags & TXT_TABSTOSPACES) {
txt_add_char(text, ' ');
}
@@ -995,7 +995,7 @@ static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_CANCELLED;
}
@@ -1016,7 +1016,7 @@ void TEXT_OT_line_break(wmOperatorType *ot)
static int text_comment_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -1026,7 +1026,7 @@ static int text_comment_exec(bContext *C, wmOperator *UNUSED(op))
text_update_edited(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1049,7 +1049,7 @@ void TEXT_OT_comment(wmOperatorType *ot)
static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -1059,7 +1059,7 @@ static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op))
text_update_edited(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1082,32 +1082,32 @@ void TEXT_OT_uncomment(wmOperatorType *ot)
/******************* convert whitespace operator *********************/
enum { TO_SPACES, TO_TABS };
static EnumPropertyItem whitespace_type_items[]= {
static EnumPropertyItem whitespace_type_items[] = {
{TO_SPACES, "SPACES", 0, "To Spaces", NULL},
{TO_TABS, "TABS", 0, "To Tabs", NULL},
{0, NULL, 0, NULL, NULL}};
static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
TextLine *tmp;
FlattenString fs;
size_t a, j;
char *text_check_line, *new_line;
int extra, number; //unknown for now
int type= RNA_enum_get(op->ptr, "type");
int type = RNA_enum_get(op->ptr, "type");
tmp = text->lines.first;
//first convert to all space, this make it a lot easier to convert to tabs because there is no mixtures of ' ' && '\t'
while (tmp) {
text_check_line = tmp->line;
number = flatten_string(st, &fs, text_check_line)+1;
number = flatten_string(st, &fs, text_check_line) + 1;
flatten_string_free(&fs);
new_line = MEM_callocN(number, "Converted_Line");
j = 0;
for (a=0; a < strlen(text_check_line); a++) { //foreach char in line
for (a = 0; a < strlen(text_check_line); a++) { //foreach char in line
if (text_check_line[a] == '\t') { //checking for tabs
//get the number of spaces this tabs is showing
//i don't like doing it this way but will look into it later
@@ -1115,8 +1115,8 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
number = flatten_string(st, &fs, new_line);
flatten_string_free(&fs);
new_line[j] = '\t';
new_line[j+1] = '\0';
number = flatten_string(st, &fs, new_line)-number;
new_line[j + 1] = '\0';
number = flatten_string(st, &fs, new_line) - number;
flatten_string_free(&fs);
for (extra = 0; extra < number; extra++) {
@@ -1150,26 +1150,26 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
for (a = 0; a < strlen(text_check_line); a++) {
number = 0;
for (j = 0; j < (size_t)st->tabnumber; j++) {
if ((a+j) <= strlen(text_check_line)) { //check to make sure we are not pass the end of the line
if (text_check_line[a+j] != ' ') {
if ((a + j) <= strlen(text_check_line)) { //check to make sure we are not pass the end of the line
if (text_check_line[a + j] != ' ') {
number = 1;
}
}
}
if (!number) { //found all number of space to equal a tab
a = a+(st->tabnumber-1);
extra = extra+1;
a = a + (st->tabnumber - 1);
extra = extra + 1;
}
}
if ( extra > 0 ) { //got tabs make malloc and do what you have to do
new_line = MEM_callocN(strlen(text_check_line)-(((st->tabnumber*extra)-extra)-1), "Converted_Line");
if (extra > 0) { //got tabs make malloc and do what you have to do
new_line = MEM_callocN(strlen(text_check_line) - (((st->tabnumber * extra) - extra) - 1), "Converted_Line");
extra = 0; //reuse vars
for (a = 0; a < strlen(text_check_line); a++) {
number = 0;
for (j = 0; j < (size_t)st->tabnumber; j++) {
if ((a+j) <= strlen(text_check_line)) { //check to make sure we are not pass the end of the line
if (text_check_line[a+j] != ' ') {
if ((a + j) <= strlen(text_check_line)) { //check to make sure we are not pass the end of the line
if (text_check_line[a + j] != ' ') {
number = 1;
}
}
@@ -1177,7 +1177,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
if (!number) { //found all number of space to equal a tab
new_line[extra] = '\t';
a = a+(st->tabnumber-1);
a = a + (st->tabnumber - 1);
++extra;
}
@@ -1202,7 +1202,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
text_update_edited(text);
text_update_cursor_moved(C);
text_drawcache_tag_update(st, 1);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1226,12 +1226,12 @@ void TEXT_OT_convert_whitespace(wmOperatorType *ot)
static int text_select_all_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
txt_sel_all(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1252,12 +1252,12 @@ void TEXT_OT_select_all(wmOperatorType *ot)
static int text_select_line_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
txt_sel_line(text);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1278,13 +1278,13 @@ void TEXT_OT_select_line(wmOperatorType *ot)
static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
txt_jump_left(text, 0);
txt_jump_right(text, 1);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1305,22 +1305,22 @@ void TEXT_OT_select_word(wmOperatorType *ot)
static int text_previous_marker_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
TextMarker *mrk;
int lineno;
lineno= txt_get_span(text->lines.first, text->curl);
mrk= text->markers.last;
while (mrk && (mrk->lineno>lineno || (mrk->lineno==lineno && mrk->end > text->curc)))
mrk= mrk->prev;
if (!mrk) mrk= text->markers.last;
lineno = txt_get_span(text->lines.first, text->curl);
mrk = text->markers.last;
while (mrk && (mrk->lineno > lineno || (mrk->lineno == lineno && mrk->end > text->curc)))
mrk = mrk->prev;
if (!mrk) mrk = text->markers.last;
if (mrk) {
txt_move_to(text, mrk->lineno, mrk->start, 0);
txt_move_to(text, mrk->lineno, mrk->end, 1);
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1341,22 +1341,22 @@ void TEXT_OT_previous_marker(wmOperatorType *ot)
static int text_next_marker_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
TextMarker *mrk;
int lineno;
lineno= txt_get_span(text->lines.first, text->curl);
mrk= text->markers.first;
while (mrk && (mrk->lineno<lineno || (mrk->lineno==lineno && mrk->start <= text->curc)))
mrk= mrk->next;
if (!mrk) mrk= text->markers.first;
lineno = txt_get_span(text->lines.first, text->curl);
mrk = text->markers.first;
while (mrk && (mrk->lineno < lineno || (mrk->lineno == lineno && mrk->start <= text->curc)))
mrk = mrk->next;
if (!mrk) mrk = text->markers.first;
if (mrk) {
txt_move_to(text, mrk->lineno, mrk->start, 0);
txt_move_to(text, mrk->lineno, mrk->end, 1);
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1377,12 +1377,12 @@ void TEXT_OT_next_marker(wmOperatorType *ot)
static int text_clear_all_markers_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
txt_clear_markers(text, 0, 0);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -1401,7 +1401,7 @@ void TEXT_OT_markers_clear(wmOperatorType *ot)
/************************ move operator ************************/
static EnumPropertyItem move_type_items[]= {
static EnumPropertyItem move_type_items[] = {
{LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
{LINE_END, "LINE_END", 0, "Line End", ""},
{FILE_TOP, "FILE_TOP", 0, "File Top", ""},
@@ -1417,78 +1417,78 @@ static EnumPropertyItem move_type_items[]= {
{0, NULL, 0, NULL, NULL}};
/* get cursor position in line by relative wrapped line and column positions */
static int text_get_cursor_rel(SpaceText* st, ARegion *ar, TextLine *linein, int rell, int relc)
static int text_get_cursor_rel(SpaceText *st, ARegion *ar, TextLine *linein, int rell, int relc)
{
int i, j, start, end, max, chop, curs, loop, endj, found, selc;
char ch;
max= wrap_width(st, ar);
max = wrap_width(st, ar);
selc= start= endj= curs= found= 0;
end= max;
chop= loop= 1;
selc = start = endj = curs = found = 0;
end = max;
chop = loop = 1;
for (i=0, j=0; loop; j+=BLI_str_utf8_size(linein->line+j)) {
for (i = 0, j = 0; loop; j += BLI_str_utf8_size(linein->line + j)) {
int chars;
/* Mimic replacement of tabs */
ch= linein->line[j];
if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
ch = linein->line[j];
if (ch == '\t') {
chars = st->tabnumber - i % st->tabnumber;
ch = ' ';
}
else chars= 1;
else chars = 1;
while (chars--) {
if (rell==0 && i-start==relc) {
if (rell == 0 && i - start == relc) {
/* current position could be wrapped to next line */
/* this should be checked when end of current line would be reached */
selc= j;
found= 1;
selc = j;
found = 1;
}
else if (i-end==relc) {
curs= j;
else if (i - end == relc) {
curs = j;
}
if (i-start>=max) {
if (i - start >= max) {
if (found) {
/* exact cursor position was found, check if it's */
/* still on needed line (hasn't been wrapped) */
if (selc>endj && !chop) selc= endj;
loop= 0;
if (selc > endj && !chop) selc = endj;
loop = 0;
break;
}
if (chop) endj= j;
if (chop) endj = j;
start= end;
start = end;
end += max;
chop= 1;
chop = 1;
rell--;
if (rell==0 && i-start>=relc) {
selc= curs;
loop= 0;
if (rell == 0 && i - start >= relc) {
selc = curs;
loop = 0;
break;
}
}
else if (ch=='\0') {
if (!found) selc= linein->len;
loop= 0;
else if (ch == '\0') {
if (!found) selc = linein->len;
loop = 0;
break;
}
else if (ch==' ' || ch=='-') {
else if (ch == ' ' || ch == '-') {
if (found) {
loop= 0;
loop = 0;
break;
}
if (rell==0 && i-start>=relc) {
selc= curs;
loop= 0;
if (rell == 0 && i - start >= relc) {
selc = curs;
loop = 0;
break;
}
end= i+1;
endj= j;
chop= 0;
end = i + 1;
endj = j;
chop = 0;
}
i++;
}
@@ -1497,87 +1497,87 @@ static int text_get_cursor_rel(SpaceText* st, ARegion *ar, TextLine *linein, int
return selc;
}
static int cursor_skip_find_line(SpaceText* st, ARegion *ar,
int lines, TextLine **linep, int *charp, int *rell, int *relc)
static int cursor_skip_find_line(SpaceText *st, ARegion *ar,
int lines, TextLine **linep, int *charp, int *rell, int *relc)
{
int offl, offc, visible_lines;
wrap_offset_in_line(st, ar, *linep, *charp, &offl, &offc);
*relc= text_get_char_pos(st, (*linep)->line, *charp) + offc;
*rell= lines;
*relc = text_get_char_pos(st, (*linep)->line, *charp) + offc;
*rell = lines;
/* handle current line */
if (lines>0) {
visible_lines= text_get_visible_lines(st, ar, (*linep)->line);
if (lines > 0) {
visible_lines = text_get_visible_lines(st, ar, (*linep)->line);
if (*rell-visible_lines+offl>=0) {
if (*rell - visible_lines + offl >= 0) {
if (!(*linep)->next) {
if (offl < visible_lines-1) {
*rell= visible_lines-1;
if (offl < visible_lines - 1) {
*rell = visible_lines - 1;
return 1;
}
*charp= (*linep)->len;
*charp = (*linep)->len;
return 0;
}
*rell-= visible_lines-offl;
*linep=(*linep)->next;
*rell -= visible_lines - offl;
*linep = (*linep)->next;
}
else {
*rell+= offl;
*rell += offl;
return 1;
}
}
else {
if (*rell+offl<=0) {
if (*rell + offl <= 0) {
if (!(*linep)->prev) {
if (offl) {
*rell= 0;
*rell = 0;
return 1;
}
*charp= 0;
*charp = 0;
return 0;
}
*rell+= offl;
*linep=(*linep)->prev;
*rell += offl;
*linep = (*linep)->prev;
}
else {
*rell+= offl;
*rell += offl;
return 1;
}
}
/* skip lines and find destination line and offsets */
while (*linep) {
visible_lines= text_get_visible_lines(st, ar, (*linep)->line);
visible_lines = text_get_visible_lines(st, ar, (*linep)->line);
if (lines<0) { /* moving top */
if (*rell+visible_lines >= 0) {
*rell+= visible_lines;
if (lines < 0) { /* moving top */
if (*rell + visible_lines >= 0) {
*rell += visible_lines;
break;
}
if (!(*linep)->prev) {
*rell= 0;
*rell = 0;
break;
}
*rell+= visible_lines;
*linep=(*linep)->prev;
*rell += visible_lines;
*linep = (*linep)->prev;
}
else { /* moving bottom */
if (*rell-visible_lines < 0) break;
if (*rell - visible_lines < 0) break;
if (!(*linep)->next) {
*rell= visible_lines-1;
*rell = visible_lines - 1;
break;
}
*rell-= visible_lines;
*linep=(*linep)->next;
*rell -= visible_lines;
*linep = (*linep)->next;
}
}
@@ -1586,7 +1586,7 @@ static int cursor_skip_find_line(SpaceText* st, ARegion *ar,
static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
{
Text *text= st->text;
Text *text = st->text;
TextLine **linep;
int *charp;
int oldl, oldc, i, j, max, start, end, endj, chop, loop;
@@ -1594,67 +1594,67 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
text_update_character_width(st);
if (sel) linep= &text->sell, charp= &text->selc;
else linep= &text->curl, charp= &text->curc;
if (sel) linep = &text->sell, charp = &text->selc;
else linep = &text->curl, charp = &text->curc;
oldc= *charp;
oldl= txt_get_span(text->lines.first, *linep);
oldc = *charp;
oldl = txt_get_span(text->lines.first, *linep);
max= wrap_width(st, ar);
max = wrap_width(st, ar);
start= endj= 0;
end= max;
chop= loop= 1;
*charp= 0;
start = endj = 0;
end = max;
chop = loop = 1;
*charp = 0;
for (i=0, j=0; loop; j+=BLI_str_utf8_size((*linep)->line+j)) {
for (i = 0, j = 0; loop; j += BLI_str_utf8_size((*linep)->line + j)) {
int chars;
/* Mimic replacement of tabs */
ch= (*linep)->line[j];
if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
ch = (*linep)->line[j];
if (ch == '\t') {
chars = st->tabnumber - i % st->tabnumber;
ch = ' ';
}
else chars= 1;
else chars = 1;
while (chars--) {
if (i-start>=max) {
*charp= endj;
if (i - start >= max) {
*charp = endj;
if (j>=oldc) {
if (ch=='\0') *charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
if (j >= oldc) {
if (ch == '\0') *charp = txt_utf8_index_to_offset((*linep)->line, start);
loop = 0;
break;
}
if (chop) endj= j;
if (chop) endj = j;
start= end;
start = end;
end += max;
chop= 1;
chop = 1;
}
else if (ch==' ' || ch=='-' || ch=='\0') {
if (j>=oldc) {
*charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
else if (ch == ' ' || ch == '-' || ch == '\0') {
if (j >= oldc) {
*charp = txt_utf8_index_to_offset((*linep)->line, start);
loop = 0;
break;
}
end= i+1;
endj= j+1;
chop= 0;
end = i + 1;
endj = j + 1;
chop = 0;
}
i++;
}
}
if (!sel) txt_pop_sel(text);
txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, oldl, oldc, oldl, *charp);
txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, oldl, oldc, oldl, *charp);
}
static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
{
Text *text= st->text;
Text *text = st->text;
TextLine **linep;
int *charp;
int oldl, oldc, i, j, max, start, end, endj, chop, loop;
@@ -1662,134 +1662,134 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
text_update_character_width(st);
if (sel) linep= &text->sell, charp= &text->selc;
else linep= &text->curl, charp= &text->curc;
if (sel) linep = &text->sell, charp = &text->selc;
else linep = &text->curl, charp = &text->curc;
oldc= *charp;
oldl= txt_get_span(text->lines.first, *linep);
oldc = *charp;
oldl = txt_get_span(text->lines.first, *linep);
max= wrap_width(st, ar);
max = wrap_width(st, ar);
start= endj= 0;
end= max;
chop= loop= 1;
*charp= 0;
start = endj = 0;
end = max;
chop = loop = 1;
*charp = 0;
for (i=0, j=0; loop; j+=BLI_str_utf8_size((*linep)->line+j)) {
for (i = 0, j = 0; loop; j += BLI_str_utf8_size((*linep)->line + j)) {
int chars;
/* Mimic replacement of tabs */
ch= (*linep)->line[j];
if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
ch = (*linep)->line[j];
if (ch == '\t') {
chars = st->tabnumber - i % st->tabnumber;
ch = ' ';
}
else chars= 1;
else chars = 1;
while (chars--) {
if (i-start>=max) {
if (chop) endj= BLI_str_prev_char_utf8((*linep)->line+j)-(*linep)->line;
if (i - start >= max) {
if (chop) endj = BLI_str_prev_char_utf8((*linep)->line + j) - (*linep)->line;
if (endj>=oldc) {
if (ch=='\0') *charp= (*linep)->len;
else *charp= endj;
loop= 0;
if (endj >= oldc) {
if (ch == '\0') *charp = (*linep)->len;
else *charp = endj;
loop = 0;
break;
}
start= end;
start = end;
end += max;
chop= 1;
chop = 1;
}
else if (ch=='\0') {
*charp= (*linep)->len;
loop= 0;
else if (ch == '\0') {
*charp = (*linep)->len;
loop = 0;
break;
}
else if (ch==' ' || ch=='-') {
end= i+1;
endj= j;
chop= 0;
else if (ch == ' ' || ch == '-') {
end = i + 1;
endj = j;
chop = 0;
}
i++;
}
}
if (!sel) txt_pop_sel(text);
txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, oldl, oldc, oldl, *charp);
txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, oldl, oldc, oldl, *charp);
}
static void txt_wrap_move_up(SpaceText *st, ARegion *ar, short sel)
{
Text *text= st->text;
Text *text = st->text;
TextLine **linep;
int *charp;
int oldl, oldc, offl, offc, col, newl;
text_update_character_width(st);
if (sel) linep= &text->sell, charp= &text->selc;
else linep= &text->curl, charp= &text->curc;
if (sel) linep = &text->sell, charp = &text->selc;
else linep = &text->curl, charp = &text->curc;
/* store previous position */
oldc= *charp;
newl= oldl= txt_get_span(text->lines.first, *linep);
oldc = *charp;
newl = oldl = txt_get_span(text->lines.first, *linep);
wrap_offset_in_line(st, ar, *linep, *charp, &offl, &offc);
col= text_get_char_pos(st, (*linep)->line, *charp) + offc;
col = text_get_char_pos(st, (*linep)->line, *charp) + offc;
if (offl) {
*charp= text_get_cursor_rel(st, ar, *linep, offl-1, col);
newl= BLI_findindex(&text->lines, linep);
*charp = text_get_cursor_rel(st, ar, *linep, offl - 1, col);
newl = BLI_findindex(&text->lines, linep);
}
else {
if ((*linep)->prev) {
int visible_lines;
*linep= (*linep)->prev;
visible_lines= text_get_visible_lines(st, ar, (*linep)->line);
*charp= text_get_cursor_rel(st, ar, *linep, visible_lines-1, col);
*linep = (*linep)->prev;
visible_lines = text_get_visible_lines(st, ar, (*linep)->line);
*charp = text_get_cursor_rel(st, ar, *linep, visible_lines - 1, col);
newl--;
}
else *charp= 0;
else *charp = 0;
}
if (!sel) txt_pop_sel(text);
txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, oldl, oldc, newl, *charp);
txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, oldl, oldc, newl, *charp);
}
static void txt_wrap_move_down(SpaceText *st, ARegion *ar, short sel)
{
Text *text= st->text;
Text *text = st->text;
TextLine **linep;
int *charp;
int oldl, oldc, offl, offc, col, newl, visible_lines;
text_update_character_width(st);
if (sel) linep= &text->sell, charp= &text->selc;
else linep= &text->curl, charp= &text->curc;
if (sel) linep = &text->sell, charp = &text->selc;
else linep = &text->curl, charp = &text->curc;
/* store previous position */
oldc= *charp;
newl= oldl= txt_get_span(text->lines.first, *linep);
oldc = *charp;
newl = oldl = txt_get_span(text->lines.first, *linep);
wrap_offset_in_line(st, ar, *linep, *charp, &offl, &offc);
col= text_get_char_pos(st, (*linep)->line, *charp) + offc;
visible_lines= text_get_visible_lines(st, ar, (*linep)->line);
if (offl<visible_lines-1) {
*charp= text_get_cursor_rel(st, ar, *linep, offl+1, col);
newl= BLI_findindex(&text->lines, linep);
col = text_get_char_pos(st, (*linep)->line, *charp) + offc;
visible_lines = text_get_visible_lines(st, ar, (*linep)->line);
if (offl < visible_lines - 1) {
*charp = text_get_cursor_rel(st, ar, *linep, offl + 1, col);
newl = BLI_findindex(&text->lines, linep);
}
else {
if ((*linep)->next) {
*linep= (*linep)->next;
*charp= text_get_cursor_rel(st, ar, *linep, 0, col);
*linep = (*linep)->next;
*charp = text_get_cursor_rel(st, ar, *linep, 0, col);
newl++;
}
else *charp= (*linep)->len;
else *charp = (*linep)->len;
}
if (!sel) txt_pop_sel(text);
txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, oldl, oldc, newl, *charp);
txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, oldl, oldc, newl, *charp);
}
/* Moves the cursor vertically by the specified number of lines.
@@ -1798,51 +1798,51 @@ static void txt_wrap_move_down(SpaceText *st, ARegion *ar, short sel)
*
* This is to replace screen_skip for PageUp/Down operations.
*/
static void cursor_skip(SpaceText* st, ARegion *ar, Text *text, int lines, int sel)
static void cursor_skip(SpaceText *st, ARegion *ar, Text *text, int lines, int sel)
{
TextLine **linep;
int oldl, oldc, *charp;
if (sel) linep= &text->sell, charp= &text->selc;
else linep= &text->curl, charp= &text->curc;
oldl= txt_get_span(text->lines.first, *linep);
oldc= *charp;
if (sel) linep = &text->sell, charp = &text->selc;
else linep = &text->curl, charp = &text->curc;
oldl = txt_get_span(text->lines.first, *linep);
oldc = *charp;
if (st && ar && st->wordwrap) {
int rell, relc;
/* find line and offsets inside it needed to set cursor position */
if (cursor_skip_find_line(st, ar, lines, linep, charp, &rell, &relc))
*charp= text_get_cursor_rel (st, ar, *linep, rell, relc);
*charp = text_get_cursor_rel(st, ar, *linep, rell, relc);
}
else {
while (lines>0 && (*linep)->next) {
*linep= (*linep)->next;
while (lines > 0 && (*linep)->next) {
*linep = (*linep)->next;
lines--;
}
while (lines<0 && (*linep)->prev) {
*linep= (*linep)->prev;
while (lines < 0 && (*linep)->prev) {
*linep = (*linep)->prev;
lines++;
}
}
if (*charp > (*linep)->len) *charp= (*linep)->len;
if (*charp > (*linep)->len) *charp = (*linep)->len;
if (!sel) txt_pop_sel(text);
txt_undo_add_toop(text, sel?UNDO_STO:UNDO_CTO, oldl, oldc, txt_get_span(text->lines.first, *linep), *charp);
txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, oldl, oldc, txt_get_span(text->lines.first, *linep), *charp);
}
static int text_move_cursor(bContext *C, int type, int select)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
ARegion *ar= CTX_wm_region(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
ARegion *ar = CTX_wm_region(C);
/* ensure we have the right region, it's optional */
if (ar && ar->regiontype != RGN_TYPE_WINDOW)
ar= NULL;
ar = NULL;
switch(type) {
switch (type) {
case LINE_BEGIN:
if (st && st->wordwrap && ar) txt_wrap_move_bol(st, ar, select);
else txt_move_bol(text, select);
@@ -1899,14 +1899,14 @@ static int text_move_cursor(bContext *C, int type, int select)
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
return OPERATOR_FINISHED;
}
static int text_move_exec(bContext *C, wmOperator *op)
{
int type= RNA_enum_get(op->ptr, "type");
int type = RNA_enum_get(op->ptr, "type");
return text_move_cursor(C, type, 0);
}
@@ -1930,7 +1930,7 @@ void TEXT_OT_move(wmOperatorType *ot)
static int text_move_select_exec(bContext *C, wmOperator *op)
{
int type= RNA_enum_get(op->ptr, "type");
int type = RNA_enum_get(op->ptr, "type");
return text_move_cursor(C, type, 1);
}
@@ -1954,26 +1954,26 @@ void TEXT_OT_move_select(wmOperatorType *ot)
static int text_jump_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
int line= RNA_int_get(op->ptr, "line");
short nlines= txt_get_span(text->lines.first, text->lines.last)+1;
Text *text = CTX_data_edit_text(C);
int line = RNA_int_get(op->ptr, "line");
short nlines = txt_get_span(text->lines.first, text->lines.last) + 1;
if (line < 1)
txt_move_toline(text, 1, 0);
else if (line > nlines)
txt_move_toline(text, nlines-1, 0);
txt_move_toline(text, nlines - 1, 0);
else
txt_move_toline(text, line-1, 0);
txt_move_toline(text, line - 1, 0);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
return OPERATOR_FINISHED;
}
static int text_jump_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
return WM_operator_props_dialog_popup(C,op,200,100);
return WM_operator_props_dialog_popup(C, op, 200, 100);
}
@@ -1995,7 +1995,7 @@ void TEXT_OT_jump(wmOperatorType *ot)
/******************* delete operator **********************/
static EnumPropertyItem delete_type_items[]= {
static EnumPropertyItem delete_type_items[] = {
{DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
{DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
{DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
@@ -2004,8 +2004,8 @@ static EnumPropertyItem delete_type_items[]= {
static int text_delete_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
int type= RNA_enum_get(op->ptr, "type");
Text *text = CTX_data_edit_text(C);
int type = RNA_enum_get(op->ptr, "type");
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -2021,7 +2021,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
text_update_line_edited(text->curl);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
if (CTX_wm_space_text(C)->live_edit)
@@ -2049,11 +2049,11 @@ void TEXT_OT_delete(wmOperatorType *ot)
static int text_toggle_overwrite_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
st->overwrite= !st->overwrite;
st->overwrite = !st->overwrite;
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
return OPERATOR_FINISHED;
}
@@ -2079,11 +2079,11 @@ static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines)
st->top += lines;
last= text_get_total_lines(st, ar);
last= last - (st->viewlines/2);
last = text_get_total_lines(st, ar);
last = last - (st->viewlines / 2);
if (st->top>last) st->top= last;
if (st->top<0) st->top= 0;
if (st->top > last) st->top = last;
if (st->top < 0) st->top = 0;
}
/* quick enum for tsc->zone (scroller handles) */
@@ -2111,15 +2111,15 @@ static int text_scroll_poll(bContext *C)
static int text_scroll_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
ARegion *ar= CTX_wm_region(C);
SpaceText *st = CTX_wm_space_text(C);
ARegion *ar = CTX_wm_region(C);
int lines= RNA_int_get(op->ptr, "lines");
int lines = RNA_int_get(op->ptr, "lines");
if (lines == 0)
return OPERATOR_CANCELLED;
txt_screen_skip(st, ar, lines*U.wheellinescroll);
txt_screen_skip(st, ar, lines * U.wheellinescroll);
ED_area_tag_redraw(CTX_wm_area(C));
@@ -2128,56 +2128,56 @@ static int text_scroll_exec(bContext *C, wmOperator *op)
static void text_scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
ARegion *ar= CTX_wm_region(C);
TextScroll *tsc= op->customdata;
int mval[2]= {event->x, event->y};
SpaceText *st = CTX_wm_space_text(C);
ARegion *ar = CTX_wm_region(C);
TextScroll *tsc = op->customdata;
int mval[2] = {event->x, event->y};
short txtdelta[2] = {0, 0};
text_update_character_width(st);
if (tsc->first) {
tsc->old[0]= mval[0];
tsc->old[1]= mval[1];
tsc->first= 0;
tsc->old[0] = mval[0];
tsc->old[1] = mval[1];
tsc->first = 0;
}
tsc->delta[0]+= mval[0] - tsc->old[0];
tsc->delta[1]+= mval[1] - tsc->old[1];
tsc->delta[0] += mval[0] - tsc->old[0];
tsc->delta[1] += mval[1] - tsc->old[1];
if (!tsc->scrollbar) {
txtdelta[0]= -tsc->delta[0]/st->cwidth;
txtdelta[1]= tsc->delta[1]/st->lheight;
txtdelta[0] = -tsc->delta[0] / st->cwidth;
txtdelta[1] = tsc->delta[1] / st->lheight;
tsc->delta[0]%= st->cwidth;
tsc->delta[1]%= st->lheight;
tsc->delta[0] %= st->cwidth;
tsc->delta[1] %= st->lheight;
}
else {
txtdelta[1]= -tsc->delta[1]*st->pix_per_line;
tsc->delta[1]+= txtdelta[1]/st->pix_per_line;
txtdelta[1] = -tsc->delta[1] * st->pix_per_line;
tsc->delta[1] += txtdelta[1] / st->pix_per_line;
}
if (txtdelta[0] || txtdelta[1]) {
txt_screen_skip(st, ar, txtdelta[1]);
if (st->wordwrap) {
st->left= 0;
st->left = 0;
}
else {
st->left+= txtdelta[0];
if (st->left<0) st->left= 0;
st->left += txtdelta[0];
if (st->left < 0) st->left = 0;
}
ED_area_tag_redraw(CTX_wm_area(C));
}
tsc->old[0]= mval[0];
tsc->old[1]= mval[1];
tsc->old[0] = mval[0];
tsc->old[1] = mval[1];
}
static void scroll_exit(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
st->flags &= ~ST_SCROLL_SELECT;
MEM_freeN(op->customdata);
@@ -2185,11 +2185,11 @@ static void scroll_exit(bContext *C, wmOperator *op)
static int text_scroll_modal(bContext *C, wmOperator *op, wmEvent *event)
{
TextScroll *tsc= op->customdata;
SpaceText *st= CTX_wm_space_text(C);
ARegion *ar= CTX_wm_region(C);
TextScroll *tsc = op->customdata;
SpaceText *st = CTX_wm_space_text(C);
ARegion *ar = CTX_wm_region(C);
switch(event->type) {
switch (event->type) {
case MOUSEMOVE:
if (tsc->zone == SCROLLHANDLE_BAR)
text_scroll_apply(C, op, event);
@@ -2200,10 +2200,10 @@ static int text_scroll_modal(bContext *C, wmOperator *op, wmEvent *event)
if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
int last;
st->top+= st->viewlines * (tsc->zone==SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1);
st->top += st->viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1);
last= text_get_total_lines(st, ar);
last= last - (st->viewlines/2);
last = text_get_total_lines(st, ar);
last = last - (st->viewlines / 2);
CLAMP(st->top, 0, last);
@@ -2225,18 +2225,18 @@ static int text_scroll_cancel(bContext *C, wmOperator *op)
static int text_scroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
TextScroll *tsc;
if (RNA_struct_property_is_set(op->ptr, "lines"))
return text_scroll_exec(C, op);
tsc= MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc->first= 1;
tsc->zone= SCROLLHANDLE_BAR;
op->customdata= tsc;
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc->first = 1;
tsc->zone = SCROLLHANDLE_BAR;
op->customdata = tsc;
st->flags|= ST_SCROLL_SELECT;
st->flags |= ST_SCROLL_SELECT;
if (event->type == MOUSEPAN) {
text_update_character_width(st);
@@ -2244,8 +2244,8 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
tsc->old[0] = event->x;
tsc->old[1] = event->y;
/* Sensitivity of scroll set to 4pix per line/char */
tsc->delta[0] = (event->x - event->prevx)*st->cwidth/4;
tsc->delta[1] = (event->y - event->prevy)*st->lheight/4;
tsc->delta[0] = (event->x - event->prevx) * st->cwidth / 4;
tsc->delta[1] = (event->y - event->prevy) * st->lheight / 4;
tsc->first = 0;
tsc->scrollbar = 0;
text_scroll_apply(C, op, event);
@@ -2276,7 +2276,7 @@ void TEXT_OT_scroll(wmOperatorType *ot)
ot->poll = text_scroll_poll;
/* flags */
ot->flag = OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER;
/* properties */
RNA_def_int(ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll", -100, 100);
@@ -2287,9 +2287,9 @@ void TEXT_OT_scroll(wmOperatorType *ot)
static int text_region_scroll_poll(bContext *C)
{
/* same as text_region_edit_poll except it works on libdata too */
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
ARegion *ar= CTX_wm_region(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
ARegion *ar = CTX_wm_region(C);
if (!st || !text)
return 0;
@@ -2302,24 +2302,24 @@ static int text_region_scroll_poll(bContext *C)
static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
ARegion *ar= CTX_wm_region(C);
SpaceText *st = CTX_wm_space_text(C);
ARegion *ar = CTX_wm_region(C);
TextScroll *tsc;
const int *mval= event->mval;
int zone= -1;
const int *mval = event->mval;
int zone = -1;
if (RNA_struct_property_is_set(op->ptr, "lines"))
return text_scroll_exec(C, op);
/* verify we are in the right zone */
if (mval[0]>st->txtbar.xmin && mval[0]<st->txtbar.xmax) {
if (mval[1]>=st->txtbar.ymin && mval[1]<=st->txtbar.ymax) {
if (mval[0] > st->txtbar.xmin && mval[0] < st->txtbar.xmax) {
if (mval[1] >= st->txtbar.ymin && mval[1] <= st->txtbar.ymax) {
/* mouse inside scroll handle */
zone = SCROLLHANDLE_BAR;
}
else if (mval[1]>TXT_SCROLL_SPACE && mval[1]<ar->winy-TXT_SCROLL_SPACE) {
if (mval[1]<st->txtbar.ymin) zone= SCROLLHANDLE_MIN_OUTSIDE;
else zone= SCROLLHANDLE_MAX_OUTSIDE;
else if (mval[1] > TXT_SCROLL_SPACE && mval[1] < ar->winy - TXT_SCROLL_SPACE) {
if (mval[1] < st->txtbar.ymin) zone = SCROLLHANDLE_MIN_OUTSIDE;
else zone = SCROLLHANDLE_MAX_OUTSIDE;
}
}
@@ -2328,12 +2328,12 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_PASS_THROUGH;
}
tsc= MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc->first= 1;
tsc->scrollbar= 1;
tsc->zone= zone;
op->customdata= tsc;
st->flags|= ST_SCROLL_SELECT;
tsc = MEM_callocN(sizeof(TextScroll), "TextScroll");
tsc->first = 1;
tsc->scrollbar = 1;
tsc->zone = zone;
op->customdata = tsc;
st->flags |= ST_SCROLL_SELECT;
/* jump scroll, works in v2d but needs to be added here too :S */
if (event->type == MIDDLEMOUSE) {
@@ -2343,7 +2343,7 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
tsc->delta[0] = 0;
tsc->delta[1] = 0;
tsc->first = 0;
tsc->zone= SCROLLHANDLE_BAR;
tsc->zone = SCROLLHANDLE_BAR;
text_scroll_apply(C, op, event);
}
@@ -2387,9 +2387,9 @@ static int flatten_len(SpaceText *st, const char *str)
{
int i, total = 0;
for (i = 0; str[i]; i += BLI_str_utf8_size(str+i)) {
if (str[i]=='\t') {
total += st->tabnumber - total%st->tabnumber;
for (i = 0; str[i]; i += BLI_str_utf8_size(str + i)) {
if (str[i] == '\t') {
total += st->tabnumber - total % st->tabnumber;
}
else total++;
}
@@ -2400,9 +2400,9 @@ static int flatten_len(SpaceText *st, const char *str)
static int flatten_index_to_offset(SpaceText *st, const char *str, int index)
{
int i, j;
for (i= 0, j= 0; i < index; j += BLI_str_utf8_size(str+j))
if (str[j]=='\t')
i += st->tabnumber - i%st->tabnumber;
for (i = 0, j = 0; i < index; j += BLI_str_utf8_size(str + j))
if (str[j] == '\t')
i += st->tabnumber - i % st->tabnumber;
else
i++;
@@ -2416,7 +2416,7 @@ static TextLine *get_first_visible_line(SpaceText *st, ARegion *ar, int *y)
for (i = st->top; i > 0 && linep; ) {
int lines = text_get_visible_lines(st, ar, linep->line);
if (i-lines < 0) {
if (i - lines < 0) {
*y += i;
break;
}
@@ -2444,13 +2444,13 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
int j = 0, curs = 0, endj = 0; /* mem */
int chop = 1; /* flags */
for (; loop; j += BLI_str_utf8_size(linep->line+j)) {
for (; loop; j += BLI_str_utf8_size(linep->line + j)) {
int chars;
/* Mimic replacement of tabs */
ch = linep->line[j];
if (ch == '\t') {
chars = st->tabnumber - i%st->tabnumber;
chars = st->tabnumber - i % st->tabnumber;
ch = ' ';
}
else chars = 1;
@@ -2463,10 +2463,10 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
break;
/* Exactly at the cursor */
}
else if (y == 0 && i-start == x) {
else if (y == 0 && i - start == x) {
/* current position could be wrapped to next line */
/* this should be checked when end of current line would be reached */
charp = curs= j;
charp = curs = j;
found = 1;
/* Prepare curs for next wrap */
}
@@ -2477,7 +2477,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
if (found) {
/* exact cursor position was found, check if it's */
/* still on needed line (hasn't been wrapped) */
if (charp > endj && !chop && ch!='\0') charp = endj;
if (charp > endj && !chop && ch != '\0') charp = endj;
loop = 0;
break;
}
@@ -2490,7 +2490,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
y--;
chop = 1;
if (y == 0 && i-start >= x) {
if (y == 0 && i - start >= x) {
charp = curs;
loop = 0;
break;
@@ -2502,7 +2502,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
break;
}
if (y == 0 && i-start >= x) {
if (y == 0 && i - start >= x) {
charp = curs;
loop = 0;
break;
@@ -2542,14 +2542,14 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
{
Text *text= st->text;
Text *text = st->text;
text_update_character_width(st);
y= (ar->winy - 2 - y)/st->lheight;
y = (ar->winy - 2 - y) / st->lheight;
if (st->showlinenrs) x-= TXT_OFFSET+TEXTXLOC;
else x-= TXT_OFFSET;
if (st->showlinenrs) x -= TXT_OFFSET + TEXTXLOC;
else x -= TXT_OFFSET;
if (x<0) x= 0;
if (x < 0) x = 0;
x = text_pixel_x_to_index(st, x) + st->left;
if (st->wordwrap) {
@@ -2560,67 +2560,67 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int
int *charp;
int w;
if (sel) { linep= &text->sell; charp= &text->selc; }
else { linep= &text->curl; charp= &text->curc; }
if (sel) { linep = &text->sell; charp = &text->selc; }
else { linep = &text->curl; charp = &text->curc; }
y-= txt_get_span(text->lines.first, *linep) - st->top;
y -= txt_get_span(text->lines.first, *linep) - st->top;
if (y>0) {
while (y-- != 0) if ((*linep)->next) *linep= (*linep)->next;
if (y > 0) {
while (y-- != 0) if ((*linep)->next) *linep = (*linep)->next;
}
else if (y<0) {
while (y++ != 0) if ((*linep)->prev) *linep= (*linep)->prev;
else if (y < 0) {
while (y++ != 0) if ((*linep)->prev) *linep = (*linep)->prev;
}
w= flatten_len(st, (*linep)->line);
if (x<w) *charp= flatten_index_to_offset(st, (*linep)->line, x);
else *charp= (*linep)->len;
w = flatten_len(st, (*linep)->line);
if (x < w) *charp = flatten_index_to_offset(st, (*linep)->line, x);
else *charp = (*linep)->len;
}
if (!sel) txt_pop_sel(text);
}
static void text_cursor_set_apply(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
ARegion *ar= CTX_wm_region(C);
SetSelection *ssel= op->customdata;
SpaceText *st = CTX_wm_space_text(C);
ARegion *ar = CTX_wm_region(C);
SetSelection *ssel = op->customdata;
if (event->mval[1]<0 || event->mval[1]>ar->winy) {
int d= (ssel->old[1]-event->mval[1])*st->pix_per_line;
if (event->mval[1] < 0 || event->mval[1] > ar->winy) {
int d = (ssel->old[1] - event->mval[1]) * st->pix_per_line;
if (d) txt_screen_skip(st, ar, d);
text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1]<0?0:ar->winy, 1);
text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1] < 0 ? 0 : ar->winy, 1);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
else if (!st->wordwrap && (event->mval[0]<0 || event->mval[0]>ar->winx)) {
if (event->mval[0]>ar->winx) st->left++;
else if (event->mval[0]<0 && st->left>0) st->left--;
else if (!st->wordwrap && (event->mval[0] < 0 || event->mval[0] > ar->winx)) {
if (event->mval[0] > ar->winx) st->left++;
else if (event->mval[0] < 0 && st->left > 0) st->left--;
text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
// XXX PIL_sleep_ms(10);
}
else {
text_cursor_set_to_pos(st, ar, event->mval[0], event->mval[1], 1);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
ssel->old[0]= event->mval[0];
ssel->old[1]= event->mval[1];
ssel->old[0] = event->mval[0];
ssel->old[1] = event->mval[1];
}
}
static void text_cursor_set_exit(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= st->text;
SetSelection *ssel= op->customdata;
SpaceText *st = CTX_wm_space_text(C);
Text *text = st->text;
SetSelection *ssel = op->customdata;
int linep2, charp2;
char *buffer;
@@ -2630,35 +2630,35 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
MEM_freeN(buffer);
}
linep2= txt_get_span(st->text->lines.first, st->text->sell);
charp2= st->text->selc;
linep2 = txt_get_span(st->text->lines.first, st->text->sell);
charp2 = st->text->selc;
if (ssel->sell!=linep2 || ssel->selc!=charp2)
if (ssel->sell != linep2 || ssel->selc != charp2)
txt_undo_add_toop(st->text, UNDO_STO, ssel->sell, ssel->selc, linep2, charp2);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
MEM_freeN(ssel);
}
static int text_set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
SetSelection *ssel;
if (event->mval[0]>=st->txtbar.xmin)
if (event->mval[0] >= st->txtbar.xmin)
return OPERATOR_PASS_THROUGH;
op->customdata= MEM_callocN(sizeof(SetSelection), "SetCursor");
ssel= op->customdata;
ssel->selecting= RNA_boolean_get(op->ptr, "select");
op->customdata = MEM_callocN(sizeof(SetSelection), "SetCursor");
ssel = op->customdata;
ssel->selecting = RNA_boolean_get(op->ptr, "select");
ssel->old[0]= event->mval[0];
ssel->old[1]= event->mval[1];
ssel->old[0] = event->mval[0];
ssel->old[1] = event->mval[1];
ssel->sell= txt_get_span(st->text->lines.first, st->text->sell);
ssel->selc= st->text->selc;
ssel->sell = txt_get_span(st->text->lines.first, st->text->sell);
ssel->selc = st->text->selc;
WM_event_add_modal_handler(C, op);
@@ -2669,7 +2669,7 @@ static int text_set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event
static int text_set_selection_modal(bContext *C, wmOperator *op, wmEvent *event)
{
switch(event->type) {
switch (event->type) {
case LEFTMOUSE:
case MIDDLEMOUSE:
case RIGHTMOUSE:
@@ -2710,31 +2710,31 @@ void TEXT_OT_selection_set(wmOperatorType *ot)
static int text_cursor_set_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= st->text;
ARegion *ar= CTX_wm_region(C);
int x= RNA_int_get(op->ptr, "x");
int y= RNA_int_get(op->ptr, "y");
SpaceText *st = CTX_wm_space_text(C);
Text *text = st->text;
ARegion *ar = CTX_wm_region(C);
int x = RNA_int_get(op->ptr, "x");
int y = RNA_int_get(op->ptr, "y");
int oldl, oldc;
oldl= txt_get_span(text->lines.first, text->curl);
oldc= text->curc;
oldl = txt_get_span(text->lines.first, text->curl);
oldc = text->curc;
text_cursor_set_to_pos(st, ar, x, y, 0);
txt_undo_add_toop(text, UNDO_CTO, oldl, oldc, txt_get_span(text->lines.first, text->curl), text->curc);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, st->text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
return OPERATOR_PASS_THROUGH;
}
static int text_cursor_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
SpaceText *st = CTX_wm_space_text(C);
if (event->mval[0]>=st->txtbar.xmin)
if (event->mval[0] >= st->txtbar.xmin)
return OPERATOR_PASS_THROUGH;
RNA_int_set(op->ptr, "x", event->mval[0]);
@@ -2764,37 +2764,37 @@ void TEXT_OT_cursor_set(wmOperatorType *ot)
static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
ARegion *ar= CTX_wm_region(C);
const int *mval= event->mval;
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
ARegion *ar = CTX_wm_region(C);
const int *mval = event->mval;
double time;
static int jump_to= 0;
static double last_jump= 0;
static int jump_to = 0;
static double last_jump = 0;
text_update_character_width(st);
if (!st->showlinenrs)
return OPERATOR_PASS_THROUGH;
if (!(mval[0]>2 && mval[0]<(TXT_OFFSET + TEXTXLOC) && mval[1]>2 && mval[1]<ar->winy-2))
if (!(mval[0] > 2 && mval[0] < (TXT_OFFSET + TEXTXLOC) && mval[1] > 2 && mval[1] < ar->winy - 2))
return OPERATOR_PASS_THROUGH;
if (!(event->ascii>='0' && event->ascii<='9'))
if (!(event->ascii >= '0' && event->ascii <= '9'))
return OPERATOR_PASS_THROUGH;
time = PIL_check_seconds_timer();
if (last_jump < time-1)
jump_to= 0;
if (last_jump < time - 1)
jump_to = 0;
jump_to *= 10;
jump_to += (int)(event->ascii-'0');
jump_to += (int)(event->ascii - '0');
txt_move_toline(text, jump_to-1, 0);
last_jump= time;
txt_move_toline(text, jump_to - 1, 0);
last_jump = time;
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
return OPERATOR_FINISHED;
}
@@ -2815,8 +2815,8 @@ void TEXT_OT_line_number(wmOperatorType *ot)
static int text_insert_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
char *str;
int done = 0;
size_t i = 0;
@@ -2824,7 +2824,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
text_drawcache_tag_update(st, 0);
str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
if (st && st->overwrite) {
while (str[i]) {
@@ -2847,7 +2847,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
text_update_line_edited(text->curl);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
return OPERATOR_FINISHED;
}
@@ -2863,7 +2863,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_PASS_THROUGH;
}
else {
char str[BLI_UTF8_MAX+1];
char str[BLI_UTF8_MAX + 1];
size_t len;
if (event->utf8_buf[0]) {
@@ -2874,7 +2874,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
/* in theory, ghost can set value to extended ascii here */
len = BLI_str_utf8_from_unicode(event->ascii, str);
}
str[len]= '\0';
str[len] = '\0';
RNA_string_set(op->ptr, "text", str);
}
}
@@ -2882,7 +2882,7 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
ret = text_insert_exec(C, op);
/* run the script while editing, evil but useful */
if (ret==OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit)
if (ret == OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit)
text_run_script(C, NULL);
return ret;
@@ -2910,97 +2910,97 @@ void TEXT_OT_insert(wmOperatorType *ot)
/******************* find operator *********************/
/* mode */
#define TEXT_FIND 0
#define TEXT_REPLACE 1
#define TEXT_MARK_ALL 2
#define TEXT_FIND 0
#define TEXT_REPLACE 1
#define TEXT_MARK_ALL 2
static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
{
Main *bmain= CTX_data_main(C);
SpaceText *st= CTX_wm_space_text(C);
Text *start= NULL, *text= st->text;
int flags, first= 1;
Main *bmain = CTX_data_main(C);
SpaceText *st = CTX_wm_space_text(C);
Text *start = NULL, *text = st->text;
int flags, first = 1;
int found = 0;
char *tmp;
if (!st->findstr[0] || (mode == TEXT_REPLACE && !st->replacestr[0]))
return OPERATOR_CANCELLED;
flags= st->flags;
flags = st->flags;
if (flags & ST_FIND_ALL)
flags ^= ST_FIND_WRAP;
do {
int proceed= 0;
int proceed = 0;
if (first) {
if (text->markers.first)
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
txt_clear_markers(text, TMARK_GRP_FINDALL, 0);
}
first= 0;
first = 0;
/* Replace current */
if (mode!=TEXT_FIND && txt_has_sel(text)) {
tmp= txt_sel_to_buf(text);
if (mode != TEXT_FIND && txt_has_sel(text)) {
tmp = txt_sel_to_buf(text);
if (flags & ST_MATCH_CASE) proceed= strcmp(st->findstr, tmp)==0;
else proceed= BLI_strcasecmp(st->findstr, tmp)==0;
if (flags & ST_MATCH_CASE) proceed = strcmp(st->findstr, tmp) == 0;
else proceed = BLI_strcasecmp(st->findstr, tmp) == 0;
if (proceed) {
if (mode==TEXT_REPLACE) {
if (mode == TEXT_REPLACE) {
txt_insert_buf(text, st->replacestr);
if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format= NULL;
text->curl->format = NULL;
}
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
text_drawcache_tag_update(CTX_wm_space_text(C), 1);
}
else if (mode==TEXT_MARK_ALL) {
else if (mode == TEXT_MARK_ALL) {
unsigned char color[4];
UI_GetThemeColor4ubv(TH_SHADE2, color);
if (txt_find_marker(text, text->curl, text->selc, TMARK_GRP_FINDALL, 0)) {
if (tmp) MEM_freeN(tmp), tmp=NULL;
if (tmp) MEM_freeN(tmp), tmp = NULL;
break;
}
txt_add_marker(text, text->curl, text->curc, text->selc, color, TMARK_GRP_FINDALL, TMARK_EDITALL);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
}
}
MEM_freeN(tmp);
tmp= NULL;
tmp = NULL;
}
/* Find next */
if (txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) {
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
}
else if (flags & ST_FIND_ALL) {
if (text==start) break;
if (!start) start= text;
if (text == start) break;
if (!start) start = text;
if (text->id.next)
text= st->text= text->id.next;
text = st->text = text->id.next;
else
text= st->text= bmain->text.first;
text = st->text = bmain->text.first;
txt_move_toline(text, 0, 0);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
first= 1;
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, text);
first = 1;
}
else {
if (!found && !proceed) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr);
break;
}
found = 1;
} while (mode==TEXT_MARK_ALL);
} while (mode == TEXT_MARK_ALL);
return OPERATOR_FINISHED;
}
@@ -3064,11 +3064,11 @@ void TEXT_OT_mark_all(wmOperatorType *ot)
static int text_find_set_selected_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp= txt_sel_to_buf(text);
tmp = txt_sel_to_buf(text);
BLI_strncpy(st->findstr, tmp, ST_MAX_FIND_STR);
MEM_freeN(tmp);
@@ -3094,11 +3094,11 @@ void TEXT_OT_find_set_selected(wmOperatorType *ot)
static int text_replace_set_selected_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
SpaceText *st = CTX_wm_space_text(C);
Text *text = CTX_data_edit_text(C);
char *tmp;
tmp= txt_sel_to_buf(text);
tmp = txt_sel_to_buf(text);
BLI_strncpy(st->replacestr, tmp, ST_MAX_FIND_STR);
MEM_freeN(tmp);
@@ -3120,12 +3120,13 @@ void TEXT_OT_replace_set_selected(wmOperatorType *ot)
/****************** resolve conflict operator ******************/
enum { RESOLVE_IGNORE, RESOLVE_RELOAD, RESOLVE_SAVE, RESOLVE_MAKE_INTERNAL };
static EnumPropertyItem resolution_items[]= {
static EnumPropertyItem resolution_items[] = {
{RESOLVE_IGNORE, "IGNORE", 0, "Ignore", ""},
{RESOLVE_RELOAD, "RELOAD", 0, "Reload", ""},
{RESOLVE_SAVE, "SAVE", 0, "Save", ""},
{RESOLVE_MAKE_INTERNAL, "MAKE_INTERNAL", 0, "Make Internal", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
/* returns 0 if file on disk is the same or Text is in memory only
* returns 1 if file has been modified on disk since last local edit
@@ -3179,15 +3180,15 @@ static void text_ignore_modified(Text *text)
if (result == -1 || (st.st_mode & S_IFMT) != S_IFREG)
return;
text->mtime= st.st_mtime;
text->mtime = st.st_mtime;
}
static int text_resolve_conflict_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
int resolution= RNA_enum_get(op->ptr, "resolution");
Text *text = CTX_data_edit_text(C);
int resolution = RNA_enum_get(op->ptr, "resolution");
switch(resolution) {
switch (resolution) {
case RESOLVE_RELOAD:
return text_reload_exec(C, op);
case RESOLVE_SAVE:
@@ -3204,24 +3205,24 @@ static int text_resolve_conflict_exec(bContext *C, wmOperator *op)
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
uiPopupMenu *pup;
uiLayout *layout;
switch(text_file_modified(text)) {
switch (text_file_modified(text)) {
case 1:
if (text->flags & TXT_ISDIRTY) {
/* modified locally and externally, ahhh. offer more possibilites. */
pup= uiPupMenuBegin(C, "File Modified Outside and Inside Blender", ICON_NONE);
layout= uiPupMenuLayout(pup);
pup = uiPupMenuBegin(C, "File Modified Outside and Inside Blender", ICON_NONE);
layout = uiPupMenuLayout(pup);
uiItemEnumO_ptr(layout, op->type, "Reload from disk (ignore local changes)", 0, "resolution", RESOLVE_RELOAD);
uiItemEnumO_ptr(layout, op->type, "Save to disk (ignore outside changes)", 0, "resolution", RESOLVE_SAVE);
uiItemEnumO_ptr(layout, op->type, "Make text internal (separate copy)", 0, "resolution", RESOLVE_MAKE_INTERNAL);
uiPupMenuEnd(C, pup);
}
else {
pup= uiPupMenuBegin(C, "File Modified Outside Blender", ICON_NONE);
layout= uiPupMenuLayout(pup);
pup = uiPupMenuBegin(C, "File Modified Outside Blender", ICON_NONE);
layout = uiPupMenuLayout(pup);
uiItemEnumO_ptr(layout, op->type, "Reload from disk", 0, "resolution", RESOLVE_RELOAD);
uiItemEnumO_ptr(layout, op->type, "Make text internal (separate copy)", 0, "resolution", RESOLVE_MAKE_INTERNAL);
uiItemEnumO_ptr(layout, op->type, "Ignore", 0, "resolution", RESOLVE_IGNORE);
@@ -3229,8 +3230,8 @@ static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, wmEvent *UN
}
break;
case 2:
pup= uiPupMenuBegin(C, "File Deleted Outside Blender", ICON_NONE);
layout= uiPupMenuLayout(pup);
pup = uiPupMenuBegin(C, "File Deleted Outside Blender", ICON_NONE);
layout = uiPupMenuLayout(pup);
uiItemEnumO_ptr(layout, op->type, "Make text internal", 0, "resolution", RESOLVE_MAKE_INTERNAL);
uiItemEnumO_ptr(layout, op->type, "Recreate file", 0, "resolution", RESOLVE_SAVE);
uiPupMenuEnd(C, pup);
@@ -3260,8 +3261,8 @@ void TEXT_OT_resolve_conflict(wmOperatorType *ot)
static int text_to_3d_object_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
int split_lines= RNA_boolean_get(op->ptr, "split_lines");
Text *text = CTX_data_edit_text(C);
int split_lines = RNA_boolean_get(op->ptr, "split_lines");
ED_text_to_object(C, text, split_lines);
@@ -3280,7 +3281,7 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot)
ot->poll = text_edit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
RNA_def_boolean(ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text");
@@ -3291,20 +3292,20 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot)
void ED_text_undo_step(bContext *C, int step)
{
Text *text= CTX_data_edit_text(C);
Text *text = CTX_data_edit_text(C);
if (!text)
return;
if (step==1)
if (step == 1)
txt_do_undo(text);
else if (step==-1)
else if (step == -1)
txt_do_redo(text);
text_update_edited(text);
text_update_cursor_moved(C);
text_drawcache_tag_update(CTX_wm_space_text(C), 1);
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
}

View File

@@ -67,36 +67,36 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
return 0;
/* Count the visible lines to the cursor */
for (tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
if (l<0) return 0;
for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) ;
if (l < 0) return 0;
text_update_character_width(st);
if (st->showlinenrs) {
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
}
y = ar->winy - st->lheight*l - 2;
y = ar->winy - st->lheight * l - 2;
w = SUGG_LIST_WIDTH*st->cwidth + 20;
h = SUGG_LIST_SIZE*st->lheight + 8;
w = SUGG_LIST_WIDTH * st->cwidth + 20;
h = SUGG_LIST_SIZE * st->lheight + 8;
// XXX getmouseco_areawin(mval);
if (mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
if (mval[0] < x || x + w < mval[0] || mval[1] < y - h || y < mval[1])
return 0;
/* Work out which of the items is at the top of the visible list */
for (i=0, item=first; i<*top && item->next; i++, item=item->next);
for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;
/* Work out the target item index in the visible list */
tgti = (y-mval[1]-4) / st->lheight;
if (tgti<0 || tgti>SUGG_LIST_SIZE)
tgti = (y - mval[1] - 4) / st->lheight;
if (tgti < 0 || tgti > SUGG_LIST_SIZE)
return 1;
for (i=tgti; i>0 && item->next; i--, item=item->next);
for (i = tgti; i > 0 && item->next; i--, item = item->next) ;
if (item)
texttool_suggest_select(item);
return 1;
@@ -107,19 +107,19 @@ void text_pop_suggest_list(void)
SuggItem *item, *sel;
int *top, i;
item= texttool_suggest_first();
sel= texttool_suggest_selected();
top= texttool_suggest_top();
item = texttool_suggest_first();
sel = texttool_suggest_selected();
top = texttool_suggest_top();
i= 0;
i = 0;
while (item && item != sel) {
item= item->next;
item = item->next;
i++;
}
if (i > *top+SUGG_LIST_SIZE-1)
*top= i-SUGG_LIST_SIZE+1;
if (i > *top + SUGG_LIST_SIZE - 1)
*top = i - SUGG_LIST_SIZE + 1;
else if (i < *top)
*top= i;
*top = i;
}
static void get_suggest_prefix(Text *text, int offset)
@@ -130,25 +130,25 @@ static void get_suggest_prefix(Text *text, int offset)
if (!text) return;
if (!texttool_text_is_active(text)) return;
line= text->curl->line;
for (i=text->curc-1+offset; i>=0; i--)
line = text->curl->line;
for (i = text->curc - 1 + offset; i >= 0; i--)
if (!text_check_identifier(line[i]))
break;
i++;
len= text->curc-i+offset;
len = text->curc - i + offset;
if (len > 255) {
printf("Suggestion prefix too long\n");
len = 255;
}
BLI_strncpy(tmp, line+i, len);
tmp[len]= '\0';
BLI_strncpy(tmp, line + i, len);
tmp[len] = '\0';
texttool_suggest_prefix(tmp);
}
static void confirm_suggestion(Text *text, int skipleft)
{
SuggItem *sel;
int i, over=0;
int i, over = 0;
char *line;
if (!text) return;
@@ -157,23 +157,23 @@ static void confirm_suggestion(Text *text, int skipleft)
sel = texttool_suggest_selected();
if (!sel) return;
line= text->curl->line;
i=text->curc-skipleft-1;
while (i>=0) {
line = text->curl->line;
i = text->curc - skipleft - 1;
while (i >= 0) {
if (!text_check_identifier(line[i]))
break;
over++;
i--;
}
for (i=0; i<skipleft; i++)
for (i = 0; i < skipleft; i++)
txt_move_left(text, 0);
for (i=0; i<over; i++)
for (i = 0; i < over; i++)
txt_move_left(text, 1);
txt_insert_buf(text, sel->name);
for (i=0; i<skipleft; i++)
for (i = 0; i < skipleft; i++)
txt_move_right(text, 0);
texttool_text_clear();
@@ -189,13 +189,13 @@ static void confirm_suggestion(Text *text, int skipleft)
#define LR_OSKEY 0
// XXX
static int doc_scroll= 0;
static int doc_scroll = 0;
static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned short evnt, short val)
static short UNUSED_FUNCTION(do_texttools) (SpaceText * st, char ascii, unsigned short evnt, short val)
{
ARegion *ar= NULL; // XXX
int qual= 0; // XXX
int draw=0, tools=0, swallow=0, scroll=1;
ARegion *ar = NULL; // XXX
int qual = 0; // XXX
int draw = 0, tools = 0, swallow = 0, scroll = 1;
if (!texttool_text_is_active(st->text)) return 0;
if (!st->text || st->text->id.lib) return 0;
@@ -213,50 +213,50 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
else if ((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
get_suggest_prefix(st->text, 0);
text_pop_suggest_list();
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
}
}
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
}
else if (val==1 && evnt) {
else if (val == 1 && evnt) {
switch (evnt) {
case LEFTMOUSE:
if (text_do_suggest_select(st, ar))
swallow= 1;
swallow = 1;
else {
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
}
draw= 1;
draw = 1;
break;
case MIDDLEMOUSE:
if (text_do_suggest_select(st, ar)) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text->curl);
swallow= 1;
swallow = 1;
}
else {
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
}
draw= 1;
draw = 1;
break;
case ESCKEY:
draw= swallow= 1;
draw = swallow = 1;
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
else draw= swallow= 0;
else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
else draw = swallow = 0;
break;
case RETKEY:
if (tools & TOOL_SUGG_LIST) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text->curl);
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
}
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
break;
case LEFTARROWKEY:
case BACKSPACEKEY:
@@ -266,8 +266,8 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
else {
/* Work out which char we are about to delete/pass */
if (st->text->curl && st->text->curc > 0) {
char ch= st->text->curl->line[st->text->curc-1];
if ((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
char ch = st->text->curl->line[st->text->curc - 1];
if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
get_suggest_prefix(st->text, -1);
text_pop_suggest_list();
}
@@ -278,7 +278,7 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
texttool_suggest_clear();
}
}
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
break;
case RIGHTARROWKEY:
if (tools & TOOL_SUGG_LIST) {
@@ -287,8 +287,8 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
else {
/* Work out which char we are about to pass */
if (st->text->curl && st->text->curc < st->text->curl->len) {
char ch= st->text->curl->line[st->text->curc+1];
if ((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
char ch = st->text->curl->line[st->text->curc + 1];
if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
get_suggest_prefix(st->text, 1);
text_pop_suggest_list();
}
@@ -299,16 +299,16 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
texttool_suggest_clear();
}
}
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
break;
case PAGEDOWNKEY:
scroll= SUGG_LIST_SIZE-1;
scroll = SUGG_LIST_SIZE - 1;
case WHEELDOWNMOUSE:
case DOWNARROWKEY:
if (tools & TOOL_DOCUMENT) {
doc_scroll++;
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
break;
}
else if (tools & TOOL_SUGG_LIST) {
@@ -316,42 +316,44 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
if (!sel) {
texttool_suggest_select(texttool_suggest_first());
}
else while (sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
texttool_suggest_select(sel->next);
sel= sel->next;
else {
while (sel && sel != texttool_suggest_last() && sel->next && scroll--) {
texttool_suggest_select(sel->next);
sel = sel->next;
}
}
text_pop_suggest_list();
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
break;
}
case PAGEUPKEY:
scroll= SUGG_LIST_SIZE-1;
scroll = SUGG_LIST_SIZE - 1;
case WHEELUPMOUSE:
case UPARROWKEY:
if (tools & TOOL_DOCUMENT) {
if (doc_scroll>0) doc_scroll--;
swallow= 1;
draw= 1;
if (doc_scroll > 0) doc_scroll--;
swallow = 1;
draw = 1;
break;
}
else if (tools & TOOL_SUGG_LIST) {
SuggItem *sel = texttool_suggest_selected();
while (sel && sel!=texttool_suggest_first() && sel->prev && scroll--) {
while (sel && sel != texttool_suggest_first() && sel->prev && scroll--) {
texttool_suggest_select(sel->prev);
sel= sel->prev;
sel = sel->prev;
}
text_pop_suggest_list();
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
break;
}
case RIGHTSHIFTKEY:
case LEFTSHIFTKEY:
break;
default:
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw= 1;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw = 1;
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
}
}
@@ -364,75 +366,75 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
#if 0
#ifdef WITH_PYTHON
/* Run text plugin scripts if enabled */
if (st->doplugins && event && val) {
if (BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
do_draw= 1;
}
/* Run text plugin scripts if enabled */
if (st->doplugins && event && val) {
if (BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
do_draw = 1;
}
}
#endif
if (do_draw)
; // XXX redraw_alltext();
if (do_draw)
; // XXX redraw_alltext();
#endif
static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned short evnt, short val)
static short UNUSED_FUNCTION(do_textmarkers) (SpaceText * st, char ascii, unsigned short evnt, short val)
{
Text *text;
TextMarker *marker, *mrk, *nxt;
int c, s, draw=0, swallow=0;
int qual= 0; // XXX
int c, s, draw = 0, swallow = 0;
int qual = 0; // XXX
text= st->text;
text = st->text;
if (!text || text->id.lib || text->curl != text->sell) return 0;
marker= txt_find_marker(text, text->sell, text->selc, 0, 0);
marker = txt_find_marker(text, text->sell, text->selc, 0, 0);
if (marker && (marker->start > text->curc || marker->end < text->curc))
marker= NULL;
marker = NULL;
if (!marker) {
/* Find the next temporary marker */
if (evnt==TABKEY) {
int lineno= txt_get_span(text->lines.first, text->curl);
mrk= text->markers.first;
if (evnt == TABKEY) {
int lineno = txt_get_span(text->lines.first, text->curl);
mrk = text->markers.first;
while (mrk) {
if (!marker && (mrk->flags & TMARK_TEMP)) marker= mrk;
if ((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno==lineno && mrk->end > text->curc))) {
marker= mrk;
if (!marker && (mrk->flags & TMARK_TEMP)) marker = mrk;
if ((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno == lineno && mrk->end > text->curc))) {
marker = mrk;
break;
}
mrk= mrk->next;
mrk = mrk->next;
}
if (marker) {
txt_move_to(text, marker->lineno, marker->start, 0);
txt_move_to(text, marker->lineno, marker->end, 1);
// XXX text_update_cursor_moved(C);
// XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
evnt= ascii= val= 0;
draw= 1;
swallow= 1;
evnt = ascii = val = 0;
draw = 1;
swallow = 1;
}
}
else if (evnt==ESCKEY) {
if (txt_clear_markers(text, 0, TMARK_TEMP)) swallow= 1;
else if (txt_clear_markers(text, 0, 0)) swallow= 1;
else if (evnt == ESCKEY) {
if (txt_clear_markers(text, 0, TMARK_TEMP)) swallow = 1;
else if (txt_clear_markers(text, 0, 0)) swallow = 1;
else return 0;
evnt= ascii= val= 0;
draw= 1;
evnt = ascii = val = 0;
draw = 1;
}
if (!swallow) return 0;
}
if (ascii) {
if (marker->flags & TMARK_EDITALL) {
c= text->curc-marker->start;
s= text->selc-marker->start;
if (s<0 || s>marker->end-marker->start) return 0;
c = text->curc - marker->start;
s = text->selc - marker->start;
if (s < 0 || s > marker->end - marker->start) return 0;
mrk= txt_next_marker(text, marker);
mrk = txt_next_marker(text, marker);
while (mrk) {
nxt=txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
if (s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start + c, 0);
if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
if (st->overwrite) {
if (txt_replace_char(text, ascii))
text_update_line_edited(st->text->curl);
@@ -443,101 +445,101 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
}
}
if (mrk==marker || mrk==nxt) break;
mrk=nxt;
if (mrk == marker || mrk == nxt) break;
mrk = nxt;
}
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
}
}
else if (val) {
switch(evnt) {
switch (evnt) {
case BACKSPACEKEY:
if (marker->flags & TMARK_EDITALL) {
c= text->curc-marker->start;
s= text->selc-marker->start;
if (s<0 || s>marker->end-marker->start) return 0;
c = text->curc - marker->start;
s = text->selc - marker->start;
if (s < 0 || s > marker->end - marker->start) return 0;
mrk= txt_next_marker(text, marker);
mrk = txt_next_marker(text, marker);
while (mrk) {
nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
if (s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start + c, 0);
if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
txt_backspace_char(text);
text_update_line_edited(st->text->curl);
if (mrk==marker || mrk==nxt) break;
mrk= nxt;
if (mrk == marker || mrk == nxt) break;
mrk = nxt;
}
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
}
break;
case DELKEY:
if (marker->flags & TMARK_EDITALL) {
c= text->curc-marker->start;
s= text->selc-marker->start;
if (s<0 || s>marker->end-marker->start) return 0;
c = text->curc - marker->start;
s = text->selc - marker->start;
if (s < 0 || s > marker->end - marker->start) return 0;
mrk= txt_next_marker(text, marker);
mrk = txt_next_marker(text, marker);
while (mrk) {
nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
if (s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
txt_move_to(text, mrk->lineno, mrk->start + c, 0);
if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
txt_delete_char(text);
text_update_line_edited(st->text->curl);
if (mrk==marker || mrk==nxt) break;
mrk= nxt;
if (mrk == marker || mrk == nxt) break;
mrk = nxt;
}
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
}
break;
case TABKEY:
if (qual & LR_SHIFTKEY) {
nxt= marker->prev;
if (!nxt) nxt= text->markers.last;
nxt = marker->prev;
if (!nxt) nxt = text->markers.last;
}
else {
nxt= marker->next;
if (!nxt) nxt= text->markers.first;
nxt = marker->next;
if (!nxt) nxt = text->markers.first;
}
if (marker->flags & TMARK_TEMP) {
if (nxt==marker) nxt= NULL;
if (nxt == marker) nxt = NULL;
BLI_freelinkN(&text->markers, marker);
}
mrk= nxt;
mrk = nxt;
if (mrk) {
txt_move_to(text, mrk->lineno, mrk->start, 0);
txt_move_to(text, mrk->lineno, mrk->end, 1);
// XXX text_update_cursor_moved(C);
// XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
}
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
break;
/* Events that should clear markers */
case UKEY: if (!(qual & LR_ALTKEY)) break;
case ZKEY: if (evnt==ZKEY && !(qual & LR_CTRLKEY)) break;
case ZKEY: if (evnt == ZKEY && !(qual & LR_CTRLKEY)) break;
case RETKEY:
case ESCKEY:
if (marker->flags & (TMARK_EDITALL | TMARK_TEMP))
txt_clear_markers(text, marker->group, 0);
else
BLI_freelinkN(&text->markers, marker);
swallow= 1;
draw= 1;
swallow = 1;
draw = 1;
break;
case RIGHTMOUSE: /* Marker context menu? */
case LEFTMOUSE:
break;
case FKEY: /* Allow find */
if (qual & LR_SHIFTKEY) swallow= 1;
if (qual & LR_SHIFTKEY) swallow = 1;
break;
default:
if (qual!=0 && qual!=LR_SHIFTKEY)
swallow= 1; /* Swallow all other shortcut events */
if (qual != 0 && qual != LR_SHIFTKEY)
swallow = 1; /* Swallow all other shortcut events */
}
}