mirror of https://github.com/procxx/kepka.git
Added archived button to touchbar.
This commit is contained in:
parent
c90e803f1b
commit
abd55679af
|
@ -19,6 +19,7 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "observer_peer.h"
|
#include "observer_peer.h"
|
||||||
#include "styles/style_media_player.h"
|
#include "styles/style_media_player.h"
|
||||||
|
#include "window/window_controller.h"
|
||||||
#include "ui/empty_userpic.h"
|
#include "ui/empty_userpic.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -116,10 +117,20 @@ auto lifetime = rpl::lifetime();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) buttonActionPin:(NSButton *)sender {
|
- (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([=] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([=] {
|
||||||
App::main()->choosePeer(self.number == kSavedMessagesId || self.number == kArchiveId
|
self.number == kArchiveId
|
||||||
? Auth().userPeerId()
|
? openFolder()
|
||||||
: self.peer->id, ShowAtUnreadMsgId);
|
: 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));
|
paint.fillRect(QRectF(0, 0, s, s), QColor(0, 0, 0, 255));
|
||||||
|
|
||||||
if (self.number == kArchiveId) {
|
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)) {
|
if (const auto folder = Auth().data().folderLoaded(Data::Folder::kId)) {
|
||||||
folder->paintUserpic(paint, 0, 0, s);
|
folder->paintUserpic(paint, 0, 0, s);
|
||||||
}
|
}
|
||||||
|
@ -236,11 +246,38 @@ auto lifetime = rpl::lifetime();
|
||||||
[self updatePinnedButtons];
|
[self updatePinnedButtons];
|
||||||
}, lifetime);
|
}, 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];
|
[self updatePinnedButtons];
|
||||||
|
|
||||||
return self;
|
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 {
|
- (void) updatePinnedButtons {
|
||||||
const auto &order = Auth().data().pinnedChatsOrder(nullptr);
|
const auto &order = Auth().data().pinnedChatsOrder(nullptr);
|
||||||
auto isSelfPeerPinned = false;
|
auto isSelfPeerPinned = false;
|
||||||
|
@ -338,7 +375,7 @@ NSImage *createImageFromStyleIcon(const style::icon &icon, int size = kIdealIcon
|
||||||
self.mainPinnedButtons = [[NSMutableArray alloc] init];
|
self.mainPinnedButtons = [[NSMutableArray alloc] init];
|
||||||
NSStackView *stackView = [[NSStackView 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];
|
PinnedDialogButton *button = [[PinnedDialogButton alloc] init:i];
|
||||||
[self.mainPinnedButtons addObject:button];
|
[self.mainPinnedButtons addObject:button];
|
||||||
[stackView addView:button.view inGravity:NSStackViewGravityCenter];
|
[stackView addView:button.view inGravity:NSStackViewGravityCenter];
|
||||||
|
|
Loading…
Reference in New Issue