main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const {Disposable} = require('atom')
  2. const GitHubFile = require('./github-file')
  3. const getActivePath = require('./get-active-path')
  4. function pathCommand (func) {
  5. return function (e) {
  6. const itemPath = getActivePath(e.target)
  7. if (itemPath) {
  8. func(itemPath)
  9. }
  10. }
  11. }
  12. function getSelectedRange () {
  13. const activePaneItem = atom.workspace.getActivePaneItem()
  14. if (activePaneItem && typeof activePaneItem.getSelectedBufferRange === 'function') {
  15. return activePaneItem.getSelectedBufferRange()
  16. }
  17. }
  18. module.exports = {
  19. activate () {
  20. this.commandsSubscription = new Disposable()
  21. this.commandsSubscription = atom.commands.add('atom-pane', {
  22. 'open-on-github:file': pathCommand((itemPath) => {
  23. GitHubFile.fromPath(itemPath).open(getSelectedRange())
  24. }),
  25. 'open-on-github:file-on-master': pathCommand((itemPath) => {
  26. GitHubFile.fromPath(itemPath).openOnMaster(getSelectedRange())
  27. }),
  28. 'open-on-github:blame': pathCommand((itemPath) => {
  29. GitHubFile.fromPath(itemPath).blame(getSelectedRange())
  30. }),
  31. 'open-on-github:history': pathCommand((itemPath) => {
  32. GitHubFile.fromPath(itemPath).history()
  33. }),
  34. 'open-on-github:issues': pathCommand((itemPath) => {
  35. GitHubFile.fromPath(itemPath).openIssues()
  36. }),
  37. 'open-on-github:pull-requests': pathCommand((itemPath) => {
  38. GitHubFile.fromPath(itemPath).openPullRequests()
  39. }),
  40. 'open-on-github:copy-url': pathCommand((itemPath) => {
  41. GitHubFile.fromPath(itemPath).copyURL(getSelectedRange())
  42. }),
  43. 'open-on-github:branch-compare': pathCommand((itemPath) => {
  44. GitHubFile.fromPath(itemPath).openBranchCompare()
  45. }),
  46. 'open-on-github:repository': pathCommand((itemPath) => {
  47. GitHubFile.fromPath(itemPath).openRepository()
  48. })
  49. })
  50. },
  51. deactivate () {
  52. this.commandsSubscription.dispose()
  53. }
  54. }