@@ -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
- } ) ) ;
135
-
136
- const close_preferences_action = new simpleaction . Action ( {
137
- name : 'close-preferences' ,
138
- activate : ( ) => this . close_preferences ( ) ,
139
- } ) ;
121
+ this . simple_action ( 'quit' , ( ) => this . quit ( ) ) ;
122
+ this . simple_action ( 'preferences' , ( ) => this . preferences ( ) ) ;
123
+ this . simple_action ( 'gc' , ( ) => System . gc ( ) ) ;
140
124
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,70 +168,51 @@ 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
200
178
this . add_action ( this . window . lookup_action ( 'toggle' ) ) ;
201
179
this . add_action ( this . window . lookup_action ( 'show' ) ) ;
202
180
this . add_action ( this . window . lookup_action ( 'hide' ) ) ;
203
181
204
- const shortcut_actions = {
205
- 'shortcut-window- hide' : 'win. hide' ,
206
- 'shortcut- window-size-inc' : 'win. window-size-inc' ,
207
- 'shortcut- window-size-dec' : 'win. window-size-dec' ,
208
- 'shortcut- background-opacity-inc' : 'win. background-opacity-inc' ,
209
- 'shortcut- background-opacity-dec' : 'win. background-opacity-dec' ,
210
- 'shortcut-toggle- maximize' : 'app.window -maximize' ,
211
- 'shortcut-toggle- transparent-background' : 'app. transparent-background' ,
212
- 'shortcut- terminal- copy' : 'terminal. copy' ,
213
- 'shortcut- terminal- copy-html' : 'terminal. copy-html' ,
214
- 'shortcut- terminal- paste' : 'terminal. paste' ,
215
- 'shortcut- terminal- select-all' : 'terminal. select-all' ,
216
- 'shortcut- terminal- reset' : 'terminal. reset' ,
217
- 'shortcut- terminal- reset-and-clear' : 'terminal. reset-and-clear' ,
218
- 'shortcut- win- new-tab' : 'win. new-tab' ,
219
- 'shortcut- win- new-tab-front' : 'win. new-tab-front' ,
220
- 'shortcut- win- new-tab-before-current' : 'win. new-tab-before-current' ,
221
- 'shortcut- win- new-tab-after-current' : 'win. new-tab-after-current' ,
222
- 'shortcut- page- close' : 'page. close' ,
223
- 'shortcut- prev-tab' : 'win. prev-tab' ,
224
- 'shortcut- next-tab' : 'win. next-tab' ,
225
- 'shortcut- move-tab-prev' : 'win. move-tab-prev' ,
226
- 'shortcut- move-tab-next' : 'win. move-tab-next' ,
227
- 'shortcut-set- custom-tab- title' : 'page.use- custom-title(true) ' ,
228
- 'shortcut-reset-tab-title' : ' page.use-custom-title(false)',
229
- 'shortcut- find' : 'terminal. find' ,
230
- 'shortcut- find-next' : 'terminal. find-next' ,
231
- 'shortcut- find-prev' : 'terminal. find-prev' ,
232
- } ;
182
+ this . bind_shortcuts ( {
183
+ 'win. hide' : 'shortcut-window- hide' ,
184
+ 'win. window-size-inc' : 'shortcut- window-size-inc' ,
185
+ 'win. window-size-dec' : 'shortcut- window-size-dec' ,
186
+ 'win. background-opacity-inc' : 'shortcut- background-opacity-inc' ,
187
+ 'win. background-opacity-dec' : 'shortcut- background-opacity-dec' ,
188
+ 'app.window- maximize' : 'shortcut-toggle -maximize' ,
189
+ 'app. transparent-background' : 'shortcut-toggle- transparent-background' ,
190
+ 'terminal. copy' : 'shortcut- terminal- copy' ,
191
+ 'terminal. copy-html' : 'shortcut- terminal- copy-html' ,
192
+ 'terminal. paste' : 'shortcut- terminal- paste' ,
193
+ 'terminal. select-all' : 'shortcut- terminal- select-all' ,
194
+ 'terminal. reset' : 'shortcut- terminal- reset' ,
195
+ 'terminal. reset-and-clear' : 'shortcut- terminal- reset-and-clear' ,
196
+ 'win. new-tab' : 'shortcut- win- new-tab' ,
197
+ 'win. new-tab-front' : 'shortcut- win- new-tab-front' ,
198
+ 'win. new-tab-before-current' : 'shortcut- win- new-tab-before-current' ,
199
+ 'win. new-tab-after-current' : 'shortcut- win- new-tab-after-current' ,
200
+ 'page. close' : 'shortcut- page- close' ,
201
+ 'win. prev-tab' : 'shortcut- prev-tab' ,
202
+ 'win. next-tab' : 'shortcut- next-tab' ,
203
+ 'win. move-tab-prev' : 'shortcut- move-tab-prev' ,
204
+ 'win. move-tab-next' : 'shortcut- move-tab-next' ,
205
+ 'page.use- custom-title(true) ' : 'shortcut-set- custom-tab- title' ,
206
+ 'page.use-custom-title(false)' : 'shortcut-reset-tab-title ',
207
+ 'terminal. find' : 'shortcut- find' ,
208
+ 'terminal. find-next' : 'shortcut- find-next' ,
209
+ 'terminal. find-prev' : 'shortcut- find-prev' ,
210
+ } ) ;
233
211
234
212
for ( let i = 0 ; i < 10 ; i += 1 )
235
- shortcut_actions [ `shortcut- switch-to-tab- ${ i + 1 } ` ] = `win. switch-to-tab( ${ i } )` ;
213
+ this . bind_shortcut ( `win. switch-to-tab( ${ i } )` , `shortcut- switch-to-tab- ${ i + 1 } ` ) ;
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
- }
255
-
256
- this . rx . connect ( this , 'activate' , this . activate . bind ( this ) ) ;
215
+ this . connect ( 'activate' , this . activate . bind ( this ) ) ;
257
216
}
258
217
259
218
activate ( ) {
@@ -297,20 +256,14 @@ const Application = backport.GObject.registerClass(
297
256
298
257
preferences ( ) {
299
258
if ( this . prefs_dialog === null ) {
300
- this . prefs_dialog = new imports . ddterm . pref . dialog . PrefsDialog ( {
259
+ this . prefs_dialog = new PrefsDialog ( {
301
260
transient_for : this . window ,
302
- settings : this . settings . gsettings ,
261
+ settings : this . settings ,
303
262
} ) ;
304
263
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' ) ;
264
+ this . prefs_dialog . connect ( 'destroy' , ( ) => {
265
+ this . prefs_dialog = null ;
266
+ } ) ;
314
267
}
315
268
316
269
this . prefs_dialog . show ( ) ;
@@ -321,10 +274,6 @@ const Application = backport.GObject.registerClass(
321
274
this . prefs_dialog . close ( ) ;
322
275
}
323
276
324
- get preferences_visible ( ) {
325
- return this . prefs_dialog !== null ;
326
- }
327
-
328
277
dump_heap ( path = null ) {
329
278
if ( ! path ) {
330
279
path = GLib . build_filenamev ( [
@@ -345,6 +294,65 @@ const Application = backport.GObject.registerClass(
345
294
System . dumpHeap ( path ) ;
346
295
printerr ( `Dumped heap to ${ path } ` ) ;
347
296
}
297
+
298
+ simple_action ( name , activate , params = { } ) {
299
+ const action = new Gio . SimpleAction ( {
300
+ name,
301
+ ...params ,
302
+ } ) ;
303
+ action . connect ( 'activate' , activate ) ;
304
+ this . add_action ( action ) ;
305
+ return action ;
306
+ }
307
+
308
+ update_theme ( ) {
309
+ const gtk_settings = Gtk . Settings . get_default ( ) ;
310
+ const theme = this . settings . get_string ( 'theme-variant' ) ;
311
+
312
+ switch ( theme ) {
313
+ case 'system' :
314
+ gtk_settings . reset_property ( 'gtk-application-prefer-dark-theme' ) ;
315
+ break ;
316
+
317
+ case 'dark' :
318
+ gtk_settings . gtk_application_prefer_dark_theme = true ;
319
+ break ;
320
+
321
+ case 'light' :
322
+ gtk_settings . gtk_application_prefer_dark_theme = false ;
323
+ break ;
324
+
325
+ default :
326
+ printerr ( `Unknown theme-variant: ${ theme } ` ) ;
327
+ }
328
+ }
329
+
330
+ bind_shortcut ( action , settings_key ) {
331
+ const handler = this . update_shortcut . bind ( this , action , settings_key ) ;
332
+
333
+ this . settings . connect ( `changed::${ settings_key } ` , handler ) ;
334
+ this . settings . connect ( 'changed::shortcuts-enabled' , handler ) ;
335
+
336
+ if ( action === 'win.hide' )
337
+ this . settings . connect ( 'changed::hide-window-on-esc' , handler ) ;
338
+
339
+ handler ( ) ;
340
+ }
341
+
342
+ update_shortcut ( action , settings_key ) {
343
+ const enable = this . settings . get_boolean ( 'shortcuts-enabled' ) ;
344
+ const keys = enable ? this . settings . get_strv ( settings_key ) : [ ] ;
345
+
346
+ if ( action === 'win.hide' && this . settings . get_boolean ( 'hide-window-on-esc' ) )
347
+ keys . push ( 'Escape' ) ;
348
+
349
+ this . set_accels_for_action ( action , keys ) ;
350
+ }
351
+
352
+ bind_shortcuts ( action_to_settings_key ) {
353
+ for ( const [ action , settings_key ] of Object . entries ( action_to_settings_key ) )
354
+ this . bind_shortcut ( action , settings_key ) ;
355
+ }
348
356
}
349
357
) ;
350
358
0 commit comments