diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index 8c0727db0..3632bcfd3 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -100,6 +100,8 @@ const auto CommandByName = base::flat_map{ { u"read_chat"_q , Command::ReadChat }, + { u"show_chat_menu"_q , Command::ShowChatMenu }, + // Shortcuts that have no default values. { u"message"_q , Command::JustSendMessage }, { u"message_silently"_q , Command::SendSilentMessage }, @@ -147,6 +149,8 @@ const auto CommandNames = base::flat_map{ { Command::ShowContacts , u"show_contacts"_q }, { Command::ReadChat , u"read_chat"_q }, + + { Command::ShowChatMenu , u"show_chat_menu"_q }, }; [[maybe_unused]] constexpr auto kNoValue = { @@ -435,6 +439,8 @@ void Manager::fillDefaults() { set(u"ctrl+j"_q, Command::ShowContacts); set(u"ctrl+r"_q, Command::ReadChat); + + set(u"ctrl+="_q, Command::ShowChatMenu); } void Manager::writeDefaultFile() { diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index 562c54e44..5355d1681 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -71,6 +71,8 @@ enum class Command { MediaViewerFullscreen, + ShowChatMenu, + SupportReloadTemplates, SupportToggleMuted, SupportScrollToCurrent, diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 83b55be6d..45324201a 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1523,6 +1523,21 @@ void InnerWidget::paintSearchTags( _searchTags->paint(p, position, context.now, context.paused); } +void InnerWidget::showPeerMenu() { + if (!_selected) { + return; + } + const auto &padding = st::defaultDialogRow.padding; + const auto pos = QPoint( + width() - padding.right(), + _selected->top() + _selected->height() + padding.bottom()); + auto event = QContextMenuEvent( + QContextMenuEvent::Keyboard, + pos, + mapToGlobal(pos)); + InnerWidget::contextMenuEvent(&event); +} + void InnerWidget::mouseMoveEvent(QMouseEvent *e) { if (_chatPreviewTouchGlobal || _touchDragStartGlobal) { return; @@ -2835,7 +2850,9 @@ bool InnerWidget::scheduleChatPreview(QPoint positionOverride) { void InnerWidget::contextMenuEvent(QContextMenuEvent *e) { _menu = nullptr; - if (e->reason() == QContextMenuEvent::Mouse) { + const auto fromMouse = e->reason() == QContextMenuEvent::Mouse; + + if (fromMouse) { selectByMouse(e->globalPos()); } @@ -2898,6 +2915,9 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) { if (_menuRow.key) { updateDialogRow(base::take(_menuRow)); } + if (!fromMouse) { + return; + } const auto globalPosition = QCursor::pos(); if (rect().contains(mapFromGlobal(globalPosition))) { setMouseTracking(true); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index f466b7527..2500f43d1 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -141,6 +141,8 @@ public: void refreshEmpty(); void resizeEmpty(); + void showPeerMenu(); + [[nodiscard]] bool isUserpicPress() const; [[nodiscard]] bool isUserpicPressOnWide() const; void cancelChatPreview(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 496ad41f0..ecabae874 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1212,6 +1212,12 @@ void Widget::setupShortcuts() { } return false; }); + request->check(Command::ShowChatMenu, 1) && request->handle([=] { + if (_inner) { + _inner->showPeerMenu(); + } + return true; + }); } }, lifetime()); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index b5fd331e4..7eab91e35 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2006,6 +2006,10 @@ void HistoryWidget::setupShortcuts() { controller()->searchInChat(_history); return true; }); + request->check(Command::ShowChatMenu, 1) && request->handle([=] { + _topBar->showPeerMenu(); + return true; + }); _canSendMessages && request->check(Command::ShowScheduled, 1) && request->handle([=] { diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index dc5a78aff..2af2448c7 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -119,6 +119,7 @@ public: QRect geometry, int narrowWidth, float64 narrowRatio); + void showPeerMenu(); protected: void paintEvent(QPaintEvent *e) override; @@ -142,7 +143,6 @@ private: void call(); void groupCall(); - void showPeerMenu(); void showGroupCallMenu(not_null peer); void toggleInfoSection(); diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index 0b4d4b354..a6dd089a2 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -15,7 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_shared_media.h" #include "boxes/delete_messages_box.h" #include "boxes/peer_list_controllers.h" -#include "mainwidget.h" #include "main/main_session.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -24,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/fade_wrap.h" #include "ui/wrap/padding_wrap.h" #include "ui/search_field_controller.h" -#include "window/window_peer_menu.h" #include "data/data_session.h" #include "data/data_channel.h" #include "data/data_user.h" diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 2e81fe681..dbef00afb 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -492,6 +492,18 @@ void WrapWidget::addTopBarMenuButton() { _topBarMenuToggle->addClickHandler([this] { showTopBarMenu(false); }); + + Shortcuts::Requests( + ) | rpl::filter([=] { + return (_controller->section().type() == Section::Type::Profile); + }) | rpl::start_with_next([=](not_null request) { + using Command = Shortcuts::Command; + + request->check(Command::ShowChatMenu, 1) && request->handle([=] { + showTopBarMenu(false); + return true; + }); + }, _topBarMenuToggle->lifetime()); } bool WrapWidget::closeByOutsideClick() const {