glimmer 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +212 -161
- data/RUBY_VERSION +1 -0
- data/VERSION +1 -0
- data/icons/scaffold_app.icns +0 -0
- data/lib/glimmer.rb +5 -47
- data/lib/glimmer/config.rb +35 -0
- data/lib/glimmer/css/{rule_set.rb → rule.rb} +3 -5
- data/lib/glimmer/css/style_sheet.rb +4 -5
- data/lib/glimmer/data_binding/observable_model.rb +1 -1
- data/lib/glimmer/dsl/css/dsl.rb +2 -2
- data/lib/glimmer/dsl/css/dynamic_property_expression.rb +12 -0
- data/lib/glimmer/dsl/css/property_expression.rb +3 -3
- data/lib/glimmer/dsl/css/pv_expression.rb +17 -0
- data/lib/glimmer/dsl/css/{rule_set_expression.rb → rule_expression.rb} +4 -4
- data/lib/glimmer/dsl/css/s_expression.rb +3 -3
- data/lib/glimmer/dsl/engine.rb +35 -5
- data/lib/glimmer/dsl/expression_handler.rb +3 -3
- data/lib/glimmer/dsl/swt/color_expression.rb +2 -0
- data/lib/glimmer/dsl/swt/dsl.rb +2 -0
- data/lib/glimmer/dsl/swt/tab_item_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +5 -5
- data/lib/glimmer/dsl/xml/name_space_expression.rb +1 -1
- data/lib/glimmer/launcher.rb +64 -19
- data/lib/glimmer/rake_task.rb +64 -23
- data/lib/glimmer/scaffold.rb +442 -0
- data/lib/glimmer/swt/layout_data_proxy.rb +1 -1
- data/lib/glimmer/swt/layout_proxy.rb +2 -2
- data/lib/glimmer/swt/swt_proxy.rb +3 -3
- data/lib/glimmer/swt/widget_proxy.rb +5 -5
- data/lib/glimmer/ui/custom_widget.rb +3 -3
- data/lib/glimmer/xml/node.rb +1 -1
- data/lib/glimmer/xml/xml_visitor.rb +2 -2
- metadata +16 -42
- data/bin/gladiator +0 -6
- data/lib/glimmer/dsl/css/p_expression.rb +0 -25
- data/lib/glimmer/ui/video.rb +0 -289
- data/samples/gladiator.rb +0 -765
data/samples/gladiator.rb
DELETED
@@ -1,765 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'filewatcher'
|
3
|
-
require 'clipboard'
|
4
|
-
|
5
|
-
Clipboard.implementation = Clipboard::Java
|
6
|
-
Clipboard.copy(Clipboard.paste) # pre-initialize library to avoid slowdown during use
|
7
|
-
|
8
|
-
# Gladiator (Glimmer Editor)
|
9
|
-
class Gladiator
|
10
|
-
include Glimmer
|
11
|
-
|
12
|
-
class Dir
|
13
|
-
include Glimmer
|
14
|
-
|
15
|
-
class << self
|
16
|
-
def local_dir
|
17
|
-
@local_dir ||= new(ENV['LOCAL_DIR'] || '.').tap do |dir|
|
18
|
-
dir.refresh
|
19
|
-
@filewatcher = Filewatcher.new(dir.path)
|
20
|
-
@thread = Thread.new(@filewatcher) do |fw|
|
21
|
-
fw.watch do |filename, event|
|
22
|
-
dir.refresh if filename != dir.selected_child_path
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_accessor :selected_child, :filter, :children, :filtered_path_options
|
30
|
-
attr_reader :path, :display_path
|
31
|
-
|
32
|
-
def initialize(path)
|
33
|
-
@path = @display_path = path
|
34
|
-
self.filtered_path_options = []
|
35
|
-
end
|
36
|
-
|
37
|
-
def children
|
38
|
-
@children ||= retrieve_children
|
39
|
-
end
|
40
|
-
|
41
|
-
def retrieve_children
|
42
|
-
::Dir.glob(::File.join(@path, '*')).map {|p| ::File.file?(p) ? Gladiator::File.new(p) : Gladiator::Dir.new(p)}.sort_by {|c| c.path.to_s.downcase }.sort_by {|c| c.class.name }
|
43
|
-
end
|
44
|
-
|
45
|
-
def refresh
|
46
|
-
new_all_children = retrieve_all_children
|
47
|
-
new_children = retrieve_children
|
48
|
-
async_exec do
|
49
|
-
@all_children = new_all_children
|
50
|
-
@children ||= []
|
51
|
-
@children.clear
|
52
|
-
new_children.each do |child|
|
53
|
-
@children << child
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def filter=(value)
|
59
|
-
if value.to_s.empty?
|
60
|
-
@filter = nil
|
61
|
-
else
|
62
|
-
@filter = value
|
63
|
-
end
|
64
|
-
self.filtered_path_options = filtered.to_a.map(&:display_path)
|
65
|
-
end
|
66
|
-
|
67
|
-
def filtered
|
68
|
-
return if filter.nil?
|
69
|
-
all_children_files.select do |child|
|
70
|
-
child.path.downcase.include?(filter.downcase) ||
|
71
|
-
child.path.downcase.gsub(/[_\/]/, '').include?(filter.downcase)
|
72
|
-
end.sort_by {|c| c.path.to_s.downcase}
|
73
|
-
end
|
74
|
-
|
75
|
-
def all_children
|
76
|
-
@all_children ||= retrieve_all_children
|
77
|
-
end
|
78
|
-
|
79
|
-
def retrieve_all_children
|
80
|
-
::Dir.glob(::File.join(@path, '**', '*')).map {|p| ::File.file?(p) ? Gladiator::File.new(p) : Gladiator::Dir.new(p)}
|
81
|
-
end
|
82
|
-
|
83
|
-
def all_children_files
|
84
|
-
all_children.select {|child| child.is_a?(Gladiator::File) }
|
85
|
-
end
|
86
|
-
|
87
|
-
def selected_child_path=(selected_path)
|
88
|
-
if selected_path && ::File.file?(selected_path)
|
89
|
-
@selected_child&.write_dirty_content
|
90
|
-
new_child = Gladiator::File.new(selected_path)
|
91
|
-
begin
|
92
|
-
unless new_child.dirty_content.nil?
|
93
|
-
self.selected_child&.stop_filewatcher
|
94
|
-
self.selected_child = new_child
|
95
|
-
self.selected_child.start_filewatcher
|
96
|
-
end
|
97
|
-
rescue
|
98
|
-
# no op
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def selected_child_path
|
104
|
-
@selected_child&.path
|
105
|
-
end
|
106
|
-
|
107
|
-
alias filtered_path selected_child_path
|
108
|
-
alias filtered_path= selected_child_path=
|
109
|
-
|
110
|
-
def to_s
|
111
|
-
path
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
class File
|
116
|
-
include Glimmer
|
117
|
-
|
118
|
-
attr_accessor :dirty_content, :line_numbers_content, :caret_position, :selection_count, :line_number, :find_text, :replace_text, :top_index
|
119
|
-
attr_reader :path, :display_path
|
120
|
-
|
121
|
-
def initialize(path)
|
122
|
-
raise "Not a file path: #{path}" unless ::File.file?(path)
|
123
|
-
@display_path = path
|
124
|
-
@path = ::File.expand_path(path)
|
125
|
-
read_dirty_content = ::File.read(path)
|
126
|
-
begin
|
127
|
-
# test read dirty content
|
128
|
-
read_dirty_content.split("\n")
|
129
|
-
observe(self, :dirty_content) do
|
130
|
-
lines_text_size = lines.size.to_s.size
|
131
|
-
self.line_numbers_content = lines.size.times.map {|n| (' ' * (lines_text_size - (n+1).to_s.size)) + (n+1).to_s }.join("\n")
|
132
|
-
end
|
133
|
-
self.dirty_content = read_dirty_content
|
134
|
-
observe(self, :caret_position) do
|
135
|
-
self.line_number = line_index_for_caret_position(caret_position) + 1
|
136
|
-
end
|
137
|
-
observe(self, :line_number) do
|
138
|
-
if line_number
|
139
|
-
new_caret_position = lines[0...(line_number.to_i - 1)].map(&:size).sum + line_number.to_i - 1
|
140
|
-
self.caret_position = new_caret_position unless line_index_for_caret_position(new_caret_position) == line_index_for_caret_position(caret_position)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
rescue
|
144
|
-
# no op in case of a binary file
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def start_filewatcher
|
149
|
-
@filewatcher = Filewatcher.new(@path)
|
150
|
-
@thread = Thread.new(@filewatcher) do |fw|
|
151
|
-
fw.watch do |filename, event|
|
152
|
-
begin
|
153
|
-
read_dirty_content = ::File.read(path)
|
154
|
-
# test read dirty content
|
155
|
-
read_dirty_content.split("\n")
|
156
|
-
async_exec do
|
157
|
-
self.dirty_content = read_dirty_content if read_dirty_content != dirty_content
|
158
|
-
end
|
159
|
-
rescue
|
160
|
-
# no op in case of a binary file
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def stop_filewatcher
|
167
|
-
@filewatcher&.stop
|
168
|
-
end
|
169
|
-
|
170
|
-
def write_dirty_content
|
171
|
-
new_dirty_content = "#{dirty_content.gsub("\r\n", "\n").gsub("\r", "\n").sub(/\n+\z/, '')}\n"
|
172
|
-
self.dirty_content = new_dirty_content if new_dirty_content != self.dirty_content
|
173
|
-
::File.write(path, dirty_content) if ::File.exists?(path) && dirty_content.to_s.strip.size > 0
|
174
|
-
end
|
175
|
-
|
176
|
-
def write_raw_dirty_content
|
177
|
-
::File.write(path, dirty_content) if ::File.exists?(path) && dirty_content.to_s.strip.size > 0
|
178
|
-
end
|
179
|
-
|
180
|
-
def comment_line!
|
181
|
-
old_lines = lines
|
182
|
-
return if old_lines.size < 1
|
183
|
-
old_selection_count = self.selection_count
|
184
|
-
old_caret_position = self.caret_position
|
185
|
-
old_caret_position_line_index = line_index_for_caret_position(old_caret_position)
|
186
|
-
old_caret_position_line_caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
187
|
-
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
188
|
-
new_lines = lines
|
189
|
-
delta = 0
|
190
|
-
line_indices_for_selection(caret_position, selection_count).reverse.each do | the_line_index |
|
191
|
-
delta = 0
|
192
|
-
the_line = old_lines[the_line_index]
|
193
|
-
if the_line.strip.start_with?('# ')
|
194
|
-
new_lines[the_line_index] = the_line.sub(/# /, '')
|
195
|
-
delta -= 2
|
196
|
-
elsif the_line.strip.start_with?('#')
|
197
|
-
new_lines[the_line_index] = the_line.sub(/#/, '')
|
198
|
-
delta -= 1
|
199
|
-
else
|
200
|
-
new_lines[the_line_index] = "# #{the_line}"
|
201
|
-
delta += 2
|
202
|
-
end
|
203
|
-
end
|
204
|
-
self.dirty_content = new_lines.join("\n")
|
205
|
-
if old_selection_count > 0
|
206
|
-
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
207
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
208
|
-
else
|
209
|
-
new_caret_position = old_caret_position + delta
|
210
|
-
new_caret_position = [new_caret_position, old_caret_position_line_caret_position].max
|
211
|
-
self.caret_position = new_caret_position
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
def indent!
|
216
|
-
new_lines = lines
|
217
|
-
old_lines = lines
|
218
|
-
return if old_lines.size < 1
|
219
|
-
old_selection_count = self.selection_count
|
220
|
-
old_caret_position = self.caret_position
|
221
|
-
old_caret_position_line_index = line_index_for_caret_position(old_caret_position)
|
222
|
-
old_caret_position_line_caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
223
|
-
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
224
|
-
delta = 2
|
225
|
-
line_indices_for_selection(caret_position, selection_count).each do |the_line_index|
|
226
|
-
the_line = old_lines[the_line_index]
|
227
|
-
new_lines[the_line_index] = " #{the_line}"
|
228
|
-
end
|
229
|
-
old_caret_position = self.caret_position
|
230
|
-
self.dirty_content = new_lines.join("\n")
|
231
|
-
if old_selection_count > 0
|
232
|
-
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
233
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
234
|
-
else
|
235
|
-
self.caret_position = old_caret_position + delta
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def outdent!
|
240
|
-
new_lines = lines
|
241
|
-
old_lines = lines
|
242
|
-
return if old_lines.size < 1
|
243
|
-
old_selection_count = self.selection_count
|
244
|
-
old_caret_position = self.caret_position
|
245
|
-
old_caret_position_line_index = line_index_for_caret_position(old_caret_position)
|
246
|
-
old_caret_position_line_caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
247
|
-
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
248
|
-
delta = 0
|
249
|
-
line_indices_for_selection(caret_position, selection_count).each do |the_line_index|
|
250
|
-
the_line = old_lines[the_line_index]
|
251
|
-
if the_line.start_with?(' ')
|
252
|
-
new_lines[the_line_index] = the_line.sub(/ /, '')
|
253
|
-
delta = -2
|
254
|
-
elsif the_line.start_with?(' ')
|
255
|
-
new_lines[the_line_index] = the_line.sub(/ /, '')
|
256
|
-
delta = -1
|
257
|
-
end
|
258
|
-
end
|
259
|
-
self.dirty_content = new_lines.join("\n")
|
260
|
-
if old_selection_count > 0
|
261
|
-
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
262
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
263
|
-
else
|
264
|
-
new_caret_position = old_caret_position + delta
|
265
|
-
new_caret_position = [new_caret_position, old_caret_position_line_caret_position].max
|
266
|
-
self.caret_position = new_caret_position
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
def kill_line!
|
271
|
-
new_lines = lines
|
272
|
-
return if new_lines.size < 2
|
273
|
-
line_indices = line_indices_for_selection(caret_position, selection_count)
|
274
|
-
new_lines = new_lines[0...line_indices.first] + new_lines[(line_indices.last+1)...new_lines.size]
|
275
|
-
old_caret_position = self.caret_position
|
276
|
-
self.dirty_content = new_lines.join("\n")
|
277
|
-
self.caret_position = old_caret_position
|
278
|
-
end
|
279
|
-
|
280
|
-
def duplicate_line!
|
281
|
-
new_lines = lines
|
282
|
-
old_lines = lines
|
283
|
-
return if old_lines.size < 1
|
284
|
-
old_selection_count = self.selection_count
|
285
|
-
old_caret_position = self.caret_position
|
286
|
-
old_caret_position_line_index = line_index_for_caret_position(old_caret_position)
|
287
|
-
old_caret_position_line_caret_position = caret_position_for_caret_position_start_of_line(old_caret_position_line_index)
|
288
|
-
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
289
|
-
the_line_indices = line_indices_for_selection(caret_position, selection_count)
|
290
|
-
the_lines = lines_for_selection(caret_position, selection_count)
|
291
|
-
delta = the_lines.join("\n").size + 1
|
292
|
-
the_lines.each_with_index do |the_line, i|
|
293
|
-
new_lines.insert(the_line_indices.first + i, the_line)
|
294
|
-
end
|
295
|
-
self.dirty_content = new_lines.join("\n")
|
296
|
-
if old_selection_count > 0
|
297
|
-
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
298
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
299
|
-
else
|
300
|
-
self.caret_position = old_caret_position + delta
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
def find_next
|
305
|
-
return if find_text.to_s.empty?
|
306
|
-
all_lines = lines
|
307
|
-
the_line_index = line_index_for_caret_position(caret_position)
|
308
|
-
all_lines.rotate(the_line_index + 1).each_with_index do |the_line, the_index|
|
309
|
-
the_index = (the_index + the_line_index + 1)%all_lines.size
|
310
|
-
if the_line.downcase.include?(find_text.to_s.downcase)
|
311
|
-
self.caret_position = the_line.downcase.index(find_text.to_s.downcase) + caret_position_for_line_index(the_index)
|
312
|
-
self.selection_count = find_text.to_s.size
|
313
|
-
return
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
def find_previous
|
319
|
-
return if find_text.to_s.empty?
|
320
|
-
all_lines = lines
|
321
|
-
the_line_index = line_index_for_caret_position(caret_position)
|
322
|
-
all_lines.rotate(the_line_index).each_with_index.map do |the_line, the_index|
|
323
|
-
the_index = (the_index + the_line_index)%all_lines.size
|
324
|
-
[the_line, the_index]
|
325
|
-
end.reverse.each do |the_line, the_index|
|
326
|
-
if the_line.downcase.include?(find_text.to_s.downcase)
|
327
|
-
self.caret_position = the_line.downcase.index(find_text.to_s.downcase) + caret_position_for_line_index(the_index)
|
328
|
-
self.selection_count = find_text.to_s.size
|
329
|
-
return
|
330
|
-
end
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
def ensure_find_next
|
335
|
-
return if find_text.to_s.empty? || dirty_content.to_s.strip.size < 1
|
336
|
-
find_next unless dirty_content[caret_position.to_i, find_text.to_s.size] == find_text
|
337
|
-
end
|
338
|
-
|
339
|
-
def replace_next!
|
340
|
-
return if find_text.to_s.empty? || dirty_content.to_s.strip.size < 1
|
341
|
-
ensure_find_next
|
342
|
-
new_dirty_content = dirty_content
|
343
|
-
new_dirty_content[caret_position, find_text.size] = replace_text.to_s
|
344
|
-
self.dirty_content = new_dirty_content
|
345
|
-
find_next
|
346
|
-
end
|
347
|
-
|
348
|
-
def page_up
|
349
|
-
self.line_number = [(self.line_number - 15), 1].max
|
350
|
-
end
|
351
|
-
|
352
|
-
def page_down
|
353
|
-
self.line_number = [(self.line_number + 15), lines.size].min
|
354
|
-
end
|
355
|
-
|
356
|
-
def home
|
357
|
-
self.line_number = 1
|
358
|
-
end
|
359
|
-
|
360
|
-
def end
|
361
|
-
self.line_number = lines.size
|
362
|
-
end
|
363
|
-
|
364
|
-
def move_up!
|
365
|
-
old_lines = lines
|
366
|
-
return if old_lines.size < 2
|
367
|
-
old_selection_count = self.selection_count
|
368
|
-
old_caret_position = self.caret_position
|
369
|
-
old_caret_position_line_index = line_index_for_caret_position(old_caret_position)
|
370
|
-
old_caret_position_line_caret_position = caret_position_for_caret_position_start_of_line(old_caret_position_line_index)
|
371
|
-
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
372
|
-
new_lines = lines
|
373
|
-
the_line_indices = line_indices_for_selection(caret_position, selection_count)
|
374
|
-
the_lines = lines_for_selection(caret_position, selection_count)
|
375
|
-
new_line_index = [the_line_indices.first - 1, 0].max
|
376
|
-
delta = -1 * (new_lines[new_line_index].size + 1)
|
377
|
-
new_lines[the_line_indices.first..the_line_indices.last] = []
|
378
|
-
new_lines[new_line_index...new_line_index] = the_lines
|
379
|
-
self.dirty_content = new_lines.join("\n")
|
380
|
-
if old_selection_count > 0
|
381
|
-
self.caret_position = caret_position_for_line_index(old_caret_position_line_index) + delta
|
382
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position + delta)
|
383
|
-
else
|
384
|
-
self.caret_position = old_caret_position + delta
|
385
|
-
end
|
386
|
-
end
|
387
|
-
|
388
|
-
def move_down!
|
389
|
-
old_lines = lines
|
390
|
-
return if old_lines.size < 2
|
391
|
-
old_selection_count = self.selection_count
|
392
|
-
old_caret_position = self.caret_position
|
393
|
-
old_caret_position_line_index = line_index_for_caret_position(old_caret_position)
|
394
|
-
old_caret_position_line_caret_position = caret_position_for_caret_position_start_of_line(old_caret_position_line_index)
|
395
|
-
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
396
|
-
new_lines = lines
|
397
|
-
the_line_indices = line_indices_for_selection(caret_position, selection_count)
|
398
|
-
the_lines = lines_for_selection(caret_position, selection_count)
|
399
|
-
new_line_index = [the_line_indices.first + 1, new_lines.size - 1].min
|
400
|
-
delta = new_lines[new_line_index].size + 1
|
401
|
-
new_lines[the_line_indices.first..the_line_indices.last] = []
|
402
|
-
new_lines[new_line_index...new_line_index] = the_lines
|
403
|
-
self.dirty_content = new_lines.join("\n")
|
404
|
-
if old_selection_count > 0
|
405
|
-
self.caret_position = caret_position_for_line_index(old_caret_position_line_index) + delta
|
406
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position + delta)
|
407
|
-
else
|
408
|
-
self.caret_position = old_caret_position + delta
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
def lines
|
413
|
-
dirty_content.split("\n")
|
414
|
-
end
|
415
|
-
|
416
|
-
def line_for_caret_position(caret_position)
|
417
|
-
lines[line_index_for_caret_position(caret_position.to_i)]
|
418
|
-
end
|
419
|
-
|
420
|
-
def line_index_for_caret_position(caret_position)
|
421
|
-
dirty_content[0...caret_position.to_i].count("\n")
|
422
|
-
end
|
423
|
-
|
424
|
-
def caret_position_for_line_index(line_index)
|
425
|
-
lines[0...line_index].join("\n").size + 1
|
426
|
-
end
|
427
|
-
|
428
|
-
def caret_position_for_caret_position_start_of_line(caret_position)
|
429
|
-
caret_position_for_line_index(line_index_for_caret_position(caret_position))
|
430
|
-
end
|
431
|
-
|
432
|
-
def line_caret_positions_for_selection(caret_position, selection_count)
|
433
|
-
line_indices = line_indices_for_selection(caret_position, selection_count)
|
434
|
-
line_caret_positions = line_indices.map { |line_index| caret_position_for_line_index(line_index) }.to_a
|
435
|
-
end
|
436
|
-
|
437
|
-
def end_caret_position_line_index(caret_position, selection_count)
|
438
|
-
end_caret_position = caret_position + selection_count.to_i
|
439
|
-
end_caret_position -= 1 if dirty_content[end_caret_position - 1] == "\n"
|
440
|
-
end_line_index = line_index_for_caret_position(end_caret_position)
|
441
|
-
end
|
442
|
-
|
443
|
-
def lines_for_selection(caret_position, selection_count)
|
444
|
-
line_indices = line_indices_for_selection(caret_position, selection_count)
|
445
|
-
lines[line_indices.first..line_indices.last]
|
446
|
-
end
|
447
|
-
|
448
|
-
def line_indices_for_selection(caret_position, selection_count)
|
449
|
-
start_line_index = line_index_for_caret_position(caret_position)
|
450
|
-
if selection_count.to_i > 0
|
451
|
-
end_line_index = end_caret_position_line_index(caret_position, selection_count)
|
452
|
-
else
|
453
|
-
end_line_index = start_line_index
|
454
|
-
end
|
455
|
-
(start_line_index..end_line_index).to_a
|
456
|
-
end
|
457
|
-
|
458
|
-
def children
|
459
|
-
[]
|
460
|
-
end
|
461
|
-
|
462
|
-
def to_s
|
463
|
-
path
|
464
|
-
end
|
465
|
-
end
|
466
|
-
|
467
|
-
def initialize
|
468
|
-
Display.setAppName('Gladiator')
|
469
|
-
@config_file_path = '.gladiator'
|
470
|
-
@config = {}
|
471
|
-
Gladiator::Dir.local_dir.all_children # pre-caches children
|
472
|
-
load_config
|
473
|
-
end
|
474
|
-
|
475
|
-
def load_config
|
476
|
-
if ::File.exists?(@config_file_path)
|
477
|
-
config_yaml = ::File.read(@config_file_path)
|
478
|
-
return if config_yaml.to_s.strip.empty?
|
479
|
-
@config = YAML.load(config_yaml)
|
480
|
-
Gladiator::Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
|
481
|
-
Gladiator::Dir.local_dir.selected_child&.caret_position = Gladiator::Dir.local_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position]) if @config[:caret_position]
|
482
|
-
Gladiator::Dir.local_dir.selected_child&.top_index = @config[:top_index] if @config[:top_index]
|
483
|
-
end
|
484
|
-
end
|
485
|
-
|
486
|
-
def save_config
|
487
|
-
child = Gladiator::Dir.local_dir.selected_child
|
488
|
-
return if child.nil?
|
489
|
-
@config = {
|
490
|
-
selected_child_path: child.path,
|
491
|
-
caret_position: child.caret_position,
|
492
|
-
top_index: child.top_index,
|
493
|
-
}
|
494
|
-
config_yaml = YAML.dump(@config)
|
495
|
-
::File.write(@config_file_path, config_yaml) unless config_yaml.to_s.empty?
|
496
|
-
rescue => e
|
497
|
-
puts e.full_message
|
498
|
-
end
|
499
|
-
|
500
|
-
def launch
|
501
|
-
@display = display {
|
502
|
-
on_event_keydown { |key_event|
|
503
|
-
if Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'f'
|
504
|
-
if @text.swt_widget.getSelectionText && @text.swt_widget.getSelectionText.size > 0
|
505
|
-
@find_text.swt_widget.setText @text.swt_widget.getSelectionText
|
506
|
-
end
|
507
|
-
@find_text.swt_widget.selectAll
|
508
|
-
@find_text.swt_widget.setFocus
|
509
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'c'
|
510
|
-
Clipboard.copy(Gladiator::Dir.local_dir.selected_child.path)
|
511
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'g'
|
512
|
-
Gladiator::Dir.local_dir.selected_child.find_previous
|
513
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'g'
|
514
|
-
Gladiator::Dir.local_dir.selected_child.find_next
|
515
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'l'
|
516
|
-
@line_number_text.swt_widget.selectAll
|
517
|
-
@line_number_text.swt_widget.setFocus
|
518
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'r'
|
519
|
-
@filter_text.swt_widget.selectAll
|
520
|
-
@filter_text.swt_widget.setFocus
|
521
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 't'
|
522
|
-
@tree.swt_widget.setFocus
|
523
|
-
end
|
524
|
-
}
|
525
|
-
}
|
526
|
-
@shell = shell {
|
527
|
-
text "Gladiator - #{::File.expand_path(Gladiator::Dir.local_dir.path)}"
|
528
|
-
minimum_size 720, 450
|
529
|
-
size 1440, 900
|
530
|
-
grid_layout 2, false
|
531
|
-
on_event_close {
|
532
|
-
Gladiator::Dir.local_dir.selected_child&.write_dirty_content
|
533
|
-
}
|
534
|
-
on_widget_disposed {
|
535
|
-
Gladiator::Dir.local_dir.selected_child&.write_dirty_content
|
536
|
-
}
|
537
|
-
composite {
|
538
|
-
grid_layout 1, false
|
539
|
-
layout_data(:fill, :fill, false, true) {
|
540
|
-
width_hint 300
|
541
|
-
}
|
542
|
-
@filter_text = text {
|
543
|
-
layout_data :fill, :center, true, false
|
544
|
-
text bind(Gladiator::Dir.local_dir, 'filter')
|
545
|
-
on_key_pressed { |key_event|
|
546
|
-
if key_event.keyCode == swt(:tab) ||
|
547
|
-
key_event.keyCode == swt(:cr) ||
|
548
|
-
key_event.keyCode == swt(:lf) ||
|
549
|
-
key_event.keyCode == swt(:arrow_up) ||
|
550
|
-
key_event.keyCode == swt(:arrow_down)
|
551
|
-
@list.swt_widget.setFocus
|
552
|
-
elsif key_event.keyCode == swt(:esc)
|
553
|
-
@text.swt_widget.setFocus
|
554
|
-
end
|
555
|
-
}
|
556
|
-
}
|
557
|
-
composite {
|
558
|
-
layout_data(:fill, :fill, true, true)
|
559
|
-
@list = list(:border, :h_scroll, :v_scroll) {
|
560
|
-
layout_data(:fill, :fill, true, true) {
|
561
|
-
#exclude bind(Gladiator::Dir.local_dir, :filter) {|f| !f}
|
562
|
-
}
|
563
|
-
#visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !!f}
|
564
|
-
selection bind(Gladiator::Dir.local_dir, :filtered_path)
|
565
|
-
on_widget_selected {
|
566
|
-
Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
|
567
|
-
}
|
568
|
-
on_key_pressed { |key_event|
|
569
|
-
if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr) || Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :lf)
|
570
|
-
Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
|
571
|
-
@text.swt_widget.setFocus
|
572
|
-
end
|
573
|
-
}
|
574
|
-
}
|
575
|
-
@tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
|
576
|
-
layout_data(:fill, :fill, true, true) {
|
577
|
-
#exclude bind(Gladiator::Dir.local_dir, :filter) {|f| !!f}
|
578
|
-
}
|
579
|
-
#visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !f}
|
580
|
-
items bind(Gladiator::Dir, :local_dir), tree_properties(children: :children, text: :display_path)
|
581
|
-
on_widget_selected {
|
582
|
-
Gladiator::Dir.local_dir.selected_child_path = @tree.swt_widget.getSelection.first.getText
|
583
|
-
}
|
584
|
-
on_key_pressed { |key_event|
|
585
|
-
if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr) || Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :lf)
|
586
|
-
Gladiator::Dir.local_dir.selected_child_path = @tree.swt_widget.getSelection.first.getText
|
587
|
-
@text.swt_widget.setFocus
|
588
|
-
end
|
589
|
-
}
|
590
|
-
on_paint_control {
|
591
|
-
root_item = @tree.swt_widget.getItems.first
|
592
|
-
if root_item && !root_item.getExpanded
|
593
|
-
root_item.setExpanded true
|
594
|
-
end
|
595
|
-
}
|
596
|
-
}
|
597
|
-
}
|
598
|
-
}
|
599
|
-
composite {
|
600
|
-
grid_layout 1, false
|
601
|
-
layout_data :fill, :fill, true, true
|
602
|
-
composite {
|
603
|
-
grid_layout 2, false
|
604
|
-
@file_path_label = styled_text(:none) {
|
605
|
-
layout_data(:fill, :fill, true, false) {
|
606
|
-
horizontal_span 2
|
607
|
-
}
|
608
|
-
background color(:widget_background)
|
609
|
-
editable false
|
610
|
-
caret nil
|
611
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.path')
|
612
|
-
on_mouse_up {
|
613
|
-
@file_path_label.swt_widget.selectAll
|
614
|
-
}
|
615
|
-
on_focus_lost {
|
616
|
-
@file_path_label.swt_widget.setSelection(0, 0)
|
617
|
-
}
|
618
|
-
}
|
619
|
-
label {
|
620
|
-
text 'Line:'
|
621
|
-
}
|
622
|
-
@line_number_text = text {
|
623
|
-
layout_data(:fill, :fill, true, false) {
|
624
|
-
minimum_width 300
|
625
|
-
}
|
626
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
|
627
|
-
on_key_pressed { |key_event|
|
628
|
-
if key_event.keyCode == swt(:cr)
|
629
|
-
@text.swt_widget.setFocus
|
630
|
-
end
|
631
|
-
}
|
632
|
-
}
|
633
|
-
label {
|
634
|
-
text 'Find:'
|
635
|
-
}
|
636
|
-
@find_text = text {
|
637
|
-
layout_data(:fill, :fill, true, false) {
|
638
|
-
minimum_width 200
|
639
|
-
}
|
640
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.find_text')
|
641
|
-
on_key_pressed { |key_event|
|
642
|
-
if key_event.keyCode == swt(:cr)
|
643
|
-
Gladiator::Dir.local_dir.selected_child.find_next
|
644
|
-
elsif key_event.keyCode == swt(:esc)
|
645
|
-
@text.swt_widget.setFocus
|
646
|
-
end
|
647
|
-
}
|
648
|
-
}
|
649
|
-
label {
|
650
|
-
text 'Replace:'
|
651
|
-
}
|
652
|
-
@replace_text = text {
|
653
|
-
layout_data(:fill, :fill, true, false) {
|
654
|
-
minimum_width 200
|
655
|
-
}
|
656
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.replace_text')
|
657
|
-
on_focus_gained {
|
658
|
-
Gladiator::Dir.local_dir.selected_child.ensure_find_next
|
659
|
-
}
|
660
|
-
on_key_pressed { |key_event|
|
661
|
-
if key_event.keyCode == swt(:cr)
|
662
|
-
Gladiator::Dir.local_dir.selected_child.replace_next!
|
663
|
-
elsif key_event.keyCode == swt(:esc)
|
664
|
-
@text.swt_widget.setFocus
|
665
|
-
end
|
666
|
-
}
|
667
|
-
}
|
668
|
-
}
|
669
|
-
composite {
|
670
|
-
layout_data :fill, :fill, true, true
|
671
|
-
grid_layout 2, false
|
672
|
-
@line_numbers_text = text(:multi) {
|
673
|
-
layout_data(:right, :fill, false, true)
|
674
|
-
font name: 'Consolas', height: 15
|
675
|
-
background color(:widget_background)
|
676
|
-
foreground rgb(75, 75, 75)
|
677
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.line_numbers_content')
|
678
|
-
top_index bind(Gladiator::Dir.local_dir, 'selected_child.top_index')
|
679
|
-
on_focus_gained {
|
680
|
-
@text&.swt_widget.setFocus
|
681
|
-
}
|
682
|
-
on_key_pressed {
|
683
|
-
@text&.swt_widget.setFocus
|
684
|
-
}
|
685
|
-
on_mouse_up {
|
686
|
-
@text&.swt_widget.setFocus
|
687
|
-
}
|
688
|
-
}
|
689
|
-
@text = text(:multi, :border, :h_scroll, :v_scroll) {
|
690
|
-
layout_data :fill, :fill, true, true
|
691
|
-
font name: 'Consolas', height: 15
|
692
|
-
foreground rgb(75, 75, 75)
|
693
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.dirty_content')
|
694
|
-
focus true
|
695
|
-
caret_position bind(Gladiator::Dir.local_dir, 'selected_child.caret_position')
|
696
|
-
selection_count bind(Gladiator::Dir.local_dir, 'selected_child.selection_count')
|
697
|
-
top_index bind(Gladiator::Dir.local_dir, 'selected_child.top_index')
|
698
|
-
on_focus_lost {
|
699
|
-
Gladiator::Dir.local_dir.selected_child&.write_dirty_content
|
700
|
-
}
|
701
|
-
on_key_pressed { |key_event|
|
702
|
-
if Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '/'
|
703
|
-
Gladiator::Dir.local_dir.selected_child.comment_line!
|
704
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'k'
|
705
|
-
Gladiator::Dir.local_dir.selected_child.kill_line!
|
706
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'd'
|
707
|
-
Gladiator::Dir.local_dir.selected_child.duplicate_line!
|
708
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '['
|
709
|
-
Gladiator::Dir.local_dir.selected_child.outdent!
|
710
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == ']'
|
711
|
-
Gladiator::Dir.local_dir.selected_child.indent!
|
712
|
-
elsif key_event.keyCode == swt(:page_up)
|
713
|
-
Gladiator::Dir.local_dir.selected_child.page_up
|
714
|
-
key_event.doit = false
|
715
|
-
elsif key_event.keyCode == swt(:page_down)
|
716
|
-
Gladiator::Dir.local_dir.selected_child.page_down
|
717
|
-
key_event.doit = false
|
718
|
-
elsif key_event.keyCode == swt(:home)
|
719
|
-
Gladiator::Dir.local_dir.selected_child.home
|
720
|
-
key_event.doit = false
|
721
|
-
elsif key_event.keyCode == swt(:end)
|
722
|
-
Gladiator::Dir.local_dir.selected_child.end
|
723
|
-
key_event.doit = false
|
724
|
-
elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:arrow_up)
|
725
|
-
Gladiator::Dir.local_dir.selected_child.move_up!
|
726
|
-
key_event.doit = false
|
727
|
-
elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:arrow_down)
|
728
|
-
Gladiator::Dir.local_dir.selected_child.move_down!
|
729
|
-
key_event.doit = false
|
730
|
-
end
|
731
|
-
}
|
732
|
-
on_verify_text { |verify_event|
|
733
|
-
key_code = verify_event.keyCode
|
734
|
-
case key_code
|
735
|
-
when swt(:tab)
|
736
|
-
verify_event.text = ' '
|
737
|
-
end
|
738
|
-
}
|
739
|
-
}
|
740
|
-
}
|
741
|
-
}
|
742
|
-
}
|
743
|
-
observe(Gladiator::Dir.local_dir, 'selected_child.line_numbers_content') do
|
744
|
-
if @last_line_numbers_content != Gladiator::Dir.local_dir.selected_child.line_numbers_content
|
745
|
-
@shell.pack_same_size
|
746
|
-
@last_line_numbers_content = Gladiator::Dir.local_dir.selected_child.line_numbers_content
|
747
|
-
end
|
748
|
-
end
|
749
|
-
observe(Gladiator::Dir.local_dir, 'selected_child.caret_position') do
|
750
|
-
save_config
|
751
|
-
end
|
752
|
-
observe(Gladiator::Dir.local_dir, 'selected_child.top_index') do
|
753
|
-
save_config
|
754
|
-
end
|
755
|
-
@shell.open
|
756
|
-
end
|
757
|
-
end
|
758
|
-
|
759
|
-
@gladiator = Gladiator.new
|
760
|
-
|
761
|
-
at_exit do
|
762
|
-
Gladiator::Dir.local_dir.selected_child&.write_raw_dirty_content
|
763
|
-
end
|
764
|
-
|
765
|
-
@gladiator.launch
|