From 06734ec8867c6e10937594a491434e1dfb12e4c6 Mon Sep 17 00:00:00 2001 From: dojineko Date: Sat, 16 Apr 2016 17:29:41 +0900 Subject: [PATCH] Add syntax theme selector --- browser/components/CodeEditor.js | 13 +++++++++---- browser/lib/fetchConfig.js | 3 ++- browser/main/modal/Preference/AppSettingTab.js | 17 +++++++++++++++-- browser/styles/main/modal/Preferences.styl | 2 +- lib/config.js | 4 ++-- lib/main.html | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index b1b463c7..8ecf1851 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -96,7 +96,8 @@ export default class CodeEditor extends React.Component { fontSize: config['editor-font-size'], fontFamily: config['editor-font-family'], indentType: config['editor-indent-type'], - indentSize: config['editor-indent-size'] + indentSize: config['editor-indent-size'], + themeSyntax: config['theme-syntax'] } this.silentChange = false @@ -114,7 +115,7 @@ export default class CodeEditor extends React.Component { var editor = this.editor = ace.edit(el) editor.$blockScrolling = Infinity editor.renderer.setShowGutter(true) - editor.setTheme('ace/theme/xcode') + editor.setTheme('ace/theme/' + this.state.themeSyntax) editor.moveCursorTo(0, 0) editor.setReadOnly(!!this.props.readOnly) editor.setFontSize(this.state.fontSize) @@ -202,9 +203,13 @@ export default class CodeEditor extends React.Component { fontSize: config['editor-font-size'], fontFamily: config['editor-font-family'], indentType: config['editor-indent-type'], - indentSize: config['editor-indent-size'] + indentSize: config['editor-indent-size'], + themeSyntax: config['theme-syntax'] }, function () { - var session = this.editor.getSession() + var editor = this.editor + editor.setTheme('ace/theme/' + this.state.themeSyntax) + + var session = editor.getSession() session.setUseSoftTabs(this.state.indentType === 'space') session.setTabSize(!isNaN(this.state.indentSize) ? parseInt(this.state.indentSize, 10) : 4) }) diff --git a/browser/lib/fetchConfig.js b/browser/lib/fetchConfig.js index bd57d4ca..0a8397df 100644 --- a/browser/lib/fetchConfig.js +++ b/browser/lib/fetchConfig.js @@ -13,7 +13,8 @@ const defaultConfig = { 'preview-font-size': '14', 'preview-font-family': 'Lato', 'switch-preview': 'blur', - 'disable-direct-write': false + 'disable-direct-write': false, + 'theme-syntax': 'xcode' } export default function fetchConfig () { diff --git a/browser/main/modal/Preference/AppSettingTab.js b/browser/main/modal/Preference/AppSettingTab.js index 1a028440..305495a5 100644 --- a/browser/main/modal/Preference/AppSettingTab.js +++ b/browser/main/modal/Preference/AppSettingTab.js @@ -6,6 +6,7 @@ import fetchConfig from 'browser/lib/fetchConfig' const electron = require('electron') const ipc = electron.ipcRenderer const remote = electron.remote +const ace = window.ace const OSX = global.process.platform === 'darwin' @@ -114,6 +115,7 @@ export default class AppSettingTab extends React.Component { {userAlert.message}

) : null + let aceThemeList = ace.require("ace/ext/themelist") return (
@@ -129,7 +131,7 @@ export default class AppSettingTab extends React.Component {
-
Text
+
Editor
this.handleConfigKeyDown(e)} type='text'/> @@ -154,6 +156,7 @@ export default class AppSettingTab extends React.Component {
+
Preview
this.handleConfigKeyDown(e)} type='text'/> @@ -178,7 +181,17 @@ export default class AppSettingTab extends React.Component { ) : null } - +
Theme
+
+ + +
diff --git a/browser/styles/main/modal/Preferences.styl b/browser/styles/main/modal/Preferences.styl index 9688fe0b..0bb32d97 100644 --- a/browser/styles/main/modal/Preferences.styl +++ b/browser/styles/main/modal/Preferences.styl @@ -8,7 +8,7 @@ iptFocusBorderColor = #369DCD border-radius 5px overflow hidden width 720px - height 450px + height 600px &>.header absolute top left right height 50px diff --git a/lib/config.js b/lib/config.js index e79f2bec..acabb023 100644 --- a/lib/config.js +++ b/lib/config.js @@ -12,7 +12,8 @@ const defaultConfig = { 'preview-font-size': '14', 'preview-font-family': 'Lato', 'switch-preview': 'blur', - 'disable-direct-write': false + 'disable-direct-write': false, + 'theme-syntax': 'xcode' } const configFile = 'config.json' @@ -76,4 +77,3 @@ app.on('ready', function () { applyConfig() }) }) - diff --git a/lib/main.html b/lib/main.html index 6e413f01..9f01fc34 100644 --- a/lib/main.html +++ b/lib/main.html @@ -56,6 +56,7 @@
+