mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added context menu to bar of pinned messages with bot button.
This commit is contained in:
parent
659a7622be
commit
dc8b693f1d
3 changed files with 45 additions and 11 deletions
|
@ -6351,6 +6351,20 @@ void HistoryWidget::setChooseReportMessagesDetails(
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
||||||
|
const auto openSection = [=] {
|
||||||
|
const auto id = _pinnedTracker
|
||||||
|
? _pinnedTracker->currentMessageId()
|
||||||
|
: HistoryView::PinnedId();
|
||||||
|
if (!id.message) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controller()->showSection(
|
||||||
|
std::make_shared<HistoryView::PinnedMemento>(
|
||||||
|
_history,
|
||||||
|
((!_migrated || peerIsChannel(id.message.peer))
|
||||||
|
? id.message.msg
|
||||||
|
: (id.message.msg - ServerMaxMsgId))));
|
||||||
|
};
|
||||||
if (const auto replyMarkup = item ? item->inlineReplyMarkup() : nullptr) {
|
if (const auto replyMarkup = item ? item->inlineReplyMarkup() : nullptr) {
|
||||||
const auto &rows = replyMarkup->data.rows;
|
const auto &rows = replyMarkup->data.rows;
|
||||||
if ((rows.size() == 1) && (rows.front().size() == 1)) {
|
if ((rows.size() == 1) && (rows.front().size() == 1)) {
|
||||||
|
@ -6372,6 +6386,18 @@ void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
||||||
if (button->width() > st::historyPinnedBotButtonMaxWidth) {
|
if (button->width() > st::historyPinnedBotButtonMaxWidth) {
|
||||||
button->setFullWidth(st::historyPinnedBotButtonMaxWidth);
|
button->setFullWidth(st::historyPinnedBotButtonMaxWidth);
|
||||||
}
|
}
|
||||||
|
struct State {
|
||||||
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
|
};
|
||||||
|
const auto state = button->lifetime().make_state<State>();
|
||||||
|
_pinnedBar->contextMenuRequested(
|
||||||
|
) | rpl::start_with_next([=, raw = button.data()] {
|
||||||
|
state->menu = base::make_unique_q<Ui::PopupMenu>(raw);
|
||||||
|
state->menu->addAction(
|
||||||
|
tr::lng_settings_events_pinned(tr::now),
|
||||||
|
openSection);
|
||||||
|
state->menu->popup(QCursor::pos());
|
||||||
|
}, button->lifetime());
|
||||||
_pinnedBar->setRightButton(std::move(button));
|
_pinnedBar->setRightButton(std::move(button));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6386,15 +6412,7 @@ void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
|
||||||
if (close) {
|
if (close) {
|
||||||
hidePinnedMessage();
|
hidePinnedMessage();
|
||||||
} else {
|
} else {
|
||||||
const auto id = _pinnedTracker->currentMessageId();
|
openSection();
|
||||||
if (id.message) {
|
|
||||||
controller()->showSection(
|
|
||||||
std::make_shared<HistoryView::PinnedMemento>(
|
|
||||||
_history,
|
|
||||||
((!_migrated || peerIsChannel(id.message.peer))
|
|
||||||
? id.message.msg
|
|
||||||
: (id.message.msg - ServerMaxMsgId))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
_pinnedBar->setRightButton(std::move(button));
|
_pinnedBar->setRightButton(std::move(button));
|
||||||
|
|
|
@ -150,10 +150,12 @@ void PinnedBar::createControls() {
|
||||||
_bar->widget()->setCursor(style::cur_pointer);
|
_bar->widget()->setCursor(style::cur_pointer);
|
||||||
_bar->widget()->events(
|
_bar->widget()->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
) | rpl::filter([=](not_null<QEvent*> event) {
|
||||||
return (event->type() == QEvent::MouseButtonPress);
|
return (event->type() == QEvent::MouseButtonPress)
|
||||||
|
&& (static_cast<QMouseEvent*>(event.get())->button()
|
||||||
|
== Qt::LeftButton);
|
||||||
}) | rpl::map([=] {
|
}) | rpl::map([=] {
|
||||||
return _bar->widget()->events(
|
return _bar->widget()->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> event) {
|
) | rpl::filter([](not_null<QEvent*> event) {
|
||||||
return (event->type() == QEvent::MouseButtonRelease);
|
return (event->type() == QEvent::MouseButtonRelease);
|
||||||
}) | rpl::take(1) | rpl::filter([=](not_null<QEvent*> event) {
|
}) | rpl::take(1) | rpl::filter([=](not_null<QEvent*> event) {
|
||||||
return _bar->widget()->rect().contains(
|
return _bar->widget()->rect().contains(
|
||||||
|
@ -247,4 +249,16 @@ rpl::producer<> PinnedBar::barClicks() const {
|
||||||
return _barClicks.events();
|
return _barClicks.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> PinnedBar::contextMenuRequested() const {
|
||||||
|
return _wrap.entity()->paintRequest(
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
return _bar && _bar->widget();
|
||||||
|
}) | rpl::map([=] {
|
||||||
|
return _bar->widget()->events(
|
||||||
|
) | rpl::filter([](not_null<QEvent*> event) {
|
||||||
|
return (event->type() == QEvent::ContextMenu);
|
||||||
|
}) | rpl::to_empty;
|
||||||
|
}) | rpl::flatten_latest();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
[[nodiscard]] int height() const;
|
[[nodiscard]] int height() const;
|
||||||
[[nodiscard]] rpl::producer<int> heightValue() const;
|
[[nodiscard]] rpl::producer<int> heightValue() const;
|
||||||
[[nodiscard]] rpl::producer<> barClicks() const;
|
[[nodiscard]] rpl::producer<> barClicks() const;
|
||||||
|
[[nodiscard]] rpl::producer<> contextMenuRequested() const;
|
||||||
|
|
||||||
[[nodiscard]] rpl::lifetime &lifetime() {
|
[[nodiscard]] rpl::lifetime &lifetime() {
|
||||||
return _wrap.lifetime();
|
return _wrap.lifetime();
|
||||||
|
@ -63,6 +64,7 @@ private:
|
||||||
std::unique_ptr<Ui::PlainShadow> _shadow;
|
std::unique_ptr<Ui::PlainShadow> _shadow;
|
||||||
Fn<bool()> _customEmojiPaused;
|
Fn<bool()> _customEmojiPaused;
|
||||||
rpl::event_stream<> _barClicks;
|
rpl::event_stream<> _barClicks;
|
||||||
|
rpl::event_stream<> _contextMenuRequested;
|
||||||
Fn<QRect(QRect)> _shadowGeometryPostprocess;
|
Fn<QRect(QRect)> _shadowGeometryPostprocess;
|
||||||
bool _shouldBeShown = false;
|
bool _shouldBeShown = false;
|
||||||
bool _forceHidden = false;
|
bool _forceHidden = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue