SettingsController.coffee 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. define [
  2. "base"
  3. ], (App) ->
  4. App.controller "SettingsController", ["$scope", "settings", "ide", ($scope, settings, ide) ->
  5. if $scope.settings.mode not in ["default", "vim", "emacs"]
  6. $scope.settings.mode = "default"
  7. if $scope.settings.pdfViewer not in ["pdfjs", "native"]
  8. $scope.settings.pdfViewer = "pdfjs"
  9. $scope.fontSizeAsStr = (newVal) ->
  10. if newVal?
  11. $scope.settings.fontSize = newVal
  12. return $scope.settings.fontSize.toString()
  13. $scope.$watch "settings.theme", (theme, oldTheme) =>
  14. if theme != oldTheme
  15. settings.saveSettings({theme: theme})
  16. $scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
  17. if fontSize != oldFontSize
  18. settings.saveSettings({fontSize: parseInt(fontSize, 10)})
  19. $scope.$watch "settings.mode", (mode, oldMode) =>
  20. if mode != oldMode
  21. settings.saveSettings({mode: mode})
  22. $scope.$watch "settings.autoComplete", (autoComplete, oldAutoComplete) =>
  23. if autoComplete != oldAutoComplete
  24. settings.saveSettings({autoComplete: autoComplete})
  25. $scope.$watch "settings.pdfViewer", (pdfViewer, oldPdfViewer) =>
  26. if pdfViewer != oldPdfViewer
  27. settings.saveSettings({pdfViewer: pdfViewer})
  28. $scope.$watch "settings.syntaxValidation", (syntaxValidation, oldSyntaxValidation) =>
  29. if syntaxValidation != oldSyntaxValidation
  30. settings.saveSettings({syntaxValidation: syntaxValidation})
  31. $scope.$watch "project.spellCheckLanguage", (language, oldLanguage) =>
  32. return if @ignoreUpdates
  33. if oldLanguage? and language != oldLanguage
  34. settings.saveProjectSettings({spellCheckLanguage: language})
  35. # Also set it as the default for the user
  36. settings.saveSettings({spellCheckLanguage: language})
  37. $scope.$watch "project.compiler", (compiler, oldCompiler) =>
  38. return if @ignoreUpdates
  39. if oldCompiler? and compiler != oldCompiler
  40. settings.saveProjectSettings({compiler: compiler})
  41. $scope.$watch "project.rootDoc_id", (rootDoc_id, oldRootDoc_id) =>
  42. return if @ignoreUpdates
  43. if oldRootDoc_id? and rootDoc_id != oldRootDoc_id
  44. settings.saveProjectSettings({rootDocId: rootDoc_id})
  45. ide.socket.on "compilerUpdated", (compiler) =>
  46. @ignoreUpdates = true
  47. $scope.$apply () =>
  48. $scope.project.compiler = compiler
  49. delete @ignoreUpdates
  50. ide.socket.on "spellCheckLanguageUpdated", (languageCode) =>
  51. @ignoreUpdates = true
  52. $scope.$apply () =>
  53. $scope.project.spellCheckLanguage = languageCode
  54. delete @ignoreUpdates
  55. ]