[Bf-blender-cvs] [8d65895af8f] master: UI: Get rid of redundant UI_BUT_IMMEDIATE button flag

Julian Eisel noreply at git.blender.org
Fri May 20 16:39:52 CEST 2022


Commit: 8d65895af8f10395dccf305579210c7dae285999
Author: Julian Eisel
Date:   Fri May 20 16:27:08 2022 +0200
Branches: master
https://developer.blender.org/rB8d65895af8f10395dccf305579210c7dae285999

UI: Get rid of redundant UI_BUT_IMMEDIATE button flag

This flag was used to activate the hotkey input buttons (e.g. for
"Assign Shortcut") when opened in a popup. Since this was added, other
more generalized ways of getting this same behavior were implemented.
Had to tweak the hotkey button event handling a bit, but it seems to
behave exactly as before now.

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_widgets.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index cc08525c6da..0e9b191a780 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -202,7 +202,7 @@ enum {
   UI_BUT_INACTIVE = 1 << 18,
   UI_BUT_LAST_ACTIVE = 1 << 19,
   UI_BUT_UNDO = 1 << 20,
-  UI_BUT_IMMEDIATE = 1 << 21,
+  /* UNUSED = 1 << 21, */
   UI_BUT_NO_UTF8 = 1 << 22,
 
   /** For popups, pressing return activates this button, overriding the highlighted button.
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 3d347fab89c..bf2d7956990 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4511,7 +4511,8 @@ static int ui_do_but_HOTKEYEVT(bContext *C,
   BLI_assert(but->type == UI_BTYPE_HOTKEY_EVENT);
 
   if (data->state == BUTTON_STATE_HIGHLIGHT) {
-    if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY) && event->val == KM_PRESS) {
+    if (ELEM(event->type, LEFTMOUSE, EVT_PADENTER, EVT_RETKEY, EVT_BUT_OPEN) &&
+        (event->val == KM_PRESS)) {
       but->drawstr[0] = 0;
       hotkey_but->modifier_key = 0;
       button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT);
@@ -4534,13 +4535,9 @@ static int ui_do_but_HOTKEYEVT(bContext *C,
     if (event->type == LEFTMOUSE && event->val == KM_PRESS) {
       /* only cancel if click outside the button */
       if (ui_but_contains_point_px(but, but->active->region, event->xy) == false) {
-        /* data->cancel doesn't work, this button opens immediate */
-        if (but->flag & UI_BUT_IMMEDIATE) {
-          ui_but_value_set(but, 0);
-        }
-        else {
-          data->cancel = true;
-        }
+        data->cancel = true;
+        /* Close the containing popup (if any). */
+        data->escapecancel = true;
         button_activate_state(C, but, BUTTON_STATE_EXIT);
         return WM_UI_HANDLER_BREAK;
       }
@@ -8501,14 +8498,6 @@ static void button_activate_init(bContext *C,
   }
   button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT);
 
-  /* activate right away */
-  if (but->flag & UI_BUT_IMMEDIATE) {
-    if (but->type == UI_BTYPE_HOTKEY_EVENT) {
-      button_activate_state(C, but, BUTTON_STATE_WAIT_KEY_EVENT);
-    }
-    /* .. more to be added here */
-  }
-
   if (type == BUTTON_ACTIVATE_OPEN) {
     button_activate_state(C, but, BUTTON_STATE_MENU_OPEN);
 
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 98f3b974d1d..933d7efb4d6 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -1107,7 +1107,7 @@ static uiBut *ui_item_with_label(uiLayout *layout,
                          NULL);
     UI_but_func_set(but, ui_keymap_but_cb, but, NULL);
     if (flag & UI_ITEM_R_IMMEDIATE) {
-      UI_but_flag_enable(but, UI_BUT_IMMEDIATE);
+      UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
     }
   }
   else {
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 98ecf91adbc..25f24bef903 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -115,7 +115,7 @@ enum {
   UI_STATE_TEXT_INPUT = UI_BUT_UNDO,
   UI_STATE_ACTIVE_LEFT = UI_BUT_VALUE_CLEAR,
   UI_STATE_ACTIVE_RIGHT = UI_BUT_TEXTEDIT_UPDATE,
-  UI_STATE_TEXT_BEFORE_WIDGET = UI_BUT_IMMEDIATE,
+  UI_STATE_TEXT_BEFORE_WIDGET = UI_BUT_ACTIVATE_ON_INIT,
 
   UI_STATE_FLAGS_ALL = (UI_STATE_HOLD_ACTION | UI_STATE_TEXT_INPUT | UI_STATE_ACTIVE_LEFT |
                         UI_STATE_ACTIVE_RIGHT | UI_STATE_TEXT_BEFORE_WIDGET),



More information about the Bf-blender-cvs mailing list