Browse Source

Merge pull request #9028 from electron/fix-popover-items-not-updating

Fix popover items not updating
Kevin Sawicki 8 years ago
parent
commit
7574c33ef1
2 changed files with 38 additions and 12 deletions
  1. 34 12
      atom/browser/ui/cocoa/atom_touch_bar.mm
  2. 4 0
      lib/browser/api/touch-bar.js

+ 34 - 12
atom/browser/ui/cocoa/atom_touch_bar.mm

@@ -113,19 +113,10 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
   return nil;
 }
 
-
 - (void)refreshTouchBarItem:(NSTouchBar*)touchBar
-                         id:(const std::string&)item_id {
-  if (![self hasItemWithID:item_id]) return;
-
-  mate::PersistentDictionary settings = settings_[item_id];
-  std::string item_type;
-  settings.Get("type", &item_type);
-
-  NSTouchBarItemIdentifier identifier = [self identifierFromID:item_id
-                                                          type:item_type];
-  if (!identifier) return;
-
+                         id:(NSTouchBarItemIdentifier)identifier
+                   withType:(const std::string&)item_type
+               withSettings:(const mate::PersistentDictionary&)settings {
   NSTouchBarItem* item = [touchBar itemForIdentifier:identifier];
   if (!item) return;
 
@@ -166,6 +157,37 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
   }
 }
 
+- (void)refreshTouchBarItem:(NSTouchBar*)touchBar
+                         id:(const std::string&)item_id {
+  if (![self hasItemWithID:item_id]) return;
+
+  mate::PersistentDictionary settings = settings_[item_id];
+  std::string item_type;
+  settings.Get("type", &item_type);
+
+  auto identifier = [self identifierFromID:item_id type:item_type];
+  if (!identifier) return;
+
+  std::vector<std::string> popover_ids;
+  settings.Get("_popover", &popover_ids);
+  for (auto& popover_id : popover_ids) {
+    auto popoverIdentifier = [self identifierFromID:popover_id type:"popover"];
+    if (!popoverIdentifier) continue;
+
+    NSPopoverTouchBarItem* popoverItem =
+        [touchBar itemForIdentifier:popoverIdentifier];
+    [self refreshTouchBarItem:popoverItem.popoverTouchBar
+                           id:identifier
+                     withType:item_type
+                 withSettings:settings];
+  }
+
+  [self refreshTouchBarItem:touchBar
+                         id:identifier
+                   withType:item_type
+               withSettings:settings];
+}
+
 - (void)buttonAction:(id)sender {
   NSString* item_id = [NSString stringWithFormat:@"%ld", ((NSButton*)sender).tag];
   window_->NotifyTouchBarItemInteraction([item_id UTF8String],

+ 4 - 0
lib/browser/api/touch-bar.js

@@ -223,6 +223,10 @@ TouchBar.TouchBarPopover = class TouchBarPopover extends TouchBarItem {
     if (!(this.child instanceof TouchBar)) {
       this.child = new TouchBar(this.child)
     }
+    this.child.ordereredItems.forEach((item) => {
+      item._popover = item._popover || []
+      if (!item._popover.includes(this.id)) item._popover.push(this.id)
+    })
   }
 }