11'use strict' ;
22
3- const { Adw , Gio, Gtk, Gdk, GLib } = imports . gi ;
3+ const { Gio, Gtk, Gdk, GLib, GObject } = imports . gi ;
44const Params = imports . misc . params ;
55const ExtensionUtils = imports . misc . extensionUtils ;
66const Me = ExtensionUtils . getCurrentExtension ( ) ;
7+ const Config = imports . misc . config ;
8+ const [ major , minor ] = Config . PACKAGE_VERSION . split ( '.' ) . map ( s => Number ( s ) ) ;
9+ let Adw ;
710
8- function init ( ) { }
11+ function init ( ) {
12+ }
913
1014function fillPreferencesWindow ( window ) {
15+ Adw = imports . gi . Adw ;
1116 let prefs = new PrefsWindow ( window ) ;
1217 prefs . fillPrefsWindow ( ) ;
1318}
1419
20+ function buildPrefsWidget ( ) {
21+ let widget = new prefsWidget ( ) ;
22+ ( major < 40 ) ? widget . show_all ( ) : widget . show ( ) ;
23+ return widget ;
24+ }
25+
26+ const prefsWidget = GObject . registerClass (
27+ class prefsWidget extends Gtk . Notebook {
28+
29+ _init ( params ) {
30+ super . _init ( params ) ;
31+ this . _settings = ExtensionUtils . getSettings ( 'org.gnome.shell.extensions.visualizer' ) ;
32+ this . margin = 20 ;
33+
34+ let grid = new Gtk . Grid ( ) ;
35+ attachItems ( grid , new Gtk . Label ( { label : 'Flip the Visualizer' } ) , getSwitch ( 'flip-visualizer' , this . _settings ) , 0 ) ;
36+ attachItems ( grid , new Gtk . Label ( { label : 'Visualizer Height' } ) , getSpinButton ( false , 'visualizer-height' , 1 , 200 , 1 , this . _settings ) , 1 ) ;
37+ attachItems ( grid , new Gtk . Label ( { label : 'Visualizer Width' } ) , getSpinButton ( false , 'visualizer-width' , 1 , 1920 , 1 , this . _settings ) , 2 ) ;
38+ attachItems ( grid , new Gtk . Label ( { label : 'Spects Line Width' } ) , getSpinButton ( false , 'spects-line-width' , 1 , 20 , 1 , this . _settings ) , 3 ) ;
39+ attachItems ( grid , new Gtk . Label ( { label : 'Change Spects Band to Get' } ) , getSpinButton ( false , 'total-spects-band' , 1 , 256 , 1 , this . _settings ) , 4 ) ;
40+ this . attachHybridRow ( grid , new Gtk . Label ( { label : 'Override Spect Value' } ) , new Gtk . Label ( { label : 'Set Spects Value' } ) , getSwitch ( 'spect-over-ride-bool' , this . _settings ) , getSpinButton ( false , 'spect-over-ride' , 1 , 256 , 1 , this . _settings ) , 5 ) ;
41+ this . append_page ( grid , new Gtk . Label ( { label : 'Visualizer' } ) ) ;
42+ let aboutBox = new Gtk . Box ( { orientation : Gtk . Orientation . VERTICAL } ) ;
43+ if ( major < 40 ) {
44+ aboutBox . add ( new Gtk . Label ( { label : Me . metadata . name } ) ) ;
45+ aboutBox . add ( new Gtk . Label ( { label : 'Version: ' + Me . metadata . version . toString ( ) } ) ) ;
46+ } else {
47+ aboutBox . append ( new Gtk . Label ( { label : Me . metadata . name } ) ) ;
48+ aboutBox . append ( new Gtk . Label ( { label : 'Version: ' + Me . metadata . version . toString ( ) } ) ) ;
49+ }
50+ this . append_page ( aboutBox , new Gtk . Label ( { label : 'About' } ) ) ;
51+ }
52+
53+ attachHybridRow ( grid , label , label1 , button , button1 , row ) {
54+ grid . attach ( label , 0 , row , 1 , 1 ) ;
55+ grid . attach ( button , 1 , row , 1 , 1 ) ;
56+ grid . attach ( label1 , 0 , row + 1 , 1 , 1 ) ;
57+ grid . attach ( button1 , 1 , row + 1 , 1 , 1 ) ;
58+ }
59+ } ) ;
60+
1561class PrefsWindow {
1662 constructor ( window ) {
1763 this . _window = window ;
@@ -42,11 +88,10 @@ class PrefsWindow {
4288 if ( title !== undefined ) {
4389 group = new Adw . PreferencesGroup ( {
4490 title : title ,
45- /* margin_top: 5,
46- margin_bottom: 5,*/
91+ // margin_top: 5,
92+ // margin_bottom: 5,
4793 } ) ;
48- }
49- else {
94+ } else {
5095 group = new Adw . PreferencesGroup ( ) ;
5196 }
5297 page . add ( group ) ;
@@ -62,35 +107,25 @@ class PrefsWindow {
62107 row . activatable_widget = widget ;
63108 }
64109
65- // create a new Adw.ActionRow to insert an option into a prefsGroup
66- append_switch ( group , title , key ) {
67- let button = new Gtk . Switch ( {
68- active : key ,
69- valign : Gtk . Align . CENTER ,
110+ append_expander_row ( group , titleEx , title , key , key1 ) {
111+ let expand_row = new Adw . ExpanderRow ( {
112+ title : titleEx ,
113+ show_enable_switch : true ,
114+ expanded : this . _settings . get_boolean ( key ) ,
115+ enable_expansion : this . _settings . get_boolean ( key )
70116 } ) ;
71-
72- this . _settings . bind (
73- key ,
74- button ,
75- 'active' ,
76- Gio . SettingsBindFlags . DEFAULT
77- ) ;
78- this . append_row ( group , title , button ) ;
79- }
80-
81- append_spin_button ( group , title , is_double , key , min , max , step ) {
82- let v = 0 ;
83- if ( is_double ) {
84- v = this . _settings . get_double ( key ) ;
85- }
86- else {
87- v = this . _settings . get_int ( key ) ;
88- }
89- let spin = Gtk . SpinButton . new_with_range ( min , max , step ) ;
90- spin . set_value ( v ) ;
91- this . _settings . bind ( key , spin , 'value' , Gio . SettingsBindFlags . DEFAULT ) ;
92- this . append_row ( group , title , spin ) ;
93- }
117+ let row = new Adw . ActionRow ( {
118+ title : title ,
119+ } ) ;
120+ expand_row . connect ( "notify::enable-expansion" , ( widget ) => {
121+ let settingArray = this . _settings . get_boolean ( key ) ;
122+ settingArray = widget . enable_expansion ;
123+ this . _settings . set_value ( key , new GLib . Variant ( 'b' , settingArray ) ) ;
124+ } ) ;
125+ row . add_suffix ( key1 ) ;
126+ expand_row . add_row ( row ) ;
127+ group . add ( expand_row ) ;
128+ } ;
94129
95130 append_info_group ( group , name , title ) {
96131 let adw_group = new Adw . PreferencesGroup ( ) ;
@@ -117,16 +152,39 @@ class PrefsWindow {
117152 fillPrefsWindow ( ) {
118153 let visualWidget = this . create_page ( 'Visualizer' ) ; {
119154 let groupVisual = this . create_group ( visualWidget ) ;
120- this . append_spin_button ( groupVisual , 'Visualizer Height' , false , 'visualizer-height' , 1 , 200 , 1 ) ;
121- this . append_spin_button ( groupVisual , 'Visualizer Width' , false , 'visualizer-width' , 1 , 1920 , 1 ) ;
122- this . append_spin_button ( groupVisual , 'Spects Line Width' , false , 'spects-line-width' , 1 , 20 , 1 ) ;
123- this . append_spin_button ( groupVisual , 'Change Spects Value' , false , 'total-spects-band' , 1 , 256 , 1 ) ;
155+ this . append_row ( groupVisual , 'Flip the Visualizer' , getSwitch ( 'flip-visualizer' , this . _settings ) ) ;
156+ this . append_row ( groupVisual , 'Visualizer Height' , getSpinButton ( false , 'visualizer-height' , 1 , 200 , 1 , this . _settings ) ) ;
157+ this . append_row ( groupVisual , 'Visualizer Width' , getSpinButton ( false , 'visualizer-width' , 1 , 1920 , 1 , this . _settings ) ) ;
158+ this . append_row ( groupVisual , 'Spects Line Width' , getSpinButton ( false , 'spects-line-width' , 1 , 20 , 1 , this . _settings ) ) ;
159+ this . append_row ( groupVisual , 'Change Spects Band to Get' , getSpinButton ( false , 'total-spects-band' , 1 , 256 , 1 , this . _settings ) ) ;
160+ this . append_expander_row ( groupVisual , 'Override Spect Value' , 'Set Spects Value' , 'spect-over-ride-bool' , getSpinButton ( false , 'spect-over-ride' , 1 , 256 , 1 , this . _settings ) ) ;
124161 }
125162
126163 let aboutPage = this . create_page ( 'About' ) ; {
127164 let groupAbout = this . create_group ( aboutPage ) ;
128- this . append_info_group ( groupAbout , Me . metadata . name ,
129- Me . metadata . version . toString ( ) ) ;
165+ this . append_info_group ( groupAbout , Me . metadata . name , Me . metadata . version . toString ( ) ) ;
130166 }
131167 }
132168}
169+
170+ function attachItems ( grid , label , widget , row ) {
171+ grid . set_column_spacing ( 200 ) ;
172+ grid . set_row_spacing ( 25 ) ;
173+ grid . attach ( label , 0 , row , 1 , 1 ) ;
174+ grid . attach ( widget , 1 , row , 1 , 1 ) ;
175+ }
176+
177+ function getSwitch ( key , settings ) {
178+ let button = new Gtk . Switch ( { active : key , valign : Gtk . Align . CENTER } ) ;
179+ settings . bind ( key , button , 'active' , Gio . SettingsBindFlags . DEFAULT ) ;
180+ return button
181+ }
182+
183+ function getSpinButton ( is_double , key , min , max , step , settings ) {
184+ let v = 0 ;
185+ ( is_double ) ? v = settings . get_double ( key ) : v = settings . get_int ( key ) ;
186+ let spin = Gtk . SpinButton . new_with_range ( min , max , step ) ;
187+ spin . set_value ( v ) ;
188+ settings . bind ( key , spin , 'value' , Gio . SettingsBindFlags . DEFAULT ) ;
189+ return spin ;
190+ }
0 commit comments