2015-08-10 04:39:05 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_UI_ATOM_MENU_MODEL_H_
|
|
|
|
#define ATOM_BROWSER_UI_ATOM_MENU_MODEL_H_
|
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
#include <map>
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
#include "base/observer_list.h"
|
2018-10-25 06:43:50 +00:00
|
|
|
#include "base/observer_list_types.h"
|
2015-08-10 04:39:05 +00:00
|
|
|
#include "ui/base/models/simple_menu_model.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
class AtomMenuModel : public ui::SimpleMenuModel {
|
|
|
|
public:
|
|
|
|
class Delegate : public ui::SimpleMenuModel::Delegate {
|
|
|
|
public:
|
2018-04-17 23:03:51 +00:00
|
|
|
~Delegate() override {}
|
2016-07-02 02:47:40 +00:00
|
|
|
|
|
|
|
virtual bool GetAcceleratorForCommandIdWithParams(
|
|
|
|
int command_id,
|
|
|
|
bool use_default_accelerator,
|
|
|
|
ui::Accelerator* accelerator) const = 0;
|
|
|
|
|
2018-11-26 18:43:55 +00:00
|
|
|
virtual bool ShouldRegisterAcceleratorForCommandId(
|
|
|
|
int command_id) const = 0;
|
|
|
|
|
2019-02-28 17:00:54 +00:00
|
|
|
virtual bool ShouldCommandIdWorkWhenHidden(int command_id) const = 0;
|
|
|
|
|
2016-07-02 02:47:40 +00:00
|
|
|
private:
|
|
|
|
// ui::SimpleMenuModel::Delegate:
|
2018-04-18 10:09:45 +00:00
|
|
|
bool GetAcceleratorForCommandId(
|
|
|
|
int command_id,
|
|
|
|
ui::Accelerator* accelerator) const override;
|
2015-08-10 04:39:05 +00:00
|
|
|
};
|
|
|
|
|
2018-10-25 06:43:50 +00:00
|
|
|
class Observer : public base::CheckedObserver {
|
2015-08-10 04:39:05 +00:00
|
|
|
public:
|
2018-10-25 06:43:50 +00:00
|
|
|
~Observer() override {}
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2018-01-27 14:35:58 +00:00
|
|
|
// Notifies the menu will open.
|
|
|
|
virtual void OnMenuWillShow() {}
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
// Notifies the menu has been closed.
|
2018-01-27 14:35:58 +00:00
|
|
|
virtual void OnMenuWillClose() {}
|
2015-08-10 04:39:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit AtomMenuModel(Delegate* delegate);
|
2018-04-17 23:03:51 +00:00
|
|
|
~AtomMenuModel() override;
|
2015-08-10 04:39:05 +00:00
|
|
|
|
|
|
|
void AddObserver(Observer* obs) { observers_.AddObserver(obs); }
|
|
|
|
void RemoveObserver(Observer* obs) { observers_.RemoveObserver(obs); }
|
|
|
|
|
2015-09-01 11:48:11 +00:00
|
|
|
void SetRole(int index, const base::string16& role);
|
|
|
|
base::string16 GetRoleAt(int index);
|
2016-07-02 02:47:40 +00:00
|
|
|
bool GetAcceleratorAtWithParams(int index,
|
|
|
|
bool use_default_accelerator,
|
|
|
|
ui::Accelerator* accelerator) const;
|
2018-11-26 18:43:55 +00:00
|
|
|
bool ShouldRegisterAcceleratorAt(int index) const;
|
2019-02-28 17:00:54 +00:00
|
|
|
bool WorksWhenHiddenAt(int index) const;
|
2015-09-01 11:48:11 +00:00
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
// ui::SimpleMenuModel:
|
2017-01-23 08:53:53 +00:00
|
|
|
void MenuWillClose() override;
|
2018-01-27 14:35:58 +00:00
|
|
|
void MenuWillShow() override;
|
2015-08-10 04:39:05 +00:00
|
|
|
|
2016-07-06 23:04:18 +00:00
|
|
|
using SimpleMenuModel::GetSubmenuModelAt;
|
|
|
|
AtomMenuModel* GetSubmenuModelAt(int index);
|
|
|
|
|
2015-08-10 04:39:05 +00:00
|
|
|
private:
|
|
|
|
Delegate* delegate_; // weak ref.
|
|
|
|
|
2016-06-21 22:28:02 +00:00
|
|
|
std::map<int, base::string16> roles_; // command id -> role
|
2015-09-02 07:16:49 +00:00
|
|
|
base::ObserverList<Observer> observers_;
|
2015-08-10 04:39:05 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomMenuModel);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_UI_ATOM_MENU_MODEL_H_
|