outline-controller.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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', function ($scope, ide, eventTracking) {
  6. $scope.isTexFile = false
  7. $scope.outline = []
  8. $scope.eventTracking = eventTracking
  9. function shouldShowOutline() {
  10. return !$scope.editor.newSourceEditor
  11. }
  12. $scope.show = shouldShowOutline()
  13. $scope.$watch('editor.newSourceEditor', function () {
  14. $scope.show = shouldShowOutline()
  15. })
  16. $scope.$on('outline-manager:outline-changed', onOutlineChange)
  17. function onOutlineChange(e, outlineInfo) {
  18. $scope.$applyAsync(() => {
  19. $scope.isTexFile = outlineInfo.isTexFile
  20. $scope.outline = outlineInfo.outline
  21. $scope.highlightedLine = outlineInfo.highlightedLine
  22. })
  23. }
  24. $scope.jumpToLine = (lineNo, syncToPdf) => {
  25. ide.outlineManager.jumpToLine(lineNo, syncToPdf)
  26. eventTracking.sendMB('outline-jump-to-line')
  27. }
  28. $scope.onToggle = isOpen => {
  29. $scope.$applyAsync(() => {
  30. $scope.$emit('outline-toggled', isOpen)
  31. })
  32. }
  33. })
  34. // Wrap React component as Angular component. Only needed for "top-level" component
  35. App.component(
  36. 'outlinePane',
  37. react2angular(rootContext.use(OutlinePane), [
  38. 'outline',
  39. 'jumpToLine',
  40. 'highlightedLine',
  41. 'eventTracking',
  42. 'onToggle',
  43. 'isTexFile',
  44. 'show',
  45. ])
  46. )