mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-19 04:08:48 +00:00
sidebar: translator: save selected language, cleaner selector
This commit is contained in:
parent
0fb28af3c7
commit
23f0e90a7b
4 changed files with 36 additions and 14 deletions
|
|
@ -66,8 +66,8 @@ Singleton {
|
|||
property QtObject language: QtObject {
|
||||
property QtObject translator: QtObject {
|
||||
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 targetLanguage: "English" // Run `trans -list-all` for available languages
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ Item {
|
|||
property real dialogMargin: 30
|
||||
property string titleText: "Selection Dialog"
|
||||
property alias items: choiceModel.values
|
||||
property int selectedId: -1 // -1 means no selection
|
||||
property int selectedId: choiceListView.currentIndex
|
||||
property var defaultChoice
|
||||
|
||||
signal canceled();
|
||||
signal selected(var result);
|
||||
|
|
@ -68,6 +69,7 @@ Item {
|
|||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
clip: true
|
||||
currentIndex: root.defaultChoice !== undefined ? root.items.indexOf(root.defaultChoice) : -1
|
||||
|
||||
model: ScriptModel {
|
||||
id: choiceModel
|
||||
|
|
@ -85,11 +87,11 @@ Item {
|
|||
}
|
||||
|
||||
description: modelData.toString()
|
||||
checked: index === root.selectedId
|
||||
checked: index === choiceListView.currentIndex
|
||||
|
||||
onCheckedChanged: {
|
||||
if (checked) {
|
||||
root.selectedId = index;
|
||||
choiceListView.currentIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,10 @@ Item {
|
|||
|
||||
property bool showLanguageSelector: false
|
||||
property bool languageSelectorTarget: false // true for target language, false for source language
|
||||
property string languageSelectorLanguage: ""
|
||||
|
||||
function showLanguageSelectorDialog(isTargetLang: bool) {
|
||||
root.showLanguageSelector = true
|
||||
root.languageSelectorTarget = isTargetLang;
|
||||
root.languageSelectorLanguage = isTargetLang ? root.targetLanguage : root.sourceLanguage;
|
||||
root.showLanguageSelector = true
|
||||
}
|
||||
|
||||
onFocusChanged: (focus) => {
|
||||
|
|
@ -93,9 +91,12 @@ Item {
|
|||
}
|
||||
}
|
||||
onExited: (exitCode, exitStatus) => {
|
||||
root.languages = getLanguagesProc.bufferList
|
||||
.filter(lang => lang.trim().length > 0) // Filter out empty lines
|
||||
.sort((a, b) => a.localeCompare(b)); // Sort alphabetically
|
||||
// Ensure "auto" is always the first language
|
||||
let langs = getLanguagesProc.bufferList
|
||||
.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
|
||||
}
|
||||
}
|
||||
|
|
@ -224,6 +225,7 @@ Item {
|
|||
id: languageSelectorDialog
|
||||
titleText: qsTr("Select Language")
|
||||
items: root.languages
|
||||
defaultChoice: root.languageSelectorTarget ? root.targetLanguage : root.sourceLanguage
|
||||
onCanceled: () => {
|
||||
root.showLanguageSelector = false;
|
||||
}
|
||||
|
|
@ -233,10 +235,10 @@ Item {
|
|||
|
||||
if (root.languageSelectorTarget) {
|
||||
root.targetLanguage = result;
|
||||
ConfigOptions.language.translator.targetLanguage = result; // Save to config
|
||||
ConfigLoader.setConfigValueAndSave("language.translator.targetLanguage", result); // Save to config
|
||||
} else {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -14,13 +14,18 @@ import Qt.labs.platform
|
|||
/**
|
||||
* Loads and manages the shell configuration file.
|
||||
* 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 {
|
||||
id: root
|
||||
property string filePath: Directories.shellConfigPath
|
||||
property bool firstLoad: true
|
||||
property bool preventNextLoad: false
|
||||
property var preventNextNotification: false
|
||||
|
||||
onPreventNextNotificationChanged: {
|
||||
console.log("HMM: preventNextNotification:", root.preventNextNotification);
|
||||
}
|
||||
|
||||
function loadConfig() {
|
||||
configFileView.reload()
|
||||
|
|
@ -87,11 +92,19 @@ Singleton {
|
|||
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 {
|
||||
id: delayedFileRead
|
||||
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
||||
running: false
|
||||
onTriggered: {
|
||||
console.log("GONNA APPLY KONFIG preventNextNotification:", root.preventNextNotification);
|
||||
if (root.preventNextLoad) {
|
||||
root.preventNextLoad = false;
|
||||
return;
|
||||
|
|
@ -99,8 +112,13 @@ Singleton {
|
|||
if (root.firstLoad) {
|
||||
root.applyConfig(configFileView.text())
|
||||
} else {
|
||||
console.log("APPLYING: preventNextNotification:", root.preventNextNotification);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue