[macOS] Add support for native help menu search callbacks, integrate editor help.
This commit is contained in:
parent
e92d55bbf4
commit
deffe6a3be
10 changed files with 216 additions and 1 deletions
|
|
@ -211,6 +211,9 @@ private:
|
|||
|
||||
IOPMAssertionID screen_keep_on_assertion = kIOPMNullAssertionID;
|
||||
|
||||
Callable help_search_callback;
|
||||
Callable help_action_callback;
|
||||
|
||||
struct MenuCall {
|
||||
Variant tag;
|
||||
Callable callback;
|
||||
|
|
@ -282,6 +285,10 @@ public:
|
|||
virtual bool has_feature(Feature p_feature) const override;
|
||||
virtual String get_name() const override;
|
||||
|
||||
virtual void help_set_search_callbacks(const Callable &p_search_callback = Callable(), const Callable &p_action_callback = Callable()) override;
|
||||
Callable _help_get_search_callback() const;
|
||||
Callable _help_get_action_callback() const;
|
||||
|
||||
virtual void global_menu_set_popup_callbacks(const String &p_menu_root, const Callable &p_open_callback = Callable(), const Callable &p_close_callback = Callable()) override;
|
||||
|
||||
virtual int global_menu_add_submenu_item(const String &p_menu_root, const String &p_label, const String &p_submenu, int p_index = -1) override;
|
||||
|
|
|
|||
|
|
@ -840,6 +840,7 @@ bool DisplayServerMacOS::has_feature(Feature p_feature) const {
|
|||
case FEATURE_EXTEND_TO_TITLE:
|
||||
case FEATURE_SCREEN_CAPTURE:
|
||||
case FEATURE_STATUS_INDICATOR:
|
||||
case FEATURE_NATIVE_HELP:
|
||||
return true;
|
||||
default: {
|
||||
}
|
||||
|
|
@ -851,6 +852,19 @@ String DisplayServerMacOS::get_name() const {
|
|||
return "macOS";
|
||||
}
|
||||
|
||||
void DisplayServerMacOS::help_set_search_callbacks(const Callable &p_search_callback, const Callable &p_action_callback) {
|
||||
help_search_callback = p_search_callback;
|
||||
help_action_callback = p_action_callback;
|
||||
}
|
||||
|
||||
Callable DisplayServerMacOS::_help_get_search_callback() const {
|
||||
return help_search_callback;
|
||||
}
|
||||
|
||||
Callable DisplayServerMacOS::_help_get_action_callback() const {
|
||||
return help_action_callback;
|
||||
}
|
||||
|
||||
bool DisplayServerMacOS::_is_menu_opened(NSMenu *p_menu) const {
|
||||
if (submenu_inv.has(p_menu)) {
|
||||
const MenuData &md = submenu[submenu_inv[p_menu]];
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface GodotApplicationDelegate : NSObject
|
||||
@interface GodotApplicationDelegate : NSObject <NSUserInterfaceItemSearching, NSApplicationDelegate>
|
||||
- (void)forceUnbundledWindowActivationHackStep1;
|
||||
- (void)forceUnbundledWindowActivationHackStep2;
|
||||
- (void)forceUnbundledWindowActivationHackStep3;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,59 @@
|
|||
return YES;
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)localizedTitlesForItem:(id)item {
|
||||
NSArray *item_name = @[ item[1] ];
|
||||
return item_name;
|
||||
}
|
||||
|
||||
- (void)searchForItemsWithSearchString:(NSString *)searchString resultLimit:(NSInteger)resultLimit matchedItemHandler:(void (^)(NSArray *items))handleMatchedItems {
|
||||
NSMutableArray *found_items = [[NSMutableArray alloc] init];
|
||||
|
||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
||||
if (ds && ds->_help_get_search_callback().is_valid()) {
|
||||
Callable cb = ds->_help_get_search_callback();
|
||||
|
||||
Variant ret;
|
||||
Variant search_string = String::utf8([searchString UTF8String]);
|
||||
Variant result_limit = (uint64_t)resultLimit;
|
||||
Callable::CallError ce;
|
||||
const Variant *args[2] = { &search_string, &result_limit };
|
||||
|
||||
cb.callp(args, 2, ret, ce);
|
||||
if (ce.error != Callable::CallError::CALL_OK) {
|
||||
ERR_PRINT(vformat(RTR("Failed to execute help search callback: %s."), Variant::get_callable_error_text(cb, args, 2, ce)));
|
||||
}
|
||||
Dictionary results = ret;
|
||||
for (const Variant *E = results.next(); E; E = results.next(E)) {
|
||||
const String &key = *E;
|
||||
const String &value = results[*E];
|
||||
if (key.length() > 0 && value.length() > 0) {
|
||||
NSArray *item = @[ [NSString stringWithUTF8String:key.utf8().get_data()], [NSString stringWithUTF8String:value.utf8().get_data()] ];
|
||||
[found_items addObject:item];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleMatchedItems(found_items);
|
||||
}
|
||||
|
||||
- (void)performActionForItem:(id)item {
|
||||
DisplayServerMacOS *ds = (DisplayServerMacOS *)DisplayServer::get_singleton();
|
||||
if (ds && ds->_help_get_action_callback().is_valid()) {
|
||||
Callable cb = ds->_help_get_action_callback();
|
||||
|
||||
Variant ret;
|
||||
Variant item_string = String::utf8([item[0] UTF8String]);
|
||||
Callable::CallError ce;
|
||||
const Variant *args[1] = { &item_string };
|
||||
|
||||
cb.callp(args, 1, ret, ce);
|
||||
if (ce.error != Callable::CallError::CALL_OK) {
|
||||
ERR_PRINT(vformat(RTR("Failed to execute help action callback: %s."), Variant::get_callable_error_text(cb, args, 1, ce)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)forceUnbundledWindowActivationHackStep1 {
|
||||
// Step 1: Switch focus to macOS SystemUIServer process.
|
||||
// Required to perform step 2, TransformProcessType will fail if app is already the in focus.
|
||||
|
|
|
|||
|
|
@ -830,6 +830,7 @@ OS_MacOS::OS_MacOS() {
|
|||
id delegate = [[GodotApplicationDelegate alloc] init];
|
||||
ERR_FAIL_NULL(delegate);
|
||||
[NSApp setDelegate:delegate];
|
||||
[NSApp registerUserInterfaceItemSearchHandler:delegate];
|
||||
|
||||
pre_wait_observer = CFRunLoopObserverCreate(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, &pre_wait_observer_cb, nullptr);
|
||||
CFRunLoopAddObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue