Browse Source

Store ordered settings in AtomTouchBar

Kevin Sawicki 8 years ago
parent
commit
708ed9d1cd

+ 0 - 3
atom/browser/native_window_mac.h

@@ -103,7 +103,6 @@ class NativeWindowMac : public NativeWindow,
   void SetTouchBar(
       const std::vector<mate::PersistentDictionary>& items) override;
   void RefreshTouchBarItem(const std::string& item_id) override;
-  std::vector<mate::PersistentDictionary> GetTouchBarItems();
 
   // content::RenderWidgetHost::InputEventObserver:
   void OnInputEvent(const blink::WebInputEvent& event) override;
@@ -158,8 +157,6 @@ class NativeWindowMac : public NativeWindow,
   base::scoped_nsobject<AtomNSWindow> window_;
   base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
 
-  std::vector<mate::PersistentDictionary> touch_bar_items_;
-
   // Event monitor for scroll wheel event.
   id wheel_event_monitor_;
 

+ 7 - 10
atom/browser/native_window_mac.mm

@@ -353,7 +353,7 @@ bool ScopedDisableResize::disable_resize_ = false;
 - (void)setShell:(atom::NativeWindowMac*)shell;
 - (void)setEnableLargerThanScreen:(bool)enable;
 - (void)enableWindowButtonsOffset;
-- (void)resetTouchBar;
+- (void)resetTouchBar:(const std::vector<mate::PersistentDictionary>&)settings;
 - (void)refreshTouchBarItem:(const std::string&)item_id;
 
 @end
@@ -368,7 +368,10 @@ bool ScopedDisableResize::disable_resize_ = false;
   enable_larger_than_screen_ = enable;
 }
 
-- (void)resetTouchBar {
+- (void)resetTouchBar:(const std::vector<mate::PersistentDictionary>&)settings {
+  atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self
+                                                        window:shell_
+                                                      settings:settings]);
   self.touchBar = nil;
 }
 
@@ -377,8 +380,7 @@ bool ScopedDisableResize::disable_resize_ = false;
 }
 
 - (NSTouchBar*)makeTouchBar {
-  atom_touch_bar_.reset([[AtomTouchBar alloc] initWithDelegate:self window:shell_]);
-  return [atom_touch_bar_ makeTouchBarFromSettings:shell_->GetTouchBarItems()];
+  return [atom_touch_bar_ makeTouchBar];
 }
 
 - (nullable NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
@@ -1374,18 +1376,13 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
 
 void NativeWindowMac::SetTouchBar(
     const std::vector<mate::PersistentDictionary>& items) {
-  touch_bar_items_ = items;
-  [window_ resetTouchBar];
+  [window_ resetTouchBar:items];
 }
 
 void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
   [window_ refreshTouchBarItem:item_id];
 }
 
-std::vector<mate::PersistentDictionary> NativeWindowMac::GetTouchBarItems() {
-  return touch_bar_items_;
-}
-
 void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
   switch (event.type) {
     case blink::WebInputEvent::GestureScrollBegin:

+ 3 - 2
atom/browser/ui/cocoa/atom_touch_bar.h

@@ -19,15 +19,16 @@
 
 @interface AtomTouchBar : NSObject {
  @protected
+  std::vector<mate::PersistentDictionary> ordered_settings_;
   std::map<std::string, mate::PersistentDictionary> settings_;
   std::map<std::string, base::scoped_nsobject<NSTouchBarItem>> items_;
   id<NSTouchBarDelegate> delegate_;
   atom::NativeWindow* window_;
 }
 
-- (id)initWithDelegate:(id<NSTouchBarDelegate>)delegate window:(atom::NativeWindow*)window;
+- (id)initWithDelegate:(id<NSTouchBarDelegate>)delegate window:(atom::NativeWindow*)window settings:(const std::vector<mate::PersistentDictionary>&)settings;
 
-- (NSTouchBar*)makeTouchBarFromSettings:(const std::vector<mate::PersistentDictionary>&)settings;
+- (NSTouchBar*)makeTouchBar;
 - (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items;
 - (NSMutableArray*)identifiersFromSettings:(const std::vector<mate::PersistentDictionary>&)settings;
 - (void)refreshTouchBarItem:(const std::string&)item_id;

+ 5 - 3
atom/browser/ui/cocoa/atom_touch_bar.mm

@@ -20,16 +20,18 @@ static NSTouchBarItemIdentifier PopOverIdentifier = @"com.electron.touchbar.popo
 static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slider.";
 
 - (id)initWithDelegate:(id<NSTouchBarDelegate>)delegate
-                window:(atom::NativeWindow*)window {
+                window:(atom::NativeWindow*)window
+              settings:(const std::vector<mate::PersistentDictionary>&)settings {
   if ((self = [super init])) {
     delegate_ = delegate;
     window_ = window;
+    ordered_settings_ = settings;
   }
   return self;
 }
 
-- (NSTouchBar*)makeTouchBarFromSettings:(const std::vector<mate::PersistentDictionary>&)settings {
-  NSMutableArray* identifiers = [self identifiersFromSettings:settings];
+- (NSTouchBar*)makeTouchBar {
+  NSMutableArray* identifiers = [self identifiersFromSettings:ordered_settings_];
   return [self touchBarFromItemIdentifiers:identifiers];
 }