fix: Menu accelerators not working Unity (#15181)
This commit is contained in:
parent
7283b78aa2
commit
5cb50b0e33
3 changed files with 18 additions and 11 deletions
|
@ -873,14 +873,17 @@ void NativeWindowViews::SetFocusable(bool focusable) {
|
|||
|
||||
void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
||||
#if defined(USE_X11)
|
||||
if (menu_model == nullptr)
|
||||
if (menu_model == nullptr) {
|
||||
global_menu_bar_.reset();
|
||||
root_view_->UnregisterAcceleratorsWithFocusManager();
|
||||
}
|
||||
|
||||
if (!global_menu_bar_ && ShouldUseGlobalMenuBar())
|
||||
global_menu_bar_.reset(new GlobalMenuBarX11(this));
|
||||
|
||||
// Use global application menu bar when possible.
|
||||
if (global_menu_bar_ && global_menu_bar_->IsServerStarted()) {
|
||||
root_view_->RegisterAcceleratorsWithFocusManager(menu_model);
|
||||
global_menu_bar_->SetMenu(menu_model);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -44,15 +44,14 @@ RootView::~RootView() {}
|
|||
void RootView::SetMenu(AtomMenuModel* menu_model) {
|
||||
if (menu_model == nullptr) {
|
||||
// Remove accelerators
|
||||
accelerator_table_.clear();
|
||||
GetFocusManager()->UnregisterAccelerators(this);
|
||||
UnregisterAcceleratorsWithFocusManager();
|
||||
// and menu bar.
|
||||
SetMenuBarVisibility(false);
|
||||
menu_bar_.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterAccelerators(menu_model);
|
||||
RegisterAcceleratorsWithFocusManager(menu_model);
|
||||
|
||||
// Do not show menu bar in frameless window.
|
||||
if (!window_->has_frame())
|
||||
|
@ -178,12 +177,11 @@ bool RootView::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
|||
accelerator);
|
||||
}
|
||||
|
||||
void RootView::RegisterAccelerators(AtomMenuModel* menu_model) {
|
||||
void RootView::RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model) {
|
||||
// Clear previous accelerators.
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
accelerator_table_.clear();
|
||||
focus_manager->UnregisterAccelerators(this);
|
||||
UnregisterAcceleratorsWithFocusManager();
|
||||
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
// Register accelerators with focus manager.
|
||||
accelerator_util::GenerateAcceleratorTable(&accelerator_table_, menu_model);
|
||||
for (const auto& iter : accelerator_table_) {
|
||||
|
@ -192,4 +190,10 @@ void RootView::RegisterAccelerators(AtomMenuModel* menu_model) {
|
|||
}
|
||||
}
|
||||
|
||||
void RootView::UnregisterAcceleratorsWithFocusManager() {
|
||||
views::FocusManager* focus_manager = GetFocusManager();
|
||||
accelerator_table_.clear();
|
||||
focus_manager->UnregisterAccelerators(this);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -34,6 +34,9 @@ class RootView : public views::View {
|
|||
bool IsMenuBarVisible() const;
|
||||
void HandleKeyEvent(const content::NativeWebKeyboardEvent& event);
|
||||
void ResetAltState();
|
||||
// Register/Unregister accelerators supported by the menu model.
|
||||
void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model);
|
||||
void UnregisterAcceleratorsWithFocusManager();
|
||||
|
||||
// views::View:
|
||||
void Layout() override;
|
||||
|
@ -42,9 +45,6 @@ class RootView : public views::View {
|
|||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||
|
||||
private:
|
||||
// Register accelerators supported by the menu model.
|
||||
void RegisterAccelerators(AtomMenuModel* menu_model);
|
||||
|
||||
// Parent window, weak ref.
|
||||
NativeWindow* window_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue