 
   openFolder: (e) ->
     console.log 'openFolder'
+    el = e.currentTarget
+    if el.classList.contains(disabled) is true
+      return
     atom.pickFolder (paths) =>
       if paths?
-        console.log "select path:#{paths[0]}"
-        @modulePath.html paths[0]
+        path = paths[0]
+        selectEl = @selectProject[0]
+        console.log "select path:#{path}"
+        if el is selectEl
+          if @checkProjectPath(path)
+            for opt in selectEl.options
+              console.log opt,opt.value,path,opt.value is path
+              if opt.value is path
+                opt.selected = true
+                console.log '...'
+                return
+            @selectProject.find('option[value=""]').remove()
+            @setSelectItem path,null,null,true,true
+            console.log '!!!'
+            # optionExists = false
+            # @projects.forEach (projectPath,i) =>
+            #   if projectPath is
+            # if optionExists is no
+            # @selectProject.find("option[value='#{path}]'").prop 'selected',true
+          else
+            alert desc.selectProjectPath
+        else
+          @modulePath.html path
 
   onSelectChange: (e) ->
     el = e.currentTarget
-    # console.log el.value
-    @modulePath.html el.value
+    console.log el.value
+    if el.value is 'other'
+      @openFolder(e)
+    # @modulePath.html el.value
     @checkPath()
+
+  checkProjectPath: (path) ->
+    result = null
+    configPath = pathM.join path,desc.ProjectConfigFileName
+    return Util.isFileExist configPath,'sync'
 
   checkPath: ->
     path = @moduleId.getText().trim()

      @h2 desc.createModuleTitle, class: 'box-subtitle'
      @div class: 'box-form', =>
        @div class: 'form-row clearfix', =>
          @label desc.moduleInApp, class: 'row-title pull-left'
          @div class: 'row-content pull-left', =>
            @select class: 'form-control', outlet: 'selectProject'
        @div class: 'form-row clearfix', =>
          @label desc.modulePath, class: 'row-title pull-left'
          @div class: 'row-content pull-left', =>
            @div class: 'textEditStyle', outlet: 'modulePath'
            @span class: 'inline-block status-added icon icon-file-directory openFolder', click: 'openFolder'
        @div class: 'form-row clearfix', =>
          @label desc.moduleId, class: 'row-title pull-left'
          @div class: 'row-content pull-left', =>

    @parentView.disableNext()
    @parentView.hidePrevBtn()

    @projects = @findProject()
    projectNum = @projects.length

    if projectNum isnt 0
      @selectProject.find('.sopt').remove()
      @setSelectItem path for path in @projects
      @selectAppPath[0].checked = true
    else
      @setSelectItem '','sopt'
      @selectModulePath[0].checked = true
    @toggleRow()
    @setSelectItem 'other','other',"#{desc.other}--#{desc.openFromFolder}"
    @checkPath()

  # destroy: ->
  #   @element.remove()

  toggleRow: ->
    console.log 'toggleRow'
    selectRow = @selectProject.parents('.form-row')
    inputRow = @modulePath.parents('.form-row')
    if @selectModulePath[0].checked
      selectRow.addClass disabled
      inputRow.removeClass disabled
      @openBtn.removeClass disabled
      @selectProject.attr(disabled,disabled)
    else
      inputRow.addClass disabled
      @openBtn.addClass disabled
      selectRow.removeClass disabled
      @selectProject.removeAttr(disabled)
    @checkPath()

  setSelectItem:(path,className,text,insertBefore,isSelected) ->
    if className?
      text?=""
      optionStr = "<option value='#{path}' class='#{className}'>#{text}</option>"
    else
      filePath = pathM.join path,desc.ProjectConfigFileName
      obj = Util.readJsonSync filePath
      projectName = if obj? then obj.name else pathM.basename path
      if isSelected? and isSelected is true
        isSelected = ' selected'
      else
        isSelected = ''
      optionStr = "<option value='#{path}' class='sopt'#{isSelected}>#{projectName}  -  #{path}</option>"
    if insertBefore is true
      @selectProject.find('.other').before optionStr
    else
      @selectProject.append optionStr

  getElement: ->
    @element

  getPath: ->
    if @selectAppPath[0].checked
      pathM.join @selectProject.val().trim(),'modules'
    else
      @modulePath.html().trim()

  serialize: ->

