(function () {
  var ns = $.namespace('pskl.service');

  ns.FileDropperService = function (piskelController) {
    this.piskelController = piskelController;
    this.dropPosition_ = null;
  };

  ns.FileDropperService.prototype.init = function () {
    document.body.addEventListener('drop', this.onFileDrop.bind(this), false);
    document.body.addEventListener('dragover', this.onFileDragOver.bind(this), false);
  };

  ns.FileDropperService.prototype.onFileDragOver = function (event) {
    event.stopPropagation();
    event.preventDefault();
    event.dataTransfer.dropEffect = 'copy';
  };

  ns.FileDropperService.prototype.onFileDrop = function (event) {
    event.preventDefault();
    event.stopPropagation();

    this.dropPosition_ = {
      x : event.clientX,
      y : event.clientY
    };

    var files = event.dataTransfer.files;
    this.isMultipleFiles_ = (files.length > 1);

    for (var i = 0; i < files.length ; i++) {
      var file = files[i];
      var isImage = file.type.indexOf('image') === 0;
      var isPiskel = /\.piskel$/i.test(file.name);
      var isPalette = /\.(gpl|txt|pal)$/i.test(file.name);
      if (isImage) {
        $.publish(Events.DIALOG_SHOW, {
          dialogId : 'import',
          initArgs : {
            rawFiles: [file]
          }
        });
        // pskl.utils.FileUtils.readImageFile(file, this.onImageLoaded_.bind(this));
      } else if (isPiskel) {
        pskl.utils.PiskelFileUtils.loadFromFile(file, this.onPiskelFileLoaded_, this.onPiskelFileError_);
      } else if (isPalette) {
        pskl.app.paletteImportService.read(file, this.onPaletteLoaded_.bind(this));
      }
    }
  };

  ns.FileDropperService.prototype.onPaletteLoaded_ = function (palette) {
    pskl.app.paletteService.savePalette(palette);
    pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE, palette.id);
  };

  ns.FileDropperService.prototype.onPiskelFileLoaded_ = function (piskel) {
    if (window.confirm('This will replace your current animation')) {
      pskl.app.piskelController.setPiskel(piskel);
    }
  };

  ns.FileDropperService.prototype.onPiskelFileError_ = function (reason) {
    $.publish(Events.PISKEL_FILE_IMPORT_FAILED, [reason]);
  };

  ns.FileDropperService.prototype.onImageLoaded_ = function (importedImage) {
    if (this.isMultipleFiles_) {
      this.piskelController.addFrameAtCurrentIndex();
      this.piskelController.selectNextFrame();
    }

    var currentFrame = this.piskelController.getCurrentFrame();
    // Convert client coordinates to sprite coordinates
    var spriteDropPosition = pskl.app.drawingController.getSpriteCoordinates(
      this.dropPosition_.x,
      this.dropPosition_.y
    );

    var x = spriteDropPosition.x;
    var y = spriteDropPosition.y;

    pskl.utils.FrameUtils.addImageToFrame(currentFrame, importedImage, x, y);

    $.publish(Events.PISKEL_RESET);
    $.publish(Events.PISKEL_SAVE_STATE, {
      type : pskl.service.HistoryService.SNAPSHOT
    });
  };

})();

@@ -1161,218 +1161,121 @@
     
-$.publish(Events.DIALOG_SHOW, %7B%0A          dialogId : 'import',%0A          initArgs : %7B%0A            rawFiles: %5Bfile%5D%0A          %7D%0A        %7D);%0A        // pskl.utils.FileUtils.readImageFile(file, this.onImageLoaded_
+pskl.utils.FileUtils.readImageFile(file, function (image) %7B%0A          this.onImageLoaded_(image, file);%0A        %7D
 .bin
@@ -2177,28 +2177,157 @@
 mportedImage
+, file
 ) %7B%0A
+    var piskelWidth = pskl.app.piskelController.getWidth();%0A    var piskelHeight = pskl.app.piskelController.getHeight();%0A%0A
     if (this
@@ -2453,16 +2453,342 @@
 );%0A    %7D
+ else if (importedImage.width %3E piskelWidth %7C%7C importedImage.height %3E piskelHeight) %7B%0A      // For single file imports, if the file is too big, trigger the import wizard.%0A      $.publish(Events.DIALOG_SHOW, %7B%0A        dialogId : 'import',%0A        initArgs : %7B%0A          rawFiles: %5Bfile%5D%0A        %7D%0A      %7D);%0A%0A      return;%0A    %7D
 %0A%0A    va

Fix #718 - when dropping image, only use import wizard for big images