Refactored code.

This commit is contained in:
23rd 2019-05-02 13:25:05 +03:00 committed by John Preston
parent 9059b2e617
commit 92ff237c2d
2 changed files with 22 additions and 53 deletions

View File

@ -25,11 +25,7 @@ static NSTouchBarCustomizationIdentifier _Nullable customIDMain = @"telegram.tou
static NSTouchBarItemIdentifier _Nullable savedMessages = [NSString stringWithFormat:@"%@.savedMessages", customIDMain]; static NSTouchBarItemIdentifier _Nullable savedMessages = [NSString stringWithFormat:@"%@.savedMessages", customIDMain];
static NSTouchBarItemIdentifier _Nullable archiveFolder = [NSString stringWithFormat:@"%@.archiveFolder", customIDMain]; static NSTouchBarItemIdentifier _Nullable archiveFolder = [NSString stringWithFormat:@"%@.archiveFolder", customIDMain];
static NSTouchBarItemIdentifier _Nullable pinnedDialog1 = [NSString stringWithFormat:@"%@.pinnedDialog1", customIDMain]; static NSTouchBarItemIdentifier _Nullable pinnedPanel = [NSString stringWithFormat:@"%@.pinnedPanel", customIDMain];
static NSTouchBarItemIdentifier _Nullable pinnedDialog2 = [NSString stringWithFormat:@"%@.pinnedDialog2", customIDMain];
static NSTouchBarItemIdentifier _Nullable pinnedDialog3 = [NSString stringWithFormat:@"%@.pinnedDialog3", customIDMain];
static NSTouchBarItemIdentifier _Nullable pinnedDialog4 = [NSString stringWithFormat:@"%@.pinnedDialog4", customIDMain];
static NSTouchBarItemIdentifier _Nullable pinnedDialog5 = [NSString stringWithFormat:@"%@.pinnedDialog5", customIDMain];
static NSTouchBarItemIdentifier _Nullable seekBar = [NSString stringWithFormat:@"%@.seekbar", BASE_ID]; static NSTouchBarItemIdentifier _Nullable seekBar = [NSString stringWithFormat:@"%@.seekbar", BASE_ID];
static NSTouchBarItemIdentifier _Nullable play = [NSString stringWithFormat:@"%@.play", BASE_ID]; static NSTouchBarItemIdentifier _Nullable play = [NSString stringWithFormat:@"%@.play", BASE_ID];

View File

@ -159,7 +159,6 @@ auto lifetime = rpl::lifetime();
self.peer = nil; self.peer = nil;
return; return;
} }
// Order is reversed.
const auto pinned = order.at(self.number - 1); const auto pinned = order.at(self.number - 1);
if (const auto history = pinned.history()) { if (const auto history = pinned.history()) {
self.peer = history->peer; self.peer = history->peer;
@ -219,32 +218,9 @@ auto lifetime = rpl::lifetime();
if (self) { if (self) {
self.view = view; self.view = view;
self.touchbarItems = @{ self.touchbarItems = @{
// savedMessages: [NSMutableDictionary dictionaryWithDictionary:@{ pinnedPanel: [NSMutableDictionary dictionaryWithDictionary:@{
// @"type": @"button",
// @"name": @"Saved Messages",
// @"cmd": [NSNumber numberWithInt:kSavedMessages],
// @"image": static_cast<NSImage*>(qt_mac_create_nsimage(*pix)),
// }],
pinnedDialog1: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"pinned", @"type": @"pinned",
@"num": @1,
}], }],
// pinnedDialog2: [NSMutableDictionary dictionaryWithDictionary:@{
// @"type": @"pinned",
// @"num": @2,
// }],
// pinnedDialog3: [NSMutableDictionary dictionaryWithDictionary:@{
// @"type": @"pinned",
// @"num": @3,
// }],
// pinnedDialog4: [NSMutableDictionary dictionaryWithDictionary:@{
// @"type": @"pinned",
// @"num": @4,
// }],
// pinnedDialog5: [NSMutableDictionary dictionaryWithDictionary:@{
// @"type": @"pinned",
// @"num": @5,
// }],
seekBar: [NSMutableDictionary dictionaryWithDictionary:@{ seekBar: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"slider", @"type": @"slider",
@"name": @"Seek Bar" @"name": @"Seek Bar"
@ -300,8 +276,7 @@ auto lifetime = rpl::lifetime();
_touchBarMain.delegate = self; _touchBarMain.delegate = self;
_touchBarMain.customizationIdentifier = customIDMain; _touchBarMain.customizationIdentifier = customIDMain;
_touchBarMain.defaultItemIdentifiers = @[savedMessages, pinnedDialog1, pinnedDialog2, pinnedDialog3, pinnedDialog4, pinnedDialog5]; _touchBarMain.defaultItemIdentifiers = @[pinnedPanel];
_touchBarMain.customizationAllowedItemIdentifiers = @[savedMessages];
_touchBarAudioPlayer = [[NSTouchBar alloc] init]; _touchBarAudioPlayer = [[NSTouchBar alloc] init];
_touchBarAudioPlayer.delegate = self; _touchBarAudioPlayer.delegate = self;
@ -334,7 +309,7 @@ auto lifetime = rpl::lifetime();
return item; return item;
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"text"]) { } else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"text"]) {
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
NSTextField *text = [NSTextField labelWithString:@"0:00"]; NSTextField *text = [NSTextField labelWithString:@"00:00 / 00:00"];
text.alignment = NSTextAlignmentCenter; text.alignment = NSTextAlignmentCenter;
item.view = text; item.view = text;
item.customizationLabel = self.touchbarItems[identifier][@"name"]; item.customizationLabel = self.touchbarItems[identifier][@"name"];
@ -344,7 +319,7 @@ auto lifetime = rpl::lifetime();
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
NSMutableArray *pins = [[NSMutableArray alloc] init]; NSMutableArray *pins = [[NSMutableArray alloc] init];
for (auto i = -1; i <= 5; i++) { for (auto i = kArchiveId; i <= Global::PinnedDialogsCountMax(); i++) {
[pins addObject:[[PinnedDialogButton alloc] init:i].view]; [pins addObject:[[PinnedDialogButton alloc] init:i].view];
} }
NSStackView *stackView = [NSStackView stackViewWithViews:[pins copy]]; NSStackView *stackView = [NSStackView stackViewWithViews:[pins copy]];
@ -468,9 +443,7 @@ auto lifetime = rpl::lifetime();
const auto command = [self.touchbarItems[identifier][@"cmd"] intValue]; const auto command = [self.touchbarItems[identifier][@"cmd"] intValue];
Core::Sandbox::Instance().customEnterFromEventLoop([=] { Core::Sandbox::Instance().customEnterFromEventLoop([=] {
if (command == kSavedMessages) { if (command == kPlayPause) {
App::main()->choosePeer(Auth().userPeerId(), ShowAtUnreadMsgId);
} else if (command == kPlayPause) {
Media::Player::instance()->playPause(); Media::Player::instance()->playPause();
} else if (command == kPlaylistPrevious) { } else if (command == kPlaylistPrevious) {
Media::Player::instance()->previous(); Media::Player::instance()->previous();