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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-06-24 07:51:46 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-06-24 08:00:12 +0300
commitd295261330d58708c70531b4cd6509e2bea0dd64 (patch)
tree7c3dd91aa385449be19616007eaa9422bbcbaf1f
parentbe8f2c698e4c1f5395add19032b7e0e077af9e11 (diff)
Text: add replace all operator
D8032 by @Poulpator with minor edits
-rw-r--r--release/scripts/startup/bl_ui/space_text.py5
-rw-r--r--source/blender/editors/space_text/text_ops.c55
2 files changed, 58 insertions, 2 deletions
diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py
index 553d79fb349..4f518d8e2d4 100644
--- a/release/scripts/startup/bl_ui/space_text.py
+++ b/release/scripts/startup/bl_ui/space_text.py
@@ -174,7 +174,10 @@ class TEXT_PT_find(Panel):
row = col.row(align=True)
row.prop(st, "replace_text", icon='DECORATE_OVERRIDE', text="")
row.operator("text.replace_set_selected", text="", icon='EYEDROPPER')
- col.operator("text.replace")
+
+ row = col.row(align=True)
+ row.operator("text.replace")
+ row.operator("text.replace", text = "Replace all").all = True
layout.separator()
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index e9e675ae226..e04e592b32d 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -3625,9 +3625,57 @@ void TEXT_OT_find(wmOperatorType *ot)
/** \name Replace Operator
* \{ */
+static int text_replace_all(bContext *C)
+{
+ SpaceText *st = CTX_wm_space_text(C);
+ Text *text = st->text;
+ const int flags = st->flags;
+ int found = 0;
+
+ if (!st->findstr[0]) {
+ return OPERATOR_CANCELLED;
+ }
+
+ const int orig_curl = BLI_findindex(&text->lines, text->curl);
+ const int orig_curc = text->curc;
+ bool has_sel = txt_has_sel(text);
+
+ txt_move_toline(text, 0, false);
+
+ found = txt_find_string(text, st->findstr, 0, flags & ST_MATCH_CASE);
+ if (found) {
+ ED_text_undo_push_init(C);
+
+ do {
+ txt_insert_buf(text, st->replacestr);
+ if (text->curl && text->curl->format) {
+ MEM_freeN(text->curl->format);
+ text->curl->format = NULL;
+ }
+ found = txt_find_string(text, st->findstr, 0, flags & ST_MATCH_CASE);
+ } while (found);
+
+ WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
+ text_drawcache_tag_update(CTX_wm_space_text(C), 1);
+ }
+ else {
+ /* Restore position */
+ txt_move_to(text, orig_curl, orig_curc, has_sel);
+ return OPERATOR_CANCELLED;
+ }
+
+ return OPERATOR_FINISHED;
+}
+
static int text_replace_exec(bContext *C, wmOperator *op)
{
- return text_find_and_replace(C, op, TEXT_REPLACE);
+ bool replace_all = RNA_boolean_get(op->ptr, "all");
+ if (replace_all) {
+ return text_replace_all(C);
+ }
+ else {
+ return text_find_and_replace(C, op, TEXT_REPLACE);
+ }
}
void TEXT_OT_replace(wmOperatorType *ot)
@@ -3643,6 +3691,11 @@ void TEXT_OT_replace(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ PropertyRNA *prop;
+ prop = RNA_def_boolean(ot->srna, "all", false, "Replace all", "Replace all occurrences");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/** \} */