glimmer-cs-gladiator 0.4.1 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -21
- data/VERSION +1 -1
- data/bin/gladiator_runner.rb +2 -1
- data/lib/glimmer-cs-gladiator.rb +1 -1
- data/lib/models/glimmer/gladiator/command.rb +4 -4
- data/lib/models/glimmer/gladiator/dir.rb +78 -42
- data/lib/models/glimmer/gladiator/file.rb +180 -102
- data/lib/views/glimmer/gladiator.rb +465 -297
- data/lib/views/glimmer/gladiator/text_editor.rb +34 -27
- metadata +6 -6
@@ -14,222 +14,145 @@ module Glimmer
|
|
14
14
|
# Gladiator (Glimmer Editor)
|
15
15
|
class Gladiator
|
16
16
|
include Glimmer::UI::CustomShell
|
17
|
-
|
18
|
-
APP_ROOT = ::File.expand_path('../../../..', __FILE__)
|
17
|
+
|
18
|
+
APP_ROOT = ::File.expand_path('../../../..', __FILE__)
|
19
|
+
# TODO make sure COMMAND_KEY doesn't clash on Linux/Windows for CMD+CTRL shortcuts
|
19
20
|
COMMAND_KEY = OS.mac? ? :command : :ctrl
|
20
21
|
|
21
22
|
class << self
|
22
23
|
attr_accessor :drag_and_drop
|
23
24
|
attr_accessor :drag
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
## Add options like the following to configure CustomShell by outside consumers
|
27
28
|
#
|
28
29
|
# options :title, :background_color
|
29
30
|
# option :width, 320
|
30
31
|
# option :height, 240
|
32
|
+
option :project_dir_path
|
31
33
|
|
32
|
-
|
34
|
+
def project_dir
|
35
|
+
@project_dir ||= Dir.new(project_dir_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def split_orientation=(value)
|
39
|
+
@split_orientation = value
|
40
|
+
save_config
|
41
|
+
if @loaded_config && !split_pane?
|
42
|
+
Gladiator.drag = true
|
43
|
+
child_path = project_dir.selected_child_path
|
44
|
+
project_dir.selected_child = nil
|
45
|
+
project_dir.selected_child_path = child_path
|
46
|
+
Gladiator.drag = false
|
47
|
+
end
|
48
|
+
@split_orientation
|
49
|
+
end
|
33
50
|
|
51
|
+
def split_pane?
|
52
|
+
pane_count = @tab_folder_sash_form&.children&.size
|
53
|
+
pane_count && pane_count > 1
|
54
|
+
end
|
55
|
+
|
56
|
+
attr_reader :find_text, :tab_folder1, :tab_folder2, :filter_text, :rename_in_progress, :line_number_text, :file_tree, :split_orientation
|
57
|
+
attr_accessor :current_tab_item, :current_tab_folder, :current_text_editor
|
58
|
+
|
34
59
|
## Uncomment before_body block to pre-initialize variables to use in body
|
35
60
|
#
|
36
61
|
#
|
37
62
|
before_body {
|
63
|
+
# TODO consider doing loading project files after displaying the GUI instead of holding it up before
|
64
|
+
project_dir #pre-initialize directory
|
65
|
+
at_exit do
|
66
|
+
project_dir.selected_child&.write_raw_dirty_content
|
67
|
+
end
|
38
68
|
Display.setAppName('Gladiator')
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@find_text.swt_widget.setFocus
|
47
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
|
48
|
-
Clipboard.copy(Dir.local_dir.selected_child.path)
|
49
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
|
50
|
-
Dir.local_dir.selected_child.find_previous
|
51
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'w'
|
52
|
-
@tab_folder.swt_widget.getItems.each do |tab_item|
|
53
|
-
Dir.local_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
|
54
|
-
tab_item.getData('proxy')&.dispose
|
55
|
-
end
|
56
|
-
close_tab_folder
|
57
|
-
@tab_item = @text_editor = Dir.local_dir.selected_child = nil
|
58
|
-
@filter_text.swt_widget.selectAll
|
59
|
-
@filter_text.swt_widget.setFocus
|
60
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :alt) && extract_char(key_event) == 'w'
|
61
|
-
other_tab_items.each do |tab_item|
|
62
|
-
Dir.local_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
|
63
|
-
tab_item.getData('proxy')&.dispose
|
64
|
-
end
|
65
|
-
elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'w'
|
66
|
-
if selected_tab_item
|
67
|
-
Dir.local_dir.selected_child_path_history.delete(Dir.local_dir.selected_child.path)
|
68
|
-
selected_tab_item.getData('proxy')&.dispose
|
69
|
-
close_tab_folder
|
70
|
-
if selected_tab_item.nil?
|
71
|
-
@tab_item = @text_editor = Dir.local_dir.selected_child = nil
|
72
|
-
@filter_text.swt_widget.selectAll
|
73
|
-
@filter_text.swt_widget.setFocus
|
74
|
-
else
|
75
|
-
@text_editor&.text_widget&.setFocus
|
76
|
-
end
|
77
|
-
end
|
78
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
|
79
|
-
self.split_orientation = split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
|
80
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
|
81
|
-
@tab_folder.swt_widget.setSelection((@tab_folder.swt_widget.getSelectionIndex() + 1) % @tab_folder.swt_widget.getItemCount) if @tab_folder.swt_widget.getItemCount > 0
|
82
|
-
@text_editor&.text_widget&.setFocus
|
83
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == '['
|
84
|
-
@tab_folder.swt_widget.setSelection((@tab_folder.swt_widget.getSelectionIndex() - 1) % @tab_folder.swt_widget.getItemCount) if @tab_folder.swt_widget.getItemCount > 0
|
85
|
-
@text_editor&.text_widget&.setFocus
|
86
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == ']'
|
87
|
-
if @tab_folder2
|
88
|
-
if @tab_folder == @tab_folder1
|
89
|
-
@tab_folder = @tab_folder2
|
90
|
-
else
|
91
|
-
@tab_folder = @tab_folder1
|
92
|
-
end
|
93
|
-
@tab_item = @tab_folder.swt_widget.getData('selected_tab_item')
|
94
|
-
Dir.local_dir.selected_child = @tab_item&.swt_tab_item&.getData('file')
|
95
|
-
@tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
|
96
|
-
end
|
97
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == '['
|
98
|
-
if @tab_folder2
|
99
|
-
if @tab_folder == @tab_folder2
|
100
|
-
@tab_folder = @tab_folder1
|
101
|
-
else
|
102
|
-
@tab_folder = @tab_folder2
|
103
|
-
end
|
104
|
-
@tab_item = @tab_folder.swt_widget.getData('selected_tab_item')
|
105
|
-
Dir.local_dir.selected_child = @tab_item&.swt_tab_item&.getData('file')
|
106
|
-
@tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
|
107
|
-
end
|
108
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '1'
|
109
|
-
@tab_folder.swt_widget.setSelection(0) if @tab_folder.swt_widget.getItemCount >= 1
|
110
|
-
@text_editor&.text_widget&.setFocus
|
111
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '2'
|
112
|
-
@tab_folder.swt_widget.setSelection(1) if @tab_folder.swt_widget.getItemCount >= 2
|
113
|
-
@text_editor&.text_widget&.setFocus
|
114
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '3'
|
115
|
-
@tab_folder.swt_widget.setSelection(2) if @tab_folder.swt_widget.getItemCount >= 3
|
116
|
-
@text_editor&.text_widget&.setFocus
|
117
|
-
@tab_folder.swt_widget.setSelection(3) if @tab_folder.swt_widget.getItemCount >= 4
|
118
|
-
@text_editor&.text_widget&.setFocus
|
119
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '5'
|
120
|
-
@tab_folder.swt_widget.setSelection(4) if @tab_folder.swt_widget.getItemCount >= 5
|
121
|
-
@text_editor&.text_widget&.setFocus
|
122
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '4'
|
123
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '6'
|
124
|
-
@tab_folder.swt_widget.setSelection(5) if @tab_folder.swt_widget.getItemCount >= 6
|
125
|
-
@text_editor&.text_widget&.setFocus
|
126
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '7'
|
127
|
-
@tab_folder.swt_widget.setSelection(6) if @tab_folder.swt_widget.getItemCount >= 7
|
128
|
-
@text_editor&.text_widget&.setFocus
|
129
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '8'
|
130
|
-
@tab_folder.swt_widget.setSelection(7) if @tab_folder.swt_widget.getItemCount >= 8
|
131
|
-
@text_editor&.text_widget&.setFocus
|
132
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '9'
|
133
|
-
@tab_folder.swt_widget.setSelection(@tab_folder.swt_widget.getItemCount - 1) if @tab_folder.swt_widget.getItemCount > 0
|
134
|
-
@text_editor&.text_widget&.setFocus
|
135
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'g'
|
136
|
-
Dir.local_dir.selected_child.find_next
|
137
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'l'
|
138
|
-
@line_number_text.swt_widget.selectAll
|
139
|
-
@line_number_text.swt_widget.setFocus
|
140
|
-
elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'r'
|
141
|
-
@filter_text.swt_widget.selectAll
|
142
|
-
@filter_text.swt_widget.setFocus
|
143
|
-
elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 't'
|
144
|
-
select_tree_item unless @rename_in_progress
|
145
|
-
@tree.swt_widget.setFocus
|
146
|
-
elsif key_event.keyCode == swt(:esc)
|
147
|
-
if @text_editor
|
148
|
-
Dir.local_dir.selected_child_path = @text_editor.file.path
|
149
|
-
@text_editor&.text_widget&.setFocus
|
150
|
-
end
|
151
|
-
end
|
69
|
+
# make sure the display events are only hooked once if multiple gladiators are created
|
70
|
+
unless defined?(@@display)
|
71
|
+
@@display = display {
|
72
|
+
on_swt_keydown { |key_event|
|
73
|
+
focused_gladiator = display.focus_control.shell&.get_data('custom_shell')
|
74
|
+
focused_gladiator.handle_display_shortcut(key_event) if !focused_gladiator.nil? && key_event.widget.shell == focused_gladiator&.swt_widget
|
75
|
+
}
|
152
76
|
}
|
153
|
-
|
77
|
+
end
|
154
78
|
|
155
79
|
@split_orientation = swt(:horizontal)
|
156
|
-
|
157
|
-
@config_file_path = ::File.join(local_dir, '.gladiator')
|
80
|
+
@config_file_path = ::File.join(project_dir.path, '.gladiator')
|
158
81
|
@config = {}
|
159
82
|
load_config_ignore_paths
|
160
|
-
#
|
83
|
+
# project_dir.all_children # pre-caches children
|
161
84
|
}
|
162
85
|
|
163
86
|
## Uncomment after_body block to setup observers for widgets in body
|
164
87
|
#
|
165
88
|
after_body {
|
166
|
-
observe(
|
89
|
+
observe(project_dir, 'children') do
|
167
90
|
select_tree_item unless @rename_in_progress
|
168
91
|
end
|
169
|
-
observe(
|
92
|
+
observe(project_dir, 'selected_child') do |selected_file|
|
170
93
|
if selected_file
|
171
94
|
if Gladiator.drag && !@tab_folder2
|
172
|
-
@tab_folder1 = @
|
95
|
+
@tab_folder1 = @current_tab_folder
|
173
96
|
@tab_folder_sash_form.content {
|
174
|
-
@
|
175
|
-
@
|
97
|
+
@current_tab_folder = @tab_folder2 = tab_folder
|
98
|
+
@current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
|
176
99
|
}
|
177
100
|
end
|
178
101
|
select_tree_item unless @rename_in_progress
|
179
102
|
found_tab_item = selected_tab_item
|
180
103
|
if found_tab_item
|
181
|
-
@
|
182
|
-
@
|
183
|
-
@
|
184
|
-
@
|
104
|
+
@current_tab_folder.swt_widget.setSelection(found_tab_item)
|
105
|
+
@current_tab_item = found_tab_item.getData('proxy')
|
106
|
+
@current_text_editor = found_tab_item.getData('text_editor')
|
107
|
+
@current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
|
185
108
|
elsif selected_file
|
186
|
-
@
|
187
|
-
@
|
109
|
+
@current_tab_folder.content {
|
110
|
+
@current_tab_item = tab_item { |the_tab_item|
|
188
111
|
text selected_file.name
|
189
112
|
fill_layout :horizontal
|
190
|
-
@
|
191
|
-
@
|
192
|
-
@
|
113
|
+
@current_text_editor = the_text_editor = text_editor(project_dir: project_dir, file: selected_file)
|
114
|
+
@current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
|
115
|
+
@current_text_editor.text_proxy.content {
|
193
116
|
on_focus_gained {
|
194
117
|
tab_folder = the_text_editor.swt_widget.getParent.getParent
|
195
|
-
@
|
196
|
-
@
|
197
|
-
@
|
198
|
-
@
|
199
|
-
@
|
200
|
-
|
118
|
+
@current_tab_folder = tab_folder.getData('proxy')
|
119
|
+
@current_tab_item = the_tab_item
|
120
|
+
@current_text_editor = the_text_editor
|
121
|
+
@current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
|
122
|
+
@current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
|
123
|
+
project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
|
201
124
|
}
|
202
125
|
}
|
203
126
|
on_swt_show {
|
204
|
-
@
|
205
|
-
@
|
206
|
-
@
|
207
|
-
@
|
208
|
-
@
|
209
|
-
|
127
|
+
@current_tab_item = the_tab_item
|
128
|
+
@current_text_editor = the_text_editor
|
129
|
+
@current_tab_folder = @current_tab_item.swt_widget.getParent.getData('proxy')
|
130
|
+
@current_tab_folder.swt_widget.setData('selected_tab_item', @current_tab_item)
|
131
|
+
@current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
|
132
|
+
project_dir.selected_child = selected_file
|
210
133
|
async_exec {
|
211
|
-
@
|
134
|
+
@current_text_editor&.text_widget&.setFocus
|
212
135
|
}
|
213
136
|
}
|
214
137
|
}
|
215
|
-
@
|
216
|
-
@
|
217
|
-
@
|
218
|
-
@
|
219
|
-
}
|
220
|
-
@
|
138
|
+
@current_tab_item.swt_tab_item.setData('file_path', selected_file.path)
|
139
|
+
@current_tab_item.swt_tab_item.setData('file', selected_file)
|
140
|
+
@current_tab_item.swt_tab_item.setData('text_editor', @current_text_editor)
|
141
|
+
@current_tab_item.swt_tab_item.setData('proxy', @current_tab_item)
|
142
|
+
}
|
143
|
+
@current_tab_folder.swt_widget.setSelection(@current_tab_item.swt_tab_item)
|
221
144
|
body_root.pack_same_size
|
222
145
|
end
|
223
|
-
@
|
146
|
+
@current_text_editor&.text_widget&.setFocus
|
224
147
|
end
|
225
148
|
end
|
226
|
-
observe(
|
149
|
+
observe(project_dir, 'selected_child') do
|
227
150
|
save_config
|
228
151
|
end
|
229
|
-
observe(
|
152
|
+
observe(project_dir, 'selected_child.caret_position') do
|
230
153
|
save_config
|
231
154
|
end
|
232
|
-
observe(
|
155
|
+
observe(project_dir, 'selected_child.top_pixel') do
|
233
156
|
save_config
|
234
157
|
end
|
235
158
|
load_config
|
@@ -240,20 +163,20 @@ module Glimmer
|
|
240
163
|
#
|
241
164
|
body {
|
242
165
|
shell {
|
243
|
-
text "Gladiator - #{::File.expand_path(
|
166
|
+
text "Gladiator - #{::File.expand_path(project_dir.path)}"
|
244
167
|
minimum_size 520, 250
|
245
|
-
size 1440, 900
|
168
|
+
size 1440, 900
|
246
169
|
grid_layout(2, false)
|
247
170
|
on_swt_show {
|
248
171
|
swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
|
249
|
-
swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
|
172
|
+
swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
|
250
173
|
@loaded_config = true
|
251
174
|
}
|
252
175
|
on_swt_close {
|
253
|
-
|
176
|
+
project_dir.selected_child&.write_dirty_content
|
254
177
|
}
|
255
178
|
on_widget_disposed {
|
256
|
-
|
179
|
+
project_dir.selected_child&.write_dirty_content
|
257
180
|
}
|
258
181
|
on_control_resized {
|
259
182
|
save_config
|
@@ -262,21 +185,46 @@ module Glimmer
|
|
262
185
|
save_config
|
263
186
|
}
|
264
187
|
on_shell_deactivated {
|
265
|
-
@
|
266
|
-
}
|
188
|
+
@current_text_editor&.file&.write_dirty_content
|
189
|
+
}
|
267
190
|
|
268
191
|
menu_bar {
|
192
|
+
menu {
|
193
|
+
text '&File'
|
194
|
+
|
195
|
+
menu_item {
|
196
|
+
text 'New &Scratchpad'
|
197
|
+
on_widget_selected {
|
198
|
+
begin
|
199
|
+
project_dir.selected_child_path = ''
|
200
|
+
rescue => e
|
201
|
+
puts e.full_message
|
202
|
+
end
|
203
|
+
}
|
204
|
+
}
|
205
|
+
menu_item(:separator)
|
206
|
+
menu_item {
|
207
|
+
text 'Open &Project...'
|
208
|
+
on_widget_selected {
|
209
|
+
open_project
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
269
213
|
menu {
|
270
214
|
text '&View'
|
271
215
|
menu {
|
272
216
|
text '&Split'
|
273
217
|
menu_item(:radio) {
|
274
218
|
text '&Horizontal'
|
275
|
-
selection bind(self, :split_orientation,
|
219
|
+
selection bind(self, :split_orientation,
|
220
|
+
on_read: ->(o) { split_pane? && o == swt(:horizontal)},
|
221
|
+
on_write: ->(b) { b ? swt(:horizontal) : swt(:vertical) })
|
276
222
|
}
|
277
223
|
menu_item(:radio) {
|
278
224
|
text '&Vertical'
|
279
|
-
selection bind(self, :split_orientation,
|
225
|
+
selection bind(self, :split_orientation,
|
226
|
+
on_read: ->(o) { split_pane? && o == swt(:vertical)},
|
227
|
+
on_write: ->(b) { b ? swt(:vertical) : swt(:horizontal) })
|
280
228
|
}
|
281
229
|
}
|
282
230
|
}
|
@@ -285,9 +233,9 @@ module Glimmer
|
|
285
233
|
# menu_item {
|
286
234
|
# text 'Launch Glimmer &App'
|
287
235
|
# on_widget_selected {
|
288
|
-
# parent_path =
|
236
|
+
# parent_path = project_dir.path
|
289
237
|
## current_directory_name = ::File.basename(parent_path)
|
290
|
-
## assumed_shell_script = ::File.join(parent_path, 'bin', current_directory_name)
|
238
|
+
## assumed_shell_script = ::File.join(parent_path, 'bin', current_directory_name)
|
291
239
|
## assumed_shell_script = ::Dir.glob(::File.join(parent_path, 'bin', '*')).detect {|f| ::File.file?(f) && !::File.read(f).include?('#!/usr/bin/env')} if !::File.exist?(assumed_shell_script)
|
292
240
|
## load assumed_shell_script
|
293
241
|
# FileUtils.cd(parent_path) do
|
@@ -296,9 +244,9 @@ module Glimmer
|
|
296
244
|
# }
|
297
245
|
# }
|
298
246
|
menu_item {
|
299
|
-
text '&
|
247
|
+
text '&Ruby'
|
300
248
|
on_widget_selected {
|
301
|
-
|
249
|
+
project_dir.selected_child.run
|
302
250
|
}
|
303
251
|
}
|
304
252
|
}
|
@@ -311,32 +259,30 @@ module Glimmer
|
|
311
259
|
}
|
312
260
|
@filter_text = text {
|
313
261
|
layout_data :fill, :center, true, false
|
314
|
-
text bind(
|
262
|
+
text bind(project_dir, 'filter')
|
315
263
|
on_key_pressed { |key_event|
|
316
|
-
if key_event.keyCode == swt(:tab) ||
|
317
|
-
key_event.keyCode == swt(:cr) ||
|
264
|
+
if key_event.keyCode == swt(:tab) ||
|
265
|
+
key_event.keyCode == swt(:cr) ||
|
318
266
|
key_event.keyCode == swt(:arrow_up) ||
|
319
267
|
key_event.keyCode == swt(:arrow_down)
|
320
268
|
@list.swt_widget.select(0) if @list.swt_widget.getSelectionIndex() == -1
|
321
269
|
@list.swt_widget.setFocus
|
322
270
|
end
|
323
|
-
}
|
324
|
-
}
|
325
|
-
composite {
|
326
|
-
fill_layout(:vertical) {
|
327
|
-
spacing 5
|
328
271
|
}
|
272
|
+
}
|
273
|
+
sash_form(:vertical) {
|
329
274
|
layout_data(:fill, :fill, true, true)
|
275
|
+
sash_width 4
|
330
276
|
@list = list(:border, :h_scroll, :v_scroll) {
|
331
|
-
#visible bind(
|
332
|
-
selection bind(
|
277
|
+
#visible bind(self, 'project_dir.filter') {|f| !!f}
|
278
|
+
selection bind(project_dir, :filtered_path)
|
333
279
|
on_mouse_up {
|
334
|
-
|
280
|
+
project_dir.selected_child_path = @list.swt_widget.getSelection.first
|
335
281
|
}
|
336
282
|
on_key_pressed { |key_event|
|
337
283
|
if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
|
338
|
-
|
339
|
-
@
|
284
|
+
project_dir.selected_child_path = @list.swt_widget.getSelection.first
|
285
|
+
@current_text_editor&.text_widget&.setFocus
|
340
286
|
end
|
341
287
|
}
|
342
288
|
drag_source(DND::DROP_COPY) {
|
@@ -346,11 +292,11 @@ module Glimmer
|
|
346
292
|
list = event.widget.getControl
|
347
293
|
event.data = list.getSelection.first
|
348
294
|
}
|
349
|
-
}
|
295
|
+
}
|
350
296
|
}
|
351
|
-
@
|
352
|
-
#visible bind(
|
353
|
-
items bind(
|
297
|
+
@file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
|
298
|
+
#visible bind(self, 'project_dir.filter') {|f| !f}
|
299
|
+
items bind(self, :project_dir), tree_properties(children: :children, text: :name)
|
354
300
|
drag_source(DND::DROP_COPY) {
|
355
301
|
transfer [TextTransfer.getInstance].to_java(Transfer)
|
356
302
|
on_drag_set_data { |event|
|
@@ -364,21 +310,21 @@ module Glimmer
|
|
364
310
|
@open_menu_item = menu_item {
|
365
311
|
text 'Open'
|
366
312
|
on_widget_selected {
|
367
|
-
|
313
|
+
project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
|
368
314
|
}
|
369
315
|
}
|
370
316
|
menu_item(:separator)
|
371
317
|
menu_item {
|
372
318
|
text 'Delete'
|
373
319
|
on_widget_selected {
|
374
|
-
tree_item = @
|
320
|
+
tree_item = @file_tree.swt_widget.getSelection.first
|
375
321
|
delete_tree_item(tree_item)
|
376
322
|
}
|
377
323
|
}
|
378
324
|
menu_item {
|
379
325
|
text 'Refresh'
|
380
326
|
on_widget_selected {
|
381
|
-
|
327
|
+
project_dir.refresh
|
382
328
|
}
|
383
329
|
}
|
384
330
|
menu_item {
|
@@ -401,25 +347,25 @@ module Glimmer
|
|
401
347
|
}
|
402
348
|
}
|
403
349
|
on_swt_menudetect { |event|
|
404
|
-
path = extract_tree_item_path(@
|
350
|
+
path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
|
405
351
|
@open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
|
406
352
|
}
|
407
353
|
on_mouse_up {
|
408
354
|
if Gladiator.drag_and_drop
|
409
355
|
Gladiator.drag_and_drop = false
|
410
356
|
else
|
411
|
-
|
412
|
-
@
|
357
|
+
project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
|
358
|
+
@current_text_editor&.text_widget&.setFocus
|
413
359
|
end
|
414
360
|
}
|
415
361
|
on_key_pressed { |key_event|
|
416
362
|
if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
|
417
|
-
|
418
|
-
@
|
363
|
+
project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
|
364
|
+
@current_text_editor&.text_widget&.setFocus
|
419
365
|
end
|
420
366
|
}
|
421
367
|
on_paint_control {
|
422
|
-
root_item = @
|
368
|
+
root_item = @file_tree.swt_widget.getItems.first
|
423
369
|
if root_item && !root_item.getExpanded
|
424
370
|
root_item.setExpanded(true)
|
425
371
|
end
|
@@ -427,10 +373,11 @@ module Glimmer
|
|
427
373
|
}
|
428
374
|
}
|
429
375
|
|
430
|
-
|
431
|
-
@
|
432
|
-
@
|
433
|
-
@
|
376
|
+
# TODO see if you could replace some of this with Glimmer DSL/API syntax
|
377
|
+
@file_tree_editor = TreeEditor.new(@file_tree.swt_widget);
|
378
|
+
@file_tree_editor.horizontalAlignment = swt(:left);
|
379
|
+
@file_tree_editor.grabHorizontal = true;
|
380
|
+
@file_tree_editor.minimumHeight = 20;
|
434
381
|
|
435
382
|
}
|
436
383
|
@editor_container = composite {
|
@@ -438,9 +385,9 @@ module Glimmer
|
|
438
385
|
layout_data :fill, :fill, true, true
|
439
386
|
composite {
|
440
387
|
grid_layout 3, false
|
441
|
-
|
388
|
+
|
442
389
|
# row 1
|
443
|
-
|
390
|
+
|
444
391
|
label {
|
445
392
|
text 'File:'
|
446
393
|
}
|
@@ -452,7 +399,7 @@ module Glimmer
|
|
452
399
|
background color(:widget_background)
|
453
400
|
editable false
|
454
401
|
caret nil
|
455
|
-
text bind(
|
402
|
+
text bind(project_dir, 'selected_child.path')
|
456
403
|
on_mouse_up {
|
457
404
|
@file_path_label.swt_widget.selectAll
|
458
405
|
}
|
@@ -460,9 +407,9 @@ module Glimmer
|
|
460
407
|
@file_path_label.swt_widget.setSelection(0, 0)
|
461
408
|
}
|
462
409
|
}
|
463
|
-
|
410
|
+
|
464
411
|
# row 2
|
465
|
-
|
412
|
+
|
466
413
|
label {
|
467
414
|
text 'Line:'
|
468
415
|
}
|
@@ -470,18 +417,18 @@ module Glimmer
|
|
470
417
|
layout_data(:fill, :fill, true, false) {
|
471
418
|
minimum_width 400
|
472
419
|
}
|
473
|
-
text bind(
|
420
|
+
text bind(project_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
|
474
421
|
on_key_pressed { |key_event|
|
475
422
|
if key_event.keyCode == swt(:cr)
|
476
|
-
@
|
423
|
+
@current_text_editor&.text_widget&.setFocus
|
477
424
|
end
|
478
425
|
}
|
479
426
|
on_verify_text { |event|
|
480
|
-
event.doit = !event.text.match(/^\d*$/).to_a.empty?
|
427
|
+
event.doit = !event.text.match(/^\d*$/).to_a.empty?
|
481
428
|
}
|
482
429
|
}
|
483
430
|
label
|
484
|
-
|
431
|
+
|
485
432
|
# row 3
|
486
433
|
|
487
434
|
label {
|
@@ -491,34 +438,34 @@ module Glimmer
|
|
491
438
|
layout_data(:fill, :center, true, false) {
|
492
439
|
minimum_width 400
|
493
440
|
}
|
494
|
-
text bind(
|
441
|
+
text bind(project_dir, 'selected_child.find_text')
|
495
442
|
on_key_pressed { |key_event|
|
496
443
|
if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
|
497
|
-
|
498
|
-
|
444
|
+
project_dir.selected_child.case_sensitive = !project_dir.selected_child.case_sensitive
|
445
|
+
project_dir.selected_child&.find_next
|
499
446
|
end
|
500
447
|
if key_event.keyCode == swt(:cr)
|
501
|
-
|
448
|
+
project_dir.selected_child&.find_next
|
502
449
|
end
|
503
450
|
}
|
504
451
|
}
|
505
452
|
composite {
|
506
453
|
row_layout
|
507
454
|
button(:check) {
|
508
|
-
selection bind(
|
455
|
+
selection bind(project_dir, 'selected_child.case_sensitive')
|
509
456
|
on_key_pressed { |key_event|
|
510
457
|
if key_event.keyCode == swt(:cr)
|
511
|
-
|
458
|
+
project_dir.selected_child&.find_next
|
512
459
|
end
|
513
|
-
}
|
460
|
+
}
|
514
461
|
}
|
515
462
|
label {
|
516
463
|
text 'Case-sensitive'
|
517
464
|
}
|
518
465
|
}
|
519
|
-
|
466
|
+
|
520
467
|
# row 4
|
521
|
-
|
468
|
+
|
522
469
|
label {
|
523
470
|
text 'Replace:'
|
524
471
|
}
|
@@ -526,14 +473,14 @@ module Glimmer
|
|
526
473
|
layout_data(:fill, :fill, true, false) {
|
527
474
|
minimum_width 300
|
528
475
|
}
|
529
|
-
text bind(
|
530
|
-
on_focus_gained {
|
531
|
-
|
476
|
+
text bind(project_dir, 'selected_child.replace_text')
|
477
|
+
on_focus_gained {
|
478
|
+
project_dir.selected_child&.ensure_find_next
|
532
479
|
}
|
533
480
|
on_key_pressed { |key_event|
|
534
481
|
if key_event.keyCode == swt(:cr)
|
535
|
-
if
|
536
|
-
Command.do(
|
482
|
+
if project_dir.selected_child
|
483
|
+
Command.do(project_dir.selected_child, :replace_next!)
|
537
484
|
end
|
538
485
|
end
|
539
486
|
}
|
@@ -547,7 +494,7 @@ module Glimmer
|
|
547
494
|
}
|
548
495
|
sash_width 10
|
549
496
|
orientation bind(self, :split_orientation)
|
550
|
-
@
|
497
|
+
@current_tab_folder = tab_folder {
|
551
498
|
drag_source(DND::DROP_COPY) {
|
552
499
|
transfer [TextTransfer.getInstance].to_java(Transfer)
|
553
500
|
event_data = nil
|
@@ -562,7 +509,7 @@ module Glimmer
|
|
562
509
|
}
|
563
510
|
}
|
564
511
|
}
|
565
|
-
@
|
512
|
+
@current_tab_folder.swt_widget.setData('proxy', @current_tab_folder)
|
566
513
|
}
|
567
514
|
}
|
568
515
|
}
|
@@ -574,48 +521,91 @@ module Glimmer
|
|
574
521
|
config_yaml = ::File.read(@config_file_path)
|
575
522
|
return if config_yaml.to_s.strip.empty?
|
576
523
|
@config = YAML.load(config_yaml)
|
577
|
-
|
578
|
-
|
524
|
+
project_dir.ignore_paths = @config[:ignore_paths] if @config[:ignore_paths]
|
525
|
+
project_dir.ignore_paths ||= ['packages', 'tmp']
|
579
526
|
else
|
580
527
|
@loaded_config = true
|
581
528
|
end
|
582
529
|
end
|
583
|
-
|
530
|
+
|
584
531
|
def load_config
|
585
532
|
if ::File.exists?(@config_file_path)
|
586
533
|
config_yaml = ::File.read(@config_file_path)
|
587
534
|
return if config_yaml.to_s.strip.empty?
|
588
535
|
@config = YAML.load(config_yaml)
|
589
|
-
|
590
|
-
|
536
|
+
project_dir.ignore_paths = @config[:ignore_paths] if @config[:ignore_paths]
|
537
|
+
project_dir.ignore_paths ||= ['packages', 'tmp']
|
591
538
|
open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
|
592
539
|
open_file_paths2 = @config[:open_file_paths2]
|
593
|
-
|
594
|
-
|
540
|
+
self.split_orientation = swt(@config[:split_orientation] || :horizontal) rescue swt(:horizontal)
|
541
|
+
if @progress_bar_shell.nil?
|
542
|
+
@progress_bar_shell = shell(body_root) {
|
543
|
+
text 'Opening Last Open Files'
|
544
|
+
fill_layout(:vertical) {
|
545
|
+
margin_width 15
|
546
|
+
margin_height 15
|
547
|
+
spacing 5
|
548
|
+
}
|
549
|
+
label(:center) {
|
550
|
+
text "Opening Last Open Files"
|
551
|
+
font height: 20
|
552
|
+
}
|
553
|
+
# @progress_bar = progress_bar(:horizontal, :indeterminate)
|
554
|
+
}
|
555
|
+
async_exec {
|
556
|
+
@progress_bar_shell.open
|
557
|
+
}
|
595
558
|
end
|
596
|
-
|
597
|
-
|
598
|
-
|
559
|
+
open_file_paths1.to_a.each do |file_path|
|
560
|
+
async_exec {
|
561
|
+
Gladiator.drag = false
|
562
|
+
project_dir.selected_child_path = file_path
|
563
|
+
}
|
599
564
|
end
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
565
|
+
# TODO replace the next line with one that selects the visible tab
|
566
|
+
async_exec {
|
567
|
+
Gladiator.drag = false
|
568
|
+
project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths1.to_a.include?(@config[:selected_child_path])
|
569
|
+
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]
|
570
|
+
project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
|
571
|
+
}
|
572
|
+
async_exec {
|
573
|
+
open_file_paths2.to_a.each do |file_path|
|
574
|
+
async_exec {
|
575
|
+
Gladiator.drag = true
|
576
|
+
project_dir.selected_child_path = file_path
|
577
|
+
}
|
578
|
+
end
|
579
|
+
# TODO replace the next line with one that selects the visible tab
|
580
|
+
async_exec {
|
581
|
+
Gladiator.drag = true
|
582
|
+
project_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path] && open_file_paths2.to_a.include?(@config[:selected_child_path])
|
583
|
+
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]
|
584
|
+
project_dir.selected_child&.top_pixel = @config[:top_pixel].to_i if @config[:top_pixel]
|
585
|
+
}
|
586
|
+
async_exec {
|
587
|
+
Gladiator.drag = false
|
588
|
+
@progress_bar_shell.close
|
589
|
+
@progress_bar_shell = nil
|
590
|
+
@loaded_config = true
|
591
|
+
}
|
592
|
+
}
|
604
593
|
else
|
605
594
|
@loaded_config = true
|
606
595
|
end
|
607
596
|
end
|
608
|
-
|
597
|
+
|
609
598
|
def save_config
|
610
599
|
return unless @loaded_config
|
611
|
-
child =
|
600
|
+
child = project_dir.selected_child
|
612
601
|
return if child.nil?
|
613
|
-
tab_folder1 = @tab_folder1 || @
|
602
|
+
tab_folder1 = @tab_folder1 || @current_tab_folder
|
614
603
|
tab_folder2 = @tab_folder2
|
615
604
|
open_file_paths1 = tab_folder1&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
|
616
605
|
open_file_paths2 = tab_folder2&.swt_widget&.items.to_a.map {|i| i.get_data('file_path')}
|
617
606
|
@config = {
|
618
607
|
selected_child_path: child.path,
|
608
|
+
split_orientation: split_orientation == swt(:horizontal) ? 'horizontal' : 'vertical',
|
619
609
|
caret_position: child.caret_position,
|
620
610
|
top_pixel: child.top_pixel,
|
621
611
|
shell_width: swt_widget&.getBounds&.width,
|
@@ -624,39 +614,43 @@ module Glimmer
|
|
624
614
|
shell_y: swt_widget&.getBounds&.y,
|
625
615
|
open_file_paths1: open_file_paths1,
|
626
616
|
open_file_paths2: open_file_paths2,
|
627
|
-
ignore_paths:
|
617
|
+
ignore_paths: project_dir.ignore_paths
|
628
618
|
}
|
629
619
|
config_yaml = YAML.dump(@config)
|
630
620
|
::File.write(@config_file_path, config_yaml) unless config_yaml.to_s.empty?
|
631
621
|
rescue => e
|
632
622
|
puts e.full_message
|
633
623
|
end
|
634
|
-
|
624
|
+
|
635
625
|
def close_tab_folder
|
636
626
|
if @tab_folder2 && !selected_tab_item
|
637
|
-
if @
|
627
|
+
if @current_tab_folder == @tab_folder2
|
638
628
|
@tab_folder2.swt_widget.dispose
|
639
|
-
@
|
629
|
+
@current_tab_folder = @tab_folder1
|
640
630
|
else
|
641
631
|
@tab_folder1.swt_widget.dispose
|
642
|
-
@
|
632
|
+
@current_tab_folder = @tab_folder1 = @tab_folder2
|
643
633
|
end
|
644
|
-
@tab_folder2 = nil
|
645
|
-
|
646
|
-
@
|
647
|
-
@
|
648
|
-
|
649
|
-
|
634
|
+
@tab_folder2 = nil
|
635
|
+
|
636
|
+
@current_tab_item = @current_tab_folder.swt_widget.getData('selected_tab_item')
|
637
|
+
@current_text_editor = @current_tab_item.swt_tab_item.getData('text_editor')
|
638
|
+
project_dir.selected_child = @current_tab_item.swt_tab_item.getData('file')
|
639
|
+
|
650
640
|
body_root.pack_same_size
|
651
641
|
end
|
652
642
|
end
|
653
|
-
|
643
|
+
|
644
|
+
def find_tab_item(file_path)
|
645
|
+
@current_tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == file_path }
|
646
|
+
end
|
647
|
+
|
654
648
|
def selected_tab_item
|
655
|
-
|
649
|
+
find_tab_item(project_dir.selected_child&.path)
|
656
650
|
end
|
657
651
|
|
658
652
|
def other_tab_items
|
659
|
-
@
|
653
|
+
@current_tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == project_dir.selected_child&.path }
|
660
654
|
end
|
661
655
|
|
662
656
|
def extract_tree_item_path(tree_item)
|
@@ -664,42 +658,44 @@ module Glimmer
|
|
664
658
|
if tree_item.getParentItem
|
665
659
|
::File.join(extract_tree_item_path(tree_item.getParentItem), tree_item.getText)
|
666
660
|
else
|
667
|
-
|
661
|
+
project_dir.path
|
668
662
|
end
|
669
663
|
end
|
670
|
-
|
664
|
+
|
671
665
|
def select_tree_item
|
672
|
-
return unless
|
673
|
-
tree_items_to_select = @
|
674
|
-
@
|
666
|
+
return unless project_dir.selected_child&.name
|
667
|
+
tree_items_to_select = @file_tree.depth_first_search { |ti| ti.getData.path == project_dir.selected_child.path }
|
668
|
+
@file_tree.swt_widget.setSelection(tree_items_to_select)
|
675
669
|
end
|
676
670
|
|
677
671
|
def delete_tree_item(tree_item)
|
678
672
|
return if tree_item.nil?
|
679
673
|
file = tree_item.getData
|
680
674
|
parent_path = ::File.dirname(file.path)
|
675
|
+
if file.is_a?(Gladiator::Dir)
|
676
|
+
file_paths = file.all_children.select {|f| f.is_a?(Gladiator::File)}.map(&:path)
|
677
|
+
else
|
678
|
+
file_paths = [file.path]
|
679
|
+
end
|
680
|
+
file_paths.each do |file_path|
|
681
|
+
found_tab_item = find_tab_item(file_path)
|
682
|
+
if found_tab_item
|
683
|
+
project_dir.selected_child_path_history.delete(found_tab_item.getData('file_path'))
|
684
|
+
found_tab_item.getData('proxy')&.dispose
|
685
|
+
end
|
686
|
+
end
|
681
687
|
file.delete! # TODO consider supporting command undo/redo
|
682
|
-
|
683
|
-
parent_tree_item = @
|
684
|
-
@
|
688
|
+
project_dir.refresh(async: false)
|
689
|
+
parent_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == parent_path}.first
|
690
|
+
@file_tree.swt_widget.showItem(parent_tree_item)
|
685
691
|
parent_tree_item.setExpanded(true)
|
686
|
-
# TODO close text editor tab
|
687
|
-
# if file.is_a?(::File)
|
688
|
-
# close tab
|
689
|
-
# end
|
690
692
|
rescue => e
|
691
|
-
puts e.full_message
|
692
|
-
end
|
693
|
-
|
694
|
-
def rename_selected_tree_item
|
695
|
-
Dir.local_dir.pause_refresh
|
696
|
-
tree_item = @tree.swt_widget.getSelection.first
|
697
|
-
rename_tree_item(tree_item)
|
693
|
+
puts e.full_message
|
698
694
|
end
|
699
|
-
|
695
|
+
|
700
696
|
def add_new_directory_to_selected_tree_item
|
701
|
-
|
702
|
-
tree_item = @
|
697
|
+
project_dir.pause_refresh
|
698
|
+
tree_item = @file_tree.swt_widget.getSelection.first
|
703
699
|
directory_path = extract_tree_item_path(tree_item)
|
704
700
|
return if directory_path.nil?
|
705
701
|
if !::Dir.exist?(directory_path)
|
@@ -708,15 +704,15 @@ module Glimmer
|
|
708
704
|
end
|
709
705
|
new_directory_path = ::File.expand_path(::File.join(directory_path, 'new_directory'))
|
710
706
|
FileUtils.mkdir_p(new_directory_path)
|
711
|
-
|
712
|
-
new_tree_item = @
|
713
|
-
@
|
714
|
-
rename_tree_item(new_tree_item
|
707
|
+
project_dir.refresh(async: false, force: true)
|
708
|
+
new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_directory_path}.first
|
709
|
+
@file_tree.swt_widget.showItem(new_tree_item)
|
710
|
+
rename_tree_item(new_tree_item)
|
715
711
|
end
|
716
|
-
|
712
|
+
|
717
713
|
def add_new_file_to_selected_tree_item
|
718
|
-
|
719
|
-
tree_item = @
|
714
|
+
project_dir.pause_refresh
|
715
|
+
tree_item = @file_tree.swt_widget.getSelection.first
|
720
716
|
directory_path = extract_tree_item_path(tree_item)
|
721
717
|
if !::Dir.exist?(directory_path)
|
722
718
|
tree_item = tree_item.getParentItem
|
@@ -725,24 +721,50 @@ module Glimmer
|
|
725
721
|
new_file_path = ::File.expand_path(::File.join(directory_path, 'new_file'))
|
726
722
|
FileUtils.touch(new_file_path)
|
727
723
|
# TODO look into refreshing only the parent directory to avoid slowdown
|
728
|
-
|
729
|
-
new_tree_item = @
|
730
|
-
@
|
724
|
+
project_dir.refresh(async: false, force: true)
|
725
|
+
new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_file_path}.first
|
726
|
+
@file_tree.swt_widget.showItem(new_tree_item)
|
731
727
|
rename_tree_item(new_tree_item, true)
|
732
728
|
end
|
733
|
-
|
734
|
-
def
|
735
|
-
|
729
|
+
|
730
|
+
def rename_selected_tree_item
|
731
|
+
project_dir.pause_refresh
|
732
|
+
tree_item = @file_tree.swt_widget.getSelection.first
|
733
|
+
rename_tree_item(tree_item)
|
734
|
+
end
|
735
|
+
|
736
|
+
def rename_tree_item(tree_item, new_file = false)
|
737
|
+
original_file = tree_item.getData
|
738
|
+
current_file = project_dir.selected_child_path == original_file.path
|
739
|
+
found_tab_item = find_tab_item(original_file.path)
|
740
|
+
found_text_editor = found_tab_item&.getData('text_editor')
|
741
|
+
@file_tree.edit_tree_item(
|
736
742
|
tree_item,
|
737
743
|
after_write: -> (edited_tree_item) {
|
738
744
|
file = edited_tree_item.getData
|
739
745
|
file_path = file.path
|
740
|
-
|
741
|
-
|
742
|
-
|
746
|
+
file.name
|
747
|
+
if new_file
|
748
|
+
project_dir.selected_child_path = file_path
|
749
|
+
else
|
750
|
+
found_text_editor&.file = file
|
751
|
+
found_tab_item&.setData('file', file)
|
752
|
+
found_tab_item&.setData('file_path', file.path)
|
753
|
+
found_tab_item&.setText(file.name)
|
754
|
+
body_root.pack_same_size
|
755
|
+
if current_file
|
756
|
+
project_dir.selected_child_path = file_path
|
757
|
+
else
|
758
|
+
selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
|
759
|
+
end
|
760
|
+
async_exec {
|
761
|
+
@file_tree.swt_widget.showItem(edited_tree_item)
|
762
|
+
}
|
763
|
+
end
|
764
|
+
project_dir.resume_refresh
|
743
765
|
},
|
744
766
|
after_cancel: -> {
|
745
|
-
|
767
|
+
project_dir.resume_refresh
|
746
768
|
}
|
747
769
|
)
|
748
770
|
end
|
@@ -752,5 +774,151 @@ module Glimmer
|
|
752
774
|
rescue => e
|
753
775
|
nil
|
754
776
|
end
|
777
|
+
|
778
|
+
def open_project
|
779
|
+
selected_directory = directory_dialog.open
|
780
|
+
@progress_bar_shell = shell(body_root) {
|
781
|
+
text 'Opening Project'
|
782
|
+
fill_layout(:vertical) {
|
783
|
+
margin_width 15
|
784
|
+
margin_height 15
|
785
|
+
spacing 5
|
786
|
+
}
|
787
|
+
label(:center) {
|
788
|
+
text "Opening Project: #{::File.basename(selected_directory)}"
|
789
|
+
font height: 20
|
790
|
+
}
|
791
|
+
# @progress_bar = progress_bar(:horizontal, :indeterminate)
|
792
|
+
}
|
793
|
+
async_exec {
|
794
|
+
@progress_bar_shell.open
|
795
|
+
}
|
796
|
+
async_exec {
|
797
|
+
gladiator(project_dir_path: selected_directory) {
|
798
|
+
on_swt_show {
|
799
|
+
@progress_bar_shell.close
|
800
|
+
@progress_bar_shell = nil
|
801
|
+
}
|
802
|
+
}.open if selected_directory
|
803
|
+
}
|
804
|
+
end
|
805
|
+
|
806
|
+
def handle_display_shortcut(key_event)
|
807
|
+
if key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'f'
|
808
|
+
if current_text_editor&.text_widget&.getSelectionText && current_text_editor&.text_widget&.getSelectionText&.size.to_i > 0
|
809
|
+
find_text.swt_widget.setText current_text_editor.text_widget.getSelectionText
|
810
|
+
end
|
811
|
+
find_text.swt_widget.selectAll
|
812
|
+
find_text.swt_widget.setFocus
|
813
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
|
814
|
+
Clipboard.copy(project_dir.selected_child.path)
|
815
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
|
816
|
+
project_dir.selected_child.find_previous
|
817
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'p'
|
818
|
+
open_project
|
819
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 's'
|
820
|
+
project_dir.selected_child_path = '' # scratchpad
|
821
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'w'
|
822
|
+
current_tab_folder.swt_widget.getItems.each do |tab_item|
|
823
|
+
project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
|
824
|
+
tab_item.getData('proxy')&.dispose
|
825
|
+
end
|
826
|
+
close_tab_folder
|
827
|
+
self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
|
828
|
+
filter_text.swt_widget.selectAll
|
829
|
+
filter_text.swt_widget.setFocus
|
830
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :alt) && extract_char(key_event) == 'w'
|
831
|
+
other_tab_items.each do |tab_item|
|
832
|
+
project_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
|
833
|
+
tab_item.getData('proxy')&.dispose
|
834
|
+
end
|
835
|
+
elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'w'
|
836
|
+
if selected_tab_item
|
837
|
+
project_dir.selected_child_path_history.delete(project_dir.selected_child.path)
|
838
|
+
selected_tab_item.getData('proxy')&.dispose
|
839
|
+
close_tab_folder
|
840
|
+
if selected_tab_item.nil?
|
841
|
+
self.current_tab_item = self.current_text_editor = project_dir.selected_child = nil
|
842
|
+
filter_text.swt_widget.selectAll
|
843
|
+
filter_text.swt_widget.setFocus
|
844
|
+
else
|
845
|
+
current_text_editor&.text_widget&.setFocus
|
846
|
+
end
|
847
|
+
end
|
848
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'o'
|
849
|
+
self.split_orientation = split_pane? && split_orientation == swt(:horizontal) ? swt(:vertical) : swt(:horizontal)
|
850
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
|
851
|
+
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
|
852
|
+
current_text_editor&.text_widget&.setFocus
|
853
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == '['
|
854
|
+
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
|
855
|
+
current_text_editor&.text_widget&.setFocus
|
856
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == ']'
|
857
|
+
if tab_folder2
|
858
|
+
if current_tab_folder == tab_folder1
|
859
|
+
self.current_tab_folder = tab_folder2
|
860
|
+
else
|
861
|
+
self.current_tab_folder = tab_folder1
|
862
|
+
end
|
863
|
+
self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
|
864
|
+
self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
|
865
|
+
current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
|
866
|
+
end
|
867
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == '['
|
868
|
+
if tab_folder2
|
869
|
+
if current_tab_folder == tab_folder2
|
870
|
+
self.current_tab_folder = tab_folder1
|
871
|
+
else
|
872
|
+
self.current_tab_folder = tab_folder2
|
873
|
+
end
|
874
|
+
self.current_tab_item = current_tab_folder.swt_widget.getData('selected_tab_item')
|
875
|
+
self.project_dir.selected_child = current_tab_item&.swt_tab_item&.getData('file')
|
876
|
+
current_tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
|
877
|
+
end
|
878
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '1'
|
879
|
+
current_tab_folder.swt_widget.setSelection(0) if current_tab_folder.swt_widget.getItemCount >= 1
|
880
|
+
current_text_editor&.text_widget&.setFocus
|
881
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '2'
|
882
|
+
current_tab_folder.swt_widget.setSelection(1) if current_tab_folder.swt_widget.getItemCount >= 2
|
883
|
+
current_text_editor&.text_widget&.setFocus
|
884
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '3'
|
885
|
+
current_tab_folder.swt_widget.setSelection(2) if current_tab_folder.swt_widget.getItemCount >= 3
|
886
|
+
current_text_editor&.text_widget&.setFocus
|
887
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '4'
|
888
|
+
current_tab_folder.swt_widget.setSelection(3) if current_tab_folder.swt_widget.getItemCount >= 4
|
889
|
+
current_text_editor&.text_widget&.setFocus
|
890
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '5'
|
891
|
+
current_tab_folder.swt_widget.setSelection(4) if current_tab_folder.swt_widget.getItemCount >= 5
|
892
|
+
current_text_editor&.text_widget&.setFocus
|
893
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '6'
|
894
|
+
current_tab_folder.swt_widget.setSelection(5) if current_tab_folder.swt_widget.getItemCount >= 6
|
895
|
+
current_text_editor&.text_widget&.setFocus
|
896
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '7'
|
897
|
+
current_tab_folder.swt_widget.setSelection(6) if current_tab_folder.swt_widget.getItemCount >= 7
|
898
|
+
current_text_editor&.text_widget&.setFocus
|
899
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '8'
|
900
|
+
current_tab_folder.swt_widget.setSelection(7) if current_tab_folder.swt_widget.getItemCount >= 8
|
901
|
+
current_text_editor&.text_widget&.setFocus
|
902
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '9'
|
903
|
+
current_tab_folder.swt_widget.setSelection(current_tab_folder.swt_widget.getItemCount - 1) if current_tab_folder.swt_widget.getItemCount > 0
|
904
|
+
current_text_editor&.text_widget&.setFocus
|
905
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'g'
|
906
|
+
project_dir.selected_child.find_next
|
907
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'l'
|
908
|
+
line_number_text.swt_widget.selectAll
|
909
|
+
line_number_text.swt_widget.setFocus
|
910
|
+
elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'r'
|
911
|
+
filter_text.swt_widget.selectAll
|
912
|
+
filter_text.swt_widget.setFocus
|
913
|
+
elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 't'
|
914
|
+
select_tree_item unless rename_in_progress
|
915
|
+
file_tree.swt_widget.setFocus
|
916
|
+
elsif key_event.keyCode == swt(:esc)
|
917
|
+
if current_text_editor
|
918
|
+
project_dir.selected_child_path = current_text_editor.file.path
|
919
|
+
current_text_editor&.text_widget&.setFocus
|
920
|
+
end
|
921
|
+
end
|
922
|
+
end
|
755
923
|
end
|
756
|
-
end
|
924
|
+
end
|