glimmer-cs-gladiator 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f660a554a1e716632a2eec69dc0204d014b93b8f2e10f35f0c6b3b5a29563a47
4
- data.tar.gz: cb7758e6669b03bfbdc8925e2c6639885db5406e424edc0860bb7e713c20181c
3
+ metadata.gz: 3b934c1a94dfd1a6544aeecc4b4be8296ba361725a3c5a668a41411eb6b2d6c5
4
+ data.tar.gz: 6060afe18157c255ad483b26ff1bf137d3f9e7083df4945876ac258e85ef412f
5
5
  SHA512:
6
- metadata.gz: 6a3f4d16e7b301079ccf0af079b53304b07d392ecb12f9f9512366fd95e13ed7b658e5dfeb4f8510aa50b2d49fd4b4ed96c14cdcb0bf7049b06a594500445009
7
- data.tar.gz: 184c54cea2a6411bd5a82b078939c637b27cdb37a238e37301447655dc7e7bb646776e3ce247e57d59c088ccd5efbb407870c753b8f3511ad8dbf1604993c7ff
6
+ metadata.gz: 9f225ed4adab885600d43209c7f21fed87d78b584f47fd9b6a35d07d39b784208d1c8df6ca0e7e8b616cb593a3d35625c48b6ff3c5b4121c49c59ce7a2dcb990
7
+ data.tar.gz: 858eff913bfd012b0aaf9511141cb55f1d427ea57a6b01bb85d7403e3e0e1c5f57000c1878efdacad0504e67949ba59a915d279165669f36d7d410b98922aee8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Gladiator (Glimmer Editor) 0.1.3 - Glimmer Custom Shell
1
+ # Gladiator (Glimmer Editor) 0.1.4 - 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)
@@ -9,20 +9,22 @@ Gladiator is also a personal tool for shaping an editor exactly the way I like.
9
9
  I leave building truly professional text editors to software tooling experts who would hopefully use Glimmer one day.
10
10
 
11
11
  Gladiator currently supports the following text editing features:
12
- - File explorer navigation to open file
13
- - File lookup by name
12
+ - File explorer navigation to open file, rename, delete, add new file, add new directory, or refresh tree
13
+ - File lookup by name ignoring slashes, underscores, and dots to ease lookup
14
+ - Watch open file for external changes to automatically refresh in editor
15
+ - Watch project subdirectories for changes to automatically refresh in file explorer/file lookup
14
16
  - Find & Replace
15
17
  - Show Line Numbers
16
18
  - Jump to Line
17
19
  - Multiple tab support
18
20
  - Remember last opened file, caret position, top line, window size, and window location
19
21
  - Autosave on focus out/quit/open new file
20
- - Watch open file for external changes to reflect in editor
21
- - Watch subdirectories for changes to reflect in file explorer/file lookup
22
- - Duplicate Line(s)
23
- - Kill Line(s)
24
- - Move up one line
25
- - Move down one line
22
+ - Duplicate Line(s)/selection
23
+ - Kill Line(s)/selection
24
+ - Move line/selection up
25
+ - Move line/selection down
26
+ - Comment/Uncomment line/selection
27
+ - Indent/Unindent line/selection
26
28
 
27
29
  ## Pre-requisites
28
30
 
@@ -51,7 +53,7 @@ To reuse Gladiator as a Glimmer Custom Shell inside another Glimmer application,
51
53
  following to the application's `Gemfile`:
52
54
 
53
55
  ```
54
- gem 'glimmer-cs-gladiator', '0.1.3'
56
+ gem 'glimmer-cs-gladiator', '0.1.4'
55
57
  ```
56
58
 
57
59
  Run:
@@ -15,41 +15,66 @@ module Glimmer
15
15
  @thread = Thread.new(@filewatcher) do |fw|
16
16
  fw.watch do |filename, event|
17
17
  if @last_update.nil? || (Time.now.to_f - @last_update) > REFRESH_DELAY
18
- dir.refresh if filename != dir.selected_child_path
18
+ dir.refresh if !filename.include?('new_file') && !dir.selected_child_path_history.include?(filename) && filename != dir.selected_child_path
19
19
  end
20
20
  @last_update = Time.now.to_f
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
25
25
  end
26
26
 
27
- attr_accessor :selected_child, :filter, :children, :filtered_path_options, :filtered_path
28
- attr_reader :path, :display_path
27
+ attr_accessor :selected_child, :filter, :children, :filtered_path_options, :filtered_path, :path, :display_path
28
+ attr_reader :name, :parent
29
+ attr_writer :all_children, :children
29
30
 
30
31
  def initialize(path)
31
- @path = @display_path = path
32
+ @display_path = path
33
+ @path = ::File.expand_path(@display_path)
34
+ @name = ::File.basename(::File.expand_path(path))
32
35
  self.filtered_path_options = []
33
36
  end
37
+
38
+ def name=(the_name)
39
+ self.display_path = display_path.sub(/#{Regexp.escape(@name)}$/, the_name)
40
+ @name = the_name
41
+ new_path = ::File.expand_path(display_path)
42
+ FileUtils.mv(path, new_path)
43
+ self.path = display_path
44
+ end
34
45
 
35
46
  def children
36
47
  @children ||= retrieve_children
37
48
  end
38
-
49
+
39
50
  def retrieve_children
40
- ::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 }
51
+ ::Dir.glob(::File.join(@display_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 }
41
52
  end
42
53
 
43
- def refresh
54
+ def selected_child_path_history
55
+ @selected_child_path_history ||= []
56
+ end
57
+
58
+ def pause_refresh
59
+ @refresh_paused = true
60
+ end
61
+
62
+ def resume_refresh
63
+ @refresh_paused = false
64
+ end
65
+
66
+ def refresh(async: true, force: false)
67
+ return if @refresh_paused && !force
44
68
  new_all_children = retrieve_all_children
45
- new_children = retrieve_children
46
- async_exec do
47
- @all_children = new_all_children
48
- @children ||= []
49
- @children.clear
50
- new_children.each do |child|
51
- @children << child
52
- end
69
+ new_children = retrieve_children
70
+ refresh_operation = lambda do
71
+ self.all_children = new_all_children
72
+ self.children = new_children
73
+ end
74
+ if async
75
+ async_exec(&refresh_operation)
76
+ else
77
+ sync_exec(&refresh_operation)
53
78
  end
54
79
  end
55
80
 
@@ -66,7 +91,7 @@ module Glimmer
66
91
  return if filter.nil?
67
92
  all_children_files.select do |child|
68
93
  child.path.downcase.include?(filter.downcase) ||
69
- child.path.downcase.gsub(/[_\/]/, '').include?(filter.downcase)
94
+ child.path.downcase.gsub(/[_\/\.]/, '').include?(filter.downcase)
70
95
  end.sort_by {|c| c.path.to_s.downcase}
71
96
  end
72
97
 
@@ -75,7 +100,7 @@ module Glimmer
75
100
  end
76
101
 
77
102
  def retrieve_all_children
78
- ::Dir.glob(::File.join(@path, '**', '*')).map {|p| ::File.file?(p) ? Gladiator::File.new(p) : Gladiator::Dir.new(p)}
103
+ ::Dir.glob(::File.join(@display_path, '**', '*')).map {|p| ::File.file?(p) ? Gladiator::File.new(p) : Gladiator::Dir.new(p)}
79
104
  end
80
105
 
81
106
  def all_children_files
@@ -83,24 +108,34 @@ module Glimmer
83
108
  end
84
109
 
85
110
  def selected_child_path=(selected_path)
86
- if selected_path && ::File.file?(selected_path)
111
+ return if selected_path.nil? ||
112
+ ::Dir.exist?(selected_path) ||
113
+ (selected_child && ::File.expand_path(selected_child.path) == ::File.expand_path(selected_path))
114
+ if ::File.file?(selected_path)
87
115
  @selected_child&.write_dirty_content
88
116
  new_child = Gladiator::File.new(selected_path)
89
117
  begin
90
118
  unless new_child.dirty_content.nil?
91
119
  self.selected_child&.stop_filewatcher
120
+ selected_child_path_history << self.selected_child.path if self.selected_child
92
121
  self.selected_child = new_child
93
122
  self.selected_child.start_filewatcher
94
123
  end
95
124
  rescue
96
125
  # no op
97
126
  end
127
+ else
128
+ refresh
98
129
  end
99
130
  end
100
131
 
101
132
  def selected_child_path
102
133
  @selected_child&.path
103
134
  end
135
+
136
+ def delete!
137
+ FileUtils.rm_rf(path)
138
+ end
104
139
 
105
140
  def to_s
106
141
  path
@@ -5,8 +5,8 @@ module Glimmer
5
5
  class File
6
6
  include Glimmer
7
7
 
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, :name
8
+ attr_accessor :line_numbers_content, :caret_position, :selection_count, :line_number, :find_text, :replace_text, :top_index, :path, :display_path
9
+ attr_reader :name, :dirty_content
10
10
 
11
11
  def initialize(path)
12
12
  raise "Not a file path: #{path}" unless ::File.file?(path)
@@ -37,6 +37,18 @@ module Glimmer
37
37
  end
38
38
  end
39
39
 
40
+ def name=(the_name)
41
+ self.display_path = display_path.sub(/#{Regexp.escape(@name)}$/, the_name)
42
+ @name = the_name
43
+ new_path = ::File.expand_path(display_path)
44
+ FileUtils.mv(path, new_path)
45
+ self.path = new_path
46
+ end
47
+
48
+ def dirty_content=(the_content)
49
+ @dirty_content = the_content if ::File.exist?(path)
50
+ end
51
+
40
52
  def start_filewatcher
41
53
  @filewatcher = Filewatcher.new(@path)
42
54
  @thread = Thread.new(@filewatcher) do |fw|
@@ -65,6 +77,7 @@ module Glimmer
65
77
  end
66
78
 
67
79
  def write_dirty_content
80
+ return unless ::File.exist?(path)
68
81
  format_dirty_content_for_writing!
69
82
  ::File.write(path, dirty_content) if ::File.exists?(path)
70
83
  rescue => e
@@ -73,12 +86,32 @@ module Glimmer
73
86
  end
74
87
 
75
88
  def write_raw_dirty_content
89
+ return unless ::File.exist?(path)
76
90
  ::File.write(path, dirty_content) if ::File.exists?(path)
77
91
  rescue => e
78
92
  puts "Error in writing raw dirty content for #{path}"
79
93
  puts e.full_message
80
94
  end
81
-
95
+
96
+ def current_line_indentation
97
+ current_line.to_s.match(/^(\s+)/).to_a[1].to_s
98
+ end
99
+
100
+ def current_line
101
+ lines[line_number - 1]
102
+ end
103
+
104
+ def delete!
105
+ FileUtils.rm(path)
106
+ end
107
+
108
+ def insert_new_line!
109
+ the_lines = lines
110
+ the_lines[line_number...line_number] = [current_line_indentation]
111
+ self.dirty_content = the_lines.join("\n")
112
+ self.caret_position = caret_position_for_line_index(line_number) + current_line_indentation.size
113
+ end
114
+
82
115
  def comment_line!
83
116
  old_lines = lines
84
117
  return if old_lines.size < 1
@@ -21,7 +21,7 @@ module Glimmer
21
21
  background color(:widget_background)
22
22
  foreground rgb(75, 75, 75)
23
23
  text bind(file, 'line_numbers_content')
24
- top_index bind(file, 'top_index')
24
+ top_index bind(file, 'top_index', read_only: true)
25
25
  on_focus_gained {
26
26
  @text&.swt_widget.setFocus
27
27
  }
@@ -55,6 +55,8 @@ module Glimmer
55
55
  file.outdent!
56
56
  elsif key_event.stateMask == swt(:command) && key_event.character.chr.downcase == ']'
57
57
  file.indent!
58
+ elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt('cr')
59
+ file.insert_new_line!
58
60
  elsif key_event.keyCode == swt(:page_up)
59
61
  file.page_up
60
62
  key_event.doit = false
@@ -78,6 +80,10 @@ module Glimmer
78
80
  on_verify_text { |verify_event|
79
81
  key_code = verify_event.keyCode
80
82
  case key_code
83
+ when swt(:cr)
84
+ if file.selection_count.to_i == 0
85
+ verify_event.text += file.current_line_indentation
86
+ end
81
87
  when swt(:tab)
82
88
  if file.selection_count.to_i > 0
83
89
  file.indent!
@@ -1,8 +1,17 @@
1
+ begin
2
+ require 'puts_debuggerer' if ENV['puts_debuggerer'].to_s.downcase == 'true'
3
+ rescue LoadError
4
+ # no op
5
+ end
6
+ require 'fileutils'
7
+
1
8
  require 'models/glimmer/gladiator/dir'
2
9
  require 'models/glimmer/gladiator/file'
3
10
 
4
11
  require 'views/glimmer/gladiator/text_editor'
5
12
 
13
+ java_import 'org.eclipse.swt.custom.TreeEditor'
14
+
6
15
  Clipboard.implementation = Clipboard::Java
7
16
  Clipboard.copy(Clipboard.paste) # pre-initialize library to avoid slowdown during use
8
17
 
@@ -22,10 +31,6 @@ module Glimmer
22
31
  #
23
32
  before_body {
24
33
  Display.setAppName('Gladiator')
25
- local_dir = ENV['LOCAL_DIR'] || '.'
26
- @config_file_path = ::File.join(local_dir, '.gladiator')
27
- @config = {}
28
- Gladiator::Dir.local_dir.all_children # pre-caches children
29
34
  @display = display {
30
35
  on_event_keydown { |key_event|
31
36
  if Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'f'
@@ -53,7 +58,28 @@ module Glimmer
53
58
  @tab_folder.swt_widget.setSelection([@tab_folder.swt_widget.getSelectionIndex() - 1, 0].max) if @tab_folder.swt_widget.getItemCount > 0
54
59
  @text_editor.text_widget.setFocus
55
60
  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
61
+ @tab_folder.swt_widget.setSelection(0) if @tab_folder.swt_widget.getItemCount >= 1
62
+ @text_editor.text_widget.setFocus
63
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '2'
64
+ @tab_folder.swt_widget.setSelection(1) if @tab_folder.swt_widget.getItemCount >= 2
65
+ @text_editor.text_widget.setFocus
66
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '3'
67
+ @tab_folder.swt_widget.setSelection(2) if @tab_folder.swt_widget.getItemCount >= 3
68
+ @text_editor.text_widget.setFocus
69
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '4'
70
+ @tab_folder.swt_widget.setSelection(3) if @tab_folder.swt_widget.getItemCount >= 4
71
+ @text_editor.text_widget.setFocus
72
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '5'
73
+ @tab_folder.swt_widget.setSelection(4) if @tab_folder.swt_widget.getItemCount >= 5
74
+ @text_editor.text_widget.setFocus
75
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '6'
76
+ @tab_folder.swt_widget.setSelection(5) if @tab_folder.swt_widget.getItemCount >= 6
77
+ @text_editor.text_widget.setFocus
78
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '7'
79
+ @tab_folder.swt_widget.setSelection(6) if @tab_folder.swt_widget.getItemCount >= 7
80
+ @text_editor.text_widget.setFocus
81
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '8'
82
+ @tab_folder.swt_widget.setSelection(7) if @tab_folder.swt_widget.getItemCount >= 8
57
83
  @text_editor.text_widget.setFocus
58
84
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '9'
59
85
  @tab_folder.swt_widget.setSelection(@tab_folder.swt_widget.getItemCount - 1) if @tab_folder.swt_widget.getItemCount > 0
@@ -68,15 +94,27 @@ module Glimmer
68
94
  @filter_text.swt_widget.setFocus
69
95
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 't'
70
96
  @tree.swt_widget.setFocus
97
+ elsif key_event.keyCode == swt(:esc)
98
+ Dir.local_dir.selected_child_path = @text_editor.file.path
99
+ @text_editor.text_widget.setFocus
71
100
  end
72
101
  }
73
102
  }
103
+
104
+ local_dir = ENV['LOCAL_DIR'] || '.'
105
+ @config_file_path = ::File.join(local_dir, '.gladiator')
106
+ @config = {}
107
+ Gladiator::Dir.local_dir.all_children # pre-caches children
74
108
  }
75
109
 
76
110
  ## Uncomment after_body block to setup observers for widgets in body
77
111
  #
78
112
  after_body {
113
+ observe(Gladiator::Dir.local_dir, 'children') do
114
+ select_tree_item unless @rename_in_progress
115
+ end
79
116
  observe(Gladiator::Dir.local_dir, 'selected_child') do
117
+ select_tree_item unless @rename_in_progress
80
118
  selected_file = Gladiator::Dir.local_dir.selected_child
81
119
  found_tab_item = @tab_folder.swt_widget.getItems.detect {|ti| ti.getData('file_path') == selected_file.path}
82
120
  if found_tab_item
@@ -135,7 +173,7 @@ module Glimmer
135
173
  }
136
174
  on_control_moved {
137
175
  save_config
138
- }
176
+ }
139
177
  composite {
140
178
  grid_layout 1, false
141
179
  layout_data(:fill, :fill, false, true) {
@@ -144,16 +182,13 @@ module Glimmer
144
182
  @filter_text = text {
145
183
  layout_data :fill, :center, true, false
146
184
  text bind(Gladiator::Dir.local_dir, 'filter')
147
- on_key_pressed { |key_event|
185
+ on_key_pressed { |key_event|
148
186
  if key_event.keyCode == swt(:tab) ||
149
187
  key_event.keyCode == swt(:cr) ||
150
- key_event.keyCode == swt(:lf) ||
151
188
  key_event.keyCode == swt(:arrow_up) ||
152
189
  key_event.keyCode == swt(:arrow_down)
153
190
  @list.swt_widget.select(0) if @list.swt_widget.getSelectionIndex() == -1
154
191
  @list.swt_widget.setFocus
155
- elsif key_event.keyCode == swt(:esc)
156
- @text_editor.text_widget.setFocus
157
192
  end
158
193
  }
159
194
  }
@@ -162,6 +197,7 @@ module Glimmer
162
197
  @list = list(:border, :h_scroll, :v_scroll) {
163
198
  layout_data(:fill, :fill, true, true) {
164
199
  #exclude bind(Gladiator::Dir.local_dir, :filter) {|f| !f}
200
+ minimum_height 400
165
201
  }
166
202
  #visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !!f}
167
203
  selection bind(Gladiator::Dir.local_dir, :filtered_path)
@@ -169,7 +205,7 @@ module Glimmer
169
205
  Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
170
206
  }
171
207
  on_key_pressed { |key_event|
172
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr) || Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :lf)
208
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
173
209
  Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
174
210
  @text_editor.text_widget.setFocus
175
211
  end
@@ -180,24 +216,74 @@ module Glimmer
180
216
  #exclude bind(Gladiator::Dir.local_dir, :filter) {|f| !!f}
181
217
  }
182
218
  #visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !f}
183
- items bind(Gladiator::Dir, :local_dir), tree_properties(children: :children, text: :display_path)
184
- on_widget_selected {
185
- Gladiator::Dir.local_dir.selected_child_path = @tree.swt_widget.getSelection.first.getText
219
+ items bind(Gladiator::Dir, :local_dir), tree_properties(children: :children, text: :name)
220
+ menu {
221
+ @open_menu_item = menu_item {
222
+ text 'Open'
223
+ on_widget_selected {
224
+ Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
225
+ }
226
+ }
227
+ menu_item(:separator)
228
+ menu_item {
229
+ text 'Delete'
230
+ on_widget_selected {
231
+ tree_item = @tree.swt_widget.getSelection.first
232
+ delete_tree_item(tree_item)
233
+ }
234
+ }
235
+ menu_item {
236
+ text 'Refresh'
237
+ on_widget_selected {
238
+ Gladiator::Dir.local_dir.refresh
239
+ }
240
+ }
241
+ menu_item {
242
+ text 'Rename'
243
+ on_widget_selected {
244
+ rename_selected_tree_item
245
+ }
246
+ }
247
+ menu_item {
248
+ text 'New Directory'
249
+ on_widget_selected {
250
+ add_new_directory_to_selected_tree_item
251
+ }
252
+ }
253
+ menu_item {
254
+ text 'New File'
255
+ on_widget_selected {
256
+ add_new_file_to_selected_tree_item
257
+ }
258
+ }
259
+ }
260
+ on_event_menudetect { |event|
261
+ path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
262
+ @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
263
+ }
264
+ on_mouse_up {
265
+ Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
186
266
  }
187
267
  on_key_pressed { |key_event|
188
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr) || Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :lf)
189
- Gladiator::Dir.local_dir.selected_child_path = @tree.swt_widget.getSelection&.first&.getText
268
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
269
+ Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
190
270
  @text_editor.text_widget.setFocus
191
271
  end
192
272
  }
193
273
  on_paint_control {
194
274
  root_item = @tree.swt_widget.getItems.first
195
275
  if root_item && !root_item.getExpanded
196
- root_item.setExpanded true
276
+ root_item.setExpanded(true)
197
277
  end
198
278
  }
199
279
  }
200
280
  }
