glimmer-cs-gladiator 0.6.1 → 0.7.1

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.
@@ -18,10 +18,14 @@ module Glimmer
18
18
  APP_ROOT = ::File.expand_path('../../../..', __FILE__)
19
19
  # TODO make sure COMMAND_KEY doesn't clash on Linux/Windows for CMD+CTRL shortcuts
20
20
  COMMAND_KEY = OS.mac? ? :command : :ctrl
21
+ VERSION = ::File.read(::File.join(APP_ROOT, 'VERSION')).to_s.strip
22
+ LICENSE = ::File.read(::File.join(APP_ROOT, 'LICENSE.txt')).to_s.strip
23
+ ICON = ::File.expand_path(::File.join(APP_ROOT, 'images', 'glimmer-cs-gladiator-logo.png'))
21
24
 
22
25
  class << self
23
26
  attr_accessor :drag_and_drop
24
27
  attr_accessor :drag
28
+ attr_accessor :startup
25
29
  end
26
30
 
27
31
  ## Add options like the following to configure CustomShell by outside consumers
@@ -38,7 +42,7 @@ module Glimmer
38
42
  def split_orientation=(value)
39
43
  @split_orientation = value
40
44
  save_config
41
- if @loaded_config && !split_pane?
45
+ if @loaded_config && !split_pane? && !value.nil?
42
46
  Gladiator.drag = true
43
47
  child_path = project_dir.selected_child_path
44
48
  project_dir.selected_child = nil
@@ -52,9 +56,11 @@ module Glimmer
52
56
  pane_count = @tab_folder_sash_form&.children&.size
53
57
  pane_count && pane_count > 1
54
58
  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
59
+
60
+ attr_reader :find_text, :filter_text, :rename_in_progress, :line_number_text, :file_tree, :split_orientation
61
+ attr_accessor :current_tab_item, :current_tab_folder, :current_text_editor, :tab_folder1, :tab_folder2, :maximized_pane, :maximized_editor
62
+ alias maximized_pane? maximized_pane
63
+ alias maximized_editor? maximized_editor
58
64
 
59
65
  ## Uncomment before_body block to pre-initialize variables to use in body
60
66
  #
@@ -62,17 +68,25 @@ module Glimmer
62
68
  before_body {
63
69
  # TODO consider doing loading project files after displaying the GUI instead of holding it up before
64
70
  project_dir #pre-initialize directory
65
- at_exit do
71
+ TOPLEVEL_BINDING.receiver.send(:at_exit) do
66
72
  project_dir.selected_child&.write_raw_dirty_content
67
73
  end
68
74
  Display.setAppName('Gladiator')
69
75
  # make sure the display events are only hooked once if multiple gladiators are created
70
76
  unless defined?(@@display)
71
77
  @@display = display {
78
+ # TODO look into why a weird java dialog comes up on about (maybe a non-issue once packaged)
79
+ on_about {
80
+ display_about_dialog
81
+ }
72
82
  on_swt_keydown { |key_event|
73
83
  focused_gladiator = display.focus_control.shell&.get_data('custom_shell')
74
84
  focused_gladiator.handle_display_shortcut(key_event) if !focused_gladiator.nil? && key_event.widget.shell == focused_gladiator&.swt_widget
75
85
  }
86
+ on_swt_Close {
87
+ save_config
88
+ project_dir.selected_child&.write_dirty_content
89
+ }
76
90
  }
77
91
  end
78
92
 
@@ -88,23 +102,24 @@ module Glimmer
88
102
  #
89
103
  after_body {
90
104
  observe(project_dir, 'children') do
91
- select_tree_item unless @rename_in_progress
105
+ select_tree_item unless @rename_in_progress || Gladiator.startup
92
106
  end
93
107
  observe(project_dir, 'selected_child') do |selected_file|
94
108
  if selected_file
95
109
  if Gladiator.drag && !@tab_folder2
96
- @tab_folder1 = @current_tab_folder
110
+ self.tab_folder1 = current_tab_folder
97
111
  @tab_folder_sash_form.content {
98
- @current_tab_folder = @tab_folder2 = tab_folder
112
+ self.current_tab_folder = self.tab_folder2 = tab_folder {}
99
113
  @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
100
114
  }
115
+ body_root.pack_same_size
101
116
  end
102
- select_tree_item unless @rename_in_progress
117
+ select_tree_item unless @rename_in_progress || Gladiator.startup
103
118
  found_tab_item = selected_tab_item
104
119
  if found_tab_item
105
120
  @current_tab_folder.swt_widget.setSelection(found_tab_item)
106
121
  @current_tab_item = found_tab_item.getData('proxy')
107
- @current_text_editor = found_tab_item.getData('text_editor')
122
+ @current_text_editor = found_tab_item.getData('text_editor') unless found_tab_item.getData('text_editor').nil?
108
123
  @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
109
124
  elsif selected_file
110
125
  @current_tab_folder.content {
@@ -114,37 +129,42 @@ module Glimmer
114
129
  margin_width 0
115
130
  margin_height 0
116
131
  }
117
- @current_text_editor = the_text_editor = text_editor(project_dir: project_dir, file: selected_file)
118
- @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
119
- @current_text_editor.text_proxy.content {
120
- on_focus_gained {
121
- tab_folder = the_text_editor.swt_widget.getParent.getParent
122
- @current_tab_folder = tab_folder.getData('proxy')
123
- @current_tab_item = the_tab_item
124
- @current_text_editor = the_text_editor
125
- @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
126
- @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
127
- project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
132
+ tab_folder = nil
133
+ the_text_editor = nil
134
+ the_tab_item.content {
135
+ @current_text_editor = the_text_editor = text_editor(project_dir: project_dir, file: selected_file)
136
+ @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
137
+ the_tab_item.swt_tab_item.setData('text_editor', @current_text_editor)
138
+ @current_text_editor.text_proxy.content {
139
+ on_focus_gained {
140
+ tab_folder = the_text_editor.swt_widget.getParent.getParent
141
+ self.current_tab_folder = tab_folder.getData('proxy')
142
+ @current_tab_item = the_tab_item
143
+ @current_text_editor = the_text_editor
144
+ @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
145
+ @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
146
+ project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
147
+ }
128
148
  }
129
149
  }
150
+
130
151
  on_swt_show {
131
152
  @current_tab_item = the_tab_item
132
153
  @current_text_editor = the_text_editor
133
- @current_tab_folder = @current_tab_item.swt_widget.getParent.getData('proxy')
154
+ self.current_tab_folder = @current_tab_item.swt_widget.getParent.getData('proxy')
134
155
  @current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
135
156
  @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
136
157
  project_dir.selected_child = selected_file
137
- async_exec {
138
- @current_text_editor&.text_widget&.setFocus
139
- }
158
+ @current_text_editor&.text_widget&.setFocus
140
159
  }
141
160
  on_widget_disposed {
142
- the_tab_item.swt_tab_item.get_data('file').close
161
+ project_dir.selected_child&.write_dirty_content
162
+ tab_item_file = the_tab_item.swt_tab_item.get_data('file')
163
+ tab_item_file.close unless [@tab_folder1, @tab_folder2].compact.map(&:items).flatten(1).detect {|ti| ti.get_data('file') == tab_item_file}
143
164
  }
144
165
  }
145
166
  @current_tab_item.swt_tab_item.setData('file_path', selected_file.path)
146
167
  @current_tab_item.swt_tab_item.setData('file', selected_file)
147
- @current_tab_item.swt_tab_item.setData('text_editor', @current_text_editor)
148
168
  @current_tab_item.swt_tab_item.setData('proxy', @current_tab_item)
149
169
  }
150
170
  @current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
@@ -153,6 +173,22 @@ module Glimmer
153
173
  @current_text_editor&.text_widget&.setFocus
154
174
  end
155
175
  end
176
+ observe(self, 'maximized_pane') do
177
+ if tab_folder2
178
+ @tab_folder_sash_form.maximized_control = (current_tab_folder.swt_widget if maximized_pane?)
179
+ end
180
+ end
181
+ observe(self, 'maximized_editor') do
182
+ @file_area_and_editor_area_sash_form.maximized_control = (@editor_area_composite.swt_widget if maximized_editor?)
183
+ if !maximized_editor?
184
+ expand_navigation_expand_bar_height
185
+ else
186
+ collapse_navigation_expand_bar_height
187
+ end
188
+ @navigation_expand_item.swt_expand_item.set_expanded !maximized_editor?
189
+ body_root.pack_same_size
190
+ async_exec { body_root.pack_same_size }
191
+ end
156
192
  observe(project_dir, 'selected_child') do
157
193
  save_config
158
194
  end
@@ -170,19 +206,30 @@ module Glimmer
170
206
  #
171
207
  body {
172
208
  shell {
173
- grid_layout(2, false)
174
-
175
209
  text "Gladiator - #{::File.expand_path(project_dir.path)}"
176
210
  minimum_size 520, 250
177
211
  size 1440, 900
212
+ image ICON
178
213
 
179
214
  on_swt_show {
180
215
  swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
181
216
  swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
182
217
  @loaded_config = true
183
218
  }
184
- on_swt_close {
219
+
220
+ on_shell_closed {
221
+ save_config
185
222
  project_dir.selected_child&.write_dirty_content
223
+ if @tab_folder2
224
+ current_tab_folder.swt_widget.getItems.each do |tab_item|
225
+ tab_item.getData('proxy')&.dispose
226
+ end
227
+ close_tab_folder
228
+ end
229
+ current_tab_folder.swt_widget.getItems.each do |tab_item|
230
+ tab_item.getData('proxy')&.dispose
231
+ end
232
+ body_root.close unless current_tab_folder.swt_widget.getItems.empty?
186
233
  }
187
234
  on_widget_disposed {
188
235
  project_dir.selected_child&.write_dirty_content
@@ -194,46 +241,109 @@ module Glimmer
194
241
  save_config
195
242
  }
196
243
  on_shell_deactivated {
197
- @current_text_editor&.file&.write_dirty_content
244
+ project_dir.selected_child&.write_dirty_content
198
245
  }
199
246
 
247
+ if OS.mac?
248
+ display.swt_display.system_menu.items.find {|mi| mi.id == swt(:id_quit)}.add_selection_listener {
249
+ save_config
250
+ project_dir.selected_child&.write_dirty_content
251
+ display.swt_display.shells.each(&:close)
252
+ }
253
+ end
254
+
200
255
  menu_bar {
201
256
  menu {
202
257
  text '&File'
203
258
 
204
259
  menu_item {
205
260
  text 'New &Scratchpad'
261
+ accelerator COMMAND_KEY, :shift, :s
206
262
  on_widget_selected {
207
- begin
208
- project_dir.selected_child_path = ''
209
- rescue => e
210
- puts e.full_message
211
- end
263
+ project_dir.selected_child_path = ''
212
264
  }
213
265
  }
214
- menu_item(:separator)
215
266
  menu_item {
216
267
  text 'Open &Project...'
268
+ accelerator COMMAND_KEY, :o
217
269
  on_widget_selected {
218
270
  open_project
219
271
  }
220
272
  }
273
+ menu_item(:separator)
274
+ menu_item {
275
+ text '&Quit Project'
276
+ accelerator COMMAND_KEY, :alt, :q
277
+ on_widget_selected {
278
+ save_config
279
+ project_dir.selected_child&.write_dirty_content
280
+ body_root.close
281
+ }
282
+ }
221
283
  }
222
284
  menu {
223
285
  text '&View'
224
286
  menu {
225
- text '&Split'
226
- menu_item(:radio) {
227
- text '&Horizontal'
228
- selection bind(self, :split_orientation,
229
- on_read: ->(o) { split_pane? && o == swt(:horizontal)},
230
- on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical) })
287
+ text '&Split Pane'
288
+ menu { |menu_proxy|
289
+ text '&Orientation'
290
+ menu_item(:radio) {
291
+ text '&Horizontal'
292
+ selection bind(self, :split_orientation,
293
+ on_read: ->(o) { split_pane? && o == swt(:horizontal) },
294
+ on_write: ->(b) { b.nil? ? nil : (b ? swt(:horizontal) : swt(:vertical)) })
295
+ }
296
+ menu_item(:radio) {
297
+ text '&Vertical'
298
+ selection bind(self, :split_orientation,
299
+ on_read: ->(o) { split_pane? && o == swt(:vertical) },
300
+ on_write: ->(b) { b.nil? ? nil : (b ? swt(:vertical) : swt(:horizontal)) })
301
+ }
302
+ }
303
+ menu_item(:check) {
304
+ text '&Maximize Pane'
305
+ enabled bind(self, :tab_folder2)
306
+ accelerator COMMAND_KEY, :shift, :m
307
+ selection bind(self, :maximized_pane)
308
+ }
309
+ menu_item {
310
+ text 'Reset &Panes'
311
+ enabled bind(self, :tab_folder2)
312
+ accelerator COMMAND_KEY, :shift, :p
313
+ on_widget_selected {
314
+ if tab_folder2
315
+ self.maximized_pane = false
316
+ @tab_folder_sash_form.weights = [1, 1]
317
+ end
318
+ }
231
319
  }
232
- menu_item(:radio) {
233
- text '&Vertical'
234
- selection bind(self, :split_orientation,
235
- on_read: ->(o) { split_pane? && o == swt(:vertical)},
236
- on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal) })
320
+ menu_item {
321
+ text '&Unsplit'
322
+ enabled bind(self, :tab_folder2)
323
+ accelerator COMMAND_KEY, :shift, :u
324
+ on_widget_selected {
325
+ if tab_folder2
326
+ self.maximized_pane = false
327
+ navigate_to_next_tab_folder if current_tab_folder != tab_folder2
328
+ close_all_tabs(tab_folder2)
329
+ self.split_orientation = nil
330
+ body_root.pack_same_size
331
+ end
332
+ }
333
+ }
334
+ }
335
+ menu_item(:check) {
336
+ text '&Maximize Editor'
337
+ accelerator COMMAND_KEY, :ctrl, :m
338
+ selection bind(self, :maximized_editor)
339
+ }
340
+ menu_item {
341
+ text '&Reset All'
342
+ accelerator COMMAND_KEY, :ctrl, :r
343
+ on_widget_selected {
344
+ self.maximized_editor = false
345
+ @file_area_and_editor_area_sash_form.weights = [1, 5]
346
+ @side_bar_sash_form.weights = [1, 1]
237
347
  }
238
348
  }
239
349
  }
@@ -254,468 +364,480 @@ module Glimmer
254
364
  # }
255
365
  menu_item {
256
366
  text '&Ruby'
367
+ accelerator COMMAND_KEY, :shift, :r
368
+ on_widget_selected {
369
+ begin
370
+ project_dir.selected_child.run
371
+ rescue Exception => e
372
+ dialog {
373
+ text 'Run - Ruby - Error Encountered!'
374
+ label {
375
+ text e.full_message
376
+ }
377
+ }.open
378
+ end
379
+ }
380
+ }
381
+ }
382
+ menu {
383
+ text '&Help'
384
+ menu_item {
385
+ text '&About'
386
+ accelerator COMMAND_KEY, :shift, :a
257
387
  on_widget_selected {
258
- project_dir.selected_child.run
388
+ display_about_dialog
259
389
  }
260
390
  }
261
391
  }
262
392
  }
393
+
394
+ @file_area_and_editor_area_sash_form = sash_form(:horizontal) {
395
+ weights 1, 5
263
396
 
264
- composite {
265
- grid_layout(1, false) {
266
- margin_width 0
267
- margin_height 0
268
- }
269
-
270
- layout_data(:fill, :fill, false, true) {
271
- width_hint 300
272
- }
273
- @side_bar_sash_form = sash_form(:vertical) {
274
- layout_data(:fill, :fill, true, true)
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
397
+ composite {
398
+ grid_layout(1, false) {
399
+ margin_width 0
400
+ margin_height 0
280
401
  }
281
402
 
282
- @file_lookup_expand_bar = expand_bar {
283
- layout_data :fill, :fill, true, true
284
- font height: 17, style: :bold
285
- foreground @default_foreground
403
+ @side_bar_sash_form = sash_form(:vertical) {
404
+ layout_data(:fill, :fill, true, true)
405
+ sash_width 4
286
406
 
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
407
+ resize_expand_items = lambda { |event=nil|
408
+ @file_lookup_expand_item&.swt_expand_item&.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
409
+ @file_explorer_expand_item&.swt_expand_item&.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
289
410
  }
290
411
 
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
412
+ @file_lookup_expand_bar = expand_bar {
413
+ layout_data :fill, :fill, true, true
414
+ font height: 17, style: :bold
415
+ foreground @default_foreground
416
+
417
+ on_swt_show {
418
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_bar.size.y - @file_lookup_expand_item.swt_expand_item.header_height
297
419
  }
298
- text 'File Lookup'
299
- height display.bounds.height
300
420
 
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
421
+ on_swt_Resize(&resize_expand_items)
422
+
423
+ @file_lookup_expand_item = expand_item {
424
+ grid_layout {
425
+ margin_width 0
426
+ margin_height 0
312
427
  }
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
428
+ text 'File Lookup'
429
+ height display.bounds.height
430
+
431
+ @filter_text = text {
432
+ layout_data :fill, :center, true, false
433
+ text bind(project_dir, 'filter')
434
+ on_key_pressed { |key_event|
435
+ if key_event.keyCode == swt(:tab) ||
436
+ key_event.keyCode == swt(:cr) ||
437
+ key_event.keyCode == swt(:arrow_up) ||
438
+ key_event.keyCode == swt(:arrow_down)
439
+ @file_lookup_list.swt_widget.select(0) if @file_lookup_list.swt_widget.getSelectionIndex() == -1
440
+ @file_lookup_list.swt_widget.setFocus
441
+ end
442
+ }
322
443
  }
323
- on_key_pressed { |key_event|
324
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
444
+
445
+ @file_lookup_list = list(:border, :h_scroll, :v_scroll) {
446
+ layout_data :fill, :fill, true, true
447
+ #visible bind(self, 'project_dir.filter') {|f| !!f}
448
+ selection bind(project_dir, :filtered_path)
449
+ foreground @default_foreground
450
+ on_mouse_up {
325
451
  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
452
+ }
453
+ on_key_pressed { |key_event|
454
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
455
+ project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
456
+ @current_text_editor&.text_widget&.setFocus
457
+ end
458
+ }
459
+ drag_source(DND::DROP_COPY) {
460
+ transfer [TextTransfer.getInstance].to_java(Transfer)
461
+ on_drag_set_data { |event|
462
+ Gladiator.drag = true
463
+ list = event.widget.getControl
464
+ event.data = list.getSelection.first
465
+ }
335
466
  }
336
467
  }
337
468
  }
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
-
355
- }
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
469
+
470
+ on_item_collapsed { |event|
471
+ if @file_explorer_expand_item.swt_expand_item.get_expanded
472
+ @file_lookup_expand_item_height = @file_lookup_expand_item.swt_expand_item.height
473
+ @file_lookup_expand_item.swt_expand_item.height = 0
474
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
475
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
476
+ @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]
477
+ end
478
+ }
361
479
 
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
480
+ on_item_expanded {
481
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
482
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
483
+ }
484
+
364
485
  }
365
486
 
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
487
+ @file_explorer_expand_bar = expand_bar {
488
+ layout_data :fill, :fill, true, true
489
+ font height: 17, style: :bold
490
+ foreground @default_foreground
491
+
492
+ on_swt_show {
493
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_bar.size.y - @file_explorer_expand_item.swt_expand_item.header_height
372
494
  }
373
- text 'File Explorer'
374
- height display.bounds.height
375
495
 
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
- }
496
+ on_swt_Resize(&resize_expand_items)
497
+
498
+ @file_explorer_expand_item = expand_item {
499
+ grid_layout {
500
+ margin_width 0
501
+ margin_height 0
389
502
  }
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)
503
+ text 'File Explorer'
504
+ height display.bounds.height
505
+
506
+ @file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
507
+ layout_data :fill, :fill, true, true
508
+ #visible bind(self, 'project_dir.filter') {|f| !f}
509
+ items bind(self, :project_dir), tree_properties(children: :children, text: :name)
510
+ foreground @default_foreground
511
+ drag_source(DND::DROP_COPY) {
512
+ transfer [TextTransfer.getInstance].to_java(Transfer)
513
+ on_drag_set_data { |event|
514
+ Gladiator.drag = true
515
+ tree = event.widget.getControl
516
+ tree_item = tree.getSelection.first
517
+ event.data = tree_item.getData.path
395
518
  }
396
519
  }
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)
520
+ menu {
521
+ @open_menu_item = menu_item {
522
+ text 'Open'
523
+ on_widget_selected {
524
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
525
+ }
403
526
  }
404
- }
405
- menu_item {
406
- text 'Refresh'
407
- on_widget_selected {
408
- project_dir.refresh
527
+ menu_item(:separator)
528
+ menu_item {
529
+ text 'Delete'
530
+ on_widget_selected {
531
+ tree_item = @file_tree.swt_widget.getSelection.first
532
+ delete_tree_item(tree_item)
533
+ }
409
534
  }
410
- }
411
- menu_item {
412
- text 'Rename'
413
- on_widget_selected {
414
- rename_selected_tree_item
535
+ menu_item {
536
+ text 'Refresh'
537
+ on_widget_selected {
538
+ project_dir.refresh
539
+ }
415
540
  }
416
- }
417
- menu_item {
418
- text 'New Directory'
419
- on_widget_selected {
420
- add_new_directory_to_selected_tree_item
541
+ menu_item {
542
+ text 'Rename'
543
+ on_widget_selected {
544
+ rename_selected_tree_item
545
+ }
421
546
  }
422
- }
423
- menu_item {
424
- text 'New File'
425
- on_widget_selected {
426
- add_new_file_to_selected_tree_item
547
+ menu_item {
548
+ text 'New Directory'
549
+ on_widget_selected {
550
+ add_new_directory_to_selected_tree_item
551
+ }
552
+ }
553
+ menu_item {
554
+ text 'New File'
555
+ on_widget_selected {
556
+ add_new_file_to_selected_tree_item
557
+ }
427
558
  }
428
559
  }
429
- }
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
433
- }
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
441
- }
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
560
+ on_swt_menudetect { |event|
561
+ path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
562
+ @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
563
+ }
564
+ on_mouse_up {
565
+ if Gladiator.drag_and_drop
566
+ Gladiator.drag_and_drop = false
567
+ else
568
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
569
+ @current_text_editor&.text_widget&.setFocus
570
+ end
571
+ }
572
+ on_key_pressed { |key_event|
573
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
574
+ project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
575
+ @current_text_editor&.text_widget&.setFocus
576
+ end
577
+ }
578
+ on_paint_control {
579
+ root_item = @file_tree.swt_widget.getItems.first
580
+ if root_item && !root_item.getExpanded
581
+ root_item.setExpanded(true)
582
+ end
583
+ }
453
584
  }
454
585
  }
455
- }
586
+
587
+ on_item_collapsed { |event|
588
+ if @file_lookup_expand_item.swt_expand_item.get_expanded
589
+ @file_explorer_expand_item_height = @file_explorer_expand_item.swt_expand_item.height
590
+ @file_explorer_expand_item.swt_expand_item.height = 0
591
+ @file_explorer_expand_bar_height = @file_explorer_expand_bar.swt_widget.size.y
592
+ @file_lookup_expand_bar_height = @file_lookup_expand_bar.swt_widget.size.y
593
+ @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]
594
+ end
595
+ }
456
596
 
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]
464
- end
465
- }
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]
597
+ on_item_expanded {
598
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
599
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
600
+ }
601
+
470
602
  }
