@@ -6,23 +6,9 @@ import GObject from "gi://GObject";
66import { gettext as _ } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js" ;
77
88// Extension imports
9- import { PreferencesPage , RemoveItemRow } from "./widgets.js" ;
9+ import { PreferencesPage , RemoveItemRow , ResetButton } from "./widgets.js" ;
1010import { ConfigManager } from "../shared/settings.js" ;
1111
12- function showAddWindow ( ) {
13- console . log ( "Add window functionality not implemented yet" ) ;
14- }
15-
16- function makeAddButton ( ) {
17- const button = new Gtk . Button ( {
18- icon_name : "tab-new-symbolic" ,
19- tooltip_text : _ ( "Add Window" ) ,
20- valign : Gtk . Align . CENTER ,
21- } ) ;
22- button . connect ( "clicked" , ( ) => showAddWindow ( ) ) ;
23- return button ;
24- }
25-
2612export class FloatingPage extends PreferencesPage {
2713 static {
2814 GObject . registerClass ( this ) ;
@@ -33,30 +19,36 @@ export class FloatingPage extends PreferencesPage {
3319
3420 this . settings = settings ;
3521 this . configMgr = new ConfigManager ( { dir } ) ;
22+
3623 let overrides = this . configMgr . windowProps . overrides ;
24+ this . rows = this . loadItemsFromConfig ( overrides ) ;
25+
26+ this . floatingWindowGroup = this . add_group ( {
27+ title : _ ( "Floating Windows" ) ,
28+ description : _ ( "Windows that will not be tiled" ) ,
29+ header_suffix : new ResetButton ( { onReset : ( ) => this . onResetHandler ( ) } ) ,
30+ children : this . rows ,
31+ } ) ;
32+ }
33+
34+ loadItemsFromConfig ( overrides ) {
3735 let children = [ ] ;
38- for ( let index in overrides ) {
39- let override = overrides [ index ] ;
36+ for ( let override of overrides ) {
4037 if ( override . mode === "float" ) {
4138 let itemrow = new RemoveItemRow ( {
4239 title : override . wmTitle ?? override . wmClass ,
4340 subtitle : override . wmClass ,
44- onRemove : this . onRemoveHandler ,
41+ onRemove : ( item , parent ) => this . onRemoveHandler ( item , parent ) ,
4542 } ) ;
4643 children . push ( itemrow ) ;
4744 }
4845 }
49-
50- this . add_group ( {
51- title : _ ( "Floating Windows" ) ,
52- description : _ ( "Windows that will not be tiled" ) ,
53- header_suffix : makeAddButton ( ) ,
54- children : children ,
55- } ) ;
46+ return children ;
5647 }
5748
5849 onRemoveHandler ( item , parent ) {
59- parent . hide ( ) ;
50+ this . floatingWindowGroup . remove ( parent ) ;
51+ this . rows = this . rows . filter ( ( row ) => row != parent ) ;
6052 const existing = this . configMgr . windowProps . overrides ;
6153 const modified = existing . filter ( ( row ) => item != row . wmClass ) ;
6254 this . saveOverrides ( modified ) ;
@@ -72,4 +64,19 @@ export class FloatingPage extends PreferencesPage {
7264 this . settings . set_uint ( "window-overrides-reload-trigger" , changed ) ;
7365 }
7466 }
67+
68+ onResetHandler ( ) {
69+ const defaultWindowProps = this . configMgr . loadDefaultWindowConfigContents ( ) ;
70+ const original = defaultWindowProps . overrides ;
71+ this . saveOverrides ( original ) ;
72+
73+ for ( const child of this . rows ) {
74+ this . floatingWindowGroup . remove ( child ) ;
75+ }
76+
77+ this . rows = this . loadItemsFromConfig ( original ) ;
78+ for ( const item of this . rows ) {
79+ this . floatingWindowGroup . add ( item ) ;
80+ }
81+ }
7582}
0 commit comments