From 42524915b5dfee539dea4e7033fb19db883e33c0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Sep 2013 22:55:42 +0000 Subject: fix/workaround [#36709] Renaming multiple objects in the outliner halts the interface Only show one edit button at a time (editing multiple buttons at once I never saw in other ui toolkits and its unclear what you change). --- .../blender/editors/space_outliner/outliner_draw.c | 81 +++++++++++----------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index e9a3c48d8dc..fe706ce2365 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -1045,48 +1045,37 @@ static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soo } -static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb) +static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, TreeElement *te) { uiBut *bt; - TreeElement *te; TreeStoreElem *tselem; int spx, dx, len; - - for (te = lb->first; te; te = te->next) { - tselem = TREESTORE(te); - if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) { - - if (tselem->flag & TSE_TEXTBUT) { - - /* If we add support to rename Sequence. - * need change this. - */ - // prevent crash when trying to rename 'pose' entry of armature - if (tselem->type == TSE_POSE_BASE) continue; - - if (tselem->type == TSE_EBONE) len = sizeof(((EditBone *) 0)->name); - else if (tselem->type == TSE_MODIFIER) len = sizeof(((ModifierData *) 0)->name); - else if (tselem->id && GS(tselem->id->name) == ID_LI) len = sizeof(((Library *) 0)->name); - else len = MAX_ID_NAME - 2; - - dx = (int)UI_GetStringWidth(te->name); - if (dx < 5 * UI_UNIT_X) dx = 5 * UI_UNIT_X; - spx = te->xs + 1.8f * UI_UNIT_X; - if (spx + dx + 0.5f * UI_UNIT_X > ar->v2d.cur.xmax) dx = ar->v2d.cur.xmax - spx - 0.5f * UI_UNIT_X; + tselem = TREESTORE(te); - bt = uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, te->ys, dx + UI_UNIT_X, UI_UNIT_Y - 1, (void *)te->name, - 1.0, (float)len, 0, 0, ""); - uiButSetRenameFunc(bt, namebutton_cb, tselem); - - /* returns false if button got removed */ - if (false == uiButActiveOnly(C, ar, block, bt)) { - tselem->flag &= ~TSE_TEXTBUT; - } - } - } - - if (TSELEM_OPEN(tselem, soops)) outliner_buttons(C, block, ar, soops, &te->subtree); + BLI_assert(tselem->flag & TSE_TEXTBUT); + /* If we add support to rename Sequence. + * need change this. + */ + + if (tselem->type == TSE_EBONE) len = sizeof(((EditBone *) 0)->name); + else if (tselem->type == TSE_MODIFIER) len = sizeof(((ModifierData *) 0)->name); + else if (tselem->id && GS(tselem->id->name) == ID_LI) len = sizeof(((Library *) 0)->name); + else len = MAX_ID_NAME - 2; + + spx = te->xs + 1.8f * UI_UNIT_X; + dx = ar->v2d.cur.xmax - (spx + 3.2f * UI_UNIT_X); + + bt = uiDefBut(block, TEX, OL_NAMEBUTTON, "", spx, te->ys, dx, UI_UNIT_Y - 1, (void *)te->name, + 1.0, (float)len, 0, 0, ""); + uiButSetRenameFunc(bt, namebutton_cb, tselem); + + /* returns false if button got removed */ + if (false == uiButActiveOnly(C, ar, block, bt)) { + tselem->flag &= ~TSE_TEXTBUT; + + /* bad! (notifier within draw) without this, we don't get a refesh */ + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL); } } @@ -1484,7 +1473,7 @@ static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, i static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, - TreeElement *te, int startx, int *starty) + TreeElement *te, int startx, int *starty, TreeElement **te_edit) { TreeElement *ten; TreeStoreElem *tselem; @@ -1497,6 +1486,10 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene int xmax = ar->v2d.cur.xmax; unsigned char alpha = 128; + if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) { + *te_edit = te; + } + /* icons can be ui buts, we don't want it to overlap with restrict */ if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0) xmax -= OL_TOGW + UI_UNIT_X; @@ -1677,7 +1670,7 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene *starty -= UI_UNIT_Y; for (ten = te->subtree.first; ten; ten = ten->next) - outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx + UI_UNIT_X, starty); + outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx + UI_UNIT_X, starty, te_edit); } else { for (ten = te->subtree.first; ten; ten = ten->next) @@ -1761,7 +1754,8 @@ static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, } -static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops) +static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, + SpaceOops *soops, TreeElement **te_edit) { TreeElement *te; int starty, startx; @@ -1793,7 +1787,7 @@ static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegio starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET; startx = 0; for (te = soops->tree.first; te; te = te->next) { - outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty); + outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty, te_edit); } } @@ -1863,6 +1857,7 @@ void draw_outliner(const bContext *C) SpaceOops *soops = CTX_wm_space_outliner(C); uiBlock *block; int sizey = 0, sizex = 0, sizex_rna = 0; + TreeElement *te_edit = NULL; outliner_build_tree(mainvar, scene, soops); // always @@ -1916,7 +1911,7 @@ void draw_outliner(const bContext *C) /* draw outliner stuff (background, hierachy lines and names) */ outliner_back(ar); block = uiBeginBlock(C, ar, __func__, UI_EMBOSS); - outliner_draw_tree((bContext *)C, block, scene, ar, soops); + outliner_draw_tree((bContext *)C, block, scene, ar, soops, &te_edit); if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) { /* draw rna buttons */ @@ -1933,7 +1928,9 @@ void draw_outliner(const bContext *C) } /* draw edit buttons if nessecery */ - outliner_buttons(C, block, ar, soops, &soops->tree); + if (te_edit) { + outliner_buttons(C, block, ar, te_edit); + } uiEndBlock(C, block); uiDrawBlock(C, block); -- cgit v1.2.3