2 /// Get our localized strings.
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.
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);
27 gui_context_menu.prototype = {
30 call: function (method_interface, method) {
31 if (method_interface in this.methods &&
32 method in this.methods[method_interface])
34 this.methods[method_interface][method] ();
35 } // XXX: else throw, or message something?
37 has_methods: function () {
38 if (! has_properties_p (this.methods))
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]);
49 /// DOM Procedures for the menu gui.
51 add_contextmenu_item : function (label, key, oncommand) {
52 var menuitem = add_menuitem (this.menu_root, null, label, key, oncommand);
55 add_contextmenu_separator : function () {
56 var menuitem = add_menuseparator (this.menu_root);
59 add_contextmenu_submenu : function (label, key) {
60 var menuitem = add_submenu (this.menu_root, null, label, key);
61 return add_menupopup (menuitem);
64 context_add_maybe : function (iface, method) {
65 if (iface in this.methods &&
66 method in this.methods[iface])
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+"');");
77 /// Procedures to add specific menu items.
79 contextmenu_add_link_items : function () {
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 ();
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 ();
92 contextmenu_add_image_items : function () {
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 ();
98 sep = sep | this.context_add_maybe ('image', 'save_image');
101 contextmenu_add_nav_items : function () {
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 ();
110 contextmenu_add_page_items : function () {
111 this.context_add_maybe ('page', 'save_page');
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');
120 contextmenu_add_edit_items : function () {
122 sep = sep | this.context_add_maybe ('edit', 'undo');
123 if (sep) this.add_contextmenu_separator ();
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 ();
131 sep = sep | this.context_add_maybe ('edit', 'select_all');
132 if (sep) this.add_contextmenu_separator ();
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)
146 if (method in methods.frame)
148 add_menuitem (frame_submenu,
150 contextmenu_sb.getString ("context_"+method+".label"),
151 contextmenu_sb.getString ("context_"+method+".accesskey"),
152 "the_gui_context_menu.call ('frame','"+method+"');");
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');
169 contextmenu_add_source_items : function () {
170 if ('source' in this.methods) this.add_contextmenu_separator ();
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');