glimmer-cs-gladiator 0.5.2 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@ module Glimmer
22
22
  class << self
23
23
  attr_accessor :drag_and_drop
24
24
  attr_accessor :drag
25
+ attr_accessor :startup
25
26
  end
26
27
 
27
28
  ## Add options like the following to configure CustomShell by outside consumers
@@ -35,8 +36,26 @@ module Glimmer
35
36
  @project_dir ||= Dir.new(project_dir_path)
36
37
  end
37
38
 
38
- attr_reader :find_text, :tab_folder1, :tab_folder2, :filter_text, :rename_in_progress, :line_number_text, :file_tree
39
- attr_accessor :split_orientation, :current_tab_item, :current_tab_folder, :current_text_editor
39
+ def split_orientation=(value)
40
+ @split_orientation = value
41
+ save_config
42
+ if @loaded_config && !split_pane?
43
+ Gladiator.drag = true
44
+ child_path = project_dir.selected_child_path
45
+ project_dir.selected_child = nil
46
+ project_dir.selected_child_path = child_path
47
+ Gladiator.drag = false
48
+ end
49
+ @split_orientation
50
+ end
51
+
52
+ def split_pane?
53
+ pane_count = @tab_folder_sash_form&.children&.size
54
+ pane_count && pane_count > 1
55
+ end
56
+
57
+ attr_reader :find_text, :tab_folder1, :tab_folder2, :filter_text, :rename_in_progress, :line_number_text, :file_tree, :split_orientation
58
+ attr_accessor :current_tab_item, :current_tab_folder, :current_text_editor
40
59
 
41
60
  ## Uncomment before_body block to pre-initialize variables to use in body
42
61
  #
@@ -58,6 +77,7 @@ module Glimmer
58
77
  }
59
78
  end
60
79
 
80
+ @default_foreground = :dark_blue
61
81
  @split_orientation = swt(:horizontal)
62
82
  @config_file_path = ::File.join(project_dir.path, '.gladiator')
63
83
  @config = {}
@@ -69,7 +89,7 @@ module Glimmer
69
89
  #
70
90
  after_body {
71
91
  observe(project_dir, 'children') do
72
- select_tree_item unless @rename_in_progress
92
+ select_tree_item unless @rename_in_progress || Gladiator.startup
73
93
  end
74
94
  observe(project_dir, 'selected_child') do |selected_file|
75
95
  if selected_file
@@ -80,31 +100,40 @@ module Glimmer
80
100
  @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
81
101
  }
82
102
  end
83
- select_tree_item unless @rename_in_progress
103
+ select_tree_item unless @rename_in_progress || Gladiator.startup
84
104
  found_tab_item = selected_tab_item
85
105
  if found_tab_item
86
106
  @current_tab_folder.swt_widget.setSelection(found_tab_item)
87
107
  @current_tab_item = found_tab_item.getData('proxy')
88
- @current_text_editor = found_tab_item.getData('text_editor')
108
+ @current_text_editor = found_tab_item.getData('text_editor') unless found_tab_item.getData('text_editor').nil?
89
109
  @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
90
110
  elsif selected_file
91
111
  @current_tab_folder.content {
92
112
  @current_tab_item = tab_item { |the_tab_item|
93
113
  text selected_file.name
94
- fill_layout :horizontal
95
- @current_text_editor = the_text_editor = text_editor(project_dir: project_dir, file: selected_file)
96
- @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
97
- @current_text_editor.text_proxy.content {
98
- on_focus_gained {
99
- tab_folder = the_text_editor.swt_widget.getParent.getParent
100
- @current_tab_folder = tab_folder.getData('proxy')
101
- @current_tab_item = the_tab_item
102
- @current_text_editor = the_text_editor
103
- @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
104
- @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
105
- project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
114
+ fill_layout(:horizontal) {
115
+ margin_width 0
116
+ margin_height 0
117
+ }
118
+ tab_folder = nil
119
+ the_text_editor = nil
120
+ the_tab_item.content {
121
+ @current_text_editor = the_text_editor = text_editor(project_dir: project_dir, file: selected_file)
122
+ @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
123
+ the_tab_item.swt_tab_item.setData('text_editor', @current_text_editor)
124
+ @current_text_editor.text_proxy.content {
125
+ on_focus_gained {
126
+ tab_folder = the_text_editor.swt_widget.getParent.getParent
127
+ @current_tab_folder = tab_folder.getData('proxy')
128
+ @current_tab_item = the_tab_item
129
+ @current_text_editor = the_text_editor
130
+ @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
131
+ @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
132
+ project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
133
+ }
106
134
  }
107
135
  }
136
+
108
137
  on_swt_show {
109
138
  @current_tab_item = the_tab_item
110
139
  @current_text_editor = the_text_editor
@@ -116,10 +145,12 @@ module Glimmer
116
145
  @current_text_editor&.text_widget&.setFocus
117
146
  }
118
147
  }
148
+ on_widget_disposed {
149
+ the_tab_item.swt_tab_item.get_data('file').close
150
+ }
119
151
  }
120
152
  @current_tab_item.swt_tab_item.setData('file_path', selected_file.path)
121
153
  @current_tab_item.swt_tab_item.setData('file', selected_file)
122
- @current_tab_item.swt_tab_item.setData('text_editor', @current_text_editor)
123
154
  @current_tab_item.swt_tab_item.setData('proxy', @current_tab_item)
124
155
  }
125
156
  @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
@@ -145,17 +176,30 @@ module Glimmer
145
176
  #
146
177
  body {
147
178
  shell {
179
+ grid_layout(2, false)
180
+
148
181
  text "Gladiator - #{::File.expand_path(project_dir.path)}"
149
182
  minimum_size 520, 250
150
183
  size 1440, 900
151
- grid_layout(2, false)
184
+
152
185
  on_swt_show {
153
186
  swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
154
187
  swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
155
188
  @loaded_config = true
156
189
  }
157
- on_swt_close {
190
+ on_shell_closed {
191
+ save_config
158
192
  project_dir.selected_child&.write_dirty_content
193
+ if @tab_folder2
194
+ current_tab_folder.swt_widget.getItems.each do |tab_item|
195
+ tab_item.getData('proxy')&.dispose
196
+ end
197
+ close_tab_folder
198
+ end
199
+ current_tab_folder.swt_widget.getItems.each do |tab_item|
200
+ tab_item.getData('proxy')&.dispose
201
+ end
202
+ body_root.close unless current_tab_folder.swt_widget.getItems.empty?
159
203
  }
160
204
  on_widget_disposed {
161
205
  project_dir.selected_child&.write_dirty_content
@@ -180,7 +224,7 @@ module Glimmer
180
224
  begin
181
225
  project_dir.selected_child_path = ''
182
226
  rescue => e
183
- pd e
227
+ puts e.full_message
184
228
  end
185
229
  }
186
230
  }
@@ -198,11 +242,15 @@ module Glimmer
198
242
  text '&Split'
199
243
  menu_item(:radio) {
200
244
  text '&Horizontal'
201
- selection bind(self, :split_orientation, on_read: ->(o) { o == swt(:horizontal)}, on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical)})
245
+ selection bind(self, :split_orientation,
246
+ on_read: ->(o) { split_pane? && o == swt(:horizontal)},
247
+ on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical) })
202
248
  }
203
249
  menu_item(:radio) {
204
250
  text '&Vertical'
205
- selection bind(self, :split_orientation, on_read: ->(o) { o == swt(:vertical)}, on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal)})
251
+ selection bind(self, :split_orientation,
252
+ on_read: ->(o) { split_pane? && o == swt(:vertical)},
253
+ on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal) })
206
254
  }
207
255
  }
208
256
  }
@@ -231,126 +279,215 @@ module Glimmer
231
279
  }
232
280
 
