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

View file

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

View file

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

View file

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