glimmer-cs-gladiator 0.6.2 → 0.7.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.
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
1
22
  require 'fileutils'
2
23
  require 'os'
3
24
 
@@ -6,6 +27,8 @@ require 'models/glimmer/gladiator/file'
6
27
  require 'models/glimmer/gladiator/command'
7
28
 
8
29
  require 'views/glimmer/gladiator/text_editor'
30
+ require 'views/glimmer/gladiator/file_lookup_list'
31
+ require 'views/glimmer/gladiator/file_explorer_tree'
9
32
 
10
33
  Clipboard.implementation = Clipboard::Java
11
34
  Clipboard.copy(Clipboard.paste) # pre-initialize library to avoid slowdown during use
@@ -18,6 +41,9 @@ module Glimmer
18
41
  APP_ROOT = ::File.expand_path('../../../..', __FILE__)
19
42
  # TODO make sure COMMAND_KEY doesn't clash on Linux/Windows for CMD+CTRL shortcuts
20
43
  COMMAND_KEY = OS.mac? ? :command : :ctrl
44
+ VERSION = ::File.read(::File.join(APP_ROOT, 'VERSION')).to_s.strip
45
+ LICENSE = ::File.read(::File.join(APP_ROOT, 'LICENSE.txt')).to_s.strip
46
+ ICON = ::File.expand_path(::File.join(APP_ROOT, 'images', 'glimmer-cs-gladiator-logo.png'))
21
47
 
22
48
  class << self
23
49
  attr_accessor :drag_and_drop
@@ -39,7 +65,7 @@ module Glimmer
39
65
  def split_orientation=(value)
40
66
  @split_orientation = value
41
67
  save_config
42
- if @loaded_config && !split_pane?
68
+ if @loaded_config && !split_pane? && !value.nil?
43
69
  Gladiator.drag = true
44
70
  child_path = project_dir.selected_child_path
45
71
  project_dir.selected_child = nil
@@ -53,9 +79,11 @@ module Glimmer
53
79
  pane_count = @tab_folder_sash_form&.children&.size
54
80
  pane_count && pane_count > 1
55
81
  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
82
+
83
+ attr_reader :find_text, :filter_text, :line_number_text, :split_orientation
84
+ attr_accessor :current_tab_item, :current_tab_folder, :current_text_editor, :tab_folder1, :tab_folder2, :maximized_pane, :maximized_editor
85
+ alias maximized_pane? maximized_pane
86
+ alias maximized_editor? maximized_editor
59
87
 
60
88
  ## Uncomment before_body block to pre-initialize variables to use in body
61
89
  #
@@ -63,17 +91,25 @@ module Glimmer
63
91
  before_body {
64
92
  # TODO consider doing loading project files after displaying the GUI instead of holding it up before
65
93
  project_dir #pre-initialize directory
66
- at_exit do
94
+ TOPLEVEL_BINDING.receiver.send(:at_exit) do
67
95
  project_dir.selected_child&.write_raw_dirty_content
68
96
  end
69
97
  Display.setAppName('Gladiator')
70
98
  # make sure the display events are only hooked once if multiple gladiators are created
71
99
  unless defined?(@@display)
72
100
  @@display = display {
101
+ # TODO look into why a weird java dialog comes up on about (maybe a non-issue once packaged)
102
+ on_about {
103
+ display_about_dialog
104
+ }
73
105
  on_swt_keydown { |key_event|
74
106
  focused_gladiator = display.focus_control.shell&.get_data('custom_shell')
75
107
  focused_gladiator.handle_display_shortcut(key_event) if !focused_gladiator.nil? && key_event.widget.shell == focused_gladiator&.swt_widget
76
108
  }
109
+ on_swt_Close {
110
+ save_config
111
+ project_dir.selected_child&.write_dirty_content
112
+ }
77
113
  }
78
114
  end
79
115
 
@@ -89,18 +125,19 @@ module Glimmer
89
125
  #
90
126
  after_body {
91
127
  observe(project_dir, 'children') do
92
- select_tree_item unless @rename_in_progress || Gladiator.startup
128
+ @file_explorer_tree.select_tree_item unless Gladiator.startup
93
129
  end
94
130
  observe(project_dir, 'selected_child') do |selected_file|
95
131
  if selected_file
96
132
  if Gladiator.drag && !@tab_folder2
97
- @tab_folder1 = @current_tab_folder
133
+ self.tab_folder1 = current_tab_folder
98
134
  @tab_folder_sash_form.content {
99
- @current_tab_folder = @tab_folder2 = tab_folder
135
+ self.current_tab_folder = self.tab_folder2 = tab_folder {}
100
136
  @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
101
137
  }
138
+ body_root.pack_same_size
102
139
  end
103
- select_tree_item unless @rename_in_progress || Gladiator.startup
140
+ @file_explorer_tree.select_tree_item unless Gladiator.startup
104
141
  found_tab_item = selected_tab_item
105
142
  if found_tab_item
106
143
  @current_tab_folder.swt_widget.setSelection(found_tab_item)
@@ -124,7 +161,7 @@ module Glimmer
124
161
  @current_text_editor.text_proxy.content {
125
162
  on_focus_gained {
126
163
  tab_folder = the_text_editor.swt_widget.getParent.getParent
127
- @current_tab_folder = tab_folder.getData('proxy')
164
+ self.current_tab_folder = tab_folder.getData('proxy')
128
165
  @current_tab_item = the_tab_item
129
166
  @current_text_editor = the_text_editor
130
167
  @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
@@ -137,16 +174,16 @@ module Glimmer
137
174
  on_swt_show {
138
175
  @current_tab_item = the_tab_item
139
176
  @current_text_editor = the_text_editor
140
- @current_tab_folder = @current_tab_item.swt_widget.getParent.getData('proxy')
177
+ self.current_tab_folder = @current_tab_item.swt_widget.getParent.getData('proxy')
141
178
  @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
142
179
  @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
143
180
  project_dir.selected_child = selected_file
144
- async_exec {
145
- @current_text_editor&.text_widget&.setFocus
146
- }
181
+ @current_text_editor&.text_widget&.setFocus
147
182
  }
148
183
  on_widget_disposed {
149
- the_tab_item.swt_tab_item.get_data('file').close
184
+ project_dir.selected_child&.write_dirty_content
185
+ tab_item_file = the_tab_item.swt_tab_item.get_data('file')
186
+ tab_item_file.close unless [@tab_folder1, @tab_folder2].compact.map(&:items).flatten(1).detect {|ti| ti.get_data('file') == tab_item_file}
150
187
  }
151
188
  }
152
189
  @current_tab_item.swt_tab_item.setData('file_path', selected_file.path)
@@ -159,6 +196,22 @@ module Glimmer
159
196
  @current_text_editor&.text_widget&.setFocus
160
197
  end
161
198
  end
199
+ observe(self, 'maximized_pane') do
200
+ if tab_folder2
201
+ @tab_folder_sash_form.maximized_control = (current_tab_folder.swt_widget if maximized_pane?)
202
+ end
203
+ end
204
+ observe(self, 'maximized_editor') do
205
+ @file_area_and_editor_area_sash_form.maximized_control = (@editor_area_composite.swt_widget if maximized_editor?)
206
+ if !maximized_editor?
207
+ expand_navigation_expand_bar_height
208
+ else
209
+ collapse_navigation_expand_bar_height
210
+ end
211
+ @navigation_expand_item.swt_expand_item.set_expanded !maximized_editor?
212
+ body_root.pack_same_size
213
+ async_exec { body_root.pack_same_size }
214
+ end
162
215
  observe(project_dir, 'selected_child') do
163
216
  save_config
164
217
  end
@@ -176,17 +229,17 @@ module Glimmer
176
229
  #
177
230
  body {
178
231
  shell {
179
- grid_layout(2, false)
180
-
181
232
  text "Gladiator - #{::File.expand_path(project_dir.path)}"
182
233
  minimum_size 520, 250
183
234
  size 1440, 900
235
+ image ICON
184
236
 
185
237
  on_swt_show {
186
238
  swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
187
239
  swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
188
240
  @loaded_config = true
189
241
  }
242
+
190
243
  on_shell_closed {
191
244
  save_config
192
245
  project_dir.selected_child&.write_dirty_content
@@ -211,46 +264,109 @@ module Glimmer
211
264
  save_config
212
265
  }
213
266
  on_shell_deactivated {
214
- @current_text_editor&.file&.write_dirty_content
267
+ project_dir.selected_child&.write_dirty_content
215
268
  }
216
269
 
270
+ if OS.mac?
271
+ display.swt_display.system_menu.items.find {|mi| mi.id == swt(:id_quit)}.add_selection_listener {
272
+ save_config
273
+ project_dir.selected_child&.write_dirty_content
274
+ display.swt_display.shells.each(&:close)
275
+ }
276
+ end
277
+
217
278
  menu_bar {
218
279
  menu {
219
280
  text '&File'
220
281
 
221
282
  menu_item {
222
283
  text 'New &Scratchpad'
284
+ accelerator COMMAND_KEY, :shift, :s
223
285
  on_widget_selected {
224
- begin
225
- project_dir.selected_child_path = ''
226
- rescue => e
227
- puts e.full_message
228
- end
286
+ project_dir.selected_child_path = ''
229
287
  }
230
288
  }
231
- menu_item(:separator)
232
289
  menu_item {
233
290
  text 'Open &Project...'
291
+ accelerator COMMAND_KEY, :o
234
292
  on_widget_selected {
235
293
  open_project
236
294
  }
237
295
  }
296
+ menu_item(:separator)
297
+ menu_item {
298
+ text '&Quit Project'
299
+ accelerator COMMAND_KEY, :alt, :q
300
+ on_widget_selected {
301
+ save_config
302
+ project_dir.selected_child&.write_dirty_content
303
+ body_root.close
304
+ }
305
+ }
238
306
  }
239
307
  menu {
240
308
  text '&View'
241
309
  menu {
242
- text '&Split'
243
- menu_item(:radio) {
244
- text '&Horizontal'
245
- selection bind(self, :split_orientation,
246
- on_read: ->(o) { split_pane? && o == swt(:horizontal)},
247
- on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical) })
310
+ text '&Split Pane'
311
+ menu { |menu_proxy|
312
+ text '&Orientation'
313
+ menu_item(:radio) {
314
+ text '&Horizontal'
315
+ selection bind(self, :split_orientation,
316
+ on_read: ->(o) { split_pane? && o == swt(:horizontal) },
317
+ on_write: ->(b) { b.nil? ? nil : (b ? swt(:horizontal) : swt(:vertical)) })
318
+ }
319
+ menu_item(:radio) {
320
+ text '&Vertical'
321
+ selection bind(self, :split_orientation,
322
+ on_read: ->(o) { split_pane? && o == swt(:vertical) },
323
+ on_write: ->(b) { b.nil? ? nil : (b ? swt(:vertical) : swt(:horizontal)) })
324
+ }
325
+ }
326
+ menu_item(:check) {
327
+ text '&Maximize Pane'
328
+ enabled bind(self, :tab_folder2)
329
+ accelerator COMMAND_KEY, :shift, :m
330
+ selection bind(self, :maximized_pane)
331
+ }
332
+ menu_item {
333
+ text 'Reset &Panes'
334
+ enabled bind(self, :tab_folder2)
335
+ accelerator COMMAND_KEY, :shift, :p
336
+ on_widget_selected {
337
+ if tab_folder2
338
+ self.maximized_pane = false
339
+ @tab_folder_sash_form.weights = [1, 1]
340
+ end
341
+ }
248
342
  }
249
- menu_item(:radio) {
250
- text '&Vertical'
251
- selection bind(self, :split_orientation,
252
- on_read: ->(o) { split_pane? && o == swt(:vertical)},
253
- on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal) })
343
+ menu_item {
344
+ text '&Unsplit'
345
+ enabled bind(self, :tab_folder2)
346
+ accelerator COMMAND_KEY, :shift, :u
347
+ on_widget_selected {
348
+ if tab_folder2
349
+ self.maximized_pane = false
350
+ navigate_to_next_tab_folder if current_tab_folder != tab_folder2
351
+ close_all_tabs(tab_folder2)
352
+ self.split_orientation = nil
353
+ body_root.pack_same_size
354
+ end
355
+ }
356
+ }
357
+ }
358
+ menu_item(:check) {
359
+ text '&Maximize Editor'
360
+ accelerator COMMAND_KEY, :ctrl, :m
361
+ selection bind(self, :maximized_editor)
362
+ }
363
+ menu_item {
364
+ text '&Reset All'
365
+ accelerator COMMAND_KEY, :ctrl, :r
366
+ on_widget_selected {
367
+ self.maximized_editor = false
368
+ @file_area_and_editor_area_sash_form.weights = [1, 5]
369
+ @side_bar_sash_form.weights = [1, 1]
254
370
  }
255
371
  }
256
372
  }
@@ -271,468 +387,378 @@ module Glimmer
271
387
  # }
272
388
  menu_item {
273
389
  text '&Ruby'
390
+ accelerator COMMAND_KEY, :shift, :r
391
+ on_widget_selected {
392
+ begin
393
+ project_dir.selected_child.run
394
+ rescue Exception => e
395
+ dialog {
396
+ text 'Run - Ruby - Error Encountered!'
397
+ label {
398
+ text e.full_message
399
+ }
400
+ }.open
401
+ end
402
+ }
403
+ }
404
+ }
405
+ menu {
406
+ text '&Help'
407
+ menu_item {
408
+ text '&About'
409
+ accelerator COMMAND_KEY, :shift, :a
274
410
  on_widget_selected {
275
- project_dir.selected_child.run
411
+ display_about_dialog
276
412
  }
277
413
  }
278
414
  }
279
415
  }
416
+
417
+ @file_area_and_editor_area_sash_form = sash_form(:horizontal) {
418
+ weights 1, 5
280
419
 
281
- composite {
282
- grid_layout(1, false) {
283
- margin_width 0
284
- margin_height 0
285
- }
286
-
287
- layout_data(:fill, :fill, false, true) {
288
- width_hint 300
289
- }
290
- @side_bar_sash_form = sash_form(:vertical) {
291
- layout_data(:fill, :fill, true, true)
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
420
+ composite {
421
+ grid_layout(1, false) {
422
+ margin_width 0
423
+ margin_height 0
297
424
  }
298
425
 
299
- @file_lookup_expand_bar = expand_bar {
300
- layout_data :fill, :fill, true, true
301
- font height: 17, style: :bold
302
- foreground @default_foreground
426
+ @side_bar_sash_form = sash_form(:vertical) {
427
+ layout_data(:fill, :fill, true, true)
428
+ sash_width 4
303
429
 
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
430
+ resize_expand_items = lambda { |event=nil|
431
+ @file_lookup_expand_item&.swt_expand_item&.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
432
+ @file_explorer_expand_item&.swt_expand_item&.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
306
433
  }
307
434
 
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
435
+ @file_lookup_expand_bar = expand_bar {
436
+ layout_data :fill, :fill, true, true
437
+ font height: 17, style: :bold
438
+ foreground @default_foreground
439
+
440
+ on_swt_show {
441
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
314
442
  }
315
- text 'File Lookup'
316
- height display.bounds.height
317
443
 
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
444
+ on_swt_Resize(&resize_expand_items)
445
+
446
+ @file_lookup_expand_item = expand_item {
447
+ grid_layout {
448
+ margin_width 0
449
+ margin_height 0
450
+ }
451
+ text 'File Lookup'
452
+ height display.bounds.height
453
+
454
+ @filter_text = text {
455
+ layout_data :fill, :center, true, false
456
+ text bind(project_dir, 'filter')
457
+ on_key_pressed { |key_event|
458
+ if key_event.keyCode == swt(:tab) ||
459
+ key_event.keyCode == swt(:cr) ||
460
+ key_event.keyCode == swt(:arrow_up) ||
461
+ key_event.keyCode == swt(:arrow_down)
462
+ @file_lookup_list.swt_widget.select(0) if @file_lookup_list.swt_widget.getSelectionIndex() == -1
463
+ @file_lookup_list.swt_widget.setFocus
464
+ end
465
+ }
329
466
  }
467
+
468
+ @file_lookup_list = file_lookup_list(gladiator: self, foreground_color: @default_foreground) {
469
+ layout_data :fill, :fill, true, true
470
+ }
471
+ }
472
+
473
+ on_item_collapsed { |event|
474
+ if @file_explorer_expand_item.swt_expand_item.get_expanded
475
+ @file_lookup_expand_item_height = @file_lookup_expand_item.swt_expand_item.height
476
+ @file_lookup_expand_item.swt_expand_item.height = 0
477
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
478
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
479
+ @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]
480
+ end
330
481
  }
331
482
 
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
483
+ on_item_expanded {
484
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
485
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
486
+ }
487
+
488
+ }
489
+
490
+ @file_explorer_expand_bar = expand_bar {
491
+ layout_data :fill, :fill, true, true
492
+ font height: 17, style: :bold
493
+ foreground @default_foreground
494
+
495
+ on_swt_show {
496
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
497
+ }
498
+
499
+ on_swt_Resize(&resize_expand_items)
500
+
501
+ @file_explorer_expand_item = expand_item {
502
+ grid_layout {
503
+ margin_width 0
504
+ margin_height 0
345
505
  }
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
- }
506
+ text 'File Explorer'
507
+ height display.bounds.height
508
+
509
+ @file_explorer_tree = file_explorer_tree(gladiator: self, foreground_color: @default_foreground) {
510
+ layout_data :fill, :fill, true, true
353
511
  }
354
512
  }
355
- }
513
+
514
+ on_item_collapsed { |event|
515
+ if @file_lookup_expand_item.swt_expand_item.get_expanded
516
+ @file_explorer_expand_item_height = @file_explorer_expand_item.swt_expand_item.height
517
+ @file_explorer_expand_item.swt_expand_item.height = 0
518
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
519
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
520
+ @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]
521
+ end
522
+ }
356
523
 
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]
524
+ on_item_expanded {
525
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
526
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
527
+ }
528
+
370
529
  }
371
-
530
+
531
+ }
532
+
533
+ }
534
+
535
+ @editor_area_composite = composite {
536
+ grid_layout(1, false) {
537
+ margin_width 0
538
+ margin_height 0
372
539
  }
373
540
 
374
- @file_explorer_expand_bar = expand_bar {
375
- layout_data :fill, :fill, true, true
541
+ @navigation_expand_bar = expand_bar {
542
+ layout_data :fill, :top, true, false
376
543
  font height: 17, style: :bold
377
544
  foreground @default_foreground
378
545
 
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
381
- }
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
546
+ @navigation_expand_item = expand_item {
547
+ text 'Navigation'
548
+ height 115
549
+
550
+ grid_layout(5, false) {
551
+ margin_right 5
389
552
  }
390
- text 'File Explorer'
391
- height display.bounds.height
392
553
 
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)
554
+ stat_font = {name: 'Consolas', height: OS.mac? ? 15 : 12}
555
+
556
+ # row 1
557
+
558
+ label {
559
+ layout_data(:left, :center, false, false)
560
+ text 'File:'
397
561
  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
- }
562
+ }
563
+
564
+ @file_path_label = styled_text(:none) {
565
+ layout_data(:fill, :center, true, false) {
566
+ horizontal_span 2
406
567
  }
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
- }
568
+ background color(:widget_background)
569
+ foreground @default_foreground
570
+ editable false
571
+ caret nil
572
+ text bind(project_dir, 'selected_child.path')
573
+ on_mouse_up {
574
+ @file_path_label.swt_widget.selectAll
446
575
  }
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
576
+ on_focus_lost {
577
+ @file_path_label.swt_widget.setSelection(0, 0)
450
578
  }
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
579
+ }
580
+
581
+ label {
582
+ layout_data(:left, :center, false, false)
583
+ text 'Caret Position:'
584
+ foreground @default_foreground
585
+ }
586
+ label(:right) {
587
+ layout_data(:fill, :center, true, false)
588
+ text bind(project_dir, 'selected_child.caret_position')
589
+ foreground @default_foreground
590
+ font stat_font
591
+ }
592
+
593
+ # row 2
594
+
595
+ label {
596
+ layout_data(:left, :center, false, false)
597
+ text 'Line:'
598
+ foreground @default_foreground
599
+ }
600
+ @line_number_text = text {
601
+ layout_data(:fill, :center, true, false) {
602
+ minimum_width 400
458
603
  }
604
+ text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
605
+ foreground @default_foreground
606
+ font stat_font
459
607
  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)
608
+ if key_event.keyCode == swt(:cr)
462
609
  @current_text_editor&.text_widget&.setFocus
463
610
  end
464
611
  }
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
612
+ on_verify_text { |event|
613
+ event.doit = !event.text.match(/^\d*$/).to_a.empty?
470
614
  }
471
615
  }
472
- }
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]
481
- end
482
- }
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]
487
- }
488
-
489
- }
490
-
491
- }
492
-
493
- # TODO see if you could replace some of this with Glimmer DSL/API syntax
494
- @file_tree_editor = TreeEditor.new(@file_tree.swt_widget);
495
- @file_tree_editor.horizontalAlignment = swt(:left);
496
- @file_tree_editor.grabHorizontal = true;
497
- @file_tree_editor.minimumHeight = 20;
498
-
499
- }
500
-
501
- composite {
502
- grid_layout(1, false) {
503
- margin_width 0
504
- margin_height 0
505
- }
506
- layout_data :fill, :fill, true, true
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
516
-
517
- grid_layout(5, false) {
518
- margin_right 5
519
- }
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
529
- }
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
616
+ label # filler
617
+
618
+ label {
619
+ layout_data(:left, :center, false, false)
620
+ text 'Line Position:'
621
+ foreground @default_foreground
542
622
  }
543
- on_focus_lost {
544
- @file_path_label.swt_widget.setSelection(0, 0)
623
+ label(:right) {
624
+ layout_data(:fill, :center, true, false)
625
+ text bind(project_dir, 'selected_child.line_position')
626
+ foreground @default_foreground
627
+ font stat_font
545
628
  }
546
- }
547
-
548
- label {
549
- layout_data(:left, :center, false, false)
550
- text 'Caret Position:'
551
- foreground @default_foreground
552
- }
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
558
- }
559
-
560
- # row 2
561
-
562
- label {
563
- layout_data(:left, :center, false, false)
564
- text 'Line:'
565
- foreground @default_foreground
566
- }
567
- @line_number_text = text {
568
- layout_data(:fill, :center, true, false) {
569
- minimum_width 400
629
+
630
+ # row 3
631
+
632
+ label {
633
+ layout_data(:left, :center, false, false)
634
+ text 'Find:'
635
+ foreground @default_foreground
570
636
  }
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
637
+ @find_text = text {
638
+ layout_data(:fill, :center, true, false) {
639
+ minimum_width 400
640
+ }
641
+ text bind(project_dir, 'selected_child.find_text')
642
+ foreground @default_foreground
643
+ font stat_font
644
+ on_key_pressed { |key_event|
645
+ if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
646
+ project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
647
+ project_dir.selected_child&.find_next
648
+ end
649
+ if key_event.keyCode == swt(:cr)
650
+ project_dir.selected_child&.find_next
651
+ end
652
+ }
578
653
  }
579
- on_verify_text { |event|
580
- event.doit = !event.text.match(/^\d*$/).to_a.empty?
654
+ composite {
655
+ layout_data(:left, :center, true, false)
656
+ row_layout {
657
+ margin_width 0
658
+ margin_height 0
659
+ }
660
+ button(:check) {
661
+ selection bind(project_dir, 'selected_child.case_sensitive')
662
+ on_key_pressed { |key_event|
663
+ if key_event.keyCode == swt(:cr)
664
+ project_dir.selected_child&.find_next
665
+ end
666
+ }
667
+ }
668
+ label {
669
+ text 'Case-sensitive'
670
+ foreground @default_foreground
671
+ }
581
672
  }
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
673
+
674
+ label {
675
+ layout_data(:left, :center, false, false)
676
+ text 'Selection Count:'
677
+ foreground @default_foreground
607
678
  }
608
- text bind(project_dir, 'selected_child.find_text')
609
- foreground @default_foreground
610
- font stat_font
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
616
- if key_event.keyCode == swt(:cr)
617
- project_dir.selected_child&.find_next
618
- end
679
+ label(:right) {
680
+ layout_data(:fill, :center, true, false)
681
+ text bind(project_dir, 'selected_child.selection_count')
682
+ foreground @default_foreground
683
+ font stat_font
619
684
  }
620
- }
621
- composite {
622
- layout_data(:left, :center, true, false)
623
- row_layout {
624
- margin_width 0
625
- margin_height 0
685
+
686
+ # row 4
687
+
688
+ label {
689
+ layout_data(:left, :center, false, false)
690
+ text 'Replace:'
691
+ foreground @default_foreground
626
692
  }
627
- button(:check) {
628
- selection bind(project_dir, 'selected_child.case_sensitive')
693
+ @replace_text = text {
694
+ layout_data(:fill, :center, true, false) {
695
+ minimum_width 400
696
+ }
697
+ text bind(project_dir, 'selected_child.replace_text')
698
+ foreground @default_foreground
699
+ font stat_font
700
+ on_focus_gained {
701
+ project_dir.selected_child&.ensure_find_next
702
+ }
629
703
  on_key_pressed { |key_event|
630
704
  if key_event.keyCode == swt(:cr)
631
- project_dir.selected_child&.find_next
705
+ if project_dir.selected_child
706
+ Command.do(project_dir.selected_child, :replace_next!)
707
+ end
632
708
  end
633
709
  }
634
710
  }
711
+ label # filler
635
712
  label {
636
- text 'Case-sensitive'
713
+ layout_data(:left, :center, false, false)
714
+ text 'Top Pixel:'
637
715
  foreground @default_foreground
638
716
  }
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
717
+ label(:right) {
718
+ layout_data(:fill, :center, true, false)
719
+ text bind(project_dir, 'selected_child.top_pixel')
720
+ foreground @default_foreground
721
+ font stat_font
676
722
  }
677
723
  }
678
- label # filler
679
- label {
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
724
+
725
+ on_item_collapsed {
726
+ collapse_navigation_expand_bar_height
689
727
  }
690
- }
691
728
 
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
729
+ on_item_expanded {
730
+ expand_navigation_expand_bar_height
697
731
  }
732
+
698
733
  }
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
734
+
735
+ @tab_folder_sash_form = sash_form {
736
+ layout_data(:fill, :fill, true, true) {
737
+ width_hint 768
738
+ height_hint 576
739
+ minimum_width 768
740
+ minimum_height 576
704
741
  }
705
- }
706
-
707
- }
708
-
709
- @tab_folder_sash_form = sash_form {
710
- layout_data(:fill, :fill, true, true) {
711
- width_hint 768
712
- height_hint 576
713
- minimum_width 768
714
- minimum_height 576
715
- }
716
- sash_width 10
717
- orientation bind(self, :split_orientation)
718
- @current_tab_folder = tab_folder {
719
- drag_source(DND::DROP_COPY) {
720
- transfer [TextTransfer.getInstance].to_java(Transfer)
721
- event_data = nil
722
- on_drag_start {|event|
723
- Gladiator.drag = true
724
- tab_folder = event.widget.getControl
725
- tab_item = tab_folder.getItem(Point.new(event.x, event.y))
726
- event_data = tab_item.getData('file_path')
727
- }
728
- on_drag_set_data { |event|
729
- event.data = event_data
742
+ orientation bind(self, :split_orientation) {|value| async_exec { body_root.pack_same_size}; value}
743
+ self.current_tab_folder = self.tab_folder1 = tab_folder {
744
+ drag_source(DND::DROP_COPY) {
745
+ transfer [TextTransfer.getInstance].to_java(Transfer)
746
+ event_data = nil
747
+ on_drag_start {|event|
748
+ Gladiator.drag = true
749
+ tab_folder = event.widget.getControl
750
+ tab_item = tab_folder.getItem(Point.new(event.x, event.y))
751
+ event_data = tab_item.getData('file_path')
752
+ }
753
+ on_drag_set_data { |event|
754
+ event.data = event_data
755
+ }
730
756
  }
731
757
  }
758
+ @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
732
759
  }
733
- @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
734
760
  }
735
- }
761
+ } # end of sash form
736
762
  }
737
763
  }
738
764
 
@@ -758,7 +784,7 @@ module Glimmer
758
784
  project_dir.ignore_paths ||= ['packages', 'tmp']
759
785
  open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
760
786
  open_file_paths2 = @config[:open_file_paths2]
761
- self.split_orientation = swt(@config[:split_orientation] || :horizontal) rescue swt(:horizontal)
787
+ self.split_orientation = (swt(@config[:split_orientation]) rescue swt(:horizontal)) if @config[:split_orientation]
762
788
  if @progress_bar_shell.nil?
763
789
  @progress_bar_shell = shell(body_root, :title) {
764
790
  text 'Gladiator'
@@ -835,16 +861,17 @@ module Glimmer
835
861
  end
836
862
 
837
863
  def save_config
838
- return unless @loaded_config
864
+ return if !@loaded_config || body_root.disposed?
839
865
  child = project_dir.selected_child
840
866
  return if child.nil?
841
867
  tab_folder1 = @tab_folder1 || @current_tab_folder
842
868
  tab_folder2 = @tab_folder2
843
869
  open_file_paths1 = tab_folder1&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
844
870
  open_file_paths2 = tab_folder2&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
871
+ split_orientation_value = split_orientation == swt(:horizontal) ? 'horizontal' : (split_orientation == swt(:vertical) ? 'vertical' : nil)
845
872
  @config = {
846
873
  selected_child_path: child.path,
847
- split_orientation: split_orientation == swt(:horizontal) ? 'horizontal' : 'vertical',
874
+ split_orientation: split_orientation_value,
848
875
  caret_position: child.caret_position,
849
876
  top_pixel: child.top_pixel,
850
877
  shell_width: swt_widget&.getBounds&.width,
@@ -860,23 +887,70 @@ module Glimmer
860
887
  rescue => e
861
888
  puts e.full_message
862
889
  end
890
+
891
+ def navigate_to_next_tab_folder
892
+ if tab_folder2
893
+ self.maximized_pane = false
894
+ if current_tab_folder == tab_folder1
895
+ self.current_tab_folder = tab_folder2
896
+ else
897
+ self.current_tab_folder = tab_folder1
898
+ end
899
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
900
+ self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
901
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
902
+ current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
903
+ end
904
+ end
863
905
 
864
- def close_tab_folder
906
+ def navigate_to_previous_tab_folder
907
+ if tab_folder2
908
+ self.maximized_pane = false
909
+ if current_tab_folder == tab_folder2
910
+ self.current_tab_folder = tab_folder1
911
+ else
912
+ self.current_tab_folder = tab_folder2
913
+ end
914
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
915
+ self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
916
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
917
+ current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
918
+ end
919
+ end
920
+
921
+ def close_all_tabs(closing_tab_folder = nil)
922
+ closing_tab_folder ||= current_tab_folder
923
+ closing_tab_folder.swt_widget.getItems.each do |tab_item|
924
+ project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
925
+ tab_item.getData('proxy')&.dispose
926
+ end
927
+ close_tab_folder(closing_tab_folder)
928
+ if self.current_tab_item.nil?
929
+ filter_text.swt_widget.selectAll
930
+ filter_text.swt_widget.setFocus
931
+ end
932
+ end
933
+
934
+ def close_tab_folder(closing_tab_folder = nil, single_tab: false)
935
+ closing_tab_folder ||= current_tab_folder
865
936
  if @tab_folder2 && !selected_tab_item
866
- if @current_tab_folder == @tab_folder2
937
+ if closing_tab_folder == @tab_folder2
867
938
  @tab_folder2.swt_widget.dispose
868
- @current_tab_folder = @tab_folder1
939
+ self.current_tab_folder = @tab_folder1
869
940
  else
870
941
  @tab_folder1.swt_widget.dispose
871
- @current_tab_folder = @tab_folder1 = @tab_folder2
942
+ self.current_tab_folder = self.tab_folder1 = @tab_folder2
872
943
  end
873
- @tab_folder2 = nil
944
+ self.tab_folder2 = nil
945
+ body_root.pack_same_size
874
946
 
875
- @current_tab_item = @current_tab_folder.swt_widget.getData('selected_tab_item')
947
+ @current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
876
948
  @current_text_editor = @current_tab_item.swt_tab_item.getData('text_editor')
877
949
  project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
878
-
879
- body_root.pack_same_size
950
+ @current_text_editor&.text_widget&.setFocus
951
+ async_exec { @current_text_editor&.text_widget&.setFocus }
952
+ elsif !single_tab
953
+ self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
880
954
  end
881
955
  end
882
956
 
@@ -891,122 +965,18 @@ module Glimmer
891
965
  def other_tab_items
892
966
  @current_tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == project_dir.selected_child&.path }
893
967
  end
894
-
895
- def extract_tree_item_path(tree_item)
896
- return if tree_item.nil?
897
- if tree_item.getParentItem
898
- ::File.join(extract_tree_item_path(tree_item.getParentItem), tree_item.getText)
899
- else
900
- project_dir.path
901
- end
902
- end
903
-
904
- def select_tree_item
905
- return unless project_dir.selected_child&.name
906
- tree_items_to_select = @file_tree.depth_first_search { |ti| ti.getData.path == project_dir.selected_child.path }
907
- @file_tree.swt_widget.setSelection(tree_items_to_select)
908
- end
909
-
910
- def delete_tree_item(tree_item)
911
- return if tree_item.nil?
912
- file = tree_item.getData
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
927
- file.delete! # TODO consider supporting command undo/redo
928
- project_dir.refresh(async: false)
929
- parent_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == parent_path}.first
930
- @file_tree.swt_widget.showItem(parent_tree_item)
931
- parent_tree_item.setExpanded(true)
932
- rescue => e
933
- puts e.full_message
934
- end
935
-
936
- def add_new_directory_to_selected_tree_item
937
- project_dir.pause_refresh
938
- tree_item = @file_tree.swt_widget.getSelection.first
939
- directory_path = extract_tree_item_path(tree_item)
940
- return if directory_path.nil?
941
- if !::Dir.exist?(directory_path)
942
- tree_item = tree_item.getParentItem
943
- directory_path = ::File.dirname(directory_path)
944
- end
945
- new_directory_path = ::File.expand_path(::File.join(directory_path, 'new_directory'))
946
- FileUtils.mkdir_p(new_directory_path)
947
- project_dir.refresh(async: false, force: true)
948
- new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_directory_path}.first
949
- @file_tree.swt_widget.showItem(new_tree_item)
950
- rename_tree_item(new_tree_item)
951
- end
952
-
953
- def add_new_file_to_selected_tree_item
954
- project_dir.pause_refresh
955
- tree_item = @file_tree.swt_widget.getSelection.first
956
- directory_path = extract_tree_item_path(tree_item)
957
- if !::Dir.exist?(directory_path)
958
- tree_item = tree_item.getParentItem
959
- directory_path = ::File.dirname(directory_path)
960
- end
961
- new_file_path = ::File.expand_path(::File.join(directory_path, 'new_file'))
962
- FileUtils.touch(new_file_path)
963
- # TODO look into refreshing only the parent directory to avoid slowdown
964
- project_dir.refresh(async: false, force: true)
965
- new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_file_path}.first
966
- @file_tree.swt_widget.showItem(new_tree_item)
967
- rename_tree_item(new_tree_item, true)
968
+
969
+ def collapse_navigation_expand_bar_height
970
+ @navigation_expand_item_height = @navigation_expand_item.swt_expand_item.height if @navigation_expand_item.swt_expand_item.height > 0
971
+ @navigation_expand_item.swt_expand_item.height = 0
972
+ body_root.pack_same_size
973
+ async_exec { body_root.pack_same_size }
968
974
  end
969
975
 
970
- def rename_selected_tree_item
971
- project_dir.pause_refresh
972
- tree_item = @file_tree.swt_widget.getSelection.first
973
- rename_tree_item(tree_item)
974
- end
975
-
976
- def rename_tree_item(tree_item, new_file = false)
977
- original_file = tree_item.getData
978
- current_file = project_dir.selected_child_path == original_file.path
979
- found_tab_item = find_tab_item(original_file.path)
980
- found_text_editor = found_tab_item&.getData('text_editor')
981
- @file_tree.edit_tree_item(
982
- tree_item,
983
- after_write: -> (edited_tree_item) {
984
- file = edited_tree_item.getData
985
- file_path = file.path
986
- file.name
987
- if new_file
988
- project_dir.selected_child_path = file_path
989
- else
990
- found_text_editor&.file = file
991
- found_tab_item&.setData('file', file)
992
- found_tab_item&.setData('file_path', file.path)
993
- found_tab_item&.setText(file.name)
994
- body_root.pack_same_size
995
- if current_file
996
- project_dir.selected_child_path = file_path
997
- else
998
- selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
999
- end
1000
- async_exec {
1001
- @file_tree.swt_widget.showItem(edited_tree_item)
1002
- }
1003
- end
1004
- project_dir.resume_refresh
1005
- },
1006
- after_cancel: -> {
1007
- project_dir.resume_refresh
1008
- }
1009
- )
976
+ def expand_navigation_expand_bar_height
977
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height || 140
978
+ body_root.pack_same_size
979
+ async_exec { body_root.pack_same_size }
1010
980
  end
1011
981
 
1012
982
  def extract_char(event)
@@ -1044,37 +1014,59 @@ module Glimmer
1044
1014
  }
1045
1015
  end
1046
1016
 
1017
+ def display_about_dialog
1018
+ dialog {
1019
+ grid_layout(2, false) {
1020
+ margin_width 15
1021
+ margin_height 15
1022
+ }
1023
+
1024
+ background :white
1025
+ image ICON
1026
+ text 'About'
1027
+
1028
+ label {
1029
+ layout_data :center, :center, false, false
1030
+ background :white
1031
+ image ICON, height: 260
1032
+ }
1033
+ label {
1034
+ layout_data :fill, :fill, true, true
1035
+ background :white
1036
+ text "Gladiator v#{VERSION}\n\n#{LICENSE}\n\nGladiator icon made by Freepik from www.flaticon.com"
1037
+ }
1038
+ }.open
1039
+ end
1040
+
1047
1041
  def handle_display_shortcut(key_event)
1048
1042
  if key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'f'
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 {
1043
+ find_action = lambda do
1055
1044
  if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
1056
1045
  find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
1057
1046
  end
1058
1047
  find_text.swt_widget.selectAll
1059
1048
  find_text.swt_widget.setFocus
1060
- }
1049
+ end
1050
+ if @navigation_expand_item.swt_expand_item.get_expanded
1051
+ find_action.call
1052
+ else
1053
+ @navigation_expand_item.swt_expand_item.set_expanded true
1054
+ async_exec {
1055
+ body_root.pack_same_size
1056
+ find_action.call
1057
+ }
1058
+ end
1061
1059
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
1062
1060
  Clipboard.copy(project_dir.selected_child.path)
1063
1061
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
1064
1062
  project_dir.selected_child.find_previous
1065
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'p'
1066
- open_project
1067
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 's'
1068
- project_dir.selected_child_path = '' # scratchpad
1063
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
1064
+ self.maximized_pane = false
1065
+ old_split_orientation = self.split_orientation
1066
+ self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
1067
+ @tab_folder_sash_form.weights = [1, 1] if old_split_orientation.nil?
1069
1068
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'w'
1070
- current_tab_folder.swt_widget.getItems.each do |tab_item|
1071
- project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
1072
- tab_item.getData('proxy')&.dispose
1073
- end
1074
- close_tab_folder
1075
- self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
1076
- filter_text.swt_widget.selectAll
1077
- filter_text.swt_widget.setFocus
1069
+ close_all_tabs
1078
1070
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :alt) && extract_char(key_event) == 'w'
1079
1071
  other_tab_items.each do |tab_item|
1080
1072
  project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
@@ -1084,17 +1076,22 @@ module Glimmer
1084
1076
  if selected_tab_item
1085
1077
  project_dir.selected_child_path_history.delete(project_dir.selected_child.path)
1086
1078
  selected_tab_item.getData('proxy')&.dispose
1087
- close_tab_folder
1079
+ close_tab_folder(single_tab: true)
1080
+ # if self.current_tab_item.nil?
1081
+ # filter_text.swt_widget.selectAll
1082
+ # filter_text.swt_widget.setFocus
1083
+ # else
1084
+ # current_text_editor&.text_widget&.setFocus
1085
+ # end
1088
1086
  if selected_tab_item.nil?
1089
1087
  self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
1090
1088
  filter_text.swt_widget.selectAll
1091
1089
  filter_text.swt_widget.setFocus
1092
1090
  else
1093
1091
  current_text_editor&.text_widget&.setFocus
1092
+ # async_exec { current_text_editor&.text_widget&.setFocus }
1094
1093
  end
1095
1094
  end
1096
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
1097
- self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
1098
1095
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
1099
1096
  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
1100
1097
  current_text_editor&.text_widget&.setFocus
@@ -1102,27 +1099,9 @@ module Glimmer
1102
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
1103
1100
  current_text_editor&.text_widget&.setFocus
1104
1101
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == ']'
1105
- if tab_folder2
1106
- if current_tab_folder == tab_folder1
1107
- self.current_tab_folder = tab_folder2
1108
- else
1109
- self.current_tab_folder = tab_folder1
1110
- end
1111
- self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
1112
- self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
1113
- current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
1114
- end
1102
+ navigate_to_next_tab_folder
1115
1103
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == '['
1116
- if tab_folder2
1117
- if current_tab_folder == tab_folder2
1118
- self.current_tab_folder = tab_folder1
1119
- else
1120
- self.current_tab_folder = tab_folder2
1121
- end
1122
- self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
1123
- self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
1124
- current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
1125
- end
1104
+ navigate_to_previous_tab_folder
1126
1105
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '1'
1127
1106
  current_tab_folder.swt_widget.setSelection(0) if current_tab_folder.swt_widget.getItemCount >= 1
1128
1107
  current_text_editor&.text_widget&.setFocus
@@ -1168,6 +1147,7 @@ module Glimmer
1168
1147
  line_number_text.swt_widget.setFocus
1169
1148
  end
1170
1149
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'r'
1150
+ self.maximized_editor = false
1171
1151
  unless @file_lookup_expand_item.swt_expand_item.get_expanded
1172
1152
  @file_lookup_expand_item.swt_expand_item.set_expanded true
1173
1153
  @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
@@ -1176,13 +1156,14 @@ module Glimmer
1176
1156
  filter_text.swt_widget.selectAll
1177
1157
  filter_text.swt_widget.setFocus
1178
1158
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 't'
1159
+ self.maximized_editor = false
1179
1160
  unless @file_explorer_expand_item.swt_expand_item.get_expanded
1180
1161
  @file_explorer_expand_item.swt_expand_item.set_expanded true
1181
1162
  @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
1182
1163
  @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
1183
1164
  end
1184
- select_tree_item unless rename_in_progress
1185
- file_tree.swt_widget.setFocus
1165
+ @file_explorer_tree.select_tree_item
1166
+ @file_explorer_tree.swt_widget.setFocus
1186
1167
  elsif key_event.keyCode == swt(:esc)
1187
1168
  if current_text_editor
1188
1169
  project_dir.selected_child_path = current_text_editor.file.path