aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcorvid <corvid@lavabit.com>2009-06-05 00:12:41 +0000
committercorvid <corvid@lavabit.com>2009-06-05 00:12:41 +0000
commit03949fea7859bb716ea4389fcf253d04a1b6c6fc (patch)
tree4af10e1b56e59a1c56b16ee88fccff01517ae4c2 /src
parent829e38e0ca1d214e00d8076120c50092f319d356 (diff)
Get key bindings for File menu
Diffstat (limited to 'src')
-rw-r--r--src/keys.cc16
-rw-r--r--src/keys.hh1
-rw-r--r--src/menu.cc20
3 files changed, 31 insertions, 6 deletions
diff --git a/src/keys.cc b/src/keys.cc
index e6f31fc4..17735822 100644
--- a/src/keys.cc
+++ b/src/keys.cc
@@ -239,6 +239,22 @@ int Keys::getModifier(char *modifierName)
}
/*
+ * 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.
*/
diff --git a/src/keys.hh b/src/keys.hh
index 9c47a635..cf3f57f3 100644
--- a/src/keys.hh
+++ b/src/keys.hh
@@ -47,6 +47,7 @@ public:
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);
};
diff --git a/src/menu.cc b/src/menu.cc
index 6ce67848..9757f523 100644
--- a/src/menu.cc
+++ b/src/menu.cc
@@ -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 @@ void a_Menu_file_popup(BrowserWindow *bw, void *v_wid)
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();
}