dynamically change theme

pull/1/head
yann300 6 years ago
parent 1faf99c18c
commit f897ebdcdf
  1. 48
      src/app/editor/editor.js
  2. 4
      src/app/tabs/settings-tab.js
  3. 9
      src/app/ui/styles-guide/theme-chooser.js

@ -4,8 +4,6 @@ const yo = require('yo-yo')
const csjs = require('csjs-inject') const csjs = require('csjs-inject')
const ace = require('brace') const ace = require('brace')
require('brace/theme/tomorrow_night_blue')
const globalRegistry = require('../../global/registry') const globalRegistry = require('../../global/registry')
const SourceHighlighters = require('./SourceHighlighters') const SourceHighlighters = require('./SourceHighlighters')
@ -17,22 +15,12 @@ require('ace-mode-solidity/build/remix-ide/mode-solidity')
require('brace/mode/javascript') require('brace/mode/javascript')
require('brace/mode/python') require('brace/mode/python')
require('brace/mode/json') require('brace/mode/json')
const styleGuide = require('../ui/styles-guide/theme-chooser') const themeChooser = require('../ui/styles-guide/theme-chooser')
const styles = styleGuide.chooser()
function setTheme (cb) {
if (styles.appProperties.aceTheme) {
cb('brace/theme/', styles.appProperties.aceTheme)
}
}
setTheme((path, theme) => {
require('brace/theme/tomorrow_night_blue') require('brace/theme/tomorrow_night_blue')
}) require('brace/theme/solarized_light')
const css = csjs` const css = csjs`
.ace-editor { .ace-editor {
background-color : ${styles.editor.backgroundColor_Editor};
width : 100%; width : 100%;
} }
` `
@ -41,35 +29,29 @@ document.head.appendChild(yo`
.ace-tm .ace_gutter, .ace-tm .ace_gutter,
.ace-tm .ace_gutter-active-line, .ace-tm .ace_gutter-active-line,
.ace-tm .ace_marker-layer .ace_active-line { .ace-tm .ace_marker-layer .ace_active-line {
background-color: ${styles.editor.backgroundColor_Tabs_Highlights}; background-color: var(--secondary);
} }
.ace_gutter-cell.ace_breakpoint{ .ace_gutter-cell.ace_breakpoint{
background-color: ${styles.editor.backgroundColor_DebuggerMode}; background-color: var(--secondary);
} }
.highlightreference { .highlightreference {
position:absolute; position:absolute;
z-index:20; z-index:20;
background-color: ${ background-color: var(--secondary);
styles.editor.backgroundColor_Editor_Context_Highlights
};
opacity: 0.7 opacity: 0.7
} }
.highlightreferenceline { .highlightreferenceline {
position:absolute; position:absolute;
z-index:20; z-index:20;
background-color: ${ background-color: var(--secondary);
styles.editor.backgroundColor_Editor_Context_Highlights
};
opacity: 0.7 opacity: 0.7
} }
.highlightcode { .highlightcode {
position:absolute; position:absolute;
z-index:20; z-index:20;
background-color: ${ background-color: var(--danger);
styles.editor.backgroundColor_Editor_Context_Error_Highlights
};
} }
</style> </style>
`) `)
@ -85,6 +67,14 @@ class Editor {
config: this._components.registry.get('config').api config: this._components.registry.get('config').api
} }
this._themes = {
'light': 'solarized_light',
'dark': 'tomorrow_night_blue'
}
themeChooser.event.on('switchTheme', (type) => {
this.setTheme(type)
})
// Init // Init
this.event = new EventManager() this.event = new EventManager()
this.sessions = {} this.sessions = {}
@ -114,9 +104,7 @@ class Editor {
this.editor.setShowPrintMargin(false) this.editor.setShowPrintMargin(false)
this.editor.resize(true) this.editor.resize(true)
if (styles.appProperties.aceTheme) { this.setTheme()
this.editor.setTheme('ace/theme/' + styles.appProperties.aceTheme)
}
this.editor.setOptions({ this.editor.setOptions({
enableBasicAutocompletion: true, enableBasicAutocompletion: true,
@ -170,6 +158,10 @@ class Editor {
}) })
} }
setTheme (type) {
this.editor.setTheme('ace/theme/' + this._themes[type])
}
_onChange () { _onChange () {
const currentFile = this._deps.config.get('currentFile') const currentFile = this._deps.config.get('currentFile')
if (!currentFile) { if (!currentFile) {

@ -148,19 +148,17 @@ module.exports = class SettingsTab {
} }
function onswitch2darkTheme (event) { function onswitch2darkTheme (event) {
styleGuide.switchTheme('dark') styleGuide.switchTheme('dark')
// window.location.reload()
} }
function onswitch2lightTheme (event) { function onswitch2lightTheme (event) {
styleGuide.switchTheme('light') styleGuide.switchTheme('light')
// window.location.reload()
} }
function onswitch2cleanTheme (event) { function onswitch2cleanTheme (event) {
styleGuide.switchTheme('clean') styleGuide.switchTheme('clean')
// window.location.reload()
} }
function onchangePersonal (event) { function onchangePersonal (event) {
self._deps.config.set('settings/personal-mode', !self._deps.config.get('settings/personal-mode')) self._deps.config.set('settings/personal-mode', !self._deps.config.get('settings/personal-mode'))
} }
styleGuide.switchTheme()
return self._view.el return self._view.el
} }
} }

@ -2,6 +2,7 @@ var styleGuideLight = require('./style-guide')
var styleGuideDark = require('./styleGuideDark') var styleGuideDark = require('./styleGuideDark')
var styleGuideClean = require('./styleGuideClean') var styleGuideClean = require('./styleGuideClean')
var Storage = require('remix-lib').Storage var Storage = require('remix-lib').Storage
var EventEmitter = require('events')
// Boostrap themes // Boostrap themes
// TODO : Put it somewhere else // TODO : Put it somewhere else
@ -17,7 +18,7 @@ const themeVariable = {
clean: 'light' clean: 'light'
} }
module.exports = { module.exports = {
event: new EventEmitter(),
chooser: function () { chooser: function () {
const themeStorage = new Storage('style:') const themeStorage = new Storage('style:')
if (themeStorage.exists('theme')) { if (themeStorage.exists('theme')) {
@ -43,10 +44,14 @@ module.exports = {
switchTheme: function (theme) { switchTheme: function (theme) {
var themeStorage = new Storage('style:') var themeStorage = new Storage('style:')
themeStorage.set('theme', theme) if (theme) themeStorage.set('theme', theme)
else {
theme = themeStorage.get('theme')
}
if (themes[theme]) { if (themes[theme]) {
document.getElementById('theme-link').setAttribute('href', themes[theme]) document.getElementById('theme-link').setAttribute('href', themes[theme])
document.documentElement.style.setProperty('--theme', themeVariable[theme]) document.documentElement.style.setProperty('--theme', themeVariable[theme])
this.event.emit('switchTheme', themeVariable[theme])
} }
// if (theme === 'dark') { // if (theme === 'dark') {
// return styleGuideDark() // return styleGuideDark()

Loading…
Cancel
Save