mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +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;
|
||||
}
|
||||
|
||||
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()) {
|
||||
activate(add(environment));
|
||||
added(add(environment));
|
||||
} else {
|
||||
for (auto &[index, account] : accounts()) {
|
||||
if (!account->sessionExists()
|
||||
&& account->mtp().environment() == environment) {
|
||||
activate(account.get());
|
||||
added(account.get());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
[[nodiscard]] not_null<Main::Account*> add(MTP::Environment environment);
|
||||
void maybeActivate(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.
|
||||
void accountAddedInStorage(AccountWithIndex accountWithIndex);
|
||||
|
|
|
@ -1294,7 +1294,7 @@ bool MainWidget::showHistoryInDifferentWindow(
|
|||
return true;
|
||||
}
|
||||
|
||||
void MainWidget::showPeerHistory(
|
||||
void MainWidget::showHistory(
|
||||
PeerId peerId,
|
||||
const SectionShow ¶ms,
|
||||
MsgId showAtMsgId) {
|
||||
|
@ -1311,6 +1311,7 @@ void MainWidget::showPeerHistory(
|
|||
Assert(isPrimary());
|
||||
if (params.activation != anim::activation::background) {
|
||||
_controller->show(Ui::MakeInformBox(unavailable));
|
||||
_controller->window().activate();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1324,9 +1325,13 @@ void MainWidget::showPeerHistory(
|
|||
return;
|
||||
}
|
||||
|
||||
if (peerId && params.activation != anim::activation::background) {
|
||||
_controller->window().activate();
|
||||
}
|
||||
|
||||
if (!(_history->peer() && _history->peer()->id == peerId)
|
||||
&& preventsCloseSection(
|
||||
[=] { showPeerHistory(peerId, params, showAtMsgId); },
|
||||
[=] { showHistory(peerId, params, showAtMsgId); },
|
||||
params)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1490,7 +1495,7 @@ void MainWidget::showMessage(
|
|||
return;
|
||||
}
|
||||
} else if (_history->peer() == item->history()->peer) {
|
||||
showPeerHistory(peerId, params, itemId);
|
||||
showHistory(peerId, params, itemId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ public:
|
|||
|
||||
void toggleChooseChatTheme(not_null<PeerData*> peer);
|
||||
|
||||
void showPeerHistory(
|
||||
void showHistory(
|
||||
PeerId peer,
|
||||
const SectionShow ¶ms,
|
||||
MsgId msgId);
|
||||
|
|
|
@ -778,23 +778,38 @@ not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
|
|||
})))->setDuration(0);
|
||||
const auto button = result->entity();
|
||||
|
||||
const auto add = [=](MTP::Environment environment) {
|
||||
Core::App().preventOrInvoke([=] {
|
||||
auto &domain = _controller->session().domain();
|
||||
if (domain.accounts().size() >= domain.maxAccounts()) {
|
||||
_controller->show(
|
||||
Box(AccountsLimitBox, &_controller->session()));
|
||||
} else {
|
||||
domain.addActivated(environment);
|
||||
using Environment = MTP::Environment;
|
||||
const auto add = [=](Environment environment, bool newWindow = false) {
|
||||
auto &domain = _controller->session().domain();
|
||||
auto found = false;
|
||||
for (const auto &[index, account] : domain.accounts()) {
|
||||
const auto raw = account.get();
|
||||
if (!raw->sessionExists()
|
||||
&& 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->clicks(
|
||||
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
||||
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;
|
||||
} else if (which != Qt::RightButton
|
||||
|| !IsAltShift(button->clickModifiers())) {
|
||||
|
@ -802,10 +817,10 @@ not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
|
|||
}
|
||||
_contextMenu = base::make_unique_q<Ui::PopupMenu>(_outer);
|
||||
_contextMenu->addAction("Production Server", [=] {
|
||||
add(MTP::Environment::Production);
|
||||
add(Environment::Production);
|
||||
});
|
||||
_contextMenu->addAction("Test Server", [=] {
|
||||
add(MTP::Environment::Test);
|
||||
add(Environment::Test);
|
||||
});
|
||||
_contextMenu->popup(QCursor::pos());
|
||||
}, button->lifetime());
|
||||
|
|
|
@ -1689,10 +1689,7 @@ void SessionController::showPeerHistory(
|
|||
PeerId peerId,
|
||||
const SectionShow ¶ms,
|
||||
MsgId msgId) {
|
||||
content()->showPeerHistory(peerId, params, msgId);
|
||||
if (peerId && params.activation != anim::activation::background) {
|
||||
_window->activate();
|
||||
}
|
||||
content()->showHistory(peerId, params, msgId);
|
||||
}
|
||||
|
||||
void SessionController::showMessage(
|
||||
|
|
Loading…
Add table
Reference in a new issue