[Bf-blender-cvs] [c053c4ceba1] soc-2020-info-editor: Separate formatting from space text
Mateusz GrzeliÅski
noreply at git.blender.org
Thu Jul 23 16:58:38 CEST 2020
Commit: c053c4ceba1d499c5e50fe84b6cf945c2d14a1a1
Author: Mateusz Grzeliński
Date: Wed Jul 22 19:00:59 2020 +0200
Branches: soc-2020-info-editor
https://developer.blender.org/rBc053c4ceba1d499c5e50fe84b6cf945c2d14a1a1
Separate formatting from space text
This is preparation for reusable syntax highlighting
===================================================================
M source/blender/editors/space_text/text_draw.c
M source/blender/editors/space_text/text_format.c
M source/blender/editors/space_text/text_format.h
M source/blender/editors/space_text/text_format_lua.c
M source/blender/editors/space_text/text_format_osl.c
M source/blender/editors/space_text/text_format_pov.c
M source/blender/editors/space_text/text_format_pov_ini.c
M source/blender/editors/space_text/text_format_py.c
M source/blender/editors/space_text/text_ops.c
===================================================================
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index e9ac6946032..ce2beb430f1 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -430,7 +430,7 @@ static int text_draw_wrapped(const SpaceText *st,
/* don't draw lines below this */
const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
- flatten_string(st, &fs, str);
+ flatten_string(&fs, st->tabnumber, str);
str = fs.buf;
max = w / st->runtime.cwidth_px;
if (max < 8) {
@@ -520,7 +520,7 @@ static void text_draw(const SpaceText *st,
int columns, size, n, w = 0, padding, amount = 0;
const char *in = NULL;
- for (n = flatten_string(st, &fs, str), str = fs.buf; n > 0; n--) {
+ for (n = flatten_string(&fs, st->tabnumber, str), str = fs.buf; n > 0; n--) {
columns = BLI_str_utf8_char_width_safe(str);
size = BLI_str_utf8_size_safe(str);
@@ -1599,7 +1599,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
lineno = 0;
for (i = 0; i < st->top && tmp; i++) {
if (tdc.syntax_highlight && !tmp->format) {
- tft->format_line(st, tmp, false);
+ tft->format_line(tmp, st->tabnumber, false);
}
if (st->wordwrap) {
@@ -1658,7 +1658,7 @@ void draw_text_main(SpaceText *st, ARegion *region)
for (i = 0; y > clip_min_y && i < viewlines && tmp; i++, tmp = tmp->next) {
if (tdc.syntax_highlight && !tmp->format) {
- tft->format_line(st, tmp, false);
+ tft->format_line(tmp, st->tabnumber, false);
}
if (st->showlinenrs && !wrap_skip) {
diff --git a/source/blender/editors/space_text/text_format.c b/source/blender/editors/space_text/text_format.c
index d099f2a20d8..a0f0adfbd88 100644
--- a/source/blender/editors/space_text/text_format.c
+++ b/source/blender/editors/space_text/text_format.c
@@ -68,7 +68,7 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i
fs->pos += len;
}
-int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
+int flatten_string(FlattenString *fs, int tabnumber, const char *in)
{
int r, i, total = 0;
@@ -79,7 +79,7 @@ int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
for (r = 0, i = 0; *in; r++) {
if (*in == '\t') {
- i = st->tabnumber - (total % st->tabnumber);
+ i = tabnumber - (total % tabnumber);
total += i;
while (i--) {
@@ -205,16 +205,26 @@ TextFormatType *ED_text_format_get(Text *text)
const char *text_ext = strchr(text->id.name + 2, '.');
if (text_ext) {
text_ext++; /* skip the '.' */
- /* Check all text formats in the static list */
- for (tft = tft_lb.first; tft; tft = tft->next) {
- /* All formats should have an ext, but just in case */
- const char **ext;
- for (ext = tft->ext; *ext; ext++) {
- /* If extension matches text name, return the matching tft */
- if (BLI_strcasecmp(text_ext, *ext) == 0) {
- return tft;
- }
- }
+ return ED_text_format_get_by_extension(text_ext);
+ }
+ }
+
+ /* Return the "default" text format */
+ return tft_lb.first;
+}
+
+TextFormatType *ED_text_format_get_by_extension(const char *extension)
+{
+ TextFormatType *tft;
+
+ /* Check all text formats in the static list */
+ for (tft = tft_lb.first; tft; tft = tft->next) {
+ /* All formats should have an ext, but just in case */
+ const char **ext;
+ for (ext = tft->ext; *ext; ext++) {
+ /* If extension matches text name, return the matching tft */
+ if (BLI_strcasecmp(extension, *ext) == 0) {
+ return tft;
}
}
diff --git a/source/blender/editors/space_text/text_format.h b/source/blender/editors/space_text/text_format.h
index 07635e4227a..c1aec707961 100644
--- a/source/blender/editors/space_text/text_format.h
+++ b/source/blender/editors/space_text/text_format.h
@@ -47,7 +47,7 @@ enum {
#define FMT_CONT_ALL \
(FMT_CONT_QUOTESINGLE | FMT_CONT_QUOTEDOUBLE | FMT_CONT_TRIPLE | FMT_CONT_COMMENT_C)
-int flatten_string(const struct SpaceText *st, FlattenString *fs, const char *in);
+int flatten_string(FlattenString *fs, int tabnumber, const char *in);
void flatten_string_free(FlattenString *fs);
int flatten_string_strlen(FlattenString *fs, const char *str);
@@ -70,7 +70,7 @@ typedef struct TextFormatType {
*
* See: FMT_TYPE_ enums below
*/
- void (*format_line)(SpaceText *st, TextLine *line, const bool do_next);
+ void (*format_line)(TextLine *line, int tabnumber, const bool do_next);
const char **ext; /* NULL terminated extensions */
} TextFormatType;
@@ -99,6 +99,7 @@ enum {
};
TextFormatType *ED_text_format_get(Text *text);
+TextFormatType *ED_text_format_get_by_extension(const char *extension);
void ED_text_format_register(TextFormatType *tft);
/* formatters */
diff --git a/source/blender/editors/space_text/text_format_lua.c b/source/blender/editors/space_text/text_format_lua.c
index 4f6d91451e0..ba1c8b89b8a 100644
--- a/source/blender/editors/space_text/text_format_lua.c
+++ b/source/blender/editors/space_text/text_format_lua.c
@@ -175,7 +175,7 @@ static char txtfmt_lua_format_identifier(const char *str)
return fmt;
}
-static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_next)
+static void txtfmt_lua_format_line(TextLine *line, int tabnumber, const bool do_next)
{
FlattenString fs;
const char *str;
@@ -203,7 +203,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
cont_orig = 0xFF;
}
- len = flatten_string(st, &fs, line->line);
+ len = flatten_string(&fs, tabnumber, line->line);
str = fs.buf;
if (!text_check_format_len(line, len)) {
flatten_string_free(&fs);
@@ -339,7 +339,7 @@ static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const bool do_
/* If continuation has changed and we're allowed, process the next line */
if (cont != cont_orig && do_next && line->next) {
- txtfmt_lua_format_line(st, line->next, do_next);
+ txtfmt_lua_format_line(line->next, tabnumber, do_next);
}
flatten_string_free(&fs);
diff --git a/source/blender/editors/space_text/text_format_osl.c b/source/blender/editors/space_text/text_format_osl.c
index b205996d1d2..945b385f167 100644
--- a/source/blender/editors/space_text/text_format_osl.c
+++ b/source/blender/editors/space_text/text_format_osl.c
@@ -201,7 +201,7 @@ static char txtfmt_osl_format_identifier(const char *str)
return fmt;
}
-static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_next)
+static void txtfmt_osl_format_line(TextLine *line, int tabnumber, const bool do_next)
{
FlattenString fs;
const char *str;
@@ -229,7 +229,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
cont_orig = 0xFF;
}
- len = flatten_string(st, &fs, line->line);
+ len = flatten_string(&fs, tabnumber, line->line);
str = fs.buf;
if (!text_check_format_len(line, len)) {
flatten_string_free(&fs);
@@ -357,7 +357,7 @@ static void txtfmt_osl_format_line(SpaceText *st, TextLine *line, const bool do_
/* If continuation has changed and we're allowed, process the next line */
if (cont != cont_orig && do_next && line->next) {
- txtfmt_osl_format_line(st, line->next, do_next);
+ txtfmt_osl_format_line(line->next, tabnumber, do_next);
}
flatten_string_free(&fs);
diff --git a/source/blender/editors/space_text/text_format_pov.c b/source/blender/editors/space_text/text_format_pov.c
index 96d9c234a40..492b1c7d8d4 100644
--- a/source/blender/editors/space_text/text_format_pov.c
+++ b/source/blender/editors/space_text/text_format_pov.c
@@ -774,7 +774,7 @@ static char txtfmt_pov_format_identifier(const char *str)
return fmt;
}
-static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_next)
+static void txtfmt_pov_format_line(TextLine *line, int tabnumber, const bool do_next)
{
FlattenString fs;
const char *str;
@@ -802,7 +802,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
cont_orig = 0xFF;
}
- len = flatten_string(st, &fs, line->line);
+ len = flatten_string(&fs, tabnumber, line->line);
str = fs.buf;
if (!text_check_format_len(line, len)) {
flatten_string_free(&fs);
@@ -934,7 +934,7 @@ static void txtfmt_pov_format_line(SpaceText *st, TextLine *line, const bool do_
/* If continuation has changed and we're allowed, process the next line */
if (cont != cont_orig && do_next && line->next) {
- txtfmt_pov_format_line(st, line->next, do_next);
+ txtfmt_pov_format_line(line->next, tabnumber, do_next);
}
flatten_string_free(&fs);
diff --git a/source/blender/editors/space_text/text_format_pov_ini.c b/source/blender/editors/space_text/text_format_pov_ini.c
index 8d6b877d3f7..5692e457b9a 100644
--- a/source/blender/editors/space_text/text_format_pov_ini.c
+++ b/source/blender/editors/space_text/text_format_pov_ini.c
@@ -359,7 +359,7 @@ static char txtfmt_pov_ini_format_identifier(const char *str)
return fmt;
}
-static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool do_next)
+static void txtfmt_pov_ini_format_line(TextLine *line, int tabnumber, const bool do_next)
{
FlattenString fs;
const char *str;
@@ -387,7 +387,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
cont_orig = 0xFF;
}
- len = flatten_string(st, &fs, line->line);
+ len = flatten_string(&fs, tabnumber, line->line);
str = fs.buf;
if (!text_check_format_len(line, len)) {
flatten_string_free(&fs);
@@ -510,7 +510,7 @@ static void txtfmt_pov_ini_format_line(SpaceText *st, TextLine *line, const bool
/* If continuation has changed and we're allowed, process the next line */
if (cont != cont_orig && do_next && line->next) {
- txtfmt_pov_ini_format_line(st, line->next, do_next);
+ txtfmt_pov_ini_format_line(line->next, tabnumber, do_next);
}
flatten_string_free(&fs);
diff --git a/source/blender/editors/space_text/text_format_py.c b/source/blender/editors/space_text/text_format_py
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list