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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-04-15 11:48:50 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-04-15 11:48:50 +0300
commitd0e3fbc06b9c1560c98ba294912ff03ebe71acc5 (patch)
treef834371cbcf16ef04e9c1cc8ae03d94f7e5c176b /source
parentfb3528d088709e8221496efaa57522b1406f4ca8 (diff)
Cleanup: remove undoing access, minor formatting
Access to undoing state isn't needed, some text insert code was overly compacted.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_text.h2
-rw-r--r--source/blender/blenkernel/intern/text.c88
2 files changed, 43 insertions, 47 deletions
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;
}
/******************/