summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-03-12 21:03:04 +0000
committerMaxim Monastirsky <momonasmon@gmail.com>2016-03-13 19:49:23 +0000
commitf9b729dba5d1dd9a87241284a67ee4dfc91bee2f (patch)
tree80e5ad249800ca3c7331486f5f04da0b21ea8f8b
parent46dac6598b066a43db851a5764778cfa1207e97d (diff)
Resolves: tdf#92067 with duplicate menu entries track which to activate
rather than just stick 2/3/4 at the end embed that this is a dup as the prefix and strip that off at dispatch time and pass the dup index around as a counter to how many dup candidates to dismiss to find the desired one. (cherry picked from commit e22618a355c0e506b8cfac9c52e9564db26949d2) Change-Id: I81d97090a7e9b8c2995a3b27934f3ee5636d05fe Reviewed-on: https://gerrit.libreoffice.org/23183 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com> Tested-by: Maxim Monastirsky <momonasmon@gmail.com>
-rw-r--r--vcl/inc/unx/gtk/gtksalmenu.hxx2
-rw-r--r--vcl/unx/gtk/gtksalmenu.cxx42
2 files changed, 36 insertions, 8 deletions
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index 5d9c26256a69..011c3e43930e 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -51,7 +51,7 @@ private:
GMenuModel* mpMenuModel;
GActionGroup* mpActionGroup;
- GtkSalMenu* GetMenuForItemCommand( gchar* aCommand, gboolean bGetSubmenu );
+ GtkSalMenu* GetMenuForItemCommand( gchar* aCommand, int& rDupsToSkip, gboolean bGetSubmenu );
void ImplUpdate( gboolean bRecurse );
void ActivateAllSubmenus(MenuBar* pMenuBar);
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index 6b977fec1acf..b6295faf6ba0 100644
--- a/vcl/unx/gtk/gtksalmenu.cxx
+++ b/vcl/unx/gtk/gtksalmenu.cxx
@@ -57,14 +57,14 @@ static gchar* GetCommandForItem( GtkSalMenuItem* pSalMenuItem, gchar* aCurrentCo
aCommand = g_strdup( aCommandStr );
// Some items could have duplicated commands. A new one should be generated.
- for ( sal_uInt16 i = 2; ; i++ )
+ for ( sal_uInt16 i = 1; ; i++ )
{
if ( !g_action_group_has_action( pActionGroup, aCommand )
|| ( aCurrentCommand && g_strcmp0( aCurrentCommand, aCommand ) == 0 ) )
break;
g_free( aCommand );
- aCommand = g_strdup_printf("%s%d", aCommandStr, i);
+ aCommand = g_strdup_printf("dup:%d:%s", i, aCommandStr);
}
g_free( aCommandStr );
@@ -630,7 +630,7 @@ void GtkSalMenu::NativeSetItemCommand( unsigned nSection,
g_variant_unref(pTarget);
}
-GtkSalMenu* GtkSalMenu::GetMenuForItemCommand( gchar* aCommand, gboolean bGetSubmenu )
+GtkSalMenu* GtkSalMenu::GetMenuForItemCommand(gchar* aCommand, int& rDupsToSkip, gboolean bGetSubmenu)
{
SolarMutexGuard aGuard;
GtkSalMenu* pMenu = nullptr;
@@ -645,7 +645,13 @@ GtkSalMenu* GtkSalMenu::GetMenuForItemCommand( gchar* aCommand, gboolean bGetSub
OString aItemCommandOStr = OUStringToOString( aItemCommand, RTL_TEXTENCODING_UTF8 );
gchar* aItemCommandStr = const_cast<gchar*>(aItemCommandOStr.getStr());
- if ( g_strcmp0( aItemCommandStr, aCommand ) == 0 )
+ bool bFound = g_strcmp0( aItemCommandStr, aCommand ) == 0;
+ if (bFound && rDupsToSkip)
+ {
+ --rDupsToSkip;
+ bFound = false;
+ }
+ if (bFound)
{
pMenu = bGetSubmenu ? pSalItem->mpSubMenu : this;
break;
@@ -653,7 +659,7 @@ GtkSalMenu* GtkSalMenu::GetMenuForItemCommand( gchar* aCommand, gboolean bGetSub
else
{
if ( pSalItem->mpSubMenu != nullptr )
- pMenu = pSalItem->mpSubMenu->GetMenuForItemCommand( aCommand, bGetSubmenu );
+ pMenu = pSalItem->mpSubMenu->GetMenuForItemCommand(aCommand, rDupsToSkip, bGetSubmenu);
if ( pMenu != nullptr )
break;
@@ -663,6 +669,24 @@ GtkSalMenu* GtkSalMenu::GetMenuForItemCommand( gchar* aCommand, gboolean bGetSub
return pMenu;
}
+namespace
+{
+ const gchar* DetermineDupIndex(const gchar *aCommand, int& rDupsToSkip)
+ {
+ if (g_str_has_prefix(aCommand, "dup:"))
+ {
+ aCommand = aCommand + strlen("dup:");
+ gchar *endptr;
+ rDupsToSkip = g_ascii_strtoll(aCommand, &endptr, 10);
+ aCommand = endptr+1;
+ }
+ else
+ rDupsToSkip = 0;
+
+ return aCommand;
+ }
+}
+
void GtkSalMenu::DispatchCommand( gint itemId, const gchar *aCommand )
{
SolarMutexGuard aGuard;
@@ -670,7 +694,9 @@ void GtkSalMenu::DispatchCommand( gint itemId, const gchar *aCommand )
if ( !mbMenuBar )
return;
- GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( const_cast<gchar*>(aCommand), FALSE );
+ int nDupsToSkip;
+ aCommand = DetermineDupIndex(aCommand, nDupsToSkip);
+ GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( const_cast<gchar*>(aCommand), nDupsToSkip, FALSE );
Menu* pSubMenu = ( pSalSubMenu != nullptr ) ? pSalSubMenu->GetMenu() : nullptr;
MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu );
@@ -703,7 +729,9 @@ void GtkSalMenu::Deactivate( const gchar* aMenuCommand )
if ( !mbMenuBar )
return;
- GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( const_cast<gchar*>(aMenuCommand), TRUE );
+ int nDupsToSkip;
+ aMenuCommand = DetermineDupIndex(aMenuCommand, nDupsToSkip);
+ GtkSalMenu* pSalSubMenu = GetMenuForItemCommand( const_cast<gchar*>(aMenuCommand), nDupsToSkip, TRUE );
if ( pSalSubMenu != nullptr ) {
MenuBar* pMenuBar = static_cast< MenuBar* >( mpVCLMenu );