471
-
603
+
472
604
  }
473
-
474
- }
475
-
476
- # TODO see if you could replace some of this with Glimmer DSL/API syntax
477
- @file_tree_editor = TreeEditor.new(@file_tree.swt_widget);
478
- @file_tree_editor.horizontalAlignment = swt(:left);
479
- @file_tree_editor.grabHorizontal = true;
480
- @file_tree_editor.minimumHeight = 20;
481
-
482
- }
483
-
484
- composite {
485
- grid_layout(1, false) {
486
- margin_width 0
487
- margin_height 0
605
+
606
+ # TODO see if you could replace some of this with Glimmer DSL/API syntax
607
+ @file_tree_editor = TreeEditor.new(@file_tree.swt_widget);
608
+ @file_tree_editor.horizontalAlignment = swt(:left);
609
+ @file_tree_editor.grabHorizontal = true;
610
+ @file_tree_editor.minimumHeight = 20;
611
+
488
612
  }
489
- layout_data :fill, :fill, true, true
490
613
 
491
- @navigation_expand_bar = expand_bar {
492
- layout_data :fill, :top, true, false
493
- font height: 17, style: :bold
494
- foreground @default_foreground
614
+ @editor_area_composite = composite {
615
+ grid_layout(1, false) {
616
+ margin_width 0
617
+ margin_height 0
618
+ }
495
619
 
496
- @navigation_expand_item = expand_item {
497
- text 'Navigation'
498
- height 115
499
-
500
- grid_layout(5, false) {
501
- margin_right 5
502
- }
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
512
- }
620
+ @navigation_expand_bar = expand_bar {
621
+ layout_data :fill, :top, true, false
622
+ font height: 17, style: :bold
623
+ foreground @default_foreground
624
+
625
+ @navigation_expand_item = expand_item {
626
+ text 'Navigation'
627
+ height 115
513
628
 
514
- @file_path_label = styled_text(:none) {
515
- layout_data(:fill, :center, true, false) {
516
- horizontal_span 2
629
+ grid_layout(5, false) {
630
+ margin_right 5
517
631
  }
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
632
+
633
+ stat_font = {name: 'Consolas', height: OS.mac? ? 15 : 12}
634
+
635
+ # row 1
636
+
637
+ label {
638
+ layout_data(:left, :center, false, false)
639
+ text 'File:'
640
+ foreground @default_foreground
525
641
  }
526
- on_focus_lost {
527
- @file_path_label.swt_widget.setSelection(0, 0)
642
+
643
+ @file_path_label = styled_text(:none) {
644
+ layout_data(:fill, :center, true, false) {
645
+ horizontal_span 2
646
+ }
647
+ background color(:widget_background)
648
+ foreground @default_foreground
649
+ editable false
650
+ caret nil
651
+ text bind(project_dir, 'selected_child.path')
652
+ on_mouse_up {
653
+ @file_path_label.swt_widget.selectAll
654
+ }
655
+ on_focus_lost {
656
+ @file_path_label.swt_widget.setSelection(0, 0)
657
+ }
528
658
  }
529
- }
530
-
531
- label {
532
- layout_data(:left, :center, false, false)
533
- text 'Caret Position:'
534
- foreground @default_foreground
535
- }
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
541
- }
542
-
543
- # row 2
544
-
545
- label {
546
- layout_data(:left, :center, false, false)
547
- text 'Line:'
548
- foreground @default_foreground
549
- }
550
- @line_number_text = text {
551
- layout_data(:fill, :center, true, false) {
552
- minimum_width 400
659
+
660
+ label {
661
+ layout_data(:left, :center, false, false)
662
+ text 'Caret Position:'
663
+ foreground @default_foreground
553
664
  }
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
665
+ label(:right) {
666
+ layout_data(:fill, :center, true, false)
667
+ text bind(project_dir, 'selected_child.caret_position')
668
+ foreground @default_foreground
669
+ font stat_font
561
670
  }
562
- on_verify_text { |event|
563
- event.doit = !event.text.match(/^\d*$/).to_a.empty?
671
+
672
+ # row 2
673
+
674
+ label {
675
+ layout_data(:left, :center, false, false)
676
+ text 'Line:'
677
+ foreground @default_foreground
564
678
  }
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
679
+ @line_number_text = text {
680
+ layout_data(:fill, :center, true, false) {
681
+ minimum_width 400
682
+ }
683
+ text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
684
+ foreground @default_foreground
685
+ font stat_font
686
+ on_key_pressed { |key_event|
687
+ if key_event.keyCode == swt(:cr)
688
+ @current_text_editor&.text_widget&.setFocus
689
+ end
690
+ }
691
+ on_verify_text { |event|
692
+ event.doit = !event.text.match(/^\d*$/).to_a.empty?
693
+ }
590
694
  }
591
- text bind(project_dir, 'selected_child.find_text')
592
- foreground @default_foreground
593
- font stat_font
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
599
- if key_event.keyCode == swt(:cr)
600
- project_dir.selected_child&.find_next
601
- end
695
+ label # filler
696
+
697
+ label {
698
+ layout_data(:left, :center, false, false)
699
+ text 'Line Position:'
700
+ foreground @default_foreground
602
701
  }
603
- }
604
- composite {
605
- layout_data(:left, :center, true, false)
606
- row_layout {
607
- margin_width 0
608
- margin_height 0
702
+ label(:right) {
703
+ layout_data(:fill, :center, true, false)
704
+ text bind(project_dir, 'selected_child.line_position')
705
+ foreground @default_foreground
706
+ font stat_font
609
707
  }
610
- button(:check) {
611
- selection bind(project_dir, 'selected_child.case_sensitive')
708
+
709
+ # row 3
710
+
711
+ label {
712
+ layout_data(:left, :center, false, false)
713
+ text 'Find:'
714
+ foreground @default_foreground
715
+ }
716
+ @find_text = text {
717
+ layout_data(:fill, :center, true, false) {
718
+ minimum_width 400
719
+ }
720
+ text bind(project_dir, 'selected_child.find_text')
721
+ foreground @default_foreground
722
+ font stat_font
612
723
  on_key_pressed { |key_event|
724
+ if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
725
+ project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
726
+ project_dir.selected_child&.find_next
727
+ end
613
728
  if key_event.keyCode == swt(:cr)
614
729
  project_dir.selected_child&.find_next
615
730
  end
616
731
  }
617
732
  }
733
+ composite {
734
+ layout_data(:left, :center, true, false)
735
+ row_layout {
736
+ margin_width 0
737
+ margin_height 0
738
+ }
739
+ button(:check) {
740
+ selection bind(project_dir, 'selected_child.case_sensitive')
741
+ on_key_pressed { |key_event|
742
+ if key_event.keyCode == swt(:cr)
743
+ project_dir.selected_child&.find_next
744
+ end
745
+ }
746
+ }
747
+ label {
748
+ text 'Case-sensitive'
749
+ foreground @default_foreground
750
+ }
751
+ }
752
+
618
753
  label {
619
- text 'Case-sensitive'
754
+ layout_data(:left, :center, false, false)
755
+ text 'Selection Count:'
620
756
  foreground @default_foreground
621
757
  }
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
-
638
- label {
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
758
+ label(:right) {
759
+ layout_data(:fill, :center, true, false)
760
+ text bind(project_dir, 'selected_child.selection_count')
761
+ foreground @default_foreground
762
+ font stat_font
646
763
  }
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
764
+
765
+ # row 4
766
+
767
+ label {
768
+ layout_data(:left, :center, false, false)
769
+ text 'Replace:'
770
+ foreground @default_foreground
652
771
  }
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!)
772
+ @replace_text = text {
773
+ layout_data(:fill, :center, true, false) {
774
+ minimum_width 400
775
+ }
776
+ text bind(project_dir, 'selected_child.replace_text')
777
+ foreground @default_foreground
778
+ font stat_font
779
+ on_focus_gained {
780
+ project_dir.selected_child&.ensure_find_next
781
+ }
782
+ on_key_pressed { |key_event|
783
+ if key_event.keyCode == swt(:cr)
784
+ if project_dir.selected_child
785
+ Command.do(project_dir.selected_child, :replace_next!)
786
+ end
657
787
  end
658
- end
788
+ }
789
+ }
790
+ label # filler
791
+ label {
792
+ layout_data(:left, :center, false, false)
793
+ text 'Top Pixel:'
794
+ foreground @default_foreground
795
+ }
796
+ label(:right) {
797
+ layout_data(:fill, :center, true, false)
798
+ text bind(project_dir, 'selected_child.top_pixel')
799
+ foreground @default_foreground
800
+ font stat_font
659
801
  }
660
802
  }
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
803
+
804
+ on_item_collapsed {
805
+ collapse_navigation_expand_bar_height
672
806
  }
673
- }
674
807
 
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
808
+ on_item_expanded {
809
+ expand_navigation_expand_bar_height
680
810
  }
811
+
681
812
  }
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
813
+
814
+ @tab_folder_sash_form = sash_form {
815
+ layout_data(:fill, :fill, true, true) {
816
+ width_hint 768
817
+ height_hint 576
818
+ minimum_width 768
819
+ minimum_height 576
687
820
  }
688
- }
689
-
690
- }
691
-
692
- @tab_folder_sash_form = sash_form {
693
- layout_data(:fill, :fill, true, true) {
694
- width_hint 768
695
- height_hint 576
696
- minimum_width 768
697
- minimum_height 576
698
- }
699
- sash_width 10
700
- orientation bind(self, :split_orientation)
701
- @current_tab_folder = tab_folder {
702
- drag_source(DND::DROP_COPY) {
703
- transfer [TextTransfer.getInstance].to_java(Transfer)
704
- event_data = nil
705
- on_drag_start {|event|
706
- Gladiator.drag = true
707
- tab_folder = event.widget.getControl
708
- tab_item = tab_folder.getItem(Point.new(event.x, event.y))
709
- event_data = tab_item.getData('file_path')
710
- }
711
- on_drag_set_data { |event|
712
- event.data = event_data
821
+ orientation bind(self, :split_orientation) {|value| async_exec { body_root.pack_same_size}; value}
822
+ self.current_tab_folder = self.tab_folder1 = tab_folder {
823
+ drag_source(DND::DROP_COPY) {
824
+ transfer [TextTransfer.getInstance].to_java(Transfer)
825
+ event_data = nil
826
+ on_drag_start {|event|
827
+ Gladiator.drag = true
828
+ tab_folder = event.widget.getControl
829
+ tab_item = tab_folder.getItem(Point.new(event.x, event.y))
830
+ event_data = tab_item.getData('file_path')
831
+ }
832
+ on_drag_set_data { |event|
833
+ event.data = event_data
834
+ }
713
835
  }
714
836
  }
837
+ @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
715
838
  }
716
- @current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
717
839
  }
718
- }
840
+ } # end of sash form
719
841
  }
720
842
  }
721
843
 
@@ -741,7 +863,7 @@ module Glimmer
741
863
  project_dir.ignore_paths ||= ['packages', 'tmp']
742
864
  open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
743
865
  open_file_paths2 = @config[:open_file_paths2]
744
- self.split_orientation = swt(@config[:split_orientation] || :horizontal) rescue swt(:horizontal)
866
+ self.split_orientation = (swt(@config[:split_orientation]) rescue swt(:horizontal)) if @config[:split_orientation]
745
867
  if @progress_bar_shell.nil?
746
868
  @progress_bar_shell = shell(body_root, :title) {
747
869
  text 'Gladiator'
@@ -763,53 +885,72 @@ module Glimmer
763
885
  open_file_paths1.to_a.each do |file_path|
764
886
  async_exec {
765
887
  Gladiator.drag = false
888
+ Gladiator.startup = file_path != open_file_paths1.to_a[-1]
766
889
  project_dir.selected_child_path = file_path
767
890
  }
768
891
  end
769
892
  # TODO replace the next line with one that selects the visible tab
770
893
  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]
894
+ # TODO check why this is not working
895
+ if open_file_paths1.to_a.include?(@config[:selected_child_path])
896
+ Gladiator.drag = false
897
+ Gladiator.startup = false
898
+ project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
899
+ 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]
900
+ project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
901
+ end
775
902
  }
776
903
  async_exec {
777
904
  open_file_paths2.to_a.each do |file_path|
778
905
  async_exec {
779
906
  Gladiator.drag = true
907
+ Gladiator.startup = file_path != open_file_paths2.to_a[-1]
780
908
  project_dir.selected_child_path = file_path
781
909
  }
782
910
  end
783
911
  # TODO replace the next line with one that selects the visible tab
784
912
  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]
913
+ # TODO check why this is not working
914
+ if open_file_paths2.to_a.include?(@config[:selected_child_path])
915
+ Gladiator.drag = true
916
+ Gladiator.startup = false
917
+ project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
918
+ 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]
919
+ project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
920
+ end
789
921
  }
790
922
  async_exec {
791
923
  Gladiator.drag = false
792
- @progress_bar_shell.close
924
+ @progress_bar_shell&.close
793
925
  @progress_bar_shell = nil
794
926
  @loaded_config = true
795
927
  }
796
928
  }
929
+ async_exec {
930
+ Thread.new {
931
+ all_files = open_file_paths1.to_a + open_file_paths2.to_a
932
+ all_files.each do |file|
933
+ project_dir.find_child_file(file)&.dirty_content
934
+ end
935
+ }
936
+ }
797
937
  else
798
938
  @loaded_config = true
799
939
  end
800
940
  end
801
941
 
802
942
  def save_config
803
- return unless @loaded_config
943
+ return if !@loaded_config || body_root.disposed?
804
944
  child = project_dir.selected_child
805
945
  return if child.nil?
806
946
  tab_folder1 = @tab_folder1 || @current_tab_folder
807
947
  tab_folder2 = @tab_folder2
808
948
  open_file_paths1 = tab_folder1&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
809
949
  open_file_paths2 = tab_folder2&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
950
+ split_orientation_value = split_orientation == swt(:horizontal) ? 'horizontal' : (split_orientation == swt(:vertical) ? 'vertical' : nil)
810
951
  @config = {
811
952
  selected_child_path: child.path,
812
- split_orientation: split_orientation == swt(:horizontal) ? 'horizontal' : 'vertical',
953
+ split_orientation: split_orientation_value,
813
954
  caret_position: child.caret_position,
814
955
  top_pixel: child.top_pixel,
815
956
  shell_width: swt_widget&.getBounds&.width,
@@ -825,23 +966,70 @@ module Glimmer
825
966
  rescue => e
826
967
  puts e.full_message
827
968
  end
969
+
970
+ def navigate_to_next_tab_folder
971
+ if tab_folder2
972
+ self.maximized_pane = false
973
+ if current_tab_folder == tab_folder1
974
+ self.current_tab_folder = tab_folder2
975
+ else
976
+ self.current_tab_folder = tab_folder1
977
+ end
978
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
979
+ self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
980
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
981
+ current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
982
+ end
983
+ end
828
984
 
829
- def close_tab_folder
985
+ def navigate_to_previous_tab_folder
986
+ if tab_folder2
987
+ self.maximized_pane = false
988
+ if current_tab_folder == tab_folder2
989
+ self.current_tab_folder = tab_folder1
990
+ else
991
+ self.current_tab_folder = tab_folder2
992
+ end
993
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
994
+ self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
995
+ self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
996
+ current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
997
+ end
998
+ end
999
+
1000
+ def close_all_tabs(closing_tab_folder = nil)
1001
+ closing_tab_folder ||= current_tab_folder
1002
+ closing_tab_folder.swt_widget.getItems.each do |tab_item|
1003
+ project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
1004
+ tab_item.getData('proxy')&.dispose
1005
+ end
1006
+ close_tab_folder(closing_tab_folder)
1007
+ if self.current_tab_item.nil?
1008
+ filter_text.swt_widget.selectAll
1009
+ filter_text.swt_widget.setFocus
1010
+ end
1011
+ end
1012
+
1013
+ def close_tab_folder(closing_tab_folder = nil, single_tab: false)
1014
+ closing_tab_folder ||= current_tab_folder
830
1015
  if @tab_folder2 && !selected_tab_item
831
- if @current_tab_folder == @tab_folder2
1016
+ if closing_tab_folder == @tab_folder2
832
1017
  @tab_folder2.swt_widget.dispose
833
- @current_tab_folder = @tab_folder1
1018
+ self.current_tab_folder = @tab_folder1
834
1019
  else
835
1020
  @tab_folder1.swt_widget.dispose
836
- @current_tab_folder = @tab_folder1 = @tab_folder2
1021
+ self.current_tab_folder = self.tab_folder1 = @tab_folder2
837
1022
  end
838
- @tab_folder2 = nil
1023
+ self.tab_folder2 = nil
1024
+ body_root.pack_same_size
839
1025
 
840
- @current_tab_item = @current_tab_folder.swt_widget.getData('selected_tab_item')
1026
+ @current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
841
1027
  @current_text_editor = @current_tab_item.swt_tab_item.getData('text_editor')
842
1028
  project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
843
-
844
- body_root.pack_same_size
1029
+ @current_text_editor&.text_widget&.setFocus
1030
+ async_exec { @current_text_editor&.text_widget&.setFocus }
1031
+ elsif !single_tab
1032
+ self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
845
1033
  end
846
1034
  end
847
1035
 
@@ -856,6 +1044,19 @@ module Glimmer
856
1044
  def other_tab_items
857
1045
  @current_tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == project_dir.selected_child&.path }
