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>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/editors/space_console
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/editors/space_console')
-rw-r--r--source/blender/editors/space_console/CMakeLists.txt36
-rw-r--r--source/blender/editors/space_console/console_draw.c272
-rw-r--r--source/blender/editors/space_console/console_intern.h10
-rw-r--r--source/blender/editors/space_console/console_ops.c1688
-rw-r--r--source/blender/editors/space_console/space_console.c361
5 files changed, 1185 insertions, 1182 deletions
diff --git a/source/blender/editors/space_console/CMakeLists.txt b/source/blender/editors/space_console/CMakeLists.txt
index d8645c3674a..5070b6fcf65 100644
--- a/source/blender/editors/space_console/CMakeLists.txt
+++ b/source/blender/editors/space_console/CMakeLists.txt
@@ -16,37 +16,37 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
- ../include
- ../../blenfont
- ../../blenkernel
- ../../blenlib
- ../../gpu
- ../../makesdna
- ../../makesrna
- ../../windowmanager
- ../../../../intern/guardedalloc
- ../../../../intern/glew-mx
+ ../include
+ ../../blenfont
+ ../../blenkernel
+ ../../blenlib
+ ../../gpu
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
+ ../../../../intern/guardedalloc
+ ../../../../intern/glew-mx
)
set(INC_SYS
- ${GLEW_INCLUDE_PATH}
+ ${GLEW_INCLUDE_PATH}
)
set(SRC
- console_draw.c
- console_ops.c
- space_console.c
+ console_draw.c
+ console_ops.c
+ space_console.c
- console_intern.h
+ console_intern.h
)
set(LIB
- bf_blenkernel
- bf_blenlib
+ bf_blenkernel
+ bf_blenlib
)
if(WITH_PYTHON)
- add_definitions(-DWITH_PYTHON)
+ add_definitions(-DWITH_PYTHON)
endif()
add_definitions(${GL_DEFINITIONS})
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index 042fb366224..4d6b05df609 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -24,7 +24,6 @@
#include <sys/stat.h>
#include <limits.h>
-
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
@@ -41,45 +40,44 @@
#include "console_intern.h"
-
#include "../space_info/textview.h"
static void console_line_color(unsigned char fg[3], int type)
{
- switch (type) {
- case CONSOLE_LINE_OUTPUT:
- UI_GetThemeColor3ubv(TH_CONSOLE_OUTPUT, fg);
- break;
- case CONSOLE_LINE_INPUT:
- UI_GetThemeColor3ubv(TH_CONSOLE_INPUT, fg);
- break;
- case CONSOLE_LINE_INFO:
- UI_GetThemeColor3ubv(TH_CONSOLE_INFO, fg);
- break;
- case CONSOLE_LINE_ERROR:
- UI_GetThemeColor3ubv(TH_CONSOLE_ERROR, fg);
- break;
- }
+ switch (type) {
+ case CONSOLE_LINE_OUTPUT:
+ UI_GetThemeColor3ubv(TH_CONSOLE_OUTPUT, fg);
+ break;
+ case CONSOLE_LINE_INPUT:
+ UI_GetThemeColor3ubv(TH_CONSOLE_INPUT, fg);
+ break;
+ case CONSOLE_LINE_INFO:
+ UI_GetThemeColor3ubv(TH_CONSOLE_INFO, fg);
+ break;
+ case CONSOLE_LINE_ERROR:
+ UI_GetThemeColor3ubv(TH_CONSOLE_ERROR, fg);
+ break;
+ }
}
void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
{
- /* fake the edit line being in the scroll buffer */
- ConsoleLine *cl = sc->history.last;
- int prompt_len = strlen(sc->prompt);
-
- cl_dummy->type = CONSOLE_LINE_INPUT;
- cl_dummy->len = prompt_len + cl->len;
- cl_dummy->len_alloc = cl_dummy->len + 1;
- cl_dummy->line = MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
- memcpy(cl_dummy->line, sc->prompt, prompt_len);
- memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1);
- BLI_addtail(&sc->scrollback, cl_dummy);
+ /* fake the edit line being in the scroll buffer */
+ ConsoleLine *cl = sc->history.last;
+ int prompt_len = strlen(sc->prompt);
+
+ cl_dummy->type = CONSOLE_LINE_INPUT;
+ cl_dummy->len = prompt_len + cl->len;
+ cl_dummy->len_alloc = cl_dummy->len + 1;
+ cl_dummy->line = MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
+ memcpy(cl_dummy->line, sc->prompt, prompt_len);
+ memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1);
+ BLI_addtail(&sc->scrollback, cl_dummy);
}
void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
{
- MEM_freeN(cl_dummy->line);
- BLI_remlink(&sc->scrollback, cl_dummy);
+ MEM_freeN(cl_dummy->line);
+ BLI_remlink(&sc->scrollback, cl_dummy);
}
#define CONSOLE_DRAW_MARGIN 4
@@ -87,165 +85,165 @@ void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dumm
/* console textview callbacks */
static int console_textview_begin(TextViewContext *tvc)
{
- SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
- tvc->lheight = sc->lheight * UI_DPI_FAC;
- tvc->sel_start = sc->sel_start;
- tvc->sel_end = sc->sel_end;
+ SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
+ tvc->lheight = sc->lheight * UI_DPI_FAC;
+ tvc->sel_start = sc->sel_start;
+ tvc->sel_end = sc->sel_end;
- /* iterator */
- tvc->iter = sc->scrollback.last;
+ /* iterator */
+ tvc->iter = sc->scrollback.last;
- return (tvc->iter != NULL);
+ return (tvc->iter != NULL);
}
static void console_textview_end(TextViewContext *tvc)
{
- SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
- (void)sc;
-
+ SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
+ (void)sc;
}
static int console_textview_step(TextViewContext *tvc)
{
- return ((tvc->iter = (void *)((Link *)tvc->iter)->prev) != NULL);
+ return ((tvc->iter = (void *)((Link *)tvc->iter)->prev) != NULL);
}
static int console_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
{
- ConsoleLine *cl = (ConsoleLine *)tvc->iter;
- *line = cl->line;
- *len = cl->len;
- // printf("'%s' %d\n", *line, cl->len);
- BLI_assert(cl->line[cl->len] == '\0' && (cl->len == 0 || cl->line[cl->len - 1] != '\0'));
- return 1;
+ ConsoleLine *cl = (ConsoleLine *)tvc->iter;
+ *line = cl->line;
+ *len = cl->len;
+ // printf("'%s' %d\n", *line, cl->len);
+ BLI_assert(cl->line[cl->len] == '\0' && (cl->len == 0 || cl->line[cl->len - 1] != '\0'));
+ return 1;
}
-static void console_cursor_wrap_offset(const char *str, int width, int *row, int *column, const char *end)
+static void console_cursor_wrap_offset(
+ const char *str, int width, int *row, int *column, const char *end)
{
- int col;
+ int col;
- for (; *str; str += BLI_str_utf8_size_safe(str)) {
- col = BLI_str_utf8_char_width_safe(str);
+ for (; *str; str += BLI_str_utf8_size_safe(str)) {
+ col = BLI_str_utf8_char_width_safe(str);
- if (*column + col > width) {
- (*row)++;
- *column = 0;
- }
+ if (*column + col > width) {
+ (*row)++;
+ *column = 0;
+ }
- if (end && str >= end) {
- break;
- }
+ if (end && str >= end) {
+ break;
+ }
- *column += col;
- }
- return;
+ *column += col;
+ }
+ return;
}
-static int console_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char UNUSED(bg[3]))
+static int console_textview_line_color(struct TextViewContext *tvc,
+ unsigned char fg[3],
+ unsigned char UNUSED(bg[3]))
{
- ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter;
-
- /* annoying hack, to draw the prompt */
- if (tvc->iter_index == 0) {
- const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
- const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
- int offl = 0, offc = 0;
- int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
- int pen[2];
- GPUVertFormat *format = immVertexFormat();
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- xy[1] += tvc->lheight / 6;
-
- console_cursor_wrap_offset(sc->prompt, tvc->console_width, &offl, &offc, NULL);
- console_cursor_wrap_offset(cl->line, tvc->console_width, &offl, &offc, cl->line + cl->cursor);
- pen[0] = tvc->cwidth * offc;
- pen[1] = -2 - tvc->lheight * offl;
-
- console_cursor_wrap_offset(cl->line + cl->cursor, tvc->console_width, &offl, &offc, NULL);
- pen[1] += tvc->lheight * offl;
-
- /* cursor */
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- immUniformThemeColor(TH_CONSOLE_CURSOR);
-
- immRectf(pos,
- (xy[0] + pen[0]) - 1,
- (xy[1] + pen[1]),
- (xy[0] + pen[0]) + 1,
- (xy[1] + pen[1] + tvc->lheight)
- );
-
- immUnbindProgram();
- }
-
- console_line_color(fg, cl_iter->type);
-
- return TVC_LINE_FG;
+ ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter;
+
+ /* annoying hack, to draw the prompt */
+ if (tvc->iter_index == 0) {
+ const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
+ const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
+ int offl = 0, offc = 0;
+ int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
+ int pen[2];
+ GPUVertFormat *format = immVertexFormat();
+ uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ xy[1] += tvc->lheight / 6;
+
+ console_cursor_wrap_offset(sc->prompt, tvc->console_width, &offl, &offc, NULL);
+ console_cursor_wrap_offset(cl->line, tvc->console_width, &offl, &offc, cl->line + cl->cursor);
+ pen[0] = tvc->cwidth * offc;
+ pen[1] = -2 - tvc->lheight * offl;
+
+ console_cursor_wrap_offset(cl->line + cl->cursor, tvc->console_width, &offl, &offc, NULL);
+ pen[1] += tvc->lheight * offl;
+
+ /* cursor */
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_CONSOLE_CURSOR);
+
+ immRectf(pos,
+ (xy[0] + pen[0]) - 1,
+ (xy[1] + pen[1]),
+ (xy[0] + pen[0]) + 1,
+ (xy[1] + pen[1] + tvc->lheight));
+
+ immUnbindProgram();
+ }
+
+ console_line_color(fg, cl_iter->type);
+
+ return TVC_LINE_FG;
}
static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned char bg_sel[4])
{
- UI_GetThemeColor4ubv(TH_CONSOLE_SELECT, bg_sel);
+ UI_GetThemeColor4ubv(TH_CONSOLE_SELECT, bg_sel);
}
-static int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, int draw,
- int mval[2], void **mouse_pick, int *pos_pick)
+static int console_textview_main__internal(
+ struct SpaceConsole *sc, ARegion *ar, int draw, int mval[2], void **mouse_pick, int *pos_pick)
{
- ConsoleLine cl_dummy = {NULL};
- int ret = 0;
+ ConsoleLine cl_dummy = {NULL};
+ int ret = 0;
- View2D *v2d = &ar->v2d;
+ View2D *v2d = &ar->v2d;
- TextViewContext tvc = {0};
+ TextViewContext tvc = {0};
- tvc.begin = console_textview_begin;
- tvc.end = console_textview_end;
+ tvc.begin = console_textview_begin;
+ tvc.end = console_textview_end;
- tvc.step = console_textview_step;
- tvc.line_get = console_textview_line_get;
- tvc.line_color = console_textview_line_color;
- tvc.const_colors = console_textview_const_colors;
+ tvc.step = console_textview_step;
+ tvc.line_get = console_textview_line_get;
+ tvc.line_color = console_textview_line_color;
+ tvc.const_colors = console_textview_const_colors;
- tvc.arg1 = sc;
- tvc.arg2 = NULL;
+ tvc.arg1 = sc;
+ tvc.arg2 = NULL;
- /* view */
- tvc.sel_start = sc->sel_start;
- tvc.sel_end = sc->sel_end;
- tvc.lheight = sc->lheight * UI_DPI_FAC;
- tvc.ymin = v2d->cur.ymin;
- tvc.ymax = v2d->cur.ymax;
- tvc.winx = ar->winx - V2D_SCROLL_WIDTH;
+ /* view */
+ tvc.sel_start = sc->sel_start;
+ tvc.sel_end = sc->sel_end;
+ tvc.lheight = sc->lheight * UI_DPI_FAC;
+ tvc.ymin = v2d->cur.ymin;
+ tvc.ymax = v2d->cur.ymax;
+ tvc.winx = ar->winx - V2D_SCROLL_WIDTH;
- console_scrollback_prompt_begin(sc, &cl_dummy);
- ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
- console_scrollback_prompt_end(sc, &cl_dummy);
+ console_scrollback_prompt_begin(sc, &cl_dummy);
+ ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
+ console_scrollback_prompt_end(sc, &cl_dummy);
- return ret;
+ return ret;
}
-
void console_textview_main(struct SpaceConsole *sc, ARegion *ar)
{
- int mval[2] = {INT_MAX, INT_MAX};
- console_textview_main__internal(sc, ar, 1, mval, NULL, NULL);
+ int mval[2] = {INT_MAX, INT_MAX};
+ console_textview_main__internal(sc, ar, 1, mval, NULL, NULL);
}
int console_textview_height(struct SpaceConsole *sc, ARegion *ar)
{
- int mval[2] = {INT_MAX, INT_MAX};
- return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL);
+ int mval[2] = {INT_MAX, INT_MAX};
+ return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL);
}
int console_char_pick(struct SpaceConsole *sc, ARegion *ar, const int mval[2])
{
- int pos_pick = 0;
- void *mouse_pick = NULL;
- int mval_clamp[2];
+ int pos_pick = 0;
+ void *mouse_pick = NULL;
+ int mval_clamp[2];
- mval_clamp[0] = CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx - CONSOLE_DRAW_MARGIN);
- mval_clamp[1] = CLAMPIS(mval[1], CONSOLE_DRAW_MARGIN, ar->winy - CONSOLE_DRAW_MARGIN);
+ mval_clamp[0] = CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx - CONSOLE_DRAW_MARGIN);
+ mval_clamp[1] = CLAMPIS(mval[1], CONSOLE_DRAW_MARGIN, ar->winy - CONSOLE_DRAW_MARGIN);
- console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick);
- return pos_pick;
+ console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick);
+ return pos_pick;
}
diff --git a/source/blender/editors/space_console/console_intern.h b/source/blender/editors/space_console/console_intern.h
index 1e4a90ca71a..30f7894ea33 100644
--- a/source/blender/editors/space_console/console_intern.h
+++ b/source/blender/editors/space_console/console_intern.h
@@ -65,6 +65,14 @@ void CONSOLE_OT_select_set(struct wmOperatorType *ot);
void CONSOLE_OT_select_word(struct wmOperatorType *ot);
enum { LINE_BEGIN, LINE_END, PREV_CHAR, NEXT_CHAR, PREV_WORD, NEXT_WORD };
-enum { DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_NEXT_WORD, DEL_PREV_WORD, DEL_SELECTION, DEL_NEXT_SEL, DEL_PREV_SEL };
+enum {
+ DEL_NEXT_CHAR,
+ DEL_PREV_CHAR,
+ DEL_NEXT_WORD,
+ DEL_PREV_WORD,
+ DEL_SELECTION,
+ DEL_NEXT_SEL,
+ DEL_PREV_SEL
+};
#endif /* __CONSOLE_INTERN_H__ */
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index d4489337847..a17c1b675e6 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -18,7 +18,6 @@
* \ingroup spconsole
*/
-
#include <stdlib.h>
#include <string.h>
#include <ctype.h> /* ispunct */
@@ -52,225 +51,224 @@
/* so when we type - the view scrolls to the bottom */
static void console_scroll_bottom(ARegion *ar)
{
- View2D *v2d = &ar->v2d;
- v2d->cur.ymin = 0.0;
- v2d->cur.ymax = (float)v2d->winy;
+ View2D *v2d = &ar->v2d;
+ v2d->cur.ymin = 0.0;
+ v2d->cur.ymax = (float)v2d->winy;
}
void console_textview_update_rect(SpaceConsole *sc, ARegion *ar)
{
- View2D *v2d = &ar->v2d;
+ View2D *v2d = &ar->v2d;
- UI_view2d_totRect_set(v2d, ar->winx - 1, console_textview_height(sc, ar));
+ UI_view2d_totRect_set(v2d, ar->winx - 1, console_textview_height(sc, ar));
}
static void console_select_offset(SpaceConsole *sc, const int offset)
{
- sc->sel_start += offset;
- sc->sel_end += offset;
+ sc->sel_start += offset;
+ sc->sel_end += offset;
}
void console_history_free(SpaceConsole *sc, ConsoleLine *cl)
{
- BLI_remlink(&sc->history, cl);
- MEM_freeN(cl->line);
- MEM_freeN(cl);
+ BLI_remlink(&sc->history, cl);
+ MEM_freeN(cl->line);
+ MEM_freeN(cl);
}
void console_scrollback_free(SpaceConsole *sc, ConsoleLine *cl)
{
- BLI_remlink(&sc->scrollback, cl);
- MEM_freeN(cl->line);
- MEM_freeN(cl);
+ BLI_remlink(&sc->scrollback, cl);
+ MEM_freeN(cl->line);
+ MEM_freeN(cl);
}
static void console_scrollback_limit(SpaceConsole *sc)
{
- int tot;
+ int tot;
- if (U.scrollback < 32) {
- U.scrollback = 256; // XXX - save in user defaults
- }
+ if (U.scrollback < 32) {
+ U.scrollback = 256; // XXX - save in user defaults
+ }
- for (tot = BLI_listbase_count(&sc->scrollback); tot > U.scrollback; tot--) {
- console_scrollback_free(sc, sc->scrollback.first);
- }
+ for (tot = BLI_listbase_count(&sc->scrollback); tot > U.scrollback; tot--) {
+ console_scrollback_free(sc, sc->scrollback.first);
+ }
}
static ConsoleLine *console_history_find(SpaceConsole *sc, const char *str, ConsoleLine *cl_ignore)
{
- ConsoleLine *cl;
+ ConsoleLine *cl;
- for (cl = sc->history.last; cl; cl = cl->prev) {
- if (cl == cl_ignore) {
- continue;
- }
+ for (cl = sc->history.last; cl; cl = cl->prev) {
+ if (cl == cl_ignore) {
+ continue;
+ }
- if (STREQ(str, cl->line)) {
- return cl;
- }
- }
+ if (STREQ(str, cl->line)) {
+ return cl;
+ }
+ }
- return NULL;
+ return NULL;
}
/* return 0 if no change made, clamps the range */
static bool console_line_cursor_set(ConsoleLine *cl, int cursor)
{
- int cursor_new;
-
- if (cursor < 0) {
- cursor_new = 0;
- }
- else if (cursor > cl->len) {
- cursor_new = cl->len;
- }
- else {
- cursor_new = cursor;
- }
-
- if (cursor_new == cl->cursor) {
- return false;
- }
-
- cl->cursor = cursor_new;
- return true;
+ int cursor_new;
+
+ if (cursor < 0) {
+ cursor_new = 0;
+ }
+ else if (cursor > cl->len) {
+ cursor_new = cl->len;
+ }
+ else {
+ cursor_new = cursor;
+ }
+
+ if (cursor_new == cl->cursor) {
+ return false;
+ }
+
+ cl->cursor = cursor_new;
+ return true;
}
-#if 0 // XXX unused
+#if 0 // XXX unused
static void console_lb_debug__internal(ListBase *lb)
{
- ConsoleLine *cl;
+ ConsoleLine *cl;
- printf("%d: ", BLI_listbase_count(lb));
- for (cl = lb->first; cl; cl = cl->next)
- printf("<%s> ", cl->line);
- printf("\n");
+ printf("%d: ", BLI_listbase_count(lb));
+ for (cl = lb->first; cl; cl = cl->next)
+ printf("<%s> ", cl->line);
+ printf("\n");
}
static void console_history_debug(const bContext *C)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
+ SpaceConsole *sc = CTX_wm_space_console(C);
- console_lb_debug__internal(&sc->history);
+ console_lb_debug__internal(&sc->history);
}
#endif
static ConsoleLine *console_lb_add__internal(ListBase *lb, ConsoleLine *from)
{
- ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
-
- if (from) {
- BLI_assert(strlen(from->line) == from->len);
- ci->line = BLI_strdupn(from->line, from->len);
- ci->len = ci->len_alloc = from->len;
- ci->cursor = from->cursor;
- ci->type = from->type;
- }
- else {
- ci->line = MEM_callocN(64, "console-in-line");
- ci->len_alloc = 64;
- ci->len = 0;
- }
-
- BLI_addtail(lb, ci);
- return ci;
+ ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
+
+ if (from) {
+ BLI_assert(strlen(from->line) == from->len);
+ ci->line = BLI_strdupn(from->line, from->len);
+ ci->len = ci->len_alloc = from->len;
+ ci->cursor = from->cursor;
+ ci->type = from->type;
+ }
+ else {
+ ci->line = MEM_callocN(64, "console-in-line");
+ ci->len_alloc = 64;
+ ci->len = 0;
+ }
+
+ BLI_addtail(lb, ci);
+ return ci;
}
static ConsoleLine *console_history_add(SpaceConsole *sc, ConsoleLine *from)
{
- return console_lb_add__internal(&sc->history, from);
+ return console_lb_add__internal(&sc->history, from);
}
#if 0 /* may use later ? */
static ConsoleLine *console_scrollback_add(const bContext *C, ConsoleLine *from)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
+ SpaceConsole *sc = CTX_wm_space_console(C);
- return console_lb_add__internal(&sc->scrollback, from);
+ return console_lb_add__internal(&sc->scrollback, from);
}
#endif
static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, bool own)
{
- ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
- if (own) {
- ci->line = str;
- }
- else {
- ci->line = BLI_strdup(str);
- }
-
- ci->len = ci->len_alloc = strlen(str);
-
- BLI_addtail(lb, ci);
- return ci;
+ ConsoleLine *ci = MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add");
+ if (own) {
+ ci->line = str;
+ }
+ else {
+ ci->line = BLI_strdup(str);
+ }
+
+ ci->len = ci->len_alloc = strlen(str);
+
+ BLI_addtail(lb, ci);
+ return ci;
}
ConsoleLine *console_history_add_str(SpaceConsole *sc, char *str, bool own)
{
- return console_lb_add_str__internal(&sc->history, str, own);
+ return console_lb_add_str__internal(&sc->history, str, own);
}
ConsoleLine *console_scrollback_add_str(SpaceConsole *sc, char *str, bool own)
{
- ConsoleLine *ci = console_lb_add_str__internal(&sc->scrollback, str, own);
- console_select_offset(sc, ci->len + 1);
- return ci;
+ ConsoleLine *ci = console_lb_add_str__internal(&sc->scrollback, str, own);
+ console_select_offset(sc, ci->len + 1);
+ return ci;
}
ConsoleLine *console_history_verify(const bContext *C)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ConsoleLine *ci = sc->history.last;
- if (ci == NULL) {
- ci = console_history_add(sc, NULL);
- }
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ConsoleLine *ci = sc->history.last;
+ if (ci == NULL) {
+ ci = console_history_add(sc, NULL);
+ }
- return ci;
+ return ci;
}
-
static void console_line_verify_length(ConsoleLine *ci, int len)
{
- /* resize the buffer if needed */
- if (len >= ci->len_alloc) {
- /* new length */
+ /* resize the buffer if needed */
+ if (len >= ci->len_alloc) {
+ /* new length */
#ifndef NDEBUG
- int new_len = len + 1;
+ int new_len = len + 1;
#else
- int new_len = (len + 1) * 2;
+ int new_len = (len + 1) * 2;
#endif
- char *new_line = MEM_callocN(new_len, "console line");
- memcpy(new_line, ci->line, ci->len);
- MEM_freeN(ci->line);
+ char *new_line = MEM_callocN(new_len, "console line");
+ memcpy(new_line, ci->line, ci->len);
+ MEM_freeN(ci->line);
- ci->line = new_line;
- ci->len_alloc = new_len;
- }
+ ci->line = new_line;
+ ci->len_alloc = new_len;
+ }
}
static int console_line_insert(ConsoleLine *ci, char *str)
{
- int len = strlen(str);
+ int len = strlen(str);
- if (len > 0 && str[len - 1] == '\n') { /* stop new lines being pasted at the end of lines */
- str[len - 1] = '\0';
- len--;
- }
+ if (len > 0 && str[len - 1] == '\n') { /* stop new lines being pasted at the end of lines */
+ str[len - 1] = '\0';
+ len--;
+ }
- if (len == 0) {
- return 0;
- }
+ if (len == 0) {
+ return 0;
+ }
- console_line_verify_length(ci, len + ci->len);
+ console_line_verify_length(ci, len + ci->len);
- memmove(ci->line + ci->cursor + len, ci->line + ci->cursor, (ci->len - ci->cursor) + 1);
- memcpy(ci->line + ci->cursor, str, len);
+ memmove(ci->line + ci->cursor + len, ci->line + ci->cursor, (ci->len - ci->cursor) + 1);
+ memcpy(ci->line + ci->cursor, str, len);
- ci->len += len;
- ci->cursor += len;
+ ci->len += len;
+ ci->cursor += len;
- return len;
+ return len;
}
/**
@@ -279,975 +277,977 @@ static int console_line_insert(ConsoleLine *ci, char *str)
* \note be sure to call console_scrollback_prompt_begin first
*/
static bool console_line_column_from_index(
- SpaceConsole *sc, const int pos,
- ConsoleLine **r_cl, int *r_cl_offset, int *r_col)
+ SpaceConsole *sc, const int pos, ConsoleLine **r_cl, int *r_cl_offset, int *r_col)
{
- ConsoleLine *cl;
- int offset = 0;
-
- for (cl = sc->scrollback.last; cl; cl = cl->prev) {
- offset += cl->len + 1;
- if (offset >= pos) {
- break;
- }
- }
-
- if (cl) {
- offset -= 1;
- *r_cl = cl;
- *r_cl_offset = offset;
- *r_col = offset - pos;
- return true;
- }
- else {
- *r_cl = NULL;
- *r_cl_offset = -1;
- *r_col = -1;
- return false;
- }
+ ConsoleLine *cl;
+ int offset = 0;
+
+ for (cl = sc->scrollback.last; cl; cl = cl->prev) {
+ offset += cl->len + 1;
+ if (offset >= pos) {
+ break;
+ }
+ }
+
+ if (cl) {
+ offset -= 1;
+ *r_cl = cl;
+ *r_cl_offset = offset;
+ *r_col = offset - pos;
+ return true;
+ }
+ else {
+ *r_cl = NULL;
+ *r_cl_offset = -1;
+ *r_col = -1;
+ return false;
+ }
}
/* static funcs for text editing */
/* similar to the text editor, with some not used. keep compatible */
static const EnumPropertyItem console_move_type_items[] = {
- {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
- {LINE_END, "LINE_END", 0, "Line End", ""},
- {PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
- {NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
- {PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
- {NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
- {0, NULL, 0, NULL, NULL},
+ {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
+ {LINE_END, "LINE_END", 0, "Line End", ""},
+ {PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
+ {NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
+ {PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
+ {NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
+ {0, NULL, 0, NULL, NULL},
};
static int console_move_exec(bContext *C, wmOperator *op)
{
- ConsoleLine *ci = console_history_verify(C);
-
- int type = RNA_enum_get(op->ptr, "type");
- bool done = false;
- int pos;
-
- switch (type) {
- case LINE_BEGIN:
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_PREV,
- STRCUR_JUMP_ALL, true);
- done = console_line_cursor_set(ci, pos);
- break;
- case LINE_END:
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_NEXT,
- STRCUR_JUMP_ALL, true);
- done = console_line_cursor_set(ci, pos);
- break;
- case PREV_CHAR:
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_PREV,
- STRCUR_JUMP_NONE, true);
- done = console_line_cursor_set(ci, pos);
- break;
- case NEXT_CHAR:
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_NEXT,
- STRCUR_JUMP_NONE, true);
- done = console_line_cursor_set(ci, pos);
- break;
-
- /* - if the character is a delimiter then skip delimiters (including white space)
- * - when jump over the word */
- case PREV_WORD:
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_PREV,
- STRCUR_JUMP_DELIM, true);
- done = console_line_cursor_set(ci, pos);
- break;
- case NEXT_WORD:
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_NEXT,
- STRCUR_JUMP_DELIM, true);
- done = console_line_cursor_set(ci, pos);
- break;
- }
-
- if (done) {
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
-
- ED_area_tag_redraw(sa);
- console_scroll_bottom(ar);
- }
-
-
- return OPERATOR_FINISHED;
+ ConsoleLine *ci = console_history_verify(C);
+
+ int type = RNA_enum_get(op->ptr, "type");
+ bool done = false;
+ int pos;
+
+ switch (type) {
+ case LINE_BEGIN:
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_ALL, true);
+ done = console_line_cursor_set(ci, pos);
+ break;
+ case LINE_END:
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_ALL, true);
+ done = console_line_cursor_set(ci, pos);
+ break;
+ case PREV_CHAR:
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_NONE, true);
+ done = console_line_cursor_set(ci, pos);
+ break;
+ case NEXT_CHAR:
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_NONE, true);
+ done = console_line_cursor_set(ci, pos);
+ break;
+
+ /* - if the character is a delimiter then skip delimiters (including white space)
+ * - when jump over the word */
+ case PREV_WORD:
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true);
+ done = console_line_cursor_set(ci, pos);
+ break;
+ case NEXT_WORD:
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true);
+ done = console_line_cursor_set(ci, pos);
+ break;
+ }
+
+ if (done) {
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ ED_area_tag_redraw(sa);
+ console_scroll_bottom(ar);
+ }
+
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_move(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Move Cursor";
- ot->description = "Move cursor position";
- ot->idname = "CONSOLE_OT_move";
-
- /* api callbacks */
- ot->exec = console_move_exec;
- ot->poll = ED_operator_console_active;
-
- /* properties */
- RNA_def_enum(ot->srna, "type", console_move_type_items, LINE_BEGIN, "Type", "Where to move cursor to");
+ /* identifiers */
+ ot->name = "Move Cursor";
+ ot->description = "Move cursor position";
+ ot->idname = "CONSOLE_OT_move";
+
+ /* api callbacks */
+ ot->exec = console_move_exec;
+ ot->poll = ED_operator_console_active;
+
+ /* properties */
+ RNA_def_enum(
+ ot->srna, "type", console_move_type_items, LINE_BEGIN, "Type", "Where to move cursor to");
}
#define TAB_LENGTH 4
static int console_insert_exec(bContext *C, wmOperator *op)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci = console_history_verify(C);
- char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
- int len;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci = console_history_verify(C);
+ char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ int len;
- if (str[0] == '\t' && str[1] == '\0') {
- len = TAB_LENGTH;
- MEM_freeN(str);
- str = MEM_mallocN(len + 1, "insert_exec");
- memset(str, ' ', len);
- str[len] = '\0';
- }
+ if (str[0] == '\t' && str[1] == '\0') {
+ len = TAB_LENGTH;
+ MEM_freeN(str);
+ str = MEM_mallocN(len + 1, "insert_exec");
+ memset(str, ' ', len);
+ str[len] = '\0';
+ }
- len = console_line_insert(ci, str);
+ len = console_line_insert(ci, str);
- MEM_freeN(str);
+ MEM_freeN(str);
- if (len == 0) {
- return OPERATOR_CANCELLED;
- }
- else {
- console_select_offset(sc, len);
- }
+ if (len == 0) {
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ console_select_offset(sc, len);
+ }
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
- console_scroll_bottom(ar);
+ console_scroll_bottom(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
static int console_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- // if (!RNA_struct_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */
- if (!RNA_string_length(op->ptr, "text")) {
- /* if alt/ctrl/super are pressed pass through except for utf8 character event
- * (when input method are used for utf8 inputs, the user may assign key event
- * including alt/ctrl/super like ctrl+m to commit utf8 string. in such case,
- * the modifiers in the utf8 character event make no sense.) */
- if ((event->ctrl || event->oskey) && !event->utf8_buf[0]) {
- return OPERATOR_PASS_THROUGH;
- }
- else {
- char str[BLI_UTF8_MAX + 1];
- size_t len;
-
- if (event->utf8_buf[0]) {
- len = BLI_str_utf8_size_safe(event->utf8_buf);
- memcpy(str, event->utf8_buf, len);
- }
- else {
- /* in theory, ghost can set value to extended ascii here */
- len = BLI_str_utf8_from_unicode(event->ascii, str);
- }
- str[len] = '\0';
- RNA_string_set(op->ptr, "text", str);
- }
- }
- return console_insert_exec(C, op);
+ // if (!RNA_struct_property_is_set(op->ptr, "text")) { /* always set from keymap XXX */
+ if (!RNA_string_length(op->ptr, "text")) {
+ /* if alt/ctrl/super are pressed pass through except for utf8 character event
+ * (when input method are used for utf8 inputs, the user may assign key event
+ * including alt/ctrl/super like ctrl+m to commit utf8 string. in such case,
+ * the modifiers in the utf8 character event make no sense.) */
+ if ((event->ctrl || event->oskey) && !event->utf8_buf[0]) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ else {
+ char str[BLI_UTF8_MAX + 1];
+ size_t len;
+
+ if (event->utf8_buf[0]) {
+ len = BLI_str_utf8_size_safe(event->utf8_buf);
+ memcpy(str, event->utf8_buf, len);
+ }
+ else {
+ /* in theory, ghost can set value to extended ascii here */
+ len = BLI_str_utf8_from_unicode(event->ascii, str);
+ }
+ str[len] = '\0';
+ RNA_string_set(op->ptr, "text", str);
+ }
+ }
+ return console_insert_exec(C, op);
}
void CONSOLE_OT_insert(wmOperatorType *ot)
{
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "Insert";
- ot->description = "Insert text at cursor position";
- ot->idname = "CONSOLE_OT_insert";
-
- /* api callbacks */
- ot->exec = console_insert_exec;
- ot->invoke = console_insert_invoke;
- ot->poll = ED_operator_console_active;
-
- /* properties */
- prop = RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Insert";
+ ot->description = "Insert text at cursor position";
+ ot->idname = "CONSOLE_OT_insert";
+
+ /* api callbacks */
+ ot->exec = console_insert_exec;
+ ot->invoke = console_insert_invoke;
+ ot->poll = ED_operator_console_active;
+
+ /* properties */
+ prop = RNA_def_string(
+ ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
static int console_indent_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci = console_history_verify(C);
- int spaces;
- int len;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci = console_history_verify(C);
+ int spaces;
+ int len;
- for (spaces = 0; spaces < ci->len; spaces++) {
- if (ci->line[spaces] != ' ') {
- break;
- }
- }
+ for (spaces = 0; spaces < ci->len; spaces++) {
+ if (ci->line[spaces] != ' ') {
+ break;
+ }
+ }
- len = TAB_LENGTH - spaces % TAB_LENGTH;
+ len = TAB_LENGTH - spaces % TAB_LENGTH;
- console_line_verify_length(ci, ci->len + len);
+ console_line_verify_length(ci, ci->len + len);
- memmove(ci->line + len, ci->line, ci->len + 1);
- memset(ci->line, ' ', len);
- ci->len += len;
- BLI_assert(ci->len >= 0);
- console_line_cursor_set(ci, ci->cursor + len);
- console_select_offset(sc, len);
+ memmove(ci->line + len, ci->line, ci->len + 1);
+ memset(ci->line, ' ', len);
+ ci->len += len;
+ BLI_assert(ci->len >= 0);
+ console_line_cursor_set(ci, ci->cursor + len);
+ console_select_offset(sc, len);
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
- console_scroll_bottom(ar);
+ console_scroll_bottom(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_indent(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Indent";
- ot->description = "Add 4 spaces at line beginning";
- ot->idname = "CONSOLE_OT_indent";
-
- /* api callbacks */
- ot->exec = console_indent_exec;
- ot->poll = ED_operator_console_active;
+ /* identifiers */
+ ot->name = "Indent";
+ ot->description = "Add 4 spaces at line beginning";
+ ot->idname = "CONSOLE_OT_indent";
+
+ /* api callbacks */
+ ot->exec = console_indent_exec;
+ ot->poll = ED_operator_console_active;
}
static int console_unindent_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci = console_history_verify(C);
- int spaces;
- int len;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci = console_history_verify(C);
+ int spaces;
+ int len;
- for (spaces = 0; spaces < ci->len; spaces++) {
- if (ci->line[spaces] != ' ') {
- break;
- }
- }
+ for (spaces = 0; spaces < ci->len; spaces++) {
+ if (ci->line[spaces] != ' ') {
+ break;
+ }
+ }
- if (spaces == 0) {
- return OPERATOR_CANCELLED;
- }
+ if (spaces == 0) {
+ return OPERATOR_CANCELLED;
+ }
- len = spaces % TAB_LENGTH;
- if (len == 0) {
- len = TAB_LENGTH;
- }
+ len = spaces % TAB_LENGTH;
+ if (len == 0) {
+ len = TAB_LENGTH;
+ }
- console_line_verify_length(ci, ci->len - len);
+ console_line_verify_length(ci, ci->len - len);
- memmove(ci->line, ci->line + len, (ci->len - len) + 1);
- ci->len -= len;
- BLI_assert(ci->len >= 0);
+ memmove(ci->line, ci->line + len, (ci->len - len) + 1);
+ ci->len -= len;
+ BLI_assert(ci->len >= 0);
- console_line_cursor_set(ci, ci->cursor - len);
- console_select_offset(sc, -len);
+ console_line_cursor_set(ci, ci->cursor - len);
+ console_select_offset(sc, -len);
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
- console_scroll_bottom(ar);
+ console_scroll_bottom(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_unindent(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Unindent";
- ot->description = "Delete 4 spaces from line beginning";
- ot->idname = "CONSOLE_OT_unindent";
-
- /* api callbacks */
- ot->exec = console_unindent_exec;
- ot->poll = ED_operator_console_active;
+ /* identifiers */
+ ot->name = "Unindent";
+ ot->description = "Delete 4 spaces from line beginning";
+ ot->idname = "CONSOLE_OT_unindent";
+
+ /* api callbacks */
+ ot->exec = console_unindent_exec;
+ ot->poll = ED_operator_console_active;
}
static const EnumPropertyItem console_delete_type_items[] = {
- {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
- {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
- {DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
- {DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
- {0, NULL, 0, NULL, NULL},
+ {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
+ {DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
+ {DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
+ {DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
+ {0, NULL, 0, NULL, NULL},
};
static int console_delete_exec(bContext *C, wmOperator *op)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci = console_history_verify(C);
- int pos;
- int stride;
-
- const short type = RNA_enum_get(op->ptr, "type");
- bool done = false;
-
- if (ci->len == 0) {
- return OPERATOR_CANCELLED;
- }
-
- switch (type) {
- case DEL_NEXT_CHAR:
- case DEL_NEXT_WORD:
- if (ci->cursor < ci->len) {
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_NEXT,
- (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
- stride = pos - ci->cursor;
- if (stride) {
- memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - (ci->cursor + stride)) + 1);
- ci->len -= stride;
- BLI_assert(ci->len >= 0);
- done = true;
- }
- }
- break;
- case DEL_PREV_CHAR:
- case DEL_PREV_WORD:
- if (ci->cursor > 0) {
- pos = ci->cursor;
- BLI_str_cursor_step_utf8(ci->line, ci->len,
- &pos, STRCUR_DIR_PREV,
- (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
- stride = ci->cursor - pos;
- if (stride) {
- ci->cursor -= stride; /* same as above */
- memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - (ci->cursor + stride)) + 1);
- ci->len -= stride;
- BLI_assert(ci->len >= 0);
- done = true;
- }
- }
- break;
- }
-
- if (!done) {
- return OPERATOR_CANCELLED;
- }
- else {
- console_select_offset(sc, -stride);
- }
-
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
-
- console_scroll_bottom(ar);
-
- return OPERATOR_FINISHED;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci = console_history_verify(C);
+ int pos;
+ int stride;
+
+ const short type = RNA_enum_get(op->ptr, "type");
+ bool done = false;
+
+ if (ci->len == 0) {
+ return OPERATOR_CANCELLED;
+ }
+
+ switch (type) {
+ case DEL_NEXT_CHAR:
+ case DEL_NEXT_WORD:
+ if (ci->cursor < ci->len) {
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line,
+ ci->len,
+ &pos,
+ STRCUR_DIR_NEXT,
+ (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM,
+ true);
+ stride = pos - ci->cursor;
+ if (stride) {
+ memmove(ci->line + ci->cursor,
+ ci->line + ci->cursor + stride,
+ (ci->len - (ci->cursor + stride)) + 1);
+ ci->len -= stride;
+ BLI_assert(ci->len >= 0);
+ done = true;
+ }
+ }
+ break;
+ case DEL_PREV_CHAR:
+ case DEL_PREV_WORD:
+ if (ci->cursor > 0) {
+ pos = ci->cursor;
+ BLI_str_cursor_step_utf8(ci->line,
+ ci->len,
+ &pos,
+ STRCUR_DIR_PREV,
+ (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM,
+ true);
+ stride = ci->cursor - pos;
+ if (stride) {
+ ci->cursor -= stride; /* same as above */
+ memmove(ci->line + ci->cursor,
+ ci->line + ci->cursor + stride,
+ (ci->len - (ci->cursor + stride)) + 1);
+ ci->len -= stride;
+ BLI_assert(ci->len >= 0);
+ done = true;
+ }
+ }
+ break;
+ }
+
+ if (!done) {
+ return OPERATOR_CANCELLED;
+ }
+ else {
+ console_select_offset(sc, -stride);
+ }
+
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
+
+ console_scroll_bottom(ar);
+
+ return OPERATOR_FINISHED;
}
-
void CONSOLE_OT_delete(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Delete";
- ot->description = "Delete text by cursor position";
- ot->idname = "CONSOLE_OT_delete";
-
- /* api callbacks */
- ot->exec = console_delete_exec;
- ot->poll = ED_operator_console_active;
-
- /* properties */
- RNA_def_enum(ot->srna, "type", console_delete_type_items, DEL_NEXT_CHAR, "Type", "Which part of the text to delete");
+ /* identifiers */
+ ot->name = "Delete";
+ ot->description = "Delete text by cursor position";
+ ot->idname = "CONSOLE_OT_delete";
+
+ /* api callbacks */
+ ot->exec = console_delete_exec;
+ ot->poll = ED_operator_console_active;
+
+ /* properties */
+ RNA_def_enum(ot->srna,
+ "type",
+ console_delete_type_items,
+ DEL_NEXT_CHAR,
+ "Type",
+ "Which part of the text to delete");
}
static int console_clear_line_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci = console_history_verify(C);
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci = console_history_verify(C);
- if (ci->len == 0) {
- return OPERATOR_CANCELLED;
- }
+ if (ci->len == 0) {
+ return OPERATOR_CANCELLED;
+ }
- console_history_add(sc, ci);
- console_history_add(sc, NULL);
- console_select_offset(sc, -ci->len);
+ console_history_add(sc, ci);
+ console_history_add(sc, NULL);
+ console_select_offset(sc, -ci->len);
- console_textview_update_rect(sc, ar);
+ console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
+ ED_area_tag_redraw(CTX_wm_area(C));
- console_scroll_bottom(ar);
+ console_scroll_bottom(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_clear_line(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Clear Line";
- ot->description = "Clear the line and store in history";
- ot->idname = "CONSOLE_OT_clear_line";
-
- /* api callbacks */
- ot->exec = console_clear_line_exec;
- ot->poll = ED_operator_console_active;
+ /* identifiers */
+ ot->name = "Clear Line";
+ ot->description = "Clear the line and store in history";
+ ot->idname = "CONSOLE_OT_clear_line";
+
+ /* api callbacks */
+ ot->exec = console_clear_line_exec;
+ ot->poll = ED_operator_console_active;
}
/* the python exec operator uses this */
static int console_clear_exec(bContext *C, wmOperator *op)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
- const bool scrollback = RNA_boolean_get(op->ptr, "scrollback");
- const bool history = RNA_boolean_get(op->ptr, "history");
+ const bool scrollback = RNA_boolean_get(op->ptr, "scrollback");
+ const bool history = RNA_boolean_get(op->ptr, "history");
- /*ConsoleLine *ci = */ console_history_verify(C);
+ /*ConsoleLine *ci = */ console_history_verify(C);
- if (scrollback) { /* last item in mistory */
- while (sc->scrollback.first) {
- console_scrollback_free(sc, sc->scrollback.first);
- }
- }
+ if (scrollback) { /* last item in mistory */
+ while (sc->scrollback.first) {
+ console_scrollback_free(sc, sc->scrollback.first);
+ }
+ }
- if (history) {
- while (sc->history.first) {
- console_history_free(sc, sc->history.first);
- }
- console_history_verify(C);
- }
+ if (history) {
+ while (sc->history.first) {
+ console_history_free(sc, sc->history.first);
+ }
+ console_history_verify(C);
+ }
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_clear(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Clear";
- ot->description = "Clear text by type";
- ot->idname = "CONSOLE_OT_clear";
-
- /* api callbacks */
- ot->exec = console_clear_exec;
- ot->poll = ED_operator_console_active;
-
- /* properties */
- RNA_def_boolean(ot->srna, "scrollback", 1, "Scrollback", "Clear the scrollback history");
- RNA_def_boolean(ot->srna, "history", 0, "History", "Clear the command history");
+ /* identifiers */
+ ot->name = "Clear";
+ ot->description = "Clear text by type";
+ ot->idname = "CONSOLE_OT_clear";
+
+ /* api callbacks */
+ ot->exec = console_clear_exec;
+ ot->poll = ED_operator_console_active;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "scrollback", 1, "Scrollback", "Clear the scrollback history");
+ RNA_def_boolean(ot->srna, "history", 0, "History", "Clear the command history");
}
-
-
/* the python exec operator uses this */
static int console_history_cycle_exec(bContext *C, wmOperator *op)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
-
- /* TODO - stupid, just prevents crashes when no command line */
- ConsoleLine *ci = console_history_verify(C);
- const bool reverse = RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
- int prev_len = ci->len;
-
- /* keep a copy of the line above so when history is cycled
- * this is the only function that needs to know about the double-up */
- if (ci->prev) {
- ConsoleLine *ci_prev = (ConsoleLine *)ci->prev;
-
- if (STREQ(ci->line, ci_prev->line)) {
- console_history_free(sc, ci_prev);
- }
- }
-
- if (reverse) { /* last item in history */
- ci = sc->history.last;
- BLI_remlink(&sc->history, ci);
- BLI_addhead(&sc->history, ci);
- }
- else {
- ci = sc->history.first;
- BLI_remlink(&sc->history, ci);
- BLI_addtail(&sc->history, ci);
- }
-
- { /* add a duplicate of the new arg and remove all other instances */
- ConsoleLine *cl;
- while ((cl = console_history_find(sc, ci->line, ci))) {
- console_history_free(sc, cl);
- }
-
- console_history_add(sc, (ConsoleLine *)sc->history.last);
- }
-
- ci = sc->history.last;
- console_select_offset(sc, ci->len - prev_len);
-
- /* could be wrapped so update scroll rect */
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
-
- console_scroll_bottom(ar);
-
- return OPERATOR_FINISHED;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ /* TODO - stupid, just prevents crashes when no command line */
+ ConsoleLine *ci = console_history_verify(C);
+ const bool reverse = RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
+ int prev_len = ci->len;
+
+ /* keep a copy of the line above so when history is cycled
+ * this is the only function that needs to know about the double-up */
+ if (ci->prev) {
+ ConsoleLine *ci_prev = (ConsoleLine *)ci->prev;
+
+ if (STREQ(ci->line, ci_prev->line)) {
+ console_history_free(sc, ci_prev);
+ }
+ }
+
+ if (reverse) { /* last item in history */
+ ci = sc->history.last;
+ BLI_remlink(&sc->history, ci);
+ BLI_addhead(&sc->history, ci);
+ }
+ else {
+ ci = sc->history.first;
+ BLI_remlink(&sc->history, ci);
+ BLI_addtail(&sc->history, ci);
+ }
+
+ { /* add a duplicate of the new arg and remove all other instances */
+ ConsoleLine *cl;
+ while ((cl = console_history_find(sc, ci->line, ci))) {
+ console_history_free(sc, cl);
+ }
+
+ console_history_add(sc, (ConsoleLine *)sc->history.last);
+ }
+
+ ci = sc->history.last;
+ console_select_offset(sc, ci->len - prev_len);
+
+ /* could be wrapped so update scroll rect */
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
+
+ console_scroll_bottom(ar);
+
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_history_cycle(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "History Cycle";
- ot->description = "Cycle through history";
- ot->idname = "CONSOLE_OT_history_cycle";
+ /* identifiers */
+ ot->name = "History Cycle";
+ ot->description = "Cycle through history";
+ ot->idname = "CONSOLE_OT_history_cycle";
- /* api callbacks */
- ot->exec = console_history_cycle_exec;
- ot->poll = ED_operator_console_active;
+ /* api callbacks */
+ ot->exec = console_history_cycle_exec;
+ ot->poll = ED_operator_console_active;
- /* properties */
- RNA_def_boolean(ot->srna, "reverse", 0, "Reverse", "Reverse cycle history");
+ /* properties */
+ RNA_def_boolean(ot->srna, "reverse", 0, "Reverse", "Reverse cycle history");
}
-
/* the python exec operator uses this */
static int console_history_append_exec(bContext *C, wmOperator *op)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ScrArea *sa = CTX_wm_area(C);
- ConsoleLine *ci = console_history_verify(C);
- /* own this text in the new line, don't free */
- char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
- int cursor = RNA_int_get(op->ptr, "current_character");
- const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
- int prev_len = ci->len;
-
- if (rem_dupes) {
- ConsoleLine *cl;
-
- while ((cl = console_history_find(sc, ci->line, ci))) {
- console_history_free(sc, cl);
- }
-
- if (STREQ(str, ci->line)) {
- MEM_freeN(str);
- return OPERATOR_FINISHED;
- }
- }
-
- ci = console_history_add_str(sc, str, 1); /* own the string */
- console_select_offset(sc, ci->len - prev_len);
- console_line_cursor_set(ci, cursor);
-
- ED_area_tag_redraw(sa);
-
- /* when calling render modally this can be NULL when calling:
- * bpy.ops.render.render('INVOKE_DEFAULT') */
- if (ar) {
- console_scroll_bottom(ar);
- }
-
- return OPERATOR_FINISHED;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ScrArea *sa = CTX_wm_area(C);
+ ConsoleLine *ci = console_history_verify(C);
+ /* own this text in the new line, don't free */
+ char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ int cursor = RNA_int_get(op->ptr, "current_character");
+ const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
+ int prev_len = ci->len;
+
+ if (rem_dupes) {
+ ConsoleLine *cl;
+
+ while ((cl = console_history_find(sc, ci->line, ci))) {
+ console_history_free(sc, cl);
+ }
+
+ if (STREQ(str, ci->line)) {
+ MEM_freeN(str);
+ return OPERATOR_FINISHED;
+ }
+ }
+
+ ci = console_history_add_str(sc, str, 1); /* own the string */
+ console_select_offset(sc, ci->len - prev_len);
+ console_line_cursor_set(ci, cursor);
+
+ ED_area_tag_redraw(sa);
+
+ /* when calling render modally this can be NULL when calling:
+ * bpy.ops.render.render('INVOKE_DEFAULT') */
+ if (ar) {
+ console_scroll_bottom(ar);
+ }
+
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_history_append(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "History Append";
- ot->description = "Append history at cursor position";
- ot->idname = "CONSOLE_OT_history_append";
-
- /* api callbacks */
- ot->exec = console_history_append_exec;
- ot->poll = ED_operator_console_active;
-
- /* properties */
- RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
- RNA_def_int(ot->srna, "current_character", 0, 0, INT_MAX, "Cursor", "The index of the cursor", 0, 10000);
- RNA_def_boolean(ot->srna, "remove_duplicates", 0, "Remove Duplicates", "Remove duplicate items in the history");
+ /* identifiers */
+ ot->name = "History Append";
+ ot->description = "Append history at cursor position";
+ ot->idname = "CONSOLE_OT_history_append";
+
+ /* api callbacks */
+ ot->exec = console_history_append_exec;
+ ot->poll = ED_operator_console_active;
+
+ /* properties */
+ RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
+ RNA_def_int(
+ ot->srna, "current_character", 0, 0, INT_MAX, "Cursor", "The index of the cursor", 0, 10000);
+ RNA_def_boolean(ot->srna,
+ "remove_duplicates",
+ 0,
+ "Remove Duplicates",
+ "Remove duplicate items in the history");
}
-
/* the python exec operator uses this */
static int console_scrollback_append_exec(bContext *C, wmOperator *op)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci;
- /* own this text in the new line, don't free */
- char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
- int type = RNA_enum_get(op->ptr, "type");
+ /* own this text in the new line, don't free */
+ char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ int type = RNA_enum_get(op->ptr, "type");
- console_history_verify(C);
+ console_history_verify(C);
- ci = console_scrollback_add_str(sc, str, 1); /* own the string */
- ci->type = type;
+ ci = console_scrollback_add_str(sc, str, 1); /* own the string */
+ ci->type = type;
- console_scrollback_limit(sc);
+ console_scrollback_limit(sc);
- /* 'ar' can be null depending on the operator that runs
- * rendering with invoke default for eg causes this */
- if (ar) {
- console_textview_update_rect(sc, ar);
- }
+ /* 'ar' can be null depending on the operator that runs
+ * rendering with invoke default for eg causes this */
+ if (ar) {
+ console_textview_update_rect(sc, ar);
+ }
- ED_area_tag_redraw(CTX_wm_area(C));
+ ED_area_tag_redraw(CTX_wm_area(C));
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_scrollback_append(wmOperatorType *ot)
{
- /* defined in DNA_space_types.h */
- static const EnumPropertyItem console_line_type_items[] = {
- {CONSOLE_LINE_OUTPUT, "OUTPUT", 0, "Output", ""},
- {CONSOLE_LINE_INPUT, "INPUT", 0, "Input", ""},
- {CONSOLE_LINE_INFO, "INFO", 0, "Information", ""},
- {CONSOLE_LINE_ERROR, "ERROR", 0, "Error", ""},
- {0, NULL, 0, NULL, NULL},
- };
-
- /* identifiers */
- ot->name = "Scrollback Append";
- ot->description = "Append scrollback text by type";
- ot->idname = "CONSOLE_OT_scrollback_append";
-
- /* api callbacks */
- ot->exec = console_scrollback_append_exec;
- ot->poll = ED_operator_console_active;
-
- /* properties */
- RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
- RNA_def_enum(ot->srna, "type", console_line_type_items, CONSOLE_LINE_OUTPUT, "Type", "Console output type");
+ /* defined in DNA_space_types.h */
+ static const EnumPropertyItem console_line_type_items[] = {
+ {CONSOLE_LINE_OUTPUT, "OUTPUT", 0, "Output", ""},
+ {CONSOLE_LINE_INPUT, "INPUT", 0, "Input", ""},
+ {CONSOLE_LINE_INFO, "INFO", 0, "Information", ""},
+ {CONSOLE_LINE_ERROR, "ERROR", 0, "Error", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Scrollback Append";
+ ot->description = "Append scrollback text by type";
+ ot->idname = "CONSOLE_OT_scrollback_append";
+
+ /* api callbacks */
+ ot->exec = console_scrollback_append_exec;
+ ot->poll = ED_operator_console_active;
+
+ /* properties */
+ RNA_def_string(ot->srna, "text", NULL, 0, "Text", "Text to insert at the cursor position");
+ RNA_def_enum(ot->srna,
+ "type",
+ console_line_type_items,
+ CONSOLE_LINE_OUTPUT,
+ "Type",
+ "Console output type");
}
-
static int console_copy_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceConsole *sc = CTX_wm_space_console(C);
+ SpaceConsole *sc = CTX_wm_space_console(C);
- DynStr *buf_dyn;
- char *buf_str;
+ DynStr *buf_dyn;
+ char *buf_str;
- ConsoleLine *cl;
- int sel[2];
- int offset = 0;
+ ConsoleLine *cl;
+ int sel[2];
+ int offset = 0;
- ConsoleLine cl_dummy = {NULL};
+ ConsoleLine cl_dummy = {NULL};
- if (sc->sel_start == sc->sel_end) {
- return OPERATOR_CANCELLED;
- }
+ if (sc->sel_start == sc->sel_end) {
+ return OPERATOR_CANCELLED;
+ }
- console_scrollback_prompt_begin(sc, &cl_dummy);
+ console_scrollback_prompt_begin(sc, &cl_dummy);
- for (cl = sc->scrollback.first; cl; cl = cl->next) {
- offset += cl->len + 1;
- }
+ for (cl = sc->scrollback.first; cl; cl = cl->next) {
+ offset += cl->len + 1;
+ }
- if (offset == 0) {
- console_scrollback_prompt_end(sc, &cl_dummy);
- return OPERATOR_CANCELLED;
- }
+ if (offset == 0) {
+ console_scrollback_prompt_end(sc, &cl_dummy);
+ return OPERATOR_CANCELLED;
+ }
- buf_dyn = BLI_dynstr_new();
- offset -= 1;
- sel[0] = offset - sc->sel_end;
- sel[1] = offset - sc->sel_start;
+ buf_dyn = BLI_dynstr_new();
+ offset -= 1;
+ sel[0] = offset - sc->sel_end;
+ sel[1] = offset - sc->sel_start;
- for (cl = sc->scrollback.first; cl; cl = cl->next) {
- if (sel[0] <= cl->len && sel[1] >= 0) {
- int sta = max_ii(sel[0], 0);
- int end = min_ii(sel[1], cl->len);
+ for (cl = sc->scrollback.first; cl; cl = cl->next) {
+ if (sel[0] <= cl->len && sel[1] >= 0) {
+ int sta = max_ii(sel[0], 0);
+ int end = min_ii(sel[1], cl->len);
- if (BLI_dynstr_get_len(buf_dyn)) {
- BLI_dynstr_append(buf_dyn, "\n");
- }
+ if (BLI_dynstr_get_len(buf_dyn)) {
+ BLI_dynstr_append(buf_dyn, "\n");
+ }
- BLI_dynstr_nappend(buf_dyn, cl->line + sta, end - sta);
- }
+ BLI_dynstr_nappend(buf_dyn, cl->line + sta, end - sta);
+ }
- sel[0] -= cl->len + 1;
- sel[1] -= cl->len + 1;
- }
+ sel[0] -= cl->len + 1;
+ sel[1] -= cl->len + 1;
+ }
- buf_str = BLI_dynstr_get_cstring(buf_dyn);
+ buf_str = BLI_dynstr_get_cstring(buf_dyn);
- BLI_dynstr_free(buf_dyn);
- WM_clipboard_text_set(buf_str, 0);
+ BLI_dynstr_free(buf_dyn);
+ WM_clipboard_text_set(buf_str, 0);
- MEM_freeN(buf_str);
+ MEM_freeN(buf_str);
- console_scrollback_prompt_end(sc, &cl_dummy);
+ console_scrollback_prompt_end(sc, &cl_dummy);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_copy(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Copy to Clipboard";
- ot->description = "Copy selected text to clipboard";
- ot->idname = "CONSOLE_OT_copy";
+ /* identifiers */
+ ot->name = "Copy to Clipboard";
+ ot->description = "Copy selected text to clipboard";
+ ot->idname = "CONSOLE_OT_copy";
- /* api callbacks */
- ot->poll = ED_operator_console_active;
- ot->exec = console_copy_exec;
+ /* api callbacks */
+ ot->poll = ED_operator_console_active;
+ ot->exec = console_copy_exec;
- /* properties */
+ /* properties */
}
static int console_paste_exec(bContext *C, wmOperator *UNUSED(op))
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- ConsoleLine *ci = console_history_verify(C);
- int buf_len;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ ConsoleLine *ci = console_history_verify(C);
+ int buf_len;
- char *buf_str = WM_clipboard_text_get(false, &buf_len);
- char *buf_step, *buf_next;
+ char *buf_str = WM_clipboard_text_get(false, &buf_len);
+ char *buf_step, *buf_next;
- if (buf_str == NULL) {
- return OPERATOR_CANCELLED;
- }
+ if (buf_str == NULL) {
+ return OPERATOR_CANCELLED;
+ }
- buf_step = buf_str;
+ buf_step = buf_str;
- while ((buf_next = buf_step) && buf_next[0] != '\0') {
- buf_step = strchr(buf_next, '\n');
- if (buf_step) {
- *buf_step = '\0';
- buf_step++;
- }
+ while ((buf_next = buf_step) && buf_next[0] != '\0') {
+ buf_step = strchr(buf_next, '\n');
+ if (buf_step) {
+ *buf_step = '\0';
+ buf_step++;
+ }
- if (buf_next != buf_str) {
- WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
- ci = console_history_verify(C);
- }
+ if (buf_next != buf_str) {
+ WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
+ ci = console_history_verify(C);
+ }
- console_select_offset(sc, console_line_insert(ci, buf_next));
- }
+ console_select_offset(sc, console_line_insert(ci, buf_next));
+ }
- MEM_freeN(buf_str);
+ MEM_freeN(buf_str);
- console_textview_update_rect(sc, ar);
- ED_area_tag_redraw(CTX_wm_area(C));
+ console_textview_update_rect(sc, ar);
+ ED_area_tag_redraw(CTX_wm_area(C));
- console_scroll_bottom(ar);
+ console_scroll_bottom(ar);
- return OPERATOR_FINISHED;
+ return OPERATOR_FINISHED;
}
void CONSOLE_OT_paste(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Paste from Clipboard";
- ot->description = "Paste text from clipboard";
- ot->idname = "CONSOLE_OT_paste";
+ /* identifiers */
+ ot->name = "Paste from Clipboard";
+ ot->description = "Paste text from clipboard";
+ ot->idname = "CONSOLE_OT_paste";
- /* api callbacks */
- ot->poll = ED_operator_console_active;
- ot->exec = console_paste_exec;
+ /* api callbacks */
+ ot->poll = ED_operator_console_active;
+ ot->exec = console_paste_exec;
- /* properties */
+ /* properties */
}
typedef struct SetConsoleCursor {
- int sel_old[2];
- int sel_init;
+ int sel_old[2];
+ int sel_init;
} SetConsoleCursor;
// TODO, cursor placement without selection
-static void console_cursor_set_to_pos(SpaceConsole *sc, ARegion *ar, SetConsoleCursor *scu, int mval[2], int UNUSED(sel))
+static void console_cursor_set_to_pos(
+ SpaceConsole *sc, ARegion *ar, SetConsoleCursor *scu, int mval[2], int UNUSED(sel))
{
- int pos;
- pos = console_char_pick(sc, ar, mval);
-
- if (scu->sel_init == INT_MAX) {
- scu->sel_init = pos;
- sc->sel_start = sc->sel_end = pos;
- return;
- }
-
- if (pos < scu->sel_init) {
- sc->sel_start = pos;
- sc->sel_end = scu->sel_init;
- }
- else if (pos > sc->sel_start) {
- sc->sel_start = scu->sel_init;
- sc->sel_end = pos;
- }
- else {
- sc->sel_start = sc->sel_end = pos;
- }
+ int pos;
+ pos = console_char_pick(sc, ar, mval);
+
+ if (scu->sel_init == INT_MAX) {
+ scu->sel_init = pos;
+ sc->sel_start = sc->sel_end = pos;
+ return;
+ }
+
+ if (pos < scu->sel_init) {
+ sc->sel_start = pos;
+ sc->sel_end = scu->sel_init;
+ }
+ else if (pos > sc->sel_start) {
+ sc->sel_start = scu->sel_init;
+ sc->sel_end = pos;
+ }
+ else {
+ sc->sel_start = sc->sel_end = pos;
+ }
}
static void console_modal_select_apply(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
- SetConsoleCursor *scu = op->customdata;
- int mval[2];
- int sel_prev[2];
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
+ SetConsoleCursor *scu = op->customdata;
+ int mval[2];
+ int sel_prev[2];
- mval[0] = event->mval[0];
- mval[1] = event->mval[1];
+ mval[0] = event->mval[0];
+ mval[1] = event->mval[1];
- sel_prev[0] = sc->sel_start;
- sel_prev[1] = sc->sel_end;
+ sel_prev[0] = sc->sel_start;
+ sel_prev[1] = sc->sel_end;
- console_cursor_set_to_pos(sc, ar, scu, mval, true);
+ console_cursor_set_to_pos(sc, ar, scu, mval, true);
- /* only redraw if the selection changed */
- if (sel_prev[0] != sc->sel_start || sel_prev[1] != sc->sel_end) {
- ED_area_tag_redraw(CTX_wm_area(C));
- }
+ /* only redraw if the selection changed */
+ if (sel_prev[0] != sc->sel_start || sel_prev[1] != sc->sel_end) {
+ ED_area_tag_redraw(CTX_wm_area(C));
+ }
}
static void console_cursor_set_exit(bContext *UNUSED(C), wmOperator *op)
{
-// SpaceConsole *sc = CTX_wm_space_console(C);
- SetConsoleCursor *scu = op->customdata;
+ // SpaceConsole *sc = CTX_wm_space_console(C);
+ SetConsoleCursor *scu = op->customdata;
#if 0
- if (txt_has_sel(text)) {
- buffer = txt_sel_to_buf(text);
- WM_clipboard_text_set(buffer, 1);
- MEM_freeN(buffer);
- }
+ if (txt_has_sel(text)) {
+ buffer = txt_sel_to_buf(text);
+ WM_clipboard_text_set(buffer, 1);
+ MEM_freeN(buffer);
+ }
#endif
- MEM_freeN(scu);
+ MEM_freeN(scu);
}
static int console_modal_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
-// ARegion *ar = CTX_wm_region(C);
- SetConsoleCursor *scu;
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ // ARegion *ar = CTX_wm_region(C);
+ SetConsoleCursor *scu;
- op->customdata = MEM_callocN(sizeof(SetConsoleCursor), "SetConsoleCursor");
- scu = op->customdata;
+ op->customdata = MEM_callocN(sizeof(SetConsoleCursor), "SetConsoleCursor");
+ scu = op->customdata;
- scu->sel_old[0] = sc->sel_start;
- scu->sel_old[1] = sc->sel_end;
+ scu->sel_old[0] = sc->sel_start;
+ scu->sel_old[1] = sc->sel_end;
- scu->sel_init = INT_MAX;
+ scu->sel_init = INT_MAX;
- WM_event_add_modal_handler(C, op);
+ WM_event_add_modal_handler(C, op);
- console_modal_select_apply(C, op, event);
+ console_modal_select_apply(C, op, event);
- return OPERATOR_RUNNING_MODAL;
+ return OPERATOR_RUNNING_MODAL;
}
static int console_modal_select(bContext *C, wmOperator *op, const wmEvent *event)
{
- switch (event->type) {
- case LEFTMOUSE:
- case MIDDLEMOUSE:
- case RIGHTMOUSE:
- if (event->val == KM_RELEASE) {
- console_cursor_set_exit(C, op);
- return OPERATOR_FINISHED;
- }
- break;
- case MOUSEMOVE:
- console_modal_select_apply(C, op, event);
- break;
- }
-
- return OPERATOR_RUNNING_MODAL;
+ switch (event->type) {
+ case LEFTMOUSE:
+ case MIDDLEMOUSE:
+ case RIGHTMOUSE:
+ if (event->val == KM_RELEASE) {
+ console_cursor_set_exit(C, op);
+ return OPERATOR_FINISHED;
+ }
+ break;
+ case MOUSEMOVE:
+ console_modal_select_apply(C, op, event);
+ break;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
}
static void console_modal_select_cancel(bContext *C, wmOperator *op)
{
- console_cursor_set_exit(C, op);
+ console_cursor_set_exit(C, op);
}
void CONSOLE_OT_select_set(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Set Selection";
- ot->idname = "CONSOLE_OT_select_set";
- ot->description = "Set the console selection";
-
- /* api callbacks */
- ot->invoke = console_modal_select_invoke;
- ot->modal = console_modal_select;
- ot->cancel = console_modal_select_cancel;
- ot->poll = ED_operator_console_active;
+ /* identifiers */
+ ot->name = "Set Selection";
+ ot->idname = "CONSOLE_OT_select_set";
+ ot->description = "Set the console selection";
+
+ /* api callbacks */
+ ot->invoke = console_modal_select_invoke;
+ ot->modal = console_modal_select;
+ ot->cancel = console_modal_select_cancel;
+ ot->poll = ED_operator_console_active;
}
static int console_selectword_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
- SpaceConsole *sc = CTX_wm_space_console(C);
- ARegion *ar = CTX_wm_region(C);
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ ARegion *ar = CTX_wm_region(C);
- ConsoleLine cl_dummy = {NULL};
- ConsoleLine *cl;
- int ret = OPERATOR_CANCELLED;
- int pos, offset, n;
+ ConsoleLine cl_dummy = {NULL};
+ ConsoleLine *cl;
+ int ret = OPERATOR_CANCELLED;
+ int pos, offset, n;
- pos = console_char_pick(sc, ar, event->mval);
+ pos = console_char_pick(sc, ar, event->mval);
- console_scrollback_prompt_begin(sc, &cl_dummy);
+ console_scrollback_prompt_begin(sc, &cl_dummy);
- if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) {
- int sel[2] = {n, n};
+ if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) {
+ int sel[2] = {n, n};
- BLI_str_cursor_step_utf8(
- cl->line, cl->len,
- &sel[0], STRCUR_DIR_NEXT,
- STRCUR_JUMP_DELIM, true);
+ BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true);
- BLI_str_cursor_step_utf8(
- cl->line, cl->len,
- &sel[1], STRCUR_DIR_PREV,
- STRCUR_JUMP_DELIM, true);
+ BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[1], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true);
- sel[0] = offset - sel[0];
- sel[1] = offset - sel[1];
+ sel[0] = offset - sel[0];
+ sel[1] = offset - sel[1];
- if ((sel[0] != sc->sel_start) || (sel[1] != sc->sel_end)) {
- sc->sel_start = sel[0];
- sc->sel_end = sel[1];
- ED_area_tag_redraw(CTX_wm_area(C));
- ret = OPERATOR_FINISHED;
- }
- }
+ if ((sel[0] != sc->sel_start) || (sel[1] != sc->sel_end)) {
+ sc->sel_start = sel[0];
+ sc->sel_end = sel[1];
+ ED_area_tag_redraw(CTX_wm_area(C));
+ ret = OPERATOR_FINISHED;
+ }
+ }
- console_scrollback_prompt_end(sc, &cl_dummy);
- return ret;
+ console_scrollback_prompt_end(sc, &cl_dummy);
+ return ret;
}
void CONSOLE_OT_select_word(wmOperatorType *ot)
{
- /* identifiers */
- ot->name = "Select Word";
- ot->description = "Select word at cursor position";
- ot->idname = "CONSOLE_OT_select_word";
-
- /* api callbacks */
- ot->invoke = console_selectword_invoke;
- ot->poll = ED_operator_console_active;
+ /* identifiers */
+ ot->name = "Select Word";
+ ot->description = "Select word at cursor position";
+ ot->idname = "CONSOLE_OT_select_word";
+
+ /* api callbacks */
+ ot->invoke = console_selectword_invoke;
+ ot->poll = ED_operator_console_active;
}
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index 5d4623e6fe6..2cf8f6c46b9 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -40,227 +40,229 @@
#include "UI_resources.h"
#include "UI_view2d.h"
-#include "console_intern.h" // own include
+#include "console_intern.h" // own include
#include "GPU_framebuffer.h"
/* ******************** default callbacks for console space ***************** */
static SpaceLink *console_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
- ARegion *ar;
- SpaceConsole *sconsole;
+ ARegion *ar;
+ SpaceConsole *sconsole;
- sconsole = MEM_callocN(sizeof(SpaceConsole), "initconsole");
- sconsole->spacetype = SPACE_CONSOLE;
+ sconsole = MEM_callocN(sizeof(SpaceConsole), "initconsole");
+ sconsole->spacetype = SPACE_CONSOLE;
- sconsole->lheight = 14;
+ sconsole->lheight = 14;
- /* header */
- ar = MEM_callocN(sizeof(ARegion), "header for console");
+ /* header */
+ ar = MEM_callocN(sizeof(ARegion), "header for console");
- BLI_addtail(&sconsole->regionbase, ar);
- ar->regiontype = RGN_TYPE_HEADER;
- ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
+ BLI_addtail(&sconsole->regionbase, ar);
+ ar->regiontype = RGN_TYPE_HEADER;
+ ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
+ /* main region */
+ ar = MEM_callocN(sizeof(ARegion), "main region for text");
- /* main region */
- ar = MEM_callocN(sizeof(ARegion), "main region for text");
+ BLI_addtail(&sconsole->regionbase, ar);
+ ar->regiontype = RGN_TYPE_WINDOW;
- BLI_addtail(&sconsole->regionbase, ar);
- ar->regiontype = RGN_TYPE_WINDOW;
+ /* keep in sync with info */
+ ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
+ ar->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
+ ar->v2d.keepofs |= V2D_LOCKOFS_X;
+ ar->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT);
+ ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
+ ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f;
- /* keep in sync with info */
- ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
- ar->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
- ar->v2d.keepofs |= V2D_LOCKOFS_X;
- ar->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT);
- ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
- ar->v2d.minzoom = ar->v2d.maxzoom = 1.0f;
+ /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
+ //ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
- /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
- //ar->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
-
- return (SpaceLink *)sconsole;
+ return (SpaceLink *)sconsole;
}
/* not spacelink itself */
static void console_free(SpaceLink *sl)
{
- SpaceConsole *sc = (SpaceConsole *) sl;
+ SpaceConsole *sc = (SpaceConsole *)sl;
- while (sc->scrollback.first) {
- console_scrollback_free(sc, sc->scrollback.first);
- }
+ while (sc->scrollback.first) {
+ console_scrollback_free(sc, sc->scrollback.first);
+ }
- while (sc->history.first) {
- console_history_free(sc, sc->history.first);
- }
+ while (sc->history.first) {
+ console_history_free(sc, sc->history.first);
+ }
}
-
/* spacetype; init callback */
static void console_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
{
-
}
static SpaceLink *console_duplicate(SpaceLink *sl)
{
- SpaceConsole *sconsolen = MEM_dupallocN(sl);
+ SpaceConsole *sconsolen = MEM_dupallocN(sl);
- /* clear or remove stuff from old */
+ /* clear or remove stuff from old */
- /* TODO - duplicate?, then we also need to duplicate the py namespace */
- BLI_listbase_clear(&sconsolen->scrollback);
- BLI_listbase_clear(&sconsolen->history);
+ /* TODO - duplicate?, then we also need to duplicate the py namespace */
+ BLI_listbase_clear(&sconsolen->scrollback);
+ BLI_listbase_clear(&sconsolen->history);
- return (SpaceLink *)sconsolen;
+ return (SpaceLink *)sconsolen;
}
-
-
/* add handlers, stuff you only do once or on area/region changes */
static void console_main_region_init(wmWindowManager *wm, ARegion *ar)
{
- wmKeyMap *keymap;
- ListBase *lb;
+ wmKeyMap *keymap;
+ ListBase *lb;
- const float prev_y_min = ar->v2d.cur.ymin; /* so re-sizing keeps the cursor visible */
+ const float prev_y_min = ar->v2d.cur.ymin; /* so re-sizing keeps the cursor visible */
- /* force it on init, for old files, until it becomes config */
- ar->v2d.scroll = (V2D_SCROLL_RIGHT);
+ /* force it on init, for old files, until it becomes config */
+ ar->v2d.scroll = (V2D_SCROLL_RIGHT);
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
+ UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
- /* always keep the bottom part of the view aligned, less annoying */
- if (prev_y_min != ar->v2d.cur.ymin) {
- const float cur_y_range = BLI_rctf_size_y(&ar->v2d.cur);
- ar->v2d.cur.ymin = prev_y_min;
- ar->v2d.cur.ymax = prev_y_min + cur_y_range;
- }
+ /* always keep the bottom part of the view aligned, less annoying */
+ if (prev_y_min != ar->v2d.cur.ymin) {
+ const float cur_y_range = BLI_rctf_size_y(&ar->v2d.cur);
+ ar->v2d.cur.ymin = prev_y_min;
+ ar->v2d.cur.ymax = prev_y_min + cur_y_range;
+ }
- /* own keymap */
- keymap = WM_keymap_ensure(wm->defaultconf, "Console", SPACE_CONSOLE, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+ /* own keymap */
+ keymap = WM_keymap_ensure(wm->defaultconf, "Console", SPACE_CONSOLE, 0);
+ WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
- /* add drop boxes */
- lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
+ /* add drop boxes */
+ lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
- WM_event_add_dropbox_handler(&ar->handlers, lb);
+ WM_event_add_dropbox_handler(&ar->handlers, lb);
}
/* same as 'text_cursor' */
static void console_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
{
- SpaceText *st = sa->spacedata.first;
- int wmcursor = BC_TEXTEDITCURSOR;
+ SpaceText *st = sa->spacedata.first;
+ int wmcursor = BC_TEXTEDITCURSOR;
- if (st->text && BLI_rcti_isect_pt(&st->txtbar, win->eventstate->x - ar->winrct.xmin, st->txtbar.ymin)) {
- wmcursor = CURSOR_STD;
- }
+ if (st->text &&
+ BLI_rcti_isect_pt(&st->txtbar, win->eventstate->x - ar->winrct.xmin, st->txtbar.ymin)) {
+ wmcursor = CURSOR_STD;
+ }
- WM_cursor_set(win, wmcursor);
+ WM_cursor_set(win, wmcursor);
}
/* ************* dropboxes ************* */
-static bool id_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
+static bool id_drop_poll(bContext *UNUSED(C),
+ wmDrag *drag,
+ const wmEvent *UNUSED(event),
+ const char **UNUSED(tooltip))
{
- return WM_drag_ID(drag, 0) != NULL;
+ return WM_drag_ID(drag, 0) != NULL;
}
static void id_drop_copy(wmDrag *drag, wmDropBox *drop)
{
- ID *id = WM_drag_ID(drag, 0);
+ ID *id = WM_drag_ID(drag, 0);
- /* copy drag path to properties */
- char *text = RNA_path_full_ID_py(id);
- RNA_string_set(drop->ptr, "text", text);
- MEM_freeN(text);
+ /* copy drag path to properties */
+ char *text = RNA_path_full_ID_py(id);
+ RNA_string_set(drop->ptr, "text", text);
+ MEM_freeN(text);
}
-static bool path_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip))
+static bool path_drop_poll(bContext *UNUSED(C),
+ wmDrag *drag,
+ const wmEvent *UNUSED(event),
+ const char **UNUSED(tooltip))
{
- return (drag->type == WM_DRAG_PATH);
+ return (drag->type == WM_DRAG_PATH);
}
static void path_drop_copy(wmDrag *drag, wmDropBox *drop)
{
- char pathname[FILE_MAX + 2];
- BLI_snprintf(pathname, sizeof(pathname), "\"%s\"", drag->path);
- RNA_string_set(drop->ptr, "text", pathname);
+ char pathname[FILE_MAX + 2];
+ BLI_snprintf(pathname, sizeof(pathname), "\"%s\"", drag->path);
+ RNA_string_set(drop->ptr, "text", pathname);
}
-
/* this region dropbox definition */
static void console_dropboxes(void)
{
- ListBase *lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
+ ListBase *lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
- WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy);
- WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy);
+ WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy);
+ WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy);
}
/* ************* end drop *********** */
static void console_main_region_draw(const bContext *C, ARegion *ar)
{
- /* draw entirely, view changes should be handled here */
- SpaceConsole *sc = CTX_wm_space_console(C);
- View2D *v2d = &ar->v2d;
- View2DScrollers *scrollers;
+ /* draw entirely, view changes should be handled here */
+ SpaceConsole *sc = CTX_wm_space_console(C);
+ View2D *v2d = &ar->v2d;
+ View2DScrollers *scrollers;
- if (BLI_listbase_is_empty(&sc->scrollback)) {
- WM_operator_name_call((bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, NULL);
- }
+ if (BLI_listbase_is_empty(&sc->scrollback)) {
+ WM_operator_name_call((bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, NULL);
+ }
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- GPU_clear(GPU_COLOR_BIT);
+ /* clear and setup matrix */
+ UI_ThemeClearColor(TH_BACK);
+ GPU_clear(GPU_COLOR_BIT);
- /* worlks best with no view2d matrix set */
- UI_view2d_view_ortho(v2d);
+ /* worlks best with no view2d matrix set */
+ UI_view2d_view_ortho(v2d);
- /* data... */
+ /* data... */
- console_history_verify(C); /* make sure we have some command line */
- console_textview_main(sc, ar);
+ console_history_verify(C); /* make sure we have some command line */
+ console_textview_main(sc, ar);
- /* reset view matrix */
- UI_view2d_view_restore(C);
+ /* reset view matrix */
+ UI_view2d_view_restore(C);
- /* scrollers */
- scrollers = UI_view2d_scrollers_calc(C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP);
- UI_view2d_scrollers_draw(C, v2d, scrollers);
- UI_view2d_scrollers_free(scrollers);
+ /* scrollers */
+ scrollers = UI_view2d_scrollers_calc(
+ C, v2d, NULL, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP);
+ UI_view2d_scrollers_draw(C, v2d, scrollers);
+ UI_view2d_scrollers_free(scrollers);
}
static void console_operatortypes(void)
{
- /* console_ops.c */
- WM_operatortype_append(CONSOLE_OT_move);
- WM_operatortype_append(CONSOLE_OT_delete);
- WM_operatortype_append(CONSOLE_OT_insert);
-
- WM_operatortype_append(CONSOLE_OT_indent);
- WM_operatortype_append(CONSOLE_OT_unindent);
-
- /* for use by python only */
- WM_operatortype_append(CONSOLE_OT_history_append);
- WM_operatortype_append(CONSOLE_OT_scrollback_append);
-
- WM_operatortype_append(CONSOLE_OT_clear);
- WM_operatortype_append(CONSOLE_OT_clear_line);
- WM_operatortype_append(CONSOLE_OT_history_cycle);
- WM_operatortype_append(CONSOLE_OT_copy);
- WM_operatortype_append(CONSOLE_OT_paste);
- WM_operatortype_append(CONSOLE_OT_select_set);
- WM_operatortype_append(CONSOLE_OT_select_word);
+ /* console_ops.c */
+ WM_operatortype_append(CONSOLE_OT_move);
+ WM_operatortype_append(CONSOLE_OT_delete);
+ WM_operatortype_append(CONSOLE_OT_insert);
+
+ WM_operatortype_append(CONSOLE_OT_indent);
+ WM_operatortype_append(CONSOLE_OT_unindent);
+
+ /* for use by python only */
+ WM_operatortype_append(CONSOLE_OT_history_append);
+ WM_operatortype_append(CONSOLE_OT_scrollback_append);
+
+ WM_operatortype_append(CONSOLE_OT_clear);
+ WM_operatortype_append(CONSOLE_OT_clear_line);
+ WM_operatortype_append(CONSOLE_OT_history_cycle);
+ WM_operatortype_append(CONSOLE_OT_copy);
+ WM_operatortype_append(CONSOLE_OT_paste);
+ WM_operatortype_append(CONSOLE_OT_select_set);
+ WM_operatortype_append(CONSOLE_OT_select_word);
}
static void console_keymap(struct wmKeyConfig *keyconf)
{
- WM_keymap_ensure(keyconf, "Console", SPACE_CONSOLE, 0);
+ WM_keymap_ensure(keyconf, "Console", SPACE_CONSOLE, 0);
}
/****************** header region ******************/
@@ -268,84 +270,79 @@ static void console_keymap(struct wmKeyConfig *keyconf)
/* add handlers, stuff you only do once or on area/region changes */
static void console_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
{
- ED_region_header_init(ar);
+ ED_region_header_init(ar);
}
static void console_header_region_draw(const bContext *C, ARegion *ar)
{
- ED_region_header(C, ar);
+ ED_region_header(C, ar);
}
static void console_main_region_listener(
- wmWindow *UNUSED(win), ScrArea *sa, ARegion *ar,
- wmNotifier *wmn, const Scene *UNUSED(scene))
+ wmWindow *UNUSED(win), ScrArea *sa, ARegion *ar, wmNotifier *wmn, const Scene *UNUSED(scene))
{
- // SpaceInfo *sinfo = sa->spacedata.first;
-
- /* context changes */
- switch (wmn->category) {
- case NC_SPACE:
- {
- if (wmn->data == ND_SPACE_CONSOLE) {
- if (wmn->action == NA_EDITED) {
- if ((wmn->reference && sa) && (wmn->reference == sa->spacedata.first)) {
- /* we've modified the geometry (font size), re-calculate rect */
- console_textview_update_rect(wmn->reference, ar);
- ED_region_tag_redraw(ar);
- }
- }
- else {
- /* generic redraw request */
- ED_region_tag_redraw(ar);
- }
- }
- break;
- }
- }
+ // SpaceInfo *sinfo = sa->spacedata.first;
+
+ /* context changes */
+ switch (wmn->category) {
+ case NC_SPACE: {
+ if (wmn->data == ND_SPACE_CONSOLE) {
+ if (wmn->action == NA_EDITED) {
+ if ((wmn->reference && sa) && (wmn->reference == sa->spacedata.first)) {
+ /* we've modified the geometry (font size), re-calculate rect */
+ console_textview_update_rect(wmn->reference, ar);
+ ED_region_tag_redraw(ar);
+ }
+ }
+ else {
+ /* generic redraw request */
+ ED_region_tag_redraw(ar);
+ }
+ }
+ break;
+ }
+ }
}
/* only called once, from space/spacetypes.c */
void ED_spacetype_console(void)
{
- SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype console");
- ARegionType *art;
-
- st->spaceid = SPACE_CONSOLE;
- strncpy(st->name, "Console", BKE_ST_MAXNAME);
-
- st->new = console_new;
- st->free = console_free;
- st->init = console_init;
- st->duplicate = console_duplicate;
- st->operatortypes = console_operatortypes;
- st->keymap = console_keymap;
- st->dropboxes = console_dropboxes;
-
- /* regions: main window */
- art = MEM_callocN(sizeof(ARegionType), "spacetype console region");
- art->regionid = RGN_TYPE_WINDOW;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
+ SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype console");
+ ARegionType *art;
- art->init = console_main_region_init;
- art->draw = console_main_region_draw;
- art->cursor = console_cursor;
- art->listener = console_main_region_listener;
+ st->spaceid = SPACE_CONSOLE;
+ strncpy(st->name, "Console", BKE_ST_MAXNAME);
+ st->new = console_new;
+ st->free = console_free;
+ st->init = console_init;
+ st->duplicate = console_duplicate;
+ st->operatortypes = console_operatortypes;
+ st->keymap = console_keymap;
+ st->dropboxes = console_dropboxes;
+ /* regions: main window */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype console region");
+ art->regionid = RGN_TYPE_WINDOW;
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
- BLI_addhead(&st->regiontypes, art);
+ art->init = console_main_region_init;
+ art->draw = console_main_region_draw;
+ art->cursor = console_cursor;
+ art->listener = console_main_region_listener;
- /* regions: header */
- art = MEM_callocN(sizeof(ARegionType), "spacetype console region");
- art->regionid = RGN_TYPE_HEADER;
- art->prefsizey = HEADERY;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
+ BLI_addhead(&st->regiontypes, art);
- art->init = console_header_region_init;
- art->draw = console_header_region_draw;
+ /* regions: header */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype console region");
+ art->regionid = RGN_TYPE_HEADER;
+ art->prefsizey = HEADERY;
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
- BLI_addhead(&st->regiontypes, art);
+ art->init = console_header_region_init;
+ art->draw = console_header_region_draw;
+ BLI_addhead(&st->regiontypes, art);
- BKE_spacetype_register(st);
+ BKE_spacetype_register(st);
}