Added ability to open shared media in window with Ctrl+Click.

This commit is contained in:
23rd 2025-01-30 12:16:31 +03:00
parent 7442ea7a16
commit a676138745
4 changed files with 23 additions and 14 deletions

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <rpl/mappers.h> #include <rpl/mappers.h>
#include <rpl/map.h> #include <rpl/map.h>
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "base/qt/qt_key_modifiers.h"
#include "data/data_saved_messages.h" #include "data/data_saved_messages.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_stories_ids.h" #include "data/data_stories_ids.h"
@ -90,7 +91,8 @@ inline auto AddButton(
MsgId topicRootId, MsgId topicRootId,
PeerData *migrated, PeerData *migrated,
Type type, Type type,
Ui::MultiSlideTracker &tracker) { Ui::MultiSlideTracker &tracker,
Fn<void()> openInWindow) {
auto result = AddCountedButton( auto result = AddCountedButton(
parent, parent,
Profile::SharedMediaCountValue(peer, topicRootId, migrated, type), Profile::SharedMediaCountValue(peer, topicRootId, migrated, type),
@ -100,6 +102,10 @@ inline auto AddButton(
if (mouse == Qt::RightButton) { if (mouse == Qt::RightButton) {
return; return;
} }
if (openInWindow
&& (base::IsCtrlPressed() || mouse == Qt::MiddleButton)) {
return openInWindow();
}
const auto topic = topicRootId const auto topic = topicRootId
? peer->forumTopicFor(topicRootId) ? peer->forumTopicFor(topicRootId)
: nullptr; : nullptr;

View file

@ -92,7 +92,8 @@ void InnerWidget::createTypeButtons() {
topicRootId, topicRootId,
migrated, migrated,
buttonType, buttonType,
tracker); tracker,
nullptr);
object_ptr<Profile::FloatingIcon>( object_ptr<Profile::FloatingIcon>(
result, result,
icon, icon,

View file

@ -93,12 +93,8 @@ Fn<void()> SeparateWindowFactory(
void AddContextMenu( void AddContextMenu(
not_null<Ui::AbstractButton*> button, not_null<Ui::AbstractButton*> button,
not_null<Window::SessionController*> window, Fn<void()> openInWindow) {
not_null<PeerData*> peer, if (!openInWindow) {
MsgId rootId,
Storage::SharedMediaType type) {
const auto callback = SeparateWindowFactory(window, peer, rootId, type);
if (!callback) {
return; return;
} }
button->setAcceptBoth(); button->setAcceptBoth();
@ -116,7 +112,7 @@ void AddContextMenu(
state->menu->addAction(tr::lng_context_new_window(tr::now), [=] { state->menu->addAction(tr::lng_context_new_window(tr::now), [=] {
base::call_delayed( base::call_delayed(
st::popupMenuWithIcons.showDuration, st::popupMenuWithIcons.showDuration,
crl::guard(button, callback)); crl::guard(button, openInWindow));
}, &st::menuIconNewWindow); }, &st::menuIconNewWindow);
state->menu->popup(QCursor::pos()); state->menu->popup(QCursor::pos());
}); });
@ -229,6 +225,12 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
MediaType type, MediaType type,
const style::icon &icon) { const style::icon &icon) {
const auto topicRootId = _topic ? _topic->rootId() : 0; const auto topicRootId = _topic ? _topic->rootId() : 0;
const auto window = _controller->parentController();
const auto openInWindow = SeparateWindowFactory(
window,
_peer,
topicRootId,
type);
auto result = Media::AddButton( auto result = Media::AddButton(
content, content,
_controller, _controller,
@ -236,10 +238,9 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
topicRootId, topicRootId,
_migrated, _migrated,
type, type,
tracker); tracker,
if (const auto window = _controller->parentController()) { openInWindow);
AddContextMenu(result, window, _peer, topicRootId, type); AddContextMenu(result, openInWindow);
}
object_ptr<Profile::FloatingIcon>( object_ptr<Profile::FloatingIcon>(
result, result,
icon, icon,

View file

@ -109,7 +109,8 @@ void SublistsWidget::setupOtherTypes() {
MsgId(), // topicRootId MsgId(), // topicRootId
nullptr, // migrated nullptr, // migrated
buttonType, buttonType,
tracker); tracker,
nullptr);
object_ptr<Profile::FloatingIcon>( object_ptr<Profile::FloatingIcon>(
result, result,
icon, icon,