glimmer-cs-gladiator 0.1.4 → 0.1.5

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: 3b934c1a94dfd1a6544aeecc4b4be8296ba361725a3c5a668a41411eb6b2d6c5
4
- data.tar.gz: 6060afe18157c255ad483b26ff1bf137d3f9e7083df4945876ac258e85ef412f
3
+ metadata.gz: 62cc5d4c7f27c15b95f6eaad4637a379a8729455532b8d924ce29a21be2c91c9
4
+ data.tar.gz: 43f501030aeca54b6a0339182ee0c064e81b0415a9cd440464950f89b6d83c6f
5
5
  SHA512:
6
- metadata.gz: 9f225ed4adab885600d43209c7f21fed87d78b584f47fd9b6a35d07d39b784208d1c8df6ca0e7e8b616cb593a3d35625c48b6ff3c5b4121c49c59ce7a2dcb990
7
- data.tar.gz: 858eff913bfd012b0aaf9511141cb55f1d427ea57a6b01bb85d7403e3e0e1c5f57000c1878efdacad0504e67949ba59a915d279165669f36d7d410b98922aee8
6
+ metadata.gz: 87353d484e3ab966ef765520ef4463831d37393fc66b5aa88f8dce389b001ef245f83af59e220d54f5fb18cd882f11e919cafda32db94ffc927cbbc086c33d35
7
+ data.tar.gz: 190d7ad3c6305a07763fc34187e12fc5c2bc6a1606f0a6ec8bef546eda63af1f6c38933c792e2f23fee9512948ddfef344ee352504d1d283ae2b1b8ba09be1c7
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Gladiator (Glimmer Editor) 0.1.4 - Glimmer Custom Shell
1
+ # Gladiator (Glimmer Editor) 0.1.5 - 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)
@@ -17,7 +17,7 @@ Gladiator currently supports the following text editing features:
17
17
  - Show Line Numbers
18
18
  - Jump to Line
19
19
  - Multiple tab support
20
- - Remember last opened file, caret position, top line, window size, and window location
20
+ - Remember opened tabs, caret position, top line, window size, and window location
21
21
  - Autosave on focus out/quit/open new file
22
22
  - Duplicate Line(s)/selection
23
23
  - Kill Line(s)/selection
@@ -53,7 +53,7 @@ To reuse Gladiator as a Glimmer Custom Shell inside another Glimmer application,
53
53
  following to the application's `Gemfile`:
54
54
 
55
55
  ```
56
- gem 'glimmer-cs-gladiator', '0.1.4'
56
+ gem 'glimmer-cs-gladiator', '0.1.5'
57
57
  ```
58
58
 
59
59
  Run:
data/bin/gladiator CHANGED
@@ -3,4 +3,11 @@
3
3
  require 'glimmer/launcher'
4
4
 
5
5
  gladiator_runner = File.expand_path('../gladiator_runner.rb', __FILE__)
6
- Glimmer::Launcher.new([gladiator_runner, '-J-Xrs'] + ARGV).launch
6
+ launcher = Glimmer::Launcher.new([gladiator_runner, '-J-Xrs'] + ARGV)
7
+ launcher.application_paths.to_a.each do |file|
8
+ if file != gladiator_runner
9
+ launcher.application_paths.delete(file)
10
+ ENV['LOCAL_DIR'] ||= file
11
+ end
12
+ end
13
+ launcher.launch
@@ -6,13 +6,15 @@ module Glimmer
6
6
  include Glimmer
7
7
 
8
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
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)
13
13
  @display_path = path
14
14
  @name = ::File.basename(path)
15
15
  @path = ::File.expand_path(path)
16
+ @caret_position = 0
17
+ @line_number = 1
16
18
  read_dirty_content = ::File.read(path)
17
19
  begin
18
20
  # test read dirty content
@@ -105,6 +107,13 @@ module Glimmer
105
107
  FileUtils.rm(path)
106
108
  end
107
109
 
110
+ def prefix_new_line!
111
+ the_lines = lines
112
+ the_lines[line_number-1...line_number-1] = [current_line_indentation]
113
+ self.dirty_content = the_lines.join("\n")
114
+ self.caret_position = caret_position_for_line_index(line_number-1) + current_line_indentation.size
115
+ end
116
+
108
117
  def insert_new_line!
109
118
  the_lines = lines
110
119
  the_lines[line_number...line_number] = [current_line_indentation]
@@ -33,70 +33,90 @@ module Glimmer
33
33
  Display.setAppName('Gladiator')
34
34
  @display = display {
35
35
  on_event_keydown { |key_event|
36
- if Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'f'
36
+ if key_event.stateMask == swt(:command) && key_event.character.chr == 'f'
37
37
  if @text_editor.text_widget.getSelectionText && @text_editor.text_widget.getSelectionText.size > 0
38
38
  @find_text.swt_widget.setText @text_editor.text_widget.getSelectionText
39
39
  end
40
40
  @find_text.swt_widget.selectAll
41
41
  @find_text.swt_widget.setFocus
42
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'c'
42
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr == 'c'
43
43
  Clipboard.copy(Gladiator::Dir.local_dir.selected_child.path)
44
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'g'
44
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr == 'g'
45
45
  Gladiator::Dir.local_dir.selected_child.find_previous
46
- # elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == 'w'
47
- # @tab_folder.swt_widget.getItems.each(&:dispose)
48
- # elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :alt) && key_event.character.chr.downcase == 'w'
49
- # @tab_folder.swt_widget.getItems.each do |ti|
50
- # ti.dispose unless ti == @tab_folder.swt_widget.getSelection()
51
- # end
52
- # elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'w'
53
- # @tab_folder.swt_widget.getSelection.each(&:dispose)
54
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == ']'
46
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr == 'w'
47
+ @tab_folder.swt_widget.getItems.each do |tab_item|
48
+ Dir.local_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
49
+ tab_item.getData('proxy').dispose
50
+ end
51
+ @tab_item = @text_editor = Dir.local_dir.selected_child = nil
52
+ @filter_text.swt_widget.selectAll
53
+ @filter_text.swt_widget.setFocus
54
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character == 8721
55
+ other_tab_items.each do |tab_item|
56
+ Dir.local_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
57
+ tab_item.getData('proxy').dispose
58
+ end
59
+ elsif key_event.stateMask == swt(:command) && key_event.character.chr == 'w'
60
+ if selected_tab_item
61
+ Dir.local_dir.selected_child_path_history.delete(Dir.local_dir.selected_child.path)
62
+ selected_tab_item.getData('proxy').dispose
63
+ if selected_tab_item.nil?
64
+ @tab_item = @text_editor = Dir.local_dir.selected_child = nil
65
+ @filter_text.swt_widget.selectAll
66
+ @filter_text.swt_widget.setFocus
67
+ else
68
+ @text_editor.text_widget.setFocus
69
+ end
70
+ end
71
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr == ']'
55
72
  @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
56
73
  @text_editor.text_widget.setFocus
57
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr.downcase == '['
74
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.character.chr == '['
58
75
  @tab_folder.swt_widget.setSelection([@tab_folder.swt_widget.getSelectionIndex() - 1, 0].max) if @tab_folder.swt_widget.getItemCount > 0
59
76
  @text_editor.text_widget.setFocus
60
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '1'
77
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '1'
61
78
  @tab_folder.swt_widget.setSelection(0) if @tab_folder.swt_widget.getItemCount >= 1
62
79
  @text_editor.text_widget.setFocus
63
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '2'
80
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '2'
64
81
  @tab_folder.swt_widget.setSelection(1) if @tab_folder.swt_widget.getItemCount >= 2
65
82
  @text_editor.text_widget.setFocus
66
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '3'
83
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '3'
67
84
  @tab_folder.swt_widget.setSelection(2) if @tab_folder.swt_widget.getItemCount >= 3
68
85
  @text_editor.text_widget.setFocus
69
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '4'
86
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '4'
70
87
  @tab_folder.swt_widget.setSelection(3) if @tab_folder.swt_widget.getItemCount >= 4
71
88
  @text_editor.text_widget.setFocus
72
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '5'
89
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '5'
73
90
  @tab_folder.swt_widget.setSelection(4) if @tab_folder.swt_widget.getItemCount >= 5
74
91
  @text_editor.text_widget.setFocus
75
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '6'
92
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '6'
76
93
  @tab_folder.swt_widget.setSelection(5) if @tab_folder.swt_widget.getItemCount >= 6
77
94
  @text_editor.text_widget.setFocus
78
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '7'
95
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '7'
79
96
  @tab_folder.swt_widget.setSelection(6) if @tab_folder.swt_widget.getItemCount >= 7
80
97
  @text_editor.text_widget.setFocus
81
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '8'
98
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '8'
82
99
  @tab_folder.swt_widget.setSelection(7) if @tab_folder.swt_widget.getItemCount >= 8
83
100
  @text_editor.text_widget.setFocus
84
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == '9'
101
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == '9'
85
102
  @tab_folder.swt_widget.setSelection(@tab_folder.swt_widget.getItemCount - 1) if @tab_folder.swt_widget.getItemCount > 0
86
103
  @text_editor.text_widget.setFocus
87
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'g'
104
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == 'g'
88
105
  Gladiator::Dir.local_dir.selected_child.find_next
89
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'l'
106
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == 'l'
90
107
  @line_number_text.swt_widget.selectAll
91
108
  @line_number_text.swt_widget.setFocus
92
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 'r'
109
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == 'r'
93
110
  @filter_text.swt_widget.selectAll
94
111
  @filter_text.swt_widget.setFocus
95
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr.downcase == 't'
112
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command) && key_event.character.chr == 't'
113
+ select_tree_item unless @rename_in_progress
96
114
  @tree.swt_widget.setFocus
97
115
  elsif key_event.keyCode == swt(:esc)
98
- Dir.local_dir.selected_child_path = @text_editor.file.path
99
- @text_editor.text_widget.setFocus
116
+ if @text_editor
117
+ Dir.local_dir.selected_child_path = @text_editor.file.path
118
+ @text_editor.text_widget.setFocus
119
+ end
100
120
  end
101
121
  }