233
281
  composite {
234
- grid_layout 1, false
282
+ grid_layout(1, false) {
283
+ margin_width 0
284
+ margin_height 0
285
+ }
286
+
235
287
  layout_data(:fill, :fill, false, true) {
236
288
  width_hint 300
237
289
  }
238
- @filter_text = text {
239
- layout_data :fill, :center, true, false
240
- text bind(project_dir, 'filter')
241
- on_key_pressed { |key_event|
242
- if key_event.keyCode == swt(:tab) ||
243
- key_event.keyCode == swt(:cr) ||
244
- key_event.keyCode == swt(:arrow_up) ||
245
- key_event.keyCode == swt(:arrow_down)
246
- @list.swt_widget.select(0) if @list.swt_widget.getSelectionIndex() == -1
247
- @list.swt_widget.setFocus
248
- end
249
- }
250
- }
251
- composite {
252
- fill_layout(:vertical) {
253
- spacing 5
254
- }
290
+ @side_bar_sash_form = sash_form(:vertical) {
255
291
  layout_data(:fill, :fill, true, true)
256
- @list = list(:border, :h_scroll, :v_scroll) {
257
- #visible bind(self, 'project_dir.filter') {|f| !!f}
258
- selection bind(project_dir, :filtered_path)
259
- on_mouse_up {
260
- project_dir.selected_child_path = @list.swt_widget.getSelection.first
261
- }
262
- on_key_pressed { |key_event|
263
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
264
- project_dir.selected_child_path = @list.swt_widget.getSelection.first
265
- @current_text_editor&.text_widget&.setFocus
266
- end
292
+ sash_width 4
293
+
294
+ resize_expand_items = lambda { |event=nil|
295
+ @file_lookup_expand_item&.swt_expand_item&.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
296
+ @file_explorer_expand_item&.swt_expand_item&.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
297
+ }
298
+
299
+ @file_lookup_expand_bar = expand_bar {
300
+ layout_data :fill, :fill, true, true
301
+ font height: 17, style: :bold
302
+ foreground @default_foreground
303
+
304
+ on_swt_show {
305
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
267
306
  }
268
- drag_source(DND::DROP_COPY) {
269
- transfer [TextTransfer.getInstance].to_java(Transfer)
270
- on_drag_set_data { |event|
271
- Gladiator.drag = true
272
- list = event.widget.getControl
273
- event.data = list.getSelection.first
307
+
308
+ on_swt_Resize(&resize_expand_items)
309
+
310
+ @file_lookup_expand_item = expand_item {
311
+ grid_layout {
312
+ margin_width 0
313
+ margin_height 0
314
+ }
315
+ text 'File Lookup'
316
+ height display.bounds.height
317
+
318
+ @filter_text = text {
319
+ layout_data :fill, :center, true, false
320
+ text bind(project_dir, 'filter')
321
+ on_key_pressed { |key_event|
322
+ if key_event.keyCode == swt(:tab) ||
323
+ key_event.keyCode == swt(:cr) ||
324
+ key_event.keyCode == swt(:arrow_up) ||
325
+ key_event.keyCode == swt(:arrow_down)
326
+ @file_lookup_list.swt_widget.select(0) if @file_lookup_list.swt_widget.getSelectionIndex() == -1
327
+ @file_lookup_list.swt_widget.setFocus
328
+ end
329
+ }
274
330
  }
331
+
332
+ @file_lookup_list = list(:border, :h_scroll, :v_scroll) {
333
+ layout_data :fill, :fill, true, true
334
+ #visible bind(self, 'project_dir.filter') {|f| !!f}
335
+ selection bind(project_dir, :filtered_path)
336
+ foreground @default_foreground
337
+ on_mouse_up {
338
+ project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
339
+ }
340
+ on_key_pressed { |key_event|
341
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
342
+ project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
343
+ @current_text_editor&.text_widget&.setFocus
344
+ end
345
+ }
346
+ drag_source(DND::DROP_COPY) {
347
+ transfer [TextTransfer.getInstance].to_java(Transfer)
348
+ on_drag_set_data { |event|
349
+ Gladiator.drag = true
350
+ list = event.widget.getControl
351
+ event.data = list.getSelection.first
352
+ }
353
+ }
354
+ }
355
+ }
356
+
357
+ on_item_collapsed { |event|
358
+ if @file_explorer_expand_item.swt_expand_item.get_expanded
359
+ @file_lookup_expand_item_height = @file_lookup_expand_item.swt_expand_item.height
360
+ @file_lookup_expand_item.swt_expand_item.height = 0
361
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
362
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
363
+ @side_bar_sash_form.weights = [@file_lookup_expand_item.swt_expand_item.header_height, @file_lookup_expand_bar_height + @file_explorer_expand_bar_height - @file_lookup_expand_item.swt_expand_item.header_height]
364
+ end
365
+ }
366
+
367
+ on_item_expanded {
368
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
369
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
275
370
  }
371
+
276
372
  }
277
- @file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
278
- #visible bind(self, 'project_dir.filter') {|f| !f}
279
- items bind(self, :project_dir), tree_properties(children: :children, text: :name)
280
- drag_source(DND::DROP_COPY) {
281
- transfer [TextTransfer.getInstance].to_java(Transfer)
282
- on_drag_set_data { |event|
283
- Gladiator.drag = true
284
- tree = event.widget.getControl
285
- tree_item = tree.getSelection.first
286
- event.data = tree_item.getData.path
287
- }
373
+
374
+ @file_explorer_expand_bar = expand_bar {
375
+ layout_data :fill, :fill, true, true
376
+ font height: 17, style: :bold
377
+ foreground @default_foreground
378
+
379
+ on_swt_show {
380
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
288
381
  }
289
- menu {
290
- @open_menu_item = menu_item {
291
- text 'Open'
292
- on_widget_selected {
293
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
294
- }
382
+
383
+ on_swt_Resize(&resize_expand_items)
384
+
385
+ @file_explorer_expand_item = expand_item {
386
+ grid_layout {
387
+ margin_width 0
388
+ margin_height 0
295
389
  }
296
- menu_item(:separator)
297
- menu_item {
298
- text 'Delete'
299
- on_widget_selected {
300
- tree_item = @file_tree.swt_widget.getSelection.first
301
- delete_tree_item(tree_item)
390
+ text 'File Explorer'
391
+ height display.bounds.height
392
+
393
+ @file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
394
+ layout_data :fill, :fill, true, true
395
+ #visible bind(self, 'project_dir.filter') {|f| !f}
396
+ items bind(self, :project_dir), tree_properties(children: :children, text: :name)
397
+ foreground @default_foreground
398
+ drag_source(DND::DROP_COPY) {
399
+ transfer [TextTransfer.getInstance].to_java(Transfer)
400
+ on_drag_set_data { |event|
401
+ Gladiator.drag = true
402
+ tree = event.widget.getControl
403
+ tree_item = tree.getSelection.first
404
+ event.data = tree_item.getData.path
405
+ }
302
406
  }
303
- }
304
- menu_item {
305
- text 'Refresh'
306
- on_widget_selected {
307
- project_dir.refresh
407
+ menu {
408
+ @open_menu_item = menu_item {
409
+ text 'Open'
410
+ on_widget_selected {
411
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
412
+ }
413
+ }
414
+ menu_item(:separator)
415
+ menu_item {
416
+ text 'Delete'
417
+ on_widget_selected {
418
+ tree_item = @file_tree.swt_widget.getSelection.first
419
+ delete_tree_item(tree_item)
420
+ }
421
+ }
422
+ menu_item {
423
+ text 'Refresh'
424
+ on_widget_selected {
425
+ project_dir.refresh
426
+ }
427
+ }
428
+ menu_item {
429
+ text 'Rename'
430
+ on_widget_selected {
431
+ rename_selected_tree_item
432
+ }
433
+ }
434
+ menu_item {
435
+ text 'New Directory'
436
+ on_widget_selected {
437
+ add_new_directory_to_selected_tree_item
438
+ }
439
+ }
440
+ menu_item {
441
+ text 'New File'
442
+ on_widget_selected {
443
+ add_new_file_to_selected_tree_item
444
+ }
445
+ }
308
446
  }
309
- }
310
- menu_item {
311
- text 'Rename'
312
- on_widget_selected {
313
- rename_selected_tree_item
447
+ on_swt_menudetect { |event|
448
+ path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
449
+ @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
314
450
  }
315
- }
316
- menu_item {
317
- text 'New Directory'
318
- on_widget_selected {
319
- add_new_directory_to_selected_tree_item
451
+ on_mouse_up {
452
+ if Gladiator.drag_and_drop
453
+ Gladiator.drag_and_drop = false
454
+ else
455
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
456
+ @current_text_editor&.text_widget&.setFocus
457
+ end
320
458
  }
321
- }
322
- menu_item {
323
- text 'New File'
324
- on_widget_selected {
325
- add_new_file_to_selected_tree_item
459
+ on_key_pressed { |key_event|
460
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
461
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
462
+ @current_text_editor&.text_widget&.setFocus
463
+ end
464
+ }
465
+ on_paint_control {
466
+ root_item = @file_tree.swt_widget.getItems.first
467
+ if root_item && !root_item.getExpanded
468
+ root_item.setExpanded(true)
469
+ end
326
470
  }
327
471
  }
328
472
  }
329
- on_swt_menudetect { |event|
330
- path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
331
- @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
332
- }
333
- on_mouse_up {
334
- if Gladiator.drag_and_drop
335
- Gladiator.drag_and_drop = false
336
- else
337
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
338
- @current_text_editor&.text_widget&.setFocus
473
+
474
+ on_item_collapsed { |event|
475
+ if @file_lookup_expand_item.swt_expand_item.get_expanded
476
+ @file_explorer_expand_item_height = @file_explorer_expand_item.swt_expand_item.height
477
+ @file_explorer_expand_item.swt_expand_item.height = 0
478
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
479
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
480
+ @side_bar_sash_form.weights = [@file_explorer_expand_bar_height + @file_explorer_expand_bar_height - @file_explorer_expand_item.swt_expand_item.header_height, @file_explorer_expand_item.swt_expand_item.header_height]
339
481
  end
340
482
  }
341
- on_key_pressed { |key_event|
342
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
343
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
344
- @current_text_editor&.text_widget&.setFocus
345
- end
346
- }
347
- on_paint_control {
348
- root_item = @file_tree.swt_widget.getItems.first
349
- if root_item && !root_item.getExpanded
350
- root_item.setExpanded(true)
351
- end
483
+
484
+ on_item_expanded {
485
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
486
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
352
487
  }
488
+
353
489
  }
490
+
354
491
  }
355
492
 
356
493
  # TODO see if you could replace some of this with Glimmer DSL/API syntax
@@ -360,117 +497,221 @@ module Glimmer
360
497
  @file_tree_editor.minimumHeight = 20;
361
498
 
362
499
  }
363
- @editor_container = composite {
364
- grid_layout 1, false
500
+
501
+ composite {
502
+ grid_layout(1, false) {
503
+ margin_width 0
504
+ margin_height 0
505
+ }
365
506
  layout_data :fill, :fill, true, true
366
- composite {
367
- grid_layout 3, false
368
-
369
- # row 1
370
-
371
- label {
372
- text 'File:'
373
- }
507
+
508
+ @navigation_expand_bar = expand_bar {
509
+ layout_data :fill, :top, true, false
510
+ font height: 17, style: :bold
511
+ foreground @default_foreground
512
+
513
+ @navigation_expand_item = expand_item {
514
+ text 'Navigation'
515
+ height 115
374
516
 
375
- @file_path_label = styled_text(:none) {
376
- layout_data(:fill, :fill, true, false) {
377
- horizontal_span 2
517
+ grid_layout(5, false) {
518
+ margin_right 5
378
519
  }
379
- background color(:widget_background)
380
- editable false
381
- caret nil
382
- text bind(project_dir, 'selected_child.path')
383
- on_mouse_up {
384
- @file_path_label.swt_widget.selectAll
520
+
521
+ stat_font = {name: 'Consolas', height: OS.mac? ? 15 : 12}
522
+
523
+ # row 1
524
+
525
+ label {
526
+ layout_data(:left, :center, false, false)
527
+ text 'File:'
528
+ foreground @default_foreground
385
529
  }
386
- on_focus_lost {
387
- @file_path_label.swt_widget.setSelection(0, 0)
530
+
531
+ @file_path_label = styled_text(:none) {
532
+ layout_data(:fill, :center, true, false) {
533
+ horizontal_span 2
534
+ }
535
+ background color(:widget_background)
536
+ foreground @default_foreground
537
+ editable false
538
+ caret nil
539
+ text bind(project_dir, 'selected_child.path')
540
+ on_mouse_up {
541
+ @file_path_label.swt_widget.selectAll
542
+ }
543
+ on_focus_lost {
544
+ @file_path_label.swt_widget.setSelection(0, 0)
545
+ }
388
546
  }
389
- }
390
-
391
- # row 2
392
-
393
- label {
394
- text 'Line:'
395
- }
396
- @line_number_text = text {
397
- layout_data(:fill, :fill, true, false) {
398
- minimum_width 400
399
- }
400
- text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
401
- on_key_pressed { |key_event|
402
- if key_event.keyCode == swt(:cr)
403
- @current_text_editor&.text_widget&.setFocus
404
- end
547
+
548
+ label {
549
+ layout_data(:left, :center, false, false)
550
+ text 'Caret Position:'
551
+ foreground @default_foreground
405
552
  }
406
- on_verify_text { |event|
407
- event.doit = !event.text.match(/^\d*$/).to_a.empty?
553
+ label(:right) {
554
+ layout_data(:fill, :center, true, false)
555
+ text bind(project_dir, 'selected_child.caret_position')
556
+ foreground @default_foreground
557
+ font stat_font
408
558
  }
409
- }
410
- label
411
-
412
- # row 3
413
-
414
- label {
415
- text 'Find:'
416
- }
417
- @find_text = text {
418
- layout_data(:fill, :center, true, false) {
419
- minimum_width 400
420
- }
421
- text bind(project_dir, 'selected_child.find_text')
422
- on_key_pressed { |key_event|
423
- if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
424
- project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
425
- project_dir.selected_child&.find_next
426
- end
427
- if key_event.keyCode == swt(:cr)
428
- project_dir.selected_child&.find_next
429
- end
559
+
560
+ # row 2
561
+
562
+ label {
563
+ layout_data(:left, :center, false, false)
564
+ text 'Line:'
565
+ foreground @default_foreground
430
566
  }
431
- }
432
- composite {
433
- row_layout
434
- button(:check) {
435
- selection bind(project_dir, 'selected_child.case_sensitive')
567
+ @line_number_text = text {
568
+ layout_data(:fill, :center, true, false) {
569
+ minimum_width 400
570
+ }
571
+ text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
572
+ foreground @default_foreground
573
+ font stat_font
574
+ on_key_pressed { |key_event|
575
+ if key_event.keyCode == swt(:cr)
576
+ @current_text_editor&.text_widget&.setFocus
577
+ end
578
+ }
579
+ on_verify_text { |event|
580
+ event.doit = !event.text.match(/^\d*$/).to_a.empty?
581
+ }
582
+ }
583
+ label # filler
584
+
585
+ label {
586
+ layout_data(:left, :center, false, false)
587
+ text 'Line Position:'
588
+ foreground @default_foreground
589
+ }
590
+ label(:right) {
591
+ layout_data(:fill, :center, true, false)
592
+ text bind(project_dir, 'selected_child.line_position')
593
+ foreground @default_foreground
594
+ font stat_font
595
+ }
596
+
597
+ # row 3
598
+
599
+ label {
600
+ layout_data(:left, :center, false, false)
601
+ text 'Find:'
602
+ foreground @default_foreground
603
+ }
604
+ @find_text = text {
605
+ layout_data(:fill, :center, true, false) {
606
+ minimum_width 400
607
+ }
608
+ text bind(project_dir, 'selected_child.find_text')
609
+ foreground @default_foreground
610
+ font stat_font
436
611
  on_key_pressed { |key_event|
612
+ if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
613
+ project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
614
+ project_dir.selected_child&.find_next
615
+ end
437
616
  if key_event.keyCode == swt(:cr)
438
617
  project_dir.selected_child&.find_next
439
618
  end
440
619
  }
441
620
  }
621
+ composite {
622
+ layout_data(:left, :center, true, false)
623
+ row_layout {
624
+ margin_width 0
625
+ margin_height 0
626
+ }
627
+ button(:check) {
628
+ selection bind(project_dir, 'selected_child.case_sensitive')
629
+ on_key_pressed { |key_event|
630
+ if key_event.keyCode == swt(:cr)
631
+ project_dir.selected_child&.find_next
632
+ end
633
+ }
634
+ }
635
+ label {
636
+ text 'Case-sensitive'
637
+ foreground @default_foreground
638
+ }
639
+ }
640
+
641
+ label {
642
+ layout_data(:left, :center, false, false)
643
+ text 'Selection Count:'
644
+ foreground @default_foreground
645
+ }
646
+ label(:right) {
647
+ layout_data(:fill, :center, true, false)
648
+ text bind(project_dir, 'selected_child.selection_count')
649
+ foreground @default_foreground
650
+ font stat_font
651
+ }
652
+
653
+ # row 4
654
+
655
+ label {
656
+ layout_data(:left, :center, false, false)
657
+ text 'Replace:'
658
+ foreground @default_foreground
659
+ }
660
+ @replace_text = text {
661
+ layout_data(:fill, :center, true, false) {
662
+ minimum_width 400
663
+ }
664
+ text bind(project_dir, 'selected_child.replace_text')
665
+ foreground @default_foreground
666
+ font stat_font
667
+ on_focus_gained {
668
+ project_dir.selected_child&.ensure_find_next
669
+ }
670
+ on_key_pressed { |key_event|
671
+ if key_event.keyCode == swt(:cr)
672
+ if project_dir.selected_child
673
+ Command.do(project_dir.selected_child, :replace_next!)
674
+ end
675
+ end
676
+ }
677
+ }
678
+ label # filler
442
679
  label {
443
- text 'Case-sensitive'
680
+ layout_data(:left, :center, false, false)
681
+ text 'Top Pixel:'
682
+ foreground @default_foreground
683
+ }
684
+ label(:right) {
685
+ layout_data(:fill, :center, true, false)
686
+ text bind(project_dir, 'selected_child.top_pixel')
687
+ foreground @default_foreground
688
+ font stat_font
444
689
  }
445
690
  }
446
-
447
- # row 4
448
-
449
- label {
450
- text 'Replace:'
691
+
692
+ on_item_collapsed {
693
+ @navigation_expand_item_height = @navigation_expand_item.swt_expand_item.height if @navigation_expand_item.swt_expand_item.height > 0
694
+ @navigation_expand_item.swt_expand_item.height = 0
695
+ async_exec {
696
+ body_root.pack_same_size
697
+ }
451
698
  }
452
- @replace_text = text {
453
- layout_data(:fill, :fill, true, false) {
454
- minimum_width 300
455
- }
456
- text bind(project_dir, 'selected_child.replace_text')
457
- on_focus_gained {
458
- project_dir.selected_child&.ensure_find_next
459
- }
460
- on_key_pressed { |key_event|
461
- if key_event.keyCode == swt(:cr)
462
- if project_dir.selected_child
463
- Command.do(project_dir.selected_child, :replace_next!)
464
- end
465
- end
699
+
700
+ on_item_expanded {
701
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height if @navigation_expand_item_height
702
+ async_exec {
703
+ body_root.pack_same_size
466
704
  }
467
705
  }
468
- label
706
+
469
707
  }
708
+
470
709
  @tab_folder_sash_form = sash_form {
471
710
  layout_data(:fill, :fill, true, true) {
472
- width_hint 640
473
- height_hint 480
711
+ width_hint 768
712
+ height_hint 576
713
+ minimum_width 768
714
+ minimum_height 576
474
715
  }
475
716
  sash_width 10
476
717
  orientation bind(self, :split_orientation)
@@ -517,20 +758,77 @@ module Glimmer
517
758
  project_dir.ignore_paths ||= ['packages', 'tmp']
518
759
  open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
519
760
  open_file_paths2 = @config[:open_file_paths2]
520
- open_file_paths1.to_a.each do |file_path|
521
- project_dir.selected_child_path = file_path
761
+ self.split_orientation = swt(@config[:split_orientation] || :horizontal) rescue swt(:horizontal)
762
+ if @progress_bar_shell.nil?
763
+ @progress_bar_shell = shell(body_root, :title) {
764
+ text 'Gladiator'
765
+ fill_layout(:vertical) {
766
+ margin_width 15
767
+ margin_height 15
768
+ spacing 5
769
+ }
770
+ label(:center) {
771
+ text "Opening Last Open Files"
772
+ font height: 20
773
+ }
774
+ # @progress_bar = progress_bar(:horizontal, :indeterminate)
775
+ }
776
+ async_exec {
777
+ @progress_bar_shell.open
778
+ }
522
779
  end
523
- # TODO replace the next line with one that selects the visible tab
524
- project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths1.to_a.include?(@config[:selected_child_path])
525
- Gladiator.drag = true
526
- open_file_paths2.to_a.each do |file_path|
527
- project_dir.selected_child_path = file_path
780
+ open_file_paths1.to_a.each do |file_path|
781
+ async_exec {
782
+ Gladiator.drag = false
783
+ Gladiator.startup = file_path != open_file_paths1.to_a[-1]
784
+ project_dir.selected_child_path = file_path
785
+ }
528
786
  end
529
787
  # TODO replace the next line with one that selects the visible tab
530
- project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths2.to_a.include?(@config[:selected_child_path])
531
- Gladiator.drag = false
532
- project_dir.selected_child&.caret_position = project_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position].to_i) if @config[:caret_position]
533
- project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
788
+ async_exec {
789
+ # TODO check why this is not working
790
+ if open_file_paths1.to_a.include?(@config[:selected_child_path])
791
+ Gladiator.drag = false
792
+ Gladiator.startup = false
793
+ project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
794
+ project_dir.selected_child&.caret_position = project_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position].to_i) if @config[:caret_position]
795
+ project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
796
+ end
797
+ }
798
+ async_exec {
799
+ open_file_paths2.to_a.each do |file_path|
800
+ async_exec {
801
+ Gladiator.drag = true
802
+ Gladiator.startup = file_path != open_file_paths2.to_a[-1]
803
+ project_dir.selected_child_path = file_path
804
+ }
805
+ end
806
+ # TODO replace the next line with one that selects the visible tab
807
+ async_exec {
808
+ # TODO check why this is not working
809
+ if open_file_paths2.to_a.include?(@config[:selected_child_path])
810
+ Gladiator.drag = true
811
+ Gladiator.startup = false
812
+ project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
813
+ project_dir.selected_child&.caret_position = project_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position].to_i) if @config[:caret_position]
814
+ project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
815
+ end
816
+ }
817
+ async_exec {
818
+ Gladiator.drag = false
819
+ @progress_bar_shell&.close
820
+ @progress_bar_shell = nil
821
+ @loaded_config = true
822
+ }
823
+ }
824
+ async_exec {
825
+ Thread.new {
826
+ all_files = open_file_paths1.to_a + open_file_paths2.to_a
827
+ all_files.each do |file|
828
+ project_dir.find_child_file(file)&.dirty_content
829
+ end
830
+ }
831
+ }
534
832
  else
535
833
  @loaded_config = true
536
834
  end
@@ -546,6 +844,7 @@ module Glimmer
546
844
  open_file_paths2 = tab_folder2&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
547
845
  @config = {
548
846
  selected_child_path: child.path,
847
+ split_orientation: split_orientation == swt(:horizontal) ? 'horizontal' : 'vertical',
549
848
  caret_position: child.caret_position,
550
849
  top_pixel: child.top_pixel,
551
850
  shell_width: swt_widget&.getBounds&.width,
@@ -612,17 +911,24 @@ module Glimmer
612
911
  return if tree_item.nil?
613
912
  file = tree_item.getData
614
913
  parent_path = ::File.dirname(file.path)
914
+ if file.is_a?(Gladiator::Dir)
915
+ file_paths = file.all_children.select {|f| f.is_a?(Gladiator::File)}.map(&:path)
916
+ file.remove_all_observers
917
+ else
918
+ file_paths = [file.path]
919
+ end
920
+ file_paths.each do |file_path|
921
+ found_tab_item = find_tab_item(file_path)
922
+ if found_tab_item
923
+ project_dir.selected_child_path_history.delete(found_tab_item.getData('file_path'))
924
+ found_tab_item.getData('proxy')&.dispose
925
+ end
926
+ end
615
927
  file.delete! # TODO consider supporting command undo/redo
616
928
  project_dir.refresh(async: false)
617
929
  parent_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == parent_path}.first
618
930
  @file_tree.swt_widget.showItem(parent_tree_item)
619
931
  parent_tree_item.setExpanded(true)
620
- # TODO close text editor tab
621
- found_tab_item = find_tab_item(file.path)
622
- if found_tab_item
623
- project_dir.selected_child_path_history.delete(found_tab_item.getData('file_path'))
624
- found_tab_item.getData('proxy')&.dispose
625
- end
626
932
  rescue => e
627
933
  puts e.full_message
628
934
  end
@@ -691,6 +997,9 @@ module Glimmer
691
997
  else
692
998
  selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
693
999
  end
1000
+ async_exec {
1001
+ @file_tree.swt_widget.showItem(edited_tree_item)
1002
+ }
694
1003
  end
695
1004
  project_dir.resume_refresh
696
1005
  },
@@ -708,8 +1017,9 @@ module Glimmer
708
1017
 
709
1018
  def open_project
710
1019
  selected_directory = directory_dialog.open
711
- @progress_bar_shell = shell(body_root) {
712
- text 'Opening Project'
1020
+ return if selected_directory.nil?
1021
+ @progress_bar_shell = shell(body_root, :title) {
1022
+ text 'Gladiator'
713
1023
  fill_layout(:vertical) {
714
1024
  margin_width 15
715
1025
  margin_height 15
@@ -721,29 +1031,33 @@ module Glimmer
721
1031
  }
722
1032
  # @progress_bar = progress_bar(:horizontal, :indeterminate)
723
1033
  }
724
- Thread.new {
725
- async_exec {
726
- @progress_bar_shell.open
727
- }
1034
+ async_exec {
1035
+ @progress_bar_shell.open
728
1036
  }
729
- Thread.new {
730
- async_exec {
731
- gladiator(project_dir_path: selected_directory) {
732
- on_swt_show {
733
- @progress_bar_shell.close
734
- }
735
- }.open if selected_directory
736
- }
1037
+ async_exec {
1038
+ gladiator(project_dir_path: selected_directory) {
1039
+ on_swt_show {
1040
+ @progress_bar_shell.close
1041
+ @progress_bar_shell = nil
1042
+ }
1043
+ }.open if selected_directory
737
1044
  }
738
1045
  end
739
1046
 
740
1047
  def handle_display_shortcut(key_event)
741
1048
  if key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'f'
742
- if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
743
- find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
744
- end
745
- find_text.swt_widget.selectAll
746
- find_text.swt_widget.setFocus
1049
+ @navigation_expand_item.swt_expand_item.set_expanded true
1050
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height if @navigation_expand_item_height
1051
+ async_exec {
1052
+ body_root.pack_same_size
1053
+ }
1054
+ async_exec {
1055
+ if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
1056
+ find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
1057
+ end
1058
+ find_text.swt_widget.selectAll
1059
+ find_text.swt_widget.setFocus
1060
+ }
747
1061
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
748
1062
  Clipboard.copy(project_dir.selected_child.path)
749
1063
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
@@ -780,7 +1094,7 @@ module Glimmer
780
1094
  end
781
1095
  end
782
1096
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
783
- self.split_orientation = split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
1097
+ self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
784
1098
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
785
1099
  current_tab_folder.swt_widget.setSelection((current_tab_folder.swt_widget.getSelectionIndex() + 1) % current_tab_folder.swt_widget.getItemCount) if current_tab_folder.swt_widget.getItemCount > 0
786
1100
  current_text_editor&.text_widget&.setFocus
@@ -839,12 +1153,34 @@ module Glimmer
839
1153
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'g'
840
1154
  project_dir.selected_child.find_next
841
1155
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'l'
842
- line_number_text.swt_widget.selectAll
843
- line_number_text.swt_widget.setFocus
1156
+ unless @navigation_expand_item.swt_expand_item.get_expanded
1157
+ @navigation_expand_item.swt_expand_item.set_expanded true
1158
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height if @navigation_expand_item_height
1159
+ async_exec {
1160
+ body_root.pack_same_size
1161
+ }
1162
+ async_exec {
1163
+ line_number_text.swt_widget.selectAll
1164
+ line_number_text.swt_widget.setFocus
1165
+ }
1166
+ else
1167
+ line_number_text.swt_widget.selectAll
1168
+ line_number_text.swt_widget.setFocus
1169
+ end
844
1170
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'r'
1171
+ unless @file_lookup_expand_item.swt_expand_item.get_expanded
1172
+ @file_lookup_expand_item.swt_expand_item.set_expanded true
1173
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
1174
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
1175
+ end
845
1176
  filter_text.swt_widget.selectAll
846
1177
  filter_text.swt_widget.setFocus
847
1178
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 't'
1179
+ unless @file_explorer_expand_item.swt_expand_item.get_expanded
1180
+ @file_explorer_expand_item.swt_expand_item.set_expanded true
1181
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
1182
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
1183
+ end
848
1184
  select_tree_item unless rename_in_progress
849
1185
  file_tree.swt_widget.setFocus
850
1186
  elsif key_event.keyCode == swt(:esc)