2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2011-02-27 20:29:51 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spconsole
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-06-09 09:44:08 +10:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2025-02-11 16:59:42 +01:00
|
|
|
#include "BLI_listbase.h"
|
2025-01-26 20:08:00 +01:00
|
|
|
#include "BLI_string.h"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_space_api.hh"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
|
|
|
|
#include "RNA_path.hh"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
#include "WM_types.hh"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_resources.hh"
|
|
|
|
|
#include "UI_view2d.hh"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2022-09-28 11:52:22 +02:00
|
|
|
|
2023-06-09 09:44:08 +10:00
|
|
|
#include "console_intern.hh" /* own include */
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
/* ******************** default callbacks for console space ***************** */
|
|
|
|
|
|
2023-06-09 09:44:08 +10:00
|
|
|
static SpaceLink *console_create(const ScrArea * /*area*/, const Scene * /*scene*/)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region;
|
2009-07-16 00:50:27 +00:00
|
|
|
SpaceConsole *sconsole;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-06-09 09:44:08 +10:00
|
|
|
sconsole = static_cast<SpaceConsole *>(MEM_callocN(sizeof(SpaceConsole), "initconsole"));
|
2012-03-28 11:53:18 +00:00
|
|
|
sconsole->spacetype = SPACE_CONSOLE;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
sconsole->lheight = 14;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* header */
|
2024-11-15 02:00:11 +01:00
|
|
|
region = BKE_area_region_new();
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
BLI_addtail(&sconsole->regionbase, region);
|
|
|
|
|
region->regiontype = RGN_TYPE_HEADER;
|
|
|
|
|
region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2015-11-28 17:14:45 +01:00
|
|
|
/* main region */
|
2024-11-15 02:00:11 +01:00
|
|
|
region = BKE_area_region_new();
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
BLI_addtail(&sconsole->regionbase, region);
|
|
|
|
|
region->regiontype = RGN_TYPE_WINDOW;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
/* keep in sync with info */
|
2020-06-18 12:21:38 +10:00
|
|
|
region->v2d.scroll |= V2D_SCROLL_RIGHT;
|
2020-03-06 16:56:42 +01:00
|
|
|
region->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */
|
|
|
|
|
region->v2d.keepofs |= V2D_LOCKOFS_X;
|
|
|
|
|
region->v2d.keepzoom = (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y | V2D_LIMITZOOM | V2D_KEEPASPECT);
|
|
|
|
|
region->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
|
|
|
|
|
region->v2d.minzoom = region->v2d.maxzoom = 1.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
/* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
|
2020-03-06 16:56:42 +01:00
|
|
|
// region->v2d.keepzoom = (V2D_KEEPASPECT|V2D_LIMITZOOM);
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
return (SpaceLink *)sconsole;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 11:39:27 +10:00
|
|
|
/* Doesn't free the space-link itself. */
|
2009-07-16 00:50:27 +00:00
|
|
|
static void console_free(SpaceLink *sl)
|
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
SpaceConsole *sc = (SpaceConsole *)sl;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
while (sc->scrollback.first) {
|
2023-06-09 09:44:08 +10:00
|
|
|
console_scrollback_free(sc, static_cast<ConsoleLine *>(sc->scrollback.first));
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
while (sc->history.first) {
|
2023-06-09 09:44:08 +10:00
|
|
|
console_history_free(sc, static_cast<ConsoleLine *>(sc->history.first));
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* spacetype; init callback */
|
2023-06-09 09:44:08 +10:00
|
|
|
static void console_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
static SpaceLink *console_duplicate(SpaceLink *sl)
|
|
|
|
|
{
|
2023-06-09 09:44:08 +10:00
|
|
|
SpaceConsole *sconsolen = static_cast<SpaceConsole *>(MEM_dupallocN(sl));
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* clear or remove stuff from old */
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: duplicate?, then we also need to duplicate the py namespace. */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&sconsolen->scrollback);
|
|
|
|
|
BLI_listbase_clear(&sconsolen->history);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
return (SpaceLink *)sconsolen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add handlers, stuff you only do once or on area/region changes */
|
2020-03-06 16:56:42 +01:00
|
|
|
static void console_main_region_init(wmWindowManager *wm, ARegion *region)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2009-09-17 21:36:02 +00:00
|
|
|
wmKeyMap *keymap;
|
2010-05-08 07:25:26 +00:00
|
|
|
ListBase *lb;
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
const float prev_y_min = region->v2d.cur.ymin; /* so re-sizing keeps the cursor visible */
|
2011-09-18 01:34:53 +00:00
|
|
|
|
2013-04-12 12:30:05 +00:00
|
|
|
/* force it on init, for old files, until it becomes config */
|
2020-03-06 16:56:42 +01:00
|
|
|
region->v2d.scroll = (V2D_SCROLL_RIGHT);
|
2013-04-12 12:30:05 +00:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2011-09-18 01:34:53 +00:00
|
|
|
/* always keep the bottom part of the view aligned, less annoying */
|
2020-03-06 16:56:42 +01:00
|
|
|
if (prev_y_min != region->v2d.cur.ymin) {
|
|
|
|
|
const float cur_y_range = BLI_rctf_size_y(®ion->v2d.cur);
|
|
|
|
|
region->v2d.cur.ymin = prev_y_min;
|
|
|
|
|
region->v2d.cur.ymax = prev_y_min + cur_y_range;
|
2011-09-18 01:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* own keymap */
|
2023-09-14 13:32:42 +10:00
|
|
|
keymap = WM_keymap_ensure(wm->defaultconf, "Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
|
2024-11-21 19:34:53 +01:00
|
|
|
WM_event_add_keymap_handler_v2d_mask(®ion->runtime->handlers, keymap);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-09-19 15:47:06 +10:00
|
|
|
/* Include after "Console" so cursor motion keys such as "Home" isn't overridden. */
|
2023-09-14 13:32:42 +10:00
|
|
|
keymap = WM_keymap_ensure(wm->defaultconf, "View2D Buttons List", SPACE_EMPTY, RGN_TYPE_WINDOW);
|
2024-11-21 19:34:53 +01:00
|
|
|
WM_event_add_keymap_handler(®ion->runtime->handlers, keymap);
|
2022-09-19 15:47:06 +10:00
|
|
|
|
2010-05-08 07:25:26 +00:00
|
|
|
/* add drop boxes */
|
2012-03-28 11:53:18 +00:00
|
|
|
lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-11-21 19:34:53 +01:00
|
|
|
WM_event_add_dropbox_handler(®ion->runtime->handlers, lb);
|
2010-05-08 07:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-30 18:12:29 +10:00
|
|
|
/* same as 'text_cursor' */
|
2023-06-09 09:44:08 +10:00
|
|
|
static void console_cursor(wmWindow *win, ScrArea * /*area*/, ARegion *region)
|
2014-06-30 18:12:29 +10:00
|
|
|
{
|
2019-09-26 14:31:48 +02:00
|
|
|
int wmcursor = WM_CURSOR_TEXT_EDIT;
|
2019-11-25 22:49:44 +11:00
|
|
|
const wmEvent *event = win->eventstate;
|
2021-10-20 20:49:02 -03:00
|
|
|
if (UI_view2d_mouse_in_scrollers(region, ®ion->v2d, event->xy)) {
|
2019-09-26 14:31:48 +02:00
|
|
|
wmcursor = WM_CURSOR_DEFAULT;
|
2014-06-30 18:12:29 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WM_cursor_set(win, wmcursor);
|
|
|
|
|
}
|
2010-05-08 07:25:26 +00:00
|
|
|
|
|
|
|
|
/* ************* dropboxes ************* */
|
|
|
|
|
|
2024-02-16 14:27:06 +11:00
|
|
|
static bool console_drop_id_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
|
2010-05-08 07:25:26 +00:00
|
|
|
{
|
2023-06-09 09:44:08 +10:00
|
|
|
return WM_drag_get_local_ID(drag, 0) != nullptr;
|
2010-05-08 07:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-16 14:27:06 +11:00
|
|
|
static void console_drop_id_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
2010-05-08 07:25:26 +00:00
|
|
|
{
|
Asset System: Support dragging assets and appending on drop
For the Asset Browser, it needs to be possible to drag assets into various
editors, which may not come from the current .blend file. In other words, the
dragging needs to work with just the asset metadata, without direct access to
the data-block itself.
Idea is simple: When dragging an asset, store the source file-path and
data-block name and when dropping, append the data-block. It uses existing drop
operators, but the function to get the dropped data-block is replaced with one
that returns the local data-block, or, in case of an external asset, appends
the data-block first.
The drop operators need to be adjusted to use this new function that respects
assets. With this patch it only works for dragging assets into the 3D view.
Note that I expect this to be a short-lived change. A refactor like D4071 is
needed to make the drag & drop system more future proof for assets and other
use cases.
Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1
project milestone on developer.blender.org.
Differential Revision: https://developer.blender.org/D9721
Reviewed by: Bastien Montagne, Brecht Van Lommel
2020-12-14 13:31:55 +01:00
|
|
|
ID *id = WM_drag_get_local_ID(drag, 0);
|
2010-05-08 07:25:26 +00:00
|
|
|
|
|
|
|
|
/* copy drag path to properties */
|
2024-01-31 17:08:09 +01:00
|
|
|
std::string text = RNA_path_full_ID_py(id);
|
|
|
|
|
RNA_string_set(drop->ptr, "text", text.c_str());
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-16 14:27:06 +11:00
|
|
|
static bool console_drop_path_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
|
2010-05-08 07:25:26 +00:00
|
|
|
{
|
2018-08-07 10:57:09 +02:00
|
|
|
return (drag->type == WM_DRAG_PATH);
|
2010-05-08 07:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
2024-02-16 14:27:06 +11:00
|
|
|
static void console_drop_path_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
2010-05-08 07:25:26 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
char pathname[FILE_MAX + 2];
|
2023-12-12 18:46:12 +01:00
|
|
|
SNPRINTF(pathname, "\"%s\"", WM_drag_get_single_path(drag));
|
2010-05-08 07:25:26 +00:00
|
|
|
RNA_string_set(drop->ptr, "text", pathname);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-16 14:27:06 +11:00
|
|
|
static bool console_drop_string_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
|
|
|
|
|
{
|
|
|
|
|
return (drag->type == WM_DRAG_STRING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void console_drop_string_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
|
|
|
|
|
{
|
|
|
|
|
/* NOTE(@ideasman42): Only a single line is supported, multiple lines could be supported
|
|
|
|
|
* but this implies executing all lines except for the last. While we could consider that,
|
|
|
|
|
* there are some security implications for this, so just drop one line for now. */
|
2024-02-16 16:34:10 +11:00
|
|
|
std::string str = WM_drag_get_string_firstline(drag);
|
|
|
|
|
RNA_string_set(drop->ptr, "text", str.c_str());
|
2024-02-16 14:27:06 +11:00
|
|
|
}
|
|
|
|
|
|
2010-05-08 07:25:26 +00:00
|
|
|
/* this region dropbox definition */
|
2023-06-09 09:44:08 +10:00
|
|
|
static void console_dropboxes()
|
2010-05-08 07:25:26 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
ListBase *lb = WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-02-16 14:27:06 +11:00
|
|
|
WM_dropbox_add(
|
|
|
|
|
lb, "CONSOLE_OT_insert", console_drop_id_poll, console_drop_id_copy, nullptr, nullptr);
|
|
|
|
|
WM_dropbox_add(
|
|
|
|
|
lb, "CONSOLE_OT_insert", console_drop_path_poll, console_drop_path_copy, nullptr, nullptr);
|
|
|
|
|
WM_dropbox_add(lb,
|
|
|
|
|
"CONSOLE_OT_insert",
|
|
|
|
|
console_drop_string_poll,
|
|
|
|
|
console_drop_string_copy,
|
|
|
|
|
nullptr,
|
|
|
|
|
nullptr);
|
2010-05-08 07:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************* end drop *********** */
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
static void console_main_region_draw(const bContext *C, ARegion *region)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
|
|
|
|
/* draw entirely, view changes should be handled here */
|
2012-03-28 11:53:18 +00:00
|
|
|
SpaceConsole *sc = CTX_wm_space_console(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
View2D *v2d = ®ion->v2d;
|
2010-11-30 22:39:41 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (BLI_listbase_is_empty(&sc->scrollback)) {
|
2023-06-09 09:44:08 +10:00
|
|
|
WM_operator_name_call(
|
|
|
|
|
(bContext *)C, "CONSOLE_OT_banner", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-05 11:17:09 +00:00
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
/* clear and setup matrix */
|
2010-04-06 07:02:16 +00:00
|
|
|
UI_ThemeClearColor(TH_BACK);
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Works best with no view2d matrix set. */
|
2010-10-14 01:22:14 +00:00
|
|
|
UI_view2d_view_ortho(v2d);
|
2009-07-16 22:47:27 +00:00
|
|
|
|
|
|
|
|
/* data... */
|
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
console_history_verify(C); /* make sure we have some command line */
|
2020-03-06 16:56:42 +01:00
|
|
|
console_textview_main(sc, region);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* reset view matrix */
|
2009-07-16 22:47:27 +00:00
|
|
|
UI_view2d_view_restore(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* scrollers */
|
2023-06-09 09:44:08 +10:00
|
|
|
UI_view2d_scrollers_draw(v2d, nullptr);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 09:44:08 +10:00
|
|
|
static void console_operatortypes()
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2023-07-31 11:50:54 +10:00
|
|
|
/* `console_ops.cc` */
|
2009-07-16 00:50:27 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_move);
|
|
|
|
|
WM_operatortype_append(CONSOLE_OT_delete);
|
|
|
|
|
WM_operatortype_append(CONSOLE_OT_insert);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-04 07:24:19 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_indent);
|
2019-11-22 20:50:17 +11:00
|
|
|
WM_operatortype_append(CONSOLE_OT_indent_or_autocomplete);
|
2012-06-04 07:24:19 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_unindent);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* for use by python only */
|
2018-06-04 09:31:30 +02:00
|
|
|
WM_operatortype_append(CONSOLE_OT_history_append);
|
2009-07-16 00:50:27 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_scrollback_append);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-09 14:58:57 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_clear);
|
|
|
|
|
WM_operatortype_append(CONSOLE_OT_clear_line);
|
2009-07-16 00:50:27 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_history_cycle);
|
2009-07-26 04:31:46 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_copy);
|
2009-07-30 01:52:00 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_paste);
|
2009-12-27 20:22:06 +00:00
|
|
|
WM_operatortype_append(CONSOLE_OT_select_set);
|
2023-09-22 13:29:17 +10:00
|
|
|
WM_operatortype_append(CONSOLE_OT_select_all);
|
2015-03-16 16:01:32 +11:00
|
|
|
WM_operatortype_append(CONSOLE_OT_select_word);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
static void console_keymap(wmKeyConfig *keyconf)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2023-09-14 13:32:42 +10:00
|
|
|
WM_keymap_ensure(keyconf, "Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************** header region ******************/
|
|
|
|
|
|
|
|
|
|
/* add handlers, stuff you only do once or on area/region changes */
|
2023-06-09 09:44:08 +10:00
|
|
|
static void console_header_region_init(wmWindowManager * /*wm*/, ARegion *region)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_header_init(region);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
static void console_header_region_draw(const bContext *C, ARegion *region)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_header(C, region);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-19 12:59:00 +11:00
|
|
|
static void console_main_region_listener(const wmRegionListenerParams *params)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2021-01-18 17:28:47 -06:00
|
|
|
ScrArea *area = params->area;
|
|
|
|
|
ARegion *region = params->region;
|
2022-08-27 12:50:43 +10:00
|
|
|
const wmNotifier *wmn = params->notifier;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* context changes */
|
2012-03-28 11:53:18 +00:00
|
|
|
switch (wmn->category) {
|
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
|
|
|
case NC_SPACE: {
|
2015-12-18 16:02:31 +11:00
|
|
|
if (wmn->data == ND_SPACE_CONSOLE) {
|
|
|
|
|
if (wmn->action == NA_EDITED) {
|
2020-04-03 13:25:03 +02:00
|
|
|
if ((wmn->reference && area) && (wmn->reference == area->spacedata.first)) {
|
2015-12-18 16:02:31 +11:00
|
|
|
/* we've modified the geometry (font size), re-calculate rect */
|
2023-06-09 09:44:08 +10:00
|
|
|
console_textview_update_rect(static_cast<SpaceConsole *>(wmn->reference), region);
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_tag_redraw(region);
|
2015-12-18 16:02:31 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* generic redraw request */
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_tag_redraw(region);
|
2015-12-18 16:02:31 +11:00
|
|
|
}
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2015-12-18 16:02:31 +11:00
|
|
|
}
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 11:52:22 +02:00
|
|
|
static void console_blend_read_data(BlendDataReader *reader, SpaceLink *sl)
|
|
|
|
|
{
|
|
|
|
|
SpaceConsole *sconsole = (SpaceConsole *)sl;
|
|
|
|
|
|
2024-04-24 17:01:22 +02:00
|
|
|
BLO_read_struct_list(reader, ConsoleLine, &sconsole->scrollback);
|
|
|
|
|
BLO_read_struct_list(reader, ConsoleLine, &sconsole->history);
|
2022-09-28 11:52:22 +02:00
|
|
|
|
|
|
|
|
/* Comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression,
|
|
|
|
|
* from left to right. the right-most expression sets the result of the comma
|
|
|
|
|
* expression as a whole. */
|
|
|
|
|
LISTBASE_FOREACH_MUTABLE (ConsoleLine *, cl, &sconsole->history) {
|
2024-04-24 17:01:22 +02:00
|
|
|
BLO_read_char_array(reader, size_t(cl->len) + 1, &cl->line);
|
2022-09-28 11:52:22 +02:00
|
|
|
if (cl->line) {
|
|
|
|
|
/* The allocated length is not written, so reset here. */
|
|
|
|
|
cl->len_alloc = cl->len + 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_remlink(&sconsole->history, cl);
|
|
|
|
|
MEM_freeN(cl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-27 14:42:21 +10:00
|
|
|
static void console_space_blend_write(BlendWriter *writer, SpaceLink *sl)
|
2022-09-28 11:52:22 +02:00
|
|
|
{
|
|
|
|
|
SpaceConsole *con = (SpaceConsole *)sl;
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (ConsoleLine *, cl, &con->history) {
|
|
|
|
|
/* 'len_alloc' is invalid on write, set from 'len' on read */
|
|
|
|
|
BLO_write_struct(writer, ConsoleLine, cl);
|
2024-04-24 17:01:22 +02:00
|
|
|
BLO_write_char_array(writer, size_t(cl->len) + 1, cl->line);
|
2022-09-28 11:52:22 +02:00
|
|
|
}
|
|
|
|
|
BLO_write_struct(writer, SpaceConsole, sl);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-02 19:37:22 +10:00
|
|
|
void ED_spacetype_console()
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2024-02-02 20:59:20 +01:00
|
|
|
std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
|
2012-03-28 11:53:18 +00:00
|
|
|
ARegionType *art;
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2014-06-30 18:12:29 +10:00
|
|
|
st->spaceid = SPACE_CONSOLE;
|
2022-09-10 16:51:15 +10:00
|
|
|
STRNCPY(st->name, "Console");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-08-04 14:39:53 +02:00
|
|
|
st->create = console_create;
|
2012-03-28 11:53:18 +00:00
|
|
|
st->free = console_free;
|
|
|
|
|
st->init = console_init;
|
|
|
|
|
st->duplicate = console_duplicate;
|
|
|
|
|
st->operatortypes = console_operatortypes;
|
|
|
|
|
st->keymap = console_keymap;
|
|
|
|
|
st->dropboxes = console_dropboxes;
|
2022-09-28 11:52:22 +02:00
|
|
|
st->blend_read_data = console_blend_read_data;
|
2023-04-27 14:42:21 +10:00
|
|
|
st->blend_write = console_space_blend_write;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* regions: main window */
|
2023-06-09 09:44:08 +10:00
|
|
|
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype console region"));
|
2009-07-16 00:50:27 +00:00
|
|
|
art->regionid = RGN_TYPE_WINDOW;
|
2012-03-28 11:53:18 +00:00
|
|
|
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2015-11-28 17:14:45 +01:00
|
|
|
art->init = console_main_region_init;
|
|
|
|
|
art->draw = console_main_region_draw;
|
2014-06-30 18:12:29 +10:00
|
|
|
art->cursor = console_cursor;
|
2019-11-25 22:49:44 +11:00
|
|
|
art->event_cursor = true;
|
2009-12-19 22:37:51 +00:00
|
|
|
art->listener = console_main_region_listener;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
BLI_addhead(&st->regiontypes, art);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* regions: header */
|
2023-06-09 09:44:08 +10:00
|
|
|
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype console region"));
|
2015-11-28 17:14:45 +01:00
|
|
|
art->regionid = RGN_TYPE_HEADER;
|
|
|
|
|
art->prefsizey = HEADERY;
|
|
|
|
|
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-12-19 22:37:51 +00:00
|
|
|
art->init = console_header_region_init;
|
|
|
|
|
art->draw = console_header_region_draw;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-19 22:37:51 +00:00
|
|
|
BLI_addhead(&st->regiontypes, art);
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2024-02-02 20:59:20 +01:00
|
|
|
BKE_spacetype_register(std::move(st));
|
2009-07-18 16:27:25 +00:00
|
|
|
}
|