Custom color schemes!
This commit is contained in:
parent
43d78e17e5
commit
7ec80e6682
3 changed files with 102 additions and 24 deletions
|
@ -192,6 +192,26 @@ MenuBar {
|
||||||
}
|
}
|
||||||
icon.name: 'label'
|
icon.name: 'label'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Menu {
|
||||||
|
title: qsTr("Color Scheme")
|
||||||
|
property var schemes: ["Breeze Light", "Breeze Dark", "Solarized", "Github Light", "Github Dark", "Nord", "Monokai"]
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
model: ["Breeze Light", "Breeze Dark", "Solarized", "Github Light", "Github Dark", "Nord", "Monokai"]
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: modelData
|
||||||
|
checkable: true
|
||||||
|
checked: Helper.getSettingInt("expression_editor.color_scheme") == index
|
||||||
|
onTriggered: {
|
||||||
|
parent.children[Helper.getSettingInt("expression_editor.color_scheme")].checked = false
|
||||||
|
checked = true
|
||||||
|
Helper.setSettingInt("expression_editor.color_scheme", index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,19 +95,74 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty string ExpressionEditor::colorScheme
|
\qmlproperty string ExpressionEditor::colorSchemes
|
||||||
Color scheme of the editor, currently based on Breeze Light.
|
Color schemes of the editor.
|
||||||
TODO: Make it configurable.
|
|
||||||
*/
|
*/
|
||||||
readonly property var colorScheme: {
|
readonly property var colorSchemes: [
|
||||||
'NORMAL': "#1F1C1B",
|
{ // Breeze Light
|
||||||
'VARIABLE': "#0057AE",
|
'NORMAL': "#1F1C1B",
|
||||||
'CONSTANT': "#5E2F00",
|
'VARIABLE': "#0057AE",
|
||||||
'FUNCTION': "#644A9B",
|
'CONSTANT': "#006E28",
|
||||||
'OPERATOR': "#A44EA4",
|
'FUNCTION': "#644A9B",
|
||||||
'STRING': "#9C0E0E",
|
'OPERATOR': "#CA60CA",
|
||||||
'NUMBER': "#805C00"
|
'STRING': "#BF0303",
|
||||||
}
|
'NUMBER': "#B08000"
|
||||||
|
},
|
||||||
|
{ // Breeze Dark
|
||||||
|
'NORMAL': "#CFCFC2",
|
||||||
|
'VARIABLE': "#2980B9",
|
||||||
|
'CONSTANT': "#27AE60",
|
||||||
|
'FUNCTION': "#8E44AD",
|
||||||
|
'OPERATOR': "#A44EA4",
|
||||||
|
'STRING': "#F44F4F",
|
||||||
|
'NUMBER': "#F67400"
|
||||||
|
},
|
||||||
|
{ // Solarized
|
||||||
|
'NORMAL': "#839496",
|
||||||
|
'VARIABLE': "#B58900",
|
||||||
|
'CONSTANT': "#859900",
|
||||||
|
'FUNCTION': "#268BD2",
|
||||||
|
'OPERATOR': "#859900",
|
||||||
|
'STRING': "#2AA198",
|
||||||
|
'NUMBER': "#2AA198"
|
||||||
|
},
|
||||||
|
{ // GitHub Light
|
||||||
|
'NORMAL': "#24292E",
|
||||||
|
'VARIABLE': "#D73A49",
|
||||||
|
'CONSTANT': "#6F42C1",
|
||||||
|
'FUNCTION': "#6F42C1",
|
||||||
|
'OPERATOR': "#24292E",
|
||||||
|
'STRING': "#032F62",
|
||||||
|
'NUMBER': "#005CC5"
|
||||||
|
},
|
||||||
|
{ // GitHub Dark
|
||||||
|
'NORMAL': "#E1E4E8",
|
||||||
|
'VARIABLE': "#F97583",
|
||||||
|
'CONSTANT': "#B392f0",
|
||||||
|
'FUNCTION': "#B392f0",
|
||||||
|
'OPERATOR': "#E1E4E8",
|
||||||
|
'STRING': "#9ECBFF",
|
||||||
|
'NUMBER': "#79B8FF"
|
||||||
|
},
|
||||||
|
{ // Nord
|
||||||
|
'NORMAL': "#D8DEE9",
|
||||||
|
'VARIABLE': "#81A1C1",
|
||||||
|
'CONSTANT': "#8FBCBB",
|
||||||
|
'FUNCTION': "#88C0D0",
|
||||||
|
'OPERATOR': "#81A1C1",
|
||||||
|
'STRING': "#A3BE8C",
|
||||||
|
'NUMBER': "#B48EAD"
|
||||||
|
},
|
||||||
|
{ // Monokai
|
||||||
|
'NORMAL': "#F8F8F2",
|
||||||
|
'VARIABLE': "#66D9EF",
|
||||||
|
'CONSTANT': "#F92672",
|
||||||
|
'FUNCTION': "#A6E22E",
|
||||||
|
'OPERATOR': "#F8F8F2",
|
||||||
|
'STRING': "#E6DB74",
|
||||||
|
'NUMBER': "#AE81FF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
Icon {
|
Icon {
|
||||||
id: iconLabel
|
id: iconLabel
|
||||||
|
@ -141,7 +196,6 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: editor
|
id: editor
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
@ -204,16 +258,11 @@ Item {
|
||||||
|
|
||||||
Keys.onPressed: function(event) {
|
Keys.onPressed: function(event) {
|
||||||
// Autocomplete popup events
|
// Autocomplete popup events
|
||||||
//console.log(acPopupContent.currentToken.dot, acPopupContent.previousToken.dot, "@", acPopupContent.currentToken.identifier, acPopupContent.previousToken.identifier, acPopupContent.previousToken2.identifier, objectPropertiesList.objectName, JSON.stringify(objectPropertiesList.baseText), objectPropertiesList.model.length, JSON.stringify(objectPropertiesList.categoryItems))
|
|
||||||
//console.log("Pressed key:", event.key, Qt.Key_Return, Qt.Key_Enter, event.text, acPopupContent.itemCount)
|
|
||||||
if(autocompleteEnabled && (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) && acPopupContent.itemCount > 0) {
|
if(autocompleteEnabled && (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) && acPopupContent.itemCount > 0) {
|
||||||
acPopupContent.autocomplete()
|
acPopupContent.autocomplete()
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
} else
|
} else
|
||||||
acPopupContent.itemSelected = 0
|
acPopupContent.itemSelected = 0
|
||||||
/*if(event.key == Qt.Key_Left) { // TODO: Don't reset the position when the key moved is still on the same word
|
|
||||||
if(!acPopupContent.identifierTokenTypes.includes())
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
if(event.text in openAndCloseMatches && autoClosing) {
|
if(event.text in openAndCloseMatches && autoClosing) {
|
||||||
|
@ -534,25 +583,26 @@ Item {
|
||||||
*/
|
*/
|
||||||
function colorize(tokenList) {
|
function colorize(tokenList) {
|
||||||
let parsedText = ""
|
let parsedText = ""
|
||||||
|
let scheme = colorSchemes[Helper.getSettingInt("expression_editor.color_scheme")]
|
||||||
for(let token of tokenList) {
|
for(let token of tokenList) {
|
||||||
switch(token.type) {
|
switch(token.type) {
|
||||||
case Parsing.TokenType.VARIABLE:
|
case Parsing.TokenType.VARIABLE:
|
||||||
parsedText += `<font color="${colorScheme.VARIABLE}">${token.value}</font>`
|
parsedText += `<font color="${scheme.VARIABLE}">${token.value}</font>`
|
||||||
break;
|
break;
|
||||||
case Parsing.TokenType.CONSTANT:
|
case Parsing.TokenType.CONSTANT:
|
||||||
parsedText += `<font color="${colorScheme.CONSTANT}">${token.value}</font>`
|
parsedText += `<font color="${scheme.CONSTANT}">${token.value}</font>`
|
||||||
break;
|
break;
|
||||||
case Parsing.TokenType.FUNCTION:
|
case Parsing.TokenType.FUNCTION:
|
||||||
parsedText += `<font color="${colorScheme.FUNCTION}">${Utils.escapeHTML(token.value)}</font>`
|
parsedText += `<font color="${scheme.FUNCTION}">${Utils.escapeHTML(token.value)}</font>`
|
||||||
break;
|
break;
|
||||||
case Parsing.TokenType.OPERATOR:
|
case Parsing.TokenType.OPERATOR:
|
||||||
parsedText += `<font color="${colorScheme.OPERATOR}">${Utils.escapeHTML(token.value)}</font>`
|
parsedText += `<font color="${scheme.OPERATOR}">${Utils.escapeHTML(token.value)}</font>`
|
||||||
break;
|
break;
|
||||||
case Parsing.TokenType.NUMBER:
|
case Parsing.TokenType.NUMBER:
|
||||||
parsedText += `<font color="${colorScheme.NUMBER}">${Utils.escapeHTML(token.value)}</font>`
|
parsedText += `<font color="${scheme.NUMBER}">${Utils.escapeHTML(token.value)}</font>`
|
||||||
break;
|
break;
|
||||||
case Parsing.TokenType.STRING:
|
case Parsing.TokenType.STRING:
|
||||||
parsedText += `<font color="${colorScheme.STRING}">${token.limitator}${Utils.escapeHTML(token.value)}${token.limitator}</font>`
|
parsedText += `<font color="${scheme.STRING}">${token.limitator}${Utils.escapeHTML(token.value)}${token.limitator}</font>`
|
||||||
break;
|
break;
|
||||||
case Parsing.TokenType.WHITESPACE:
|
case Parsing.TokenType.WHITESPACE:
|
||||||
case Parsing.TokenType.PUNCT:
|
case Parsing.TokenType.PUNCT:
|
||||||
|
|
|
@ -123,6 +123,10 @@ class Helper(QObject):
|
||||||
def getSetting(self, namespace):
|
def getSetting(self, namespace):
|
||||||
return config.getSetting(namespace)
|
return config.getSetting(namespace)
|
||||||
|
|
||||||
|
@Slot(str, result=int)
|
||||||
|
def getSettingInt(self, namespace):
|
||||||
|
return config.getSetting(namespace)
|
||||||
|
|
||||||
@Slot(str, result=bool)
|
@Slot(str, result=bool)
|
||||||
def getSettingBool(self, namespace):
|
def getSettingBool(self, namespace):
|
||||||
return config.getSetting(namespace)
|
return config.getSetting(namespace)
|
||||||
|
@ -135,6 +139,10 @@ class Helper(QObject):
|
||||||
def setSettingBool(self, namespace, value):
|
def setSettingBool(self, namespace, value):
|
||||||
return config.setSetting(namespace, value)
|
return config.setSetting(namespace, value)
|
||||||
|
|
||||||
|
@Slot(str, int)
|
||||||
|
def setSettingInt(self, namespace, value):
|
||||||
|
return config.setSetting(namespace, value)
|
||||||
|
|
||||||
@Slot(str)
|
@Slot(str)
|
||||||
def setLanguage(self, new_lang):
|
def setLanguage(self, new_lang):
|
||||||
config.setSetting("language", new_lang)
|
config.setSetting("language", new_lang)
|
||||||
|
|
Loading…
Reference in a new issue