Refactored touchbar code.

This commit is contained in:
23rd 2019-05-08 12:29:38 +03:00 committed by John Preston
parent 04843ebdd8
commit c89a21ef5e
1 changed files with 22 additions and 52 deletions

View File

@ -50,7 +50,6 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm);
@property(nonatomic, assign) bool isDeletedFromView; @property(nonatomic, assign) bool isDeletedFromView;
- (id) init:(int)num; - (id) init:(int)num;
- (id) initSavedMessages;
- (NSImage *) getPinImage; - (NSImage *) getPinImage;
- (void)buttonActionPin:(NSButton *)sender; - (void)buttonActionPin:(NSButton *)sender;
- (void)updatePinnedDialog; - (void)updatePinnedDialog;
@ -63,24 +62,32 @@ auto lifetime = rpl::lifetime();
- (id) init:(int)num { - (id) init:(int)num {
if (num == kSavedMessagesId) { if (num == kSavedMessagesId) {
return [self initSavedMessages]; self = [super initWithIdentifier:savedMessages];
self.waiting = false;
self.customizationLabel = [NSString stringWithFormat:@"Pinned Dialog %d", num];
} else if (num == kArchiveId) { } else if (num == kArchiveId) {
return [self initArchive]; self = [super initWithIdentifier:archiveFolder];
self.waiting = false;
self.customizationLabel = @"Archive Folder";
} else {
NSString *identifier = [NSString stringWithFormat:@"%@.pinnedDialog%d", customIDMain, num];
self = [super initWithIdentifier:identifier];
self.waiting = true;
self.customizationLabel = @"Saved Messages";
} }
NSString *identifier = [NSString stringWithFormat:@"%@.pinnedDialog%d", customIDMain, num];
self = [super initWithIdentifier:identifier];
if (!self) { if (!self) {
return nil; return nil;
} }
self.number = num; self.number = num;
self.waiting = true;
NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)]; NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)];
[button setBordered:NO]; [button setBordered:NO];
[button sizeToFit]; [button sizeToFit];
[button setHidden:(num > Auth().data().pinnedChatsOrder(nullptr).size())];
self.view = button; self.view = button;
self.customizationLabel = [NSString stringWithFormat:@"Pinned Dialog %d", num];
if (num <= kSavedMessagesId) {
return self;
}
if (self.peer) { if (self.peer) {
Notify::PeerUpdateViewer( Notify::PeerUpdateViewer(
@ -108,40 +115,6 @@ auto lifetime = rpl::lifetime();
button.image = [self getPinImage]; button.image = [self getPinImage];
} }
- (id) initSavedMessages {
self = [super initWithIdentifier:savedMessages];
if (!self) {
return nil;
}
self.number = kSavedMessagesId;
self.waiting = false;
NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)];
[button setBordered:NO];
[button sizeToFit];
self.view = button;
self.customizationLabel = @"Saved Messages";
return self;
}
- (id) initArchive {
self = [super initWithIdentifier:archiveFolder];
if (!self) {
return nil;
}
self.number = kArchiveId;
self.waiting = false;
NSButton *button = [NSButton buttonWithImage:[self getPinImage] target:self action:@selector(buttonActionPin:)];
[button setBordered:NO];
[button sizeToFit];
self.view = button;
self.customizationLabel = @"Archive Folder";
return self;
}
- (void) buttonActionPin:(NSButton *)sender { - (void) buttonActionPin:(NSButton *)sender {
Core::Sandbox::Instance().customEnterFromEventLoop([=] { Core::Sandbox::Instance().customEnterFromEventLoop([=] {
App::main()->choosePeer(self.number == kSavedMessagesId || self.number == kArchiveId App::main()->choosePeer(self.number == kSavedMessagesId || self.number == kArchiveId
@ -300,16 +273,13 @@ auto lifetime = rpl::lifetime();
} }
// If self chat is pinned, delete from view saved messages button. // If self chat is pinned, delete from view saved messages button.
if (isSelfPeerPinned) { if (isSelfPeerPinned && !selfChatButton.isDeletedFromView) {
if (!selfChatButton.isDeletedFromView) { selfChatButton.isDeletedFromView = true;
selfChatButton.isDeletedFromView = true; [stack removeView:selfChatButton.view];
[stack removeView:selfChatButton.view]; }
} if (!isSelfPeerPinned && selfChatButton.isDeletedFromView) {
} else { selfChatButton.isDeletedFromView = false;
if (selfChatButton.isDeletedFromView) { [stack insertView:selfChatButton.view atIndex:0 inGravity:NSStackViewGravityLeading];
selfChatButton.isDeletedFromView = false;
[stack insertView:selfChatButton.view atIndex:0 inGravity:NSStackViewGravityLeading];
}
} }
} }