2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-02-18 13:05:18 +00:00
|
|
|
*/
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-09-04 21:02:43 +00:00
|
|
|
struct Main;
|
2002-10-12 11:37:38 +00:00
|
|
|
struct Text;
|
|
|
|
|
struct TextLine;
|
|
|
|
|
|
2022-03-11 15:09:55 +11:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* \note caller must handle `compiled` member.
|
|
|
|
|
*/
|
2015-12-14 17:12:16 +11:00
|
|
|
void BKE_text_free_lines(struct Text *text);
|
2013-03-14 05:52:30 +00:00
|
|
|
struct Text *BKE_text_add(struct Main *bmain, const char *name);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Use to a valid UTF-8 sequences.
|
|
|
|
|
* this function replaces extended ascii characters.
|
|
|
|
|
*/
|
2012-01-17 17:26:58 +00:00
|
|
|
int txt_extended_ascii_as_utf8(char **str);
|
2015-06-05 11:46:01 +10:00
|
|
|
bool BKE_text_reload(struct Text *text);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Load a text file.
|
|
|
|
|
*
|
|
|
|
|
* \param is_internal: If \a true, this text data-block only exists in memory,
|
|
|
|
|
* not as a file on disk.
|
|
|
|
|
*
|
|
|
|
|
* \note text data-blocks have no real user but have 'fake user' enabled by default
|
|
|
|
|
*/
|
2013-06-02 17:52:06 +00:00
|
|
|
struct Text *BKE_text_load_ex(struct Main *bmain,
|
2022-04-26 13:59:54 +10:00
|
|
|
const char *filepath,
|
|
|
|
|
const char *relbase,
|
2022-04-26 14:02:49 +10:00
|
|
|
bool is_internal) ATTR_NONNULL(1, 2, 3);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Load a text file.
|
|
|
|
|
*
|
|
|
|
|
* \note Text data-blocks have no user by default, only the 'real user' flag.
|
|
|
|
|
*/
|
2022-04-26 14:02:49 +10:00
|
|
|
struct Text *BKE_text_load(struct Main *bmain, const char *filepath, const char *relbase)
|
|
|
|
|
ATTR_NONNULL(1, 2, 3);
|
2022-04-07 15:43:23 +10:00
|
|
|
void BKE_text_clear(struct Text *text) ATTR_NONNULL(1);
|
|
|
|
|
void BKE_text_write(struct Text *text, const char *str, int str_len) ATTR_NONNULL(1, 2);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* \return codes:
|
2022-04-26 13:59:54 +10:00
|
|
|
* - 0 if filepath on disk is the same or Text is in memory only.
|
|
|
|
|
* - 1 if filepath has been modified on disk since last local edit.
|
|
|
|
|
* - 2 if filepath on disk has been deleted.
|
2021-12-07 17:19:15 +11:00
|
|
|
* - -1 is returned if an error occurs.
|
|
|
|
|
*/
|
2014-01-28 01:55:10 +11:00
|
|
|
int BKE_text_file_modified_check(struct Text *text);
|
|
|
|
|
void BKE_text_file_modified_ignore(struct Text *text);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2022-03-14 14:25:33 +11:00
|
|
|
char *txt_to_buf(struct Text *text, size_t *r_buf_strlen)
|
2022-03-11 15:09:55 +11:00
|
|
|
ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
void txt_clean_text(struct Text *text);
|
2022-01-07 11:38:08 +11:00
|
|
|
void txt_order_cursors(struct Text *text, bool reverse);
|
2011-11-05 11:04:28 +00:00
|
|
|
int txt_find_string(struct Text *text, const char *findstr, int wrap, int match_case);
|
2021-06-30 16:37:14 +10:00
|
|
|
bool txt_has_sel(const struct Text *text);
|
2002-10-12 11:37:38 +00:00
|
|
|
int txt_get_span(struct TextLine *from, struct TextLine *to);
|
2022-01-07 11:38:08 +11:00
|
|
|
void txt_move_up(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_down(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_left(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_right(struct Text *text, bool sel);
|
|
|
|
|
void txt_jump_left(struct Text *text, bool sel, bool use_init_step);
|
|
|
|
|
void txt_jump_right(struct Text *text, bool sel, bool use_init_step);
|
|
|
|
|
void txt_move_bof(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_eof(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_bol(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_eol(struct Text *text, bool sel);
|
|
|
|
|
void txt_move_toline(struct Text *text, unsigned int line, bool sel);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Moves to a certain byte in a line, not a certain utf8-character.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel);
|
2002-10-12 11:37:38 +00:00
|
|
|
void txt_pop_sel(struct Text *text);
|
2019-07-11 15:25:52 +10:00
|
|
|
void txt_delete_char(struct Text *text);
|
|
|
|
|
void txt_delete_word(struct Text *text);
|
|
|
|
|
void txt_delete_selected(struct Text *text);
|
2002-10-12 11:37:38 +00:00
|
|
|
void txt_sel_all(struct Text *text);
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Reverse of #txt_pop_sel
|
|
|
|
|
* Clears the selection and ensures the cursor is located
|
|
|
|
|
* at the selection (where the cursor is visually while editing).
|
|
|
|
|
*/
|
2014-08-29 14:52:23 +10:00
|
|
|
void txt_sel_clear(struct Text *text);
|
2002-10-12 11:37:38 +00:00
|
|
|
void txt_sel_line(struct Text *text);
|
2019-10-04 05:56:41 +10:00
|
|
|
void txt_sel_set(struct Text *text, int startl, int startc, int endl, int endc);
|
2022-03-14 14:25:33 +11:00
|
|
|
char *txt_sel_to_buf(struct Text *text, size_t *r_buf_strlen);
|
2022-04-07 15:43:23 +10:00
|
|
|
void txt_insert_buf(struct Text *text, const char *in_buffer, int in_buffer_len)
|
|
|
|
|
ATTR_NONNULL(1, 2);
|
2019-07-11 15:25:52 +10:00
|
|
|
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);
|
2019-08-01 20:31:57 +10:00
|
|
|
bool txt_unindent(struct Text *text);
|
2019-07-11 15:25:52 +10:00
|
|
|
void txt_comment(struct Text *text);
|
|
|
|
|
void txt_indent(struct Text *text);
|
2019-08-01 20:31:57 +10:00
|
|
|
bool txt_uncomment(struct Text *text);
|
2022-01-07 11:38:08 +11:00
|
|
|
void txt_move_lines(struct Text *text, int direction);
|
2019-07-11 15:25:52 +10:00
|
|
|
void txt_duplicate_line(struct Text *text);
|
2013-03-14 05:52:30 +00:00
|
|
|
int txt_setcurr_tab_spaces(struct Text *text, int space);
|
2021-06-30 16:37:14 +10:00
|
|
|
bool txt_cursor_is_line_start(const struct Text *text);
|
|
|
|
|
bool txt_cursor_is_line_end(const struct Text *text);
|
2008-08-04 23:01:47 +00:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
int txt_calc_tab_left(struct TextLine *tl, int ch);
|
|
|
|
|
int txt_calc_tab_right(struct TextLine *tl, int ch);
|
2016-03-11 00:04:13 +11:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Utility functions, could be moved somewhere more generic but are python/text related.
|
|
|
|
|
*/
|
2022-01-07 11:38:08 +11:00
|
|
|
int text_check_bracket(char ch);
|
|
|
|
|
bool text_check_delim(char ch);
|
|
|
|
|
bool text_check_digit(char ch);
|
|
|
|
|
bool text_check_identifier(char ch);
|
|
|
|
|
bool text_check_identifier_nodigit(char ch);
|
|
|
|
|
bool text_check_whitespace(char ch);
|
2014-02-03 18:55:59 +11:00
|
|
|
int text_find_identifier_start(const char *str, int i);
|
2009-09-22 16:23:46 +00:00
|
|
|
|
2021-12-07 17:19:15 +11:00
|
|
|
/* EVIL: defined in `bpy_interface.c`. */
|
2022-01-07 11:38:08 +11:00
|
|
|
extern int text_check_identifier_unicode(unsigned int ch);
|
|
|
|
|
extern int text_check_identifier_nodigit_unicode(unsigned int ch);
|
2013-02-19 16:13:41 +00:00
|
|
|
|
2012-05-04 16:17:09 +00:00
|
|
|
enum {
|
|
|
|
|
TXT_MOVE_LINE_UP = -1,
|
2019-01-15 23:57:49 +11:00
|
|
|
TXT_MOVE_LINE_DOWN = 1,
|
2012-05-04 16:17:09 +00:00
|
|
|
};
|
|
|
|
|
|
2019-07-11 15:25:52 +10:00
|
|
|
/* Fast non-validating buffer conversion for undo. */
|
2021-12-07 17:19:15 +11:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a buffer, the only requirement is #txt_from_buf_for_undo can decode it.
|
|
|
|
|
*/
|
2022-03-14 14:25:33 +11:00
|
|
|
char *txt_to_buf_for_undo(struct Text *text, size_t *r_buf_len)
|
2022-03-11 15:09:55 +11:00
|
|
|
ATTR_NONNULL(1, 2) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL;
|
2021-12-07 17:19:15 +11:00
|
|
|
/**
|
|
|
|
|
* Decode a buffer from #txt_to_buf_for_undo.
|
|
|
|
|
*/
|
2022-03-14 14:25:33 +11:00
|
|
|
void txt_from_buf_for_undo(struct Text *text, const char *buf, size_t buf_len) ATTR_NONNULL(1, 2);
|
2018-04-05 15:22:33 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|