OutlineManager.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import './controllers/OutlineController'
  2. import './components/OutlinePane'
  3. import './components/OutlineRoot'
  4. import './components/OutlineList'
  5. import './components/OutlineItem'
  6. import parseOutline from './OutlineParser'
  7. import isValidTeXFile from '../../main/is-valid-tex-file'
  8. class OutlineManager {
  9. constructor(ide, scope) {
  10. this.ide = ide
  11. this.scope = scope
  12. this.shareJsDoc = null
  13. this.isTexFile = false
  14. this.outline = []
  15. scope.$watch('editor.sharejs_doc', shareJsDoc => {
  16. this.shareJsDoc = shareJsDoc
  17. this.isTexFile = isValidTeXFile(scope.editor.open_doc_name)
  18. this.updateOutline()
  19. this.broadcastChangeEvent()
  20. })
  21. scope.$watch('openFile.name', openFileName => {
  22. this.isTexFile = isValidTeXFile(openFileName)
  23. this.updateOutline()
  24. this.broadcastChangeEvent()
  25. })
  26. scope.$on('doc:changed', () => {
  27. this.updateOutline()
  28. this.broadcastChangeEvent()
  29. })
  30. }
  31. updateOutline() {
  32. this.outline = []
  33. if (this.isTexFile) {
  34. const content = this.ide.editorManager.getCurrentDocValue()
  35. if (content) {
  36. this.outline = parseOutline(content)
  37. }
  38. }
  39. }
  40. jumpToLine(line) {
  41. this.ide.editorManager.openDocId(this.shareJsDoc.doc.doc_id, {
  42. gotoLine: line
  43. })
  44. }
  45. broadcastChangeEvent() {
  46. this.scope.$broadcast('outline-manager:outline-changed', {
  47. isTexFile: this.isTexFile,
  48. outline: this.outline
  49. })
  50. }
  51. }
  52. export default OutlineManager