   notify:(msg, style, details)->
 
     notification.destroy() if notification
-    
+
     style or= 'error' if details
-    
+
     notification = new KDNotificationView
       title     : msg or "Something went wrong"
       type      : "mini"

###
  todo:
    
    - put search replace
    - fix setSoftWrap it goes back to off when you reopen the settings




class Ace extends KDView

  constructor:(options, file)->

    super options, file
    @lastSavedContents = ""
    @appStorage = new AppStorage 'Ace', '1.0'

  setDomElement:(cssClass)->

    @domElement = $ "<figure class='kdview'><div id='editor#{@getId()}' class='code-wrapper'></div></figure>"

  viewAppended:->

    @appStorage.fetchStorage (storage)=>
      log storage
      require ['ace/ace'], (ace)=>
        @editor = ace.edit "editor#{@getId()}"
        @prepareEditor()
        @utils.wait => @emit "ace.ready"
        @fetchContents (err, contents)=>
          @setContents contents if contents
          @editor.gotoLine 0

  prepareEditor:->

    @setTheme()
    @setSyntax()
    @setUseSoftTabs         @appStorage.getValue 'useSoftTabs',         yes
    @setShowGutter          @appStorage.getValue 'showGutter',          yes
    @setShowPrintMargin     @appStorage.getValue 'showPrintMargin',     no
    @setHighlightActiveLine @appStorage.getValue 'highlightActiveLine', yes
    @setShowInvisibles      @appStorage.getValue 'showInvisibles',      yes
    @setFontSize            @appStorage.getValue 'fontSize',            10
    @setTabSize             @appStorage.getValue 'tabSize',             4
    @setUseWordWrap         @appStorage.getValue 'useWordWrap',         yes
    @setSoftWrap            @appStorage.getValue 'softWrap',            'free'
    @setEditorListeners()

  setEditorListeners:->

    @editor.getSession().selection.on 'changeCursor', (cursor)=>
      @emit "ace.change.cursor", @editor.getSession().getSelection().getCursor()

    @editor.commands.addCommand
        name    : 'save'
        bindKey :
