Add "Open in new window" to context menu.

This commit is contained in:
John Preston 2023-02-03 19:32:25 +04:00
parent 94b489835c
commit bbd937115c
18 changed files with 92 additions and 48 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -2124,6 +2124,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_choose_files" = "Choose files"; "lng_choose_files" = "Choose files";
"lng_game_tag" = "Game"; "lng_game_tag" = "Game";
"lng_context_new_window" = "Open in new window";
"lng_context_view_profile" = "View profile"; "lng_context_view_profile" = "View profile";
"lng_context_send_message" = "Send message"; "lng_context_send_message" = "Send message";
"lng_context_view_group" = "View group info"; "lng_context_view_group" = "View group info";

View file

@ -519,7 +519,7 @@ groupCallMenu: Menu(defaultMenu) {
padding: margins(0px, 4px, 0px, 4px); padding: margins(0px, 4px, 0px, 4px);
fg: groupCallMenuBgOver; fg: groupCallMenuBgOver;
} }
arrow: icon {{ "dropdown_submenu_arrow", groupCallMemberNotJoinedStatus }}; arrow: icon {{ "menu/submenu_arrow", groupCallMemberNotJoinedStatus }};
ripple: RippleAnimation(defaultRippleAnimation) { ripple: RippleAnimation(defaultRippleAnimation) {
color: groupCallMenuBgRipple; color: groupCallMenuBgRipple;

View file

@ -60,6 +60,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_chat_filters.h" #include "api/api_chat_filters.h"
#include "base/qt/qt_common_adapters.h" #include "base/qt/qt_common_adapters.h"
#include "styles/style_dialogs.h" #include "styles/style_dialogs.h"
#include "styles/style_chat.h" // popupMenuExpandedSeparator
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_window.h" #include "styles/style_window.h"
#include "styles/style_menu_icons.h" #include "styles/style_menu_icons.h"
@ -70,13 +71,6 @@ namespace {
constexpr auto kHashtagResultsLimit = 5; constexpr auto kHashtagResultsLimit = 5;
constexpr auto kStartReorderThreshold = 30; constexpr auto kStartReorderThreshold = 30;
base::options::toggle CtrlClickChatNewWindow({
.id = kOptionCtrlClickChatNewWindow,
.name = "New chat window by Ctrl+Click",
.description = "Open chat in a new window by Ctrl+Click "
"(Cmd+Click on macOS).",
});
int FixedOnTopDialogsCount(not_null<Dialogs::IndexedList*> list) { int FixedOnTopDialogsCount(not_null<Dialogs::IndexedList*> list) {
auto result = 0; auto result = 0;
for (const auto &row : *list) { for (const auto &row : *list) {
@ -105,8 +99,6 @@ int PinnedDialogsCount(
} // namespace } // namespace
const char kOptionCtrlClickChatNewWindow[] = "ctrl-click-chat-new-window";
struct InnerWidget::CollapsedRow { struct InnerWidget::CollapsedRow {
CollapsedRow(Data::Folder *folder) : folder(folder) { CollapsedRow(Data::Folder *folder) : folder(folder) {
} }
@ -2206,7 +2198,7 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) {
_menu = base::make_unique_q<Ui::PopupMenu>( _menu = base::make_unique_q<Ui::PopupMenu>(
this, this,
row.fullId ? st::defaultPopupMenu : st::popupMenuWithIcons); row.fullId ? st::defaultPopupMenu : st::popupMenuExpandedSeparator);
if (row.fullId) { if (row.fullId) {
if (session().supportMode()) { if (session().supportMode()) {
fillSupportSearchMenu(_menu.get()); fillSupportSearchMenu(_menu.get());
@ -3310,9 +3302,7 @@ bool InnerWidget::chooseRow(
const auto modifyChosenRow = []( const auto modifyChosenRow = [](
ChosenRow row, ChosenRow row,
Qt::KeyboardModifiers modifiers) { Qt::KeyboardModifiers modifiers) {
if (CtrlClickChatNewWindow.value()) { row.newWindow = (modifiers & Qt::ControlModifier);
row.newWindow = (modifiers & Qt::ControlModifier);
}
return row; return row;
}; };
auto chosen = modifyChosenRow(computeChosenRow(), modifiers); auto chosen = modifyChosenRow(computeChosenRow(), modifiers);

View file

@ -54,8 +54,6 @@ struct TopicJumpCache;
namespace Dialogs { namespace Dialogs {
extern const char kOptionCtrlClickChatNewWindow[];
class Row; class Row;
class FakeRow; class FakeRow;
class IndexedList; class IndexedList;

View file

@ -484,24 +484,8 @@ void Widget::chosenRow(const ChosenRow &row) {
const auto showAtMsgId = controller()->uniqueChatsInSearchResults() const auto showAtMsgId = controller()->uniqueChatsInSearchResults()
? ShowAtUnreadMsgId ? ShowAtUnreadMsgId
: row.message.fullId.msg; : row.message.fullId.msg;
if (row.newWindow && controller()->canShowSeparateWindow(peer)) { if (row.newWindow) {
const auto active = controller()->activeChatCurrent(); controller()->showInNewWindow(peer, showAtMsgId);
const auto fromActive = active.history()
? (active.history()->peer == peer)
: false;
const auto toSeparate = [=] {
Core::App().ensureSeparateWindowForPeer(
peer,
showAtMsgId);
};
if (fromActive) {
controller()->window().preventOrInvoke([=] {
controller()->clearSectionStack();
toSeparate();
});
} else {
toSeparate();
}
} else { } else {
controller()->showThread( controller()->showThread(
history, history,

View file

@ -192,7 +192,7 @@ mediaviewControlsMenu: Menu(defaultMenu) {
fg: mediaviewPlaybackIconRipple; fg: mediaviewPlaybackIconRipple;
} }
arrow: icon {{ "dropdown_submenu_arrow", mediaviewPlaybackProgressFg }}; arrow: icon {{ "menu/submenu_arrow", mediaviewPlaybackProgressFg }};
ripple: RippleAnimation(defaultRippleAnimation) { ripple: RippleAnimation(defaultRippleAnimation) {
color: mediaviewPlaybackIconRipple; color: mediaviewPlaybackIconRipple;

View file

@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "core/launcher.h" #include "core/launcher.h"
#include "chat_helpers/tabbed_panel.h" #include "chat_helpers/tabbed_panel.h"
#include "dialogs/dialogs_inner_widget.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
@ -140,7 +139,6 @@ void SetupExperimental(
addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick); addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick);
addToggle(Core::kOptionFractionalScalingEnabled); addToggle(Core::kOptionFractionalScalingEnabled);
addToggle(Window::kOptionViewProfileInChatsListContextMenu); addToggle(Window::kOptionViewProfileInChatsListContextMenu);
addToggle(Dialogs::kOptionCtrlClickChatNewWindow);
addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL); addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL);
addToggle(Ui::kOptionUseSmallMsgBubbleRadius); addToggle(Ui::kOptionUseSmallMsgBubbleRadius);
addToggle(Media::Player::kOptionDisableAutoplayNext); addToggle(Media::Player::kOptionDisableAutoplayNext);

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "settings/settings_information.h" #include "settings/settings_information.h"
#include "dialogs/dialogs_inner_widget.h" // kOptionCtrlClickChatNewWindow.
#include "editor/photo_editor_layer_widget.h" #include "editor/photo_editor_layer_widget.h"
#include "settings/settings_common.h" #include "settings/settings_common.h"
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
@ -23,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
#include "ui/controls/userpic_button.h" #include "ui/controls/userpic_button.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/delayed_activation.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/unread_badge_paint.h" #include "ui/unread_badge_paint.h"
#include "core/application.h" #include "core/application.h"
@ -55,6 +55,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/options.h" #include "base/options.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/random.h" #include "base/random.h"
#include "styles/style_chat.h" // popupMenuExpandedSeparator
#include "styles/style_dialogs.h" // dialogsPremiumIcon #include "styles/style_dialogs.h" // dialogsPremiumIcon
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_settings.h" #include "styles/style_settings.h"
@ -670,9 +671,16 @@ void SetupAccountsWrap(
} }
state->menu = base::make_unique_q<Ui::PopupMenu>( state->menu = base::make_unique_q<Ui::PopupMenu>(
raw, raw,
st::popupMenuWithIcons); st::popupMenuExpandedSeparator);
const auto addAction = Ui::Menu::CreateAddActionCallback( const auto addAction = Ui::Menu::CreateAddActionCallback(
state->menu); state->menu);
addAction(tr::lng_context_new_window(tr::now), [=] {
Ui::PreventDelayedActivation();
Core::App().ensureSeparateWindowForAccount(account);
Core::App().domain().maybeActivate(account);
}, &st::menuIconNewWindow);
Window::AddSeparatorAndShiftUp(addAction);
addAction(tr::lng_profile_copy_phone(tr::now), [=] { addAction(tr::lng_profile_copy_phone(tr::now), [=] {
const auto phone = rpl::variable<TextWithEntities>( const auto phone = rpl::variable<TextWithEntities>(
Info::Profile::PhoneValue(session->user())); Info::Profile::PhoneValue(session->user()));
@ -812,9 +820,7 @@ not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
) | rpl::start_with_next([=](Qt::MouseButton which) { ) | rpl::start_with_next([=](Qt::MouseButton which) {
if (which == Qt::LeftButton) { if (which == Qt::LeftButton) {
const auto modifiers = button->clickModifiers(); const auto modifiers = button->clickModifiers();
const auto newWindow = (modifiers & Qt::ControlModifier) const auto newWindow = (modifiers & Qt::ControlModifier);
&& base::options::lookup<bool>(
Dialogs::kOptionCtrlClickChatNewWindow).value();
add(Environment::Production, newWindow); add(Environment::Production, newWindow);
return; return;
} else if (which != Qt::RightButton } else if (which != Qt::RightButton
@ -884,9 +890,7 @@ void AccountsList::rebuild() {
_currentAccountActivations.fire({}); _currentAccountActivations.fire({});
return; return;
} }
const auto newWindow = (modifiers & Qt::ControlModifier) const auto newWindow = (modifiers & Qt::ControlModifier);
&& base::options::lookup<bool>(
Dialogs::kOptionCtrlClickChatNewWindow).value();
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{ auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
if (guard) { if (guard) {
_reorder->finishReordering(); _reorder->finishReordering();

View file

@ -99,6 +99,7 @@ menuIconSpoilerOff: icon {{ "menu/spoiler_off", menuIconColor }};
menuIconDisable: icon {{ "menu/disable", menuIconColor }}; menuIconDisable: icon {{ "menu/disable", menuIconColor }};
menuIconPhotoSet: icon {{ "menu/photo_set", menuIconColor }}; menuIconPhotoSet: icon {{ "menu/photo_set", menuIconColor }};
menuIconPhotoSuggest: icon {{ "menu/photo_suggest", menuIconColor }}; menuIconPhotoSuggest: icon {{ "menu/photo_suggest", menuIconColor }};
menuIconNewWindow: icon {{ "menu/new_window", menuIconColor }};
menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }}; menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }};
menuIconTTLAnyTextPosition: point(11px, 22px); menuIconTTLAnyTextPosition: point(11px, 22px);

View file

@ -147,7 +147,6 @@ private:
MsgId singlePeerShowAtMsgId); MsgId singlePeerShowAtMsgId);
void setupSideBar(); void setupSideBar();
void sideBarChanged(); void sideBarChanged();
void logoutWithChecks(Main::Account *account);
void showBox( void showBox(
object_ptr<Ui::BoxContent> content, object_ptr<Ui::BoxContent> content,

View file

@ -41,6 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/menu/menu_add_action_callback_factory.h" #include "ui/widgets/menu/menu_add_action_callback_factory.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
#include "ui/toasts/common_toasts.h" #include "ui/toasts/common_toasts.h"
#include "ui/delayed_activation.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_session_settings.h" #include "main/main_session_settings.h"
#include "menu/menu_mute.h" #include "menu/menu_mute.h"
@ -81,6 +82,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "export/export_manager.h" #include "export/export_manager.h"
#include "boxes/peers/edit_peer_info_box.h" #include "boxes/peers/edit_peer_info_box.h"
#include "styles/style_chat.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_window.h" // st::windowMinWidth #include "styles/style_window.h" // st::windowMinWidth
@ -254,6 +256,7 @@ private:
void addToggleMuteSubmenu(bool addSeparator); void addToggleMuteSubmenu(bool addSeparator);
void addSupportInfo(); void addSupportInfo();
void addInfo(); void addInfo();
void addNewWindow();
void addToggleFolder(); void addToggleFolder();
void addToggleUnreadMark(); void addToggleUnreadMark();
void addToggleArchive(); void addToggleArchive();
@ -597,6 +600,25 @@ void Filler::addToggleUnreadMark() {
}, (unread ? &st::menuIconMarkRead : &st::menuIconMarkUnread)); }, (unread ? &st::menuIconMarkRead : &st::menuIconMarkUnread));
} }
void Filler::addNewWindow() {
const auto history = _request.key.history();
if (!_peer
|| _topic
|| _peer->isForum()
|| (history
&& history->useTopPromotion()
&& !history->topPromotionType().isEmpty())) {
return;
}
const auto peer = _peer;
const auto controller = _controller;
_addAction(tr::lng_context_new_window(tr::now), [=] {
Ui::PreventDelayedActivation();
controller->showInNewWindow(peer);
}, &st::menuIconNewWindow);
AddSeparatorAndShiftUp(_addAction);
}
void Filler::addToggleArchive() { void Filler::addToggleArchive() {
if (!_peer || _topic) { if (!_peer || _topic) {
return; return;
@ -1162,6 +1184,7 @@ void Filler::addVideoChat() {
} }
void Filler::fillContextMenuActions() { void Filler::fillContextMenuActions() {
addNewWindow();
addHidePromotion(); addHidePromotion();
addToggleArchive(); addToggleArchive();
addTogglePin(); addTogglePin();
@ -2413,4 +2436,17 @@ void MarkAsReadThread(not_null<Data::Thread*> thread) {
} }
} }
void AddSeparatorAndShiftUp(const PeerMenuCallback &addAction) {
addAction({ .isSeparator = true });
const auto &st = st::popupMenuExpandedSeparator.menu;
const auto shift = st::popupMenuExpandedSeparator.scrollPadding.top()
+ st.itemPadding.top()
+ st.itemStyle.font->height
+ st.itemPadding.bottom()
+ st.separator.padding.top()
+ st.separator.width / 2;
addAction({ .addTopShift = -shift });
}
} // namespace Window } // namespace Window

View file

@ -164,4 +164,6 @@ void UnpinAllMessages(
[[nodiscard]] bool IsUnreadThread(not_null<Data::Thread*> thread); [[nodiscard]] bool IsUnreadThread(not_null<Data::Thread*> thread);
void MarkAsReadThread(not_null<Data::Thread*> thread); void MarkAsReadThread(not_null<Data::Thread*> thread);
void AddSeparatorAndShiftUp(const PeerMenuCallback &addAction);
} // namespace Window } // namespace Window

View file

@ -1460,7 +1460,7 @@ void SessionController::closeThirdSection() {
bool SessionController::canShowSeparateWindow( bool SessionController::canShowSeparateWindow(
not_null<PeerData*> peer) const { not_null<PeerData*> peer) const {
return peer->computeUnavailableReason().isEmpty(); return !peer->isForum() && peer->computeUnavailableReason().isEmpty();
} }
void SessionController::showPeer(not_null<PeerData*> peer, MsgId msgId) { void SessionController::showPeer(not_null<PeerData*> peer, MsgId msgId) {
@ -1690,6 +1690,33 @@ void SessionController::clearChooseReportMessages() {
content()->clearChooseReportMessages(); content()->clearChooseReportMessages();
} }
void SessionController::showInNewWindow(
not_null<PeerData*> peer,
MsgId msgId) {
if (!canShowSeparateWindow(peer)) {
showThread(
peer->owner().history(peer),
msgId,
Window::SectionShow::Way::ClearStack);
return;
}
const auto active = activeChatCurrent();
const auto fromActive = active.history()
? (active.history()->peer == peer)
: false;
const auto toSeparate = [=] {
Core::App().ensureSeparateWindowForPeer(peer, msgId);
};
if (fromActive) {
window().preventOrInvoke([=] {
clearSectionStack();
toSeparate();
});
} else {
toSeparate();
}
}
void SessionController::toggleChooseChatTheme(not_null<PeerData*> peer) { void SessionController::toggleChooseChatTheme(not_null<PeerData*> peer) {
content()->toggleChooseChatTheme(peer); content()->toggleChooseChatTheme(peer);
} }

View file

@ -477,6 +477,10 @@ public:
Fn<void(MessageIdsList)> done); Fn<void(MessageIdsList)> done);
void clearChooseReportMessages(); void clearChooseReportMessages();
void showInNewWindow(
not_null<PeerData*> peer,
MsgId msgId = ShowAtUnreadMsgId);
void toggleChooseChatTheme(not_null<PeerData*> peer); void toggleChooseChatTheme(not_null<PeerData*> peer);
[[nodiscard]] bool dialogsListFocused() const { [[nodiscard]] bool dialogsListFocused() const {

@ -1 +1 @@
Subproject commit 30e765785946f3e4aa89d1b1b7fa2118b612a8a0 Subproject commit 98fa93787a13d8ad9427facb465500fe3179860e