<commit_before>Ui.LBox.extend('Ui.DropBox', 
/**@lends Ui.DropBox#*/
{
	/**
	 * Fires when a draggable object is drop
	 * @name Ui.DropBox#drop
	 * @event
	 * @param {Ui.DropBox} dropbox The dropbox itself
	 * @param {string} mimetype The dropped object mimetype
	 * @param {string) data The dropped object linked data (can be a JSON object stringify)
	 * @param {number} posX The dropped object x position
	 * @param {number} posY The dropped object y position
	 */
	/**
	 * Fires when a file is drop from the desktop
	 * @name Ui.DropBox#dropfile
	 * @event
	 * @param {Ui.DropBox} dropbox the dropbox itself
	 * @param {Core.File} file The dropped file
	 */

	allowedMimetypes: undefined,
	allowFiles: false,
	allowedMode: 'all',

	/**
	 * @constructs
	 * @class
	 * @extends Ui.LBox
	 */
	constructor: function(config) {
		this.addEvents('dragover', 'drop', 'dropfile');

		this.allowedMimetypes = [];

		this.connect(this.drawing, 'dragenter', this.onDragEnter);
		this.connect(this.drawing, 'dragover', this.onDragOver);
		this.connect(this.drawing, 'drop', this.onDrop);
		this.connect(this.drawing, 'localdragenter', this.onDragEnter);
		this.connect(this.drawing, 'localdragover', this.onDragOver);
		this.connect(this.drawing, 'localdrop', this.onDrop);
	},

	/**
	 * Set the allowed operation. Possible values are:
	 * [copy|copyLink|copyMove|link|linkMove|move|all]
	 */
	setAllowedMode: function(allowedMode) {
		this.allowedMode = allowedMode;
	},

	/**
	 * Add a mimetype allowed to be dropped on the current
	 * dropbox.
	 * If the special type 'Files' is provided, the dropbox
	 * will accept files dragged from the desktop.
	 */
	addMimetype: function(mimetype) {
		this.allowedMimetypes.push(mimetype);
		if((typeof(mimetype) === 'string') && mimetype.toLowerCase() == 'files')
			this.allowFiles = true;
	},

	/**#@+
	 * @private
	 */

	dragMimetype: function(event) {
		var local = Core.DragDataTransfer.hasInstance(event.dataTransfer);
		var found = undefined;
		if(event.dataTransfer.types != undefined) {
			for(var i = 0; (found === undefined) && (i < event.dataTransfer.types.length); i++) {
				var type = event.dataTransfer.types[i];
				var data = undefined;
				var coreObject = false;
				if(local) {
					data = event.dataTransfer.getData(event.dataTransfer.types[i]);
					coreObject = Core.Object.hasInstance(data);
				}
				for(var i2 = 0; (found === undefined) && (i2 < this.allowedMimetypes.length); i2++) {
					if((coreObject && data.isSubclassOf(this.allowedMimetypes[i2])) || (type.toLowerCase() == this.allowedMimetypes[i2].toLowerCase()))
						found = this.allowedMimetypes[i2];
				}
			}
		}
		return found;
	},

	onLocalDragEnter: function(event) {
		if(this.dragMimetype(event) !== undefined) {
			// accept the drag
			event.preventDefault();
			event.stopPropagation();
			return false;
		}
	},

	onDragEnter: function(event) {
//		console.log('onDragEnter allowText: '+this.allowText+', allowFiles: '+this.allowFiles);
		if(this.dragMimetype(event) !== undefined) {
			// accept the drag
			event.preventDefault();
			event.stopPropagation();
			return false;
		}
	},

	onDragOver: function(event) {
//		console.log(this+'.onDragOver effectAllowed: '+event.dataTransfer.effectAllowed+', mimetype: '+this.dragMimetype(event));
		if((event.dataTransfer !== undefined) && (this.dragMimetype(event) !== undefined)) {
			// accept the drag over
			var effectAllowed = 'all';
			if(event.dataTransfer.effectAllowed != undefined)
				effectAllowed = event.dataTransfer.effectAllowed;
			if(effectAllowed == 'uninitialized')
				effectAllowed = 'all';

			var dropEffect = 'copy';
			if(((this.allowedMode == 'all') || (this.allowedMode == 'copy') ||  (this.allowedMode == 'copyLink') || (this.allowedMode == 'copyMove')) &&
			   ((effectAllowed == 'copy') || (effectAllowed == 'copyLink') || (effectAllowed == 'copyMove') || (effectAllowed == 'all')))
				dropEffect = 'copy';
			else if(((this.allowedMode == 'all') || (this.allowedMode == 'copyMove') ||  (this.allowedMode == 'linkMove') || (this.allowedMode == 'move')) &&
					((effectAllowed == 'all') || (effectAllowed == 'copyMove') || (effectAllowed == 'linkMove') || (effectAllowed == 'move')))
				dropEffect = 'move';
			else if(((this.allowedMode == 'all') || (this.allowedMode == 'copyLink') ||  (this.allowedMode == 'link') || (this.allowedMode == 'linkMove')) &&
					((effectAllowed == 'all') || (effectAllowed == 'copyLink') || (effectAllowed == 'link') || (effectAllowed == 'linkMove')))
				dropEffect = 'link';
			else
				dropEffect = 'none';

//			console.log('effectAllowed: '+effectAllowed+', dropEffect: '+dropEffect);

			event.dataTransfer.dropEffect = dropEffect;
			event.preventDefault();
			event.stopPropagation();

			var point = this.pointFromWindow({ x: event.clientX, y: event.clientY });
			this.fireEvent('dragover', this, point.x, point.y);
			return false;
		}
	},

	onDrop: function(event) {
//		console.log('onDrop '+event.clientX+','+event.clientY);
		
		var dropPoint = this.pointFromWindow({ x: event.clientX, y: event.clientY });

//		console.log('drop Files: '+((event.dataTransfer.files === undefined)?0:event.dataTransfer.files.length));

		if((event.dataTransfer.files != undefined) && (event.dataTransfer.files.length > 0)) {
			// accept the drop
			event.preventDefault();
			event.stopPropagation();

//			console.log('drop files');
			for(var i = 0; i < event.dataTransfer.files.length; i++)
				this.fireEvent('dropfile', this, new Core.File({ fileApi: event.dataTransfer.files[i] }), dropPoint.x, dropPoint.y);
		}
		else {
			var mimetype = this.dragMimetype(event);
//			console.log(this+'.onDrop mimetype: '+mimetype);
			
			if(mimetype !== undefined) {
				var data = event.dataTransfer.getData(mimetype);
				// accept the drop
				event.preventDefault();
				event.stopPropagation();
				this.fireEvent('drop', this, mimetype, data, dropPoint.x, dropPoint.y, event.dataTransfer.effectAllowed);
			}
/*
			// handle "text encoded" mimetypes<commit_msg>add the effect for "dropfile" event<commit_after>Ui.LBox.extend('Ui.DropBox', 
/**@lends Ui.DropBox#*/
{
	/**
	 * Fires when a draggable object is drop
	 * @name Ui.DropBox#drop
	 * @event
	 * @param {Ui.DropBox} dropbox The dropbox itself
	 * @param {string} mimetype The dropped object mimetype
	 * @param {string) data The dropped object linked data (can be a JSON object stringify)
	 * @param {number} posX The dropped object x position
	 * @param {number} posY The dropped object y position
	 */
	/**
	 * Fires when a file is drop from the desktop
	 * @name Ui.DropBox#dropfile
	 * @event
	 * @param {Ui.DropBox} dropbox the dropbox itself
	 * @param {Core.File} file The dropped file
	 */

	allowedMimetypes: undefined,
	allowFiles: false,
	allowedMode: 'all',

	/**
	 * @constructs
	 * @class
	 * @extends Ui.LBox
	 */
	constructor: function(config) {
		this.addEvents('dragover', 'drop', 'dropfile');

		this.allowedMimetypes = [];

		this.connect(this.drawing, 'dragenter', this.onDragEnter);
		this.connect(this.drawing, 'dragover', this.onDragOver);
		this.connect(this.drawing, 'drop', this.onDrop);
		this.connect(this.drawing, 'localdragenter', this.onDragEnter);
		this.connect(this.drawing, 'localdragover', this.onDragOver);
		this.connect(this.drawing, 'localdrop', this.onDrop);
	},

	/**
	 * Set the allowed operation. Possible values are:
	 * [copy|copyLink|copyMove|link|linkMove|move|all]
	 */
	setAllowedMode: function(allowedMode) {
		this.allowedMode = allowedMode;
	},

	/**
	 * Add a mimetype allowed to be dropped on the current
	 * dropbox.
	 * If the special type 'Files' is provided, the dropbox
	 * will accept files dragged from the desktop.
	 */
	addMimetype: function(mimetype) {
		this.allowedMimetypes.push(mimetype);
		if((typeof(mimetype) === 'string') && mimetype.toLowerCase() == 'files')
			this.allowFiles = true;
	},

	/**#@+
	 * @private
	 */

	dragMimetype: function(event) {
		var local = Core.DragDataTransfer.hasInstance(event.dataTransfer);
		var found = undefined;
		if(event.dataTransfer.types != undefined) {
			for(var i = 0; (found === undefined) && (i < event.dataTransfer.types.length); i++) {
				var type = event.dataTransfer.types[i];
				var data = undefined;
				var coreObject = false;
				if(local) {
					data = event.dataTransfer.getData(event.dataTransfer.types[i]);
					coreObject = Core.Object.hasInstance(data);
				}
				for(var i2 = 0; (found === undefined) && (i2 < this.allowedMimetypes.length); i2++) {
					if((coreObject && data.isSubclassOf(this.allowedMimetypes[i2])) || (type.toLowerCase() == this.allowedMimetypes[i2].toLowerCase()))
						found = this.allowedMimetypes[i2];
				}
			}
		}
		return found;
	},

	onLocalDragEnter: function(event) {
		if(this.dragMimetype(event) !== undefined) {
			// accept the drag
			event.preventDefault();
			event.stopPropagation();
			return false;
		}
	},

	onDragEnter: function(event) {
//		console.log('onDragEnter allowText: '+this.allowText+', allowFiles: '+this.allowFiles);
		if(this.dragMimetype(event) !== undefined) {
			// accept the drag
			event.preventDefault();
			event.stopPropagation();
			return false;
		}
	},

	onDragOver: function(event) {
//		console.log(this+'.onDragOver effectAllowed: '+event.dataTransfer.effectAllowed+', mimetype: '+this.dragMimetype(event));
		if((event.dataTransfer !== undefined) && (this.dragMimetype(event) !== undefined)) {
			// accept the drag over
			var effectAllowed = 'all';
			if(event.dataTransfer.effectAllowed != undefined)
				effectAllowed = event.dataTransfer.effectAllowed;
			if(effectAllowed == 'uninitialized')
				effectAllowed = 'all';
			
			var dropEffect = 'copy';
			if(((this.allowedMode == 'all') || (this.allowedMode == 'copy') ||  (this.allowedMode == 'copyLink') || (this.allowedMode == 'copyMove')) &&
			   ((effectAllowed == 'copy') || (effectAllowed == 'copyLink') || (effectAllowed == 'copyMove') || (effectAllowed == 'all')))
				dropEffect = 'copy';
			else if(((this.allowedMode == 'all') || (this.allowedMode == 'copyMove') ||  (this.allowedMode == 'linkMove') || (this.allowedMode == 'move')) &&
					((effectAllowed == 'all') || (effectAllowed == 'copyMove') || (effectAllowed == 'linkMove') || (effectAllowed == 'move')))
				dropEffect = 'move';
			else if(((this.allowedMode == 'all') || (this.allowedMode == 'copyLink') ||  (this.allowedMode == 'link') || (this.allowedMode == 'linkMove')) &&
					((effectAllowed == 'all') || (effectAllowed == 'copyLink') || (effectAllowed == 'link') || (effectAllowed == 'linkMove')))
				dropEffect = 'link';
			else
				dropEffect = 'none';
			
			event.dataTransfer.dropEffect = dropEffect;
			event.preventDefault();
			event.stopPropagation();

			var point = this.pointFromWindow({ x: event.clientX, y: event.clientY });
			this.fireEvent('dragover', this, point.x, point.y);
			return false;
		}
	},

	onDrop: function(event) {
//		console.log('onDrop '+event.clientX+','+event.clientY);
		
		var dropPoint = this.pointFromWindow({ x: event.clientX, y: event.clientY });

//		console.log('drop Files: '+((event.dataTransfer.files === undefined)?0:event.dataTransfer.files.length));

		if((event.dataTransfer.files != undefined) && (event.dataTransfer.files.length > 0)) {
			// accept the drop
			event.preventDefault();
			event.stopPropagation();

//			console.log('drop files');
			for(var i = 0; i < event.dataTransfer.files.length; i++)
				this.fireEvent('dropfile', this, new Core.File({ fileApi: event.dataTransfer.files[i] }), dropPoint.x, dropPoint.y, event.dataTransfer.effectAllowed);
		}
		else {
			var mimetype = this.dragMimetype(event);
//			console.log(this+'.onDrop mimetype: '+mimetype);
			
			if(mimetype !== undefined) {
				var data = event.dataTransfer.getData(mimetype);
				// accept the drop
				event.preventDefault();
				event.stopPropagation();
				this.fireEvent('drop', this, mimetype, data, dropPoint.x, dropPoint.y, event.dataTransfer.effectAllowed);
			}
/*
			// handle "text encoded" mimetypes
{'fraction_non_alphanumeric': 0.1681939353548817, 'fraction_numerical': 0.0018327224258580473, 'mean_word_length': 4.095500848896434, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5128451', 'n_tokens_mistral': 4330, 'n_tokens_neox': 3917, 'n_words': 831}