how to get multifile from Clipboard ?

Talk about add-ons and extension development.
b337
Posts: 7
Joined: May 3rd, 2016, 10:02 pm

Re: how to get multifile from Clipboard ?

Post by b337 »

sorry for vanishing for over one month , got another work to do #-o

](*,) i really don't understand C, i just search word "clipboard" everywhere
i found some in xcb.c file from http://www.ibiblio.org/pub/X11/contrib/ ... 2.3.tar.gz
and maybe use function XSetSelectionOwner , XGetSelectionOwner , XInternAtom to call clipboard
and document about that function
https://tronche.com/gui/x/xlib/window-i ... Owner.html
https://tronche.com/gui/x/xlib/window-i ... Owner.html
https://tronche.com/gui/x/xlib/window-i ... nAtom.html
dunno maybe this relate to http://www.linuxhowtos.org/manpages/3/x ... n_atom.htm

i will search some more.

about worker , i dunno what i have to put in worker

Code: Select all

var pasteFile = {
	watcher : Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher),
	button : false,
	remove : function() {
		pasteFile.watcher.unregisterNotification(pasteFile.observe);
	},
	load : function() {
		pasteFile.watcher.registerNotification(pasteFile.observe);
	},
	observe : function(subject, topic, data) {
		let windowElm = subject;
		
		windowElm.addEventListener("load",function(e) {
			if ( e.target.URL.split("/").pop() == "messengercompose.xul" ) {
				console.log("windows load", e.currentTarget);
				var buttonmenu = e.currentTarget.document.getElementById('paste-button');
				if( buttonmenu) {
					buttonmenu.command="";
					buttonmenu.addEventListener("click", pasteFile.paste);
					pasteFile.button = buttonmenu;
					buttonmenu.disabled = false;
				}
				
				var button = e.currentTarget.document.querySelectorAll('menuitem[label="Paste"]');
				for(var i=0;i<button.length;i++) {
					button[i].addEventListener("click", pasteFile.paste);
				}
				
				e.currentTarget.addEventListener("cut", pasteFile.buttoncheck,true);
				e.currentTarget.addEventListener("copy", pasteFile.buttoncheck,true);
				e.currentTarget.addEventListener("activate", pasteFile.buttoncheck);
				e.currentTarget.addEventListener("paste", pasteFile.paste);
				e.currentTarget.addEventListener("popupshowing", pasteFile.popupshowing);
				e.currentTarget.addEventListener("popuphiding" , pasteFile.popuphiding);
				e.currentTarget.addEventListener("keydown" 	   , pasteFile.key,true);
			}
		});
	},
	toURL : function(str) {
		return "file:///" + str.replace(/%/g,'%25').replace(/ /g,'%20');
	},
	paste : function(event) {
		if ( this.OS ) {
			var chromewindow = this;
		} else if ( event.OS ) {
			var chromewindow = event;
		} else {
			var chromewindow = this.ownerGlobal;
		}
		var file = getFilesOnClipboard();
		if ( file ) {
			for(var i=0;i<file.length;i++) {
				let j = i;
				var loc = file[j].replace(/\\/g, "/");
				promise = chromewindow.OS.File.stat(loc);
				promise = promise.then(
					function onSuccess(a) {
						if ( !a.isDir ) {
							let attachment = chromewindow.Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(chromewindow.Components.interfaces.nsIMsgAttachment);
							attachment.url = pasteFile.toURL(a.path);
							attachment.size = a.size;
							chromewindow.AddAttachments([attachment]);
						}
					},function failure(reason) {
						console.log(reason);
					}
				);
			}
		}
	},
	check : function(target) {
		if ( enumFormatsOnClipboard() > 0 ) {
			target.ownerGlobal.setTimeout(function(){
				target.disabled = false;
			}, 50);
			return true;
		} else {
			target.disabled = true;
			return false;
		}
	},
	buttoncheck : function(event) {
		this.setTimeout(function(){
			if ( pasteFile.button ) {
				pasteFile.check(pasteFile.button);
			}
		}, 50);
	},
	popupshowing : function(event) {
		var button = event.composedTarget.querySelector('menuitem[label="Paste"]');
		if ( button ) {
			if ( pasteFile.check(button) ) {
				pasteFile.popup = true;
			}
		}
	},
	popuphiding : function(event) {
		pasteFile.popup = false;
	},
	key : function(event) {
		var chromewindow = this;
		if ( pasteFile.popup ) {
			if ( event.key.toLowerCase() == "p" ) {
				pasteFile.paste(chromewindow);
			}
		}
	},
	popup : false,
};
Noitidart
Posts: 1168
Joined: September 16th, 2007, 8:01 am

Re: how to get multifile from Clipboard ?

Post by Noitidart »

No problem, thanks for that research. Those X*** functions are apart of libX11 - those are not thread safe. So we can use that, but we won't be able to run it from a ChromeWorker. It's not nice to run code on mainthread, as much of it should be done off the mainthread, lots of benefits.

I'm busy with some other stuff so can't research this right now, but am very eager to port if someone does find out how to do it in xcb.
Post Reply