Skip to content

Commit

Permalink
style handler: add support for multiple gtk styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Dec 26, 2019
1 parent c3b59c0 commit 119deaa
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions [email protected]/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ function setFileContents(path, contents) {
GLib.file_set_contents(path, contents)
}

function resetGtkStyles() {
let style = getFileContents(USER_STYLES)

style = style.replace(/\/\* UNITE ([\s\S]*?) UNITE \*\/\n/g, '')
style = style.replace(/@import.*unite@hardpixel\.eu.*css['"]\);\n/g, '')

setFileContents(USER_STYLES, style)
}

var Signals = class Signals {
constructor() {
this.signals = new Map()
Expand Down Expand Up @@ -146,21 +155,22 @@ var WidgetStyle = class WidgetStyle {
}

var GtkStyle = class GtkStyle {
constructor(contents) {
this.contents = `${contents}\n`
constructor(name, contents) {
this.contents = `/* UNITE ${name} */\n${contents}\n/* ${name} UNITE */\n`
}

get existing() {
const contents = getFileContents(USER_STYLES)
return contents.replace(/@import.*unite@hardpixel\.eu.*css['"]\);\n/g, '')
return getFileContents(USER_STYLES)
}

load() {
setFileContents(USER_STYLES, this.contents + this.existing)
const style = this.contents + this.existing
setFileContents(USER_STYLES, style)
}

unload() {
setFileContents(USER_STYLES, this.existing)
const style = this.existing.replace(this.contents, '')
setFileContents(USER_STYLES, style)
}
}

Expand Down Expand Up @@ -207,7 +217,7 @@ var Styles = class Styles {

addGtkStyle(name, contents) {
this.deleteStyle(name)
this.setStyle(name, GtkStyle, contents)
this.setStyle(name, GtkStyle, name, contents)
}

removeAll() {
Expand All @@ -216,3 +226,5 @@ var Styles = class Styles {
}
}
}

resetGtkStyles()

0 comments on commit 119deaa

Please sign in to comment.