forked from Shinonome/dots-hyprland
sidebar: translator: save selected language, cleaner selector
This commit is contained in:
@@ -66,8 +66,8 @@ Singleton {
|
|||||||
property QtObject language: QtObject {
|
property QtObject language: QtObject {
|
||||||
property QtObject translator: QtObject {
|
property QtObject translator: QtObject {
|
||||||
property string engine: "auto" // Run `trans -list-engines` for available engines. auto should use google
|
property string engine: "auto" // Run `trans -list-engines` for available engines. auto should use google
|
||||||
|
property string targetLanguage: "auto" // Run `trans -list-all` for available languages
|
||||||
property string sourceLanguage: "auto"
|
property string sourceLanguage: "auto"
|
||||||
property string targetLanguage: "English" // Run `trans -list-all` for available languages
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ Item {
|
|||||||
property real dialogMargin: 30
|
property real dialogMargin: 30
|
||||||
property string titleText: "Selection Dialog"
|
property string titleText: "Selection Dialog"
|
||||||
property alias items: choiceModel.values
|
property alias items: choiceModel.values
|
||||||
property int selectedId: -1 // -1 means no selection
|
property int selectedId: choiceListView.currentIndex
|
||||||
|
property var defaultChoice
|
||||||
|
|
||||||
signal canceled();
|
signal canceled();
|
||||||
signal selected(var result);
|
signal selected(var result);
|
||||||
@@ -68,6 +69,7 @@ Item {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
clip: true
|
clip: true
|
||||||
|
currentIndex: root.defaultChoice !== undefined ? root.items.indexOf(root.defaultChoice) : -1
|
||||||
|
|
||||||
model: ScriptModel {
|
model: ScriptModel {
|
||||||
id: choiceModel
|
id: choiceModel
|
||||||
@@ -85,11 +87,11 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
description: modelData.toString()
|
description: modelData.toString()
|
||||||
checked: index === root.selectedId
|
checked: index === choiceListView.currentIndex
|
||||||
|
|
||||||
onCheckedChanged: {
|
onCheckedChanged: {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
root.selectedId = index;
|
choiceListView.currentIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,10 @@ Item {
|
|||||||
|
|
||||||
property bool showLanguageSelector: false
|
property bool showLanguageSelector: false
|
||||||
property bool languageSelectorTarget: false // true for target language, false for source language
|
property bool languageSelectorTarget: false // true for target language, false for source language
|
||||||
property string languageSelectorLanguage: ""
|
|
||||||
|
|
||||||
function showLanguageSelectorDialog(isTargetLang: bool) {
|
function showLanguageSelectorDialog(isTargetLang: bool) {
|
||||||
root.showLanguageSelector = true
|
|
||||||
root.languageSelectorTarget = isTargetLang;
|
root.languageSelectorTarget = isTargetLang;
|
||||||
root.languageSelectorLanguage = isTargetLang ? root.targetLanguage : root.sourceLanguage;
|
root.showLanguageSelector = true
|
||||||
}
|
}
|
||||||
|
|
||||||
onFocusChanged: (focus) => {
|
onFocusChanged: (focus) => {
|
||||||
@@ -93,9 +91,12 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
root.languages = getLanguagesProc.bufferList
|
// Ensure "auto" is always the first language
|
||||||
.filter(lang => lang.trim().length > 0) // Filter out empty lines
|
let langs = getLanguagesProc.bufferList
|
||||||
.sort((a, b) => a.localeCompare(b)); // Sort alphabetically
|
.filter(lang => lang.trim().length > 0 && lang !== "auto")
|
||||||
|
.sort((a, b) => a.localeCompare(b));
|
||||||
|
langs.unshift("auto");
|
||||||
|
root.languages = langs;
|
||||||
getLanguagesProc.bufferList = []; // Clear the buffer
|
getLanguagesProc.bufferList = []; // Clear the buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,6 +225,7 @@ Item {
|
|||||||
id: languageSelectorDialog
|
id: languageSelectorDialog
|
||||||
titleText: qsTr("Select Language")
|
titleText: qsTr("Select Language")
|
||||||
items: root.languages
|
items: root.languages
|
||||||
|
defaultChoice: root.languageSelectorTarget ? root.targetLanguage : root.sourceLanguage
|
||||||
onCanceled: () => {
|
onCanceled: () => {
|
||||||
root.showLanguageSelector = false;
|
root.showLanguageSelector = false;
|
||||||
}
|
}
|
||||||
@@ -233,10 +235,10 @@ Item {
|
|||||||
|
|
||||||
if (root.languageSelectorTarget) {
|
if (root.languageSelectorTarget) {
|
||||||
root.targetLanguage = result;
|
root.targetLanguage = result;
|
||||||
ConfigOptions.language.translator.targetLanguage = result; // Save to config
|
ConfigLoader.setConfigValueAndSave("language.translator.targetLanguage", result); // Save to config
|
||||||
} else {
|
} else {
|
||||||
root.sourceLanguage = result;
|
root.sourceLanguage = result;
|
||||||
ConfigOptions.language.translator.sourceLanguage = result; // Save to config
|
ConfigLoader.setConfigValueAndSave("language.translator.sourceLanguage", result); // Save to config
|
||||||
}
|
}
|
||||||
|
|
||||||
translateTimer.restart(); // Restart translation after language change
|
translateTimer.restart(); // Restart translation after language change
|
||||||
|
|||||||
@@ -14,13 +14,18 @@ import Qt.labs.platform
|
|||||||
/**
|
/**
|
||||||
* Loads and manages the shell configuration file.
|
* Loads and manages the shell configuration file.
|
||||||
* The config file is by default at XDG_CONFIG_HOME/illogical-impulse/config.json.
|
* The config file is by default at XDG_CONFIG_HOME/illogical-impulse/config.json.
|
||||||
* Automatically reloaded when the file changes, but does not provide a way to save changes.
|
* Automatically reloaded when the file changes.
|
||||||
*/
|
*/
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
property string filePath: Directories.shellConfigPath
|
property string filePath: Directories.shellConfigPath
|
||||||
property bool firstLoad: true
|
property bool firstLoad: true
|
||||||
property bool preventNextLoad: false
|
property bool preventNextLoad: false
|
||||||
|
property var preventNextNotification: false
|
||||||
|
|
||||||
|
onPreventNextNotificationChanged: {
|
||||||
|
console.log("HMM: preventNextNotification:", root.preventNextNotification);
|
||||||
|
}
|
||||||
|
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
configFileView.reload()
|
configFileView.reload()
|
||||||
@@ -87,11 +92,19 @@ Singleton {
|
|||||||
Hyprland.dispatch(`exec echo '${StringUtils.shellSingleQuoteEscape(JSON.stringify(plainConfig, null, 2))}' > '${root.filePath}'`)
|
Hyprland.dispatch(`exec echo '${StringUtils.shellSingleQuoteEscape(JSON.stringify(plainConfig, null, 2))}' > '${root.filePath}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setConfigValueAndSave(nestedKey, value, preventNextNotification = true) {
|
||||||
|
setLiveConfigValue(nestedKey, value);
|
||||||
|
root.preventNextNotification = preventNextNotification;
|
||||||
|
console.log("SETTING: preventNextNotification:", root.preventNextNotification);
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: delayedFileRead
|
id: delayedFileRead
|
||||||
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
||||||
running: false
|
running: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
|
console.log("GONNA APPLY KONFIG preventNextNotification:", root.preventNextNotification);
|
||||||
if (root.preventNextLoad) {
|
if (root.preventNextLoad) {
|
||||||
root.preventNextLoad = false;
|
root.preventNextLoad = false;
|
||||||
return;
|
return;
|
||||||
@@ -99,8 +112,13 @@ Singleton {
|
|||||||
if (root.firstLoad) {
|
if (root.firstLoad) {
|
||||||
root.applyConfig(configFileView.text())
|
root.applyConfig(configFileView.text())
|
||||||
} else {
|
} else {
|
||||||
|
console.log("APPLYING: preventNextNotification:", root.preventNextNotification);
|
||||||
root.applyConfig(configFileView.text())
|
root.applyConfig(configFileView.text())
|
||||||
Hyprland.dispatch(`exec notify-send "${qsTr("Shell configuration reloaded")}" "${root.filePath}"`)
|
if (!root.preventNextNotification) {
|
||||||
|
Hyprland.dispatch(`exec notify-send "${qsTr("Shell configuration reloaded")}" "${root.filePath}"`)
|
||||||
|
} else {
|
||||||
|
// root.preventNextNotification = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user