2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.controller "SettingsController", ["$scope", "settings", "ide", ($scope, settings, ide) ->
|
|
|
|
if $scope.settings.mode not in ["default", "vim", "emacs"]
|
|
|
|
$scope.settings.mode = "default"
|
2014-07-16 12:05:57 -04:00
|
|
|
|
|
|
|
if $scope.settings.pdfViewer not in ["pdfjs", "native"]
|
|
|
|
$scope.settings.pdfViewer = "pdfjs"
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2018-05-10 13:03:54 -04:00
|
|
|
if $scope.settings.fontFamily? and $scope.settings.fontFamily not in ["monaco", "lucida"]
|
|
|
|
delete $scope.settings.fontFamily
|
|
|
|
|
|
|
|
if $scope.settings.lineHeight? and $scope.settings.lineHeight not in ["compact", "normal", "wide"]
|
|
|
|
delete $scope.settings.lineHeight
|
|
|
|
|
2017-06-20 12:08:53 -04:00
|
|
|
$scope.fontSizeAsStr = (newVal) ->
|
|
|
|
if newVal?
|
|
|
|
$scope.settings.fontSize = newVal
|
|
|
|
return $scope.settings.fontSize.toString()
|
|
|
|
|
2018-08-27 10:25:00 -04:00
|
|
|
$scope.$watch "settings.editorTheme", (editorTheme, oldEditorTheme) =>
|
|
|
|
if editorTheme != oldEditorTheme
|
|
|
|
settings.saveSettings({editorTheme})
|
|
|
|
|
|
|
|
$scope.$watch "settings.overallTheme", (overallTheme, oldOverallTheme) =>
|
|
|
|
if overallTheme != oldOverallTheme
|
|
|
|
settings.saveSettings({overallTheme})
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
$scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
|
|
|
|
if fontSize != oldFontSize
|
|
|
|
settings.saveSettings({fontSize: parseInt(fontSize, 10)})
|
|
|
|
|
|
|
|
$scope.$watch "settings.mode", (mode, oldMode) =>
|
|
|
|
if mode != oldMode
|
|
|
|
settings.saveSettings({mode: mode})
|
|
|
|
|
|
|
|
$scope.$watch "settings.autoComplete", (autoComplete, oldAutoComplete) =>
|
|
|
|
if autoComplete != oldAutoComplete
|
|
|
|
settings.saveSettings({autoComplete: autoComplete})
|
|
|
|
|
2017-07-06 06:06:51 -04:00
|
|
|
$scope.$watch "settings.autoPairDelimiters", (autoPairDelimiters, oldAutoPairDelimiters) =>
|
|
|
|
if autoPairDelimiters != oldAutoPairDelimiters
|
|
|
|
settings.saveSettings({autoPairDelimiters: autoPairDelimiters})
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.$watch "settings.pdfViewer", (pdfViewer, oldPdfViewer) =>
|
|
|
|
if pdfViewer != oldPdfViewer
|
|
|
|
settings.saveSettings({pdfViewer: pdfViewer})
|
|
|
|
|
2016-10-06 06:51:24 -04:00
|
|
|
$scope.$watch "settings.syntaxValidation", (syntaxValidation, oldSyntaxValidation) =>
|
|
|
|
if syntaxValidation != oldSyntaxValidation
|
2016-10-25 09:59:20 -04:00
|
|
|
settings.saveSettings({syntaxValidation: syntaxValidation})
|
2016-10-06 06:51:24 -04:00
|
|
|
|
2018-05-10 13:03:54 -04:00
|
|
|
$scope.$watch "settings.fontFamily", (fontFamily, oldFontFamily) =>
|
|
|
|
if fontFamily != oldFontFamily
|
|
|
|
settings.saveSettings({fontFamily: fontFamily})
|
|
|
|
|
|
|
|
$scope.$watch "settings.lineHeight", (lineHeight, oldLineHeight) =>
|
|
|
|
if lineHeight != oldLineHeight
|
|
|
|
settings.saveSettings({lineHeight: lineHeight})
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
$scope.$watch "project.spellCheckLanguage", (language, oldLanguage) =>
|
|
|
|
return if @ignoreUpdates
|
|
|
|
if oldLanguage? and language != oldLanguage
|
|
|
|
settings.saveProjectSettings({spellCheckLanguage: language})
|
|
|
|
# Also set it as the default for the user
|
|
|
|
settings.saveSettings({spellCheckLanguage: language})
|
|
|
|
|
|
|
|
$scope.$watch "project.compiler", (compiler, oldCompiler) =>
|
|
|
|
return if @ignoreUpdates
|
|
|
|
if oldCompiler? and compiler != oldCompiler
|
|
|
|
settings.saveProjectSettings({compiler: compiler})
|
|
|
|
|
2018-08-13 05:22:23 -04:00
|
|
|
$scope.$watch "project.imageName", (imageName, oldImageName) =>
|
|
|
|
return if @ignoreUpdates
|
|
|
|
if oldImageName? and imageName != oldImageName
|
|
|
|
settings.saveProjectSettings({imageName: imageName})
|
|
|
|
|
2014-07-21 10:09:19 -04:00
|
|
|
$scope.$watch "project.rootDoc_id", (rootDoc_id, oldRootDoc_id) =>
|
|
|
|
return if @ignoreUpdates
|
2017-10-18 09:14:59 -04:00
|
|
|
# don't save on initialisation, Angular passes oldRootDoc_id as
|
|
|
|
# undefined in this case.
|
|
|
|
return if typeof oldRootDoc_id is "undefined"
|
|
|
|
# otherwise only save changes, null values are allowed
|
|
|
|
if (rootDoc_id != oldRootDoc_id)
|
2014-07-21 10:09:19 -04:00
|
|
|
settings.saveProjectSettings({rootDocId: rootDoc_id})
|
|
|
|
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
ide.socket.on "compilerUpdated", (compiler) =>
|
|
|
|
@ignoreUpdates = true
|
|
|
|
$scope.$apply () =>
|
|
|
|
$scope.project.compiler = compiler
|
|
|
|
delete @ignoreUpdates
|
|
|
|
|
2018-08-13 05:22:23 -04:00
|
|
|
ide.socket.on "imageNameUpdated", (imageName) =>
|
|
|
|
@ignoreUpdates = true
|
|
|
|
$scope.$apply () =>
|
|
|
|
$scope.project.imageName = imageName
|
|
|
|
delete @ignoreUpdates
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
ide.socket.on "spellCheckLanguageUpdated", (languageCode) =>
|
|
|
|
@ignoreUpdates = true
|
|
|
|
$scope.$apply () =>
|
|
|
|
$scope.project.spellCheckLanguage = languageCode
|
|
|
|
delete @ignoreUpdates
|
2017-07-06 06:06:51 -04:00
|
|
|
]
|