@@ -24,7 +24,7 @@ const System = imports.system;
24
24
const Me = imports . misc . extensionUtils . getCurrentExtension ( ) ;
25
25
26
26
const { backport } = imports . ddterm ;
27
- const { translations, simpleaction } = imports . ddterm . util ;
27
+ const { translations } = imports . ddterm . util ;
28
28
const { timers } = imports . ddterm . rx ;
29
29
30
30
translations . init ( Me . dir ) ;
@@ -41,20 +41,27 @@ imports.ddterm.app.dependencies.gi_require({
41
41
42
42
const { Gdk, Gtk } = imports . gi ;
43
43
44
- const { rxjs } = imports . ddterm . thirdparty . rxjs ;
45
- const { rxutil , settings } = imports . ddterm . rx ;
44
+ const { AppWindow } = imports . ddterm . app . appwindow ;
45
+ const { PrefsDialog } = imports . ddterm . pref . dialog ;
46
46
47
47
const APP_DIR = Me . dir . get_child ( 'ddterm' ) . get_child ( 'app' ) ;
48
48
49
49
const Application = backport . GObject . registerClass (
50
50
{
51
51
Properties : {
52
- 'preferences-visible ' : GObject . ParamSpec . boolean (
53
- 'preferences-visible ' ,
52
+ 'window ' : GObject . ParamSpec . object (
53
+ 'window ' ,
54
54
'' ,
55
55
'' ,
56
- GObject . ParamFlags . READABLE | GObject . ParamFlags . EXPLICIT_NOTIFY ,
57
- false
56
+ GObject . ParamFlags . READWRITE | GObject . ParamFlags . EXPLICIT_NOTIFY ,
57
+ AppWindow
58
+ ) ,
59
+ 'prefs-dialog' : GObject . ParamSpec . object (
60
+ 'prefs-dialog' ,
61
+ '' ,
62
+ '' ,
63
+ GObject . ParamFlags . READWRITE | GObject . ParamFlags . EXPLICIT_NOTIFY ,
64
+ PrefsDialog
58
65
) ,
59
66
} ,
60
67
} ,
@@ -97,14 +104,11 @@ const Application = backport.GObject.registerClass(
97
104
null
98
105
) ;
99
106
100
- this . env_gdk_backend = null ;
101
- this . unset_gdk_backend = false ;
102
-
103
107
this . connect ( 'startup' , this . startup . bind ( this ) ) ;
104
108
this . connect ( 'handle-local-options' , this . handle_local_options . bind ( this ) ) ;
105
109
106
- this . window = null ;
107
- this . prefs_dialog = null ;
110
+ this . env_gdk_backend = null ;
111
+ this . unset_gdk_backend = false ;
108
112
}
109
113
110
114
startup ( ) {
@@ -114,41 +118,28 @@ const Application = backport.GObject.registerClass(
114
118
if ( this . env_gdk_backend !== null )
115
119
GLib . setenv ( 'GDK_BACKEND' , this . env_gdk_backend , true ) ;
116
120
117
- this . rx = rxutil . scope ( this , rxutil . signal ( this , 'shutdown' ) ) ;
118
-
119
- const actions = {
120
- 'quit' : ( ) => this . quit ( ) ,
121
- 'preferences' : ( ) => this . preferences ( ) ,
122
- 'begin-subscription-leak-check' : ( ) => rxutil . begin_subscription_leak_check ( ) ,
123
- 'end-subscription-leak-check' : ( ) => rxutil . end_subscription_leak_check ( ) ,
124
- 'gc' : ( ) => System . gc ( ) ,
125
- } ;
126
-
127
- for ( const [ name , activate ] of Object . entries ( actions ) )
128
- this . add_action ( new simpleaction . Action ( { name, activate } ) ) ;
129
-
130
- this . add_action ( new simpleaction . Action ( {
131
- name : 'dump-heap' ,
132
- activate : arg => this . dump_heap ( arg . deepUnpack ( ) ) ,
133
- parameter_type : new GLib . VariantType ( 's' ) ,
134
- } ) ) ;
121
+ this . simple_action ( 'quit' , ( ) => this . quit ( ) ) ;
122
+ this . simple_action ( 'preferences' , ( ) => this . preferences ( ) ) ;
123
+ this . simple_action ( 'gc' , ( ) => System . gc ( ) ) ;
135
124
136
- const close_preferences_action = new simpleaction . Action ( {
137
- name : 'close-preferences' ,
138
- activate : ( ) => this . close_preferences ( ) ,
139
- } ) ;
140
-
141
- this . rx . subscribe (
142
- rxutil . property ( this , 'preferences-visible' ) ,
143
- rxutil . property ( close_preferences_action , 'enabled' )
125
+ this . simple_action (
126
+ 'dump-heap' ,
127
+ ( _ , param ) => this . dump_heap ( param . deepUnpack ( ) ) ,
128
+ { parameter_type : new GLib . VariantType ( 's' ) }
144
129
) ;
145
130
146
- this . add_action ( close_preferences_action ) ;
131
+ const close_preferences_action = this . simple_action (
132
+ 'close-preferences' ,
133
+ ( ) => this . close_preferences ( ) ,
134
+ { enabled : false }
135
+ ) ;
147
136
148
- this . settings = new settings . Settings ( {
149
- gsettings : imports . ddterm . util . settings . get_settings ( ) ,
137
+ this . connect ( 'notify::prefs-dialog' , ( ) => {
138
+ close_preferences_action . enabled = this . prefs_dialog !== null ;
150
139
} ) ;
151
140
141
+ this . settings = imports . ddterm . util . settings . get_settings ( ) ;
142
+
152
143
[
153
144
'window-above' ,
154
145
'window-stick' ,
@@ -161,24 +152,11 @@ const Application = backport.GObject.registerClass(
161
152
'preserve-working-directory' ,
162
153
'transparent-background' ,
163
154
] . forEach ( key => {
164
- this . add_action ( this . settings . gsettings . create_action ( key ) ) ;
155
+ this . add_action ( this . settings . create_action ( key ) ) ;
165
156
} ) ;
166
157
167
- const gtk_settings = Gtk . Settings . get_default ( ) ;
168
-
169
- this . rx . subscribe (
170
- this . settings . resolved [ 'theme-variant' ] ,
171
- theme => {
172
- if ( theme === 'default' )
173
- gtk_settings . reset_property ( 'gtk-application-prefer-dark-theme' ) ;
174
- else if ( theme === 'dark' )
175
- gtk_settings . gtk_application_prefer_dark_theme = true ;
176
- else if ( theme === 'light' )
177
- gtk_settings . gtk_application_prefer_dark_theme = false ;
178
- else
179
- printerr ( `Unknown theme-variant: ${ theme } ` ) ;
180
- }
181
- ) ;
158
+ this . settings . connect ( 'changed::theme-variant' , this . update_theme . bind ( this ) ) ;
159
+ this . update_theme ( ) ;
182
160
183
161
const menus = Gtk . Builder . new_from_file ( APP_DIR . get_child ( 'menus.ui' ) . get_path ( ) ) ;
184
162
@@ -190,10 +168,10 @@ const Application = backport.GObject.registerClass(
190
168
Gtk . STYLE_PROVIDER_PRIORITY_APPLICATION
191
169
) ;
192
170
193
- this . window = new imports . ddterm . app . appwindow . AppWindow ( {
171
+ this . window = new AppWindow ( {
194
172
application : this ,
195
173
decorated : this . decorated ,
196
- settings : this . settings ,
174
+ gsettings : this . settings ,
197
175
menus,
198
176
} ) ;
199
177
@@ -234,26 +212,11 @@ const Application = backport.GObject.registerClass(
234
212
for ( let i = 0 ; i < 10 ; i += 1 )
235
213
shortcut_actions [ `shortcut-switch-to-tab-${ i + 1 } ` ] = `win.switch-to-tab(${ i } )` ;
236
214
237
- const shortcuts_enabled = this . settings [ 'shortcuts-enabled' ] ;
238
-
239
- const append_escape = rxjs . pipe (
240
- rxjs . combineLatestWith ( this . settings [ 'hide-window-on-esc' ] ) ,
241
- rxjs . map ( ( [ shortcuts , append ] ) => append ? shortcuts . concat ( [ 'Escape' ] ) : shortcuts )
242
- ) ;
243
-
244
- for ( const [ key , action ] of Object . entries ( shortcut_actions ) ) {
245
- this . rx . subscribe (
246
- rxutil . switch_on ( shortcuts_enabled , {
247
- true : this . settings [ key ] ,
248
- false : rxjs . of ( [ ] ) ,
249
- } ) . pipe ( action === 'win.hide' ? append_escape : rxjs . identity ) ,
250
- value => {
251
- this . set_accels_for_action ( action , value ) ;
252
- }
253
- ) ;
254
- }
215
+ Object . entries ( shortcut_actions ) . forEach ( ( [ key , action ] ) => {
216
+ this . bind_shortcut ( action , key ) ;
217
+ } ) ;
255
218
256
- this . rx . connect ( this , 'activate' , this . activate . bind ( this ) ) ;
219
+ this . connect ( 'activate' , this . activate . bind ( this ) ) ;
257
220
}
258
221
259
222
activate ( ) {
@@ -297,20 +260,14 @@ const Application = backport.GObject.registerClass(
297
260
298
261
preferences ( ) {
299
262
if ( this . prefs_dialog === null ) {
300
- this . prefs_dialog = new imports . ddterm . pref . dialog . PrefsDialog ( {
263
+ this . prefs_dialog = new PrefsDialog ( {
301
264
transient_for : this . window ,
302
- settings : this . settings . gsettings ,
265
+ settings : this . settings ,
303
266
} ) ;
304
267
305
- this . rx . subscribe (
306
- rxutil . signal ( this . prefs_dialog , 'delete-event' ) . pipe ( rxjs . take ( 1 ) ) ,
307
- ( ) => {
308
- this . prefs_dialog = null ;
309
- this . notify ( 'preferences-visible' ) ;
310
- }
311
- ) ;
312
-
313
- this . notify ( 'preferences-visible' ) ;
268
+ this . prefs_dialog . connect ( 'destroy' , ( ) => {
269
+ this . prefs_dialog = null ;
270
+ } ) ;
314
271
}
315
272
316
273
this . prefs_dialog . show ( ) ;
@@ -321,10 +278,6 @@ const Application = backport.GObject.registerClass(
321
278
this . prefs_dialog . close ( ) ;
322
279
}
323
280
324
- get preferences_visible ( ) {
325
- return this . prefs_dialog !== null ;
326
- }
327
-
328
281
dump_heap ( path = null ) {
329
282
if ( ! path ) {
330
283
path = GLib . build_filenamev ( [
@@ -345,6 +298,60 @@ const Application = backport.GObject.registerClass(
345
298
System . dumpHeap ( path ) ;
346
299
printerr ( `Dumped heap to ${ path } ` ) ;
347
300
}
301
+
302
+ simple_action ( name , activate , params = { } ) {
303
+ const action = new Gio . SimpleAction ( {
304
+ name,
305
+ ...params ,
306
+ } ) ;
307
+ action . connect ( 'activate' , activate ) ;
308
+ this . add_action ( action ) ;
309
+ return action ;
310
+ }
311
+
312
+ update_theme ( ) {
313
+ const gtk_settings = Gtk . Settings . get_default ( ) ;
314
+ const theme = this . settings . get_string ( 'theme-variant' ) ;
315
+
316
+ switch ( theme ) {
317
+ case 'system' :
318
+ gtk_settings . reset_property ( 'gtk-application-prefer-dark-theme' ) ;
319
+ break ;
320
+
321
+ case 'dark' :
322
+ gtk_settings . gtk_application_prefer_dark_theme = true ;
323
+ break ;
324
+
325
+ case 'light' :
326
+ gtk_settings . gtk_application_prefer_dark_theme = false ;
327
+ break ;
328
+
329
+ default :
330
+ printerr ( `Unknown theme-variant: ${ theme } ` ) ;
331
+ }
332
+ }
333
+
334
+ bind_shortcut ( action , settings_key ) {
335
+ const handler = this . update_shortcut . bind ( this , action , settings_key ) ;
336
+
337
+ this . settings . connect ( `changed::${ settings_key } ` , handler ) ;
338
+ this . settings . connect ( 'changed::shortcuts-enabled' , handler ) ;
339
+
340
+ if ( action === 'win.hide' )
341
+ this . settings . connect ( 'changed::hide-window-on-esc' , handler ) ;
342
+
343
+ handler ( ) ;
344
+ }
345
+
346
+ update_shortcut ( action , settings_key ) {
347
+ const enable = this . settings . get_boolean ( 'shortcuts-enabled' ) ;
348
+ const keys = enable ? this . settings . get_strv ( settings_key ) : [ ] ;
349
+
350
+ if ( action === 'win.hide' && this . settings . get_boolean ( 'hide-window-on-esc' ) )
351
+ keys . push ( 'Escape' ) ;
352
+
353
+ this . set_accels_for_action ( action , keys ) ;
354
+ }
348
355
}
349
356
) ;
350
357
0 commit comments