Store ordered settings in AtomTouchBar

This commit is contained in:
Kevin Sawicki 2017-03-01 15:26:10 -08:00
parent 5f9e9d4b36
commit 708ed9d1cd
4 changed files with 15 additions and 18 deletions

View file

@ -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_;

View file

@ -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:

View file

@ -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;

View file

@ -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];
}