instead of , but would need to adjust colors
@@ -73,25 +24,8 @@ module.exports = class SpellPaletteEntryView extends View
constructor: (options) ->
super options
@thang = options.thang
- @doc = options.doc
- if _.isString @doc
- @doc = name: @doc, type: typeof @thang[@doc]
- if options.isSnippet
- @doc.type = @doc.owner = 'snippet'
- @doc.shortName = @doc.shorterName = @doc.title = @doc.name
- else
- @doc.owner ?= 'this'
- suffix = ''
- if @doc.type is 'function'
- argNames = (arg.name for arg in @doc.args ? []).join(', ')
- argNames = '...' if argNames.length > 6
- suffix = "(#{argNames})"
- @doc.shortName = "#{@doc.owner}.#{@doc.name}#{suffix};"
- if @doc.owner is 'this' or options.tabbify
- @doc.shorterName = "#{@doc.name}#{suffix}"
- else
- @doc.shorterName = @doc.shortName.replace ';', ''
- @doc.title = if options.shortenize then @doc.shorterName else @doc.shortName
+ @docFormatter = new DocFormatter options
+ @doc = @docFormatter.doc
getRenderData: ->
c = super()
@@ -106,46 +40,15 @@ module.exports = class SpellPaletteEntryView extends View
html: true
placement: 'top'
trigger: 'manual' # Hover, until they click, which will then pin it until unclick.
- content: @formatPopover()
+ content: @docFormatter.formatPopover()
container: '#tome-view'
)
@$el.on 'show.bs.popover', =>
Backbone.Mediator.publish 'tome:palette-hovered', thang: @thang, prop: @doc.name, entry: @
- formatPopover: ->
- content = popoverTemplate doc: @doc, value: @formatValue(), marked: marked, argumentExamples: (arg.example or arg.default or arg.name for arg in @doc.args ? [])
- owner = if @doc.owner is 'this' then @thang else window[@doc.owner]
- content = content.replace /#{spriteName}/g, @thang.type ? @thang.spriteName # Prefer type, and excluded the quotes we'd get with @formatValue
- content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))
-
- formatValue: (v) ->
- return null if @doc.type is 'snippet'
- return @thang.now() if @doc.name is 'now'
- return '[Function]' if not v and @doc.type is 'function'
- unless v?
- if @doc.owner is 'this'
- v = @thang[@doc.name]
- else
- v = window[@doc.owner][@doc.name] # grab Math or Vector
- if @doc.type is 'number' and not isNaN v
- if v == Math.round v
- return v
- return v.toFixed 2
- if _.isString v
- return "\"#{v}\""
- if v?.id
- return v.id
- if v?.name
- return v.name
- if _.isArray v
- return '[' + (@formatValue v2 for v2 in v).join(', ') + ']'
- if _.isPlainObject v
- return safeJSONStringify v, 2
- v
-
onMouseEnter: (e) ->
# Make sure the doc has the updated Thang so it can regenerate its prop value
- @$el.data('bs.popover').options.content = @formatPopover()
+ @$el.data('bs.popover').options.content = @docFormatter.formatPopover()
@$el.popover('setContent')
@$el.popover 'show' unless @popoverPinned or @otherPopoverPinned
@@ -173,7 +76,7 @@ module.exports = class SpellPaletteEntryView extends View
onFrameChanged: (e) ->
return unless e.selectedThang?.id is @thang.id
- @options.thang = @thang = e.selectedThang # Update our thang to the current version
+ @options.thang = @thang = @docFormatter.options.thang = e.selectedThang # Update our thang to the current version
onPaletteHovered: (e) ->
return if e.entry is @
diff --git a/app/views/play/level/tome/spell_palette_view.coffee b/app/views/play/level/tome/spell_palette_view.coffee
index d2ca1c42b..f88049822 100644
--- a/app/views/play/level/tome/spell_palette_view.coffee
+++ b/app/views/play/level/tome/spell_palette_view.coffee
@@ -4,6 +4,7 @@ template = require 'templates/play/level/tome/spell_palette'
filters = require 'lib/image_filter'
SpellPaletteEntryView = require './spell_palette_entry_view'
LevelComponent = require 'models/LevelComponent'
+EditorConfigModal = require '../modal/editor_config_modal'
N_ROWS = 4
@@ -16,6 +17,10 @@ module.exports = class SpellPaletteView extends View
'level-disable-controls': 'onDisableControls'
'level-enable-controls': 'onEnableControls'
'surface:frame-changed': "onFrameChanged"
+ 'tome:change-language': 'onTomeChangedLanguage'
+
+ events:
+ 'click .code-language-logo': 'onEditEditorConfig'
constructor: (options) ->
super options
@@ -26,6 +31,7 @@ module.exports = class SpellPaletteView extends View
c = super()
c.entryGroups = @entryGroups
c.entryGroupSlugs = @entryGroupSlugs
+ c.entryGroupNames = @entryGroupNames
c.tabbed = _.size(@entryGroups) > 1
c.defaultGroupSlug = @defaultGroupSlug
c
@@ -39,14 +45,18 @@ module.exports = class SpellPaletteView extends View
for entry in entryColumn
col.append entry.el
entry.render() # Render after appending so that we can access parent container for popover
- $('.nano').nanoScroller()
+ $('.nano').nanoScroller()
+ @updateCodeLanguage @options.language
+
+ updateCodeLanguage: (language) ->
+ @options.language = language
+ @$el.find('.code-language-logo').removeClass().addClass 'code-language-logo ' + language
createPalette: ->
lcs = @supermodel.getModels LevelComponent
allDocs = {}
for lc in lcs
for doc in (lc.get('propertyDocumentation') ? [])
- doc = _.clone doc
allDocs['__' + doc.name] ?= []
allDocs['__' + doc.name].push doc
if doc.type is 'snippet' then doc.owner = 'snippets'
@@ -90,7 +100,7 @@ module.exports = class SpellPaletteView extends View
return 'more' if entry.doc.owner is 'this' and entry.doc.name in (propGroups.more ? [])
entry.doc.owner
@entries = _.sortBy @entries, (entry) ->
- order = ['this', 'more', 'Math', 'Vector', 'snippets']
+ order = ['this', 'more', 'Math', 'Vector', 'String', 'Object', 'Array', 'Function', 'snippets']
index = order.indexOf groupForEntry entry
index = String.fromCharCode if index is -1 then order.length else index
index += entry.doc.name
@@ -102,13 +112,18 @@ module.exports = class SpellPaletteView extends View
@entryGroups[defaultGroup] = @entries
@defaultGroupSlug = _.string.slugify defaultGroup
@entryGroupSlugs = {}
+ @entryGroupNames = {}
for group, entries of @entryGroups
- @entryGroupSlugs[group] = _.string.slugify group
@entryGroups[group] = _.groupBy entries, (entry, i) -> Math.floor i / N_ROWS
+ @entryGroupSlugs[group] = _.string.slugify group
+ @entryGroupNames[group] = group
+ if thisName = {coffeescript: '@', lua: 'self', clojure: 'self'}[@options.language]
+ if @entryGroupNames.this
+ @entryGroupNames.this = thisName
null
addEntry: (doc, shortenize, tabbify, isSnippet=false) ->
- new SpellPaletteEntryView doc: doc, thang: @thang, shortenize: shortenize, tabbify: tabbify, isSnippet: isSnippet
+ new SpellPaletteEntryView doc: doc, thang: @thang, shortenize: shortenize, tabbify: tabbify, isSnippet: isSnippet, language: @options.language
onDisableControls: (e) -> @toggleControls e, false
onEnableControls: (e) -> @toggleControls e, true
@@ -132,6 +147,15 @@ module.exports = class SpellPaletteView extends View
return unless e.selectedThang?.id is @thang.id
@options.thang = @thang = e.selectedThang # Update our thang to the current version
+ onTomeChangedLanguage: (e) ->
+ @updateCodeLanguage e.language
+ entry.destroy() for entry in @entries
+ @createPalette()
+ @render()
+
+ onEditEditorConfig: (e) ->
+ @openModalView new EditorConfigModal session: @options.session
+
destroy: ->
entry.destroy() for entry in @entries
@toggleBackground = null
diff --git a/app/views/play/level/tome/spell_view.coffee b/app/views/play/level/tome/spell_view.coffee
index 81f3bb4a1..161d6768a 100644
--- a/app/views/play/level/tome/spell_view.coffee
+++ b/app/views/play/level/tome/spell_view.coffee
@@ -42,7 +42,7 @@ module.exports = class SpellView extends View
'tome:spell-changed': 'onSpellChanged'
'level:session-will-save': 'onSessionWillSave'
'modal-closed': 'focus'
- 'focus-editor': 'focus'
+ 'tome:focus-editor': 'focus'
'tome:spell-statement-index-updated': 'onStatementIndexUpdated'
'tome:change-language': 'onChangeLanguage'
'tome:change-config': 'onChangeEditorConfig'
@@ -299,7 +299,10 @@ module.exports = class SpellView extends View
else
@ace.setValue source
@eventsSuppressed = false
- @ace.resize true # hack: @ace may not have updated its text properly, so we force it to refresh
+ try
+ @ace.resize true # hack: @ace may not have updated its text properly, so we force it to refresh
+ catch error
+ console.warn "Error resizing ACE after an update:", error
# Called from CastButtonView initially and whenever the delay is changed
setAutocastDelay: (@autocastDelay) ->
diff --git a/app/views/play/level/tome/tome_view.coffee b/app/views/play/level/tome/tome_view.coffee
index bf39def61..7fbe51475 100644
--- a/app/views/play/level/tome/tome_view.coffee
+++ b/app/views/play/level/tome/tome_view.coffee
@@ -163,7 +163,7 @@ module.exports = class TomeView extends View
@spellList.$el.hide()
onClick: (e) ->
- Backbone.Mediator.publish 'focus-editor' unless $(e.target).parents('.popover').length
+ Backbone.Mediator.publish 'tome:focus-editor' unless $(e.target).parents('.popover').length
clearSpellView: ->
@spellView?.dismiss()
@@ -202,7 +202,7 @@ module.exports = class TomeView extends View
updateSpellPalette: (thang, spell) ->
return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties
- @spellPaletteView = @insertSubView new SpellPaletteView thang: thang, supermodel: @supermodel, programmable: spell?.canRead()
+ @spellPaletteView = @insertSubView new SpellPaletteView thang: thang, supermodel: @supermodel, programmable: spell?.canRead(), language: spell?.language ? @options.session.get('codeLanguage'), session: @options.session
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled if spell # TODO: know when palette should have been disabled but didn't exist
spellFor: (thang, spellName) ->