outline-controller.js 1.6 KB

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