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:
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r--source/blender/blenkernel/intern/text.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 83be64e84c9..5c050dde990 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -312,7 +312,7 @@ bool BKE_text_reload(Text *text)
}
BLI_strncpy(filepath_abs, text->name, FILE_MAX);
- BLI_path_abs(filepath_abs, BKE_main_blendfile_path_from_global());
+ BLI_path_abs(filepath_abs, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len);
if (buffer == NULL) {
@@ -352,7 +352,7 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len);
if (buffer == NULL) {
- return false;
+ return NULL;
}
ta = BKE_libblock_alloc(bmain, ID_TXT, BLI_path_basename(filepath_abs), 0);
@@ -477,7 +477,7 @@ int BKE_text_file_modified_check(Text *text)
}
BLI_strncpy(file, text->name, FILE_MAX);
- BLI_path_abs(file, BKE_main_blendfile_path_from_global());
+ BLI_path_abs(file, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
if (!BLI_exists(file)) {
return 2;
@@ -511,7 +511,7 @@ void BKE_text_file_modified_ignore(Text *text)
}
BLI_strncpy(file, text->name, FILE_MAX);
- BLI_path_abs(file, BKE_main_blendfile_path_from_global());
+ BLI_path_abs(file, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
if (!BLI_exists(file)) {
return;
@@ -1218,6 +1218,58 @@ void txt_sel_line(Text *text)
text->selc = text->sell->len;
}
+void txt_sel_set(Text *text, int startl, int startc, int endl, int endc)
+{
+ TextLine *froml, *tol;
+ int fromllen, tollen;
+
+ /* Support negative indices. */
+ if (startl < 0 || endl < 0) {
+ int end = BLI_listbase_count(&text->lines) - 1;
+ if (startl < 0) {
+ startl = end + startl + 1;
+ }
+ if (endl < 0) {
+ endl = end + endl + 1;
+ }
+ }
+ CLAMP_MIN(startl, 0);
+ CLAMP_MIN(endl, 0);
+
+ froml = BLI_findlink(&text->lines, startl);
+ if (froml == NULL) {
+ froml = text->lines.last;
+ }
+ if (startl == endl) {
+ tol = froml;
+ }
+ else {
+ tol = BLI_findlink(&text->lines, endl);
+ if (tol == NULL) {
+ tol = text->lines.last;
+ }
+ }
+
+ fromllen = BLI_strlen_utf8(froml->line);
+ tollen = BLI_strlen_utf8(tol->line);
+
+ /* Support negative indices. */
+ if (startc < 0) {
+ startc = fromllen + startc + 1;
+ }
+ if (endc < 0) {
+ endc = tollen + endc + 1;
+ }
+
+ CLAMP(startc, 0, fromllen);
+ CLAMP(endc, 0, tollen);
+
+ text->curl = froml;
+ text->curc = BLI_str_utf8_offset_from_index(froml->line, startc);
+ text->sell = tol;
+ text->selc = BLI_str_utf8_offset_from_index(tol->line, endc);
+}
+
/* -------------------------------------------------------------------- */
/** \name Buffer Conversion for Undo/Redo
*