Skip to content

Commit

Permalink
migrate preference screen to libadwaita (getPreferencesWidget => fill…
Browse files Browse the repository at this point in the history
…PreferencesWindow)
  • Loading branch information
axxapy committed Oct 17, 2023
1 parent f6e23b0 commit bf247dc
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,40 @@

import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';
import Adw from 'gi://Adw';

import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import * as modsListNames from './src/modsListNames.js'

export default class extends ExtensionPreferences {
getPreferencesWidget() {
fillPreferencesWindow(window) {
const settings = this.getSettings()

let prefsWidget = new Gtk.Grid({
margin_top: 18,
margin_bottom: 18,
margin_start: 18,
margin_end: 18,
column_spacing: 12,
row_spacing: 22,
visible: true
const page = new Adw.PreferencesPage({
icon_name: 'dialog-information-symbolic',
});
window.add(page);

let title = new Gtk.Label({
label: `<b>${_('settings-mods-list')}</b>`,
halign: Gtk.Align.START,
use_markup: true,
visible: true
const group = new Adw.PreferencesGroup({
title: _('settings-mods-list'),
//description: _('settings-mods-list'),
});
prefsWidget.attach(title, 0, 0, 2, 1);
page.add(group);

const mods = modsListNames.getNames()
const mods_list = modsListNames.getNames()
for (let modNum = 0; modNum < mods_list.length; modNum++) {
const key = mods_list[modNum]

for (let modNum = 0; modNum < mods.length; modNum++) {
const key = mods[modNum]

const row = modNum + 1

const label = new Gtk.Label({label: _(key), halign: Gtk.Align.START})
const rowNum = modNum + 1

let row = null
const value = settings.get_value(key)
let toggle = null
switch (value.get_type_string()) {
case "s":
toggle = new Gtk.Box({halign: Gtk.Align.END, css_classes: ['linked']})
row = new Adw.ActionRow({
title: _(key),
})
const toggle = new Gtk.Box({halign: Gtk.Align.END, css_classes: ['linked']})
const value_enum = settings.get_enum(key)
const value_string = settings.get_string(key)

Expand All @@ -51,26 +45,26 @@ export default class extends ExtensionPreferences {
for (let v in values) {
btn = new Gtk.ToggleButton({
active: value_string === values[v],
label: values[v],
group: btn
label : values[v],
group : btn
})
toggle.append(btn)
btn.connect('toggled', button => {
button.active && settings.set_string(key, values[v])
})
}
row.add_suffix(toggle)
break

default:
toggle = new Gtk.Switch({halign: Gtk.Align.END, active: settings.get_boolean(key)})
settings.bind(key, toggle, 'active', Gio.SettingsBindFlags.DEFAULT)
row = new Adw.SwitchRow({
title: _(key),
//subtitle: _(key),
})
settings.bind(key, row, 'active', Gio.SettingsBindFlags.DEFAULT)
}

prefsWidget.attach(label, 0, row, 1, 1);
prefsWidget.attach(toggle, 1, row, 1, 1);
group.add(row);
}


return prefsWidget
}
}

0 comments on commit bf247dc

Please sign in to comment.