UI: 'View Online Manual' Shortcut
authorJulian Eisel <eiseljulian@gmail.com>
Sun, 26 Apr 2015 15:17:51 +0000 (01:17 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 26 Apr 2015 15:35:24 +0000 (01:35 +1000)
D1031, implement proposal T37478 to give easy access to the online manual.

Use Alt+F1 while hovering over a button/setting.

source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_utils.c
source/blender/windowmanager/intern/wm_operators.c

index 66b946811ea5dc10fa968d3af27b88693afbdfc5..1e0cc972ef82ae04a3042660cec0d15bfda888ea 100644 (file)
@@ -483,6 +483,14 @@ bool    UI_but_active_only(const struct bContext *C, struct ARegion *ar, uiBlock
 
 void    UI_but_execute(const struct bContext *C, uiBut *but);
 
+bool UI_but_online_manual_id(
+        const uiBut *but,
+        char *r_str, size_t maxlength)
+        ATTR_WARN_UNUSED_RESULT;
+bool UI_but_online_manual_id_from_active(
+        const struct bContext *C,
+        char *r_str, size_t maxlength)
+        ATTR_WARN_UNUSED_RESULT;
 
 /* Buttons
  *
index 57a26ce62ec81efb02da894cb359d02b48faa4ef..1d71a5db3506b4a28b90b1d0f7e41e14adb2867d 100644 (file)
@@ -6253,14 +6253,9 @@ static bool ui_but_menu(bContext *C, uiBut *but)
                char buf[512];
                PointerRNA ptr_props;
 
-               if (but->rnapoin.data && but->rnaprop) {
-                       BLI_snprintf(buf, sizeof(buf), "%s.%s",
-                                    RNA_struct_identifier(but->rnapoin.type), RNA_property_identifier(but->rnaprop));
-
-                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
-                       RNA_string_set(&ptr_props, "doc_id", buf);
-                       uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
-                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
+               if (UI_but_online_manual_id(but, buf, sizeof(buf))) {
+                       uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
+                               ICON_NONE, "WM_OT_doc_view_manual_ui_context");
 
                        WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
                        RNA_string_set(&ptr_props, "doc_id", buf);
@@ -6274,30 +6269,6 @@ static bool ui_but_menu(bContext *C, uiBut *but)
                        RNA_string_set(&ptr_props, "doc_new", RNA_property_description(but->rnaprop));
 
                        uiItemFullO(layout, "WM_OT_doc_edit", "Submit Description", ICON_NONE, ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
-#endif
-               }
-               else if (but->optype) {
-                       WM_operator_py_idname(buf, but->optype->idname);
-
-
-                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
-                       RNA_string_set(&ptr_props, "doc_id", buf);
-                       uiItemFullO(layout, "WM_OT_doc_view_manual", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Manual"),
-                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
-
-                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_view");
-                       RNA_string_set(&ptr_props, "doc_id", buf);
-                       uiItemFullO(layout, "WM_OT_doc_view", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Online Python Reference"),
-                                   ICON_NONE, ptr_props.data, WM_OP_EXEC_DEFAULT, 0);
-
-                       /* XXX inactive option, not for public! */
-#if 0
-                       WM_operator_properties_create(&ptr_props, "WM_OT_doc_edit");
-                       RNA_string_set(&ptr_props, "doc_id", buf);
-                       RNA_string_set(&ptr_props, "doc_new", but->optype->description);
-
-                       uiItemFullO(layout, "WM_OT_doc_edit", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Submit Description"),
-                                   ICON_NONE, ptr_props.data, WM_OP_INVOKE_DEFAULT, 0);
 #endif
                }
        }
index 28bd637ae592c4b24e58ea335f006f92f8d0b434..14d97dd883e1afd6227330427f91d16f96599c95 100644 (file)
@@ -52,6 +52,9 @@
 #include "UI_interface.h"
 #include "UI_resources.h"
 
+#include "WM_api.h"
+#include "WM_types.h"
+
 #include "interface_intern.h"
 
 
@@ -309,6 +312,34 @@ int UI_calc_float_precision(int prec, double value)
        return prec;
 }
 
+bool UI_but_online_manual_id(const uiBut *but, char *r_str, size_t maxlength)
+{
+       if (but->rnapoin.id.data && but->rnapoin.data && but->rnaprop) {
+               BLI_snprintf(r_str, maxlength, "%s.%s", RNA_struct_identifier(but->rnapoin.type),
+                            RNA_property_identifier(but->rnaprop));
+               return true;
+       }
+       else if (but->optype) {
+               WM_operator_py_idname(r_str, but->optype->idname);
+               return true;
+       }
+
+       *r_str = '\0';
+       return false;
+}
+
+bool UI_but_online_manual_id_from_active(const struct bContext *C, char *r_str, size_t maxlength)
+{
+       uiBut *but = UI_context_active_but_get(C);
+
+       if (but) {
+               return UI_but_online_manual_id(but, r_str, maxlength);
+       }
+
+       *r_str = '\0';
+       return false;
+}
+
 
 /* -------------------------------------------------------------------- */
 /* Modal Button Store API */
index 434e47d344e29ce30977668a3189bf61b61fcd92..4913b8698c0072702f65c0df04e59083bb8c4925 100644 (file)
@@ -4833,6 +4833,38 @@ static void WM_OT_previews_ensure(wmOperatorType *ot)
        ot->exec = previews_ensure_exec;
 }
 
+static int doc_view_manual_ui_context_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       PointerRNA ptr_props;
+       char buf[512];
+       short retval = OPERATOR_CANCELLED;
+
+       if (UI_but_online_manual_id_from_active(C, buf, sizeof(buf))) {
+               WM_operator_properties_create(&ptr_props, "WM_OT_doc_view_manual");
+               RNA_string_set(&ptr_props, "doc_id", buf);
+
+               retval = WM_operator_name_call_ptr(
+                       C, WM_operatortype_find("WM_OT_doc_view_manual", false),
+                       WM_OP_EXEC_DEFAULT, &ptr_props);
+
+               WM_operator_properties_free(&ptr_props);
+       }
+
+       return retval;
+}
+
+static void WM_OT_doc_view_manual_ui_context(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "View Online Manual";
+       ot->idname = "WM_OT_doc_view_manual_ui_context";
+       ot->description = "View a context based online manual in a webbrowser";
+
+       /* callbacks */
+       ot->poll = ED_operator_regionactive;
+       ot->exec = doc_view_manual_ui_context_exec;
+}
+
 /* ******************************************************* */
 
 static void operatortype_ghash_free_cb(wmOperatorType *ot)
@@ -4929,6 +4961,7 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_console_toggle);
 #endif
        WM_operatortype_append(WM_OT_previews_ensure);
+       WM_operatortype_append(WM_OT_doc_view_manual_ui_context);
 }
 
 /* circleselect-like modal operators */
@@ -5155,6 +5188,8 @@ void wm_window_keymap(wmKeyConfig *keyconf)
        WM_keymap_verify_item(keymap, "WM_OT_window_fullscreen_toggle", F11KEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "WM_OT_quit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
 
+       WM_keymap_add_item(keymap, "WM_OT_doc_view_manual_ui_context", F1KEY, KM_PRESS, KM_ALT, 0);
+
        /* debug/testing */
        WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT | KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT | KM_CTRL, 0);