diff options
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index bce2266f3e9..5f85e1a1664 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -59,34 +59,6 @@ # include "BPY_extern.h" #endif -/* - * How Texts should work - * -- - * A text should relate to a file as follows - - * (Text *)->name should be the place where the - * file will or has been saved. - * - * (Text *)->flags has the following bits - * TXT_ISDIRTY - should always be set if the file in mem. differs from - * the file on disk, or if there is no file on disk. - * TXT_ISMEM - should always be set if the Text has not been mapped to - * a file, in which case (Text *)->name may be NULL or garbage. - * TXT_ISEXT - should always be set if the Text is not to be written into - * the .blend - * TXT_ISSCRIPT - should be set if the user has designated the text - * as a script. (NEW: this was unused, but now it is needed by - * space handler script links (see header_view3d.c, for example) - * - * ->>> see also: /makesdna/DNA_text_types.h - * - * Display - * -- - * - * The st->top determines at what line the top of the text is displayed. - * If the user moves the cursor the st containing that cursor should - * be popped ... other st's retain their own top location. - */ - /* -------------------------------------------------------------------- */ /** \name Prototypes * \{ */ @@ -110,9 +82,8 @@ static void text_init_data(ID *id) BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(text, id)); - text->name = NULL; + text->filepath = NULL; - text->nlines = 1; text->flags = TXT_ISDIRTY | TXT_ISMEM; if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) { text->flags |= TXT_TABSTOSPACES; @@ -157,8 +128,8 @@ static void text_copy_data(Main *UNUSED(bmain), const Text *text_src = (Text *)id_src; /* File name can be NULL. */ - if (text_src->name) { - text_dst->name = BLI_strdup(text_src->name); + if (text_src->filepath) { + text_dst->filepath = BLI_strdup(text_src->filepath); } text_dst->flags |= TXT_ISDIRTY; @@ -190,7 +161,7 @@ static void text_free_data(ID *id) BKE_text_free_lines(text); - MEM_SAFE_FREE(text->name); + MEM_SAFE_FREE(text->filepath); #ifdef WITH_PYTHON BPY_text_free_code(text); #endif @@ -316,12 +287,12 @@ static void cleanup_textline(TextLine *tl) */ static void text_from_buf(Text *text, const unsigned char *buffer, const int len) { - int i, llen; + int i, llen, lines_count; BLI_assert(BLI_listbase_is_empty(&text->lines)); - text->nlines = 0; llen = 0; + lines_count = 0; for (i = 0; i < len; i++) { if (buffer[i] == '\n') { TextLine *tmp; @@ -339,7 +310,7 @@ static void text_from_buf(Text *text, const unsigned char *buffer, const int len cleanup_textline(tmp); BLI_addtail(&text->lines, tmp); - text->nlines++; + lines_count += 1; llen = 0; continue; @@ -353,7 +324,7 @@ static void text_from_buf(Text *text, const unsigned char *buffer, const int len * - file is empty. in this case new line is needed to start editing from. * - last character in buffer is \n. in this case new line is needed to * deal with newline at end of file. (see [#28087]) (sergey) */ - if (llen != 0 || text->nlines == 0 || buffer[len - 1] == '\n') { + if (llen != 0 || lines_count == 0 || buffer[len - 1] == '\n') { TextLine *tmp; tmp = (TextLine *)MEM_mallocN(sizeof(TextLine), "textline"); @@ -370,7 +341,7 @@ static void text_from_buf(Text *text, const unsigned char *buffer, const int len cleanup_textline(tmp); BLI_addtail(&text->lines, tmp); - text->nlines++; + /* lines_count += 1; */ /* UNUSED */ } text->curl = text->sell = text->lines.first; @@ -384,11 +355,11 @@ bool BKE_text_reload(Text *text) char filepath_abs[FILE_MAX]; BLI_stat_t st; - if (!text->name) { + if (!text->filepath) { return false; } - BLI_strncpy(filepath_abs, text->name, FILE_MAX); + BLI_strncpy(filepath_abs, text->filepath, FILE_MAX); BLI_path_abs(filepath_abs, ID_BLEND_PATH_FROM_GLOBAL(&text->id)); buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len); @@ -444,8 +415,8 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const } if (is_internal == false) { - ta->name = MEM_mallocN(strlen(file) + 1, "text_name"); - strcpy(ta->name, file); + ta->filepath = MEM_mallocN(strlen(file) + 1, "text_name"); + strcpy(ta->filepath, file); } else { ta->flags |= TXT_ISMEM | TXT_ISDIRTY; @@ -503,11 +474,11 @@ int BKE_text_file_modified_check(Text *text) int result; char file[FILE_MAX]; - if (!text->name) { + if (!text->filepath) { return 0; } - BLI_strncpy(file, text->name, FILE_MAX); + BLI_strncpy(file, text->filepath, FILE_MAX); BLI_path_abs(file, ID_BLEND_PATH_FROM_GLOBAL(&text->id)); if (!BLI_exists(file)) { @@ -537,11 +508,11 @@ void BKE_text_file_modified_ignore(Text *text) int result; char file[FILE_MAX]; - if (!text->name) { + if (!text->filepath) { return; } - BLI_strncpy(file, text->name, FILE_MAX); + BLI_strncpy(file, text->filepath, FILE_MAX); BLI_path_abs(file, ID_BLEND_PATH_FROM_GLOBAL(&text->id)); if (!BLI_exists(file)) { @@ -738,6 +709,10 @@ bool txt_cursor_is_line_end(Text *text) /* -------------------------------------------------------------------- */ /** \name Cursor Movement Functions + * + * \note If the user moves the cursor the space containing that cursor should be popped + * See #txt_pop_first, #txt_pop_last + * Other space-types retain their own top location. * \{ */ void txt_move_up(Text *text, const bool sel) @@ -1309,6 +1284,8 @@ void txt_sel_set(Text *text, int startl, int startc, int endl, int endc) text->selc = BLI_str_utf8_offset_from_index(tol->line, endc); } +/** \} */ + /* -------------------------------------------------------------------- */ /** \name Buffer Conversion for Undo/Redo * @@ -2105,8 +2082,6 @@ static void txt_select_prefix(Text *text, const char *add, bool skip_blank_lines /** * Generic un-prefix operation, use for comment & indent. * - * \param r_line_index_mask: List of lines that are already at indent level 0, - * to store them later into the undo buffer. * \param require_all: When true, all non-empty lines must have this prefix. * Needed for comments where we might want to un-comment a block which contains some comments. * |