Bug 32359 - fix context menu for mailtos

patch by gerv, r=bz,dr sr=alecf
This commit is contained in:
bbaetz%cs.mcgill.ca 2001-05-12 17:52:35 +00:00
parent d1f2414952
commit 422292336c
3 changed files with 52 additions and 6 deletions

View File

@ -47,13 +47,16 @@
<!-- Open ==================================== -->
<menuitem id="context-openlink"
label="&openLinkCmd.label;"
accesskey="&openLinkCmd.accesskey;"
oncommand="contextMenu.openLink();"/>
<!-- XXX - DEPENDENT ON PRESENCE OF EDITOR!! - XXX -->
<menuitem id="context-editlink"
label="&editLinkCmd.label;"
accesskey="&editLinkCmd.accesskey;"
oncommand="contextMenu.editLink();"/>
<menuitem id="context-openframe"
label="&openFrameCmd.label;"
accesskey="&openFrameCmd.accesskey;"
oncommand="contextMenu.openFrame();"/>
<menuitem id="context-showonlythisframe"
label="&showOnlyThisFrameCmd.label;"
@ -84,18 +87,23 @@
<!-- View ==================================== -->
<menuitem id="context-viewsource"
label="&viewPageSourceCmd.label;"
accesskey="&viewPageSourceCmd.accesskey;"
oncommand="BrowserViewSource();"/>
<menuitem id="context-viewframesource"
label="&viewFrameSourceCmd.label;"
accesskey="&viewFrameSourceCmd.accesskey;"
oncommand="contextMenu.viewFrameSource();"/>
<menuitem id="context-viewinfo"
label="&viewPageInfoCmd.label;"
accesskey="&viewPageInfoCmd.accesskey;"
oncommand="contextMenu.viewInfo();"/>
<menuitem id="context-viewframeinfo"
label="&viewFrameInfoCmd.label;"
accesskey="&viewFrameInfoCmd.accesskey;"
oncommand="contextMenu.viewFrameInfo();"/>
<menuitem id="context-viewimage"
label="&viewImageCmd.label;"
accesskey="&viewImageCmd.accesskey;"
oncommand="contextMenu.viewImage();"/>
<menuitem id="context-viewbgimage"
label="&viewBGImageCmd.label;"
@ -147,6 +155,10 @@
label="&pasteCmd.label;"
accesskey="&pasteCmd.accesskey;"
command="cmd_paste"/>
<menuitem id="context-copyemail"
label="&copyEmailCmd.label;"
accesskey="&copyEmailCmd.accesskey;"
oncommand="contextMenu.copyEmail();"/>
<menuitem id="context-copylink"
label="&copyLinkCmd.label;"
accesskey="&copyLinkCmd.accesskey;"

View File

@ -177,6 +177,9 @@ nsContextMenu.prototype = {
// nsDocumentViewer.cpp has code to determine whether we're
// on a link or an image. we really ought to be using that...
// Copy email link depends on whether we're on an email link.
this.showItem( "context-copyemail", this.onMailtoLink );
// Copy link location depends on whether we're on a link.
this.showItem( "context-copylink", this.onLink );
@ -344,6 +347,7 @@ nsContextMenu.prototype = {
this.onMetaDataItem = true;
// Remember corresponding element.
this.link = elem;
this.onMailtoLink = this.isLinkType( "mailto:", this.link );
// Remember if it is saveable.
this.onSaveableLink = this.isLinkSaveable( this.link );
}
@ -383,23 +387,32 @@ nsContextMenu.prototype = {
},
// Returns true iff clicked on link is saveable.
isLinkSaveable : function ( link ) {
// We don't do the Right Thing for news/snews yet, so turn them off
// until we do.
return !(this.isLinkType( "mailto:" , link ) ||
this.isLinkType( "javascript:" , link ) ||
this.isLinkType( "news:", link ) ||
this.isLinkType( "snews:", link ) );
},
// Returns true iff clicked on link is of type given.
isLinkType : function ( linktype, link ) {
try {
// Test for missing protocol property.
if ( !link.protocol ) {
// We must resort to testing the URL string :-(.
var protocol;
if (link.href) {
protocol = link.href.substr( 0, 11 );
if ( link.href ) {
protocol = link.href.substr( 0, linktype.length );
} else {
protocol = link.getAttributeNS("http://www.w3.org/1999/xlink","href");
if (protocol) {
protocol = protocol.substr( 0, 11 );
if ( protocol ) {
protocol = protocol.substr( 0, linktype.length );
}
}
return protocol.toLowerCase() != "javascript:";
return protocol.toLowerCase() === linktype;
} else {
// Presume all but javascript: urls are saveable.
return link.protocol.toLowerCase() != "javascript:";
return link.protocol.toLowerCase() === linktype;
}
} catch (e) {
// something was wrong with the link,
@ -461,6 +474,25 @@ nsContextMenu.prototype = {
saveImage : function () {
this.savePage( this.imageURL, true );
},
// Generate email address and put it on clipboard.
copyEmail : function () {
// Copy the comma-separated list of email addresses only.
// There are other ways of embedding email addresses in a mailto:
// link, but such complex parsing is beyond us.
var url = this.linkURL();
var qmark = url.indexOf( "?" );
var addresses;
if ( qmark > 7 ) { // 7 == length of "mailto:"
addresses = url.substring( 7, qmark );
} else {
addresses = url.substr( 7 );
}
var clipboard = this.getService( "@mozilla.org/widget/clipboardhelper;1",
Components.interfaces.nsIClipboardHelper );
clipboard.copyString(addresses);
},
// Open Metadata window for node
showMetadata : function () {
window.openDialog( "chrome://navigator/content/metadata.xul",

View File

@ -52,6 +52,8 @@
<!ENTITY copyImageCmd.accesskey "m">
<!ENTITY metadataCmd.label "Properties">
<!ENTITY metadataCmd.accesskey "">
<!ENTITY copyEmailCmd.label "Copy Email Address">
<!ENTITY copyEmailCmd.accesskey "e">
<!ENTITY pasteCmd.label "Paste">
<!ENTITY pasteCmd.accesskey "p">
<!ENTITY cutCmd.label "Cut">