Add facilities for querying information about installed extensions
[conkeror.git] / content / gui_context_menu.js
blob46182cba3cd5716d1c9c9d785b3b0017f708d7a6
2 /// Get our localized strings.
3 /// 
4 var contextmenu_sb = add_stringbundle ("contextmenu_sb", "chrome://conkeror/locale/gui_context_menu.properties");
6 var the_gui_context_menu = null;
9 function gui_context_menu (menu) {
10     this.methods = context_methods (document.popupNode);
11     // initialize the gui menu here.
12     //
13     this.menu_root = document.getElementById ("contentAreaContextMenu");
14     this.contextmenu_add_link_items (this.methods);
15     this.contextmenu_add_image_items (this.methods);
16     this.contextmenu_add_nav_items (this.methods);
17     this.contextmenu_add_page_items (this.methods);
18     this.contextmenu_add_background_image_items (this.methods);
19     this.contextmenu_add_edit_items (this.methods);
20     if ('frame' in this.methods)
21         this.contextmenu_add_frame_items (this.methods);
22     this.contextmenu_add_source_items (this.methods);
23     return this;
27 gui_context_menu.prototype = {
28 menu_root: null,
29 methods: {},
30 call: function (method_interface, method) {
31         if (method_interface in this.methods &&
32             method in this.methods[method_interface])
33         {
34             this.methods[method_interface][method] ();
35         } // XXX: else throw, or message something?
36     },
37 has_methods: function () {
38         if (! has_properties_p (this.methods))
39             return false;
40         return true;
41     },
42 destroy: function () {
43         var menu_root = document.getElementById ("contentAreaContextMenu");
44         for (var i = menu_root.childNodes.length -1; i >= 0; i --)
45             menu_root.removeChild(menu_root.childNodes[i]);
46     },
48 ///
49 /// DOM Procedures for the menu gui.
50 ///
51 add_contextmenu_item : function (label, key, oncommand) {
52         var menuitem = add_menuitem (this.menu_root, null, label, key, oncommand);
53     },
55 add_contextmenu_separator : function () {
56         var menuitem = add_menuseparator (this.menu_root);
57     },
59 add_contextmenu_submenu : function (label, key) {
60         var menuitem = add_submenu (this.menu_root, null, label, key);
61         return add_menupopup (menuitem);
62     },
64 context_add_maybe : function (iface, method) {
65         if (iface in this.methods &&
66             method in this.methods[iface])
67         {
68             this.add_contextmenu_item (contextmenu_sb.getString ("context_"+method+".label"),
69                                        contextmenu_sb.getString ("context_"+method+".accesskey"),
70                                        "the_gui_context_menu.call ('"+iface+"','"+method+"');");
71             return true;
72         }
73         return false;
74     },
76 ///
77 /// Procedures to add specific menu items.
78 /// 
79 contextmenu_add_link_items : function () {
80         var sep = false;
81         sep = sep | this.context_add_maybe ('link', 'follow_link');
82         sep = sep | this.context_add_maybe ('link', 'follow_link_in_buffer');
83         sep = sep | this.context_add_maybe ('link', 'follow_link_in_frame');
84         if (sep) this.add_contextmenu_separator ();
85         sep = false;
86         sep = sep | this.context_add_maybe ('link', 'save_link');
87         sep = sep | this.context_add_maybe ('link', 'copy_email');
88         sep = sep | this.context_add_maybe ('link', 'copy_link');
89         if (sep) this.add_contextmenu_separator ();
90     },
92 contextmenu_add_image_items : function () {
93         var sep = false;
94         sep = sep | this.context_add_maybe ('image', 'follow_image');
95         sep = sep | this.context_add_maybe ('image', 'copy_image');
96         if (sep) this.add_contextmenu_separator ();
97         sep = false;
98         sep = sep | this.context_add_maybe ('image', 'save_image');
99     },
101 contextmenu_add_nav_items : function () {
102         var sep = false;
103         sep = sep | this.context_add_maybe ('nav', 'back');
104         sep = sep | this.context_add_maybe ('nav', 'forward');
105         sep = sep | this.context_add_maybe ('nav', 'stop');
106         sep = sep | this.context_add_maybe ('nav', 'reload');
107         if (sep) this.add_contextmenu_separator ();
108     },
110 contextmenu_add_page_items : function () {
111         this.context_add_maybe ('page', 'save_page');
112     },
114 contextmenu_add_background_image_items : function () {
115         if ('background_image' in this.methods)
116             this.add_contextmenu_separator ();
117         this.context_add_maybe ('background_image', 'follow_background_image');
118     },
120 contextmenu_add_edit_items : function () {
121         var sep = false;
122         sep = sep | this.context_add_maybe ('edit', 'undo');
123         if (sep) this.add_contextmenu_separator ();
124         sep = false;
125         sep = sep | this.context_add_maybe ('edit', 'cut');
126         sep = sep | this.context_add_maybe ('edit', 'copy');
127         sep = sep | this.context_add_maybe ('edit', 'paste');
128         sep = sep | this.context_add_maybe ('edit', 'delete');
129         if (sep) this.add_contextmenu_separator ();
130         sep = false;
131         sep = sep | this.context_add_maybe ('edit', 'select_all');
132         if (sep) this.add_contextmenu_separator ();
133     },
135 contextmenu_add_frame_items : function () {
136         if ('frame' in this.methods)
137             this.add_contextmenu_separator ();
139         var frame_submenu = this.add_contextmenu_submenu (contextmenu_sb.getString ("thisFrameMenu.label"),
140                                                           contextmenu_sb.getString ("thisFrameMenu.accesskey"));
142         var methods = this.methods;
144         function frame_menu_add_maybe (method)
145         {
146             if (method in methods.frame)
147             {
148                 add_menuitem (frame_submenu,
149                               null,
150                               contextmenu_sb.getString ("context_"+method+".label"),
151                               contextmenu_sb.getString ("context_"+method+".accesskey"),
152                               "the_gui_context_menu.call ('frame','"+method+"');");
153                 return true;
154             }
155             return false;
156         }
158         frame_menu_add_maybe ('show_only_this_frameset_frame');
159         frame_menu_add_maybe ('open_frameset_frame_in_buffer');
160         frame_menu_add_maybe ('open_frameset_frame_in_frame');
161         add_menuseparator (frame_submenu);
162         frame_menu_add_maybe ('reload_frameset_frame');
163         add_menuseparator (frame_submenu);
164         frame_menu_add_maybe ('save_frameset_frame_page');
165         add_menuseparator (frame_submenu);
166         frame_menu_add_maybe ('view_frameset_frame_source');
167     },
169 contextmenu_add_source_items : function () {
170         if ('source' in this.methods) this.add_contextmenu_separator ();
171         var sep = false;
172         sep = sep | this.context_add_maybe ('source', 'view_selection_source');
173         sep = sep | this.context_add_maybe ('source', 'view_mathml_source');
174         sep = sep | this.context_add_maybe ('source', 'view_source');
175     }