2017-02-28 20:29:23 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_TOUCH_BAR_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_TOUCH_BAR_H_
|
2017-02-28 20:29:23 +00:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-06-13 18:45:48 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_helper/persistent_dictionary.h"
|
2017-02-28 20:29:23 +00:00
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
@interface ElectronTouchBar : NSObject <NSScrubberDelegate,
|
|
|
|
NSScrubberDataSource,
|
|
|
|
NSScrubberFlowLayoutDelegate> {
|
2017-02-28 20:29:23 +00:00
|
|
|
@protected
|
2019-10-31 07:56:00 +00:00
|
|
|
std::vector<gin_helper::PersistentDictionary> ordered_settings_;
|
|
|
|
std::map<std::string, gin_helper::PersistentDictionary> settings_;
|
2017-02-28 20:29:23 +00:00
|
|
|
id<NSTouchBarDelegate> delegate_;
|
2023-06-13 18:45:48 +00:00
|
|
|
raw_ptr<electron::NativeWindow> window_;
|
2017-02-28 20:29:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
- (id)initWithDelegate:(id<NSTouchBarDelegate>)delegate
|
|
|
|
window:(electron::NativeWindow*)window
|
2019-10-31 07:56:00 +00:00
|
|
|
settings:(std::vector<gin_helper::PersistentDictionary>)settings;
|
2017-02-28 20:29:23 +00:00
|
|
|
|
2022-06-02 18:43:40 +00:00
|
|
|
- (NSTouchBar*)makeTouchBar;
|
|
|
|
- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSMutableArray*)identifiersFromSettings:
|
2019-10-31 07:56:00 +00:00
|
|
|
(const std::vector<gin_helper::PersistentDictionary>&)settings;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)refreshTouchBarItem:(NSTouchBar*)touchBar
|
2022-06-02 18:43:40 +00:00
|
|
|
id:(const std::string&)item_id;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)addNonDefaultTouchBarItems:
|
2019-10-31 07:56:00 +00:00
|
|
|
(const std::vector<gin_helper::PersistentDictionary>&)items;
|
|
|
|
- (void)setEscapeTouchBarItem:(gin_helper::PersistentDictionary)item
|
2022-06-02 18:43:40 +00:00
|
|
|
forTouchBar:(NSTouchBar*)touchBar;
|
2017-03-02 18:23:24 +00:00
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSString*)idFromIdentifier:(NSString*)identifier
|
|
|
|
withPrefix:(NSString*)prefix;
|
|
|
|
- (NSTouchBarItemIdentifier)identifierFromID:(const std::string&)item_id
|
|
|
|
type:(const std::string&)typere;
|
2017-03-01 01:12:35 +00:00
|
|
|
- (bool)hasItemWithID:(const std::string&)item_id;
|
2017-02-28 20:29:23 +00:00
|
|
|
- (NSColor*)colorFromHexColorString:(const std::string&)colorString;
|
|
|
|
|
|
|
|
// Selector actions
|
|
|
|
- (void)buttonAction:(id)sender;
|
2022-06-02 18:43:40 +00:00
|
|
|
- (void)colorPickerAction:(id)sender;
|
|
|
|
- (void)sliderAction:(id)sender;
|
2017-02-28 20:29:23 +00:00
|
|
|
|
|
|
|
// Helpers to create touch bar items
|
2022-06-02 18:43:40 +00:00
|
|
|
- (NSTouchBarItem*)makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSTouchBarItem*)makeButtonForID:(NSString*)id
|
2022-06-02 18:43:40 +00:00
|
|
|
withIdentifier:(NSString*)identifier;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSTouchBarItem*)makeLabelForID:(NSString*)id
|
2022-06-02 18:43:40 +00:00
|
|
|
withIdentifier:(NSString*)identifier;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
|
2022-06-02 18:43:40 +00:00
|
|
|
withIdentifier:(NSString*)identifier;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSTouchBarItem*)makeSliderForID:(NSString*)id
|
2022-06-02 18:43:40 +00:00
|
|
|
withIdentifier:(NSString*)identifier;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSTouchBarItem*)makePopoverForID:(NSString*)id
|
2022-06-02 18:43:40 +00:00
|
|
|
withIdentifier:(NSString*)identifier;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (NSTouchBarItem*)makeGroupForID:(NSString*)id
|
2022-06-02 18:43:40 +00:00
|
|
|
withIdentifier:(NSString*)identifier;
|
2017-02-28 20:29:23 +00:00
|
|
|
|
|
|
|
// Helpers to update touch bar items
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)updateButton:(NSCustomTouchBarItem*)item
|
2022-06-02 18:43:40 +00:00
|
|
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)updateLabel:(NSCustomTouchBarItem*)item
|
2022-06-02 18:43:40 +00:00
|
|
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)updateColorPicker:(NSColorPickerTouchBarItem*)item
|
2022-06-02 18:43:40 +00:00
|
|
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)updateSlider:(NSSliderTouchBarItem*)item
|
2022-06-02 18:43:40 +00:00
|
|
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
2018-04-18 01:44:10 +00:00
|
|
|
- (void)updatePopover:(NSPopoverTouchBarItem*)item
|
2022-06-02 18:43:40 +00:00
|
|
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
2017-02-28 20:29:23 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_COCOA_ELECTRON_TOUCH_BAR_H_
|