[Bf-blender-cvs] [d0e3fbc06b9] master: Cleanup: remove undoing access, minor formatting

Campbell Barton noreply at git.blender.org
Sun Apr 15 10:51:42 CEST 2018


Commit: d0e3fbc06b9c1560c98ba294912ff03ebe71acc5
Author: Campbell Barton
Date:   Sun Apr 15 10:48:50 2018 +0200
Branches: master
https://developer.blender.org/rBd0e3fbc06b9c1560c98ba294912ff03ebe71acc5

Cleanup: remove undoing access, minor formatting

Access to undoing state isn't needed,
some text insert code was overly compacted.

===================================================================

M	source/blender/blenkernel/BKE_text.h
M	source/blender/blenkernel/intern/text.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index 98db06752c8..b53af3cec53 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -44,8 +44,6 @@ struct TextUndoBuf;
 
 void			BKE_text_free_lines	(struct Text *text);
 void			BKE_text_free		(struct Text *text);
-void 			txt_set_undostate	(int u);
-int 			txt_get_undostate	(void);
 void            BKE_text_init(struct Text *ta);
 struct Text    *BKE_text_add	(struct Main *bmain, const char *name);
 int				txt_extended_ascii_as_utf8(char **str);
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 212a9c86613..b650b6e9fb8 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -175,18 +175,12 @@ static void txt_make_dirty(Text *text);
 
 /***/
 
-static unsigned char undoing;
-
-/* allow to switch off undoing externally */
-void txt_set_undostate(int u)
-{
-	undoing = u;
-}
-
-int txt_get_undostate(void)
-{
-	return undoing;
-}
+/**
+ * Set to true when undoing (so we don't generate undo steps while undoing).
+ *
+ * Also use to disable undo entirely.
+ */
+static bool undoing;
 
 /**
  * \note caller must handle `undo_buf` and `compiled` members.
@@ -526,26 +520,26 @@ void BKE_text_make_local(Main *bmain, Text *text, const bool lib_local)
 
 void BKE_text_clear(Text *text, TextUndoBuf *utxt) /* called directly from rna */
 {
-	const bool undostate_orig = txt_get_undostate();
-	txt_set_undostate(utxt == NULL);
+	const bool undoing_orig = undoing;
+	undoing = (utxt == NULL);
 
 	txt_sel_all(text);
 	txt_delete_sel(text, utxt);
 
-	txt_set_undostate(undostate_orig);
+	undoing = undoing_orig;
 
 	txt_make_dirty(text);
 }
 
 void BKE_text_write(Text *text, TextUndoBuf *utxt, const char *str) /* called directly from rna */
 {
-	const bool undostate_orig = txt_get_undostate();
-	txt_set_undostate(utxt == NULL);
+	const bool undoing_orig = undoing;
+	undoing = (utxt == NULL);
 
 	txt_insert_buf(text, utxt, str);
 	txt_move_eof(text, 0);
 
-	txt_set_undostate(undostate_orig);
+	undoing = undoing_orig;
 
 	txt_make_dirty(text);
 }
@@ -1393,7 +1387,8 @@ char *txt_sel_to_buf(Text *text)
 
 void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
 {
-	int l = 0, u, len;
+	const bool undoing_orig = undoing;
+	int l = 0, len;
 	size_t i = 0, j;
 	TextLine *add;
 	char *buffer;
@@ -1406,41 +1401,44 @@ void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
 	buffer = BLI_strdupn(in_buffer, len);
 	len += txt_extended_ascii_as_utf8(&buffer);
 	
-	if (!undoing) txt_undo_add_blockop(text, utxt, UNDO_IBLOCK, buffer);
-
-	u = undoing;
-	undoing = 1;
+	if (!undoing) {
+		txt_undo_add_blockop(text, utxt, UNDO_IBLOCK, buffer);
+	}
+	undoing = true;
 
 	/* Read the first line (or as close as possible */
-	while (buffer[i] && buffer[i] != '\n')
+	while (buffer[i] && buffer[i] != '\n') {
 		txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &i));
+	}
 	
-	if (buffer[i] == '\n') txt_split_curline(text, utxt);
-	else { undoing = u; MEM_freeN(buffer); return; }
-	i++;
+	if (buffer[i] == '\n') {
+		txt_split_curline(text, utxt);
+		i++;
 
-	while (i < len) {
-		l = 0;
+		while (i < len) {
+			l = 0;
 
-		while (buffer[i] && buffer[i] != '\n') {
-			i++; l++;
-		}
-	
-		if (buffer[i] == '\n') {
-			add = txt_new_linen(buffer + (i - l), l);
-			BLI_insertlinkbefore(&text->lines, text->curl, add);
-			i++;
-		}
-		else {
-			for (j = i - l; j < i && j < len; )
-				txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &j));
-			break;
+			while (buffer[i] && buffer[i] != '\n') {
+				i++;
+				l++;
+			}
+
+			if (buffer[i] == '\n') {
+				add = txt_new_linen(buffer + (i - l), l);
+				BLI_insertlinkbefore(&text->lines, text->curl, add);
+				i++;
+			}
+			else {
+				for (j = i - l; j < i && j < len; ) {
+					txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &j));
+				}
+				break;
+			}
 		}
 	}
-	
-	MEM_freeN(buffer);
 
-	undoing = u;
+	MEM_freeN(buffer);
+	undoing = undoing_orig;
 }
 
 /******************/



More information about the Bf-blender-cvs mailing list