Adding context menu with search. Bug 15176. r=law sr=hyatt

This commit is contained in:
matt%netscape.com 2006-07-29 05:37:55 +00:00
Родитель a9e292a4d4
Коммит f1859bdf5d
3 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@ -123,6 +123,9 @@
oncommand="BookmarksUtils.addBookmark(gContextMenu.linkURL(),
gContextMenu.linkText(),
undefined, true);"/>
<menuitem id="context-searchselect"
oncommand="OpenSearch('internet',false, gContextMenu.searchSelected());"/>
<menuseparator id="context-sep-bookmark"/>
<!-- Save ==================================== -->
<menuitem id="context-savepage"

Просмотреть файл

@ -154,7 +154,7 @@ nsContextMenu.prototype = {
// Use "Bookmark This Link" if on a link.
this.showItem( "context-bookmarkpage", !this.onLink );
this.showItem( "context-bookmarklink", this.onLink );
this.showItem( "context-searchselect", this.isTextSelected() );
// Send Page not working yet.
this.showItem( "context-sendpage", false );
},
@ -661,6 +661,32 @@ nsContextMenu.prototype = {
// Not implemented so all text-selected-based options are disabled.
return "true";
},
//Get selected object and convert it to a string to get
//selected text. Only use the first 15 chars.
isTextSelected : function() {
var result = false;
if (_content.getSelection() != "") {
var searchSelect = document.getElementById('context-searchselect');
var searchSelectText = _content.getSelection().toString();
var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties");
if (searchSelectText.length > 15)
searchSelectText = searchSelectText.substr(0,15) + "...";
searchSelectText = bundle.formatStringFromName("searchText",[searchSelectText],1);
searchSelect.setAttribute("label", searchSelectText);
result = true;
}
return result;
},
searchSelected : function() {
var aSearchStr = _content.getSelection();
aSearchStr = aSearchStr.toString();
aSearchStr = aSearchStr.replace( /^\s+/, "" );
aSearchStr = aSearchStr.replace(/\s+$/,"");
return aSearchStr;
},
// Determine if target <object> is an image.
objectIsImage : function ( objElem ) {
var result = false;

Просмотреть файл

@ -1,3 +1,4 @@
# context menu strings
saveImageAs=Save Image (%S)...
searchText=Search for '%S'