Commit 1afc2b11 authored by Florian Müllner's avatar Florian Müllner

wip: Port to GTK4

parent 23c2915c
Pipeline #212540 passed with stages
in 40 seconds
......@@ -29,9 +29,9 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
margin_start: 36,
margin_end: 36,
});
this.add(box);
this.set_child(box);
box.add(new Gtk.Label({
box.append(new Gtk.Label({
label: '<b>%s</b>'.format(_('Workspace Rules')),
use_markup: true,
halign: Gtk.Align.START,
......@@ -40,9 +40,9 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
valign: Gtk.Align.START,
show_separators: true,
});
this._list.set_header_func(this._updateHeader.bind(this));
box.add(this._list);
box.append(this._list);
const context = this._list.get_style_context();
const cssProvider = new Gtk.CssProvider();
......@@ -53,7 +53,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_class('frame');
this._list.add(new NewRuleRow());
this._list.insert(new NewRuleRow(), -1);
this._actionGroup = new Gio.SimpleActionGroup();
this._list.insert_action_group('rules', this._actionGroup);
......@@ -84,12 +84,10 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._sync();
this.connect('destroy', () => this._settings.run_dispose());
this.show_all();
}
_onAddActivated() {
const dialog = new NewRuleDialog(this.get_toplevel());
const dialog = new NewRuleDialog(this.get_root());
dialog.connect('response', (dlg, id) => {
const appInfo = id === Gtk.ResponseType.OK
? dialog.get_widget().get_app_info() : null;
......@@ -101,6 +99,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
}
dialog.destroy();
});
dialog.show();
}
_onRemoveActivated(action, param) {
......@@ -113,7 +112,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
}
_getRuleRows() {
return this._list.get_children().filter(row => !!row.id);
return [...this._list].filter(row => !!row.id);
}
_sync() {
......@@ -139,17 +138,11 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
const removed = oldRules.filter(
({ id }) => !newRules.find(r => r.id === id));
removed.forEach(r => r.destroy());
removed.forEach(r => this._list.remove(r));
this._settings.unblock_signal_handler(this._changedId);
this._updateAction.enabled = true;
}
_updateHeader(row, before) {
if (!before || row.get_header())
return;
row.set_header(new Gtk.Separator());
}
});
const RuleRow = GObject.registerClass({
......@@ -165,12 +158,6 @@ const RuleRow = GObject.registerClass({
},
}, class RuleRow extends Gtk.ListBoxRow {
_init(appInfo, value) {
super._init({
activatable: false,
value,
});
this._appInfo = appInfo;
const box = new Gtk.Box({
spacing: 6,
margin_top: 6,
......@@ -179,12 +166,19 @@ const RuleRow = GObject.registerClass({
margin_end: 6,
});
super._init({
activatable: false,
value,
child: box,
});
this._appInfo = appInfo;
const icon = new Gtk.Image({
gicon: appInfo.get_icon(),
pixel_size: 32,
});
icon.get_style_context().add_class('icon-dropshadow');
box.add(icon);
box.append(icon);
const label = new Gtk.Label({
label: appInfo.get_display_name(),
......@@ -193,7 +187,7 @@ const RuleRow = GObject.registerClass({
max_width_chars: 20,
ellipsize: Pango.EllipsizeMode.END,
});
box.add(label);
box.append(label);
const spinButton = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
......@@ -207,26 +201,17 @@ const RuleRow = GObject.registerClass({
this.bind_property('value',
spinButton, 'value',
GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.BIDIRECTIONAL);
box.add(spinButton);
box.append(spinButton);
const button = new Gtk.Button({
action_name: 'rules.remove',
action_target: new GLib.Variant('s', this.id),
image: new Gtk.Image({
icon_name: 'edit-delete-symbolic',
pixel_size: 16,
}),
});
box.add(button);
this.add(box);
this.connect('notify::value', () => {
const actionGroup = this.get_action_group('rules');
actionGroup.activate_action('update', null);
icon_name: 'edit-delete-symbolic',
});
box.append(button);
this.show_all();
this.connect('notify::value',
() => this.activate_action('rules.update', null));
}
get id() {
......@@ -239,19 +224,17 @@ class NewRuleRow extends Gtk.ListBoxRow {
_init() {
super._init({
action_name: 'rules.add',
child: new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
}),
});
this.get_accessible().set_name(_('Add Rule'));
this.add(new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
}));
this.show_all();
this.update_property(
[Gtk.AccessibleProperty.LABEL], [_('Add Rule')]);
}
});
......@@ -273,8 +256,6 @@ class NewRuleDialog extends Gtk.AppChooserDialog {
this.get_widget().connect('application-selected',
this._updateSensitivity.bind(this));
this._updateSensitivity();
this.show();
}
_updateSensitivity() {
......
......@@ -26,18 +26,21 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
});
const box = new Gtk.Box();
this.add(box);
this.set_child(box);
this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
show_separators: true,
halign: Gtk.Align.CENTER,
valign: Gtk.Align.START,
hexpand: true,
margin: 60,
margin_top: 60,
margin_bottom: 60,
margin_start: 60,
margin_end: 60,
});
this._list.get_style_context().add_class('frame');
this._list.set_header_func(this._updateHeader.bind(this));
box.add(this._list);
box.append(this._list);
this._actionGroup = new Gio.SimpleActionGroup();
this._list.insert_action_group('theme', this._actionGroup);
......@@ -90,11 +93,10 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
}
_addTheme(name) {
const row = new ThemeRow(name);
const row = new ThemeRow(name, this._settings);
this._rows.set(name, row);
this._list.add(row);
row.show_all();
this._list.insert(row, -1);
}
async _enumerateDir(dir) {
......@@ -121,31 +123,29 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
return fileInfos.map(info => info.get_name());
}
_updateHeader(row, before) {
if (!before || row.get_header())
return;
row.set_header(new Gtk.Separator());
}
});
const ThemeRow = GObject.registerClass(
class ThemeRow extends Gtk.ListBoxRow {
_init(name) {
this._name = new GLib.Variant('s', name);
super._init({
action_name: 'theme.name',
action_target: this._name,
});
_init(name, settings) {
this._name = name;
this._settings = settings;
const box = new Gtk.Box({
spacing: 12,
margin: 12,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
});
const target = new GLib.Variant('s', name);
super._init({
action_name: 'theme.name',
action_target: target,
child: box,
});
this.add(box);
box.add(new Gtk.Label({
box.append(new Gtk.Label({
label: name || 'Default',
hexpand: true,
xalign: 0,
......@@ -157,24 +157,21 @@ class ThemeRow extends Gtk.ListBoxRow {
icon_name: 'emblem-ok-symbolic',
pixel_size: 16,
});
box.add(this._checkmark);
box.append(this._checkmark);
box.show_all();
const id = this._settings.connect('changed::name',
this._syncCheckmark.bind(this));
this._syncCheckmark();
const id = this.connect('parent-set', () => {
this.disconnect(id);
const actionGroup = this.get_action_group('theme');
actionGroup.connect('action-state-changed::name',
this._syncCheckmark.bind(this));
this._syncCheckmark();
this.connect('destroy', () => {
this._settings.disconnect(id);
this._settings = null;
});
}
_syncCheckmark() {
const actionGroup = this.get_action_group('theme');
const state = actionGroup.get_action_state('name');
this._checkmark.opacity = this._name.equal(state);
const visible = this._name === this._settings.get_string('name');
this._checkmark.opacity = visible ? 1. : 0.;
}
});
......@@ -182,8 +179,5 @@ function init() {
}
function buildPrefsWidget() {
let widget = new UserThemePrefsWidget();
widget.show_all();
return widget;
return new UserThemePrefsWidget();
}
......@@ -27,7 +27,7 @@ class WindowListPrefsWidget extends Gtk.Box {
});
let groupingLabel = '<b>%s</b>'.format(_('Window Grouping'));
this.add(new Gtk.Label({
this.append(new Gtk.Label({
label: groupingLabel, use_markup: true,
halign: Gtk.Align.START,
}));
......@@ -37,7 +37,7 @@ class WindowListPrefsWidget extends Gtk.Box {
spacing: 12,
margin_bottom: 12,
});
this.add(box);
this.append(box);
const context = box.get_style_context();
const cssProvider = new Gtk.CssProvider();
......@@ -70,13 +70,13 @@ class WindowListPrefsWidget extends Gtk.Box {
continue;
}
radio = new Gtk.RadioButton({
radio = new Gtk.CheckButton({
active: !i,
label,
group: radio,
margin_end: 12,
});
box.add(radio);
box.append(radio);
if (currentMode === mode)
currentRadio = radio;
......@@ -94,15 +94,13 @@ class WindowListPrefsWidget extends Gtk.Box {
label: _('Show on all monitors'),
});
this._settings.bind('show-on-all-monitors', check, 'active', Gio.SettingsBindFlags.DEFAULT);
this.add(check);
this.append(check);
check = new Gtk.CheckButton({
label: _('Show windows from all workspaces'),
});
this._settings.bind('display-all-workspaces', check, 'active', Gio.SettingsBindFlags.DEFAULT);
this.add(check);
this.show_all();
this.append(check);
}
});
......
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
/* exported init buildPrefsWidget */
const { Gdk, Gio, GLib, GObject, Gtk, Pango } = imports.gi;
const { Gio, GLib, GObject, Gtk, Pango } = imports.gi;
const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;
......@@ -28,9 +28,9 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
margin_start: 36,
margin_end: 36,
});
this.add(box);
this.set_child(box);
box.add(new Gtk.Label({
box.append(new Gtk.Label({
label: '<b>%s</b>'.format(_('Workspace Names')),
use_markup: true,
halign: Gtk.Align.START,
......@@ -39,10 +39,10 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
valign: Gtk.Align.START,
show_separators: true,
});
this._list.set_header_func(this._updateHeader.bind(this));
this._list.connect('row-activated', (l, row) => row.edit());
box.add(this._list);
box.append(this._list);
const context = this._list.get_style_context();
const cssProvider = new Gtk.CssProvider();
......@@ -53,7 +53,7 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
context.add_class('frame');
this._list.add(new NewWorkspaceRow());
this._list.insert(new NewWorkspaceRow(), -1);
this._actionGroup = new Gio.SimpleActionGroup();
this._list.insert_action_group('workspaces', this._actionGroup);
......@@ -94,12 +94,10 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
this._settings.connect(`changed::${WORKSPACE_KEY}`,
this._sync.bind(this));
this._sync();
this.show_all();
}
_getWorkspaceRows() {
return this._list.get_children().filter(row => row.name);
return [...this._list].filter(row => row.name);
}
_sync() {
......@@ -111,17 +109,11 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
const removed = oldNames.filter(n => !newNames.includes(n));
const added = newNames.filter(n => !oldNames.includes(n));
removed.forEach(n => rows.find(r => r.name === n).destroy());
removed.forEach(n => this._list.remove(rows.find(r => r.name === n)));
added.forEach(n => {
this._list.insert(new WorkspaceRow(n), newNames.indexOf(n));
});
}
_updateHeader(row, before) {
if (!before || row.get_header())
return;
row.set_header(new Gtk.Separator());
}
});
const WorkspaceRow = GObject.registerClass(
......@@ -129,6 +121,13 @@ class WorkspaceRow extends Gtk.ListBoxRow {
_init(name) {
super._init({ name });
const controller = new Gtk.ShortcutController();
controller.add_shortcut(new Gtk.Shortcut({
trigger: Gtk.ShortcutTrigger.parse_string('Escape'),
action: Gtk.CallbackAction.new(this._stopEdit.bind(this)),
}));
this.add_controller(controller);
const box = new Gtk.Box({
spacing: 12,
margin_top: 6,
......@@ -145,18 +144,14 @@ class WorkspaceRow extends Gtk.ListBoxRow {
});
this.bind_property('name', label, 'label',
GObject.BindingFlags.SYNC_CREATE);
box.add(label);
box.append(label);
const image = new Gtk.Image({
icon_name: 'edit-delete-symbolic',
pixel_size: 16,
});
const button = new Gtk.Button({
action_name: 'workspaces.remove',
action_target: new GLib.Variant('s', name),
image,
icon_name: 'edit-delete-symbolic',
});
box.add(button);
box.append(button);
this._entry = new Gtk.Entry({
max_width_chars: 25,
......@@ -165,7 +160,7 @@ class WorkspaceRow extends Gtk.ListBoxRow {
this._stack = new Gtk.Stack();
this._stack.add_named(box, 'display');
this._stack.add_named(this._entry, 'edit');
this.add(this._stack);
this.child = this._stack;
this._entry.connect('activate', () => {
this.name = this._entry.text;
......@@ -176,17 +171,11 @@ class WorkspaceRow extends Gtk.ListBoxRow {
return;
this._stopEdit();
});
this._entry.connect('key-press-event',
this._onEntryKeyPress.bind(this));
this.connect('notify::name', () => {
button.action_target = new GLib.Variant('s', this.name);
const actionGroup = this.get_action_group('workspaces');
actionGroup.activate_action('update', null);
this.activate_action('workspaces.update', null);
});
this.show_all();
}
edit() {
......@@ -199,14 +188,6 @@ class WorkspaceRow extends Gtk.ListBoxRow {
this.grab_focus();
this._stack.visible_child_name = 'display';
}
_onEntryKeyPress(entry, event) {
const [, keyval] = event.get_keyval();
if (keyval !== Gdk.KEY_Escape)
return Gdk.EVENT_PROPAGATE;
this._stopEdit();
return Gdk.EVENT_STOP;
}
});
const NewWorkspaceRow = GObject.registerClass(
......@@ -214,19 +195,17 @@ class NewWorkspaceRow extends Gtk.ListBoxRow {
_init() {
super._init({
action_name: 'workspaces.add',
});
this.get_accessible().set_name(_('Add Workspace'));
this.add(new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
}));
this.show_all();
child: new Gtk.Image({
icon_name: 'list-add-symbolic',
pixel_size: 16,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
}),
});
this.update_property(
[Gtk.AccessibleProperty.LABEL], [_('Add Workspace')]);
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment