Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/space_file.c
| Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | if ((region = BKE_area_find_region_type(area, RGN_TYPE_TOOL_PROPS)) != NULL) { | ||||
| return region; | return region; | ||||
| } | } | ||||
| /* add subdiv level; after execute region */ | /* add subdiv level; after execute region */ | ||||
| region = MEM_callocN(sizeof(ARegion), "tool props for file"); | region = MEM_callocN(sizeof(ARegion), "tool props for file"); | ||||
| BLI_insertlinkafter(&area->regionbase, region_prev, region); | BLI_insertlinkafter(&area->regionbase, region_prev, region); | ||||
| region->regiontype = RGN_TYPE_TOOL_PROPS; | region->regiontype = RGN_TYPE_TOOL_PROPS; | ||||
| region->alignment = RGN_ALIGN_RIGHT; | region->alignment = RGN_ALIGN_RIGHT; | ||||
| region->flag = RGN_FLAG_HIDDEN; | |||||
| return region; | return region; | ||||
| } | } | ||||
| /* ******************** default callbacks for file space ***************** */ | /* ******************** default callbacks for file space ***************** */ | ||||
| static SpaceLink *file_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) | static SpaceLink *file_create(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | static void file_ensure_valid_region_state(bContext *C, | ||||
| FileSelectParams *params) | FileSelectParams *params) | ||||
| { | { | ||||
| ARegion *region_tools = BKE_area_find_region_type(area, RGN_TYPE_TOOLS); | ARegion *region_tools = BKE_area_find_region_type(area, RGN_TYPE_TOOLS); | ||||
| bool needs_init = false; /* To avoid multiple ED_area_init() calls. */ | bool needs_init = false; /* To avoid multiple ED_area_init() calls. */ | ||||
| BLI_assert(region_tools); | BLI_assert(region_tools); | ||||
| if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS) { | if (sfile->browse_mode == FILE_BROWSE_MODE_ASSETS) { | ||||
| ARegion *region_execute = file_execute_region_ensure(area, region_tools); | file_tool_props_region_ensure(area, region_tools); | ||||
| ARegion *region_props = file_tool_props_region_ensure(area, region_execute); | |||||
| /* Hide specific regions by default. */ | |||||
| region_props->flag |= RGN_FLAG_HIDDEN; | |||||
| region_execute->flag |= RGN_FLAG_HIDDEN; | |||||
| ARegion *region_execute = BKE_area_find_region_type(area, RGN_TYPE_EXECUTE); | |||||
| if (region_execute) { | |||||
| ED_region_remove(C, area, region_execute); | |||||
| needs_init = true; | |||||
| } | |||||
| ARegion *region_ui = BKE_area_find_region_type(area, RGN_TYPE_UI); | ARegion *region_ui = BKE_area_find_region_type(area, RGN_TYPE_UI); | ||||
| if (region_ui) { | if (region_ui) { | ||||
| ED_region_remove(C, area, region_ui); | ED_region_remove(C, area, region_ui); | ||||
| needs_init = true; | needs_init = true; | ||||
| } | } | ||||
| } | } | ||||
| /* If there's an file-operation, ensure we have the option and execute region */ | /* If there's an file-operation, ensure we have the option and execute region */ | ||||
| else if (sfile->op) { | else if (sfile->op) { | ||||
| Show All 12 Lines | static void file_ensure_valid_region_state(bContext *C, | ||||
| } | } | ||||
| /* If there's _no_ file-operation, ensure we _don't_ have the option and execute region */ | /* If there's _no_ file-operation, ensure we _don't_ have the option and execute region */ | ||||
| else { | else { | ||||
| ARegion *region_props = BKE_area_find_region_type(area, RGN_TYPE_TOOL_PROPS); | ARegion *region_props = BKE_area_find_region_type(area, RGN_TYPE_TOOL_PROPS); | ||||
| ARegion *region_execute = BKE_area_find_region_type(area, RGN_TYPE_EXECUTE); | ARegion *region_execute = BKE_area_find_region_type(area, RGN_TYPE_EXECUTE); | ||||
| ARegion *region_ui = file_ui_region_ensure(area, region_tools); | ARegion *region_ui = file_ui_region_ensure(area, region_tools); | ||||
| UNUSED_VARS(region_ui); | UNUSED_VARS(region_ui); | ||||
| if (region_execute) { | |||||
| ED_region_remove(C, area, region_execute); | |||||
| needs_init = true; | |||||
| } | |||||
| if (region_props) { | if (region_props) { | ||||
| BLI_assert(region_execute); | |||||
| ED_region_remove(C, area, region_props); | ED_region_remove(C, area, region_props); | ||||
| ED_region_remove(C, area, region_execute); | |||||
| needs_init = true; | needs_init = true; | ||||
| } | } | ||||
| } | } | ||||
| if (needs_init) { | if (needs_init) { | ||||
| ED_area_init(wm, win, area); | ED_area_init(wm, win, area); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | static void file_refresh(const bContext *C, ScrArea *area) | ||||
| /* Might be called with NULL area, see file_main_region_draw() below. */ | /* Might be called with NULL area, see file_main_region_draw() below. */ | ||||
| if (area) { | if (area) { | ||||
| file_ensure_valid_region_state((bContext *)C, wm, win, area, sfile, params); | file_ensure_valid_region_state((bContext *)C, wm, win, area, sfile, params); | ||||
| } | } | ||||
| ED_area_tag_redraw(area); | ED_area_tag_redraw(area); | ||||
| } | } | ||||
| static void file_listener(wmWindow *UNUSED(win), | static void file_listener(const wmSpaceTypeListenerParams *params) | ||||
| ScrArea *area, | |||||
| wmNotifier *wmn, | |||||
| Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ScrArea *area = params->area; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| SpaceFile *sfile = (SpaceFile *)area->spacedata.first; | SpaceFile *sfile = (SpaceFile *)area->spacedata.first; | ||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SPACE: | case NC_SPACE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_SPACE_FILE_LIST: | case ND_SPACE_FILE_LIST: | ||||
| ED_area_tag_refresh(area); | ED_area_tag_refresh(area); | ||||
| Show All 34 Lines | static void file_main_region_init(wmWindowManager *wm, ARegion *region) | ||||
| /* own keymaps */ | /* own keymaps */ | ||||
| keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0); | keymap = WM_keymap_ensure(wm->defaultconf, "File Browser", SPACE_FILE, 0); | ||||
| WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | ||||
| keymap = WM_keymap_ensure(wm->defaultconf, "File Browser Main", SPACE_FILE, 0); | keymap = WM_keymap_ensure(wm->defaultconf, "File Browser Main", SPACE_FILE, 0); | ||||
| WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | ||||
| } | } | ||||
| static void file_main_region_listener(wmWindow *UNUSED(win), | static void file_main_region_listener(const wmRegionListenerParams *params) | ||||
| ScrArea *UNUSED(area), | |||||
| ARegion *region, | |||||
| wmNotifier *wmn, | |||||
| const Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ARegion *region = params->region; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SPACE: | case NC_SPACE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_SPACE_FILE_LIST: | case ND_SPACE_FILE_LIST: | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| break; | break; | ||||
| case ND_SPACE_FILE_PARAMS: | case ND_SPACE_FILE_PARAMS: | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| break; | break; | ||||
| } | } | ||||
| break; | break; | ||||
| case NC_ID: | |||||
| if (ELEM(wmn->action, NA_RENAME)) { | |||||
| /* In case the filelist shows ID names. */ | |||||
| ED_region_tag_redraw(region); | |||||
| } | |||||
| break; | |||||
| } | } | ||||
| } | } | ||||
| static void file_main_region_message_subscribe(const struct bContext *UNUSED(C), | static void file_main_region_message_subscribe(const wmRegionMessageSubscribeParams *params) | ||||
| struct WorkSpace *UNUSED(workspace), | |||||
| struct Scene *UNUSED(scene), | |||||
| struct bScreen *screen, | |||||
| struct ScrArea *area, | |||||
| struct ARegion *region, | |||||
| struct wmMsgBus *mbus) | |||||
| { | { | ||||
| struct wmMsgBus *mbus = params->message_bus; | |||||
| bScreen *screen = params->screen; | |||||
| ScrArea *area = params->area; | |||||
| ARegion *region = params->region; | |||||
| SpaceFile *sfile = area->spacedata.first; | SpaceFile *sfile = area->spacedata.first; | ||||
| FileSelectParams *params = ED_fileselect_ensure_active_params(sfile); | |||||
| FileSelectParams *file_params = ED_fileselect_ensure_active_params(sfile); | |||||
| /* This is a bit odd that a region owns the subscriber for an area, | /* This is a bit odd that a region owns the subscriber for an area, | ||||
| * keep for now since all subscribers for WM are regions. | * keep for now since all subscribers for WM are regions. | ||||
| * May be worth re-visiting later. */ | * May be worth re-visiting later. */ | ||||
| wmMsgSubscribeValue msg_sub_value_area_tag_refresh = { | wmMsgSubscribeValue msg_sub_value_area_tag_refresh = { | ||||
| .owner = region, | .owner = region, | ||||
| .user_data = area, | .user_data = area, | ||||
| .notify = ED_area_do_msg_notify_tag_refresh, | .notify = ED_area_do_msg_notify_tag_refresh, | ||||
| }; | }; | ||||
| /* SpaceFile itself. */ | /* SpaceFile itself. */ | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| RNA_pointer_create(&screen->id, &RNA_SpaceFileBrowser, sfile, &ptr); | RNA_pointer_create(&screen->id, &RNA_SpaceFileBrowser, sfile, &ptr); | ||||
| /* All properties for this space type. */ | /* All properties for this space type. */ | ||||
| WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__); | WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__); | ||||
| } | } | ||||
| /* FileSelectParams */ | /* FileSelectParams */ | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| RNA_pointer_create(&screen->id, &RNA_FileSelectParams, params, &ptr); | RNA_pointer_create(&screen->id, &RNA_FileSelectParams, file_params, &ptr); | ||||
| /* All properties for this space type. */ | /* All properties for this space type. */ | ||||
| WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__); | WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__); | ||||
| } | } | ||||
| } | } | ||||
| static bool file_main_region_needs_refresh_before_draw(SpaceFile *sfile) | static bool file_main_region_needs_refresh_before_draw(SpaceFile *sfile) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | static void file_tools_region_init(wmWindowManager *wm, ARegion *region) | ||||
| WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | ||||
| } | } | ||||
| static void file_tools_region_draw(const bContext *C, ARegion *region) | static void file_tools_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_region_panels(C, region); | ED_region_panels(C, region); | ||||
| } | } | ||||
| static void file_tools_region_listener(wmWindow *UNUSED(win), | static void file_tools_region_listener(const wmRegionListenerParams *UNUSED(params)) | ||||
| ScrArea *UNUSED(area), | |||||
| ARegion *UNUSED(region), | |||||
| wmNotifier *UNUSED(wmn), | |||||
| const Scene *UNUSED(scene)) | |||||
| { | { | ||||
| #if 0 | } | ||||
| /* context changes */ | |||||
| static void file_tool_props_region_listener(const wmRegionListenerParams *params) | |||||
| { | |||||
| const wmNotifier *wmn = params->notifier; | |||||
| ARegion *region = params->region; | |||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| /* pass */ | case NC_ID: | ||||
| if (ELEM(wmn->action, NA_RENAME)) { | |||||
| /* In case the filelist shows ID names. */ | |||||
| ED_region_tag_redraw(region); | |||||
| } | |||||
| break; | |||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| /* add handlers, stuff you only do once or on area/region changes */ | /* add handlers, stuff you only do once or on area/region changes */ | ||||
| static void file_header_region_init(wmWindowManager *wm, ARegion *region) | static void file_header_region_init(wmWindowManager *wm, ARegion *region) | ||||
| { | { | ||||
| wmKeyMap *keymap; | wmKeyMap *keymap; | ||||
| ED_region_header_init(region); | ED_region_header_init(region); | ||||
| Show All 40 Lines | static void file_execution_region_init(wmWindowManager *wm, ARegion *region) | ||||
| WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | WM_event_add_keymap_handler_v2d_mask(®ion->handlers, keymap); | ||||
| } | } | ||||
| static void file_execution_region_draw(const bContext *C, ARegion *region) | static void file_execution_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_region_panels(C, region); | ED_region_panels(C, region); | ||||
| } | } | ||||
| static void file_ui_region_listener(wmWindow *UNUSED(win), | static void file_ui_region_listener(const wmRegionListenerParams *params) | ||||
| ScrArea *UNUSED(area), | |||||
| ARegion *region, | |||||
| wmNotifier *wmn, | |||||
| const Scene *UNUSED(scene)) | |||||
| { | { | ||||
| ARegion *region = params->region; | |||||
| wmNotifier *wmn = params->notifier; | |||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SPACE: | case NC_SPACE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_SPACE_FILE_LIST: | case ND_SPACE_FILE_LIST: | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | void ED_spacetype_file(void) | ||||
| BLI_addhead(&st->regiontypes, art); | BLI_addhead(&st->regiontypes, art); | ||||
| /* regions: tool properties */ | /* regions: tool properties */ | ||||
| art = MEM_callocN(sizeof(ARegionType), "spacetype file operator region"); | art = MEM_callocN(sizeof(ARegionType), "spacetype file operator region"); | ||||
| art->regionid = RGN_TYPE_TOOL_PROPS; | art->regionid = RGN_TYPE_TOOL_PROPS; | ||||
| art->prefsizex = 240; | art->prefsizex = 240; | ||||
| art->prefsizey = 60; | art->prefsizey = 60; | ||||
| art->keymapflag = ED_KEYMAP_UI; | art->keymapflag = ED_KEYMAP_UI; | ||||
| art->listener = file_tools_region_listener; | art->listener = file_tool_props_region_listener; | ||||
| art->init = file_tools_region_init; | art->init = file_tools_region_init; | ||||
| art->draw = file_tools_region_draw; | art->draw = file_tools_region_draw; | ||||
| BLI_addhead(&st->regiontypes, art); | BLI_addhead(&st->regiontypes, art); | ||||
| file_tool_props_region_panels_register(art); | file_tool_props_region_panels_register(art); | ||||
| BKE_spacetype_register(st); | BKE_spacetype_register(st); | ||||
| } | } | ||||
| Show All 34 Lines | |||||