Commits

Nicolas Froidure committed dc186b6

Added availability to edit background images and linked images

  • Participants
  • Parent commits 59ebbd0

Comments (0)

Files changed (7)

File chrome/canimage/content/browser-overlay.js

 function canImageContextDisplay()
 	{
 	var contextMenuitem=document.getElementById('canimage-context');
+	var contextBgMenuitem=document.getElementById('canimage-bg-context');
+	var contextLinkMenuitem=document.getElementById('canimage-link-context');
 	if(gContextMenu&&(gContextMenu.onImage||gContextMenu.onCanvas||gContextMenu.onVideo))
 		{
 		contextMenuitem.disabled=false;
 		contextMenuitem.disabled=true;
 		contextMenuitem.hidden=true;
 		}
-	}
-function canImageContextEdit()
-	{
-	var sidebar = document.getElementById("sidebar");
-	if(gContextMenu&&(gContextMenu.onImage||gContextMenu.onCanvas||gContextMenu.onVideo))
+	if(gContextMenu&&gContextMenu.hasBGImage&&gContextMenu.bgImageURL)
 		{
-		if(sidebar&&sidebar.contentWindow&&sidebar.contentWindow.canImageUI)
-			{
-			sidebar.contentWindow.canImageUI.openFromContextMenu(gContextMenu.target);
-			}
-		else
-			{
-			toggleSidebar('bbcomp-canimage-sidebar', true);
-			canImageCurSel=gContextMenu.target;
-			}
+		contextBgMenuitem.disabled=false;
+		contextBgMenuitem.hidden=false;
+		}
+	else
+		{
+		contextBgMenuitem.disabled=true;
+		contextBgMenuitem.hidden=true;
+		}
+	if(gContextMenu&&gContextMenu.onLink&&gContextMenu.onSaveableLink&&gContextMenu.linkURL&&/(.+)\.(gif|png|jpg|jpeg)/i.test(gContextMenu.linkURL))
+		{
+		contextLinkMenuitem.disabled=false;
+		contextLinkMenuitem.hidden=false;
+		}
+	else
+		{
+		contextLinkMenuitem.disabled=true;
+		contextLinkMenuitem.hidden=true;
 		}
 	}
+function canImageContextEdit(type)
+	{
+	canImageSelType=type;
+	switch(type)
+		{
+		case 'bg':
+			canImageCurSel=gContextMenu.bgImageURL;
+		break;
+		case 'link':
+			canImageCurSel=gContextMenu.linkURL;
+		break;
+		default:
+			canImageCurSel=gContextMenu.target;
+		break;
+		}
+	var sidebar = document.getElementById("sidebar");
+	if(sidebar&&sidebar.contentWindow&&sidebar.contentWindow.canImageUI)
+		{
+		sidebar.contentWindow.canImageUI.openFromContextMenu();
+		}
+	else
+		{
+		toggleSidebar('bbcomp-canimage-sidebar', true);
+		}
+	}
+var canImageSelType;
 var canImageCurSel;

File chrome/canimage/content/browser-overlay.xul

 
 	<popup id="contentAreaContextMenu"
 		onpopupshowing="if (event.target != this) return true; updateEditUIVisibility(); gContextMenu = new nsContextMenu(this, window.getBrowser()); canImageContextDisplay(); return gContextMenu.shouldDisplay;">
-		<menuitem label="&canimage.context;" tooltiptext="&canimage.context.ttt;" id="canimage-context" oncommand="canImageContextEdit()" insertafter="context-copyimage"/>
+		<menuitem label="&canimage.context;" tooltiptext="&canimage.context.ttt;" id="canimage-context" oncommand="canImageContextEdit('img')" insertafter="context-copyimage"/>
+		<menuitem label="&canimage.context.link;" tooltiptext="&canimage.context.link.ttt;" id="canimage-link-context" oncommand="canImageContextEdit('link')" insertafter="context-openlinkintab"/>
+		<menuitem label="&canimage.context.bg;" tooltiptext="&canimage.context.bg.ttt;" id="canimage-bg-context" oncommand="canImageContextEdit('bg')" insertafter="context-viewbgimage"/>
 	</popup>
 
 	<toolbarpalette id="BrowserToolbarPalette">

