Prevent jumping of tray menu

Instead of adding the "Apps" menu after the apps are fetched, add it
from the start (together with other actions) but in a disabled state,
and enable it after the apps data is ready.

Signed-off-by: Sergey Zolotarev <sryze@protonmail.com>
This commit is contained in:
Sergey Zolotarev 2019-10-05 21:54:09 +06:00
parent 998354b5ab
commit f6b6765424
2 changed files with 12 additions and 6 deletions

View file

@ -675,6 +675,12 @@ void ownCloudGui::updateContextMenu()
_contextMenu->addSeparator(); _contextMenu->addSeparator();
if (_navLinksMenu) {
_contextMenu->addMenu(_navLinksMenu);
}
_contextMenu->addSeparator();
if (accountList.isEmpty()) { if (accountList.isEmpty()) {
_contextMenu->addAction(_actionNewAccountWizard); _contextMenu->addAction(_actionNewAccountWizard);
} }
@ -688,6 +694,7 @@ void ownCloudGui::updateContextMenu()
} }
_contextMenu->addSeparator(); _contextMenu->addSeparator();
if (atLeastOnePaused) { if (atLeastOnePaused) {
QString text; QString text;
if (accountList.count() > 1) { if (accountList.count() > 1) {
@ -777,6 +784,8 @@ void ownCloudGui::setupActions()
{ {
_actionStatus = new QAction(tr("Unknown status"), this); _actionStatus = new QAction(tr("Unknown status"), this);
_actionStatus->setEnabled(false); _actionStatus->setEnabled(false);
_navLinksMenu = new QMenu(tr("Apps"));
_navLinksMenu->setEnabled(false);
_actionSettings = new QAction(tr("Settings..."), this); _actionSettings = new QAction(tr("Settings..."), this);
_actionNewAccountWizard = new QAction(tr("New account..."), this); _actionNewAccountWizard = new QAction(tr("New account..."), this);
_actionRecent = new QAction(tr("View more activity..."), this); _actionRecent = new QAction(tr("View more activity..."), this);
@ -819,7 +828,6 @@ void ownCloudGui::fetchNavigationApps(AccountStatePtr account){
void ownCloudGui::buildNavigationAppsMenu(AccountStatePtr account, QMenu *accountMenu){ void ownCloudGui::buildNavigationAppsMenu(AccountStatePtr account, QMenu *accountMenu){
auto navLinks = _navApps.value(account); auto navLinks = _navApps.value(account);
if(navLinks.size() > 0){ if(navLinks.size() > 0){
// when there is only one account add the nav links above the settings // when there is only one account add the nav links above the settings
QAction *actionBefore = _actionSettings; QAction *actionBefore = _actionSettings;
@ -838,17 +846,14 @@ void ownCloudGui::buildNavigationAppsMenu(AccountStatePtr account, QMenu *accoun
} }
// Create submenu with links // Create submenu with links
QMenu *navLinksMenu = new QMenu(tr("Apps"));
accountMenu->insertSeparator(actionBefore);
accountMenu->insertMenu(actionBefore, navLinksMenu);
foreach (const QJsonValue &value, navLinks) { foreach (const QJsonValue &value, navLinks) {
auto navLink = value.toObject(); auto navLink = value.toObject();
QAction *action = new QAction(navLink.value("name").toString(), this); QAction *action = new QAction(navLink.value("name").toString(), this);
QUrl href(navLink.value("href").toString()); QUrl href(navLink.value("href").toString());
connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); }); connect(action, &QAction::triggered, this, [href] { QDesktopServices::openUrl(href); });
navLinksMenu->addAction(action); _navLinksMenu->addAction(action);
} }
accountMenu->insertSeparator(actionBefore); _navLinksMenu->setEnabled(true);
} }
} }

View file

@ -168,6 +168,7 @@ private:
QAction *_actionQuit; QAction *_actionQuit;
QAction *_actionCrash; QAction *_actionCrash;
QMenu *_navLinksMenu;
QMap<AccountStatePtr, QJsonArray> _navApps; QMap<AccountStatePtr, QJsonArray> _navApps;
QList<QAction *> _recentItemsActions; QList<QAction *> _recentItemsActions;