858
1046
  end
1047
+
1048
+ def collapse_navigation_expand_bar_height
1049
+ @navigation_expand_item_height = @navigation_expand_item.swt_expand_item.height if @navigation_expand_item.swt_expand_item.height > 0
1050
+ @navigation_expand_item.swt_expand_item.height = 0
1051
+ body_root.pack_same_size
1052
+ async_exec { body_root.pack_same_size }
1053
+ end
1054
+
1055
+ def expand_navigation_expand_bar_height
1056
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height || 140
1057
+ body_root.pack_same_size
1058
+ async_exec { body_root.pack_same_size }
1059
+ end
859
1060
 
860
1061
  def extract_tree_item_path(tree_item)
861
1062
  return if tree_item.nil?
@@ -949,22 +1150,24 @@ module Glimmer
949
1150
  file = edited_tree_item.getData
950
1151
  file_path = file.path
951
1152
  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
1153
+ if ::File.file?(file_path)
1154
+ if new_file
961
1155
  project_dir.selected_child_path = file_path
962
1156
  else
963
- selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
1157
+ found_text_editor&.file = file
1158
+ found_tab_item&.setData('file', file)
1159
+ found_tab_item&.setData('file_path', file.path)
1160
+ found_tab_item&.setText(file.name)
1161
+ body_root.pack_same_size
1162
+ if current_file
1163
+ project_dir.selected_child_path = file_path
1164
+ else
1165
+ selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
1166
+ end
1167
+ async_exec {
1168
+ @file_tree.swt_widget.showItem(edited_tree_item)
1169
+ }
964
1170
  end
965
- async_exec {
966
- @file_tree.swt_widget.showItem(edited_tree_item)
967
- }
968
1171
  end
969
1172
  project_dir.resume_refresh
970
1173
  },
@@ -982,6 +1185,7 @@ module Glimmer
982
1185
 
983
1186
  def open_project
984
1187
  selected_directory = directory_dialog.open
1188
+ return if selected_directory.nil?
985
1189
  @progress_bar_shell = shell(body_root, :title) {
986
1190
  text 'Gladiator'
987
1191
  fill_layout(:vertical) {
@@ -1008,30 +1212,59 @@ module Glimmer
1008
1212
  }
1009
1213
  end
1010
1214
 
1215
+ def display_about_dialog
1216
+ dialog {
1217
+ grid_layout(2, false) {
1218
+ margin_width 15
1219
+ margin_height 15
1220
+ }
1221
+
1222
+ background :white
1223
+ image ICON
1224
+ text 'About'
1225
+
1226
+ label {
1227
+ layout_data :center, :center, false, false
1228
+ background :white
1229
+ image ICON, height: 260
1230
+ }
1231
+ label {
1232
+ layout_data :fill, :fill, true, true
1233
+ background :white
1234
+ text "Gladiator v#{VERSION}\n\n#{LICENSE}\n\nGladiator icon made by Freepik from www.flaticon.com"
1235
+ }
1236
+ }.open
1237
+ end
1238
+
1011
1239
  def handle_display_shortcut(key_event)
1012
1240
  if key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'f'
1013
- if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
1014
- find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
1241
+ find_action = lambda do
1242
+ if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
1243
+ find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
1244
+ end
1245
+ find_text.swt_widget.selectAll
1246
+ find_text.swt_widget.setFocus
1247
+ end
1248
+ if @navigation_expand_item.swt_expand_item.get_expanded
1249
+ find_action.call
1250
+ else
1251
+ @navigation_expand_item.swt_expand_item.set_expanded true
1252
+ async_exec {
1253
+ body_root.pack_same_size
1254
+ find_action.call
1255
+ }
1015
1256
  end
1016
- find_text.swt_widget.selectAll
1017
- find_text.swt_widget.setFocus
1018
1257
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
1019
1258
  Clipboard.copy(project_dir.selected_child.path)
1020
1259
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
1021
1260
  project_dir.selected_child.find_previous
1022
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'p'
1023
- open_project
1024
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 's'
1025
- project_dir.selected_child_path = '' # scratchpad
1261
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
1262
+ self.maximized_pane = false
1263
+ old_split_orientation = self.split_orientation
1264
+ self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
1265
+ @tab_folder_sash_form.weights = [1, 1] if old_split_orientation.nil?
1026
1266
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'w'
1027
- current_tab_folder.swt_widget.getItems.each do |tab_item|
1028
- project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
1029
- tab_item.getData('proxy')&.dispose
1030
- end
1031
- close_tab_folder
1032
- self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
1033
- filter_text.swt_widget.selectAll
1034
- filter_text.swt_widget.setFocus
1267
+ close_all_tabs
1035
1268
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :alt) && extract_char(key_event) == 'w'
1036
1269
  other_tab_items.each do |tab_item|
1037
1270
  project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
@@ -1041,17 +1274,22 @@ module Glimmer
1041
1274
  if selected_tab_item
1042
1275
  project_dir.selected_child_path_history.delete(project_dir.selected_child.path)
1043
1276
  selected_tab_item.getData('proxy')&.dispose
1044
- close_tab_folder
1277
+ close_tab_folder(single_tab: true)
1278
+ # if self.current_tab_item.nil?
1279
+ # filter_text.swt_widget.selectAll
1280
+ # filter_text.swt_widget.setFocus
1281
+ # else
1282
+ # current_text_editor&.text_widget&.setFocus
1283
+ # end
1045
1284
  if selected_tab_item.nil?
1046
1285
  self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
1047
1286
  filter_text.swt_widget.selectAll
1048
1287
  filter_text.swt_widget.setFocus
1049
1288
  else
1050
1289
  current_text_editor&.text_widget&.setFocus
1290
+ # async_exec { current_text_editor&.text_widget&.setFocus }
1051
1291
  end
1052
1292
  end
1053
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
1054
- self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
1055
1293
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
1056
1294
  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
1057
1295
  current_text_editor&.text_widget&.setFocus
@@ -1059,27 +1297,9 @@ module Glimmer
1059
1297
  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
1060
1298
  current_text_editor&.text_widget&.setFocus
1061
1299
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == ']'
1062
- if tab_folder2
1063
- if current_tab_folder == tab_folder1
1064
- self.current_tab_folder = tab_folder2
1065
- else
1066
- self.current_tab_folder = tab_folder1
1067
- end
1068
- self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
1069
- self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
1070
- current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
1071
- end
1300
+ navigate_to_next_tab_folder
1072
1301
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == '['
1073
- if tab_folder2
1074
- if current_tab_folder == tab_folder2
1075
- self.current_tab_folder = tab_folder1
1076
- else
1077
- self.current_tab_folder = tab_folder2
1078
- end
1079
- self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
1080
- self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
1081
- current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
1082
- end
1302
+ navigate_to_previous_tab_folder
1083
1303
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '1'
1084
1304
  current_tab_folder.swt_widget.setSelection(0) if current_tab_folder.swt_widget.getItemCount >= 1
1085
1305
  current_text_editor&.text_widget&.setFocus
@@ -1110,12 +1330,36 @@ module Glimmer
1110
1330
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'g'
1111
1331
  project_dir.selected_child.find_next
1112
1332
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'l'
1113
- line_number_text.swt_widget.selectAll
1114
- line_number_text.swt_widget.setFocus
1333
+ unless @navigation_expand_item.swt_expand_item.get_expanded
1334
+ @navigation_expand_item.swt_expand_item.set_expanded true
1335
+ @navigation_expand_item.swt_expand_item.height = @navigation_expand_item_height if @navigation_expand_item_height
1336
+ async_exec {
1337
+ body_root.pack_same_size
1338
+ }
1339
+ async_exec {
1340
+ line_number_text.swt_widget.selectAll
1341
+ line_number_text.swt_widget.setFocus
1342
+ }
1343
+ else
1344
+ line_number_text.swt_widget.selectAll
1345
+ line_number_text.swt_widget.setFocus
1346
+ end
1115
1347
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'r'
1348
+ self.maximized_editor = false
1349
+ unless @file_lookup_expand_item.swt_expand_item.get_expanded
1350
+ @file_lookup_expand_item.swt_expand_item.set_expanded true
1351
+ @file_lookup_expand_item.swt_expand_item.height = @file_lookup_expand_item_height if @file_lookup_expand_item_height
1352
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
1353
+ end
1116
1354
  filter_text.swt_widget.selectAll
1117
1355
  filter_text.swt_widget.setFocus
1118
1356
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 't'
1357
+ self.maximized_editor = false
1358
+ unless @file_explorer_expand_item.swt_expand_item.get_expanded
1359
+ @file_explorer_expand_item.swt_expand_item.set_expanded true
1360
+ @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
1361
+ @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
1362
+ end
1119
1363
  select_tree_item unless rename_in_progress
1120
1364
  file_tree.swt_widget.setFocus
1121
1365
  elsif key_event.keyCode == swt(:esc)