Added archived button to touchbar.

This commit is contained in:
23rd 2019-05-08 15:15:36 +03:00 committed by John Preston
parent c90e803f1b
commit abd55679af
1 changed files with 42 additions and 5 deletions

View File

@ -19,6 +19,7 @@
#include "mainwindow.h"
#include "observer_peer.h"
#include "styles/style_media_player.h"
#include "window/window_controller.h"
#include "ui/empty_userpic.h"
namespace {
@ -116,10 +117,20 @@ auto lifetime = rpl::lifetime();
}
- (void) buttonActionPin:(NSButton *)sender {
const auto openFolder = [=] {
if (!App::wnd()) {
return;
}
if (const auto folder = Auth().data().folderLoaded(Data::Folder::kId)) {
App::wnd()->controller()->openFolder(folder);
}
};
Core::Sandbox::Instance().customEnterFromEventLoop([=] {
App::main()->choosePeer(self.number == kSavedMessagesId || self.number == kArchiveId
? Auth().userPeerId()
: self.peer->id, ShowAtUnreadMsgId);
self.number == kArchiveId
? openFolder()
: App::main()->choosePeer(self.number == kSavedMessagesId
? Auth().userPeerId()
: self.peer->id, ShowAtUnreadMsgId);
});
}
@ -136,7 +147,6 @@ auto lifetime = rpl::lifetime();
paint.fillRect(QRectF(0, 0, s, s), QColor(0, 0, 0, 255));
if (self.number == kArchiveId) {
paint.fillRect(QRectF(0, 0, s, s), QColor(0, 0, 0, 255));
if (const auto folder = Auth().data().folderLoaded(Data::Folder::kId)) {
folder->paintUserpic(paint, 0, 0, s);
}
@ -236,11 +246,38 @@ auto lifetime = rpl::lifetime();
[self updatePinnedButtons];
}, lifetime);
Auth().data().chatsListChanges(
) | rpl::filter([](Data::Folder *folder) {
return folder && folder->chatsList();
}) | rpl::start_with_next([=](Data::Folder *folder) {
[self toggleArchiveButton:folder->chatsList()->empty()];
}, lifetime);
[self updatePinnedButtons];
return self;
}
- (void) toggleArchiveButton:(bool)hide {
for (PinnedDialogButton *button in self.mainPinnedButtons) {
if (button.number == kArchiveId) {
NSCustomTouchBarItem *item = [self.touchBarMain itemForIdentifier:pinnedPanel];
NSStackView *stack = item.view;
[button updatePinnedDialog];
if (hide && !button.isDeletedFromView) {
button.isDeletedFromView = true;
[stack removeView:button.view];
}
if (!hide && button.isDeletedFromView) {
button.isDeletedFromView = false;
[stack insertView:button.view
atIndex:(button.number + 1)
inGravity:NSStackViewGravityLeading];
}
}
}
}
- (void) updatePinnedButtons {
const auto &order = Auth().data().pinnedChatsOrder(nullptr);
auto isSelfPeerPinned = false;
@ -338,7 +375,7 @@ NSImage *createImageFromStyleIcon(const style::icon &icon, int size = kIdealIcon
self.mainPinnedButtons = [[NSMutableArray alloc] init];
NSStackView *stackView = [[NSStackView alloc] init];
for (auto i = kSavedMessagesId; i <= Global::PinnedDialogsCountMax(); i++) {
for (auto i = kArchiveId; i <= Global::PinnedDialogsCountMax(); i++) {
PinnedDialogButton *button = [[PinnedDialogButton alloc] init:i];
[self.mainPinnedButtons addObject:button];
[stackView addView:button.view inGravity:NSStackViewGravityCenter];