281
+
282
+ @tree_editor = TreeEditor.new(@tree.swt_widget);
283
+ @tree_editor.horizontalAlignment = swt(:left);
284
+ @tree_editor.grabHorizontal = true;
285
+ @tree_editor.minimumHeight = 20;
286
+
201
287
  }
202
288
  @editor_container = composite {
203
289
  grid_layout 1, false
@@ -224,7 +310,7 @@ module Glimmer
224
310
  }
225
311
  @line_number_text = text {
226
312
  layout_data(:fill, :fill, true, false) {
227
- minimum_width 300
313
+ minimum_width 400
228
314
  }
229
315
  text bind(Gladiator::Dir.local_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
230
316
  on_key_pressed { |key_event|
@@ -238,14 +324,12 @@ module Glimmer
238
324
  }
239
325
  @find_text = text {
240
326
  layout_data(:fill, :fill, true, false) {
241
- minimum_width 300
327
+ minimum_width 400
242
328
  }
243
329
  text bind(Gladiator::Dir.local_dir, 'selected_child.find_text')
244
330
  on_key_pressed { |key_event|
245
331
  if key_event.keyCode == swt(:cr)
246
332
  Gladiator::Dir.local_dir.selected_child.find_next
247
- elsif key_event.keyCode == swt(:esc)
248
- @text_editor.text_widget.setFocus
249
333
  end
250
334
  }
251
335
  }
@@ -263,8 +347,6 @@ module Glimmer
263
347
  on_key_pressed { |key_event|
264
348
  if key_event.keyCode == swt(:cr)
265
349
  Gladiator::Dir.local_dir.selected_child.replace_next!
266
- elsif key_event.keyCode == swt(:esc)
267
- @text_editor.text_widget.setFocus
268
350
  end
269
351
  }
270
352
  }
@@ -282,13 +364,13 @@ module Glimmer
282
364
  return if config_yaml.to_s.strip.empty?
283
365
  @config = YAML.load(config_yaml)
284
366
  Gladiator::Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
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]
286
- Gladiator::Dir.local_dir.selected_child&.top_index = @config[:top_index] if @config[:top_index]
287
- body_root.on_event_show do
367
+ 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].to_i) if @config[:caret_position]
368
+ Gladiator::Dir.local_dir.selected_child&.top_index = @config[:top_index].to_i if @config[:top_index]
369
+ body_root.on_event_show {
288
370
  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]
371
+ swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
290
372
  @loaded_config = true
291
- end
373
+ }
292
374
  end
293
375
  end
294
376
 
@@ -310,5 +392,111 @@ module Glimmer
310
392
  rescue => e
311
393
  puts e.full_message
312
394
  end
395
+
396
+ def extract_tree_item_path(tree_item)
397
+ return if tree_item.nil?
398
+ if tree_item.getParentItem
399
+ ::File.join(extract_tree_item_path(tree_item.getParentItem), tree_item.getText)
400
+ else
401
+ '.'
402
+ end
403
+ end
404
+
405
+ def select_tree_item
406
+ return unless Gladiator::Dir.local_dir.selected_child&.name
407
+ tree_items_to_select = @tree.depth_first_search { |ti| ti.getData.path == Gladiator::Dir.local_dir.selected_child.path }
408
+ @tree.swt_widget.setSelection(tree_items_to_select)
409
+ end
410
+
411
+ def delete_tree_item(tree_item)
412
+ file = tree_item.getData
413
+ parent_path = ::File.dirname(file.path)
414
+ file.delete!
415
+ Dir.local_dir.refresh(async: false)
416
+ parent_tree_item = @tree.depth_first_search {|ti| ti.getData.path == parent_path}.first
417
+ @tree.swt_widget.showItem(parent_tree_item)
418
+ parent_tree_item.setExpanded(true)
419
+ # TODO close text editor tab
420
+ # if file.is_a?(::File)
421
+ # close tab
422
+ # end
423
+ end
424
+
425
+ def rename_selected_tree_item
426
+ Dir.local_dir.pause_refresh
427
+ tree_item = @tree.swt_widget.getSelection.first
428
+ rename_tree_item(tree_item)
429
+ end
430
+
431
+ def add_new_directory_to_selected_tree_item
432
+ Dir.local_dir.pause_refresh
433
+ tree_item = @tree.swt_widget.getSelection.first
434
+ directory_path = extract_tree_item_path(tree_item)
435
+ if !::Dir.exist?(directory_path)
436
+ tree_item = tree_item.getParentItem
437
+ directory_path = ::File.dirname(directory_path)
438
+ end
439
+ new_directory_path = ::File.expand_path(::File.join(directory_path, 'new_directory'))
440
+ FileUtils.mkdir_p(new_directory_path)
441
+ Dir.local_dir.refresh(async: false, force: true)
442
+ new_tree_item = @tree.depth_first_search {|ti| ti.getData.path == new_directory_path}.first
443
+ @tree.swt_widget.showItem(new_tree_item)
444
+ rename_tree_item(new_tree_item, true)
445
+ end
446
+
447
+ def add_new_file_to_selected_tree_item
448
+ Dir.local_dir.pause_refresh
449
+ tree_item = @tree.swt_widget.getSelection.first
450
+ directory_path = extract_tree_item_path(tree_item)
451
+ if !::Dir.exist?(directory_path)
452
+ tree_item = tree_item.getParentItem
453
+ directory_path = ::File.dirname(directory_path)
454
+ end
455
+ new_file_path = ::File.expand_path(::File.join(directory_path, 'new_file'))
456
+ FileUtils.touch(new_file_path)
457
+ Dir.local_dir.refresh(async: false, force: true)
458
+ new_tree_item = @tree.depth_first_search {|ti| ti.getData.path == new_file_path}.first
459
+ @tree.swt_widget.showItem(new_tree_item)
460
+ rename_tree_item(new_tree_item, true)
461
+ end
462
+
463
+ def rename_tree_item(tree_item, open_afterwards = false)
464
+ @tree.content {
465
+ @tree_text = text {
466
+ focus true
467
+ text tree_item.getText
468
+ @action_taken = false
469
+ action = lambda { |event|
470
+ if !@action_taken && !@rename_in_progress
471
+ @action_taken = true
472
+ @rename_in_progress = true
473
+ new_text = @tree_text.swt_widget.getText
474
+ tree_item.setText(new_text)
475
+ file = tree_item.getData
476
+ file.name = new_text
477
+ file_path = file.path
478
+ tree_item = @tree.depth_first_search { |ti| ti.getData.path == file_path }
479
+ @tree.swt_widget.showItem(tree_item.first)
480
+ @tree_text.swt_widget.dispose
481
+ Dir.local_dir.selected_child_path = file_path if open_afterwards
482
+ Dir.local_dir.resume_refresh
483
+ @rename_in_progress = false
484
+ end
485
+ }
486
+ on_focus_lost(&action)
487
+ on_key_pressed { |key_event|
488
+ if key_event.keyCode == swt(:cr)
489
+ action.call(key_event)
490
+ elsif key_event.keyCode == swt(:esc)
491
+ @tree_text.swt_widget.dispose
492
+ Dir.local_dir.resume_refresh
493
+ @rename_in_progress = false
494
+ end
495
+ }
496
+ }
497
+ @tree_text.swt_widget.selectAll
498
+ }
499
+ @tree_editor.setEditor(@tree_text.swt_widget, tree_item);
500
+ end
313
501
  end
314
502
  end
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.3
4
+ version: 0.1.4
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-16 00:00:00.000000000 Z
11
+ date: 2020-05-19 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.3
18
+ version: 0.7.4
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.3
26
+ version: 0.7.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements: