     else
       @titleEditor.setText(selection)
 
+  openImageDialog: ->
+    files = dialog.showOpenDialog
+      properties: ['openFile']
+      defaultPath: atom.project.getPath()
+    return unless files
+    @imgEditor.setText(files[0])
+    @displayImagePreview(files[0])
+    @titleEditor.focus()
+
   displayImagePreview: (file) ->
     return if @imageOnPreview == file
 
     if @isValidImageFile(file)
       @imageOnPreview = file
       @message.text("Opening Image Preview ...")
-      @imagePreview.attr("src", file)
+      @imagePreview.attr("src", @resolveImageUrl(file))
       @imagePreview.load =>
         @message.text("")
         @widthEditor.setText("" + @imagePreview.context.naturalWidth)

          @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'


      @widthEditor.setText("")
      @heightEditor.setText("")

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

  resolveImageUrl: (file) ->
    if utils.isUrl(file)
      file
    else if fs.existsSync(file)
      file
    else
      "#{atom.project.getPath()}#{file}"

  generateImageUrl: (file) ->
    return file if utils.isUrl(file)
