[Bf-blender-cvs] [ad1ea9a427e] master: Undo: split text undo steps out of the data-block
Campbell Barton
noreply at git.blender.org
Thu Apr 5 15:59:04 CEST 2018
Commit: ad1ea9a427e3543a43ca2589f87f0c94b9be03ca
Author: Campbell Barton
Date: Thu Apr 5 15:22:33 2018 +0200
Branches: master
https://developer.blender.org/rBad1ea9a427e3543a43ca2589f87f0c94b9be03ca
Undo: split text undo steps out of the data-block
This moves undo storage into a separate struct which is passed
in from the undo system.
===================================================================
M source/blender/blenkernel/BKE_text.h
M source/blender/blenkernel/intern/text.c
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/include/ED_text.h
M source/blender/editors/interface/interface_ops.c
M source/blender/editors/space_text/text_autocomplete.c
M source/blender/editors/space_text/text_ops.c
M source/blender/editors/space_text/text_undo.c
M source/blender/editors/undo/undo_system_types.c
M source/blender/makesdna/DNA_text_types.h
M source/blender/makesrna/intern/rna_text_api.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index b3b1ad23b32..98db06752c8 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -40,6 +40,7 @@ extern "C" {
struct Main;
struct Text;
struct TextLine;
+struct TextUndoBuf;
void BKE_text_free_lines (struct Text *text);
void BKE_text_free (struct Text *text);
@@ -55,8 +56,8 @@ struct Text *BKE_text_load (struct Main *bmain, const char *file, const char
void BKE_text_copy_data(struct Main *bmain, struct Text *ta_dst, const struct Text *ta_src, const int flag);
struct Text *BKE_text_copy (struct Main *bmain, const struct Text *ta);
void BKE_text_make_local (struct Main *bmain, struct Text *text, const bool lib_local);
-void BKE_text_clear (struct Text *text);
-void BKE_text_write (struct Text *text, const char *str);
+void BKE_text_clear (struct Text *text, struct TextUndoBuf *utxt);
+void BKE_text_write (struct Text *text, struct TextUndoBuf *utxt, const char *str);
int BKE_text_file_modified_check(struct Text *text);
void BKE_text_file_modified_ignore(struct Text *text);
@@ -83,29 +84,29 @@ void txt_move_eol (struct Text *text, const bool sel);
void txt_move_toline (struct Text *text, unsigned int line, const bool sel);
void txt_move_to (struct Text *text, unsigned int line, unsigned int ch, const bool sel);
void txt_pop_sel (struct Text *text);
-void txt_delete_char (struct Text *text);
-void txt_delete_word (struct Text *text);
-void txt_delete_selected (struct Text *text);
+void txt_delete_char (struct Text *text, struct TextUndoBuf *utxt);
+void txt_delete_word (struct Text *text, struct TextUndoBuf *utxt);
+void txt_delete_selected (struct Text *text, struct TextUndoBuf *utxt);
void txt_sel_all (struct Text *text);
void txt_sel_clear (struct Text *text);
void txt_sel_line (struct Text *text);
char *txt_sel_to_buf (struct Text *text);
-void txt_insert_buf (struct Text *text, const char *in_buffer);
-void txt_undo_add_op (struct Text *text, int op);
-void txt_do_undo (struct Text *text);
-void txt_do_redo (struct Text *text);
-void txt_split_curline (struct Text *text);
-void txt_backspace_char (struct Text *text);
-void txt_backspace_word (struct Text *text);
-bool txt_add_char (struct Text *text, unsigned int add);
-bool txt_add_raw_char (struct Text *text, unsigned int add);
-bool txt_replace_char (struct Text *text, unsigned int add);
-void txt_unindent (struct Text *text);
-void txt_comment (struct Text *text);
-void txt_indent (struct Text *text);
-void txt_uncomment (struct Text *text);
-void txt_move_lines (struct Text *text, const int direction);
-void txt_duplicate_line (struct Text *text);
+void txt_insert_buf (struct Text *text, struct TextUndoBuf *utxt, const char *in_buffer);
+void txt_undo_add_op (struct Text *text, struct TextUndoBuf *utxt, int op);
+void txt_do_undo (struct Text *text, struct TextUndoBuf *utxt);
+void txt_do_redo (struct Text *text, struct TextUndoBuf *utxt);
+void txt_split_curline (struct Text *text, struct TextUndoBuf *utxt);
+void txt_backspace_char (struct Text *text, struct TextUndoBuf *utxt);
+void txt_backspace_word (struct Text *text, struct TextUndoBuf *utxt);
+bool txt_add_char (struct Text *text, struct TextUndoBuf *utxt, unsigned int add);
+bool txt_add_raw_char (struct Text *text, struct TextUndoBuf *utxt, unsigned int add);
+bool txt_replace_char (struct Text *text, struct TextUndoBuf *utxt, unsigned int add);
+void txt_unindent (struct Text *text, struct TextUndoBuf *utxt);
+void txt_comment (struct Text *text, struct TextUndoBuf *utxt);
+void txt_indent (struct Text *text, struct TextUndoBuf *utxt);
+void txt_uncomment (struct Text *text, struct TextUndoBuf *utxt);
+void txt_move_lines (struct Text *text, struct TextUndoBuf *utxt, const int direction);
+void txt_duplicate_line (struct Text *text, struct TextUndoBuf *utxt);
int txt_setcurr_tab_spaces(struct Text *text, int space);
bool txt_cursor_is_line_start(struct Text *text);
bool txt_cursor_is_line_end(struct Text *text);
@@ -135,6 +136,11 @@ enum {
TXT_MOVE_LINE_DOWN = 1
};
+typedef struct TextUndoBuf {
+ char *buf;
+ int pos, len;
+} TextUndoBuf;
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index b8307031920..c7588a4ed48 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -168,9 +168,9 @@ enum {
static void txt_pop_first(Text *text);
static void txt_pop_last(Text *text);
-static void txt_undo_add_blockop(Text *text, int op, const char *buf);
+static void txt_undo_add_blockop(Text *text, TextUndoBuf *utxt, int op, const char *buf);
static void txt_delete_line(Text *text, TextLine *line);
-static void txt_delete_sel(Text *text);
+static void txt_delete_sel(Text *text, TextUndoBuf *utxt);
static void txt_make_dirty(Text *text);
/***/
@@ -188,13 +188,6 @@ int txt_get_undostate(void)
return undoing;
}
-static void init_undo_text(Text *text)
-{
- text->undo_pos = -1;
- text->undo_len = 0;
- text->undo_buf = NULL;
-}
-
/**
* \note caller must handle `undo_buf` and `compiled` members.
*/
@@ -222,7 +215,6 @@ void BKE_text_free(Text *text)
BKE_text_free_lines(text);
MEM_SAFE_FREE(text->name);
- MEM_SAFE_FREE(text->undo_buf);
#ifdef WITH_PYTHON
BPY_text_free_code(text);
#endif
@@ -236,8 +228,6 @@ void BKE_text_init(Text *ta)
ta->name = NULL;
- init_undo_text(ta);
-
ta->nlines = 1;
ta->flags = TXT_ISDIRTY | TXT_ISMEM;
if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0)
@@ -419,10 +409,6 @@ bool BKE_text_reload(Text *text)
txt_make_dirty(text);
/* clear undo buffer */
- MEM_freeN(text->undo_buf);
- init_undo_text(text);
-
-
if (BLI_stat(filepath_abs, &st) != -1) {
text->mtime = st.st_mtime;
}
@@ -471,8 +457,6 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
}
/* clear undo buffer */
- init_undo_text(ta);
-
if (BLI_stat(filepath_abs, &st) != -1) {
ta->mtime = st.st_mtime;
}
@@ -526,8 +510,6 @@ void BKE_text_copy_data(Main *UNUSED(bmain), Text *ta_dst, const Text *ta_src, c
ta_dst->curl = ta_dst->sell = ta_dst->lines.first;
ta_dst->curc = ta_dst->selc = 0;
-
- init_undo_text(ta_dst);
}
Text *BKE_text_copy(Main *bmain, const Text *ta)
@@ -542,25 +524,29 @@ void BKE_text_make_local(Main *bmain, Text *text, const bool lib_local)
BKE_id_make_local_generic(bmain, &text->id, true, lib_local);
}
-void BKE_text_clear(Text *text) /* called directly from rna */
+void BKE_text_clear(Text *text, TextUndoBuf *utxt) /* called directly from rna */
{
int oldstate;
- oldstate = txt_get_undostate();
- txt_set_undostate(1);
+ if (utxt) {
+ oldstate = txt_get_undostate();
+ }
+ txt_set_undostate(utxt != NULL);
+
txt_sel_all(text);
- txt_delete_sel(text);
+ txt_delete_sel(text, utxt);
+
txt_set_undostate(oldstate);
txt_make_dirty(text);
}
-void BKE_text_write(Text *text, const char *str) /* called directly from rna */
+void BKE_text_write(Text *text, TextUndoBuf *utxt, const char *str) /* called directly from rna */
{
int oldstate;
oldstate = txt_get_undostate();
- txt_insert_buf(text, str);
+ txt_insert_buf(text, utxt, str);
txt_move_eof(text, 0);
txt_set_undostate(oldstate);
@@ -1153,7 +1139,7 @@ bool txt_has_sel(Text *text)
return ((text->curl != text->sell) || (text->curc != text->selc));
}
-static void txt_delete_sel(Text *text)
+static void txt_delete_sel(Text *text, TextUndoBuf *utxt)
{
TextLine *tmpl;
char *buf;
@@ -1167,7 +1153,7 @@ static void txt_delete_sel(Text *text)
if (!undoing) {
buf = txt_sel_to_buf(text);
- txt_undo_add_blockop(text, UNDO_DBLOCK, buf);
+ txt_undo_add_blockop(text, utxt, UNDO_DBLOCK, buf);
MEM_freeN(buf);
}
@@ -1408,7 +1394,7 @@ char *txt_sel_to_buf(Text *text)
return buf;
}
-void txt_insert_buf(Text *text, const char *in_buffer)
+void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
{
int l = 0, u, len;
size_t i = 0, j;
@@ -1417,22 +1403,22 @@ void txt_insert_buf(Text *text, const char *in_buffer)
if (!in_buffer) return;
- txt_delete_sel(text);
+ txt_delete_sel(text, utxt);
len = strlen(in_buffer);
buffer = BLI_strdupn(in_buffer, len);
len += txt_extended_ascii_as_utf8(&buffer);
- if (!undoing) txt_undo_add_blockop(text, UNDO_IBLOCK, buffer);
+ if (!undoing) txt_undo_add_blockop(text, utxt, UNDO_IBLOCK, buffer);
u = undoing;
undoing = 1;
/* Read the first line (or as close as possible */
while (buffer[i] && buffer[i] != '\n')
- txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i));
+ txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &i));
- if (buffer[i] == '\n') txt_split_curline(text);
+ if (buffer[i] == '\n') txt_split_curline(text, utxt);
else { undoing = u; MEM_freeN(buffer); return; }
i++;
@@ -1450,7 +1436,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
}
else {
for (j = i - l; j < i && j < len; )
- txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j));
+ txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &j));
break;
}
}
@@ -1464,7 +1450,7 @@ void txt_insert_buf(Text *text, const char *in_buffer)
/* Undo functions */
/******************/
-static bool max_undo_test(Text *text, int x)
+static bool max_undo_test(TextUndoBuf *utxt, int x)
{
/* Normally over-allocating is preferred,
* however in this case the buffer is small enough and re-allocation
@@ -1474,25 +1460,24 @@ static bool max_undo_test(Text *text, int x)
*/
/* Add one for the null terminator. */
- text->undo_len = text->undo_pos + x + 1;
- if (text->undo_len > TXT_MAX_UNDO) {
+ utxt->len = utxt->pos + x + 1;
+ if (utxt->len > TXT_MAX_UNDO) {
/* XXX error("Undo limit reached, buffer cleared\n"); */
- MEM_freeN(text->undo_buf);
- init_undo_text(text);
+ MEM_freeN(utxt->buf);
return false;
}
else {
/* Small reallocations on each undo step is fine. */
- text->undo_buf = MEM_recallocN(text->und
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list