citadel-realms/js/ConfigureRealm.js

152 lines
5.4 KiB
JavaScript
Raw Normal View History

2024-11-12 17:12:37 -05:00
var _a;
import GObject from 'gi://GObject';
import Gdk from 'gi://Gdk?version=4.0';
import Gtk from 'gi://Gtk?version=4.0';
import Adw from 'gi://Adw';
import { BoolOptionData } from './model/RealmConfig.js';
import { Base16Theme } from './model/Base16Themes.js';
import { RealmManager } from './model/RealmManager.js';
import { ColorSchemeChooser } from './ColorSchemeChooser.js';
class OptionState {
constructor(row) {
this.value = null;
this.row = row;
}
initValue(value) {
this.value = value;
this.originalValue = value;
this.row.active = value;
}
/** @param {any} value */
setValue(value) {
this.value = value;
}
hasChanged() {
return this.value !== this.originalValue;
}
}
export class ConfigureRealm extends Adw.NavigationPage {
constructor() {
var _b, _c;
super();
this.realm = null;
this.optionState = new Map();
this.theme = Base16Theme.lookup('default-dark');
this._addOptions();
const keyController = new Gtk.EventControllerKey();
keyController.connect('key-pressed', (_, keyval) => {
if (keyval === Gdk.KEY_j) {
this.vfunc_move_focus(Gtk.DirectionType.TAB_FORWARD);
}
else if (keyval === Gdk.KEY_k) {
this.vfunc_move_focus(Gtk.DirectionType.TAB_BACKWARD);
}
});
this.add_controller(keyController);
(_b = this._labelColorButton) === null || _b === void 0 ? void 0 : _b.connect('notify::rgba', () => this._scanChanges());
(_c = this._colorSchemeButton) === null || _c === void 0 ? void 0 : _c.connect('clicked', () => {
var _b;
(_b = this.navigationView) === null || _b === void 0 ? void 0 : _b.push_by_tag('realm-colorscheme');
});
}
get colorschemeChooser() {
return this._colorschemeChooser;
}
set colorschemeChooser(val) {
this._colorschemeChooser = val;
}
set navigationView(val) {
var _b;
this._navigationView = val;
(_b = this._navigationView) === null || _b === void 0 ? void 0 : _b.connect('popped', (_view, page) => {
if (page === this.colorschemeChooser) {
let theme = this.colorschemeChooser.getSelectedTheme();
if (theme && this._colorSchemeButton) {
this.theme = theme;
this._colorSchemeButton.label = this.theme.name;
}
}
});
}
get navigationView() {
return this._navigationView;
}
configure(realm) {
this.realm = realm;
this.set_title(`Configure realm-${realm.name}`);
this._setOptions(realm);
}
_setOptions(realm) {
var _b;
let config = realm.config;
this.optionState.forEach((op, name) => {
let v = config.get_bool(name);
op.initValue(v);
});
let scheme = realm.config.get_colorscheme();
this.theme = Base16Theme.lookup(scheme);
if (this.theme && this._colorSchemeButton) {
this._colorSchemeButton.label = this.theme.name;
(_b = this.colorschemeChooser) === null || _b === void 0 ? void 0 : _b.selectTheme(this.theme.id);
}
let realmfs_list = RealmManager.instance().realmfsList();
// @ts-ignore
let model = this._realmfsCombo.model;
if (model.n_items > 0) {
model.splice(0, model.n_items, []);
}
realmfs_list.forEach(realmfs => model.append(realmfs.name));
let labelColor = realm.getLabelColor();
this._labelColorButton.rgba = labelColor;
this._scanChanges();
}
_addOptions() {
BoolOptionData.allOptions().forEach(option => {
let row = new Adw.SwitchRow({
title: option.description,
});
if (option.tooltip.length > 0) {
row.tooltipMarkup = option.tooltip;
}
let state = new OptionState(row);
this.optionState.set(option.name, state);
row.connect("notify::active", () => {
state.setValue(row.active);
this._scanChanges();
});
this._optionsGroup.add(row);
});
}
_scanChanges() {
var _b;
let changed = false;
this.optionState.forEach(op => {
if (op.hasChanged()) {
changed = true;
}
});
let labelColor = (_b = this.realm) === null || _b === void 0 ? void 0 : _b.getLabelColor();
if (labelColor) {
if (!this._labelColorButton.rgba.equal(labelColor)) {
changed = true;
}
}
this._changedBanner.set_revealed(changed);
}
_onApplyClicked() {
print("clikkk");
}
}
_a = ConfigureRealm;
(() => {
GObject.registerClass({
GTypeName: "ConfigureRealm",
Template: 'resource:///com/subgraph/citadel/Realms/ui/ConfigureRealm.ui',
InternalChildren: ['optionsGroup', 'changedBanner', 'overlayCombo', 'realmfsCombo', 'colorSchemeButton', 'labelColorButton'],
Properties: {
'navigation-view': GObject.ParamSpec.object('navigation-view', '', '', GObject.ParamFlags.READWRITE, Adw.NavigationView),
'colorscheme-chooser': GObject.ParamSpec.object('colorscheme-chooser', '', '', GObject.ParamFlags.READWRITE, ColorSchemeChooser),
}
}, _a);
})();