Commit: 1c683de82be3cdf6b899b3f41a1051c3dbc337f1 Author: Lukas Tönne Date: Fri May 30 10:28:36 2014 +0200 https://developer.blender.org/rB1c683de82be3cdf6b899b3f41a1051c3dbc337f1
Added a toolbar to the info space. This allows showing a mode switch button without having to put this into the main menu bar. =================================================================== M release/scripts/startup/bl_ui/space_info.py M source/blender/editors/space_info/CMakeLists.txt M source/blender/editors/space_info/info_intern.h A source/blender/editors/space_info/info_toolbar.c M source/blender/editors/space_info/space_info.c =================================================================== diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py index 3188167..de00631 100644 --- a/release/scripts/startup/bl_ui/space_info.py +++ b/release/scripts/startup/bl_ui/space_info.py @@ -18,7 +18,7 @@ # <pep8 compliant> import bpy -from bpy.types import Header, Menu +from bpy.types import Header, Menu, Panel class INFO_HT_header(Header): @@ -299,5 +299,18 @@ class INFO_MT_help(Menu): layout.operator("wm.splash", icon='BLENDER') +class INFO_PT_tools(Panel): + bl_space_type = 'INFO' + bl_region_type = 'TOOLS' + bl_label = "Tools" + bl_options = {'HIDE_HEADER'} + + def draw(self, context): + layout = self.layout + info = context.space_data + + col = layout.column() + col.prop(info, "mode") + if __name__ == "__main__": # only for live edit. bpy.utils.register_module(__name__) diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt index 47092ca..f129c2a 100644 --- a/source/blender/editors/space_info/CMakeLists.txt +++ b/source/blender/editors/space_info/CMakeLists.txt @@ -42,6 +42,7 @@ set(SRC info_stats.c info_draw.c info_report.c + info_toolbar.c textview.c depsgraphview.c space_info.c diff --git a/source/blender/editors/space_info/info_intern.h b/source/blender/editors/space_info/info_intern.h index 52285d1..ed1a2e2 100644 --- a/source/blender/editors/space_info/info_intern.h +++ b/source/blender/editors/space_info/info_intern.h @@ -34,6 +34,9 @@ /* internal exports only */ struct bContext; +struct ARegion; +struct ARegionType; +struct ScrArea; struct SpaceInfo; struct wmOperatorType; struct ReportList; @@ -69,4 +72,11 @@ void INFO_OT_report_replay(struct wmOperatorType *ot); void INFO_OT_report_delete(struct wmOperatorType *ot); void INFO_OT_report_copy(struct wmOperatorType *ot); +/* info_toolbar.c */ +void info_toolbar_register(struct ARegionType *art); +void INFO_OT_toolbar(struct wmOperatorType *ot); + +/* space_info.c */ +struct ARegion *info_has_tools_region(struct ScrArea *sa); + #endif /* __INFO_INTERN_H__ */ diff --git a/source/blender/editors/space_info/info_toolbar.c b/source/blender/editors/space_info/info_toolbar.c new file mode 100644 index 0000000..edb86f6 --- /dev/null +++ b/source/blender/editors/space_info/info_toolbar.c @@ -0,0 +1,85 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Lukas Toenne + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_node/info_toolbar.c + * \ingroup spinfo + */ + + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" + +#include "DNA_listBase.h" + +#include "BKE_context.h" +#include "BKE_screen.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_screen.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "info_intern.h" /* own include */ + + +/* ******************* toolbar registration ************** */ + +void info_toolbar_register(ARegionType *UNUSED(art)) +{ +} + +/* ********** operator to open/close toolshelf region */ + +static int info_toolbar_toggle_exec(bContext *C, wmOperator *UNUSED(op)) +{ + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = info_has_tools_region(sa); + + if (ar) + ED_region_toggle_hidden(C, ar); + + return OPERATOR_FINISHED; +} + +/* non-standard poll operator which doesn't care if there are any nodes */ +static int info_toolbar_poll(bContext *C) +{ + ScrArea *sa = CTX_wm_area(C); + return (sa && (sa->spacetype == SPACE_INFO)); +} + +void INFO_OT_toolbar(wmOperatorType *ot) +{ + ot->name = "Tool Shelf"; + ot->description = "Toggles tool shelf display"; + ot->idname = "INFO_OT_toolbar"; + + ot->exec = info_toolbar_toggle_exec; + ot->poll = info_toolbar_poll; + + /* flags */ + ot->flag = 0; +} diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index 6600507..45f36d5 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -58,6 +58,32 @@ #include "info_intern.h" /* own include */ #include "BLO_readfile.h" +/* ******************** manage regions ********************* */ + +ARegion *info_has_tools_region(ScrArea *sa) +{ + ARegion *ar, *arnew; + + ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); + if (ar) return ar; + + /* add subdiv level; after header */ + ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER); + + /* is error! */ + if (ar == NULL) return NULL; + + arnew = MEM_callocN(sizeof(ARegion), "info tools"); + + BLI_insertlinkafter(&sa->regionbase, ar, arnew); + arnew->regiontype = RGN_TYPE_TOOLS; + arnew->alignment = RGN_ALIGN_LEFT; + + arnew->flag = RGN_FLAG_HIDDEN; + + return arnew; +} + /* ******************** default callbacks for info space ***************** */ static SpaceLink *info_new(const bContext *UNUSED(C)) @@ -82,7 +108,16 @@ static SpaceLink *info_new(const bContext *UNUSED(C)) BLI_addtail(&sinfo->regionbase, ar); ar->regiontype = RGN_TYPE_WINDOW; + + /* toolbar */ + ar = MEM_callocN(sizeof(ARegion), "tools for info"); + BLI_addtail(&sinfo->regionbase, ar); + ar->regiontype = RGN_TYPE_TOOLS; + ar->alignment = RGN_ALIGN_LEFT; + + ar->flag = RGN_FLAG_HIDDEN; + /* keep in sync with console */ ar->v2d.scroll |= (V2D_SCROLL_RIGHT); ar->v2d.align |= V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y; /* align bottom left */ @@ -133,6 +168,9 @@ static void info_main_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); /* own keymap */ + keymap = WM_keymap_find(wm->defaultconf, "Info Generic", SPACE_INFO, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); + keymap = WM_keymap_find(wm->defaultconf, "Info", SPACE_INFO, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); } @@ -206,6 +244,9 @@ static void info_operatortypes(void) WM_operatortype_append(INFO_OT_report_replay); WM_operatortype_append(INFO_OT_report_delete); WM_operatortype_append(INFO_OT_report_copy); + + /* info_toolbar.c */ + WM_operatortype_append(INFO_OT_toolbar); } static void info_keymap(struct wmKeyConfig *keyconf) @@ -214,10 +255,15 @@ static void info_keymap(struct wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "INFO_OT_reports_display_update", TIMERREPORT, KM_ANY, KM_ANY, 0); + /* Entire Editor only ----------------- */ + keymap = WM_keymap_find(keyconf, "Info Generic", SPACE_INFO, 0); + + WM_keymap_add_item(keymap, "INFO_OT_toolbar", TKEY, KM_PRESS, 0, 0); + + /* info space */ keymap = WM_keymap_find(keyconf, "Info", SPACE_INFO, 0); - - + /* report selection */ WM_keymap_add_item(keymap, "INFO_OT_select_pick", SELECTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "INFO_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); @@ -286,6 +332,34 @@ static void info_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegi } +static void info_toolbar_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +{ + /* context changes */ + switch (wmn->category) { + case NC_SPACE: + if (wmn->data == ND_SPACE_INFO) + ED_region_tag_redraw(ar); + break; + } +} + + +/* add handlers, stuff you only do once or on area/region changes */ +static void info_toolbar_area_init(wmWindowManager *wm, ARegion *ar) +{ + wmKeyMap *keymap; + + ED_region_panels_init(wm, ar); + + keymap = WM_keymap_find(wm->defaultconf, "Info Generic", SPACE_NODE, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); +} + +static void info_toolbar_area_draw(const bContext *C, ARegion *ar) +{ + ED_region_panels(C, ar, 1, NULL, -1); +} + static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu) { struct RecentFile *recent; @@ -337,7 +411,7 @@ void ED_spacetype_info(void) /* regions: main window */ art = MEM_callocN(sizeof(ARegionType), "spacetype info region"); art->regionid = RGN_TYPE_WINDOW; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES; art->init = info_main_area_init; art->draw = info_main_area_draw; @@ -358,6 +432,20 @@ void ED_spacetype_info(void) BLI_addhead(&st->regiontypes, art); recent_files_menu_register(); + + /* regions: toolbar */ + art = MEM_callocN(sizeof(ARegionType), "spacetype info tools region"); + art->regionid = RGN_TYPE_TOOLS; + art->prefsizex = 160; + art->prefsizey = 50; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + art->listener = info_toolbar_listener; + art->init = info_toolbar_area_init; + art->draw = info_toolbar_area_draw; + + BLI_addhead(&st->regiontypes, art); + + info_toolbar_register(art); BKE_spacetype_register(st); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs