glimmer-cs-gladiator 0.5.1 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,7 @@ module Glimmer
23
23
  attr_accessor :drag_and_drop
24
24
  attr_accessor :drag
25
25
  end
26
-
26
+
27
27
  ## Add options like the following to configure CustomShell by outside consumers
28
28
  #
29
29
  # options :title, :background_color
@@ -35,16 +35,33 @@ module Glimmer
35
35
  @project_dir ||= Dir.new(project_dir_path)
36
36
  end
37
37
 
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
38
+ def split_orientation=(value)
39
+ @split_orientation = value
40
+ save_config
41
+ if @loaded_config && !split_pane?
42
+ Gladiator.drag = true
43
+ child_path = project_dir.selected_child_path
44
+ project_dir.selected_child = nil
45
+ project_dir.selected_child_path = child_path
46
+ Gladiator.drag = false
47
+ end
48
+ @split_orientation
49
+ end
50
+
51
+ def split_pane?
52
+ pane_count = @tab_folder_sash_form&.children&.size
53
+ pane_count && pane_count > 1
54
+ end
55
+
56
+ attr_reader :find_text, :tab_folder1, :tab_folder2, :filter_text, :rename_in_progress, :line_number_text, :file_tree, :split_orientation
57
+ attr_accessor :current_tab_item, :current_tab_folder, :current_text_editor
40
58
 
41
59
  ## Uncomment before_body block to pre-initialize variables to use in body
42
60
  #
43
61
  #
44
62
  before_body {
45
- Thread.new {
46
- project_dir #pre-initialize directory
47
- }
63
+ # TODO consider doing loading project files after displaying the GUI instead of holding it up before
64
+ project_dir #pre-initialize directory
48
65
  at_exit do
49
66
  project_dir.selected_child&.write_raw_dirty_content
50
67
  end
@@ -59,6 +76,7 @@ module Glimmer
59
76
  }
60
77
  end
61
78
 
79
+ @default_foreground = :dark_blue
62
80
  @split_orientation = swt(:horizontal)
63
81
  @config_file_path = ::File.join(project_dir.path, '.gladiator')
64
82
  @config = {}
@@ -92,7 +110,10 @@ module Glimmer
92
110
  @current_tab_folder.content {
93
111
  @current_tab_item = tab_item { |the_tab_item|
94
112
  text selected_file.name
95
- fill_layout :horizontal
113
+ fill_layout(:horizontal) {
114
+ margin_width 0
115
+ margin_height 0
116
+ }
96
117
  @current_text_editor = the_text_editor = text_editor(project_dir: project_dir, file: selected_file)
97
118
  @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
98
119
  @current_text_editor.text_proxy.content {
@@ -117,6 +138,9 @@ module Glimmer
117
138
  @current_text_editor&.text_widget&.setFocus
118
139
  }
119
140
  }
141
+ on_widget_disposed {
142
+ the_tab_item.swt_tab_item.get_data('file').close
143
+ }
120
144
  }
121
145
  @current_tab_item.swt_tab_item.setData('file_path', selected_file.path)
122
146
  @current_tab_item.swt_tab_item.setData('file', selected_file)
@@ -146,10 +170,12 @@ module Glimmer
146
170
  #
147
171
  body {
148
172
  shell {
173
+ grid_layout(2, false)
174
+
149
175
  text "Gladiator - #{::File.expand_path(project_dir.path)}"
150
176
  minimum_size 520, 250
151
177
  size 1440, 900
152
- grid_layout(2, false)
178
+
153
179
  on_swt_show {
154
180
  swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
155
181
  swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
@@ -181,7 +207,7 @@ module Glimmer
181
207
  begin
182
208
  project_dir.selected_child_path = ''
183
209
  rescue => e
184
- pd e
210
+ puts e.full_message
185
211
  end
186
212
  }
187
213
  }
@@ -199,11 +225,15 @@ module Glimmer
199
225
  text '&Split'
200
226
  menu_item(:radio) {
201
227
  text '&Horizontal'
202
- selection bind(self, :split_orientation, on_read: ->(o) { o == swt(:horizontal)}, on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical)})
228
+ selection bind(self, :split_orientation,
229
+ on_read: ->(o) { split_pane? && o == swt(:horizontal)},
230
+ on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical) })
203
231
  }
204
232
  menu_item(:radio) {
205
233
  text '&Vertical'
206
- selection bind(self, :split_orientation, on_read: ->(o) { o == swt(:vertical)}, on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal)})
234
+ selection bind(self, :split_orientation,
235
+ on_read: ->(o) { split_pane? && o == swt(:vertical)},
236
+ on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal) })
207
237
  }
208
238
  }
209
239
  }
@@ -232,126 +262,215 @@ module Glimmer
232
262
  }
233
263
 
234
264
  composite {
235
- grid_layout 1, false
265
+ grid_layout(1, false) {
266
+ margin_width 0
267
+ margin_height 0
268
+ }
269
+
236
270
  layout_data(:fill, :fill, false, true) {
237
271
  width_hint 300
238
272
  }
239
- @filter_text = text {
240
- layout_data :fill, :center, true, false
241
- text bind(project_dir, 'filter')
242
- on_key_pressed { |key_event|
243
- if key_event.keyCode == swt(:tab) ||
244
- key_event.keyCode == swt(:cr) ||
245
- key_event.keyCode == swt(:arrow_up) ||
246
- key_event.keyCode == swt(:arrow_down)
247
- @list.swt_widget.select(0) if @list.swt_widget.getSelectionIndex() == -1
248
- @list.swt_widget.setFocus
249
- end
250
- }
251
- }
252
- composite {
253
- fill_layout(:vertical) {
254
- spacing 5
255
- }
273
+ @side_bar_sash_form = sash_form(:vertical) {
256
274
  layout_data(:fill, :fill, true, true)
257
- @list = list(:border, :h_scroll, :v_scroll) {
258
- #visible bind(self, 'project_dir.filter') {|f| !!f}
259
- selection bind(project_dir, :filtered_path)
260
- on_mouse_up {
261
- project_dir.selected_child_path = @list.swt_widget.getSelection.first
262
- }
263
- on_key_pressed { |key_event|
264
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
265
- project_dir.selected_child_path = @list.swt_widget.getSelection.first
266
- @current_text_editor&.text_widget&.setFocus
267
- end
275
+ sash_width 4
276
+
277
+ resize_expand_items = lambda { |event=nil|
278
+ @file_lookup_expand_item&.swt_expand_item&.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
279
+ @file_explorer_expand_item&.swt_expand_item&.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
280
+ }
281
+
282
+ @file_lookup_expand_bar = expand_bar {
283
+ layout_data :fill, :fill, true, true
284
+ font height: 17, style: :bold
285
+ foreground @default_foreground
286
+
287
+ on_swt_show {
288
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
268
289
  }
269
- drag_source(DND::DROP_COPY) {
270
- transfer [TextTransfer.getInstance].to_java(Transfer)
271
- on_drag_set_data { |event|
272
- Gladiator.drag = true
273
- list = event.widget.getControl
274
- event.data = list.getSelection.first
290
+
291
+ on_swt_Resize(&resize_expand_items)
292
+
293
+ @file_lookup_expand_item = expand_item {
294
+ grid_layout {
295
+ margin_width 0
296
+ margin_height 0
297
+ }
298
+ text 'File Lookup'
299
+ height display.bounds.height
300
+
301
+ @filter_text = text {
302
+ layout_data :fill, :center, true, false
303
+ text bind(project_dir, 'filter')
304
+ on_key_pressed { |key_event|
305
+ if key_event.keyCode == swt(:tab) ||
306
+ key_event.keyCode == swt(:cr) ||
307
+ key_event.keyCode == swt(:arrow_up) ||
308
+ key_event.keyCode == swt(:arrow_down)
309
+ @file_lookup_list.swt_widget.select(0) if @file_lookup_list.swt_widget.getSelectionIndex() == -1
310
+ @file_lookup_list.swt_widget.setFocus
311
+ end
312
+ }
313
+ }
314
+
315
+ @file_lookup_list = list(:border, :h_scroll, :v_scroll) {
316
+ layout_data :fill, :fill, true, true
317
+ #visible bind(self, 'project_dir.filter') {|f| !!f}
318
+ selection bind(project_dir, :filtered_path)
319
+ foreground @default_foreground
320
+ on_mouse_up {
321
+ project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
322
+ }
323
+ on_key_pressed { |key_event|
324
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
325
+ project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
326
+ @current_text_editor&.text_widget&.setFocus
327
+ end
328
+ }
329
+ drag_source(DND::DROP_COPY) {
330
+ transfer [TextTransfer.getInstance].to_java(Transfer)
331
+ on_drag_set_data { |event|
332
+ Gladiator.drag = true
333
+ list = event.widget.getControl
334
+ event.data = list.getSelection.first
335
+ }
336
+ }
275
337
  }
276
338
  }
339
+
340
+ on_item_collapsed { |event|
341
+ if @file_explorer_expand_item.swt_expand_item.get_expanded
342
+ @file_lookup_expand_item_height = @file_lookup_expand_item.swt_expand_item.height
343
+ @file_lookup_expand_item.swt_expand_item.height = 0
344
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
345
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
346
+ @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]
347
+ end
348
+ }
349
+
350
+ on_item_expanded {
351
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
352
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
353
+ }
354
+
277
355
  }
278
- @file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
279
- #visible bind(self, 'project_dir.filter') {|f| !f}
280
- items bind(self, :project_dir), tree_properties(children: :children, text: :name)
281
- drag_source(DND::DROP_COPY) {
282
- transfer [TextTransfer.getInstance].to_java(Transfer)
283
- on_drag_set_data { |event|
284
- Gladiator.drag = true
285
- tree = event.widget.getControl
286
- tree_item = tree.getSelection.first
287
- event.data = tree_item.getData.path
288
- }
356
+
357
+ @file_explorer_expand_bar = expand_bar {
358
+ layout_data :fill, :fill, true, true
359
+ font height: 17, style: :bold
360
+ foreground @default_foreground
361
+
362
+ on_swt_show {
363
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
289
364
  }
290
- menu {
291
- @open_menu_item = menu_item {
292
- text 'Open'
293
- on_widget_selected {
294
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
295
- }
365
+
366
+ on_swt_Resize(&resize_expand_items)
367
+
368
+ @file_explorer_expand_item = expand_item {
369
+ grid_layout {
370
+ margin_width 0
371
+ margin_height 0
296
372
  }
297
- menu_item(:separator)
298
- menu_item {
299
- text 'Delete'
300
- on_widget_selected {
301
- tree_item = @file_tree.swt_widget.getSelection.first
302
- delete_tree_item(tree_item)
373
+ text 'File Explorer'
374
+ height display.bounds.height
375
+
376
+ @file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
377
+ layout_data :fill, :fill, true, true
378
+ #visible bind(self, 'project_dir.filter') {|f| !f}
379
+ items bind(self, :project_dir), tree_properties(children: :children, text: :name)
380
+ foreground @default_foreground
381
+ drag_source(DND::DROP_COPY) {
382
+ transfer [TextTransfer.getInstance].to_java(Transfer)
383
+ on_drag_set_data { |event|
384
+ Gladiator.drag = true
385
+ tree = event.widget.getControl
386
+ tree_item = tree.getSelection.first
387
+ event.data = tree_item.getData.path
388
+ }
303
389
  }
304
- }
305
- menu_item {
306
- text 'Refresh'
307
- on_widget_selected {
308
- project_dir.refresh
390
+ menu {
391
+ @open_menu_item = menu_item {
392
+ text 'Open'
393
+ on_widget_selected {
394
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
395
+ }
396
+ }
397
+ menu_item(:separator)
398
+ menu_item {
399
+ text 'Delete'
400
+ on_widget_selected {
401
+ tree_item = @file_tree.swt_widget.getSelection.first
402
+ delete_tree_item(tree_item)
403
+ }
404
+ }
405
+ menu_item {
406
+ text 'Refresh'
407
+ on_widget_selected {
408
+ project_dir.refresh
409
+ }
410
+ }
411
+ menu_item {
412
+ text 'Rename'
413
+ on_widget_selected {
414
+ rename_selected_tree_item
415
+ }
416
+ }
417
+ menu_item {
418
+ text 'New Directory'
419
+ on_widget_selected {
420
+ add_new_directory_to_selected_tree_item
421
+ }
422
+ }
423
+ menu_item {
424
+ text 'New File'
425
+ on_widget_selected {
426
+ add_new_file_to_selected_tree_item
427
+ }
428
+ }
309
429
  }
310
- }
311
- menu_item {
312
- text 'Rename'
313
- on_widget_selected {
314
- rename_selected_tree_item
430
+ on_swt_menudetect { |event|
431
+ path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
432
+ @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
315
433
  }
316
- }
317
- menu_item {
318
- text 'New Directory'
319
- on_widget_selected {
320
- add_new_directory_to_selected_tree_item
434
+ on_mouse_up {
435
+ if Gladiator.drag_and_drop
436
+ Gladiator.drag_and_drop = false
437
+ else
438
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
439
+ @current_text_editor&.text_widget&.setFocus
440
+ end
321
441
  }
322
- }
323
- menu_item {
324
- text 'New File'
325
- on_widget_selected {
326
- add_new_file_to_selected_tree_item
442
+ on_key_pressed { |key_event|
443
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
444
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
445
+ @current_text_editor&.text_widget&.setFocus
446
+ end
447
+ }
448
+ on_paint_control {
449
+ root_item = @file_tree.swt_widget.getItems.first
450
+ if root_item && !root_item.getExpanded
451
+ root_item.setExpanded(true)
452
+ end
327
453
  }
328
454
  }
329
455
  }
330
- on_swt_menudetect { |event|
331
- path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
332
- @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
333
- }
334
- on_mouse_up {
335
- if Gladiator.drag_and_drop
336
- Gladiator.drag_and_drop = false
337
- else
338
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
339
- @current_text_editor&.text_widget&.setFocus
456
+
457
+ on_item_collapsed { |event|
458
+ if @file_lookup_expand_item.swt_expand_item.get_expanded
459
+ @file_explorer_expand_item_height = @file_explorer_expand_item.swt_expand_item.height
460
+ @file_explorer_expand_item.swt_expand_item.height = 0
461
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
462
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
463
+ @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]
340
464
  end
341
465
  }
342
- on_key_pressed { |key_event|
343
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
344
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
345
- @current_text_editor&.text_widget&.setFocus
346
- end
347
- }
348
- on_paint_control {
349
- root_item = @file_tree.swt_widget.getItems.first
350
- if root_item && !root_item.getExpanded
351
- root_item.setExpanded(true)
352
- end
466
+
467
+ on_item_expanded {
468
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
469
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
353
470
  }
471
+
354
472
  }
473
+
355
474
  }
356
475
 
357
476
  # TODO see if you could replace some of this with Glimmer DSL/API syntax
@@ -361,117 +480,221 @@ module Glimmer
361
480
  @file_tree_editor.minimumHeight = 20;
362
481
 
363
482
  }
364
- @editor_container = composite {
365
- grid_layout 1, false
483
+
484
+ composite {
485
+ grid_layout(1, false) {
486
+ margin_width 0
487
+ margin_height 0
488
+ }
366
489
  layout_data :fill, :fill, true, true
367
- composite {
368
- grid_layout 3, false
369
-
370
- # row 1
371
-
372
- label {
373
- text 'File:'
374
- }
490
+
491
+ @navigation_expand_bar = expand_bar {
492
+ layout_data :fill, :top, true, false
493
+ font height: 17, style: :bold
494
+ foreground @default_foreground
495
+
496
+ @navigation_expand_item = expand_item {
497
+ text 'Navigation'
498
+ height 115
375
499
 
376
- @file_path_label = styled_text(:none) {
377
- layout_data(:fill, :fill, true, false) {
378
- horizontal_span 2
500
+ grid_layout(5, false) {
501
+ margin_right 5
379
502
  }
380
- background color(:widget_background)
381
- editable false
382
- caret nil
383
- text bind(project_dir, 'selected_child.path')
384
- on_mouse_up {
385
- @file_path_label.swt_widget.selectAll
503
+
504
+ stat_font = {name: 'Consolas', height: OS.mac? ? 15 : 12}
505
+
506
+ # row 1
507
+
508
+ label {
509
+ layout_data(:left, :center, false, false)
510
+ text 'File:'
511
+ foreground @default_foreground
386
512
  }
387
- on_focus_lost {
388
- @file_path_label.swt_widget.setSelection(0, 0)
513
+
514
+ @file_path_label = styled_text(:none) {
515
+ layout_data(:fill, :center, true, false) {
516
+ horizontal_span 2
517
+ }
518
+ background color(:widget_background)
519
+ foreground @default_foreground
520
+ editable false
521
+ caret nil
522
+ text bind(project_dir, 'selected_child.path')
523
+ on_mouse_up {
524
+ @file_path_label.swt_widget.selectAll
525
+ }
526
+ on_focus_lost {
527
+ @file_path_label.swt_widget.setSelection(0, 0)
528
+ }
389
529
  }
390
- }
391
-
392
- # row 2
393
-
394
- label {
395
- text 'Line:'
396
- }
397
- @line_number_text = text {
398
- layout_data(:fill, :fill, true, false) {
399
- minimum_width 400
400
- }
401
- text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
402
- on_key_pressed { |key_event|
403
- if key_event.keyCode == swt(:cr)
404
- @current_text_editor&.text_widget&.setFocus
405
- end
530
+
531
+ label {
532
+ layout_data(:left, :center, false, false)
533
+ text 'Caret Position:'
534
+ foreground @default_foreground
406
535
  }
407
- on_verify_text { |event|
408
- event.doit = !event.text.match(/^\d*$/).to_a.empty?
536
+ label(:right) {
537
+ layout_data(:fill, :center, true, false)
538
+ text bind(project_dir, 'selected_child.caret_position')
539
+ foreground @default_foreground
540
+ font stat_font
409
541
  }
410
- }
411
- label
412
-
413
- # row 3
414
-
415
- label {
416
- text 'Find:'
417
- }
418
- @find_text = text {
419
- layout_data(:fill, :center, true, false) {
420
- minimum_width 400
421
- }
422
- text bind(project_dir, 'selected_child.find_text')
423
- on_key_pressed { |key_event|
424
- if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
425
- project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
426
- project_dir.selected_child&.find_next
427
- end
428
- if key_event.keyCode == swt(:cr)
429
- project_dir.selected_child&.find_next
430
- end
542
+
543
+ # row 2
544
+
545
+ label {
546
+ layout_data(:left, :center, false, false)
547
+ text 'Line:'
548
+ foreground @default_foreground
431
549
  }
432
- }
433
- composite {
434
- row_layout
435
- button(:check) {
436
- selection bind(project_dir, 'selected_child.case_sensitive')
550
+ @line_number_text = text {
551
+ layout_data(:fill, :center, true, false) {
552
+ minimum_width 400
553
+ }
554
+ text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
555
+ foreground @default_foreground
556
+ font stat_font
557
+ on_key_pressed { |key_event|
558
+ if key_event.keyCode == swt(:cr)
559
+ @current_text_editor&.text_widget&.setFocus
560
+ end
561
+ }
562
+ on_verify_text { |event|
563
+ event.doit = !event.text.match(/^\d*$/).to_a.empty?
564
+ }
565
+ }
566
+ label # filler
567
+
568
+ label {
569
+ layout_data(:left, :center, false, false)
570
+ text 'Line Position:'
571
+ foreground @default_foreground
572
+ }
573
+ label(:right) {
574
+ layout_data(:fill, :center, true, false)
575
+ text bind(project_dir, 'selected_child.line_position')
576
+ foreground @default_foreground
577
+ font stat_font
578
+ }
579
+
580
+ # row 3
581
+
582
+ label {
583
+ layout_data(:left, :center, false, false)
584
+ text 'Find:'
585
+ foreground @default_foreground
586
+ }
587
+ @find_text = text {
588
+ layout_data(:fill, :center, true, false) {
589
+ minimum_width 400
590
+ }
591
+ text bind(project_dir, 'selected_child.find_text')
592
+ foreground @default_foreground
593
+ font stat_font
437
594
  on_key_pressed { |key_event|
595
+ if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
596
+ project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
597
+ project_dir.selected_child&.find_next
598
+ end
438
599
  if key_event.keyCode == swt(:cr)
439
600
  project_dir.selected_child&.find_next
440
601
  end
441
602
  }
442
603
  }
604
+ composite {
605
+ layout_data(:left, :center, true, false)
606
+ row_layout {
607
+ margin_width 0
608
+ margin_height 0
609
+ }
610
+ button(:check) {
611
+ selection bind(project_dir, 'selected_child.case_sensitive')
612
+ on_key_pressed { |key_event|
613
+ if key_event.keyCode == swt(:cr)
614
+ project_dir.selected_child&.find_next
615
+ end
616
+ }
617
+ }
618
+ label {
619
+ text 'Case-sensitive'
620
+ foreground @default_foreground
621
+ }
622
+ }
623
+
624
+ label {
625
+ layout_data(:left, :center, false, false)
626
+ text 'Selection Count:'
627
+ foreground @default_foreground
628
+ }
629
+ label(:right) {
630
+ layout_data(:fill, :center, true, false)
631
+ text bind(project_dir, 'selected_child.selection_count')
632
+ foreground @default_foreground
633
+ font stat_font
634
+ }
635
+
636
+ # row 4
637
+
443
638
  label {
444
- text 'Case-sensitive'
639
+ layout_data(:left, :center, false, false)
640
+ text 'Replace:'
641
+ foreground @default_foreground
642
+ }
643
+ @replace_text = text {
644
+ layout_data(:fill, :center, true, false) {
645
+ minimum_width 400
646
+ }
647
+ text bind(project_dir, 'selected_child.replace_text')
648
+ foreground @default_foreground
649
+ font stat_font
650
+ on_focus_gained {
651
+ project_dir.selected_child&.ensure_find_next
652
+ }
653
+ on_key_pressed { |key_event|
654
+ if key_event.keyCode == swt(:cr)
655
+ if project_dir.selected_child
656
+ Command.do(project_dir.selected_child, :replace_next!)
657
+ end
658
+ end
659
+ }
660
+ }
661
+ label # filler
662
+ label {
663
+ layout_data(:left, :center, false, false)
664
+ text 'Top Pixel:'
665
+ foreground @default_foreground
666
+ }
667
+ label(:right) {
668
+ layout_data(:fill, :center, true, false)
669
+ text bind(project_dir, 'selected_child.top_pixel')
670
+ foreground @default_foreground
671
+ font stat_font
445
672
  }
446
673
  }
447
-
448
- # row 4
449
-
450
- label {
451
- text 'Replace:'
674
+
675
+ on_item_collapsed {
676
+ @navigation_expand_item_height = @navigation_expand_item.swt_expand_item.height if @navigation_expand_item.swt_expand_item.height > 0
677
+ @navigation_expand_item.swt_expand_item.height = 0
678
+ async_exec {
679
+ body_root.pack_same_size
680
+ }
452
681
  }
453
- @replace_text = text {
454
- layout_data(:fill, :fill, true, false) {
455
- minimum_width 300
456
- }
457
- text bind(project_dir, 'selected_child.replace_text')
458
- on_focus_gained {
459
- project_dir.selected_child&.ensure_find_next
460
- }
461
- on_key_pressed { |key_event|
462
- if key_event.keyCode == swt(:cr)
463
- if project_dir.selected_child
464
- Command.do(project_dir.selected_child, :replace_next!)
465
- end
466
- end
682
+
683
+ on_item_expanded {
684
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height if @navigation_expand_item_height
685
+ async_exec {
686
+ body_root.pack_same_size
467
687
  }
468
688
  }
469
- label
689
+
470
690
  }
691
+
471
692
  @tab_folder_sash_form = sash_form {
472
693
  layout_data(:fill, :fill, true, true) {
473
- width_hint 640
474
- height_hint 480
694
+ width_hint 768
695
+ height_hint 576
696
+ minimum_width 768
697
+ minimum_height 576
475
698
  }
476
699
  sash_width 10
477
700
  orientation bind(self, :split_orientation)
@@ -518,20 +741,59 @@ module Glimmer
518
741
  project_dir.ignore_paths ||= ['packages', 'tmp']
519
742
  open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
520
743
  open_file_paths2 = @config[:open_file_paths2]
521
- open_file_paths1.to_a.each do |file_path|
522
- project_dir.selected_child_path = file_path
744
+ self.split_orientation = swt(@config[:split_orientation] || :horizontal) rescue swt(:horizontal)
745
+ if @progress_bar_shell.nil?
746
+ @progress_bar_shell = shell(body_root, :title) {
747
+ text 'Gladiator'
748
+ fill_layout(:vertical) {
749
+ margin_width 15
750
+ margin_height 15
751
+ spacing 5
752
+ }
753
+ label(:center) {
754
+ text "Opening Last Open Files"
755
+ font height: 20
756
+ }
757
+ # @progress_bar = progress_bar(:horizontal, :indeterminate)
758
+ }
759
+ async_exec {
760
+ @progress_bar_shell.open
761
+ }
523
762
  end
524
- # TODO replace the next line with one that selects the visible tab
525
- project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths1.to_a.include?(@config[:selected_child_path])
526
- Gladiator.drag = true
527
- open_file_paths2.to_a.each do |file_path|
528
- project_dir.selected_child_path = file_path
763
+ open_file_paths1.to_a.each do |file_path|
764
+ async_exec {
765
+ Gladiator.drag = false
766
+ project_dir.selected_child_path = file_path
767
+ }
529
768
  end
530
769
  # TODO replace the next line with one that selects the visible tab
531
- project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths2.to_a.include?(@config[:selected_child_path])
532
- Gladiator.drag = false
533
- 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]
534
- project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
770
+ async_exec {
771
+ Gladiator.drag = false
772
+ project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths1.to_a.include?(@config[:selected_child_path])
773
+ 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]
774
+ project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
775
+ }
776
+ async_exec {
777
+ open_file_paths2.to_a.each do |file_path|
778
+ async_exec {
779
+ Gladiator.drag = true
780
+ project_dir.selected_child_path = file_path
781
+ }
782
+ end
783
+ # TODO replace the next line with one that selects the visible tab
784
+ async_exec {
785
+ Gladiator.drag = true
786
+ project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths2.to_a.include?(@config[:selected_child_path])
787
+ 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]
788
+ project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
789
+ }
790
+ async_exec {
791
+ Gladiator.drag = false
792
+ @progress_bar_shell.close
793
+ @progress_bar_shell = nil
794
+ @loaded_config = true
795
+ }
796
+ }
535
797
  else
536
798
  @loaded_config = true
537
799
  end
@@ -547,6 +809,7 @@ module Glimmer
547
809
  open_file_paths2 = tab_folder2&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
548
810
  @config = {
549
811
  selected_child_path: child.path,
812
+ split_orientation: split_orientation == swt(:horizontal) ? 'horizontal' : 'vertical',
550
813
  caret_position: child.caret_position,
551
814
  top_pixel: child.top_pixel,
552
815
  shell_width: swt_widget&.getBounds&.width,
@@ -582,8 +845,12 @@ module Glimmer
582
845
  end
583
846
  end
584
847
 
848
+ def find_tab_item(file_path)
849
+ @current_tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == file_path }
850
+ end
851
+
585
852
  def selected_tab_item
586
- @current_tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == project_dir.selected_child&.path }
853
+ find_tab_item(project_dir.selected_child&.path)
587
854
  end
588
855
 
589
856
  def other_tab_items
@@ -609,25 +876,28 @@ module Glimmer
609
876
  return if tree_item.nil?
610
877
  file = tree_item.getData
611
878
  parent_path = ::File.dirname(file.path)
879
+ if file.is_a?(Gladiator::Dir)
880
+ file_paths = file.all_children.select {|f| f.is_a?(Gladiator::File)}.map(&:path)
881
+ file.remove_all_observers
882
+ else
883
+ file_paths = [file.path]
884
+ end
885
+ file_paths.each do |file_path|
886
+ found_tab_item = find_tab_item(file_path)
887
+ if found_tab_item
888
+ project_dir.selected_child_path_history.delete(found_tab_item.getData('file_path'))
889
+ found_tab_item.getData('proxy')&.dispose
890
+ end
891
+ end
612
892
  file.delete! # TODO consider supporting command undo/redo
613
893
  project_dir.refresh(async: false)
614
894
  parent_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == parent_path}.first
615
895
  @file_tree.swt_widget.showItem(parent_tree_item)
616
896
  parent_tree_item.setExpanded(true)
617
- # TODO close text editor tab
618
- # if file.is_a?(::File)
619
- # close tab
620
- # end
621
897
  rescue => e
622
898
  puts e.full_message
623
899
  end
624
900
 
625
- def rename_selected_tree_item
626
- project_dir.pause_refresh
627
- tree_item = @file_tree.swt_widget.getSelection.first
628
- rename_tree_item(tree_item)
629
- end
630
-
631
901
  def add_new_directory_to_selected_tree_item
632
902
  project_dir.pause_refresh
633
903
  tree_item = @file_tree.swt_widget.getSelection.first
@@ -642,7 +912,7 @@ module Glimmer
642
912
  project_dir.refresh(async: false, force: true)
643
913
  new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_directory_path}.first
644
914
  @file_tree.swt_widget.showItem(new_tree_item)
645
- rename_tree_item(new_tree_item, true)
915
+ rename_tree_item(new_tree_item)
646
916
  end
647
917
 
648
918
  def add_new_file_to_selected_tree_item
@@ -662,14 +932,40 @@ module Glimmer
662
932
  rename_tree_item(new_tree_item, true)
663
933
  end
664
934
 
665
- def rename_tree_item(tree_item, open_afterwards = false)
935
+ def rename_selected_tree_item
936
+ project_dir.pause_refresh
937
+ tree_item = @file_tree.swt_widget.getSelection.first
938
+ rename_tree_item(tree_item)
939
+ end
940
+
941
+ def rename_tree_item(tree_item, new_file = false)
942
+ original_file = tree_item.getData
943
+ current_file = project_dir.selected_child_path == original_file.path
944
+ found_tab_item = find_tab_item(original_file.path)
945
+ found_text_editor = found_tab_item&.getData('text_editor')
666
946
  @file_tree.edit_tree_item(
667
947
  tree_item,
668
948
  after_write: -> (edited_tree_item) {
669
949
  file = edited_tree_item.getData
670
950
  file_path = file.path
671
- # TODO rename file in tab title
672
- project_dir.selected_child_path = file_path if open_afterwards
951
+ file.name
952
+ if new_file
953
+ project_dir.selected_child_path = file_path
954
+ else
955
+ found_text_editor&.file = file
956
+ found_tab_item&.setData('file', file)
957
+ found_tab_item&.setData('file_path', file.path)
958
+ found_tab_item&.setText(file.name)
959
+ body_root.pack_same_size
960
+ if current_file
961
+ project_dir.selected_child_path = file_path
962
+ else
963
+ selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
964
+ end
965
+ async_exec {
966
+ @file_tree.swt_widget.showItem(edited_tree_item)
967
+ }
968
+ end
673
969
  project_dir.resume_refresh
674
970
  },
675
971
  after_cancel: -> {
@@ -686,8 +982,8 @@ module Glimmer
686
982
 
687
983
  def open_project
688
984
  selected_directory = directory_dialog.open
689
- @progress_bar_shell = shell(body_root) {
690
- text 'Opening Project'
985
+ @progress_bar_shell = shell(body_root, :title) {
986
+ text 'Gladiator'
691
987
  fill_layout(:vertical) {
692
988
  margin_width 15
693
989
  margin_height 15
@@ -699,19 +995,16 @@ module Glimmer
699
995
  }
700
996
  # @progress_bar = progress_bar(:horizontal, :indeterminate)
701
997
  }
702
- Thread.new {
703
- async_exec {
704
- @progress_bar_shell.open
705
- }
998
+ async_exec {
999
+ @progress_bar_shell.open
706
1000
  }
707
- Thread.new {
708
- async_exec {
709
- gladiator(project_dir_path: selected_directory) {
710
- on_swt_show {
711
- @progress_bar_shell.close
712
- }
713
- }.open if selected_directory
714
- }
1001
+ async_exec {
1002
+ gladiator(project_dir_path: selected_directory) {
1003
+ on_swt_show {
1004
+ @progress_bar_shell.close
1005
+ @progress_bar_shell = nil
1006
+ }
1007
+ }.open if selected_directory
715
1008
  }
716
1009
  end
717
1010
 
@@ -758,7 +1051,7 @@ module Glimmer
758
1051
  end
759
1052
  end
760
1053
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
761
- self.split_orientation = split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
1054
+ self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
762
1055
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
763
1056
  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
764
1057
  current_text_editor&.text_widget&.setFocus