summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 23:56:35 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 23:56:35 +0000
commit6abef1768b1f65779bf520e39e6825752971d709 (patch)
tree2457493b5b683a738b62d701ade800e18c1cd4a4 /chrome/browser
parentc8816c164145d55d46635aface02072461d4824f (diff)
downloadchromium_src-6abef1768b1f65779bf520e39e6825752971d709.zip
chromium_src-6abef1768b1f65779bf520e39e6825752971d709.tar.gz
chromium_src-6abef1768b1f65779bf520e39e6825752971d709.tar.bz2
Add menu shortcuts on linux instead of & everywhere.
Review URL: http://codereview.chromium.org/21486 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/menu_gtk.cc30
1 files changed, 28 insertions, 2 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc
index db8da36..4efe09e 100644
--- a/chrome/browser/gtk/menu_gtk.cc
+++ b/chrome/browser/gtk/menu_gtk.cc
@@ -8,6 +8,30 @@
#include "base/string_util.h"
#include "chrome/common/l10n_util.h"
+namespace {
+
+// GTK uses _ for accelerators. Windows uses & with && as an escape for &.
+std::wstring ConvertAcceleratorsFromWindowsStyle(const std::wstring& label) {
+ std::wstring ret;
+ ret.reserve(label.length());
+ for (size_t i = 0; i < label.length(); ++i) {
+ if (L'&' == label[i]) {
+ if (i + 1 < label.length() && L'&' == label[i + 1]) {
+ ret.push_back(label[i]);
+ ++i;
+ } else {
+ ret.push_back(L'_');
+ }
+ } else {
+ ret.push_back(label[i]);
+ }
+ }
+
+ return ret;
+}
+
+}
+
MenuGtk::MenuGtk(MenuGtk::Delegate* delegate,
const MenuCreateMaterial* menu_data)
: delegate_(delegate),
@@ -58,9 +82,11 @@ void MenuGtk::BuildMenuIn(GtkWidget* menu,
DCHECK(menu_data->type == MENU_SEPARATOR) << "Menu definition broken";
}
+ label = ConvertAcceleratorsFromWindowsStyle(label);
+
switch (menu_data->type) {
case MENU_CHECKBOX:
- menu_item = gtk_check_menu_item_new_with_label(
+ menu_item = gtk_check_menu_item_new_with_mnemonic(
WideToUTF8(label).c_str());
break;
case MENU_SEPARATOR:
@@ -68,7 +94,7 @@ void MenuGtk::BuildMenuIn(GtkWidget* menu,
break;
case MENU_NORMAL:
default:
- menu_item = gtk_menu_item_new_with_label(WideToUTF8(label).c_str());
+ menu_item = gtk_menu_item_new_with_mnemonic(WideToUTF8(label).c_str());
break;
}