Repository: flutter
Issue: Add option to retain the default macOS menu bar search functionality for macOS apps
Labels: c: new feature,platform-mac,c: proposal,a: desktop,P2,team-macos,triaged-macos

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Use case

Flutter doesn't provide a way to keep the macOS provided functionality to search the application menu when setting up menus with `PlatformMenuBar` and `PlatformMenuDelegate` as soon as a custom menu is set the search text field is not provided any more in any of the menus.

By default macOS applications have a Help menu that includes a search text field to search for menu items. By hovering over search results the system will highlight the menu item in its original placement by opening the containing top level menu and thus greatly enhancing discoverability.

Flutter's `PlatformMenuDelegate` gives you an option to set your custom menus with `setMenus`, but it's implementation always builds the menus from scratch (caching some of the system provided items) thus the default search will be discarded.

To my knowledge there's no way to programmatically insert the macOS menu search field as an `NSMenuItem` and it's also not listed by querying the list of items in the original `NSMenu` object for the help menu.
It looks like the best strategy to keep the search functionality is _keeping_ the Help menu provided by the system and only _modifying_ them to insert and remove items.

You can see an example of how that can be done in this gist by only appending menus to the original one:
https://gist.github.com/intonarumori/bca1c47ced59e6ff1259d6f8c5ef27c6

<img width="839" alt="Screenshot 2023-08-22 at 12 59 03" src="https://github.com/flutter/flutter/assets/86030/3bfb5a58-de96-44cc-a593-15dc4dad8d01">



## Proposal

I propose to update the [platform code](https://github.com/flutter/engine/blob/0290d0bd79eef30c51494437e22624f4c3baaa0d/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm) to handle the Help menu as a special case.

### Detecting the help menu
- There are no public APIs to detect system provided menus
- In Nib files the help menu is designated with the`systemMenu="help"`:
```
<menuItem title="Help" id="wpr-3q-Mcd">
  <modifierMask key="keyEquivalentModifierMask"/>
    <menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
       <items>
         <menuItem title="MenuTests Help" keyEquivalent="?" id="FKE-Sm-Kum">
             <connections>
               <action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/>
             </connections>
         </menuItem>
       </items>
    </menu>
</menuItem>
```
- At runtime the following private properties can be inspected (probably not App Store safe):
```
let isHelp = menu.value(forKey: "_extra").value(forKey: "_name") == "_NSHelpMenu"
```
- In general we could assume that the Help menu is the last one and retain it to have an App Store compatible solution, Flutter already takes a similar assumption with the Services menu
- This only breaks if a developer manually removes the Help menu in the Flutter generated Xcode project Main nib file, in which case we could assume they are experienced enough to use `PlatformMenuDelegate` to account for those changes

### API additions

I propose adding the boolean flag to customize if the platform code retains the help menu or not:
```
// https://api.flutter.dev/flutter/widgets/PlatformMenuDelegate-class.html

abstract class PlatformMenuDelegate {
  void setHelpMenuRetained(bool retained);
}

```

Optionally add a way to customize the help menu items:
```
// https://api.flutter.dev/flutter/widgets/PlatformMenuDelegate-class.html

abstract class PlatformMenuDelegate {
  void setHelpMenuItems(List<PlatformMenuItem> helpMenuItems);
}

```

The above is just one way to approach the problem so any improvements or alternative strategies are welcome.