mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allow opening new account in a separate window.
This commit is contained in:
parent
42a2f53a11
commit
e10964a0bc
6 changed files with 51 additions and 24 deletions
|
@ -305,14 +305,24 @@ not_null<Main::Account*> Domain::add(MTP::Environment environment) {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Domain::addActivated(MTP::Environment environment) {
|
void Domain::addActivated(MTP::Environment environment, bool newWindow) {
|
||||||
|
const auto added = [&](not_null<Main::Account*> account) {
|
||||||
|
if (newWindow) {
|
||||||
|
Core::App().ensureSeparateWindowForAccount(account);
|
||||||
|
} else if (const auto window = Core::App().separateWindowForAccount(
|
||||||
|
account)) {
|
||||||
|
window->activate();
|
||||||
|
} else {
|
||||||
|
activate(account);
|
||||||
|
}
|
||||||
|
};
|
||||||
if (accounts().size() < maxAccounts()) {
|
if (accounts().size() < maxAccounts()) {
|
||||||
activate(add(environment));
|
added(add(environment));
|
||||||
} else {
|
} else {
|
||||||
for (auto &[index, account] : accounts()) {
|
for (auto &[index, account] : accounts()) {
|
||||||
if (!account->sessionExists()
|
if (!account->sessionExists()
|
||||||
&& account->mtp().environment() == environment) {
|
&& account->mtp().environment() == environment) {
|
||||||
activate(account.get());
|
added(account.get());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
|
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
|
||||||
void maybeActivate(not_null<Main::Account*> account);
|
void maybeActivate(not_null<Main::Account*> account);
|
||||||
void activate(not_null<Main::Account*> account);
|
void activate(not_null<Main::Account*> account);
|
||||||
void addActivated(MTP::Environment environment);
|
void addActivated(MTP::Environment environment, bool newWindow = false);
|
||||||
|
|
||||||
// Interface for Storage::Domain.
|
// Interface for Storage::Domain.
|
||||||
void accountAddedInStorage(AccountWithIndex accountWithIndex);
|
void accountAddedInStorage(AccountWithIndex accountWithIndex);
|
||||||
|
|
|
@ -1294,7 +1294,7 @@ bool MainWidget::showHistoryInDifferentWindow(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::showPeerHistory(
|
void MainWidget::showHistory(
|
||||||
PeerId peerId,
|
PeerId peerId,
|
||||||
const SectionShow ¶ms,
|
const SectionShow ¶ms,
|
||||||
MsgId showAtMsgId) {
|
MsgId showAtMsgId) {
|
||||||
|
@ -1311,6 +1311,7 @@ void MainWidget::showPeerHistory(
|
||||||
Assert(isPrimary());
|
Assert(isPrimary());
|
||||||
if (params.activation != anim::activation::background) {
|
if (params.activation != anim::activation::background) {
|
||||||
_controller->show(Ui::MakeInformBox(unavailable));
|
_controller->show(Ui::MakeInformBox(unavailable));
|
||||||
|
_controller->window().activate();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1324,9 +1325,13 @@ void MainWidget::showPeerHistory(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (peerId && params.activation != anim::activation::background) {
|
||||||
|
_controller->window().activate();
|
||||||
|
}
|
||||||
|
|
||||||
if (!(_history->peer() && _history->peer()->id == peerId)
|
if (!(_history->peer() && _history->peer()->id == peerId)
|
||||||
&& preventsCloseSection(
|
&& preventsCloseSection(
|
||||||
[=] { showPeerHistory(peerId, params, showAtMsgId); },
|
[=] { showHistory(peerId, params, showAtMsgId); },
|
||||||
params)) {
|
params)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1490,7 +1495,7 @@ void MainWidget::showMessage(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (_history->peer() == item->history()->peer) {
|
} else if (_history->peer() == item->history()->peer) {
|
||||||
showPeerHistory(peerId, params, itemId);
|
showHistory(peerId, params, itemId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ public:
|
||||||
|
|
||||||
void toggleChooseChatTheme(not_null<PeerData*> peer);
|
void toggleChooseChatTheme(not_null<PeerData*> peer);
|
||||||
|
|
||||||
void showPeerHistory(
|
void showHistory(
|
||||||
PeerId peer,
|
PeerId peer,
|
||||||
const SectionShow ¶ms,
|
const SectionShow ¶ms,
|
||||||
MsgId msgId);
|
MsgId msgId);
|
||||||
|
|
|
@ -778,23 +778,38 @@ not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
|
||||||
})))->setDuration(0);
|
})))->setDuration(0);
|
||||||
const auto button = result->entity();
|
const auto button = result->entity();
|
||||||
|
|
||||||
const auto add = [=](MTP::Environment environment) {
|
using Environment = MTP::Environment;
|
||||||
Core::App().preventOrInvoke([=] {
|
const auto add = [=](Environment environment, bool newWindow = false) {
|
||||||
auto &domain = _controller->session().domain();
|
auto &domain = _controller->session().domain();
|
||||||
if (domain.accounts().size() >= domain.maxAccounts()) {
|
auto found = false;
|
||||||
_controller->show(
|
for (const auto &[index, account] : domain.accounts()) {
|
||||||
Box(AccountsLimitBox, &_controller->session()));
|
const auto raw = account.get();
|
||||||
} else {
|
if (!raw->sessionExists()
|
||||||
domain.addActivated(environment);
|
&& raw->mtp().environment() == environment) {
|
||||||
|
found = true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
if (!found && domain.accounts().size() >= domain.maxAccounts()) {
|
||||||
|
_controller->show(
|
||||||
|
Box(AccountsLimitBox, &_controller->session()));
|
||||||
|
} else if (newWindow) {
|
||||||
|
domain.addActivated(environment, true);
|
||||||
|
} else {
|
||||||
|
_controller->window().preventOrInvoke([=] {
|
||||||
|
_controller->session().domain().addActivated(environment);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
button->setAcceptBoth(true);
|
button->setAcceptBoth(true);
|
||||||
button->clicks(
|
button->clicks(
|
||||||
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
||||||
if (which == Qt::LeftButton) {
|
if (which == Qt::LeftButton) {
|
||||||
add(MTP::Environment::Production);
|
const auto modifiers = button->clickModifiers();
|
||||||
|
const auto newWindow = (modifiers & Qt::ControlModifier)
|
||||||
|
&& base::options::lookup<bool>(
|
||||||
|
Dialogs::kOptionCtrlClickChatNewWindow).value();
|
||||||
|
add(Environment::Production, newWindow);
|
||||||
return;
|
return;
|
||||||
} else if (which != Qt::RightButton
|
} else if (which != Qt::RightButton
|
||||||
|| !IsAltShift(button->clickModifiers())) {
|
|| !IsAltShift(button->clickModifiers())) {
|
||||||
|
@ -802,10 +817,10 @@ not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
|
||||||
}
|
}
|
||||||
_contextMenu = base::make_unique_q<Ui::PopupMenu>(_outer);
|
_contextMenu = base::make_unique_q<Ui::PopupMenu>(_outer);
|
||||||
_contextMenu->addAction("Production Server", [=] {
|
_contextMenu->addAction("Production Server", [=] {
|
||||||
add(MTP::Environment::Production);
|
add(Environment::Production);
|
||||||
});
|
});
|
||||||
_contextMenu->addAction("Test Server", [=] {
|
_contextMenu->addAction("Test Server", [=] {
|
||||||
add(MTP::Environment::Test);
|
add(Environment::Test);
|
||||||
});
|
});
|
||||||
_contextMenu->popup(QCursor::pos());
|
_contextMenu->popup(QCursor::pos());
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
|
|
|
@ -1689,10 +1689,7 @@ void SessionController::showPeerHistory(
|
||||||
PeerId peerId,
|
PeerId peerId,
|
||||||
const SectionShow ¶ms,
|
const SectionShow ¶ms,
|
||||||
MsgId msgId) {
|
MsgId msgId) {
|
||||||
content()->showPeerHistory(peerId, params, msgId);
|
content()->showHistory(peerId, params, msgId);
|
||||||
if (peerId && params.activation != anim::activation::background) {
|
|
||||||
_window->activate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionController::showMessage(
|
void SessionController::showMessage(
|
||||||
|
|
Loading…
Add table
Reference in a new issue