102
122
  }
@@ -116,12 +136,12 @@ module Glimmer
116
136
  observe(Gladiator::Dir.local_dir, 'selected_child') do
117
137
  select_tree_item unless @rename_in_progress
118
138
  selected_file = Gladiator::Dir.local_dir.selected_child
119
- found_tab_item = @tab_folder.swt_widget.getItems.detect {|ti| ti.getData('file_path') == selected_file.path}
139
+ found_tab_item = selected_tab_item
120
140
  if found_tab_item
121
141
  @tab_folder.swt_widget.setSelection(found_tab_item)
122
142
  @tab_item = found_tab_item.getData('tab_item')
123
143
  @text_editor = found_tab_item.getData('text_editor')
124
- else
144
+ elsif selected_file
125
145
  @tab_folder.content {
126
146
  @tab_item = tab_item { |the_tab_item|
127
147
  text selected_file.name
@@ -136,6 +156,7 @@ module Glimmer
136
156
  @tab_item.swt_tab_item.setData('file_path', selected_file.path)
137
157
  @tab_item.swt_tab_item.setData('tab_item', @tab_item)
138
158
  @tab_item.swt_tab_item.setData('text_editor', @text_editor)
159
+ @tab_item.swt_tab_item.setData('proxy', @tab_item)
139
160
  }
140
161
  @tab_folder.swt_widget.setSelection(@tab_item.swt_tab_item)
141
162
  body_root.pack_same_size
@@ -173,6 +194,9 @@ module Glimmer
173
194
  }
