Support renaming workspaces through tabs
Rename workspaces by double or ctrl clicking their tab.
This commit is contained in:
@@ -2189,12 +2189,7 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
|
||||
MEM_freeN((void *)buf);
|
||||
}
|
||||
}
|
||||
else if (but->type == UI_BTYPE_TEXT) {
|
||||
/* string */
|
||||
BLI_strncpy(str, but->poin, maxlen);
|
||||
return;
|
||||
}
|
||||
else if (but->type == UI_BTYPE_SEARCH_MENU) {
|
||||
else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) {
|
||||
/* string */
|
||||
BLI_strncpy(str, but->poin, maxlen);
|
||||
return;
|
||||
@@ -2430,7 +2425,7 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (but->type == UI_BTYPE_SEARCH_MENU) {
|
||||
else if (ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) {
|
||||
/* string */
|
||||
BLI_strncpy(but->poin, str, but->hardmax);
|
||||
return true;
|
||||
|
@@ -938,6 +938,21 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
data->applied = true;
|
||||
}
|
||||
|
||||
static void ui_apply_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
{
|
||||
if (data->str) {
|
||||
ui_apply_but_TEX(C, but, data);
|
||||
return;
|
||||
}
|
||||
|
||||
ui_but_value_set(but, but->hardmax);
|
||||
|
||||
ui_apply_but_func(C, but);
|
||||
|
||||
data->retval = but->retval;
|
||||
data->applied = true;
|
||||
}
|
||||
|
||||
static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
|
||||
{
|
||||
if (data->str) {
|
||||
@@ -2113,9 +2128,11 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
|
||||
break;
|
||||
case UI_BTYPE_ROW:
|
||||
case UI_BTYPE_LISTROW:
|
||||
case UI_BTYPE_TAB:
|
||||
ui_apply_but_ROW(C, block, but, data);
|
||||
break;
|
||||
case UI_BTYPE_TAB:
|
||||
ui_apply_but_TAB(C, but, data);
|
||||
break;
|
||||
case UI_BTYPE_SCROLL:
|
||||
case UI_BTYPE_GRIP:
|
||||
case UI_BTYPE_NUM:
|
||||
@@ -3858,13 +3875,27 @@ static int ui_do_but_KEYEVT(
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
}
|
||||
|
||||
static int ui_do_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
|
||||
static int ui_do_but_TAB(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
|
||||
{
|
||||
if (data->state == BUTTON_STATE_HIGHLIGHT) {
|
||||
if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && event->val == KM_RELEASE) {
|
||||
button_activate_state(C, but, BUTTON_STATE_EXIT);
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
if ((event->type == LEFTMOUSE) &&
|
||||
((event->val == KM_DBL_CLICK) || event->ctrl))
|
||||
{
|
||||
button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
else if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && (event->val == KM_CLICK)) {
|
||||
button_activate_state(C, but, BUTTON_STATE_EXIT);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
}
|
||||
else if (data->state == BUTTON_STATE_TEXT_EDITING) {
|
||||
ui_do_but_textedit(C, block, but, data, event);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
else if (data->state == BUTTON_STATE_TEXT_SELECTING) {
|
||||
ui_do_but_textedit_select(C, block, but, data, event);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
|
||||
return WM_UI_HANDLER_CONTINUE;
|
||||
@@ -7132,7 +7163,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
|
||||
retval = ui_do_but_HOTKEYEVT(C, but, data, event);
|
||||
break;
|
||||
case UI_BTYPE_TAB:
|
||||
retval = ui_do_but_TAB(C, but, data, event);
|
||||
retval = ui_do_but_TAB(C, block, but, data, event);
|
||||
break;
|
||||
case UI_BTYPE_BUT_TOGGLE:
|
||||
case UI_BTYPE_TOGGLE:
|
||||
|
@@ -249,6 +249,15 @@ static void id_search_call_cb(bContext *C, void *arg_template, void *item)
|
||||
}
|
||||
}
|
||||
|
||||
static void id_rename_cb(bContext *C, void *arg, char *origstr)
|
||||
{
|
||||
ID *id = arg;
|
||||
|
||||
if (origstr && !STREQ(id->name + 2, origstr)) {
|
||||
BLI_libblock_ensure_unique_name(CTX_data_main(C), id->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* ID Search browse menu, do the search */
|
||||
static void id_search_cb(const bContext *C, void *arg_template, const char *str, uiSearchItems *items)
|
||||
{
|
||||
@@ -712,8 +721,12 @@ static void template_ID_tabs(
|
||||
|
||||
but = uiDefButR_prop(
|
||||
block, UI_BTYPE_TAB, 0, id_name, 0, 0, but_width, UI_UNIT_Y,
|
||||
&template->ptr, template->prop, 0, 0.0f, 0.0f, 0.0f, 0.0f, "");
|
||||
&template->ptr, template->prop, 0, 0.0f,
|
||||
sizeof(id->name) - 2, 0.0f, 0.0f, "");
|
||||
UI_but_funcN_set(but, id_search_call_cb, MEM_dupallocN(template), id);
|
||||
but->poin = &id->name[2];
|
||||
|
||||
UI_but_func_rename_set(but, id_rename_cb, id);
|
||||
if (active_ptr.data == id) {
|
||||
UI_but_flag_enable(but, UI_SELECT);
|
||||
}
|
||||
|
Reference in New Issue
Block a user