atom_menu_controller.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  3. // Use of this source code is governed by the MIT license that can be
  4. // found in the LICENSE file.
  5. #ifndef ATOM_BROWSER_UI_COCOA_ATOM_MENU_CONTROLLER_H_
  6. #define ATOM_BROWSER_UI_COCOA_ATOM_MENU_CONTROLLER_H_
  7. #import <Cocoa/Cocoa.h>
  8. #include "base/callback.h"
  9. #include "base/mac/scoped_nsobject.h"
  10. #include "base/strings/string16.h"
  11. namespace atom {
  12. class AtomMenuModel;
  13. }
  14. // A controller for the cross-platform menu model. The menu that's created
  15. // has the tag and represented object set for each menu item. The object is a
  16. // NSValue holding a pointer to the model for that level of the menu (to
  17. // allow for hierarchical menus). The tag is the index into that model for
  18. // that particular item. It is important that the model outlives this object
  19. // as it only maintains weak references.
  20. @interface AtomMenuController : NSObject <NSMenuDelegate> {
  21. @protected
  22. atom::AtomMenuModel* model_; // weak
  23. base::scoped_nsobject<NSMenu> menu_;
  24. BOOL isMenuOpen_;
  25. BOOL useDefaultAccelerator_;
  26. base::Callback<void()> closeCallback;
  27. }
  28. @property(nonatomic, assign) atom::AtomMenuModel* model;
  29. // Builds a NSMenu from the pre-built model (must not be nil). Changes made
  30. // to the contents of the model after calling this will not be noticed.
  31. - (id)initWithModel:(atom::AtomMenuModel*)model useDefaultAccelerator:(BOOL)use;
  32. - (void)setCloseCallback:(const base::Callback<void()>&)callback;
  33. // Populate current NSMenu with |model|.
  34. - (void)populateWithModel:(atom::AtomMenuModel*)model;
  35. // Programmatically close the constructed menu.
  36. - (void)cancel;
  37. // Access to the constructed menu if the complex initializer was used. If the
  38. // default initializer was used, then this will create the menu on first call.
  39. - (NSMenu*)menu;
  40. // Whether the menu is currently open.
  41. - (BOOL)isMenuOpen;
  42. // NSMenuDelegate methods this class implements. Subclasses should call super
  43. // if extending the behavior.
  44. - (void)menuWillOpen:(NSMenu*)menu;
  45. - (void)menuDidClose:(NSMenu*)menu;
  46. @end
  47. #endif // ATOM_BROWSER_UI_COCOA_ATOM_MENU_CONTROLLER_H_