2
0

qsp.coffee 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {CompositeDrawable, Directory, File} = require 'atom'
  2. QspFilesView = require './qsp-files-view'
  3. fs = require 'fs'
  4. QspDecoder = require './qsp-decoder'
  5. module.exports =
  6. subscriptions: null
  7. activate: () ->
  8. @subscriptions = new CompositeDisposable()
  9. @subscriptions.add(atom.commands.add('atom-workspace', {
  10. 'qsp:toggle': () => @toggle(),
  11. 'qsp:decode': () => @decode(),
  12. 'qsp:test': () => @test()
  13. }))
  14. deactivate: () -> @subscriptions.dispose()
  15. toggle: () -> console.log('Qsp was toggled!')
  16. decode: () ->
  17. files = @findQspFiles()
  18. view = new QspFilesView()
  19. view.initialize(files, @decodeQspFile)
  20. findQspFiles: (directory) ->
  21. found = []
  22. if !directory
  23. for innerDirectory in atom.project.getDirectories()
  24. found = found.concat(@findQspFiles(innerDirectory))
  25. else
  26. for entry in directory.getEntriesSync()
  27. if entry instanceof File and entry.getPath().slice((entry.getPath().lastIndexOf('.') - 1 >>> 0) + 2) == 'qsp'
  28. found.push(entry)
  29. if entry instanceof Directory
  30. found = found.concat(@findQspFiles(entry))
  31. return found
  32. decodeQspFile: (file) ->
  33. new QspDecoder(fs.readFileSync(file.getPath()), file)
  34. test: ->
  35. console.log atom.workspace.getActivePaneItem()