2 * (C) Copyright 2008 David Glasser
3 * (C) Copyright 2008 Will Farrington
4 * (C) Copyright 2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
10 require("content-buffer.js");
11 require("bindings/default/content-buffer/normal.js");
12 require("bindings/default/content-buffer/richedit.js");
13 require("bindings/default/content-buffer/text.js");
14 require("bindings/default/content-buffer/textarea.js");
16 define_keymap("gmail_keymap", $parent = content_buffer_normal_keymap);
18 function gmail_label_go(buffer, label)
20 buffer.window.content.location.hash = "#label/" + encodeURIComponent(label);
22 interactive("gmail-label-go",
23 "Go to a GMail label.",
25 gmail_label_go(I.buffer, (yield I.minibuffer.read($prompt = "Go to label: ")));
29 let gmail_bind_common = function (keymap) {
30 define_key(keymap, "C-c C-g", "gmail-label-go");
32 // Rebind overridden commands
33 define_key(keymap, "C-c g", "find-url");
34 define_key(keymap, "C-c c", "copy");
35 define_key(keymap, "C-c x", "shell-command-on-file");
36 define_key(keymap, "C-c s", "save");
37 define_key(keymap, "C-c r", "reload");
38 define_key(keymap, "C-c f", "follow");
39 define_key(keymap, "C-c t", "follow-top");
41 define_key(keymap, "tab", null, $fallthrough);
42 define_key(keymap, "escape", "gmail-focus-primary-frame");
45 gmail_bind_common(gmail_keymap);
48 define_key(gmail_keymap, "g", null, $fallthrough);
49 define_key(gmail_keymap, "i", null, $fallthrough);
50 define_key(gmail_keymap, "t", null, $fallthrough);
51 define_key(gmail_keymap, "d", null, $fallthrough);
52 define_key(gmail_keymap, "a", null, $fallthrough);
55 define_key(gmail_keymap, "*", null, $fallthrough);
58 define_key(gmail_keymap, "u", null, $fallthrough);
59 define_key(gmail_keymap, "j", null, $fallthrough);
60 define_key(gmail_keymap, "k", null, $fallthrough);
61 define_key(gmail_keymap, "o", null, $fallthrough);
62 define_key(gmail_keymap, "n", null, $fallthrough);
63 define_key(gmail_keymap, "p", null, $fallthrough);
66 define_key(gmail_keymap, "c", null, $fallthrough);
67 define_key(gmail_keymap, "/", null, $fallthrough);
68 define_key(gmail_keymap, "q", null, $fallthrough);
69 define_key(gmail_keymap, "?", null, $fallthrough);
72 define_key(gmail_keymap, "x", null, $fallthrough);
73 define_key(gmail_keymap, "s", null, $fallthrough);
74 define_key(gmail_keymap, "y", null, $fallthrough);
75 define_key(gmail_keymap, "e", null, $fallthrough);
76 define_key(gmail_keymap, "m", null, $fallthrough);
77 define_key(gmail_keymap, "!", null, $fallthrough);
78 define_key(gmail_keymap, "#", null, $fallthrough);
79 define_key(gmail_keymap, "r", null, $fallthrough);
80 define_key(gmail_keymap, "f", null, $fallthrough);
81 define_key(gmail_keymap, "S-n", null, $fallthrough);
82 define_key(gmail_keymap, ".", null, $fallthrough);
83 define_key(gmail_keymap, "S-i", null, $fallthrough);
84 define_key(gmail_keymap, "S-u", null, $fallthrough);
85 define_key(gmail_keymap, "]", null, $fallthrough);
86 define_key(gmail_keymap, "[", null, $fallthrough);
88 define_keymap("gmail_richedit_keymap", $parent = content_buffer_richedit_keymap);
89 gmail_bind_common(gmail_richedit_keymap);
91 define_keymap("gmail_text_keymap", $parent = content_buffer_text_keymap);
92 gmail_bind_common(gmail_text_keymap);
94 define_keymap("gmail_textarea_keymap", $parent = content_buffer_textarea_keymap);
95 gmail_bind_common(gmail_textarea_keymap);
98 function gmail_focus_primary_frame(buffer) {
99 var frames = buffer.top_frame.frames;
100 if (frames.length >= 4)
101 buffer.top_frame.frames[3].focus();
103 interactive("gmail-focus-primary-frame", "Focus the main GMail frame.",
104 function (I) {gmail_focus_primary_frame(I.buffer); unfocus(I.window, I.buffer);});
106 define_page_mode("gmail_mode", "GMail",
107 $enable = function (buffer) {
108 buffer.local_variables.content_buffer_normal_keymap = gmail_keymap;
109 buffer.local_variables.content_buffer_richedit_keymap = gmail_richedit_keymap;
110 buffer.local_variables.content_buffer_text_keymap = gmail_richedit_keymap;
111 buffer.local_variables.content_buffer_textarea_keymap = gmail_richedit_keymap;
112 add_hook.call(buffer, "buffer_dom_content_loaded_hook", gmail_focus_primary_frame);
114 $disable = function (buffer) {
115 remove_hook.call(buffer, "buffer_dom_content_loaded_hook", gmail_focus_primary_frame);
118 var gmail_re = build_url_regex($domain = "mail.google");
119 auto_mode_list.push([gmail_re, gmail_mode]);