 path = require "path"
 fs = require "fs-plus"
 
-imageExtensions = [".jpg", ".png", ".gif"]
+imageExtensions = [".jpg", ".png", ".gif", ".bmp"]
 
 module.exports =
 class InsertImageView extends View
+  imageOnPreview: null
   editor: null
   previouslyFocusedElement: null
 

    @previouslyFocusedElement = $(':focus')
    @editor = atom.workspace.getActiveEditor()
    atom.workspaceView.append(this)
    @imgEditor.focus()

  openImageDialog: ->
    files = dialog.showOpenDialog(properties: ['openFile'])
    return unless files

    file = files[0]
    if @isValidImageFile(file)
      @imgEditor.setText(file)
      @setImage(file)
      @message.text("Image: #{@imageWidth} x #{@imageHeight}")
    else
      @message.text("Error: Invalid Image File.")

  setImage: (file) ->
    return unless @isValidImageFile(file)
    @imageSrc = file
    @image.attr("src", file)
    @image.load =>
      @imageWidth = @image.context.naturalWidth
      @imageHeight = @image.context.naturalHeight

  moveLocalImage: (file) ->
    return unless isLocalImageFile(file)

  isValidImageFile: (file) ->
    path.extname(file) in imageExtensions

        @div =>
          @button "Choose Local Image", outlet: "openImg", class: "btn"
          @label outlet: "message", class: "side-label"
        @label "Title (Alt)", class: "message"
        @subview "titleEditor", new EditorView(mini: true)
        @label "Width", class: "message"
        @subview "widthEditor", new EditorView(mini: true)
        @label "Height", class: "message"
        @subview "heightEditor", new EditorView(mini: true)
      @div class: "image-container", =>
        @img outlet: 'imagePreview'

  initialize: ->
    @handleEvents()
