[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59602] branches/soc-2013-ui_replay/source /blender: Added a right click menu to the custom panel headers.
Vincent Akkermans
vincent at ack-err.net
Wed Aug 28 15:43:34 CEST 2013
Revision: 59602
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59602
Author: ack-err
Date: 2013-08-28 13:43:34 +0000 (Wed, 28 Aug 2013)
Log Message:
-----------
Added a right click menu to the custom panel headers. This can be used to rename a panel and to remove it.
Modified Paths:
--------------
branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c
branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c
Modified: branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h 2013-08-28 13:28:26 UTC (rev 59601)
+++ branches/soc-2013-ui_replay/source/blender/editors/include/UI_interface.h 2013-08-28 13:43:34 UTC (rev 59602)
@@ -686,7 +686,7 @@
void uiPanelFree(struct Panel *pa);
int uiPanelClosed(struct Panel *pa);
-struct PanelType *uiCreateCustomPanelType(struct ScrArea *sa, struct ARegion *ar, const char *context, const char *name);
+struct PanelType *uiCreateCustomPanelType(struct ScrArea *sa, struct ARegion *ar, const char *context, const char *name, const char *label);
/* Handlers
*
Modified: branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c 2013-08-28 13:28:26 UTC (rev 59601)
+++ branches/soc-2013-ui_replay/source/blender/editors/interface/interface_panel.c 2013-08-28 13:43:34 UTC (rev 59602)
@@ -933,7 +933,7 @@
* and it's the correct context. */
if (pa->type == NULL && pa->flag & PNL_CUSTOM_PANEL && strcmp(context, pa->context) == 0) {
/* recreate custom paneltypes for typeless panels */
- pt = uiCreateCustomPanelType(sa, ar, context, pa->panelname);
+ pt = uiCreateCustomPanelType(sa, ar, context, pa->panelname, pa->drawname);
pa->type = pt;
}
}
@@ -1178,6 +1178,81 @@
return block;
}
+static void rename_custom_panel(bContext *C, void *but_arg, void *pa_arg)
+{
+ uiBut *but = but_arg;
+ Panel *pa = pa_arg;
+ ARegion *ar = CTX_wm_region(C);
+
+ if (pa->type) {
+ BLI_strncpy(pa->type->label, but->drawstr, MAX_NAME);
+ BLI_strncpy(pa->drawname, but->drawstr, MAX_NAME);
+ }
+
+ ED_region_tag_redraw(ar);
+}
+
+static void delete_custom_panel(bContext *C, void *pa_arg, void *UNUSED(arg2))
+{
+ Panel *pa = pa_arg;
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
+
+ if (pa->type && ar->type)
+ BLI_freelinkN(&ar->type->paneltypes, pa->type);
+
+ BLI_remlink(&ar->panels, pa);
+ uiPanelFree(pa);
+
+ /* make sure we don't leave gaps in the layout */
+ for (pa = ar->panels.first; pa; pa = pa->next) {
+ panel_activate_state(C, pa, PANEL_STATE_ANIMATION);
+ }
+ ED_region_tag_redraw(ar);
+}
+
+static uiBlock *custom_panel_options_create_block(bContext *C, ARegion *ar, void *pa_arg)
+{
+ uiBlock *block;
+ Panel *pa = (Panel*)pa_arg; // the custom panel
+ uiLayout *layout;
+ uiBut *but;
+ PointerRNA ptr;
+
+ block = uiBeginBlock(C, ar, "panel options", UI_EMBOSS);
+
+ uiBlockClearFlag(block, UI_BLOCK_LOOP);
+ uiBlockSetFlag(block, UI_BLOCK_MOVEMOUSE_QUIT);
+
+ uiStyle *style = UI_GetStyleDraw();
+
+ int xco, yco;
+ int w = UI_PANEL_WIDTH / 2;
+ int em = UI_UNIT_Y;
+
+ layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_TOOLBAR,
+ style->panelspace, 0, w - 2 * style->panelspace, em, style);
+
+ /* Rename panel */
+ RNA_pointer_create(NULL, &RNA_Panel, pa, &ptr);
+
+ but = uiDefButR(block, TEX, 1, "", 0, 0, w, UI_UNIT_Y,
+ &ptr, "text", -1, 0, 0, -1, -1, NULL);
+ uiButSetFunc(but, rename_custom_panel, but, pa);
+
+
+ /* Delete panel button */
+ but = uiDefIconTextBut(block, BUTM, 0, ICON_NONE, IFACE_("Delete Panel"), 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
+ uiButSetFunc(but, delete_custom_panel, pa, NULL);
+
+ uiBlockLayoutResolve(block, &xco, &yco);
+
+ uiPopupBoundsBlock(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
+ uiEndBlock(C, block);
+
+ return block;
+}
+
/* this function is supposed to call general window drawing too */
/* also it supposes a block has panel, and isn't a menu */
static void ui_handle_panel_header(bContext *C, uiBlock *block, int mx, int my, int event, int ctrl)
@@ -1331,6 +1406,9 @@
retval = WM_UI_HANDLER_BREAK;
continue;
}
+ else if (event->type == RIGHTMOUSE && pa->flag & PNL_CUSTOM_PANEL) {
+ uiPupBlock(C, custom_panel_options_create_block, block->panel);
+ }
}
/* on active button, do not handle panels */
@@ -1552,12 +1630,12 @@
}
}
-PanelType *uiCreateCustomPanelType(ScrArea *sa, ARegion *ar, const char *context, const char *name)
+PanelType *uiCreateCustomPanelType(ScrArea *sa, ARegion *ar, const char *context, const char *name, const char *label)
{
PanelType *pt = MEM_callocN(sizeof(PanelType), "custom panel type");
// Create new panel type and add to the current editor's toolbar
BLI_strncpy(pt->idname, name, BKE_ST_MAXNAME);
- strcpy(pt->label, N_("Custom Panel"));
+ strcpy(pt->label, label);
strcpy(pt->translation_context, BLF_I18NCONTEXT_DEFAULT_BPYRNA);
// pt_new->draw_header = custom_panel_draw_header;
pt->draw = custom_panel_draw;
Modified: branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c 2013-08-28 13:28:26 UTC (rev 59601)
+++ branches/soc-2013-ui_replay/source/blender/windowmanager/intern/wm_operators.c 2013-08-28 13:43:34 UTC (rev 59602)
@@ -4213,24 +4213,16 @@
static int wm_create_custom_panel_poll(bContext *C)
{
+ ScrArea *sa;
+ ARegion *ar;
- if (CTX_wm_window(C) == NULL) {
+ if (CTX_wm_window(C) == NULL)
return 0;
- } else {
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar;
- if (sa) {
- // We should be in a space where there are toolbars
- //if (!ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_CLIP)) return 0;
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->type && ar->type->regionid == RGN_TYPE_TOOLS) {
- return 1;
- }
- }
- }
- }
- // If a RGN_TYPE_TOOLS wasn't found we can't create a panel for it
- return 0;
+
+ sa = CTX_wm_area(C);
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
+
+ return (ar != NULL);
}
static int wm_create_custom_panel_exec(bContext *C, wmOperator *UNUSED(op))
@@ -4242,10 +4234,7 @@
int name_taken = 1;
// find RGN_TYPE_TOOLS
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- if (ar->type && ar->type->regionid == RGN_TYPE_TOOLS)
- break;
-
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
if (ar == NULL) return OPERATOR_CANCELLED;
// find new name for paneltype
@@ -4274,7 +4263,7 @@
if (name_taken)
return OPERATOR_CANCELLED;
- uiCreateCustomPanelType(sa, ar, CTX_data_mode_string(C), name);
+ uiCreateCustomPanelType(sa, ar, CTX_data_mode_string(C), name, "Custom Panel");
MEM_freeN(name);
More information about the Bf-blender-cvs
mailing list