UI: 'View Online Manual' Shortcut
D1031, implement proposal T37478 to give easy access to the online manual. Use Alt+F1 while hovering over a button/setting.
This commit is contained in:
parent
5efbd2a407
commit
cf366c8b66
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue