Cleanup: remove unused text editor documentation functions

This commit is contained in:
Campbell Barton
2023-06-10 17:35:58 +10:00
parent a2865b701d
commit 90f123e95a
5 changed files with 2 additions and 209 deletions

View File

@@ -59,11 +59,6 @@ void texttool_suggest_select(SuggItem *sel);
SuggItem *texttool_suggest_selected(void);
int *texttool_suggest_top(void);
/* Documentation */
void texttool_docs_show(const char *docs);
char *texttool_docs_get(void);
void texttool_docs_clear(void);
#ifdef __cplusplus
}
#endif

View File

@@ -207,42 +207,3 @@ int *texttool_suggest_top(void)
{
return &suggestions.top;
}
/*************************/
/* Documentation methods */
/*************************/
void texttool_docs_show(const char *docs)
{
int len;
if (!docs) {
return;
}
len = strlen(docs);
MEM_SAFE_FREE(documentation);
/* Ensure documentation ends with a '\n' */
if (docs[len - 1] != '\n') {
documentation = MEM_mallocN(len + 2, "Documentation");
memcpy(documentation, docs, len);
documentation[len++] = '\n';
}
else {
documentation = MEM_mallocN(len + 1, "Documentation");
memcpy(documentation, docs, len);
}
documentation[len] = '\0';
}
char *texttool_docs_get(void)
{
return documentation;
}
void texttool_docs_clear(void)
{
txttl_free_docs();
}

View File

