outline-controller.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import App from '../../../base'
  2. import OutlinePane from '../components/outline-pane'
  3. import { react2angular } from 'react2angular'
  4. import { rootContext } from '../../../shared/context/root-context'
  5. App.controller('OutlineController', [
  6. '$scope',
  7. 'ide',
  8. 'eventTracking',
  9. function ($scope, ide, eventTracking) {
  10. $scope.isTexFile = false
  11. $scope.outline = []
  12. $scope.eventTracking = eventTracking
  13. function shouldShowOutline() {
  14. return !$scope.editor.newSourceEditor
  15. }
  16. $scope.show = shouldShowOutline()
  17. $scope.$watch('editor.newSourceEditor', function () {
  18. $scope.show = shouldShowOutline()
  19. })
  20. $scope.$on('outline-manager:outline-changed', onOutlineChange)
  21. function onOutlineChange(e, outlineInfo) {
  22. $scope.$applyAsync(() => {
  23. $scope.isTexFile = outlineInfo.isTexFile
  24. $scope.outline = outlineInfo.outline
  25. $scope.highlightedLine = outlineInfo.highlightedLine
  26. })
  27. }
  28. $scope.jumpToLine = (lineNo, syncToPdf) => {
  29. ide.outlineManager.jumpToLine(lineNo, syncToPdf)
  30. eventTracking.sendMB('outline-jump-to-line')
  31. }
  32. $scope.onToggle = isOpen => {
  33. $scope.$applyAsync(() => {
  34. $scope.$emit('outline-toggled', isOpen)
  35. })
  36. }
  37. },
  38. ])
  39. // Wrap React component as Angular component. Only needed for "top-level" component
  40. App.component(
  41. 'outlinePane',
  42. react2angular(rootContext.use(OutlinePane), [
  43. 'outline',
  44. 'jumpToLine',
  45. 'highlightedLine',
  46. 'eventTracking',
  47. 'onToggle',
  48. 'isTexFile',
  49. 'show',
  50. ])
  51. )