Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-03-24 10:38:07 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-03-24 10:38:07 +0400
commitab4a2aaf4a4b2b4e416aa1f113b30362cbe0dec3 (patch)
tree81af4c18519181490074508dbe9a8d515eab634f /source/blender/editors/space_text
parent5a90ea77bc1333efe4e1e54984a080550ed3f707 (diff)
style cleanup: follow style guide for formatting of if/for/while loops, and else if's
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r--source/blender/editors/space_text/space_text.c20
-rw-r--r--source/blender/editors/space_text/text_draw.c505
-rw-r--r--source/blender/editors/space_text/text_header.c12
-rw-r--r--source/blender/editors/space_text/text_ops.c551
-rw-r--r--source/blender/editors/space_text/text_python.c224
5 files changed, 670 insertions, 642 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index d06a8139b6f..cc9ce10d017 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -129,7 +129,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
/* 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
* case -- no way to know was text active before unlinking or not */
- if(wmn->reference && wmn->reference != st->text)
+ if (wmn->reference && wmn->reference != st->text)
break;
switch(wmn->data) {
@@ -137,7 +137,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
ED_area_tag_redraw(sa);
break;
case ND_CURSOR:
- if(st->text && st->text == wmn->reference)
+ if (st->text && st->text == wmn->reference)
text_scroll_to_cursor(st, sa);
ED_area_tag_redraw(sa);
@@ -146,7 +146,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
switch(wmn->action) {
case NA_EDITED:
- if(st->text) {
+ if (st->text) {
text_drawcache_tag_update(st, 1);
text_update_edited(st->text);
}
@@ -158,7 +158,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
ED_area_tag_redraw(sa);
break;
case NA_SELECTED:
- if(st->text && st->text == wmn->reference)
+ if (st->text && st->text == wmn->reference)
text_scroll_to_cursor(st, sa);
break;
@@ -166,7 +166,7 @@ static void text_listener(ScrArea *sa, wmNotifier *wmn)
break;
case NC_SPACE:
- if(wmn->data == ND_SPACE_TEXT)
+ if (wmn->data == ND_SPACE_TEXT)
ED_area_tag_redraw(sa);
break;
}
@@ -298,7 +298,7 @@ static void text_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0);
- if(U.uiflag & USER_MMB_PASTE) { // XXX not dynamic
+ if (U.uiflag & USER_MMB_PASTE) { // XXX not dynamic
kmi = WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "selection", TRUE);
}
@@ -388,11 +388,11 @@ static int text_context(const bContext *C, const char *member, bContextDataResul
{
SpaceText *st= CTX_wm_space_text(C);
- if(CTX_data_dir(member)) {
+ if (CTX_data_dir(member)) {
CTX_data_dir_set(result, text_context_dir);
return 1;
}
- else if(CTX_data_equals(member, "edit_text")) {
+ else if (CTX_data_equals(member, "edit_text")) {
CTX_data_id_pointer_set(result, &st->text->id);
return 1;
}
@@ -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;
}
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index 20f2654971b..b2259aac035 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -111,7 +111,7 @@ 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;
@@ -121,7 +121,7 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf));
memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum));
- if(fs->buf != fs->fixedbuf) {
+ if (fs->buf != fs->fixedbuf) {
MEM_freeN(fs->buf);
MEM_freeN(fs->accum);
}
@@ -148,12 +148,12 @@ int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
fs->accum= fs->fixedaccum;
fs->len = sizeof(fs->fixedbuf);
- for(r = 0, i = 0; *in; r++) {
- if(*in=='\t') {
+ for (r = 0, i = 0; *in; r++) {
+ if (*in=='\t') {
i= st->tabnumber - (total%st->tabnumber);
total+= i;
- while(i--)
+ while (i--)
flatten_string_append(fs, " ", r, 1);
in++;
@@ -173,9 +173,9 @@ int flatten_string(SpaceText *st, FlattenString *fs, const char *in)
void flatten_string_free(FlattenString *fs)
{
- if(fs->buf != fs->fixedbuf)
+ if (fs->buf != fs->fixedbuf)
MEM_freeN(fs->buf);
- if(fs->accum != fs->fixedaccum)
+ if (fs->accum != fs->fixedaccum)
MEM_freeN(fs->accum);
}
@@ -195,25 +195,25 @@ static int find_builtinfunc(char *string)
"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) {
+ 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]))
+ if (text_check_identifier(string[i]))
i = -1; /* No match */
break; /* Next keyword if no match, otherwise we're done */
/* 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,22 +229,22 @@ 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;
}
static int find_decorator(char *string)
{
- if(string[0] == '@') {
+ if (string[0] == '@') {
int i = 1;
- while(text_check_identifier(string[i])) {
+ while (text_check_identifier(string[i])) {
i++;
}
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;
}
@@ -274,16 +274,16 @@ static int find_bool(char *string)
* as needed. Allocation is done here, alone, to ensure consistency. */
static int text_check_format_len(TextLine *line, unsigned int len)
{
- if(line->format) {
- if(strlen(line->format) < len) {
+ if (line->format) {
+ if (strlen(line->format) < len) {
MEM_freeN(line->format);
line->format = MEM_mallocN(len+2, "SyntaxFormat");
- if(!line->format) return 0;
+ if (!line->format) return 0;
}
}
else {
line->format = MEM_mallocN(len+2, "SyntaxFormat");
- if(!line->format) return 0;
+ if (!line->format) return 0;
}
return 1;
@@ -310,14 +310,14 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
int len, i;
/* Get continuation from previous line */
- if(line->prev && line->prev->format != NULL) {
+ if (line->prev && line->prev->format != NULL) {
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) {
+ if (line->format != NULL) {
fmt= line->format;
orig = fmt[strlen(fmt)+1]; /* Just after the null-terminator */
}
@@ -325,26 +325,26 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
len = flatten_string(st, &fs, line->line);
str = fs.buf;
- if(!text_check_format_len(line, len)) {
+ if (!text_check_format_len(line, len)) {
flatten_string_free(&fs);
return;
}
fmt = line->format;
- while(*str) {
+ while (*str) {
/* Handle escape sequences by skipping both \ and next char */
- if(*str == '\\') {
+ if (*str == '\\') {
*fmt = prev; fmt++; str++;
- if(*str == '\0') break;
+ if (*str == '\0') break;
*fmt = prev; fmt++; str += BLI_str_utf8_size(str);
continue;
}
/* Handle continuations */
- else if(cont) {
+ else if (cont) {
/* Triple strings ("""...""" or '''...''') */
- if(cont & TXT_TRISTR) {
+ 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;
@@ -353,7 +353,7 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
}
else {
find = (cont & TXT_DBLQUOTSTR) ? '"' : '\'';
- if(*str == find) cont = 0;
+ if (*str == find) cont = 0;
}
*fmt = 'l';
@@ -362,14 +362,15 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
/* Not in a string... */
else {
/* Deal with comments first */
- if(prev == '#' || *str == '#') {
+ if (prev == '#' || *str == '#') {
*fmt = '#';
str += BLI_str_utf8_size(str) - 1;
- } else if(*str == '"' || *str == '\'') {
+ }
+ else if (*str == '"' || *str == '\'') {
/* Strings */
find = *str;
cont = (*str== '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
- if(*(str+1) == find && *(str+2) == find) {
+ if (*(str+1) == find && *(str+2) == find) {
*fmt = 'l'; fmt++; str++;
*fmt = 'l'; fmt++; str++;
cont |= TXT_TRISTR;
@@ -377,15 +378,15 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
*fmt = 'l';
}
/* Whitespace (all ws. has been converted to spaces) */
- else if(*str == ' ')
+ 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--;
}
@@ -396,24 +397,24 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next)
*fmt = 'q';
}
/* Punctuation */
- else if(text_check_delim(*str))
+ else if (text_check_delim(*str))
*fmt = '!';
/* Identifiers and other text (no previous ws. or delims. so text continues) */
- else if(prev == 'q') {
+ else if (prev == 'q') {
str += BLI_str_utf8_size(str) - 1;
*fmt = 'q';
}
/* 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)
+ else if ((i=find_decorator(str)) != -1)
prev = 'v'; /* could have a new color for this */
- if(i>0) {
- while(i>1) {
+ if (i>0) {
+ while (i>1) {
*fmt = prev; fmt++; str++;
i--;
}
@@ -435,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);
}
@@ -448,9 +449,9 @@ static void txt_format_text(SpaceText *st)
{
TextLine *linep;
- if(!st->text) return;
+ 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
@@ -532,27 +533,28 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
*offl= *offc= 0;
- if(!st->text) return;
- if(!st->wordwrap) return;
+ if (!st->text) return;
+ if (!st->wordwrap) return;
text= st->text;
/* Move pointer to first visible line (top) */
linep= text->lines.first;
i= st->top;
- while(i>0 && linep) {
+ while (i>0 && linep) {
int lines= text_get_visible_lines(st, ar, linep->line);
/* Line before top */
- if(linep == linein) {
- if(lines <= i)
+ if (linep == linein) {
+ if (lines <= i)
/* no visible part of line */
return;
}
if (i-lines<0) {
break;
- } else {
+ }
+ else {
linep= linep->next;
(*offl)+= lines-1;
i-= lines;
@@ -562,28 +564,28 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
max= wrap_width(st, ar);
cursin = txt_utf8_offset_to_index(linein->line, cursin);
- while(linep) {
+ 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)) {
+ 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') {
+ if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
- if(linep==linein && i<cursin) cursin += chars-1;
+ if (linep==linein && i<cursin) cursin += chars-1;
ch= ' ';
}
else {
chars= 1;
}
- while(chars--) {
- if(i-start>=max) {
- if(chop && linep==linein && i >= cursin) {
+ while (chars--) {
+ if (i-start>=max) {
+ if (chop && linep==linein && i >= cursin) {
if (i==cursin) {
(*offl)++;
*offc -= end-start;
@@ -599,16 +601,16 @@ void wrap_offset(SpaceText *st, ARegion *ar, TextLine *linein, int cursin, int *
end += max;
chop= 1;
}
- else if(ch==' ' || ch=='-') {
+ else if (ch==' ' || ch=='-') {
end = i+1;
chop= 0;
- if(linep==linein && i >= cursin)
+ if (linep==linein && i >= cursin)
return;
}
i++;
}
}
- if(linep==linein) break;
+ if (linep==linein) break;
linep= linep->next;
}
}
@@ -621,8 +623,8 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
*offl= *offc= 0;
- if(!st->text) return;
- if(!st->wordwrap) return;
+ if (!st->text) return;
+ if (!st->wordwrap) return;
max= wrap_width(st, ar);
@@ -632,21 +634,21 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
*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') {
+ if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
- if(i<cursin) cursin += chars-1;
+ if (i<cursin) cursin += chars-1;
ch= ' ';
}
else
chars= 1;
- while(chars--) {
- if(i-start>=max) {
- if(chop && i >= cursin) {
+ while (chars--) {
+ if (i-start>=max) {
+ if (chop && i >= cursin) {
if (i==cursin) {
(*offl)++;
*offc -= end-start;
@@ -662,10 +664,10 @@ void wrap_offset_in_line(SpaceText *st, ARegion *ar, TextLine *linein, int cursi
end += max;
chop= 1;
}
- else if(ch==' ' || ch=='-') {
+ else if (ch==' ' || ch=='-') {
end = i+1;
chop= 0;
- if(i >= cursin)
+ if (i >= cursin)
return;
}
i++;
@@ -677,8 +679,8 @@ int text_get_char_pos(SpaceText *st, const char *line, int cur)
{
int a=0, i;
- for(i=0; i<cur && line[i]; i += BLI_str_utf8_size(line + i)) {
- if(line[i]=='\t')
+ 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++;
@@ -704,17 +706,17 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w
flatten_string(st, &fs, str);
str= fs.buf;
max= w/st->cwidth;
- if(max<8) max= 8;
+ if (max<8) max= 8;
basex= x;
lines= 1;
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) {
+ if (skip) {
skip--;
start= end; mstart= mend;
end += max; mend= txt_utf8_get_nth(str+mend, max) - str;
@@ -722,8 +724,8 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w
}
/* 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)) {
- if(st->showsyntax && format) format_draw_color(format[a]);
+ 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;
@@ -732,16 +734,16 @@ static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w
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]=='-') {
+ 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)) {
- if(st->showsyntax && format)
+ 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);
@@ -759,7 +761,7 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
const char *in;
int w= flatten_string(st, &fs, str);
- if(w < cshift) {
+ if (w < cshift) {
flatten_string_free(&fs);
return 0; /* String is shorter than shift */
}
@@ -768,14 +770,14 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
acc= fs.accum+cshift;
w= w-cshift;
- if(draw) {
+ if (draw) {
int amount = maxwidth ? MIN2(w, maxwidth) : w;
- if(st->showsyntax && format) {
+ if (st->showsyntax && format) {
int a, str_shift= 0;
format = format+cshift;
- for(a = 0; a < amount; a++) {
+ for (a = 0; a < amount; a++) {
format_draw_color(format[a]);
x += text_font_draw_character_utf8(st, x, y, in + str_shift);
str_shift += BLI_str_utf8_size(in + str_shift);
@@ -784,15 +786,15 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
else text_font_draw(st, x, y, in);
}
else {
- while(w-- && *acc++ < maxwidth)
+ while (w-- && *acc++ < maxwidth)
r+= st->cwidth;
}
flatten_string_free(&fs);
- if(cshift && r==0)
+ if (cshift && r==0)
return 0;
- else if(st->showlinenrs)
+ else if (st->showlinenrs)
return r+TXT_OFFSET+TEXTXLOC;
else
return r+TXT_OFFSET;
@@ -832,7 +834,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
int full_update= 0, nlines= 0;
Text *txt= st->text;
- if(!st->drawcache) text_drawcache_init(st);
+ if (!st->drawcache) text_drawcache_init(st);
text_update_character_width(st);
@@ -848,15 +850,15 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
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) {
+ if (st->wordwrap) {
/* update line heights */
- if(full_update || !drawcache->line_height) {
+ if (full_update || !drawcache->line_height) {
drawcache->valid_head = 0;
drawcache->valid_tail = 0;
drawcache->update_flag = 1;
}
- if(drawcache->update_flag) {
+ 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;
@@ -864,7 +866,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
nlines= BLI_countlist(&txt->lines);
size= sizeof(int)*nlines;
- if(fp) fp= MEM_reallocN(fp, size);
+ if (fp) fp= MEM_reallocN(fp, size);
else fp= MEM_callocN(size, "text drawcache line_height");
drawcache->valid_tail= drawcache->valid_head= 0;
@@ -874,16 +876,18 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
drawcache->total_lines= 0;
- if(st->showlinenrs)
+ if (st->showlinenrs)
st->linenrs_tot= (int)floor(log10((float)nlines)) + 1;
- while(line) {
- if(drawcache->valid_head) { /* we're inside valid head lines */
+ while (line) {
+ if (drawcache->valid_head) { /* we're inside valid head lines */
lines_count= fp[lineno];
drawcache->valid_head--;
- } else if (lineno > new_tail - fp) { /* we-re inside valid tail lines */
+ }
+ else if (lineno > new_tail - fp) { /* we-re inside valid tail lines */
lines_count= fp[lineno];
- } else {
+ }
+ else {
lines_count= text_get_visible_lines(st, ar, line->line);
}
@@ -896,16 +900,17 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
drawcache->line_height= fp;
}
- } else {
- if(drawcache->line_height) {
+ }
+ else {
+ if (drawcache->line_height) {
MEM_freeN(drawcache->line_height);
drawcache->line_height= NULL;
}
- if(full_update || drawcache->update_flag) {
+ if (full_update || drawcache->update_flag) {
nlines= BLI_countlist(&txt->lines);
- if(st->showlinenrs)
+ if (st->showlinenrs)
st->linenrs_tot= (int)floor(log10((float)nlines)) + 1;
}
@@ -936,24 +941,25 @@ void text_drawcache_tag_update(SpaceText *st, int full)
if (st == NULL)
return;
- if(st->drawcache) {
+ if (st->drawcache) {
DrawCache *drawcache= (DrawCache *)st->drawcache;
Text *txt= st->text;
- if(drawcache->update_flag) {
+ if (drawcache->update_flag) {
/* happens when tagging update from space listener */
/* should do nothing to prevent locally tagged cache be fully recalculated */
return;
}
- if(!full) {
+ if (!full) {
int sellno= BLI_findindex(&txt->lines, txt->sell);
int curlno= BLI_findindex(&txt->lines, txt->curl);
- if(curlno < sellno) {
+ if (curlno < sellno) {
drawcache->valid_head= curlno;
drawcache->valid_tail= drawcache->nlines - sellno - 1;
- } else {
+ }
+ else {
drawcache->valid_head= sellno;
drawcache->valid_tail= drawcache->nlines - curlno - 1;
}
@@ -961,9 +967,10 @@ void text_drawcache_tag_update(SpaceText *st, int full)
/* 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--;
- } else {
+ 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;
}
@@ -976,8 +983,8 @@ void text_free_caches(SpaceText *st)
{
DrawCache *drawcache= (DrawCache *)st->drawcache;
- if(drawcache) {
- if(drawcache->line_height)
+ if (drawcache) {
+ if (drawcache->line_height)
MEM_freeN(drawcache->line_height);
MEM_freeN(drawcache);
@@ -1003,22 +1010,22 @@ int text_get_visible_lines(SpaceText *st, ARegion *ar, const char *str)
lines= 1;
start= 0;
end= max;
- for(i= 0, j= 0; str[j]; j+=BLI_str_utf8_size(str+j)) {
+ for (i= 0, j= 0; str[j]; j+=BLI_str_utf8_size(str+j)) {
/* Mimic replacement of tabs */
ch= str[j];
- if(ch=='\t') {
+ if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
}
else chars= 1;
- while(chars--) {
- if(i-start >= max) {
+ while (chars--) {
+ if (i-start >= max) {
lines++;
start= end;
end += max;
}
- else if(ch==' ' || ch=='-') {
+ else if (ch==' ' || ch=='-') {
end= i+1;
}
@@ -1031,7 +1038,7 @@ 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) {
+ if (st->wordwrap) {
int ret=0;
TextLine *tmp= from;
@@ -1043,7 +1050,8 @@ int text_get_span_wrap(SpaceText *st, ARegion *ar, TextLine *from, TextLine *to)
}
return ret;
- } else return txt_get_span(from, to);
+ }
+ else return txt_get_span(from, to);
}
int text_get_total_lines(SpaceText *st, ARegion *ar)
@@ -1065,23 +1073,25 @@ static TextLine *first_visible_line(SpaceText *st, ARegion *ar, int *wrap_top)
text_update_drawcache(st, ar);
- if(wrap_top) *wrap_top= 0;
+ if (wrap_top) *wrap_top= 0;
- if(st->wordwrap) {
- while(i>0 && pline) {
+ if (st->wordwrap) {
+ while (i>0 && pline) {
int lines= text_get_visible_lines_no(st, lineno);
if (i-lines<0) {
- if(wrap_top) *wrap_top= i;
+ if (wrap_top) *wrap_top= i;
break;
- } else {
+ }
+ else {
pline= pline->next;
i-= lines;
lineno++;
}
}
- } else {
- for(i=st->top; pline->next && i>0; i--)
+ }
+ else {
+ for (i=st->top; pline->next && i>0; i--)
pline= pline->next;
}
@@ -1114,7 +1124,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
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) {
+ if (ltexth + blank_lines < st->top + st->viewlines) {
blank_lines = st->top + st->viewlines - ltexth;
}
@@ -1122,7 +1132,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
barheight = (ltexth > 0)? (st->viewlines*pix_available)/ltexth: 0;
pix_bardiff = 0;
- if(barheight < 20) {
+ if (barheight < 20) {
pix_bardiff = 20 - barheight; /* take into account the now non-linear sizing of the bar */
barheight = 20;
}
@@ -1136,52 +1146,52 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
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;
+ 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);
lhlstart = MIN2(curl_off, sell_off);
lhlend = MAX2(curl_off, sell_off);
- if(ltexth > 0) {
+ if (ltexth > 0) {
hlstart = (lhlstart * pix_available)/ltexth;
hlend = (lhlend * pix_available)/ltexth;
/* the scrollbar is non-linear sized */
- if(pix_bardiff > 0) {
+ if (pix_bardiff > 0) {
/* the start of the highlight is in the current viewport */
- if(ltexth && st->viewlines && lhlstart >= st->top && lhlstart <= st->top + st->viewlines) {
+ if (ltexth && st->viewlines && lhlstart >= st->top && lhlstart <= st->top + st->viewlines) {
/* speed the progresion of the start of the highlight through the scrollbar */
hlstart = ( ( (pix_available - pix_bardiff) * lhlstart) / ltexth) + (pix_bardiff * (lhlstart - st->top) / st->viewlines);
}
- else if(lhlstart > st->top + st->viewlines && hlstart < barstart + barheight && hlstart > barstart) {
+ else if (lhlstart > st->top + st->viewlines && hlstart < barstart + barheight && hlstart > barstart) {
/* push hl start down */
hlstart = barstart + barheight;
}
- else if(lhlend > st->top && lhlstart < st->top && hlstart > barstart) {
+ else if (lhlend > st->top && lhlstart < st->top && hlstart > barstart) {
/*fill out start */
hlstart = barstart;
}
- if(hlend <= hlstart) {
+ if (hlend <= hlstart) {
hlend = hlstart + 2;
}
/* the end of the highlight is in the current viewport */
- if(ltexth && st->viewlines && lhlend >= st->top && lhlend <= st->top + st->viewlines) {
+ 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);
}
- else if(lhlend < st->top && hlend >= barstart - 2 && hlend < barstart + barheight) {
+ else if (lhlend < st->top && hlend >= barstart - 2 && hlend < barstart + barheight) {
/* push hl end up */
hlend = barstart;
}
- else if(lhlend > st->top + st->viewlines && lhlstart < st->top + st->viewlines && hlend < barstart + barheight) {
+ else if (lhlend > st->top + st->viewlines && lhlstart < st->top + st->viewlines && hlend < barstart + barheight) {
/* fill out end */
hlend = barstart + barheight;
}
- if(hlend <= hlstart) {
+ if (hlend <= hlstart) {
hlstart = hlend - 2;
}
}
@@ -1191,7 +1201,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
hlend = 0;
}
- if(hlend - hlstart < 2) {
+ if (hlend - hlstart < 2) {
hlend = hlstart + 2;
}
@@ -1241,16 +1251,16 @@ static void draw_markers(SpaceText *st, ARegion *ar)
topy= txt_get_span(text->lines.first, top);
- for(marker= text->markers.first; marker; 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);
/* 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;
}
@@ -1264,13 +1274,13 @@ 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;
- if(y1==y2) {
+ if (y1==y2) {
y -= y1*st->lheight;
glBegin(GL_LINE_LOOP);
glVertex2i(x+x2*st->cwidth+1, y);
@@ -1289,7 +1299,7 @@ static void draw_markers(SpaceText *st, ARegion *ar)
glEnd();
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);
@@ -1318,24 +1328,24 @@ static void draw_documentation(SpaceText *st, ARegion *ar)
int i, br, lines;
int boxw, boxh, l, x, y /* , top */ /* UNUSED */;
- if(!st || !st->text) return;
- if(!texttool_text_is_active(st->text)) return;
+ if (!st || !st->text) return;
+ if (!texttool_text_is_active(st->text)) return;
docs = texttool_docs_get();
- if(!docs) return;
+ 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) {
+ if (st->showlinenrs) {
x= st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
x= st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
}
- if(texttool_suggest_first()) {
+ if (texttool_suggest_first()) {
x += SUGG_LIST_WIDTH*st->cwidth + 50;
}
@@ -1366,32 +1376,32 @@ static void draw_documentation(SpaceText *st, ARegion *ar)
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 */
- if(*p == ' ' || *p == '\t')
+ for (p=docs; *p; p++) {
+ if (*p == '\r' && *(++p) != '\n') *(--p)= '\n'; /* Fix line endings */
+ if (*p == ' ' || *p == '\t')
br= i;
- else if(*p == '\n') {
+ else if (*p == '\n') {
buf[i]= '\0';
- if(lines>=0) {
+ if (lines>=0) {
y -= st->lheight;
text_draw(st, buf, 0, 0, 1, x+4, y-3, NULL);
}
i= 0; br= DOC_WIDTH; lines++;
}
buf[i++]= *p;
- if(i == DOC_WIDTH) { /* Reached the width, go to last break and wrap there */
+ if (i == DOC_WIDTH) { /* Reached the width, go to last break and wrap there */
buf[br]= '\0';
- if(lines>=0) {
+ if (lines>=0) {
y -= st->lheight;
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++;
}
- if(lines >= DOC_HEIGHT) break;
+ if (lines >= DOC_HEIGHT) break;
}
- if(0 /* XXX doc_scroll*/ > 0 && lines < DOC_HEIGHT) {
+ if (0 /* XXX doc_scroll*/ > 0 && lines < DOC_HEIGHT) {
// XXX doc_scroll--;
draw_documentation(st, ar);
}
@@ -1406,23 +1416,23 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
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;
+ if (!st || !st->text) return;
+ if (!texttool_text_is_active(st->text)) return;
first = texttool_suggest_first();
last = texttool_suggest_last();
- if(!first || !last) return;
+ if (!first || !last) return;
text_pop_suggest_list();
sel = texttool_suggest_selected();
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) {
+ if (st->showlinenrs) {
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
@@ -1439,9 +1449,9 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
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;
@@ -1449,7 +1459,7 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
w = BLF_width(mono, str);
- if(item == sel) {
+ if (item == sel) {
UI_ThemeColor(TH_SHADE2);
glRecti(x+16, y-3, x+16+w, y+st->lheight-3);
}
@@ -1461,13 +1471,13 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
case 'v': UI_ThemeColor(TH_SYNTAX_N); break;
case '?': UI_ThemeColor(TH_TEXT); b=0; break;
}
- if(b) {
+ if (b) {
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);
- if(item == last) break;
+ if (item == last) break;
}
}
@@ -1480,7 +1490,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
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);
@@ -1490,16 +1500,16 @@ 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;
- if(vcurl==vsell) {
+ if (vcurl==vsell) {
y -= vcurl*st->lheight;
- if(vcurc < vselc)
+ if (vcurc < vselc)
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);
@@ -1507,7 +1517,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
else {
int froml, fromc, tol, toc;
- if(vcurl < vsell) {
+ if (vcurl < vsell) {
froml= vcurl; tol= vsell;
fromc= vcurc; toc= vselc;
}
@@ -1518,7 +1528,7 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
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++)
+ 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;
@@ -1530,16 +1540,16 @@ 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) {
+ if (vselc<0) {
vselc= 0;
hidden= 1;
}
}
- if(st->line_hlight) {
+ if (st->line_hlight) {
int x1, x2, y1, y2;
- if(st->wordwrap) {
+ if (st->wordwrap) {
int visible_lines = text_get_visible_lines(st, ar, text->sell->line);
int offl, offc;
@@ -1547,12 +1557,13 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
y1= ar->winy-2 - (vsell-offl)*st->lheight;
y2= y1-st->lheight*visible_lines+1;
- } else {
+ }
+ else {
y1= ar->winy-2 - vsell*st->lheight;
y2= y1-st->lheight+1;
}
- if(!(y1<0 || y2 > ar->winy)) { /* check we need to draw */
+ if (!(y1<0 || y2 > ar->winy)) { /* check we need to draw */
x1= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x2= x1 + ar->winx;
@@ -1565,17 +1576,17 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
}
}
- if(!hidden) {
+ 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;
- if(st->overwrite) {
+ if (st->overwrite) {
char ch= text->sell->line[text->selc];
w= st->cwidth;
- if(ch=='\t') w*= st->tabnumber-(vselc+st->left)%st->tabnumber;
+ 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);
@@ -1599,13 +1610,13 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
char ch;
// showsyntax must be on or else the format string will be null
- if(!text->curl || !st->showsyntax) return;
+ 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;
+ if (b==0 && startc>0) b = text_check_bracket(startl->line[--startc]);
+ if (b==0) return;
linep= startl;
c= startc;
@@ -1616,33 +1627,33 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
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] == '#')
+ 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);
- while(linep) {
- while(c<linep->len) {
- if(linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
+ while (linep) {
+ 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) {
+ 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);
}
- if(endl) break;
+ if (endl) break;
linep= linep->next;
c= 0;
fc= 0;
@@ -1652,28 +1663,28 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
/* closing bracket, search backward for open */
fc--;
if (c>0) c -= linep->line+c-BLI_str_prev_char_utf8(linep->line+c);
- while(linep) {
- while(fc>=0) {
- if(linep->format && linep->format[fc] != 'l' && linep->format[fc] != '#') {
+ while (linep) {
+ 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) {
+ 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(endl) break;
+ if (endl) break;
linep= linep->prev;
- if(linep) {
+ 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;
@@ -1682,7 +1693,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
}
}
- if(!endl || endc==-1)
+ if (!endl || endc==-1)
return;
UI_ThemeColor(TH_HILITE);
@@ -1694,7 +1705,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
wrap_offset(st, ar, startl, startc, &offl, &offc);
viewc= text_get_char_pos(st, startl->line, startc) - st->left + offc;
- if(viewc >= 0){
+ if (viewc >= 0) {
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);
@@ -1706,7 +1717,7 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
wrap_offset(st, ar, endl, endc, &offl, &offc);
viewc= text_get_char_pos(st, endl->line, endc) - st->left + offc;
- if(viewc >= 0) {
+ if (viewc >= 0) {
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);
@@ -1725,17 +1736,17 @@ void draw_text_main(SpaceText *st, ARegion *ar)
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;
+ if (st->lheight) st->viewlines= (int)ar->winy/st->lheight;
else st->viewlines= 0;
/* if no text, nothing to do */
- if(!text)
+ if (!text)
return;
text_update_drawcache(st, ar);
/* make sure all the positional pointers exist */
- if(!text->curl || !text->sell || !text->lines.first || !text->lines.last)
+ if (!text->curl || !text->sell || !text->lines.first || !text->lines.last)
txt_clean_text(text);
/* update rects for scroll */
@@ -1744,22 +1755,24 @@ void draw_text_main(SpaceText *st, ARegion *ar)
/* update syntax formatting if needed */
tmp= text->lines.first;
lineno= 0;
- for(i= 0; i<st->top && tmp; i++) {
- if(st->showsyntax && !tmp->format)
+ for (i= 0; i<st->top && tmp; i++) {
+ if (st->showsyntax && !tmp->format)
txt_format_line(st, tmp, 0);
- if(st->wordwrap) {
+ if (st->wordwrap) {
int lines= text_get_visible_lines_no(st, lineno);
if (wraplinecount+lines>st->top) {
wrap_skip= st->top-wraplinecount;
break;
- } else {
+ }
+ else {
wraplinecount+= lines;
tmp= tmp->next;
linecount++;
}
- } else {
+ }
+ else {
tmp= tmp->next;
linecount++;
}
@@ -1772,7 +1785,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
st->cwidth= MAX2(st->cwidth, 1);
/* draw line numbers background */
- if(st->showlinenrs) {
+ if (st->showlinenrs) {
x= TXT_OFFSET + TEXTXLOC;
UI_ThemeColor(TH_GRID);
@@ -1791,13 +1804,13 @@ 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) {
- if(st->showsyntax && !tmp->format)
+ for (i=0; y>0 && i<st->viewlines && tmp; i++, tmp= tmp->next) {
+ if (st->showsyntax && !tmp->format)
txt_format_line(st, tmp, 0);
- if(st->showlinenrs && !wrap_skip) {
+ if (st->showlinenrs && !wrap_skip) {
/* draw line number */
- if(tmp == text->curl)
+ if (tmp == text->curl)
UI_ThemeColor(TH_HILITE);
else
UI_ThemeColor(TH_TEXT);
@@ -1809,7 +1822,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
UI_ThemeColor(TH_TEXT);
}
- if(st->wordwrap) {
+ 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;
@@ -1823,7 +1836,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
wrap_skip= 0;
}
- if(st->flags&ST_SHOW_MARGIN) {
+ if (st->flags&ST_SHOW_MARGIN) {
UI_ThemeColor(TH_HILITE);
glBegin(GL_LINES);
@@ -1861,12 +1874,12 @@ void text_scroll_to_cursor(SpaceText *st, ScrArea *sa)
ARegion *ar= NULL;
int i, x, winx= 0;
- if(ELEM3(NULL, st, st->text, st->text->curl)) return;
+ if (ELEM3(NULL, st, st->text, st->text->curl)) return;
text= st->text;
- for(ar=sa->regionbase.first; ar; ar= ar->next)
- if(ar->regiontype==RGN_TYPE_WINDOW) {
+ for (ar=sa->regionbase.first; ar; ar= ar->next)
+ if (ar->regiontype==RGN_TYPE_WINDOW) {
winx= ar->winx;
break;
}
@@ -1876,27 +1889,27 @@ void text_scroll_to_cursor(SpaceText *st, ScrArea *sa)
text_update_character_width(st);
i= txt_get_span(text->lines.first, text->sell);
- if(st->wordwrap) {
+ if (st->wordwrap) {
int offl, offc;
wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
i+= offl;
}
- if(st->top+st->viewlines <= i || st->top > i)
+ if (st->top+st->viewlines <= i || st->top > i)
st->top= i - st->viewlines/2;
- if(st->wordwrap) {
+ if (st->wordwrap) {
st->left= 0;
}
else {
x= text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL);
- if(x==0 || x>winx)
+ 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)
diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c
index 02de29e098b..f4f92ac8db3 100644
--- a/source/blender/editors/space_text/text_header.c
+++ b/source/blender/editors/space_text/text_header.c
@@ -79,13 +79,13 @@ static ARegion *text_has_properties_region(ScrArea *sa)
ARegion *ar, *arnew;
ar= BKE_area_find_region_type(sa, RGN_TYPE_UI);
- if(ar) return ar;
+ if (ar) return ar;
/* add subdiv level; after 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");
@@ -108,7 +108,7 @@ static int text_properties_exec(bContext *C, wmOperator *UNUSED(op))
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= text_has_properties_region(sa);
- if(ar)
+ if (ar)
ED_region_toggle_hidden(C, ar);
return OPERATOR_FINISHED;
@@ -134,9 +134,9 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPopupMenu *pup;
- if(text) {
+ if (text) {
pup= uiPupMenuBegin(C, "Text", ICON_NONE);
- if(txt_has_sel(text)) {
+ if (txt_has_sel(text)) {
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_cut");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_copy");
}
@@ -173,7 +173,7 @@ void TEXT_OT_properties(wmOperatorType *ot)
uiPopupMenu *pup;
- if(text) {
+ if (text) {
pup= uiPupMenuBegin(C, "Text", ICON_NONE);
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_new");
uiItemO(layout, NULL, ICON_NONE, "TEXT_OT_open");
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index fd4b334eeec..8230da838e7 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -89,10 +89,10 @@ static int text_edit_poll(bContext *C)
{
Text *text= CTX_data_edit_text(C);
- if(!text)
+ if (!text)
return 0;
- if(text->id.lib) {
+ if (text->id.lib) {
// BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata");
return 0;
}
@@ -105,10 +105,10 @@ static int text_space_edit_poll(bContext *C)
SpaceText *st= CTX_wm_space_text(C);
Text *text= CTX_data_edit_text(C);
- if(!st || !text)
+ if (!st || !text)
return 0;
- if(text->id.lib) {
+ if (text->id.lib) {
// BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata");
return 0;
}
@@ -122,13 +122,13 @@ static int text_region_edit_poll(bContext *C)
Text *text= CTX_data_edit_text(C);
ARegion *ar= CTX_wm_region(C);
- if(!st || !text)
+ if (!st || !text)
return 0;
- if(!ar || ar->regiontype != RGN_TYPE_WINDOW)
+ if (!ar || ar->regiontype != RGN_TYPE_WINDOW)
return 0;
- if(text->id.lib) {
+ if (text->id.lib) {
// BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata");
return 0;
}
@@ -140,11 +140,11 @@ static int text_region_edit_poll(bContext *C)
void text_update_line_edited(TextLine *line)
{
- if(!line)
+ if (!line)
return;
/* we just free format here, and let it rebuild during draw */
- if(line->format) {
+ if (line->format) {
MEM_freeN(line->format);
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);
}
@@ -172,18 +172,18 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
/* hook into UI */
uiIDContextProperty(C, &ptr, &prop);
- if(prop) {
+ if (prop) {
/* 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);
RNA_property_pointer_set(&ptr, prop, idptr);
RNA_property_update(C, &ptr, prop);
}
- else if(st) {
+ else if (st) {
st->text= text;
st->top= 0;
text_drawcache_tag_update(st, 1);
@@ -238,18 +238,18 @@ static int text_open_exec(bContext *C, wmOperator *op)
text= add_text(str, G.main->name);
- if(!text) {
- if(op->customdata) MEM_freeN(op->customdata);
+ if (!text) {
+ if (op->customdata) MEM_freeN(op->customdata);
return OPERATOR_CANCELLED;
}
- if(!op->customdata)
+ if (!op->customdata)
text_open_init(C, op);
/* hook into UI */
pprop= op->customdata;
- if(pprop->prop) {
+ if (pprop->prop) {
/* when creating new ID blocks, use is already 1, but RNA
* pointer se also increases user, so this compensates it */
text->id.us--;
@@ -258,13 +258,13 @@ static int text_open_exec(bContext *C, wmOperator *op)
RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
RNA_property_update(C, &pprop->ptr, pprop->prop);
}
- else if(st) {
+ else if (st) {
st->text= text;
st->top= 0;
}
if (internal) {
- if(text->name)
+ if (text->name)
MEM_freeN(text->name);
text->name = NULL;
@@ -283,7 +283,7 @@ 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;
- if(RNA_struct_property_is_set(op->ptr, "filepath"))
+ if (RNA_struct_property_is_set(op->ptr, "filepath"))
return text_open_exec(C, op);
text_open_init(C, op);
@@ -320,13 +320,13 @@ static int text_reload_exec(bContext *C, wmOperator *op)
{
Text *text= CTX_data_edit_text(C);
- if(!reopen_text(text)) {
+ if (!reopen_text(text)) {
BKE_report(op->reports, RPT_ERROR, "Could not reopen file");
return OPERATOR_CANCELLED;
}
#ifdef WITH_PYTHON
- if(text->compiled)
+ if (text->compiled)
BPY_text_free_code(text);
#endif
@@ -366,13 +366,13 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
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) {
+ 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);
}
- else if(text->id.next) {
+ 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);
@@ -412,7 +412,7 @@ static int text_make_internal_exec(bContext *C, wmOperator *UNUSED(op))
text->flags |= TXT_ISMEM | TXT_ISDIRTY;
- if(text->name) {
+ if (text->name) {
MEM_freeN(text->name);
text->name= NULL;
}
@@ -444,7 +444,7 @@ static int text_save_poll(bContext *C)
{
Text *text= CTX_data_edit_text(C);
- if(!text_edit_poll(C))
+ if (!text_edit_poll(C))
return 0;
return (text->name != NULL && !(text->flags & TXT_ISMEM));
@@ -461,14 +461,14 @@ static void txt_write_file(Text *text, ReportList *reports)
BLI_path_abs(filepath, G.main->name);
fp= BLI_fopen(filepath, "w");
- if(fp==NULL) {
+ 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;
- while(tmp) {
- if(tmp->next) fprintf(fp, "%s\n", tmp->line);
+ while (tmp) {
+ if (tmp->next) fprintf(fp, "%s\n", tmp->line);
else fprintf(fp, "%s", tmp->line);
tmp= tmp->next;
@@ -476,7 +476,7 @@ static void txt_write_file(Text *text, ReportList *reports)
fclose (fp);
- if(stat(filepath, &st) == 0) {
+ if (stat(filepath, &st) == 0) {
text->mtime= st.st_mtime;
}
else {
@@ -484,7 +484,7 @@ static void txt_write_file(Text *text, ReportList *reports)
BKE_reportf(reports, RPT_WARNING, "Unable to stat \"%s\": %s", filepath, errno ? strerror(errno) : "Unknown error starrng file");
}
- if(text->flags & TXT_ISDIRTY)
+ if (text->flags & TXT_ISDIRTY)
text->flags ^= TXT_ISDIRTY;
}
@@ -519,12 +519,12 @@ static int text_save_as_exec(bContext *C, wmOperator *op)
Text *text= CTX_data_edit_text(C);
char str[FILE_MAX];
- if(!text)
+ if (!text)
return OPERATOR_CANCELLED;
RNA_string_get(op->ptr, "filepath", str);
- if(text->name) MEM_freeN(text->name);
+ if (text->name) MEM_freeN(text->name);
text->name= BLI_strdup(str);
text->flags &= ~TXT_ISMEM;
@@ -541,12 +541,12 @@ static int text_save_as_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even
Text *text= CTX_data_edit_text(C);
char *str;
- if(RNA_struct_property_is_set(op->ptr, "filepath"))
+ if (RNA_struct_property_is_set(op->ptr, "filepath"))
return text_save_as_exec(C, op);
- if(text->name)
+ if (text->name)
str= text->name;
- else if(text->flags & TXT_ISMEM)
+ else if (text->flags & TXT_ISMEM)
str= text->id.name+2;
else
str= G.main->name;
@@ -591,7 +591,7 @@ static int text_run_script(bContext *C, ReportList *reports)
int curc_prev= text->curc;
if (BPY_text_exec(C, text, reports, !is_live)) {
- if(is_live) {
+ if (is_live) {
/* for nice live updates */
WM_event_add_notifier(C, NC_WINDOW|NA_EDITED, NULL);
}
@@ -599,8 +599,8 @@ static int text_run_script(bContext *C, ReportList *reports)
}
/* Don't report error messages while live editing */
- if(!is_live) {
- if(text->curl != curl_prev || curc_prev != text->curc) {
+ 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);
}
@@ -654,30 +654,30 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS
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;
}
}
- if(update) {
+ if (update) {
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
@@ -707,25 +707,25 @@ static char *txt_copy_selected(Text *text)
char *buf= NULL;
int charf, charl, length= 0;
- if(!text) return NULL;
- if(!text->curl) return NULL;
- if(!text->sell) return NULL;
+ if (!text) return NULL;
+ if (!text->curl) return NULL;
+ if (!text->sell) return NULL;
- if(!txt_has_sel(text)) return NULL;
+ if (!txt_has_sel(text)) return NULL;
- if(text->curl==text->sell) {
+ if (text->curl==text->sell) {
linef= linel= text->curl;
- if(text->curc < text->selc) {
+ if (text->curc < text->selc) {
charf= text->curc;
charl= text->selc;
}
- else{
+ else {
charf= text->selc;
charl= text->curc;
}
}
- else if(txt_get_span(text->curl, text->sell)<0) {
+ else if (txt_get_span(text->curl, text->sell)<0) {
linef= text->sell;
linel= text->curl;
@@ -740,7 +740,7 @@ static char *txt_copy_selected(Text *text)
charl= text->selc;
}
- if(linef == linel) {
+ if (linef == linel) {
length= charl-charf;
buf= MEM_callocN(length+1, "cut buffera");
@@ -753,7 +753,7 @@ static char *txt_copy_selected(Text *text)
length++; /* For the '\n' */
tmp= linef->next;
- while(tmp && tmp!= linel) {
+ while (tmp && tmp!= linel) {
length+= tmp->len+1;
tmp= tmp->next;
}
@@ -766,7 +766,7 @@ static char *txt_copy_selected(Text *text)
buf[length++]='\n';
tmp= linef->next;
- while(tmp && tmp!=linel) {
+ while (tmp && tmp!=linel) {
strncpy(buf+length, tmp->line, tmp->len);
length+= tmp->len;
@@ -791,7 +791,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
buf= WM_clipboard_text_get(selection);
- if(!buf)
+ if (!buf)
return OPERATOR_CANCELLED;
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
@@ -805,7 +805,7 @@ static int text_paste_exec(bContext *C, wmOperator *op)
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)
+ if (CTX_wm_space_text(C)->live_edit)
text_run_script(C, NULL);
return OPERATOR_FINISHED;
@@ -834,7 +834,7 @@ static void txt_copy_clipboard(Text *text)
buf= txt_copy_selected(text);
- if(buf) {
+ if (buf) {
WM_clipboard_text_set(buf, 0);
MEM_freeN(buf);
}
@@ -876,7 +876,7 @@ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
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)
+ if (CTX_wm_space_text(C)->live_edit)
text_run_script(C, NULL);
return OPERATOR_FINISHED;
@@ -902,7 +902,7 @@ static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
- if(txt_has_sel(text)) {
+ if (txt_has_sel(text)) {
txt_order_cursors(text);
txt_indent(text);
}
@@ -935,7 +935,7 @@ static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
- if(txt_has_sel(text)) {
+ if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
txt_order_cursors(text);
@@ -979,16 +979,17 @@ static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
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, ' ');
- } else {
+ }
+ else {
txt_add_char(text, '\t');
}
}
- if(text->curl) {
- if(text->curl->prev)
+ if (text->curl) {
+ if (text->curl->prev)
text_update_line_edited(text->curl->prev);
text_update_line_edited(text->curl);
}
@@ -1017,7 +1018,7 @@ static int text_comment_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
- if(txt_has_sel(text)) {
+ if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
txt_order_cursors(text);
@@ -1050,7 +1051,7 @@ static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text= CTX_data_edit_text(C);
- if(txt_has_sel(text)) {
+ if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
txt_order_cursors(text);
@@ -1100,14 +1101,14 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
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) {
+ while (tmp) {
text_check_line = tmp->line;
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
- if(text_check_line[a] == '\t') { //checking for tabs
+ 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
new_line[j] = '\0';
@@ -1118,7 +1119,7 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
number = flatten_string(st, &fs, new_line)-number;
flatten_string_free(&fs);
- for(extra = 0; extra < number; extra++) {
+ for (extra = 0; extra < number; extra++) {
new_line[j] = ' ';
j++;
}
@@ -1130,8 +1131,8 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
}
new_line[j] = '\0';
// put new_line in the tmp->line spot still need to try and set the curc correctly
- if(tmp->line) MEM_freeN(tmp->line);
- if(tmp->format) MEM_freeN(tmp->format);
+ if (tmp->line) MEM_freeN(tmp->line);
+ if (tmp->format) MEM_freeN(tmp->format);
tmp->line = new_line;
tmp->len = strlen(new_line);
@@ -1143,38 +1144,38 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
//start over from the beginning
tmp = text->lines.first;
- while(tmp) {
+ while (tmp) {
text_check_line = tmp->line;
extra = 0;
- for(a = 0; a < strlen(text_check_line); a++) {
+ 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] != ' ') {
+ 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] != ' ') {
number = 1;
}
}
}
- if(!number) { //found all number of space to equal a tab
+ if (!number) { //found all number of space to equal a tab
a = a+(st->tabnumber-1);
extra = extra+1;
}
}
- if( extra > 0 ) { //got tabs make malloc and do what you have to do
+ 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++) {
+ 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] != ' ') {
+ 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] != ' ') {
number = 1;
}
}
}
- if(!number) { //found all number of space to equal a tab
+ if (!number) { //found all number of space to equal a tab
new_line[extra] = '\t';
a = a+(st->tabnumber-1);
++extra;
@@ -1187,8 +1188,8 @@ static int text_convert_whitespace_exec(bContext *C, wmOperator *op)
}
new_line[extra] = '\0';
// put new_line in the tmp->line spot still need to try and set the curc correctly
- if(tmp->line) MEM_freeN(tmp->line);
- if(tmp->format) MEM_freeN(tmp->format);
+ if (tmp->line) MEM_freeN(tmp->line);
+ if (tmp->format) MEM_freeN(tmp->format);
tmp->line = new_line;
tmp->len = strlen(new_line);
@@ -1310,10 +1311,10 @@ static int text_previous_marker_exec(bContext *C, wmOperator *UNUSED(op))
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)))
+ while (mrk && (mrk->lineno>lineno || (mrk->lineno==lineno && mrk->end > text->curc)))
mrk= mrk->prev;
- if(!mrk) mrk= text->markers.last;
- if(mrk) {
+ 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);
}
@@ -1346,10 +1347,10 @@ static int text_next_marker_exec(bContext *C, wmOperator *UNUSED(op))
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)))
+ while (mrk && (mrk->lineno<lineno || (mrk->lineno==lineno && mrk->start <= text->curc)))
mrk= mrk->next;
- if(!mrk) mrk= text->markers.first;
- if(mrk) {
+ 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);
}
@@ -1427,60 +1428,60 @@ static int text_get_cursor_rel(SpaceText* st, ARegion *ar, TextLine *linein, int
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') {
+ if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
}
else chars= 1;
- while(chars--) {
- if(rell==0 && i-start==relc) {
+ while (chars--) {
+ 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;
}
- else if(i-end==relc) {
+ else if (i-end==relc) {
curs= j;
}
- if(i-start>=max) {
- if(found) {
+ 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;
+ if (selc>endj && !chop) selc= endj;
loop= 0;
break;
}
- if(chop) endj= j;
+ if (chop) endj= j;
start= end;
end += max;
chop= 1;
rell--;
- if(rell==0 && i-start>=relc) {
+ if (rell==0 && i-start>=relc) {
selc= curs;
loop= 0;
break;
}
}
else if (ch=='\0') {
- if(!found) selc= linein->len;
+ if (!found) selc= linein->len;
loop= 0;
break;
}
- else if(ch==' ' || ch=='-') {
- if(found) {
+ else if (ch==' ' || ch=='-') {
+ if (found) {
loop= 0;
break;
}
- if(rell==0 && i-start>=relc) {
+ if (rell==0 && i-start>=relc) {
selc= curs;
loop= 0;
break;
@@ -1506,12 +1507,12 @@ static int cursor_skip_find_line(SpaceText* st, ARegion *ar,
*rell= lines;
/* handle current line */
- if(lines>0) {
+ if (lines>0) {
visible_lines= text_get_visible_lines(st, ar, (*linep)->line);
- if(*rell-visible_lines+offl>=0) {
- if(!(*linep)->next) {
- if(offl < visible_lines-1) {
+ if (*rell-visible_lines+offl>=0) {
+ if (!(*linep)->next) {
+ if (offl < visible_lines-1) {
*rell= visible_lines-1;
return 1;
}
@@ -1522,14 +1523,16 @@ static int cursor_skip_find_line(SpaceText* st, ARegion *ar,
*rell-= visible_lines-offl;
*linep=(*linep)->next;
- } else {
+ }
+ else {
*rell+= offl;
return 1;
}
- } else {
- if(*rell+offl<=0) {
- if(!(*linep)->prev) {
- if(offl) {
+ }
+ else {
+ if (*rell+offl<=0) {
+ if (!(*linep)->prev) {
+ if (offl) {
*rell= 0;
return 1;
}
@@ -1540,33 +1543,35 @@ static int cursor_skip_find_line(SpaceText* st, ARegion *ar,
*rell+= offl;
*linep=(*linep)->prev;
- } else {
+ }
+ else {
*rell+= offl;
return 1;
}
}
/* skip lines and find destination line and offsets */
- while(*linep) {
+ while (*linep) {
visible_lines= text_get_visible_lines(st, ar, (*linep)->line);
- if(lines<0) { /* moving top */
- if(*rell+visible_lines >= 0) {
+ if (lines<0) { /* moving top */
+ if (*rell+visible_lines >= 0) {
*rell+= visible_lines;
break;
}
- if(!(*linep)->prev) {
+ if (!(*linep)->prev) {
*rell= 0;
break;
}
*rell+= visible_lines;
*linep=(*linep)->prev;
- } else { /* moving bottom */
- if(*rell-visible_lines < 0) break;
+ }
+ else { /* moving bottom */
+ if (*rell-visible_lines < 0) break;
- if(!(*linep)->next) {
+ if (!(*linep)->next) {
*rell= visible_lines-1;
break;
}
@@ -1602,34 +1607,34 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
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') {
+ if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
}
else chars= 1;
- while(chars--) {
- if(i-start>=max) {
+ while (chars--) {
+ if (i-start>=max) {
*charp= endj;
- if(j>=oldc) {
- if(ch=='\0') *charp= txt_utf8_index_to_offset((*linep)->line, start);
+ 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;
end += max;
chop= 1;
}
- else if(ch==' ' || ch=='-' || ch=='\0') {
- if(j>=oldc) {
+ else if (ch==' ' || ch=='-' || ch=='\0') {
+ if (j>=oldc) {
*charp= txt_utf8_index_to_offset((*linep)->line, start);
loop= 0;
break;
@@ -1670,22 +1675,22 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
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') {
+ if (ch=='\t') {
chars= st->tabnumber-i%st->tabnumber;
ch= ' ';
}
else chars= 1;
- while(chars--) {
- if(i-start>=max) {
- if(chop) endj= BLI_str_prev_char_utf8((*linep)->line+j)-(*linep)->line;
+ while (chars--) {
+ 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;
+ if (endj>=oldc) {
+ if (ch=='\0') *charp= (*linep)->len;
else *charp= endj;
loop= 0;
break;
@@ -1694,11 +1699,13 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
start= end;
end += max;
chop= 1;
- } else if(ch=='\0') {
+ }
+ else if (ch=='\0') {
*charp= (*linep)->len;
loop= 0;
break;
- } else if(ch==' ' || ch=='-') {
+ }
+ else if (ch==' ' || ch=='-') {
end= i+1;
endj= j;
chop= 0;
@@ -1729,18 +1736,20 @@ static void txt_wrap_move_up(SpaceText *st, ARegion *ar, short sel)
wrap_offset_in_line(st, ar, *linep, *charp, &offl, &offc);
col= text_get_char_pos(st, (*linep)->line, *charp) + offc;
- if(offl) {
+ if (offl) {
*charp= text_get_cursor_rel(st, ar, *linep, offl-1, col);
newl= BLI_findindex(&text->lines, linep);
- } else {
- if((*linep)->prev) {
+ }
+ 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);
newl--;
- } else *charp= 0;
+ }
+ else *charp= 0;
}
if (!sel) txt_pop_sel(text);
@@ -1766,15 +1775,17 @@ static void txt_wrap_move_down(SpaceText *st, ARegion *ar, short sel)
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) {
+ 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) {
+ }
+ else {
+ if ((*linep)->next) {
*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);
@@ -1797,13 +1808,14 @@ static void cursor_skip(SpaceText* st, ARegion *ar, Text *text, int lines, int s
oldl= txt_get_span(text->lines.first, *linep);
oldc= *charp;
- if(st && ar && st->wordwrap) {
+ 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))
+ if (cursor_skip_find_line(st, ar, lines, linep, charp, &rell, &relc))
*charp= text_get_cursor_rel (st, ar, *linep, rell, relc);
- } else {
+ }
+ else {
while (lines>0 && (*linep)->next) {
*linep= (*linep)->next;
lines--;
@@ -1827,17 +1839,17 @@ static int text_move_cursor(bContext *C, int type, int select)
ARegion *ar= CTX_wm_region(C);
/* ensure we have the right region, it's optional */
- if(ar && ar->regiontype != RGN_TYPE_WINDOW)
+ if (ar && ar->regiontype != RGN_TYPE_WINDOW)
ar= NULL;
switch(type) {
case LINE_BEGIN:
- if(st && st->wordwrap && ar) txt_wrap_move_bol(st, ar, select);
+ if (st && st->wordwrap && ar) txt_wrap_move_bol(st, ar, select);
else txt_move_bol(text, select);
break;
case LINE_END:
- if(st && st->wordwrap && ar) txt_wrap_move_eol(st, ar, select);
+ if (st && st->wordwrap && ar) txt_wrap_move_eol(st, ar, select);
else txt_move_eol(text, select);
break;
@@ -1866,22 +1878,22 @@ static int text_move_cursor(bContext *C, int type, int select)
break;
case PREV_LINE:
- if(st && st->wordwrap && ar) txt_wrap_move_up(st, ar, select);
+ if (st && st->wordwrap && ar) txt_wrap_move_up(st, ar, select);
else txt_move_up(text, select);
break;
case NEXT_LINE:
- if(st && st->wordwrap && ar) txt_wrap_move_down(st, ar, select);
+ if (st && st->wordwrap && ar) txt_wrap_move_down(st, ar, select);
else txt_move_down(text, select);
break;
case PREV_PAGE:
- if(st) cursor_skip(st, ar, st->text, -st->viewlines, select);
+ if (st) cursor_skip(st, ar, st->text, -st->viewlines, select);
else cursor_skip(NULL, NULL, text, -10, select);
break;
case NEXT_PAGE:
- if(st) cursor_skip(st, ar, st->text, st->viewlines, select);
+ if (st) cursor_skip(st, ar, st->text, st->viewlines, select);
else cursor_skip(NULL, NULL, text, 10, select);
break;
}
@@ -1946,9 +1958,9 @@ static int text_jump_exec(bContext *C, wmOperator *op)
int line= RNA_int_get(op->ptr, "line");
short nlines= txt_get_span(text->lines.first, text->lines.last)+1;
- if(line < 1)
+ if (line < 1)
txt_move_toline(text, 1, 0);
- else if(line > nlines)
+ else if (line > nlines)
txt_move_toline(text, nlines-1, 0);
else
txt_move_toline(text, line-1, 0);
@@ -1997,13 +2009,13 @@ static int text_delete_exec(bContext *C, wmOperator *op)
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
- if(type == DEL_PREV_WORD)
+ if (type == DEL_PREV_WORD)
txt_backspace_word(text);
- else if(type == DEL_PREV_CHAR)
+ else if (type == DEL_PREV_CHAR)
txt_backspace_char(text);
- else if(type == DEL_NEXT_WORD)
+ else if (type == DEL_NEXT_WORD)
txt_delete_word(text);
- else if(type == DEL_NEXT_CHAR)
+ else if (type == DEL_NEXT_CHAR)
txt_delete_char(text);
text_update_line_edited(text->curl);
@@ -2012,7 +2024,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
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)
+ if (CTX_wm_space_text(C)->live_edit)
text_run_script(C, NULL);
return OPERATOR_FINISHED;
@@ -2070,8 +2082,8 @@ static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines)
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) */
@@ -2104,7 +2116,7 @@ static int text_scroll_exec(bContext *C, wmOperator *op)
int lines= RNA_int_get(op->ptr, "lines");
- if(lines == 0)
+ if (lines == 0)
return OPERATOR_CANCELLED;
txt_screen_skip(st, ar, lines*U.wheellinescroll);
@@ -2124,7 +2136,7 @@ static void text_scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
text_update_character_width(st);
- if(tsc->first) {
+ if (tsc->first) {
tsc->old[0]= mval[0];
tsc->old[1]= mval[1];
tsc->first= 0;
@@ -2133,7 +2145,7 @@ static void text_scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
tsc->delta[0]+= mval[0] - tsc->old[0];
tsc->delta[1]+= mval[1] - tsc->old[1];
- if(!tsc->scrollbar) {
+ if (!tsc->scrollbar) {
txtdelta[0]= -tsc->delta[0]/st->cwidth;
txtdelta[1]= tsc->delta[1]/st->lheight;
@@ -2145,15 +2157,15 @@ static void text_scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
tsc->delta[1]+= txtdelta[1]/st->pix_per_line;
}
- if(txtdelta[0] || txtdelta[1]) {
+ if (txtdelta[0] || txtdelta[1]) {
txt_screen_skip(st, ar, txtdelta[1]);
- if(st->wordwrap) {
+ if (st->wordwrap) {
st->left= 0;
}
else {
st->left+= txtdelta[0];
- if(st->left<0) st->left= 0;
+ if (st->left<0) st->left= 0;
}
ED_area_tag_redraw(CTX_wm_area(C));
@@ -2179,13 +2191,13 @@ static int text_scroll_modal(bContext *C, wmOperator *op, wmEvent *event)
switch(event->type) {
case MOUSEMOVE:
- if(tsc->zone == SCROLLHANDLE_BAR)
+ if (tsc->zone == SCROLLHANDLE_BAR)
text_scroll_apply(C, op, event);
break;
case LEFTMOUSE:
case RIGHTMOUSE:
case MIDDLEMOUSE:
- if(ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
+ if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
int last;
st->top+= st->viewlines * (tsc->zone==SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1);
@@ -2216,7 +2228,7 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
SpaceText *st= CTX_wm_space_text(C);
TextScroll *tsc;
- if(RNA_struct_property_is_set(op->ptr, "lines"))
+ if (RNA_struct_property_is_set(op->ptr, "lines"))
return text_scroll_exec(C, op);
tsc= MEM_callocN(sizeof(TextScroll), "TextScroll");
@@ -2279,10 +2291,10 @@ static int text_region_scroll_poll(bContext *C)
Text *text= CTX_data_edit_text(C);
ARegion *ar= CTX_wm_region(C);
- if(!st || !text)
+ if (!st || !text)
return 0;
- if(!ar || ar->regiontype != RGN_TYPE_WINDOW)
+ if (!ar || ar->regiontype != RGN_TYPE_WINDOW)
return 0;
return 1;
@@ -2296,22 +2308,22 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
const int *mval= event->mval;
int zone= -1;
- if(RNA_struct_property_is_set(op->ptr, "lines"))
+ 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 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;
}
}
- if(zone == -1) {
+ if (zone == -1) {
/* we are outside slider - nothing to do */
return OPERATOR_PASS_THROUGH;
}
@@ -2375,8 +2387,8 @@ 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') {
+ for (i = 0; str[i]; i += BLI_str_utf8_size(str+i)) {
+ if (str[i]=='\t') {
total += st->tabnumber - total%st->tabnumber;
}
else total++;
@@ -2389,7 +2401,7 @@ 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')
+ if (str[j]=='\t')
i += st->tabnumber - i%st->tabnumber;
else
i++;
@@ -2407,7 +2419,8 @@ static TextLine *get_first_visible_line(SpaceText *st, ARegion *ar, int *y)
if (i-lines < 0) {
*y += i;
break;
- } else {
+ }
+ else {
linep = linep->next;
i -= lines;
}
@@ -2426,7 +2439,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
/* Point to first visible line */
TextLine *linep = get_first_visible_line(st, ar, &y);
- while(loop && linep) {
+ while (loop && linep) {
int i = 0, start = 0, end = max; /* view */
int j = 0, curs = 0, endj = 0; /* mem */
int chop = 1; /* flags */
@@ -2436,7 +2449,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
/* Mimic replacement of tabs */
ch = linep->line[j];
- if(ch == '\t') {
+ if (ch == '\t') {
chars = st->tabnumber - i%st->tabnumber;
ch = ' ';
}
@@ -2457,7 +2470,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
found = 1;
/* Prepare curs for next wrap */
}
- else if(i - end == x) {
+ else if (i - end == x) {
curs = j;
}
if (i - start >= max) {
@@ -2469,11 +2482,11 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
break;
}
- if(chop) endj = j;
+ if (chop) endj = j;
start = end;
end += max;
- if(j < linep->len)
+ if (j < linep->len)
y--;
chop = 1;
@@ -2489,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;
@@ -2501,12 +2514,12 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
i++;
}
- if(ch == '\0') break;
+ if (ch == '\0') break;
}
- if(!loop || found) break;
+ if (!loop || found) break;
- if(!linep->next) {
+ if (!linep->next) {
charp = linep->len;
break;
}
@@ -2522,7 +2535,7 @@ static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, in
}
if (linep && charp != -1) {
- if(sel) { text->sell = linep; text->selc = charp; }
+ if (sel) { text->sell = linep; text->selc = charp; }
else { text->curl = linep; text->curc = charp; }
}
}
@@ -2533,13 +2546,13 @@ static void text_cursor_set_to_pos(SpaceText *st, ARegion *ar, int x, int y, int
text_update_character_width(st);
y= (ar->winy - 2 - y)/st->lheight;
- if(st->showlinenrs) x-= TXT_OFFSET+TEXTXLOC;
+ 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) {
+ if (st->wordwrap) {
text_cursor_set_to_pos_wrapped(st, ar, x, y, sel);
}
else {
@@ -2547,24 +2560,24 @@ 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; }
+ 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;
- 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);
+ if (x<w) *charp= flatten_index_to_offset(st, (*linep)->line, x);
else *charp= (*linep)->len;
}
- if(!sel) txt_pop_sel(text);
+ if (!sel) txt_pop_sel(text);
}
static void text_cursor_set_apply(bContext *C, wmOperator *op, wmEvent *event)
@@ -2573,18 +2586,18 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, wmEvent *event)
ARegion *ar= CTX_wm_region(C);
SetSelection *ssel= op->customdata;
- if(event->mval[1]<0 || event->mval[1]>ar->winy) {
+ 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);
+ 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_update_cursor_moved(C);
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);
@@ -2611,7 +2624,7 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
int linep2, charp2;
char *buffer;
- if(txt_has_sel(text)) {
+ if (txt_has_sel(text)) {
buffer = txt_sel_to_buf(text);
WM_clipboard_text_set(buffer, 1);
MEM_freeN(buffer);
@@ -2620,7 +2633,7 @@ static void text_cursor_set_exit(bContext *C, wmOperator *op)
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);
@@ -2634,7 +2647,7 @@ static int text_set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event
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");
@@ -2721,7 +2734,7 @@ static int text_cursor_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
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]);
@@ -2761,17 +2774,17 @@ static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent
text_update_character_width(st);
- if(!st->showlinenrs)
+ 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)
+ if (last_jump < time-1)
jump_to= 0;
jump_to *= 10;
@@ -2813,12 +2826,13 @@ static int text_insert_exec(bContext *C, wmOperator *op)
str= RNA_string_get_alloc(op->ptr, "text", NULL, 0);
- if(st && st->overwrite) {
+ if (st && st->overwrite) {
while (str[i]) {
code = BLI_str_utf8_as_unicode_step(str, &i);
done |= txt_replace_char(text, code);
}
- } else {
+ }
+ else {
while (str[i]) {
code = BLI_str_utf8_as_unicode_step(str, &i);
done |= txt_add_char(text, code);
@@ -2827,7 +2841,7 @@ static int text_insert_exec(bContext *C, wmOperator *op)
MEM_freeN(str);
- if(!done)
+ if (!done)
return OPERATOR_CANCELLED;
text_update_line_edited(text->curl);
@@ -2843,9 +2857,9 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
int ret;
// if(!RNA_struct_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */
- if(!RNA_string_length(op->ptr, "text")) {
+ if (!RNA_string_length(op->ptr, "text")) {
/* if alt/ctrl/super are pressed pass through */
- if(event->ctrl || event->oskey) {
+ if (event->ctrl || event->oskey) {
return OPERATOR_PASS_THROUGH;
}
else {
@@ -2855,7 +2869,8 @@ static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
if (event->utf8_buf[0]) {
len = BLI_str_utf8_size(event->utf8_buf);
memcpy(str, event->utf8_buf, len);
- } else {
+ }
+ else {
/* in theory, ghost can set value to extended ascii here */
len = BLI_str_utf8_from_unicode(event->ascii, str);
}
@@ -2867,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;
@@ -2908,18 +2923,18 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
int found = 0;
char *tmp;
- if(!st->findstr[0] || (mode == TEXT_REPLACE && !st->replacestr[0]))
+ if (!st->findstr[0] || (mode == TEXT_REPLACE && !st->replacestr[0]))
return OPERATOR_CANCELLED;
flags= st->flags;
- if(flags & ST_FIND_ALL)
+ if (flags & ST_FIND_ALL)
flags ^= ST_FIND_WRAP;
do {
int proceed= 0;
- if(first) {
- if(text->markers.first)
+ if (first) {
+ if (text->markers.first)
WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
txt_clear_markers(text, TMARK_GRP_FINDALL, 0);
@@ -2928,16 +2943,16 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
first= 0;
/* Replace current */
- if(mode!=TEXT_FIND && txt_has_sel(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;
+ 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 (proceed) {
+ if (mode==TEXT_REPLACE) {
txt_insert_buf(text, st->replacestr);
- if(text->curl && text->curl->format) {
+ if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format= NULL;
}
@@ -2945,12 +2960,12 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
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 (txt_find_marker(text, text->curl, text->selc, TMARK_GRP_FINDALL, 0)) {
+ if (tmp) MEM_freeN(tmp), tmp=NULL;
break;
}
@@ -2964,14 +2979,14 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
}
/* Find next */
- if(txt_find_string(text, st->findstr, flags & ST_FIND_WRAP, flags & ST_MATCH_CASE)) {
+ 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);
}
- else if(flags & ST_FIND_ALL) {
- if(text==start) break;
- if(!start) start= text;
- if(text->id.next)
+ else if (flags & ST_FIND_ALL) {
+ if (text==start) break;
+ if (!start) start= text;
+ if (text->id.next)
text= st->text= text->id.next;
else
text= st->text= bmain->text.first;
@@ -2981,11 +2996,11 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
first= 1;
}
else {
- if(!found && !proceed) BKE_reportf(op->reports, RPT_ERROR, "Text not found: %s", st->findstr);
+ 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;
}
@@ -3057,7 +3072,7 @@ static int text_find_set_selected_exec(bContext *C, wmOperator *op)
BLI_strncpy(st->findstr, tmp, ST_MAX_FIND_STR);
MEM_freeN(tmp);
- if(!st->findstr[0])
+ if (!st->findstr[0])
return OPERATOR_FINISHED;
return text_find_and_replace(C, op, TEXT_FIND);
@@ -3123,24 +3138,24 @@ int text_file_modified(Text *text)
int result;
char file[FILE_MAX];
- if(!text || !text->name)
+ if (!text || !text->name)
return 0;
BLI_strncpy(file, text->name, FILE_MAX);
BLI_path_abs(file, G.main->name);
- if(!BLI_exists(file))
+ if (!BLI_exists(file))
return 2;
result = stat(file, &st);
- if(result == -1)
+ if (result == -1)
return -1;
- if((st.st_mode & S_IFMT) != S_IFREG)
+ if ((st.st_mode & S_IFMT) != S_IFREG)
return -1;
- if(st.st_mtime > text->mtime)
+ if (st.st_mtime > text->mtime)
return 1;
return 0;
@@ -3152,16 +3167,16 @@ static void text_ignore_modified(Text *text)
int result;
char file[FILE_MAX];
- if(!text || !text->name) return;
+ if (!text || !text->name) return;
BLI_strncpy(file, text->name, FILE_MAX);
BLI_path_abs(file, G.main->name);
- if(!BLI_exists(file)) return;
+ if (!BLI_exists(file)) return;
result = stat(file, &st);
- if(result == -1 || (st.st_mode & S_IFMT) != S_IFREG)
+ if (result == -1 || (st.st_mode & S_IFMT) != S_IFREG)
return;
text->mtime= st.st_mtime;
@@ -3195,7 +3210,7 @@ static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, wmEvent *UN
switch(text_file_modified(text)) {
case 1:
- if(text->flags & TXT_ISDIRTY) {
+ 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);
@@ -3278,12 +3293,12 @@ void ED_text_undo_step(bContext *C, int step)
{
Text *text= CTX_data_edit_text(C);
- if(!text)
+ 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);
diff --git a/source/blender/editors/space_text/text_python.c b/source/blender/editors/space_text/text_python.c
index 88bd6b9c4c0..f8472a132e1 100644
--- a/source/blender/editors/space_text/text_python.c
+++ b/source/blender/editors/space_text/text_python.c
@@ -55,24 +55,24 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
int tgti, *top;
int mval[2] = {0, 0};
- if(!st || !st->text) return 0;
- if(!texttool_text_is_active(st->text)) return 0;
+ if (!st || !st->text) return 0;
+ if (!texttool_text_is_active(st->text)) return 0;
first = texttool_suggest_first();
last = texttool_suggest_last();
/* sel = texttool_suggest_selected(); */ /* UNUSED */
top = texttool_suggest_top();
- if(!last || !first)
+ if (!last || !first)
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) {
+ if (st->showlinenrs) {
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
@@ -85,19 +85,19 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
// 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)
+ if (tgti<0 || tgti>SUGG_LIST_SIZE)
return 1;
- for(i=tgti; i>0 && item->next; i--, item=item->next);
- if(item)
+ for (i=tgti; i>0 && item->next; i--, item=item->next);
+ if (item)
texttool_suggest_select(item);
return 1;
}
@@ -112,13 +112,13 @@ void text_pop_suggest_list(void)
top= texttool_suggest_top();
i= 0;
- while(item && item != sel) {
+ while (item && item != sel) {
item= item->next;
i++;
}
- if(i > *top+SUGG_LIST_SIZE-1)
+ if (i > *top+SUGG_LIST_SIZE-1)
*top= i-SUGG_LIST_SIZE+1;
- else if(i < *top)
+ else if (i < *top)
*top= i;
}
@@ -127,16 +127,16 @@ static void get_suggest_prefix(Text *text, int offset)
int i, len;
char *line, tmp[256];
- if(!text) return;
- if(!texttool_text_is_active(text)) return;
+ if (!text) return;
+ if (!texttool_text_is_active(text)) return;
line= text->curl->line;
- for(i=text->curc-1+offset; i>=0; i--)
- if(!text_check_identifier(line[i]))
+ for (i=text->curc-1+offset; i>=0; i--)
+ if (!text_check_identifier(line[i]))
break;
i++;
len= text->curc-i+offset;
- if(len > 255) {
+ if (len > 255) {
printf("Suggestion prefix too long\n");
len = 255;
}
@@ -151,29 +151,29 @@ static void confirm_suggestion(Text *text, int skipleft)
int i, over=0;
char *line;
- if(!text) return;
- if(!texttool_text_is_active(text)) return;
+ if (!text) return;
+ if (!texttool_text_is_active(text)) return;
sel = texttool_suggest_selected();
- if(!sel) return;
+ if (!sel) return;
line= text->curl->line;
i=text->curc-skipleft-1;
- while(i>=0) {
- if(!text_check_identifier(line[i]))
+ 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();
@@ -196,78 +196,78 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
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;
+ if (!texttool_text_is_active(st->text)) return 0;
+ if (!st->text || st->text->id.lib) return 0;
- if(st->doplugins && texttool_text_is_active(st->text)) {
- if(texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
- if(texttool_docs_get()) tools |= TOOL_DOCUMENT;
+ if (st->doplugins && texttool_text_is_active(st->text)) {
+ if (texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
+ if (texttool_docs_get()) tools |= TOOL_DOCUMENT;
}
- if(ascii) {
- if(tools & TOOL_SUGG_LIST) {
- if((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
+ if (ascii) {
+ if (tools & TOOL_SUGG_LIST) {
+ if ((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text->curl);
}
- else if((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
+ 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;
}
}
- 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))
+ if (text_do_suggest_select(st, ar))
swallow= 1;
else {
- if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
- if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+ if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
+ if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
}
draw= 1;
break;
case MIDDLEMOUSE:
- if(text_do_suggest_select(st, ar)) {
+ if (text_do_suggest_select(st, ar)) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text->curl);
swallow= 1;
}
else {
- if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
- if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+ if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
+ if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
}
draw= 1;
break;
case ESCKEY:
draw= swallow= 1;
- if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
- else if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
+ if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
+ else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
else draw= swallow= 0;
break;
case RETKEY:
- if(tools & TOOL_SUGG_LIST) {
+ if (tools & TOOL_SUGG_LIST) {
confirm_suggestion(st->text, 0);
text_update_line_edited(st->text->curl);
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:
- if(tools & TOOL_SUGG_LIST) {
- if(qual)
+ if (tools & TOOL_SUGG_LIST) {
+ if (qual)
texttool_suggest_clear();
else {
/* Work out which char we are about to delete/pass */
- if(st->text->curl && st->text->curc > 0) {
+ 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)) {
+ if ((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
get_suggest_prefix(st->text, -1);
text_pop_suggest_list();
}
@@ -278,17 +278,17 @@ 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) {
- if(qual)
+ if (tools & TOOL_SUGG_LIST) {
+ if (qual)
texttool_suggest_clear();
else {
/* Work out which char we are about to pass */
- if(st->text->curl && st->text->curc < st->text->curl->len) {
+ 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)) {
+ if ((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
get_suggest_prefix(st->text, 1);
text_pop_suggest_list();
}
@@ -299,24 +299,24 @@ 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;
case WHEELDOWNMOUSE:
case DOWNARROWKEY:
- if(tools & TOOL_DOCUMENT) {
+ if (tools & TOOL_DOCUMENT) {
doc_scroll++;
swallow= 1;
draw= 1;
break;
}
- else if(tools & TOOL_SUGG_LIST) {
+ else if (tools & TOOL_SUGG_LIST) {
SuggItem *sel = texttool_suggest_selected();
- if(!sel) {
+ if (!sel) {
texttool_suggest_select(texttool_suggest_first());
}
- else while(sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
+ else while (sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
texttool_suggest_select(sel->next);
sel= sel->next;
}
@@ -329,15 +329,15 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
scroll= SUGG_LIST_SIZE-1;
case WHEELUPMOUSE:
case UPARROWKEY:
- if(tools & TOOL_DOCUMENT) {
- if(doc_scroll>0) doc_scroll--;
+ if (tools & TOOL_DOCUMENT) {
+ if (doc_scroll>0) doc_scroll--;
swallow= 1;
draw= 1;
break;
}
- else if(tools & TOOL_SUGG_LIST) {
+ 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;
}
@@ -350,8 +350,8 @@ static short UNUSED_FUNCTION(do_texttools)(SpaceText *st, char ascii, unsigned s
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;
}
}
@@ -365,13 +365,13 @@ 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)) {
+ if (st->doplugins && event && val) {
+ if (BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
do_draw= 1;
}
}
#endif
- if(do_draw)
+ if (do_draw)
; // XXX redraw_alltext();
#endif
@@ -383,26 +383,26 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
int qual= 0; // XXX
text= st->text;
- if(!text || text->id.lib || text->curl != text->sell) return 0;
+ if (!text || text->id.lib || text->curl != text->sell) return 0;
marker= txt_find_marker(text, text->sell, text->selc, 0, 0);
- if(marker && (marker->start > text->curc || marker->end < text->curc))
+ if (marker && (marker->start > text->curc || marker->end < text->curc))
marker= NULL;
- if(!marker) {
+ if (!marker) {
/* Find the next temporary marker */
- if(evnt==TABKEY) {
+ 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))) {
+ 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;
break;
}
mrk= mrk->next;
}
- if(marker) {
+ 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);
@@ -412,60 +412,60 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
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;
}
- if(!swallow) return 0;
+ if (!swallow) return 0;
}
- if(ascii) {
- if(marker->flags & TMARK_EDITALL) {
+ 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;
+ if (s<0 || s>marker->end-marker->start) return 0;
mrk= txt_next_marker(text, marker);
- while(mrk) {
+ 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);
- if(st->overwrite) {
- if(txt_replace_char(text, ascii))
+ 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);
}
else {
- if(txt_add_char(text, ascii)) {
+ if (txt_add_char(text, ascii)) {
text_update_line_edited(st->text->curl);
}
}
- if(mrk==marker || mrk==nxt) break;
+ if (mrk==marker || mrk==nxt) break;
mrk=nxt;
}
swallow= 1;
draw= 1;
}
}
- else if(val) {
+ else if (val) {
switch(evnt) {
case BACKSPACEKEY:
- if(marker->flags & TMARK_EDITALL) {
+ 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;
+ if (s<0 || s>marker->end-marker->start) return 0;
mrk= txt_next_marker(text, marker);
- while(mrk) {
+ 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);
+ 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;
+ if (mrk==marker || mrk==nxt) break;
mrk= nxt;
}
swallow= 1;
@@ -473,19 +473,19 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
}
break;
case DELKEY:
- if(marker->flags & TMARK_EDITALL) {
+ 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;
+ if (s<0 || s>marker->end-marker->start) return 0;
mrk= txt_next_marker(text, marker);
- while(mrk) {
+ 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);
+ 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;
+ if (mrk==marker || mrk==nxt) break;
mrk= nxt;
}
swallow= 1;
@@ -493,20 +493,20 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
}
break;
case TABKEY:
- if(qual & LR_SHIFTKEY) {
+ if (qual & LR_SHIFTKEY) {
nxt= marker->prev;
- if(!nxt) nxt= text->markers.last;
+ if (!nxt) nxt= text->markers.last;
}
else {
nxt= marker->next;
- if(!nxt) nxt= text->markers.first;
+ if (!nxt) nxt= text->markers.first;
}
- if(marker->flags & TMARK_TEMP) {
- if(nxt==marker) nxt= NULL;
+ if (marker->flags & TMARK_TEMP) {
+ if (nxt==marker) nxt= NULL;
BLI_freelinkN(&text->markers, marker);
}
mrk= nxt;
- if(mrk) {
+ 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);
@@ -521,7 +521,7 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
case ZKEY: if(evnt==ZKEY && !(qual & LR_CTRLKEY)) break;
case RETKEY:
case ESCKEY:
- if(marker->flags & (TMARK_EDITALL | TMARK_TEMP))
+ if (marker->flags & (TMARK_EDITALL | TMARK_TEMP))
txt_clear_markers(text, marker->group, 0);
else
BLI_freelinkN(&text->markers, marker);
@@ -532,11 +532,11 @@ static short UNUSED_FUNCTION(do_textmarkers)(SpaceText *st, char ascii, unsigned
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)
+ if (qual!=0 && qual!=LR_SHIFTKEY)
swallow= 1; /* Swallow all other shortcut events */
}
}