diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-09-28 12:52:22 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-09-28 12:52:22 +0300 |
commit | 808b03da437043d7bb809a4d0e9e523bbfad95f9 (patch) | |
tree | 4a3ef1f74b09328b2e97bf827fa1fc700a9e2e41 /source/blender/editors/space_console | |
parent | 5270ac5ed87fb5f9b5605fdc332f16ea0f7ee59d (diff) |
Cleanup: decentralize .blend I/O for space types
This adds callbacks to `SpaceType` to make each editor responsible to
manage their own .blend I/O, and moves relevant code from `screen.c`
to the editors files.
Differential Revision: D11069
Diffstat (limited to 'source/blender/editors/space_console')
-rw-r--r-- | source/blender/editors/space_console/CMakeLists.txt | 7 | ||||
-rw-r--r-- | source/blender/editors/space_console/space_console.c | 39 |
2 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/editors/space_console/CMakeLists.txt b/source/blender/editors/space_console/CMakeLists.txt index 345ab8b0970..51523bcb383 100644 --- a/source/blender/editors/space_console/CMakeLists.txt +++ b/source/blender/editors/space_console/CMakeLists.txt @@ -5,11 +5,15 @@ set(INC ../../blenfont ../../blenkernel ../../blenlib + ../../blenloader ../../gpu ../../makesdna ../../makesrna ../../windowmanager ../../../../intern/guardedalloc + + # dna_type_offsets.h + ${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern ) set(SRC @@ -31,3 +35,6 @@ endif() blender_add_lib(bf_editor_space_console "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") + +# dna_type_offsets.h +add_dependencies(bf_editor_space_console bf_dna) diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index 8838b5d341f..0abb108d5e8 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -28,6 +28,8 @@ #include "UI_resources.h" #include "UI_view2d.h" +#include "BLO_read_write.h" + #include "console_intern.h" /* own include */ /* ******************** default callbacks for console space ***************** */ @@ -284,6 +286,41 @@ static void console_main_region_listener(const wmRegionListenerParams *params) } } +static void console_blend_read_data(BlendDataReader *reader, SpaceLink *sl) +{ + SpaceConsole *sconsole = (SpaceConsole *)sl; + + BLO_read_list(reader, &sconsole->scrollback); + BLO_read_list(reader, &sconsole->history); + + /* 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) { + BLO_read_data_address(reader, &cl->line); + 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); + } + } +} + +static void console_blend_write(BlendWriter *writer, SpaceLink *sl) +{ + 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); + BLO_write_raw(writer, (size_t)cl->len + 1, cl->line); + } + BLO_write_struct(writer, SpaceConsole, sl); +} + void ED_spacetype_console(void) { SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype console"); @@ -299,6 +336,8 @@ void ED_spacetype_console(void) st->operatortypes = console_operatortypes; st->keymap = console_keymap; st->dropboxes = console_dropboxes; + st->blend_read_data = console_blend_read_data; + st->blend_write = console_blend_write; /* regions: main window */ art = MEM_callocN(sizeof(ARegionType), "spacetype console region"); |