--- a/ginebra2/chrome/bedrockchrome/contextmenu.snippet/ViewContextMenu.js Thu Sep 23 15:32:11 2010 -0400
+++ b/ginebra2/chrome/bedrockchrome/contextmenu.snippet/ViewContextMenu.js Fri Oct 15 17:30:59 2010 -0400
@@ -50,13 +50,29 @@
}
function viewMenu_getLinkItems(linkUrl) {
- var matchFound = false;
- var errorUrl= "javascript:"
-
- if(linkUrl.substring(0,errorUrl.length) == errorUrl) {
- matchFound=true;
- }
const maxWindowCount = 5;
+ var browserSchemeFound = true;
+ // schemes other than http(s) and file may be handled by other app
+ var browserSchemePattern = /^(http|https|file):/i;
+ var matchFound = false;
+ var errorUrl= "javascript:"
+ var disableLink = false;
+
+ if (linkUrl.substring(0,errorUrl.length) == errorUrl) {
+ matchFound = true;
+ }
+
+ if (!browserSchemePattern.test(linkUrl)) {
+ // scheme not directly handled by browser and therefore not displayed
+ // in browser window
+ browserSchemeFound = false;
+ }
+
+ if ((pageController.pageCount() >= maxWindowCount)
+ || matchFound || !browserSchemeFound) {
+ disableLink = true;
+ }
+
var items = new Array();
items =
[
@@ -65,7 +81,7 @@
"onclick": function() {
pageController.LoadInNewWindow(linkUrl);
},
- "disabled": (pageController.pageCount() >= maxWindowCount || matchFound) ? "true" : "false",
+ "disabled": disableLink ? "true" : "false",
},
]
;
@@ -75,8 +91,8 @@
function viewMenu_getNavMenuData(current) {
return {
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_tab_navigation"), // "Navigation",
- "iconHighlighted": "contextmenu.snippet/icons/nav_selected.png",
- "icon": "contextmenu.snippet/icons/nav_deselected.png",
+ "iconHighlighted": "/contextmenu/nav_selected.png",
+ "icon": "/contextmenu/nav_deselected.png",
"current": current ? "true" : "false",
"menuItems":
[
@@ -104,14 +120,49 @@
};
}
+function viewMenu_getTextEditMenuData(isContentSelected) {
+
+ var items = new Array();
+ items = [
+ {
+ "text": "copy",
+ "disabled" : isContentSelected ? "false" : "true",
+ "onclick": function() {
+ pageController.copy();
+ },
+ },
+ {
+ "text": "cut",
+ "disabled" : isContentSelected ? "false" : "true",
+ "onclick": function() {
+ pageController.cut();
+ },
+ },
+ ];
+
+ items = items.concat( [ {
+ "text": "paste",
+ "disabled": pageController.hasTextOnClipBoard() ? "false" : "true",
+ "onclick": function() {
+ pageController.paste();
+ },
+ },]);
+
+ return {
+ "text": "",
+ "current": "true",
+ "menuItems": items,
+ };
+}
+
function viewMenu_getPageMenuData(current) {
var popupsBlocked = pageController.getPopupSettings();
var tempUrl = pageController.currentDocUrl;
return {
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_tab_page"), // "Page",
- "iconHighlighted": "contextmenu.snippet/icons/page_selected.png",
- "icon": "contextmenu.snippet/icons/page_deselected.png",
+ "iconHighlighted": "/contextmenu/page_selected.png",
+ "icon": "/contextmenu/page_deselected.png",
"current": current ? "true" : "false",
"menuItems":
[
@@ -149,6 +200,16 @@
var isLink = linkUrl != "";
var isImage = imageUrl != "";
var isLinkOrImage = isLink || isImage;
+ var isContentEditable = contextEvent != undefined ? contextEvent.isContentEditable : false;
+ var isContentSelected = contextEvent != undefined ? contextEvent.isContentSelected : false;
+
+ if (isContentEditable) {
+ var menuList = new Array;
+ menuList = menuList.concat(viewMenu_getTextEditMenuData(isContentSelected));
+ return {
+ "menus": menuList
+ };
+ }
// Build Navigation tab and its menu.
if (contextEvent == undefined)
@@ -194,8 +255,8 @@
: (isLink
? window.localeDelegate.translateText("txt_browser_content_view_menu_tab_link") // "Link"
: window.localeDelegate.translateText("txt_browser_content_view_menu_tab_image")), // "image"
- "icon": "contextmenu.snippet/icons/links_deselected.png",
- "iconHighlighted": "contextmenu.snippet/icons/links_selected.png",
+ "icon": "/contextmenu/links_deselected.png",
+ "iconHighlighted": "/contextmenu/links_selected.png",
"current": isLinkOrImage ? "true" : "false",
"disabled": isLinkOrImage ? "false" : "true",
"menuItems": linkMenuItems,
@@ -213,15 +274,75 @@
};
}
+// Return a data structure representing the context menu for the edit widget
+function viewMenu_getEditWidgetContextMenuData(isContentSelected, snippetId) {
+ var menuItems = new Array();
+ menuItems = [
+ {
+ "text": "copy",
+ "disabled" : isContentSelected ? "false" : "true",
+ "onclick": function() {
+ window.snippets[snippetId].copy();
+ },
+ },
+ {
+ "text": "cut",
+ "disabled" : isContentSelected ? "false" : "true",
+ "onclick": function() {
+ window.snippets[snippetId].cut();
+ },
+ },
+ ];
+
+ menuItems = menuItems.concat( [ {
+ "text": "paste",
+ "disabled": pageController.hasTextOnClipBoard() ? "false" : "true",
+ "onclick": function() {
+ window.snippets[snippetId].paste();
+ },
+ },]);
+
+ return {
+ "menus": [
+ { "text": "",
+ "current": "true",
+ "menuItems": menuItems,
+ },
+ ]
+ };
+}
+
// Initialize the WebView's context menu.
function viewMenu_initWebViewContextMenu() {
// Connect to the view's contextEvent signal.
views.WebView.contextEvent.connect(
function(contextEvent) {
//printProp(contextEvent);
- cm_TheContextMenu.show(viewMenu_getWebViewContextMenuData(contextEvent));
+ var menuData = viewMenu_getWebViewContextMenuData(contextEvent);
+ if (menuData.menus != undefined && menuData.menus[0].menuItems.length == 0)
+ return;
+ cm_TheContextMenu.editingSnippet = undefined;
+ cm_TheContextMenu.show(menuData);
}
);
+
+ // Connect to the snippets' contextEvent signal
+ for(var i = 0; i < chrome.snippets.length; i++) {
+ var snippet = chrome.snippets[i];
+ if (snippet.editable() && !snippet.useNativeCopyPasteMenu()) {
+ //alert(snippet);
+ snippet.contextEvent.connect(
+ function(isContentSelected, snippetId) {
+ var menuData = viewMenu_getEditWidgetContextMenuData(isContentSelected, snippetId);
+ if (menuData.menus != undefined && menuData.menus[0].menuItems.length == 0)
+ return;
+ cm_TheContextMenu.editingSnippet = window.snippets[snippetId];
+ cm_TheContextMenu.show(menuData);
+ }
+ );
+ }
+ }
+
}
chrome.chromeComplete.connect(viewMenu_initWebViewContextMenu);