mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
cloudproviders keep track of the length of the main menu items
cloudproviderwrapper creates (and provides a menu model) that is used to populate a menu within file managers. The menu includes a submenu of recent activity that has no limit on the maximum number of characters. In order to create a more reasonably sized menu, let's keep track of the width of the items in the main menu as a baseline for the width of the items in the submenu. This is done dynamically in order to account for translations Signed-off-by: Corey Berla <corey@berla.me>
This commit is contained in:
parent
9b8b7d4d6b
commit
f65b736aa4
@ -13,6 +13,7 @@
|
||||
#include <account.h>
|
||||
#include <folder.h>
|
||||
#include <accountstate.h>
|
||||
#include <QApplication>
|
||||
#include <QDesktopServices>
|
||||
#include "openfilemanager.h"
|
||||
#include "owncloudgui.h"
|
||||
@ -21,6 +22,7 @@
|
||||
using namespace OCC;
|
||||
|
||||
GSimpleActionGroup *actionGroup = nullptr;
|
||||
int preferredTextWidth = 0;
|
||||
|
||||
CloudProviderWrapper::CloudProviderWrapper(QObject *parent, Folder *folder, int folderId, CloudProvidersProviderExporter* cloudprovider) : QObject(parent)
|
||||
, _folder(folder)
|
||||
@ -198,6 +200,13 @@ void CloudProviderWrapper::slotSyncFinished(const SyncResult &result)
|
||||
updateStatusText(result.statusString());
|
||||
}
|
||||
|
||||
static GMenuItem* addMenuItem(const QString text, const gchar *action)
|
||||
{
|
||||
QFontMetrics fm = QApplication::fontMetrics();
|
||||
preferredTextWidth = MAX (preferredTextWidth, (fm.boundingRect (text)).width ());
|
||||
return menu_item_new (text, action);
|
||||
}
|
||||
|
||||
GMenuModel* CloudProviderWrapper::getMenuModel() {
|
||||
|
||||
GMenu* section = nullptr;
|
||||
@ -207,14 +216,14 @@ GMenuModel* CloudProviderWrapper::getMenuModel() {
|
||||
_mainMenu = g_menu_new();
|
||||
|
||||
section = g_menu_new();
|
||||
item = menu_item_new(tr("Open website"), "cloudprovider.openwebsite");
|
||||
item = addMenuItem(tr("Open website"), "cloudprovider.openwebsite");
|
||||
g_menu_append_item(section, item);
|
||||
g_clear_object (&item);
|
||||
g_menu_append_section(_mainMenu, nullptr, G_MENU_MODEL(section));
|
||||
g_clear_object (§ion);
|
||||
|
||||
_recentMenu = g_menu_new();
|
||||
item = menu_item_new(tr("No recently changed files"), nullptr);
|
||||
item = addMenuItem(tr("No recently changed files"), nullptr);
|
||||
g_menu_append_item(_recentMenu, item);
|
||||
g_clear_object (&item);
|
||||
|
||||
@ -226,23 +235,23 @@ GMenuModel* CloudProviderWrapper::getMenuModel() {
|
||||
g_clear_object (§ion);
|
||||
|
||||
section = g_menu_new();
|
||||
item = menu_item_new(tr("Pause synchronization"), "cloudprovider.pause");
|
||||
item = addMenuItem (tr("Pause synchronization"), "cloudprovider.pause");
|
||||
g_menu_append_item(section, item);
|
||||
g_clear_object (&item);
|
||||
g_menu_append_section(_mainMenu, nullptr, G_MENU_MODEL(section));
|
||||
g_clear_object (§ion);
|
||||
|
||||
section = g_menu_new();
|
||||
item = menu_item_new(tr("Help"), "cloudprovider.openhelp");
|
||||
item = addMenuItem(tr("Help"), "cloudprovider.openhelp");
|
||||
g_menu_append_item(section, item);
|
||||
g_clear_object (&item);
|
||||
item = menu_item_new(tr("Settings"), "cloudprovider.opensettings");
|
||||
item = addMenuItem(tr("Settings"), "cloudprovider.opensettings");
|
||||
g_menu_append_item(section, item);
|
||||
g_clear_object (&item);
|
||||
item = menu_item_new(tr("Log out"), "cloudprovider.logout");
|
||||
item = addMenuItem(tr("Log out"), "cloudprovider.logout");
|
||||
g_menu_append_item(section, item);
|
||||
g_clear_object (&item);
|
||||
item = menu_item_new(tr("Quit sync client"), "cloudprovider.quit");
|
||||
item = addMenuItem(tr("Quit sync client"), "cloudprovider.quit");
|
||||
g_menu_append_item(section, item);
|
||||
g_clear_object (&item);
|
||||
g_menu_append_section(_mainMenu, nullptr, G_MENU_MODEL(section));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user