File chrome/canimage/content/canimage.js

 	// Temporary files
 	this.tempNum=0;
 	// Open selected image
-	if(window.parent.canImageCurSel)
-		this.openFromContextMenu(window.parent.canImageCurSel);
+	if(window.parent.canImageSelType)
+		this.openFromContextMenu();
 	}
 CanImageUI.prototype.unInit = function ()
 	{
 		image.addEventListener('load', this.newEventHandler(this,this.imageHandler), false);
 		}
 	}
-CanImageUI.prototype.openFromContextMenu = function (element)
+CanImageUI.prototype.openFromContextMenu = function ()
 	{
-	if(element.nodeName.toLowerCase()=='img')
+	var type=window.parent.canImageSelType;
+	var selection=window.parent.canImageCurSel;
+	if(type=='link'||type=='bg')
 		{
-		this.openImageEditor(element);
+		this.openFromDataUri(selection);
 		}
-	else if(element.nodeName.toLowerCase()=='canvas')
+	else if(selection.nodeName.toLowerCase()=='img')
 		{
-		this.openFromDataUri(element.toDataURL("image/png"));
+		this.openImageEditor(selection);
 		}
-	else if(element.nodeName.toLowerCase()=='video')
+	else if(selection.nodeName.toLowerCase()=='canvas')
 		{
-		this.openImageEditor(element);
+		this.openFromDataUri(selection.toDataURL("image/png"));
+		}
+	else if(selection.nodeName.toLowerCase()=='video')
+		{
+		this.openImageEditor(selection);
 		}
 	}
 CanImageUI.prototype.streamUri = '';

File chrome/canimage/locale/en-US/canimage-overlay.dtd

 <!ENTITY canimage.name "CanImage">
 <!ENTITY canimage.ttt "Edit an image">
-<!ENTITY canimage.context "Edit with CanImage">
-<!ENTITY canimage.context.ttt "Edit this image with CanImage">
+<!ENTITY canimage.context "Edit the image">
+<!ENTITY canimage.context.ttt "Edit this image with CanImage">
+<!ENTITY canimage.context.bg "Edit background image">
+<!ENTITY canimage.context.bg.ttt "Edit the background image with CanImage">
+<!ENTITY canimage.context.link "Edit linked image">
+<!ENTITY canimage.context.link.ttt "Edit the linked image with CanImage">

File chrome/canimage/locale/fr-FR/canimage-overlay.dtd

 <!ENTITY canimage.name "CanImage">
 <!ENTITY canimage.ttt "Editer une image">
-<!ENTITY canimage.context "Editer avec CanImage">
-<!ENTITY canimage.context.ttt "Editer cette image avec CanImage">
+<!ENTITY canimage.context "Editer l'image">
+<!ENTITY canimage.context.ttt "Editer cette image avec CanImage">
+<!ENTITY canimage.context.bg "Editer l'image de fond">
+<!ENTITY canimage.context.bg.ttt "Editer l'image de fond avec CanImage">
+<!ENTITY canimage.context.link "Editer l'image pointée">
+<!ENTITY canimage.context.link.ttt "Editer l'image que pointe ce lien avec CanImage">

File chrome/canimage/skin/classic/canimage.css

 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
 @namespace html url("http://www.w3.org/1999/xhtml");
+
+window { min-width:300px; }
+
 /* Toolbar buttons */
 #canImageZoomIn {
 	list-style-image: url("chrome://canimage/skin/zoom_in.png");

File chrome/canimage/skin/classic/toolbar-button.css

 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
 
+#sidebar-box {
+    overflow-x: hidden !important;
+}
+
+#sidebar {
+    min-width: 0px !important;
+    max-width: none !important;
+    overflow-x: hidden !important;
+}
+
 #canimage-toolbarbutton, #canimage-addonbarbutton {
 	list-style-image: url("chrome://canimage/skin/canimage.png");
 }