@@ -316,8 +316,6 @@ static int text_autocomplete_invoke(bContext *C, wmOperator *op, const wmEvent *
return OPERATOR_CANCELLED;
}
static int doc_scroll = 0;
static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
/* NOTE(@ideasman42): this code could be refactored or rewritten. */
@@ -332,9 +330,6 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
if (texttool_suggest_first()) {
tools |= TOOL_SUGG_LIST;
}
if (texttool_docs_get()) {
tools |= TOOL_DOCUMENT;
}
}
switch (event->type) {
@@ -356,21 +351,12 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
swallow = 1;
draw = 1;
}
if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
draw = 1;
}
retval = OPERATOR_FINISHED;
}
else {
if (tools & TOOL_SUGG_LIST) {
texttool_suggest_clear();
}
if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
}
retval = OPERATOR_CANCELLED;
}
draw = 1;
@@ -382,10 +368,6 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
if (tools & TOOL_SUGG_LIST) {
texttool_suggest_clear();
}
else if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
}
else {
draw = swallow = 0;
}
@@ -403,11 +385,6 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
swallow = 1;
draw = 1;
}
if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
draw = 1;
}
retval = OPERATOR_FINISHED;
}
break;
@@ -443,10 +420,6 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
}
}
}
if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
}
}
break;
case EVT_RIGHTARROWKEY:
@@ -480,10 +453,6 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
}
}
}
if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
}
}
break;
case EVT_PAGEDOWNKEY:
@@ -492,12 +461,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
case WHEELDOWNMOUSE:
case EVT_DOWNARROWKEY:
if (event->val == KM_PRESS) {
if (tools & TOOL_DOCUMENT) {
doc_scroll++;
swallow = 1;
draw = 1;
}
else if (tools & TOOL_SUGG_LIST) {
if (tools & TOOL_SUGG_LIST) {
SuggItem *sel = texttool_suggest_selected();
if (!sel) {
texttool_suggest_select(texttool_suggest_first());
@@ -526,14 +490,7 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
case WHEELUPMOUSE:
case EVT_UPARROWKEY:
if (event->val == KM_PRESS) {
if (tools & TOOL_DOCUMENT) {
if (doc_scroll > 0) {
doc_scroll--;
}
swallow = 1;
draw = 1;
}
else if (tools & TOOL_SUGG_LIST) {
if (tools & TOOL_SUGG_LIST) {
SuggItem *sel = texttool_suggest_selected();
while (sel && scroll--) {
if (sel != texttool_suggest_first() && sel->prev) {
@@ -560,11 +517,6 @@ static int text_autocomplete_modal(bContext *C, wmOperator *op, const wmEvent *e
texttool_suggest_clear();
draw = 1;
}
if (tools & TOOL_DOCUMENT) {
texttool_docs_clear();
doc_scroll = 0;
draw = 1;
}
#endif
}

View File

@@ -1031,120 +1031,6 @@ static void draw_textscroll(const SpaceText *st, rcti *scroll, rcti *back)
/** \name Draw Documentation
* \{ */
#if 0
static void draw_documentation(const SpaceText *st, ARegion *region)
{
TextDrawContext tdc = {0};
TextLine *tmp;
char *docs, buf[DOC_WIDTH + 1], *p;
int i, br, lines;
int boxw, boxh, l, x, y /* , top */ /* UNUSED */;
if (!st || !st->text) {
return;
}
if (!texttool_text_is_active(st->text)) {
return;
}
docs = texttool_docs_get();
if (!docs) {
return;
}
text_draw_context_init(st, &tdc);
/* Count the visible lines to the cursor */
for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) {
/* pass */
}
if (l < 0) {
return;
}
x = TXT_BODY_LEFT(st) + (st->runtime.cwidth_px * (st->text->curc - st->left));
if (texttool_suggest_first()) {
x += SUGG_LIST_WIDTH * st->runtime.cwidth_px + 50;
}
/* top = */ /* UNUSED */ y = region->winy - st->runtime.lheight_px * l - 2;
boxw = DOC_WIDTH * st->runtime.cwidth_px + 20;
boxh = (DOC_HEIGHT + 1) * TXT_LINE_HEIGHT(st);
/* Draw panel */
uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformThemeColor(TH_BACK);
immRecti(pos, x, y, x + boxw, y - boxh);
immUniformThemeColor(TH_SHADE1);
immBegin(GPU_PRIM_LINE_LOOP, 4);
immVertex2i(pos, x, y);
immVertex2i(pos, x + boxw, y);
immVertex2i(pos, x + boxw, y - boxh);
immVertex2i(pos, x, y - boxh);
immEnd();
immBegin(GPU_PRIM_LINE_LOOP, 3);
immVertex2i(pos, x + boxw - 10, y - 7);
immVertex2i(pos, x + boxw - 4, y - 7);
immVertex2i(pos, x + boxw - 7, y - 2);
immEnd();
immBegin(GPU_PRIM_LINE_LOOP, 3);
immVertex2i(pos, x + boxw - 10, y - boxh + 7);
immVertex2i(pos, x + boxw - 4, y - boxh + 7);
immVertex2i(pos, x + boxw - 7, y - boxh + 2);
immEnd();
immUnbindProgram();
UI_FontThemeColor(tdc.font_id, TH_TEXT);
i = 0;
br = DOC_WIDTH;
lines = 0; /* XXX -doc_scroll; */
for (p = docs; *p; p++) {
if (*p == '\r' && *(++p) != '\n') {
*(--p) = '\n'; /* Fix line endings */
}
if (ELEM(*p, ' ', '\t')) {
br = i;
}
else if (*p == '\n') {
buf[i] = '\0';
if (lines >= 0) {
y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, nullptr);
}
i = 0;
br = DOC_WIDTH;
lines++;
}
buf[i++] = *p;
if (i == DOC_WIDTH) { /* Reached the width, go to last break and wrap there */
buf[br] = '\0';
if (lines >= 0) {
y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, nullptr);
}
p -= i - br - 1; /* Rewind pointer to last break */
i = 0;
br = DOC_WIDTH;
lines++;
}
if (lines >= DOC_HEIGHT) {
break;
}
}
}
#endif
/** \} */
/* -------------------------------------------------------------------- */
/** \name Draw Suggestion List
* \{ */

View File

@@ -63,7 +63,6 @@ void text_update_cursor_moved(struct bContext *C);
#define DOC_HEIGHT 10
#define TOOL_SUGG_LIST 0x01
#define TOOL_DOCUMENT 0x02
int wrap_width(const struct SpaceText *st, struct ARegion *region);
/**