174
195
  on_control_moved {
175
196
  save_config
197
+ }
198
+ on_shell_deactivated {
199
+ @text_editor&.file&.write_dirty_content
176
200
  }
177
201
  composite {
178
202
  grid_layout 1, false
@@ -262,12 +286,13 @@ module Glimmer
262
286
  @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
263
287
  }
264
288
  on_mouse_up {
265
- Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
289
+ Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
290
+ @text_editor&.text_widget&.setFocus
266
291
  }
267
292
  on_key_pressed { |key_event|
268
293
  if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
269
294
  Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
270
- @text_editor.text_widget.setFocus
295
+ @text_editor&.text_widget&.setFocus
271
296
  end
272
297
  }
273
298
  on_paint_control {
@@ -363,6 +388,9 @@ module Glimmer
363
388
  config_yaml = ::File.read(@config_file_path)
364
389
  return if config_yaml.to_s.strip.empty?
365
390
  @config = YAML.load(config_yaml)
391
+ @config[:open_file_paths].to_a.each do |file_path|
392
+ Gladiator::Dir.local_dir.selected_child_path = file_path
393
+ end
366
394
  Gladiator::Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
367
395
  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
396
  Gladiator::Dir.local_dir.selected_child&.top_index = @config[:top_index].to_i if @config[:top_index]
@@ -386,19 +414,28 @@ module Glimmer
386
414
  shell_height: swt_widget&.getBounds&.height,
387
415
  shell_x: swt_widget&.getBounds&.x,
388
416
  shell_y: swt_widget&.getBounds&.y,
417
+ open_file_paths: Dir.local_dir.selected_child_path_history,
389
418
  }
390
419
  config_yaml = YAML.dump(@config)
391
420
  ::File.write(@config_file_path, config_yaml) unless config_yaml.to_s.empty?
392
421
  rescue => e
393
422
  puts e.full_message
394
423
  end
424
+
425
+ def selected_tab_item
426
+ @tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == Gladiator::Dir.local_dir.selected_child&.path }
427
+ end
428
+
429
+ def other_tab_items
430
+ @tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == Gladiator::Dir.local_dir.selected_child&.path }
431
+ end
395
432
 
396
433
  def extract_tree_item_path(tree_item)
397
434
  return if tree_item.nil?
398
435
  if tree_item.getParentItem
399
436
  ::File.join(extract_tree_item_path(tree_item.getParentItem), tree_item.getText)
400
437
  else
401
- '.'
438
+ Dir.local_dir.path
402
439
  end
403
440
  end
404
441
 
@@ -461,42 +498,19 @@ module Glimmer
461
498
  end
462
499
 
463
500
  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
- }
501
+ @tree.edit_tree_item(
502
+ tree_item,
503
+ after_write: -> (edited_tree_item) {
504
+ file = edited_tree_item.getData
505
+ file_path = file.path
506
+ # TODO rename file in tab title
507
+ Dir.local_dir.selected_child_path = file_path if open_afterwards
508
+ Dir.local_dir.resume_refresh
509
+ },
510
+ after_cancel: -> {
511
+ Dir.local_dir.resume_refresh
496
512
  }
497
- @tree_text.swt_widget.selectAll
498
- }
499
- @tree_editor.setEditor(@tree_text.swt_widget, tree_item);
513
+ )
500
514
  end
501
515
  end
502
516
  end
@@ -55,7 +55,9 @@ 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')
58
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :command, :shift) && key_event.keyCode == swt(:cr)
59
+ file.prefix_new_line!
60
+ elsif key_event.stateMask == swt(:command) && key_event.keyCode == swt(:cr)
59
61
  file.insert_new_line!
60
62
  elsif key_event.keyCode == swt(:page_up)
61
63
  file.page_up
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-cs-gladiator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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-19 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement