From 325967e8d8d242b63bf58492639b9f96d1eba228 Mon Sep 17 00:00:00 2001 From: Mateus Rodrigues Costa Date: Sat, 1 Jun 2024 14:21:56 -0300 Subject: [PATCH] Refactor preferences screen Fixes #3 --- src/cmb/DefaultWorkspace.cmb | 24 ------------------- src/metadata.json | 2 +- src/prefs.js | 45 +++++++++++++++++++++++++----------- src/ui/prefs.ui | 29 ----------------------- 4 files changed, 33 insertions(+), 67 deletions(-) delete mode 100644 src/cmb/DefaultWorkspace.cmb delete mode 100644 src/ui/prefs.ui diff --git a/src/cmb/DefaultWorkspace.cmb b/src/cmb/DefaultWorkspace.cmb deleted file mode 100644 index 2b3ee05..0000000 --- a/src/cmb/DefaultWorkspace.cmb +++ /dev/null @@ -1,24 +0,0 @@ - - - - - (1,None,"defaultworkspace.ui","defaultworkspace.ui",None,None,None,None,None,None,None) - - - (1,1,"AdwPreferencesPage","preferences_main_page",None,None,None,None,-1,None), - (1,2,"AdwPreferencesGroup","workspace_group",1,None,None,None,-1,None), - (1,3,"AdwSpinRow","default_workspace_spinrow",2,None,None,None,-1,None), - (1,4,"GtkAdjustment","default_workspace_adjustment",3,None,None,None,-1,None) - - - (1,2,"AdwPreferencesGroup","title","Workspace",None,None,None,None,None,None,None,None,None), - (1,3,"AdwPreferencesRow","title","Default Workspace",None,None,None,None,None,None,None,None,None), - (1,3,"AdwSpinRow","adjustment",None,None,None,None,None,4,None,None,None,None), - (1,4,"GtkAdjustment","lower","1.0",None,None,None,None,None,None,None,None,None), - (1,4,"GtkAdjustment","page-increment","1.0",None,None,None,None,None,None,None,None,None), - (1,4,"GtkAdjustment","page-size","1.0",None,None,None,None,None,None,None,None,None), - (1,4,"GtkAdjustment","step-increment","1.0",None,None,None,None,None,None,None,None,None), - (1,4,"GtkAdjustment","upper","37.0",None,None,None,None,None,None,None,None,None), - (1,4,"GtkAdjustment","value","1.0",None,None,None,None,None,None,None,None,None) - - diff --git a/src/metadata.json b/src/metadata.json index bce233a..fa10d97 100644 --- a/src/metadata.json +++ b/src/metadata.json @@ -5,5 +5,5 @@ "url": "https://github.com/MateusRodCosta/gnome-shell-extension-default-workspace", "uuid": "default-workspace@mateusrodcosta.com", "settings-schema": "org.gnome.shell.extensions.default-workspace", - "version": 7 + "version": 8 } diff --git a/src/prefs.js b/src/prefs.js index 2f3c394..24ae922 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -1,6 +1,7 @@ +import Adw from 'gi://Adw'; import Gio from 'gi://Gio'; import Gtk from 'gi://Gtk'; -import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; +import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; const DEFAULT_WORKSPACE_KEY = 'default-workspace-number'; @@ -9,21 +10,39 @@ export default class DefaultWorkspacePreferences extends ExtensionPreferences { fillPreferencesWindow(window) { let settings = this.getSettings(); - let builder = new Gtk.Builder(); + const page = new Adw.PreferencesPage({ + title: _('Default Workspace'), + icon_name: 'dialog-information-symbolic', + }); + window.add(page); + + const group = new Adw.PreferencesGroup({ + title: _('Workspace'), + }); + page.add(group); + + const spin_row = new Adw.SpinRow({ + title: _('Default Workspace'), + }); + group.add(spin_row); - builder.add_from_file(`${this.path}/ui/prefs.ui`); + const adjustment = new Gtk.Adjustment({ + lower: 1.0, + page_increment: 1.0, + page_size: 1.0, + step_increment: 1.0, + upper: 37.0, + lower: 1.0, + }); + spin_row.set_adjustment(adjustment); - let spin_row = builder.get_object('default_workspace_spinrow'); - if (spin_row) { - settings.bind( - DEFAULT_WORKSPACE_KEY, - spin_row, - 'value', - Gio.SettingsBindFlags.DEFAULT - ); - } + settings.bind( + DEFAULT_WORKSPACE_KEY, + spin_row, + 'value', + Gio.SettingsBindFlags.DEFAULT + ); - let page = builder.get_object('preferences_main_page'); window.add(page); } } diff --git a/src/ui/prefs.ui b/src/ui/prefs.ui deleted file mode 100644 index f2cbcd1..0000000 --- a/src/ui/prefs.ui +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - Workspace - - - - - 1.0 - 1.0 - 1.0 - 1.0 - 37.0 - 1.0 - - - Default Workspace - - - - - -