changeset 1157:d4955772f3e0

Get key bindings for File menu
author corvid <corvid@lavabit.com>
date Fri, 05 Jun 2009 00:12:41 +0000
parents 3153db5d894a
children 752b1f8da34f
files src/keys.cc src/keys.hh src/menu.cc
diffstat 3 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/keys.cc	Mon Jun 01 05:15:10 2009 +0000
+++ b/src/keys.cc	Fri Jun 05 00:12:41 2009 +0000
@@ -239,6 +239,22 @@
 }
 
 /*
+ * Given a keys command, return a shortcut for it, or 0 if there is none
+ * (e.g., for KEYS_NEW_WINDOW, return CTRL+'n').
+ */
+int Keys::getShortcut(int command)
+{
+   int len = dList_length(bindings);
+
+   for (int i = 0; i < len; i++) {
+      KeyBinding_t *node = (KeyBinding_t*)dList_nth_data(bindings, i);
+      if (command == node->cmd)
+         return node->modifier + node->key;
+   }
+   return 0;
+}
+
+/*
  * Parse a key-combination/command-name pair, and
  * insert it into the bindings list.
  */
--- a/src/keys.hh	Mon Jun 01 05:15:10 2009 +0000
+++ b/src/keys.hh	Fri Jun 05 00:12:41 2009 +0000
@@ -47,6 +47,7 @@
    static int getCmdCode(const char *symbolName);
    static int getKeyCode(char *keyName);
    static int getModifier(char *modifierName);
+   static int getShortcut(int command);
    static void parseKey(char *key, char *symbol);
    static void parse(FILE *fp);
 };
--- a/src/menu.cc	Mon Jun 01 05:15:10 2009 +0000
+++ b/src/menu.cc	Fri Jun 05 00:12:41 2009 +0000
@@ -26,6 +26,7 @@
 #include "history.h"
 #include "html.hh"
 #include "ui.hh" // for (UI *)
+#include "keys.hh"
 #include "timeout.hh"
 
 using namespace fltk;
@@ -559,17 +560,24 @@
    popup_url = NULL;
 
    if (!pm) {
+      int shortcut;
       Item *i;
       pm = new PopupMenu(0,0,0,0,"File");
       pm->begin();
-       i = new Item("New Window", CTRL+'n', filemenu_cb, (void*)"nw");
-       i = new Item("New Tab", CTRL+'t', filemenu_cb, (void*)"nt");
+       shortcut = Keys::getShortcut(KEYS_NEW_WINDOW);
+       i = new Item("New Window", shortcut, filemenu_cb, (void*)"nw");
+       shortcut = Keys::getShortcut(KEYS_NEW_TAB);
+       i = new Item("New Tab", shortcut, filemenu_cb, (void*)"nt");
        new Divider();
-       i = new Item("Open File...", CTRL+'o', filemenu_cb, (void*)"of");
-       i = new Item("Open URL...", CTRL+'l', filemenu_cb, (void*)"ou");
-       i = new Item("Close", CTRL+'q', filemenu_cb, (void*)"cw");
+       shortcut = Keys::getShortcut(KEYS_OPEN);
+       i = new Item("Open File...", shortcut, filemenu_cb, (void*)"of");
+       shortcut = Keys::getShortcut(KEYS_GOTO);
+       i = new Item("Open URL...", shortcut, filemenu_cb, (void*)"ou");
+       shortcut = Keys::getShortcut(KEYS_CLOSE_TAB);
+       i = new Item("Close", shortcut, filemenu_cb, (void*)"cw");
        new Divider();
-       i = new Item("Exit Dillo", ALT+'q', filemenu_cb, (void*)"ed");
+       shortcut = Keys::getShortcut(KEYS_CLOSE_ALL);
+       i = new Item("Exit Dillo", shortcut, filemenu_cb, (void*)"ed");
       pm->type(PopupMenu::POPUP123);
       pm->end();
    }