diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-03-12 21:03:04 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-03-12 21:05:07 +0000 |
commit | e22618a355c0e506b8cfac9c52e9564db26949d2 (patch) | |
tree | 2b61854023e71facc2959d93ba10b6899cab5056 | |
parent | 0cead356b8bc8983a0bd45a661b299dec8f64330 (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.
Change-Id: I81d97090a7e9b8c2995a3b27934f3ee5636d05fe
-rw-r--r-- | vcl/inc/unx/gtk/gtksalmenu.hxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk/gtksalmenu.cxx | 50 |
2 files changed, 43 insertions, 9 deletions
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx index 51cb4511f75e..8dadcfe7e40e 100644 --- a/vcl/inc/unx/gtk/gtksalmenu.hxx +++ b/vcl/inc/unx/gtk/gtksalmenu.hxx @@ -54,7 +54,7 @@ private: GMenuModel* mpMenuModel; GActionGroup* mpActionGroup; - GtkSalMenu* GetMenuForItemCommand( gchar* aCommand, gboolean bGetSubmenu ); + GtkSalMenu* GetMenuForItemCommand( gchar* aCommand, int& rDupsToSkip, gboolean bGetSubmenu ); void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries); void ActivateAllSubmenus(Menu* pMenuBar); diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 722d24269381..91b7f3576a5e 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -62,14 +62,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 ); @@ -867,7 +867,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; @@ -882,7 +882,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; @@ -890,7 +896,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; @@ -900,10 +906,32 @@ 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; - 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; mpVCLMenu->HandleMenuCommandEvent(pSubMenu, itemId); } @@ -930,7 +958,10 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand ) 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 ) { mpVCLMenu->HandleMenuActivateEvent( pSalSubMenu->mpVCLMenu ); @@ -940,7 +971,10 @@ void GtkSalMenu::Activate( const gchar* aMenuCommand ) void GtkSalMenu::Deactivate( const gchar* aMenuCommand ) { - 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 ) { mpVCLMenu->HandleMenuDeActivateEvent( pSalSubMenu->mpVCLMenu ); |