For example in this menu:
This app was created in Gnome Builder, and template app has a basic menu. But how to improve it? It is not just classic code of XML(with child, objects), not understand how to attach radiobuttons, or something, only what I tried sucesfully - just label with action.
Maybe, what I must to know/read?
*after asking found this:
<menu id="primary-menu">
<section>
<attribute translatable="yes" name="label">Temperature Unit</attribute>
<item>
<attribute translatable="yes" name="label">_Celsius</attribute>
<attribute name="action">app.temperature-unit</attribute>
<attribute name="target">centigrade</attribute>
</item>
<item>
<attribute translatable="yes" name="label">_Fahrenheit</attribute>
<attribute name="action">app.temperature-unit</attribute>
<attribute name="target">fahrenheit</attribute>
</item>
</section>
<section>
<item>
<attribute name="action">win.about</attribute>
<attribute name="label" translatable="yes">_About Weather</attribute>
</item>
</section>
With js:
function resolveDefaultTemperatureUnit(unit) {
unit = GWeather.TemperatureUnit.to_real(unit);
if (unit == GWeather.TemperatureUnit.CENTIGRADE)
return new GLib.Variant('s', 'centigrade');
else if (unit == GWeather.TemperatureUnit.FAHRENHEIT)
return new GLib.Variant('s', 'fahrenheit');
else
return new GLib.Variant('s', 'default');
}
let temperatureAction = new Gio.SimpleAction({
enabled: true,
name: 'temperature-unit',
state: resolveDefaultTemperatureUnit(gwSettings.get_enum('temperature-unit')),
parameter_type: new GLib.VariantType('s')
});
temperatureAction.connect('activate', function (_, parameter) {
gwSettings.set_value('temperature-unit', parameter);
if (legacyGwSettings) {
legacyGwSettings.set_value('temperature-unit', parameter);
}
});
gwSettings.connect('changed::temperature-unit', function () {
temperatureAction.state = resolveDefaultTemperatureUnit(gwSettings.get_enum('temperature-unit'));
});
this.add_action(temperatureAction);
From this app:
system
(system)
Closed
April 27, 2024, 2:19pm
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.