glimmer-cs-gladiator 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/models/glimmer/gladiator/dir.rb +1 -4
- data/lib/models/glimmer/gladiator/file.rb +73 -46
- data/lib/views/glimmer/gladiator/text_editor.rb +95 -0
- data/lib/views/glimmer/gladiator.rb +79 -94
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f660a554a1e716632a2eec69dc0204d014b93b8f2e10f35f0c6b3b5a29563a47
|
4
|
+
data.tar.gz: cb7758e6669b03bfbdc8925e2c6639885db5406e424edc0860bb7e713c20181c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a3f4d16e7b301079ccf0af079b53304b07d392ecb12f9f9512366fd95e13ed7b658e5dfeb4f8510aa50b2d49fd4b4ed96c14cdcb0bf7049b06a594500445009
|
7
|
+
data.tar.gz: 184c54cea2a6411bd5a82b078939c637b27cdb37a238e37301447655dc7e7bb646776e3ce247e57d59c088ccd5efbb407870c753b8f3511ad8dbf1604993c7ff
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Gladiator (Glimmer Editor) 0.1.
|
1
|
+
# Gladiator (Glimmer Editor) 0.1.3 - Glimmer Custom Shell
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/glimmer-cs-gladiator.svg)](http://badge.fury.io/rb/glimmer-cs-gladiator)
|
3
3
|
|
4
4
|
![Gladiator](images/glimmer-gladiator.png)
|
@@ -14,7 +14,8 @@ Gladiator currently supports the following text editing features:
|
|
14
14
|
- Find & Replace
|
15
15
|
- Show Line Numbers
|
16
16
|
- Jump to Line
|
17
|
-
-
|
17
|
+
- Multiple tab support
|
18
|
+
- Remember last opened file, caret position, top line, window size, and window location
|
18
19
|
- Autosave on focus out/quit/open new file
|
19
20
|
- Watch open file for external changes to reflect in editor
|
20
21
|
- Watch subdirectories for changes to reflect in file explorer/file lookup
|
@@ -50,7 +51,7 @@ To reuse Gladiator as a Glimmer Custom Shell inside another Glimmer application,
|
|
50
51
|
following to the application's `Gemfile`:
|
51
52
|
|
52
53
|
```
|
53
|
-
gem 'glimmer-cs-gladiator', '0.1.
|
54
|
+
gem 'glimmer-cs-gladiator', '0.1.3'
|
54
55
|
```
|
55
56
|
|
56
57
|
Run:
|
@@ -24,7 +24,7 @@ module Glimmer
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
attr_accessor :selected_child, :filter, :children, :filtered_path_options
|
27
|
+
attr_accessor :selected_child, :filter, :children, :filtered_path_options, :filtered_path
|
28
28
|
attr_reader :path, :display_path
|
29
29
|
|
30
30
|
def initialize(path)
|
@@ -102,9 +102,6 @@ module Glimmer
|
|
102
102
|
@selected_child&.path
|
103
103
|
end
|
104
104
|
|
105
|
-
alias filtered_path selected_child_path
|
106
|
-
alias filtered_path= selected_child_path=
|
107
|
-
|
108
105
|
def to_s
|
109
106
|
path
|
110
107
|
end
|
@@ -6,11 +6,12 @@ module Glimmer
|
|
6
6
|
include Glimmer
|
7
7
|
|
8
8
|
attr_accessor :dirty_content, :line_numbers_content, :caret_position, :selection_count, :line_number, :find_text, :replace_text, :top_index
|
9
|
-
attr_reader :path, :display_path
|
9
|
+
attr_reader :path, :display_path, :name
|
10
10
|
|
11
11
|
def initialize(path)
|
12
12
|
raise "Not a file path: #{path}" unless ::File.file?(path)
|
13
13
|
@display_path = path
|
14
|
+
@name = ::File.basename(path)
|
14
15
|
@path = ::File.expand_path(path)
|
15
16
|
read_dirty_content = ::File.read(path)
|
16
17
|
begin
|
@@ -28,7 +29,7 @@ module Glimmer
|
|
28
29
|
if line_number
|
29
30
|
line_index = line_number - 1
|
30
31
|
new_caret_position = caret_position_for_line_index(line_index)
|
31
|
-
self.caret_position = new_caret_position unless line_index_for_caret_position(new_caret_position) == line_index_for_caret_position(caret_position)
|
32
|
+
self.caret_position = new_caret_position unless self.caret_position && line_index_for_caret_position(new_caret_position) == line_index_for_caret_position(caret_position)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
rescue
|
@@ -57,18 +58,22 @@ module Glimmer
|
|
57
58
|
def stop_filewatcher
|
58
59
|
@filewatcher&.stop
|
59
60
|
end
|
60
|
-
|
61
|
-
def
|
61
|
+
|
62
|
+
def format_dirty_content_for_writing!
|
62
63
|
new_dirty_content = "#{dirty_content.gsub("\r\n", "\n").gsub("\r", "\n").sub(/\n+\z/, '')}\n"
|
63
64
|
self.dirty_content = new_dirty_content if new_dirty_content != self.dirty_content
|
64
|
-
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_dirty_content
|
68
|
+
format_dirty_content_for_writing!
|
69
|
+
::File.write(path, dirty_content) if ::File.exists?(path)
|
65
70
|
rescue => e
|
66
71
|
puts "Error in writing dirty content for #{path}"
|
67
72
|
puts e.full_message
|
68
73
|
end
|
69
74
|
|
70
75
|
def write_raw_dirty_content
|
71
|
-
::File.write(path, dirty_content) if ::File.exists?(path)
|
76
|
+
::File.write(path, dirty_content) if ::File.exists?(path)
|
72
77
|
rescue => e
|
73
78
|
puts "Error in writing raw dirty content for #{path}"
|
74
79
|
puts e.full_message
|
@@ -99,7 +104,7 @@ module Glimmer
|
|
99
104
|
end
|
100
105
|
end
|
101
106
|
self.dirty_content = new_lines.join("\n")
|
102
|
-
if old_selection_count > 0
|
107
|
+
if old_selection_count.to_i > 0
|
103
108
|
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
104
109
|
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
105
110
|
else
|
@@ -125,7 +130,7 @@ module Glimmer
|
|
125
130
|
end
|
126
131
|
old_caret_position = self.caret_position
|
127
132
|
self.dirty_content = new_lines.join("\n")
|
128
|
-
if old_selection_count > 0
|
133
|
+
if old_selection_count.to_i > 0
|
129
134
|
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
130
135
|
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
131
136
|
else
|
@@ -154,7 +159,7 @@ module Glimmer
|
|
154
159
|
end
|
155
160
|
end
|
156
161
|
self.dirty_content = new_lines.join("\n")
|
157
|
-
if old_selection_count > 0
|
162
|
+
if old_selection_count.to_i > 0
|
158
163
|
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
159
164
|
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
160
165
|
else
|
@@ -166,12 +171,15 @@ module Glimmer
|
|
166
171
|
|
167
172
|
def kill_line!
|
168
173
|
new_lines = lines
|
169
|
-
return if new_lines.size <
|
174
|
+
return if new_lines.size < 1
|
170
175
|
line_indices = line_indices_for_selection(caret_position, selection_count)
|
171
176
|
new_lines = new_lines[0...line_indices.first] + new_lines[(line_indices.last+1)...new_lines.size]
|
172
177
|
old_caret_position = self.caret_position
|
173
|
-
self.
|
174
|
-
|
178
|
+
old_line_index = self.line_number - 1
|
179
|
+
line_position = line_position_for_caret_position(old_caret_position)
|
180
|
+
self.dirty_content = "#{new_lines.join("\n")}\n"
|
181
|
+
self.caret_position = caret_position_for_line_index(old_line_index) + [line_position, lines[old_line_index].to_s.size].min
|
182
|
+
self.selection_count = 0
|
175
183
|
end
|
176
184
|
|
177
185
|
def duplicate_line!
|
@@ -190,7 +198,7 @@ module Glimmer
|
|
190
198
|
new_lines.insert(the_line_indices.first + i, the_line)
|
191
199
|
end
|
192
200
|
self.dirty_content = new_lines.join("\n")
|
193
|
-
if old_selection_count > 0
|
201
|
+
if old_selection_count.to_i > 0
|
194
202
|
self.caret_position = caret_position_for_line_index(old_caret_position_line_index)
|
195
203
|
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position)
|
196
204
|
else
|
@@ -202,12 +210,21 @@ module Glimmer
|
|
202
210
|
return if find_text.to_s.empty?
|
203
211
|
all_lines = lines
|
204
212
|
the_line_index = line_index_for_caret_position(caret_position)
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
213
|
+
line_position = line_position_for_caret_position(caret_position)
|
214
|
+
found =
|
215
|
+
2.times do |i|
|
216
|
+
rotation = the_line_index
|
217
|
+
all_lines.rotate(rotation).each_with_index do |the_line, the_index|
|
218
|
+
the_index = (the_index + rotation)%all_lines.size
|
219
|
+
start_position = 0
|
220
|
+
start_position = line_position + find_text.to_s.size if i == 0 && the_index == the_line_index && found_text?(caret_position)
|
221
|
+
text_to_find_in = the_line.downcase[start_position..-1]
|
222
|
+
occurrence_index = text_to_find_in.index(find_text.to_s.downcase)
|
223
|
+
if occurrence_index
|
224
|
+
self.caret_position = caret_position_for_line_index(the_index) + start_position + occurrence_index
|
225
|
+
self.selection_count = find_text.to_s.size
|
226
|
+
return
|
227
|
+
end
|
211
228
|
end
|
212
229
|
end
|
213
230
|
end
|
@@ -216,21 +233,34 @@ module Glimmer
|
|
216
233
|
return if find_text.to_s.empty?
|
217
234
|
all_lines = lines
|
218
235
|
the_line_index = line_index_for_caret_position(caret_position)
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
236
|
+
line_position = line_position_for_caret_position(caret_position)
|
237
|
+
2.times do |i|
|
238
|
+
rotation = - the_line_index - 1 + all_lines.size
|
239
|
+
all_lines.reverse.rotate(rotation).each_with_index do |the_line, the_index|
|
240
|
+
the_index = all_lines.size - 1 - (the_index + rotation)%all_lines.size
|
241
|
+
if the_index == the_line_index
|
242
|
+
start_position = i > 0 ? 0 : (the_line.size - line_position)
|
243
|
+
else
|
244
|
+
start_position = 0
|
245
|
+
end
|
246
|
+
text_to_find_in = the_line.downcase.reverse[start_position...the_line.size].to_s
|
247
|
+
occurrence_index = text_to_find_in.index(find_text.to_s.downcase.reverse)
|
248
|
+
if occurrence_index
|
249
|
+
self.caret_position = caret_position_for_line_index(the_index) + (the_line.size - (start_position + occurrence_index + find_text.to_s.size))
|
250
|
+
self.selection_count = find_text.to_s.size
|
251
|
+
return
|
252
|
+
end
|
227
253
|
end
|
228
254
|
end
|
229
255
|
end
|
230
256
|
|
231
257
|
def ensure_find_next
|
232
258
|
return if find_text.to_s.empty? || dirty_content.to_s.strip.size < 1
|
233
|
-
find_next unless
|
259
|
+
find_next unless found_text?(self.caret_position)
|
260
|
+
end
|
261
|
+
|
262
|
+
def found_text?(caret_position)
|
263
|
+
dirty_content[caret_position.to_i, find_text.to_s.size].to_s.downcase == find_text.to_s.downcase
|
234
264
|
end
|
235
265
|
|
236
266
|
def replace_next!
|
@@ -263,23 +293,18 @@ module Glimmer
|
|
263
293
|
return if old_lines.size < 2
|
264
294
|
old_selection_count = self.selection_count
|
265
295
|
old_caret_position = self.caret_position
|
266
|
-
|
267
|
-
|
296
|
+
old_caret_position_line_caret_position = caret_position_for_caret_position_start_of_line(old_caret_position)
|
297
|
+
old_caret_position_line_position = old_caret_position - old_caret_position_line_caret_position
|
268
298
|
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
269
299
|
new_lines = lines
|
270
300
|
the_line_indices = line_indices_for_selection(caret_position, selection_count)
|
271
301
|
the_lines = lines_for_selection(caret_position, selection_count)
|
272
302
|
new_line_index = [the_line_indices.first - 1, 0].max
|
273
|
-
delta = -1 * (new_lines[new_line_index].size + 1)
|
274
303
|
new_lines[the_line_indices.first..the_line_indices.last] = []
|
275
304
|
new_lines[new_line_index...new_line_index] = the_lines
|
276
305
|
self.dirty_content = new_lines.join("\n")
|
277
|
-
|
278
|
-
|
279
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position + delta)
|
280
|
-
else
|
281
|
-
self.caret_position = old_caret_position + delta
|
282
|
-
end
|
306
|
+
self.caret_position = caret_position_for_line_index(new_line_index) + [old_caret_position_line_position, new_lines[new_line_index].size].min
|
307
|
+
self.selection_count = old_selection_count.to_i if old_selection_count.to_i > 0
|
283
308
|
end
|
284
309
|
|
285
310
|
def move_down!
|
@@ -287,23 +312,18 @@ module Glimmer
|
|
287
312
|
return if old_lines.size < 2
|
288
313
|
old_selection_count = self.selection_count
|
289
314
|
old_caret_position = self.caret_position
|
290
|
-
|
291
|
-
|
315
|
+
old_caret_position_line_caret_position = caret_position_for_caret_position_start_of_line(old_caret_position)
|
316
|
+
old_caret_position_line_position = old_caret_position - old_caret_position_line_caret_position
|
292
317
|
old_end_caret_line_index = end_caret_position_line_index(caret_position, selection_count)
|
293
318
|
new_lines = lines
|
294
319
|
the_line_indices = line_indices_for_selection(caret_position, selection_count)
|
295
320
|
the_lines = lines_for_selection(caret_position, selection_count)
|
296
321
|
new_line_index = [the_line_indices.first + 1, new_lines.size - 1].min
|
297
|
-
delta = new_lines[new_line_index].size + 1
|
298
322
|
new_lines[the_line_indices.first..the_line_indices.last] = []
|
299
323
|
new_lines[new_line_index...new_line_index] = the_lines
|
300
324
|
self.dirty_content = new_lines.join("\n")
|
301
|
-
|
302
|
-
|
303
|
-
self.selection_count = (caret_position_for_line_index(old_end_caret_line_index + 1) - self.caret_position + delta)
|
304
|
-
else
|
305
|
-
self.caret_position = old_caret_position + delta
|
306
|
-
end
|
325
|
+
self.caret_position = caret_position_for_line_index(new_line_index) + [old_caret_position_line_position, new_lines[new_line_index].size].min
|
326
|
+
self.selection_count = old_selection_count.to_i if old_selection_count.to_i > 0
|
307
327
|
end
|
308
328
|
|
309
329
|
def lines
|
@@ -327,6 +347,13 @@ module Glimmer
|
|
327
347
|
def caret_position_for_caret_position_start_of_line(caret_position)
|
328
348
|
caret_position_for_line_index(line_index_for_caret_position(caret_position))
|
329
349
|
end
|
350
|
+
|
351
|
+
# position within line containing "caret position" (e.g. for caret position 5 in 1st line, they match as 5, for 15 in line 2 with line 1 having 10 characters, line position is 4)
|
352
|
+
# TODO consider renaming to line_character_position_for_caret_position
|
353
|
+
def line_position_for_caret_position(caret_position)
|
354
|
+
caret_position = caret_position.to_i
|
355
|
+
caret_position - caret_position_for_caret_position_start_of_line(caret_position)
|
356
|
+
end
|
330
357
|
|
331
358
|
def line_caret_positions_for_selection(caret_position, selection_count)
|
332
359
|
line_indices = line_indices_for_selection(caret_position, selection_count)
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Glimmer
|
2
|
+
class Gladiator
|
3
|
+
class TextEditor
|
4
|
+
include Glimmer::UI::CustomWidget
|
5
|
+
|
6
|
+
options :file
|
7
|
+
|
8
|
+
attr_reader :text_widget
|
9
|
+
|
10
|
+
after_body {
|
11
|
+
@text_widget = @text.swt_widget
|
12
|
+
}
|
13
|
+
|
14
|
+
body {
|
15
|
+
composite {
|
16
|
+
layout_data :fill, :fill, true, true
|
17
|
+
grid_layout 2, false
|
18
|
+
@line_numbers_text = text(:multi) {
|
19
|
+
layout_data(:right, :fill, false, true)
|
20
|
+
font name: 'Consolas', height: 15
|
21
|
+
background color(:widget_background)
|
22
|
+
foreground rgb(75, 75, 75)
|
23
|
+
text bind(file, 'line_numbers_content')
|
24
|
+
top_index bind(file, 'top_index')
|
25
|
+
on_focus_gained {
|
26
|
+
@text&.swt_widget.setFocus
|
27
|
+
}
|
28
|
+
on_key_pressed {
|
29
|
+
@text&.swt_widget.setFocus
|
30
|
+
}
|
31
|
+
on_mouse_up {
|
32
|
+
@text&.swt_widget.setFocus
|
33
|
+
}
|
34
|
+
}
|
35
|
+
@text = text(:multi, :border, :h_scroll, :v_scroll) {
|
36
|
+
layout_data :fill, :fill, true, true
|
37
|
+
font name: 'Consolas', height: 15
|
38
|
+
foreground rgb(75, 75, 75)
|
39
|
+
text bind(file, 'dirty_content')
|
40
|
+
focus true
|
41
|
+
caret_position bind(file, 'caret_position')
|
42
|
+
selection_count bind(file, 'selection_count')
|
43
|
+
top_index bind(file, 'top_index')
|
44
|
+
on_focus_lost {
|
45
|
+
file&.write_dirty_content
|
46
|
+
}
|
47
|
+
on_key_pressed { |key_event|
|
48
|
+
if key_event.stateMask == swt(:command) && key_event.character.chr.downcase == '/'
|
49
|
+
file.comment_line!
|
50
|
+
elsif key_event.stateMask == swt(:command) && key_event.character.chr.downcase == 'k'
|
51
|
+
file.kill_line!
|
52
|
+
elsif key_event.stateMask == swt(:command) && key_event.character.chr.downcase == 'd'
|
53
|
+
file.duplicate_line!
|
54
|
+
elsif key_event.stateMask == swt(:command) && key_event.character.chr.downcase == '['
|
55
|
+
file.outdent!
|
56
|
+
elsif key_event.stateMask == swt(:command) && key_event.character.chr.downcase == ']'
|
57
|
+
file.indent!
|
58
|
+
elsif key_event.keyCode == swt(:page_up)
|
59
|
+
file.page_up
|
60
|
+
key_event.doit = false
|
61
|
+
elsif key_event.keyCode == swt(:page_down)
|
62
|
+
file.page_down
|
63
|
+
key_event.doit = false
|
64
|
+
elsif key_event.keyCode == swt(:home)
|
65
|
+
file.home
|
66
|
+
key_event.doit = false
|
67
|
+
elsif key_event.keyCode == swt(:end)
|
68
|
+
file.end
|
69
|
+
key_event.doit = false
|
70
|
+
elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:arrow_up)
|
71
|
+
file.move_up!
|
72
|
+
key_event.doit = false
|
73
|
+
elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:arrow_down)
|
74
|
+
file.move_down!
|
75
|
+
key_event.doit = false
|
76
|
+
end
|
77
|
+
}
|
78
|
+
on_verify_text { |verify_event|
|
79
|
+
key_code = verify_event.keyCode
|
80
|
+
case key_code
|
81
|
+
when swt(:tab)
|
82
|
+
if file.selection_count.to_i > 0
|
83
|
+
file.indent!
|
84
|
+
verify_event.doit = false
|
85
|
+
else
|
86
|
+
verify_event.text = ' '
|
87
|
+
end
|
88
|
+
end
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'models/glimmer/gladiator/dir'
|
2
2
|
require 'models/glimmer/gladiator/file'
|
3
3
|
|
4
|
+
require 'views/glimmer/gladiator/text_editor'
|
5
|
+
|
4
6
|
Clipboard.implementation = Clipboard::Java
|
5
7
|
Clipboard.copy(Clipboard.paste) # pre-initialize library to avoid slowdown during use
|
6
8
|
|
@@ -24,12 +26,11 @@ module Glimmer
|
|
24
26
|
@config_file_path = ::File.join(local_dir, '.gladiator')
|
25
27
|
@config = {}
|
26
28
|
Gladiator::Dir.local_dir.all_children # pre-caches children
|
27
|
-
load_config
|
28
29
|
@display = display {
|
29
30
|
on_event_keydown { |key_event|
|
30
31
|
if Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'f'
|
31
|
-
if @
|
32
|
-
@find_text.swt_widget.setText @
|
32
|
+
if @text_editor.text_widget.getSelectionText && @text_editor.text_widget.getSelectionText.size > 0
|
33
|
+
@find_text.swt_widget.setText @text_editor.text_widget.getSelectionText
|
33
34
|
end
|
34
35
|
@find_text.swt_widget.selectAll
|
35
36
|
@find_text.swt_widget.setFocus
|
@@ -37,6 +38,26 @@ module Glimmer
|
|
37
38
|
Clipboard.copy(Gladiator::Dir.local_dir.selected_child.path)
|
38
39
|
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'g'
|
39
40
|
Gladiator::Dir.local_dir.selected_child.find_previous
|
41
|
+
# elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'w'
|
42
|
+
# @tab_folder.swt_widget.getItems.each(&:dispose)
|
43
|
+
# elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :alt) && key_event.character.chr.downcase == 'w'
|
44
|
+
# @tab_folder.swt_widget.getItems.each do |ti|
|
45
|
+
# ti.dispose unless ti == @tab_folder.swt_widget.getSelection()
|
46
|
+
# end
|
47
|
+
# elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'w'
|
48
|
+
# @tab_folder.swt_widget.getSelection.each(&:dispose)
|
49
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == ']'
|
50
|
+
@tab_folder.swt_widget.setSelection([@tab_folder.swt_widget.getSelectionIndex() + 1, @tab_folder.swt_widget.getItemCount - 1].min) if @tab_folder.swt_widget.getItemCount > 0
|
51
|
+
@text_editor.text_widget.setFocus
|
52
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == '['
|
53
|
+
@tab_folder.swt_widget.setSelection([@tab_folder.swt_widget.getSelectionIndex() - 1, 0].max) if @tab_folder.swt_widget.getItemCount > 0
|
54
|
+
@text_editor.text_widget.setFocus
|
55
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '1'
|
56
|
+
@tab_folder.swt_widget.setSelection(0) if @tab_folder.swt_widget.getItemCount > 0
|
57
|
+
@text_editor.text_widget.setFocus
|
58
|
+
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '9'
|
59
|
+
@tab_folder.swt_widget.setSelection(@tab_folder.swt_widget.getItemCount - 1) if @tab_folder.swt_widget.getItemCount > 0
|
60
|
+
@text_editor.text_widget.setFocus
|
40
61
|
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'g'
|
41
62
|
Gladiator::Dir.local_dir.selected_child.find_next
|
42
63
|
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'l'
|
@@ -56,20 +77,42 @@ module Glimmer
|
|
56
77
|
#
|
57
78
|
after_body {
|
58
79
|
observe(Gladiator::Dir.local_dir, 'selected_child') do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
80
|
+
selected_file = Gladiator::Dir.local_dir.selected_child
|
81
|
+
found_tab_item = @tab_folder.swt_widget.getItems.detect {|ti| ti.getData('file_path') == selected_file.path}
|
82
|
+
if found_tab_item
|
83
|
+
@tab_folder.swt_widget.setSelection(found_tab_item)
|
84
|
+
@tab_item = found_tab_item.getData('tab_item')
|
85
|
+
@text_editor = found_tab_item.getData('text_editor')
|
86
|
+
else
|
87
|
+
@tab_folder.content {
|
88
|
+
@tab_item = tab_item { |the_tab_item|
|
89
|
+
text selected_file.name
|
90
|
+
fill_layout :horizontal
|
91
|
+
@text_editor = the_text_editor = text_editor(file: selected_file)
|
92
|
+
on_event_show {
|
93
|
+
Gladiator::Dir.local_dir.selected_child = selected_file
|
94
|
+
@tab_item = the_tab_item
|
95
|
+
@text_editor = the_text_editor
|
96
|
+
}
|
97
|
+
}
|
98
|
+
@tab_item.swt_tab_item.setData('file_path', selected_file.path)
|
99
|
+
@tab_item.swt_tab_item.setData('tab_item', @tab_item)
|
100
|
+
@tab_item.swt_tab_item.setData('text_editor', @text_editor)
|
101
|
+
}
|
102
|
+
@tab_folder.swt_widget.setSelection(@tab_item.swt_tab_item)
|
63
103
|
body_root.pack_same_size
|
64
|
-
@last_line_numbers_content = Gladiator::Dir.local_dir.selected_child.line_numbers_content
|
65
104
|
end
|
66
105
|
end
|
106
|
+
observe(Gladiator::Dir.local_dir, 'selected_child') do
|
107
|
+
save_config
|
108
|
+
end
|
67
109
|
observe(Gladiator::Dir.local_dir, 'selected_child.caret_position') do
|
68
110
|
save_config
|
69
111
|
end
|
70
112
|
observe(Gladiator::Dir.local_dir, 'selected_child.top_index') do
|
71
113
|
save_config
|
72
|
-
end
|
114
|
+
end
|
115
|
+
load_config
|
73
116
|
}
|
74
117
|
|
75
118
|
## Add widget content inside custom shell body
|
@@ -87,6 +130,12 @@ module Glimmer
|
|
87
130
|
on_widget_disposed {
|
88
131
|
Gladiator::Dir.local_dir.selected_child&.write_dirty_content
|
89
132
|
}
|
133
|
+
on_control_resized {
|
134
|
+
save_config
|
135
|
+
}
|
136
|
+
on_control_moved {
|
137
|
+
save_config
|
138
|
+
}
|
90
139
|
composite {
|
91
140
|
grid_layout 1, false
|
92
141
|
layout_data(:fill, :fill, false, true) {
|
@@ -104,7 +153,7 @@ module Glimmer
|
|
104
153
|
@list.swt_widget.select(0) if @list.swt_widget.getSelectionIndex() == -1
|
105
154
|
@list.swt_widget.setFocus
|
106
155
|
elsif key_event.keyCode == swt(:esc)
|
107
|
-
@
|
156
|
+
@text_editor.text_widget.setFocus
|
108
157
|
end
|
109
158
|
}
|
110
159
|
}
|
@@ -116,13 +165,13 @@ module Glimmer
|
|
116
165
|
}
|
117
166
|
#visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !!f}
|
118
167
|
selection bind(Gladiator::Dir.local_dir, :filtered_path)
|
119
|
-
|
168
|
+
on_mouse_up {
|
120
169
|
Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
|
121
170
|
}
|
122
171
|
on_key_pressed { |key_event|
|
123
172
|
if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr) || Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :lf)
|
124
173
|
Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
|
125
|
-
@
|
174
|
+
@text_editor.text_widget.setFocus
|
126
175
|
end
|
127
176
|
}
|
128
177
|
}
|
@@ -138,7 +187,7 @@ module Glimmer
|
|
138
187
|
on_key_pressed { |key_event|
|
139
188
|
if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr) || Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :lf)
|
140
189
|
Gladiator::Dir.local_dir.selected_child_path = @tree.swt_widget.getSelection&.first&.getText
|
141
|
-
@
|
190
|
+
@text_editor.text_widget.setFocus
|
142
191
|
end
|
143
192
|
}
|
144
193
|
on_paint_control {
|
@@ -150,10 +199,10 @@ module Glimmer
|
|
150
199
|
}
|
151
200
|
}
|
152
201
|
}
|
153
|
-
composite {
|
202
|
+
@editor_container = composite {
|
154
203
|
grid_layout 1, false
|
155
204
|
layout_data :fill, :fill, true, true
|
156
|
-
|
205
|
+
composite {
|
157
206
|
grid_layout 2, false
|
158
207
|
@file_path_label = styled_text(:none) {
|
159
208
|
layout_data(:fill, :fill, true, false) {
|
@@ -180,7 +229,7 @@ module Glimmer
|
|
180
229
|
text bind(Gladiator::Dir.local_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
|
181
230
|
on_key_pressed { |key_event|
|
182
231
|
if key_event.keyCode == swt(:cr)
|
183
|
-
@
|
232
|
+
@text_editor.text_widget.setFocus
|
184
233
|
end
|
185
234
|
}
|
186
235
|
}
|
@@ -196,7 +245,7 @@ module Glimmer
|
|
196
245
|
if key_event.keyCode == swt(:cr)
|
197
246
|
Gladiator::Dir.local_dir.selected_child.find_next
|
198
247
|
elsif key_event.keyCode == swt(:esc)
|
199
|
-
@
|
248
|
+
@text_editor.text_widget.setFocus
|
200
249
|
end
|
201
250
|
}
|
202
251
|
}
|
@@ -215,87 +264,13 @@ module Glimmer
|
|
215
264
|
if key_event.keyCode == swt(:cr)
|
216
265
|
Gladiator::Dir.local_dir.selected_child.replace_next!
|
217
266
|
elsif key_event.keyCode == swt(:esc)
|
218
|
-
@
|
267
|
+
@text_editor.text_widget.setFocus
|
219
268
|
end
|
220
269
|
}
|
221
270
|
}
|
222
271
|
}
|
223
|
-
|
224
|
-
layout_data
|
225
|
-
grid_layout 2, false
|
226
|
-
@line_numbers_text = text(:multi) {
|
227
|
-
layout_data(:right, :fill, false, true)
|
228
|
-
font name: 'Consolas', height: 15
|
229
|
-
background color(:widget_background)
|
230
|
-
foreground rgb(75, 75, 75)
|
231
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.line_numbers_content')
|
232
|
-
top_index bind(Gladiator::Dir.local_dir, 'selected_child.top_index')
|
233
|
-
on_focus_gained {
|
234
|
-
@text&.swt_widget.setFocus
|
235
|
-
}
|
236
|
-
on_key_pressed {
|
237
|
-
@text&.swt_widget.setFocus
|
238
|
-
}
|
239
|
-
on_mouse_up {
|
240
|
-
@text&.swt_widget.setFocus
|
241
|
-
}
|
242
|
-
}
|
243
|
-
@text = text(:multi, :border, :h_scroll, :v_scroll) {
|
244
|
-
layout_data :fill, :fill, true, true
|
245
|
-
font name: 'Consolas', height: 15
|
246
|
-
foreground rgb(75, 75, 75)
|
247
|
-
text bind(Gladiator::Dir.local_dir, 'selected_child.dirty_content')
|
248
|
-
focus true
|
249
|
-
caret_position bind(Gladiator::Dir.local_dir, 'selected_child.caret_position')
|
250
|
-
selection_count bind(Gladiator::Dir.local_dir, 'selected_child.selection_count')
|
251
|
-
top_index bind(Gladiator::Dir.local_dir, 'selected_child.top_index')
|
252
|
-
on_focus_lost {
|
253
|
-
Gladiator::Dir.local_dir.selected_child&.write_dirty_content
|
254
|
-
}
|
255
|
-
on_key_pressed { |key_event|
|
256
|
-
if Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '/'
|
257
|
-
Gladiator::Dir.local_dir.selected_child.comment_line!
|
258
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'k'
|
259
|
-
Gladiator::Dir.local_dir.selected_child.kill_line!
|
260
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'd'
|
261
|
-
Gladiator::Dir.local_dir.selected_child.duplicate_line!
|
262
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '['
|
263
|
-
Gladiator::Dir.local_dir.selected_child.outdent!
|
264
|
-
elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == ']'
|
265
|
-
Gladiator::Dir.local_dir.selected_child.indent!
|
266
|
-
elsif key_event.keyCode == swt(:page_up)
|
267
|
-
Gladiator::Dir.local_dir.selected_child.page_up
|
268
|
-
key_event.doit = false
|
269
|
-
elsif key_event.keyCode == swt(:page_down)
|
270
|
-
Gladiator::Dir.local_dir.selected_child.page_down
|
271
|
-
key_event.doit = false
|
272
|
-
elsif key_event.keyCode == swt(:home)
|
273
|
-
Gladiator::Dir.local_dir.selected_child.home
|
274
|
-
key_event.doit = false
|
275
|
-
elsif key_event.keyCode == swt(:end)
|
276
|
-
Gladiator::Dir.local_dir.selected_child.end
|
277
|
-
key_event.doit = false
|
278
|
-
elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:arrow_up)
|
279
|
-
Gladiator::Dir.local_dir.selected_child.move_up!
|
280
|
-
key_event.doit = false
|
281
|
-
elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:arrow_down)
|
282
|
-
Gladiator::Dir.local_dir.selected_child.move_down!
|
283
|
-
key_event.doit = false
|
284
|
-
end
|
285
|
-
}
|
286
|
-
on_verify_text { |verify_event|
|
287
|
-
key_code = verify_event.keyCode
|
288
|
-
case key_code
|
289
|
-
when swt(:tab)
|
290
|
-
if Gladiator::Dir.local_dir.selected_child.selection_count.to_i > 0
|
291
|
-
Gladiator::Dir.local_dir.selected_child.indent!
|
292
|
-
verify_event.doit = false
|
293
|
-
else
|
294
|
-
verify_event.text = ' '
|
295
|
-
end
|
296
|
-
end
|
297
|
-
}
|
298
|
-
}
|
272
|
+
@tab_folder = tab_folder {
|
273
|
+
layout_data(:fill, :fill, true, true)
|
299
274
|
}
|
300
275
|
}
|
301
276
|
}
|
@@ -309,16 +284,26 @@ module Glimmer
|
|
309
284
|
Gladiator::Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
|
310
285
|
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]
|
311
286
|
Gladiator::Dir.local_dir.selected_child&.top_index = @config[:top_index] if @config[:top_index]
|
287
|
+
body_root.on_event_show do
|
288
|
+
swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
|
289
|
+
swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
|
290
|
+
@loaded_config = true
|
291
|
+
end
|
312
292
|
end
|
313
293
|
end
|
314
294
|
|
315
295
|
def save_config
|
296
|
+
return unless @loaded_config
|
316
297
|
child = Gladiator::Dir.local_dir.selected_child
|
317
298
|
return if child.nil?
|
318
299
|
@config = {
|
319
300
|
selected_child_path: child.path,
|
320
301
|
caret_position: child.caret_position,
|
321
302
|
top_index: child.top_index,
|
303
|
+
shell_width: swt_widget&.getBounds&.width,
|
304
|
+
shell_height: swt_widget&.getBounds&.height,
|
305
|
+
shell_x: swt_widget&.getBounds&.x,
|
306
|
+
shell_y: swt_widget&.getBounds&.y,
|
322
307
|
}
|
323
308
|
config_yaml = YAML.dump(@config)
|
324
309
|
::File.write(@config_file_path, config_yaml) unless config_yaml.to_s.empty?
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-cs-gladiator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.7.
|
18
|
+
version: 0.7.3
|
19
19
|
name: glimmer
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.7.
|
26
|
+
version: 0.7.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.8.1
|
103
|
+
name: puts_debuggerer
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.8.1
|
97
111
|
description: Gladiator (short for Glimmer Editor) is a Glimmer sample project under
|
98
112
|
on-going development. It is not intended to be a full-fledged editor by any means,
|
99
113
|
yet mostly a fun educational exercise in using Glimmer to build a text editor. Gladiator
|
@@ -116,6 +130,7 @@ files:
|
|
116
130
|
- lib/models/glimmer/gladiator/dir.rb
|
117
131
|
- lib/models/glimmer/gladiator/file.rb
|
118
132
|
- lib/views/glimmer/gladiator.rb
|
133
|
+
- lib/views/glimmer/gladiator/text_editor.rb
|
119
134
|
homepage: http://github.com/AndyObtiva/glimmer-cs-gladiator
|
120
135
|
licenses:
|
121
136
|
- MIT
|