From 98e828b33751f12de112b1febf26c2ef0f06e7e8 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Sep 2014 10:18:21 -0700 Subject: [PATCH] Move default schema into config-default-schema.coffee --- src/atom.coffee | 3 +- src/config-default-schema.coffee | 113 +++++++++++++++++++++++++++++++ src/config.coffee | 28 ++++---- src/text-editor-view.coffee | 104 ---------------------------- src/workspace-view.coffee | 30 -------- 5 files changed, 128 insertions(+), 150 deletions(-) create mode 100644 src/config-default-schema.coffee diff --git a/src/atom.coffee b/src/atom.coffee index 1160cb26f..9c507928e 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -603,8 +603,7 @@ class Atom extends Model @deserializeWorkspaceView() loadConfig: -> - @config.setSchema 'core', {type: 'object', properties: require('./workspace-view').config} - @config.setSchema 'editor', {type: 'object', properties: require('./editor-view').config} + @config.setSchema null, {type: 'object', properties: _.clone(require('./config-default-schema'))} @config.load() loadThemes: -> diff --git a/src/config-default-schema.coffee b/src/config-default-schema.coffee new file mode 100644 index 000000000..4dc96d1cd --- /dev/null +++ b/src/config-default-schema.coffee @@ -0,0 +1,113 @@ +path = require 'path' +fs = require 'fs-plus' + +# This is loaded by atom.coffee +module.exports = + core: + type: 'object' + properties: + ignoredNames: + type: 'array' + default: [".git", ".hg", ".svn", ".DS_Store", "Thumbs.db"] + items: + type: 'string' + excludeVcsIgnoredPaths: + type: 'boolean' + default: true + disabledPackages: + type: 'array' + default: [] + items: + type: 'string' + themes: + type: 'array' + default: ['atom-dark-ui', 'atom-dark-syntax'] + items: + type: 'string' + projectHome: + type: 'string' + default: path.join(fs.getHomeDirectory(), 'github') + audioBeep: + type: 'boolean' + default: true + destroyEmptyPanes: + type: 'boolean' + default: true + + editor: + type: 'object' + properties: + fontFamily: + type: 'string' + default: '' + fontSize: + type: 'integer' + default: 16 + minimum: 1 + lineHeight: + type: 'string' + default: 1.3 + showInvisibles: + type: 'boolean' + default: false + showIndentGuide: + type: 'boolean' + default: false + showLineNumbers: + type: 'boolean' + default: true + autoIndent: + type: 'boolean' + default: true + normalizeIndentOnPaste: + type: 'boolean' + default: true + nonWordCharacters: + type: 'string' + default: "/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" + preferredLineLength: + type: 'integer' + default: 80 + minimum: 1 + tabLength: + type: 'integer' + default: 2 + minimum: 1 + softWrap: + type: 'boolean' + default: false + softTabs: + type: 'boolean' + default: true + softWrapAtPreferredLineLength: + type: 'boolean' + default: false + scrollSensitivity: + type: 'integer' + default: 40 + minimum: 10 + maximum: 200 + scrollPastEnd: + type: 'boolean' + default: false + useHardwareAcceleration: + type: 'boolean' + default: true + confirmCheckoutHeadRevision: + type: 'boolean' + default: true + invisibles: + type: 'object' + properties: + eol: + type: ['string', 'boolean'] + default: '\u00ac' + space: + type: ['string', 'boolean'] + default: '\u00b7' + tab: + type: ['string', 'boolean'] + default: '\u00bb' + cr: + type: ['string', 'boolean'] + default: '\u00a4' diff --git a/src/config.coffee b/src/config.coffee index 88106071b..b2164f8c7 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -336,14 +336,14 @@ class Config return setDefaults: (keyPath, defaults) -> - if typeof defaults isnt 'object' + unless isPlainObject(defaults) return _.setValueForKeyPath(@defaultSettings, keyPath, defaults) - keys = keyPath.split('.') hash = @defaultSettings - for key in keys - hash[key] ?= {} - hash = hash[key] + if keyPath + for key in keyPath.split('.') + hash[key] ?= {} + hash = hash[key] _.extend hash, defaults @emit 'updated' @@ -351,19 +351,19 @@ class Config setSchema: (keyPath, schema) -> unless typeof schema is "object" - throw new Error("Schemas can only be objects!") + throw new Error("Error loading schema for #{keyPath}: schemas can only be objects!") unless typeof schema.type? - throw new Error("Schema object's must have a type attribute") + throw new Error("Error loading schema for #{keyPath}: schema objects must have a type attribute") - keys = keyPath.split('.') rootSchema = @schema - for key in keys - rootSchema.type = 'object' - rootSchema.properties ?= {} - properties = rootSchema.properties - properties[key] ?= {} - rootSchema = properties[key] + if keyPath + for key in keyPath.split('.') + rootSchema.type = 'object' + rootSchema.properties ?= {} + properties = rootSchema.properties + properties[key] ?= {} + rootSchema = properties[key] _.extend rootSchema, schema @setDefaults(keyPath, @extractDefaultsFromSchema(schema)) diff --git a/src/text-editor-view.coffee b/src/text-editor-view.coffee index a457100d3..b84a8adcf 100644 --- a/src/text-editor-view.coffee +++ b/src/text-editor-view.coffee @@ -36,111 +36,7 @@ TextEditorComponent = require './text-editor-component' # console.log(editorView.getModel().getPath()) # ``` module.exports = -<<<<<<< HEAD:src/text-editor-view.coffee class TextEditorView extends View - @configDefaults: - fontFamily: '' - fontSize: 16 - lineHeight: 1.3 - showInvisibles: false - showIndentGuide: false - showLineNumbers: true - autoIndent: true - normalizeIndentOnPaste: true - nonWordCharacters: "/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" - preferredLineLength: 80 - tabLength: 2 - softWrap: false - softTabs: true - softWrapAtPreferredLineLength: false - scrollSensitivity: 40 - useHardwareAcceleration: true - confirmCheckoutHeadRevision: true - invisibles: - eol: '\u00ac' - space: '\u00b7' - tab: '\u00bb' - cr: '\u00a4' - scrollPastEnd: false -======= -class EditorView extends View - @config: - fontFamily: - type: 'string' - default: '' - fontSize: - type: 'integer' - default: 16 - minimum: 1 - lineHeight: - type: 'string' - default: 1.3 - showInvisibles: - type: 'boolean' - default: false - showIndentGuide: - type: 'boolean' - default: false - showLineNumbers: - type: 'boolean' - default: true - autoIndent: - type: 'boolean' - default: true - normalizeIndentOnPaste: - type: 'boolean' - default: true - nonWordCharacters: - type: 'string' - default: "/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-" - preferredLineLength: - type: 'integer' - default: 80 - minimum: 1 - tabLength: - type: 'integer' - default: 2 - minimum: 1 - softWrap: - type: 'boolean' - default: false - softTabs: - type: 'boolean' - default: true - softWrapAtPreferredLineLength: - type: 'boolean' - default: false - scrollSensitivity: - type: 'integer' - default: 40 - minimum: 10 - maximum: 200 - useHardwareAcceleration: - type: 'boolean' - default: true - confirmCheckoutHeadRevision: - type: 'boolean' - default: true - scrollPastEnd: - type: 'boolean' - default: false - invisibles: - type: 'object' - properties: - eol: - type: ['string', 'boolean'] - default: '\u00ac' - space: - type: ['string', 'boolean'] - default: '\u00b7' - tab: - type: ['string', 'boolean'] - default: '\u00bb' - cr: - type: ['string', 'boolean'] - default: '\u00a4' ->>>>>>> Editor config uses a schema:src/editor-view.coffee - @content: (params) -> attributes = params.attributes ? {} attributes.class = 'editor react editor-colors' diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index 6827a37d5..f011d4818 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -6,7 +6,6 @@ Delegator = require 'delegato' {deprecate, logDeprecationWarnings} = require 'grim' scrollbarStyle = require 'scrollbar-style' {$, $$, View} = require './space-pen-extensions' -fs = require 'fs-plus' Workspace = require './workspace' CommandInstaller = require './command-installer' PaneView = require './pane-view' @@ -67,35 +66,6 @@ class WorkspaceView extends View @version: 4 - @config: - ignoredNames: - type: 'array' - default: [".git", ".hg", ".svn", ".DS_Store", "Thumbs.db"] - items: - type: 'string' - excludeVcsIgnoredPaths: - type: 'boolean' - default: true - disabledPackages: - type: 'array' - default: [] - items: - type: 'string' - themes: - type: 'array' - default: ['atom-dark-ui', 'atom-dark-syntax'] - items: - type: 'string' - projectHome: - type: 'string' - default: path.join(fs.getHomeDirectory(), 'github') - audioBeep: - type: 'boolean' - default: true - destroyEmptyPanes: - type: 'boolean' - default: true - @content: -> @div class: 'workspace', tabindex: -1, => @div class: 'horizontal', outlet: 'horizontal', =>