atom_touch_bar.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (c) 2017 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_UI_COCOA_ATOM_TOUCH_BAR_H_
  5. #define ATOM_BROWSER_UI_COCOA_ATOM_TOUCH_BAR_H_
  6. #import <Cocoa/Cocoa.h>
  7. #include <map>
  8. #include <string>
  9. #include <vector>
  10. #include "atom/browser/native_window.h"
  11. #include "atom/browser/ui/cocoa/touch_bar_forward_declarations.h"
  12. #include "base/mac/scoped_nsobject.h"
  13. #include "native_mate/constructor.h"
  14. #include "native_mate/persistent_dictionary.h"
  15. @interface AtomTouchBar : NSObject <NSScrubberDelegate,
  16. NSScrubberDataSource,
  17. NSScrubberFlowLayoutDelegate> {
  18. @protected
  19. std::vector<mate::PersistentDictionary> ordered_settings_;
  20. std::map<std::string, mate::PersistentDictionary> settings_;
  21. id<NSTouchBarDelegate> delegate_;
  22. atom::NativeWindow* window_;
  23. }
  24. - (id)initWithDelegate:(id<NSTouchBarDelegate>)delegate
  25. window:(atom::NativeWindow*)window
  26. settings:(const std::vector<mate::PersistentDictionary>&)settings;
  27. - (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2));
  28. - (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items
  29. API_AVAILABLE(macosx(10.12.2));
  30. - (NSMutableArray*)identifiersFromSettings:
  31. (const std::vector<mate::PersistentDictionary>&)settings;
  32. - (void)refreshTouchBarItem:(NSTouchBar*)touchBar
  33. id:(const std::string&)item_id
  34. API_AVAILABLE(macosx(10.12.2));
  35. - (void)addNonDefaultTouchBarItems:
  36. (const std::vector<mate::PersistentDictionary>&)items;
  37. - (void)setEscapeTouchBarItem:(const mate::PersistentDictionary&)item
  38. forTouchBar:(NSTouchBar*)touchBar
  39. API_AVAILABLE(macosx(10.12.2));
  40. - (NSString*)idFromIdentifier:(NSString*)identifier
  41. withPrefix:(NSString*)prefix;
  42. - (NSTouchBarItemIdentifier)identifierFromID:(const std::string&)item_id
  43. type:(const std::string&)typere;
  44. - (bool)hasItemWithID:(const std::string&)item_id;
  45. - (NSColor*)colorFromHexColorString:(const std::string&)colorString;
  46. // Selector actions
  47. - (void)buttonAction:(id)sender;
  48. - (void)colorPickerAction:(id)sender API_AVAILABLE(macosx(10.12.2));
  49. - (void)sliderAction:(id)sender API_AVAILABLE(macosx(10.12.2));
  50. // Helpers to create touch bar items
  51. - (NSTouchBarItem*)makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
  52. API_AVAILABLE(macosx(10.12.2));
  53. - (NSTouchBarItem*)makeButtonForID:(NSString*)id
  54. withIdentifier:(NSString*)identifier
  55. API_AVAILABLE(macosx(10.12.2));
  56. - (NSTouchBarItem*)makeLabelForID:(NSString*)id
  57. withIdentifier:(NSString*)identifier
  58. API_AVAILABLE(macosx(10.12.2));
  59. - (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
  60. withIdentifier:(NSString*)identifier
  61. API_AVAILABLE(macosx(10.12.2));
  62. - (NSTouchBarItem*)makeSliderForID:(NSString*)id
  63. withIdentifier:(NSString*)identifier
  64. API_AVAILABLE(macosx(10.12.2));
  65. - (NSTouchBarItem*)makePopoverForID:(NSString*)id
  66. withIdentifier:(NSString*)identifier
  67. API_AVAILABLE(macosx(10.12.2));
  68. - (NSTouchBarItem*)makeGroupForID:(NSString*)id
  69. withIdentifier:(NSString*)identifier
  70. API_AVAILABLE(macosx(10.12.2));
  71. // Helpers to update touch bar items
  72. - (void)updateButton:(NSCustomTouchBarItem*)item
  73. withSettings:(const mate::PersistentDictionary&)settings
  74. API_AVAILABLE(macosx(10.12.2));
  75. - (void)updateLabel:(NSCustomTouchBarItem*)item
  76. withSettings:(const mate::PersistentDictionary&)settings
  77. API_AVAILABLE(macosx(10.12.2));
  78. - (void)updateColorPicker:(NSColorPickerTouchBarItem*)item
  79. withSettings:(const mate::PersistentDictionary&)settings
  80. API_AVAILABLE(macosx(10.12.2));
  81. - (void)updateSlider:(NSSliderTouchBarItem*)item
  82. withSettings:(const mate::PersistentDictionary&)settings
  83. API_AVAILABLE(macosx(10.12.2));
  84. - (void)updatePopover:(NSPopoverTouchBarItem*)item
  85. withSettings:(const mate::PersistentDictionary&)settings
  86. API_AVAILABLE(macosx(10.12.2));
  87. @end
  88. #endif // ATOM_BROWSER_UI_COCOA_ATOM_TOUCH_BAR_H_