]> git.lyx.org Git - lyx.git/commitdiff
Display accelerator (binding) labels in menus.
authorJohn Spray <spray@lyx.org>
Sat, 2 Oct 2004 23:21:36 +0000 (23:21 +0000)
committerJohn Spray <spray@lyx.org>
Sat, 2 Oct 2004 23:21:36 +0000 (23:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9035 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/gtk/GLyXKeySym.C
src/frontends/gtk/GMenubar.C

index 86d7855ddd92561bd088526622451e659421fe83..e345bfe26db5d00520ae28bc58e0f4c04103b5fd 100644 (file)
@@ -13,6 +13,8 @@
 #include "GLyXKeySym.h"
 #include "kbmap.h"
 
+#include "support/lstrings.h"
+
 #include <gtkmm.h>
 #include <gdk/gdkkeysyms.h>
 
@@ -94,9 +96,27 @@ char GLyXKeySym::getISOEncoded(string const & /*encoding*/) const
 }
 
 
+//Produce a human readable version (eg "Ctrl+N")
 string const GLyXKeySym::print(key_modifier::state mod) const
 {
-       return kb_keymap::printKeySym(*this, mod);
+       string buf;
+
+       if (mod & key_modifier::ctrl)
+               buf += "Ctrl+";
+       if (mod & key_modifier::shift)
+               buf += "Shift+";
+       if (mod & key_modifier::alt)
+               buf += "Alt+";
+
+       //Uppercase the first letter, for Ctrl+N rather than Ctrl+n,
+       //and for Ctrl+Greater rather than Ctrl+GREATER
+       string symname = getSymbolName();
+  if (!symname.empty()) {
+         symname[0] = lyx::support::uppercase(symname[0]);
+         buf += symname;
+       }
+
+       return buf;
 }
 
 
index df2b90ac92cb08ed2b64aceaa548bf5796bfe9b1..45a2159d62a9fb364c1ee93ce843ac7691ff6338 100644 (file)
@@ -180,9 +180,6 @@ void GMenubar::onSubMenuActivate(MenuItem const * item,
                        break;
                case MenuItem::Command:
                {
-#ifdef WITH_WARNINGS
-#warning Bindings are not inserted into the menu labels here. (Lgb)
-#endif
                        FuncStatus const flag =
                                view_->getLyXFunc().getStatus(i->func());
                        bool on = flag.onoff(true);
@@ -198,10 +195,21 @@ void GMenubar::onSubMenuActivate(MenuItem const * item,
                                                gmenu->items().back());
                                citem.set_active(on);
                        } else {
-                               gmenu->items().push_back(
-                                       Gtk::Menu_Helpers::MenuElem(
-                                               labelTrans(i->label(),
-                                                          i->shortcut())));
+                               //This is necessary because add_accel_label is protected,
+                               //and even if you subclass Gtk::MenuItem then add_accel_label
+                               //doesn't do what you'd expect.
+                               Gtk::MenuItem * item = Gtk::manage(new Gtk::MenuItem);
+                               Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox);
+                               Gtk::Label * label1 = Gtk::manage(new Gtk::Label(
+                                       labelTrans(i->label(), i->shortcut()), true));
+                               Gtk::Label * label2 = Gtk::manage(new Gtk::Label(
+                                       "   " + i->binding(), false));
+                               hbox->pack_start(*label1, false, false, 0);
+                               hbox->pack_end(*label2, false, false, 0);
+                               item->add(*hbox);
+
+                               gmenu->append(*item);
+                               item->show_all();
                        }
                        Gtk::MenuItem & item = gmenu->items().back();
                        item.signal_activate().connect(