glimmer-cs-gladiator 0.1.8 → 0.2.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: d1fedd5416ae759bea0cbfa6d14572cedd58f74d14c544a187efb9310c5954c3
4
- data.tar.gz: fd0d141721cb77e391c6a07aea9bbb637d326c22374ffc5e2f157487116f59a2
3
+ metadata.gz: 1d7db15419bc0913d01e3e15634e12833a1f36a7fc3160e2a7835ab6560832af
4
+ data.tar.gz: 6e55a2c18985603a0b6438198fad5959bcea27b65a8e43b8a810fd42ec5fda76
5
5
  SHA512:
6
- metadata.gz: 19c5ae152d5bbe45f434c06da679b1779b844ad180cca79a945f4368d05bb50a2342ca5d085a1ad7c8b06b6aa5a97548c98d4487ee66f0b0be3f4a16089c7d74
7
- data.tar.gz: 3acdffb642c32c894af12b9f4fa27f51a4b04eba7c13dbedc6a5c89e6dc97da7dd1cd79c3c93a75c2c0e7318866d3de33b58ad269ffee29b221632ff21b02348
6
+ metadata.gz: bae9a2b2eb76cf9ca64ec0d76216fa8aa7c12e97805dbfee42dace54deceedba6eeb1579b65cbdb7c1ad595a44e5768ac372619db804f5fbc240ee52afbecb4d
7
+ data.tar.gz: 56186b8a8d31dc8974ff4f35afd4f7a37d4932cea6b1c4517832ae760ec1f6c5d0092c6048a5f333bf1e438bd514ccd2db3a6ca0ac45d35a519d35194861c251
data/README.md CHANGED
@@ -1,15 +1,18 @@
1
- # Gladiator (Glimmer Editor) 0.1.8 - Glimmer Custom Shell
1
+ # <img src='https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-gladiator/master/images/glimmer-cs-gladiator-logo.svg' height=85 /> Gladiator 0.2.4 - [Ugliest Text Editor Ever](https://www.reddit.com/r/ruby/comments/hgve8k/gladiator_glimmer_editor_ugliest_text_editor_ever/)
2
+ ## [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 /> Glimmer Custom Shell](https://github.com/AndyObtiva/glimmer#custom-shell-gem)
2
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-cs-gladiator.svg)](http://badge.fury.io/rb/glimmer-cs-gladiator)
3
4
 
4
5
  ![Gladiator](images/glimmer-gladiator.png)
5
6
 
6
- Gladiator (short for Glimmer Editor) is a Glimmer sample project under on-going development.
7
- It is not intended to be a full-fledged editor by any means, yet mostly a fun educational exercise in using Glimmer to build a text editor.
8
- Gladiator is also a personal tool for shaping an editor exactly the way I like.
9
- I leave building truly professional text editors to software tooling experts who would hopefully use Glimmer one day.
7
+ Gladiator (short for Glimmer Editor) is a [Glimmer](https://github.com/AndyObtiva/glimmer) sample project under on-going development that demonstrates how to build a text editor in [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library).
8
+ It is not intended to be a full-fledged editor by any means, yet mostly a fun educational exercise in using [Glimmer](https://github.com/AndyObtiva/glimmer).
9
+ Gladiator is also a personal tool for shaping an editor exactly the way I like, with all the keyboard shortcuts I prefer.
10
+ I leave building truly professional text editors to software tooling experts who would hopefully use [Glimmer](https://github.com/AndyObtiva/glimmer) one day. Otherwise, I have been happily using Gladiator to develop all my [open-source projects](https://github.com/AndyObtiva) since May of 2020.
10
11
 
11
- Gladiator currently supports the following text editing features:
12
- - File explorer navigation to open file, rename, delete, add new file, add new directory, or refresh tree (CMD+T)
12
+ ## Features
13
+
14
+ Gladiator currently supports the following text editing features (including keyboard shortcuts with Mac CMD=CTRL on Windows/Linux):
15
+ - File explorer navigation with context menu to open file, rename, delete, add new file, add new directory, or refresh tree (CMD+T)
13
16
  - File lookup by name ignoring slashes, underscores, and dots to ease lookup (CMD+R)
14
17
  - Watch open file for external changes to automatically refresh in editor
15
18
  - Watch project subdirectories for changes to automatically refresh in file explorer/file lookup
@@ -26,34 +29,69 @@ Gladiator currently supports the following text editing features:
26
29
  - Comment/Uncomment line/selection (CMD+/)
27
30
  - Indent/Unindent line/selection (CMD+] & CMD+[)
28
31
  - Insert/Prefix New Line (CMD+ENTER & CMD+SHIFT+ENTER)
32
+ - Drag and Drop Text Editor Split Screen (drag a file from File Tree or File Lookup List, and it splits the screen)
29
33
 
30
34
  ## Platforms
31
35
 
32
- - Mac: Gladiator works best on the Mac.
33
- - Linux: Gladiator works with handicaps on Linux (performing text editing operations causes scroll jitter)
34
- - Windows: Not tested on Windows yet, but should theoretically work there too.
36
+ - Mac: Gladiator works best on the Mac. This is the platform it is most used on and receives the most maintenance for.
37
+ - Windows: Gladiator works OK on Windows, but has some annoying bugs.
38
+ - Linux: Gladiator works with very bad handicaps on Linux (performing text editing operations causes scroll jitter)
35
39
 
36
40
  ## Pre-requisites
37
41
 
38
- - [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library): '>= 0.8.0', '< 2.0.0' (dependency included in Ruby gem).
42
+ - [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library): '>= 0.1.0', '< 2.0.0' (dependency included in Ruby gem).
39
43
  - [JRuby](https://www.jruby.org/download): Same version required by [Glimmer](https://github.com/AndyObtiva/glimmer)
40
44
  - [JDK](https://www.oracle.com/java/technologies/javase-downloads.html): Same version required by [Glimmer](https://github.com/AndyObtiva/glimmer)
41
45
 
42
46
  ## Setup Instructions
43
47
 
44
- Install Gladiator gem by running (`jgem`, `jruby -S gem`, or `gem` directly if you have RVM):
48
+ Install Gladiator gem by running (`jgem`, `jruby -S gem`, or `gem` directly if you have [RVM](https://rvm.io/)):
45
49
 
46
50
  ```
47
51
  jgem install glimmer-cs-gladiator
48
52
  ```
49
53
 
50
- Afterwards, you may run `gladiator` to bring up the text editor:
54
+ Or add to a JRuby project Bundler `Gemfile` under the `:developement` group:
55
+
56
+ ```
57
+ group :development do
58
+ gem 'glimmer-cs-gladiator'
59
+ end
60
+ ```
61
+
62
+ Run (`jruby -S bundle` or `bundle` directly if you have [RVM](https://rvm.io/)):
63
+
64
+ ```
65
+ jruby -S bundle
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ You may run the `gladiator` command to bring up the text editor in the project directory you would like to edit:
51
71
 
52
72
  ```
53
73
  gladiator
54
74
  ```
55
75
 
56
- Note: If you cloned this project and bundle installed, you may invoke via `bin/gladiator` instead.
76
+ On Windows, you may need to run with extra memory via this command instead:
77
+
78
+ ```
79
+ gladiator -J-Xmx3000M
80
+ ```
81
+
82
+ If you are in a different directory from the project you would like to edit, then pass its path as an argument:
83
+
84
+ ```
85
+ gladiator relative-or-absolute-path/to/project
86
+ ```
87
+
88
+ Note: If you cloned this project and bundle installed, you may invoke via `bin/gladiator` instead.
89
+
90
+ If your project is not a JRuby project, then you cannot install [glimmer-cs-gladiator](https://rubygems.org/gems/glimmer-cs-gladiator), so you must install in a separate JRuby environment and invoke by passing the project path as per command above. Alternatively, you may clone this project, and invoke gladiator via `bin/gladiator` (that's how I use Gladiator for most of my projects):
91
+
92
+ ```
93
+ bin/gladiator relative-or-absolute-path/to/project
94
+ ```
57
95
 
58
96
  ### Glimmer Custom Shell Reuse
59
97
 
@@ -61,7 +99,7 @@ To reuse Gladiator as a Glimmer Custom Shell inside another Glimmer application,
61
99
  following to the application's `Gemfile`:
62
100
 
63
101
  ```
64
- gem 'glimmer-cs-gladiator', '0.1.8'
102
+ gem 'glimmer-cs-gladiator', '~> 0.2.4'
65
103
  ```
66
104
 
67
105
  Run:
@@ -70,7 +108,7 @@ Run:
70
108
  jruby -S bundle
71
109
  ```
72
110
 
73
- And, then instantiate the Gladiator custom shell in your Glimmer application via the `gladiator` keyword.
111
+ And, then instantiate the Gladiator [custom shell](https://github.com/AndyObtiva/glimmer#custom-shells) in your [Glimmer](https://github.com/AndyObtiva/glimmer) application via the `gladiator` keyword assuming you already have `include Glimmer` in your class, module, or main object.
74
112
 
75
113
  ## Env Var Options
76
114
 
@@ -93,6 +131,7 @@ It currently remembers:
93
131
  - Last opened file
94
132
  - Caret position
95
133
  - Top line position
134
+ - Opened tabs
96
135
 
97
136
  ## Gotcha
98
137
 
@@ -119,5 +158,12 @@ The signal TERM is in use by the JVM and will not work correctly on this platfor
119
158
 
120
159
  ## Copyright
121
160
 
122
- Copyright (c) 2020 Andy Maleh. See LICENSE.txt for
123
- further details.
161
+ [MIT](https://opensource.org/licenses/MIT)
162
+
163
+ Copyright (c) 2020 Andy Maleh. See [LICENSE.txt](LICENSE.txt) for further details.
164
+
165
+ --
166
+
167
+ [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />](https://github.com/AndyObtiva/glimmer) Built with [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library)
168
+
169
+ Gladiator icon made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.2.4
@@ -2,4 +2,5 @@ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
2
2
 
3
3
  require 'filewatcher'
4
4
  require 'clipboard'
5
+ require 'puts_debuggerer'
5
6
  require 'views/glimmer/gladiator'
@@ -9,32 +9,43 @@ module Glimmer
9
9
 
10
10
  class << self
11
11
  def local_dir
12
- @local_dir ||= new(ENV['LOCAL_DIR'] || '.').tap do |dir|
13
- dir.refresh
14
- @filewatcher = Filewatcher.new(dir.path)
12
+ unless @local_dir
13
+ @local_dir = new(ENV['LOCAL_DIR'] || '.', true)
14
+ @local_dir.refresh
15
+ @filewatcher = Filewatcher.new(@local_dir.path)
15
16
  @thread = Thread.new(@filewatcher) do |fw|
16
17
  fw.watch do |filename, event|
17
18
  if @last_update.nil? || (Time.now.to_f - @last_update) > REFRESH_DELAY
18
- dir.refresh if !filename.include?('new_file') && !dir.selected_child_path_history.include?(filename) && filename != dir.selected_child_path
19
+ @local_dir.refresh if !filename.include?('new_file') && !@local_dir.selected_child_path_history.include?(filename) && filename != @local_dir.selected_child_path
19
20
  end
20
21
  @last_update = Time.now.to_f
21
22
  end
22
23
  end
23
24
  end
25
+ @local_dir
24
26
  end
25
27
  end
26
28
 
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
+ attr_accessor :selected_child, :filter, :children, :filtered_path_options, :filtered_path, :display_path
30
+ attr_reader :name, :parent, :path, :is_local_dir
31
+ attr_writer :all_children
30
32
 
31
- def initialize(path)
32
- @display_path = path
33
- @path = ::File.expand_path(@display_path)
33
+ def initialize(path, is_local_dir = false)
34
+ @is_local_dir = is_local_dir
35
+ self.path = ::File.expand_path(path)
34
36
  @name = ::File.basename(::File.expand_path(path))
35
37
  self.filtered_path_options = []
36
38
  end
37
39
 
40
+ def path=(the_path)
41
+ @path = the_path
42
+ generate_display_path
43
+ end
44
+
45
+ def generate_display_path
46
+ is_local_dir ? path : @display_path = @path.sub(Dir.local_dir.path, '').sub(/^\//, '')
47
+ end
48
+
38
49
  def name=(the_name)
39
50
  self.display_path = display_path.sub(/#{Regexp.escape(@name)}$/, the_name)
40
51
  @name = the_name
@@ -48,7 +59,15 @@ module Glimmer
48
59
  end
49
60
 
50
61
  def retrieve_children
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 }
62
+ @children = ::Dir.glob(::File.join(@path, '*')).map do |p|
63
+ ::File.file?(p) ? Gladiator::File.new(p) : Gladiator::Dir.new(p)
64
+ end.sort_by do |c|
65
+ c.path.to_s.downcase
66
+ end.sort_by do |c|
67
+ c.class.name
68
+ end.each do |child|
69
+ child.retrieve_children if child.is_a?(Dir)
70
+ end
52
71
  end
53
72
 
54
73
  def selected_child_path_history
@@ -65,11 +84,11 @@ module Glimmer
65
84
 
66
85
  def refresh(async: true, force: false)
67
86
  return if @refresh_paused && !force
68
- new_all_children = retrieve_all_children
69
- new_children = retrieve_children
87
+ retrieve_children
88
+ collect_all_children
70
89
  refresh_operation = lambda do
71
- self.all_children = new_all_children
72
- self.children = new_children
90
+ notify_observers(:children)
91
+ notify_observers(:all_children)
73
92
  end
74
93
  if async
75
94
  async_exec(&refresh_operation)
@@ -84,23 +103,31 @@ module Glimmer
84
103
  else
85
104
  @filter = value
86
105
  end
87
- self.filtered_path_options = filtered.to_a.map(&:display_path)
106
+ @last_filtered = filtered.to_a
107
+ self.filtered_path_options = @last_filtered.map(&:display_path)
108
+ @last_filter = @filter
88
109
  end
89
110
 
90
111
  def filtered
91
112
  return if filter.nil?
92
- all_children_files.select do |child|
93
- child.path.downcase.include?(filter.downcase) ||
94
- child.path.downcase.gsub(/[_\/\.]/, '').include?(filter.downcase)
113
+ children_files = !@last_filter.to_s.empty? && filter.downcase.start_with?(@last_filter.downcase) ? @last_filtered : all_children_files
114
+ children_files.select do |child|
115
+ child_path = child.path.to_s.sub(Dir.local_dir.path, '')
116
+ child_path.downcase.include?(filter.downcase) ||
117
+ child_path.downcase.gsub(/[_\/.-]/, '').include?(filter.downcase.gsub(/[_\/.-]/, ''))
95
118
  end.sort_by {|c| c.path.to_s.downcase}
96
119
  end
97
120
 
98
121
  def all_children
99
- @all_children ||= retrieve_all_children
122
+ @all_children ||= collect_all_children
100
123
  end
101
124
 
102
- def retrieve_all_children
103
- ::Dir.glob(::File.join(@display_path, '**', '*')).map {|p| ::File.file?(p) ? Gladiator::File.new(p) : Gladiator::Dir.new(p)}
125
+ def collect_all_children
126
+ @all_children = children.reduce([]) do |output, child|
127
+ addition = [child]
128
+ addition += child.collect_all_children if child.is_a?(Dir)
129
+ output + addition
130
+ end
104
131
  end
105
132
 
106
133
  def all_children_files
@@ -108,9 +135,11 @@ module Glimmer
108
135
  end
109
136
 
110
137
  def selected_child_path=(selected_path)
138
+ full_selected_path = selected_path.include?(Dir.local_dir.path) ? selected_path : ::File.join(Dir.local_dir.path, selected_path)
111
139
  return if selected_path.nil? ||
112
- ::Dir.exist?(selected_path) ||
113
- (selected_child && ::File.expand_path(selected_child.path) == ::File.expand_path(selected_path))
140
+ ::Dir.exist?(full_selected_path) ||
141
+ (selected_child && selected_child.path == full_selected_path)
142
+ selected_path = full_selected_path
114
143
  if ::File.file?(selected_path)
115
144
  @selected_child&.write_dirty_content
116
145
  new_child = Gladiator::File.new(selected_path)
@@ -5,15 +5,14 @@ module Glimmer
5
5
  class File
6
6
  include Glimmer
7
7
 
8
- attr_accessor :dirty_content, :line_numbers_content, :selection, :selection_count, :line_number, :find_text, :replace_text, :top_index, :path, :display_path, :case_sensitive
9
- attr_reader :name
8
+ attr_accessor :dirty_content, :line_numbers_content, :selection, :selection_count, :line_number, :find_text, :replace_text, :top_index, :display_path, :case_sensitive
9
+ attr_reader :name, :path
10
10
 
11
11
  def initialize(path)
12
12
  raise "Not a file path: #{path}" unless ::File.file?(path)
13
13
  @command_history = []
14
- @display_path = path
15
14
  @name = ::File.basename(path)
16
- @path = ::File.expand_path(path)
15
+ self.path = ::File.expand_path(path)
17
16
  @top_index = 0
18
17
  @selection_count = 0
19
18
  @selection = Point.new(0, 0 + @selection_count)
@@ -42,6 +41,15 @@ module Glimmer
42
41
  end
43
42
  end
44
43
 
44
+ def path=(the_path)
45
+ @path = the_path
46
+ generate_display_path
47
+ end
48
+
49
+ def generate_display_path
50
+ @display_path = @path.sub(Dir.local_dir.path, '').sub(/^\//, '')
51
+ end
52
+
45
53
  # to use for widget data-binding
46
54
  def content=(value)
47
55
  Command.do(self) # record a native (OS-widget) operation
@@ -66,11 +74,12 @@ module Glimmer
66
74
  end
67
75
 
68
76
  def name=(the_name)
69
- self.display_path = display_path.sub(/#{Regexp.escape(@name)}$/, the_name)
77
+ new_path = path.sub(/#{Regexp.escape(@name)}$/, the_name)
70
78
  @name = the_name
71
- new_path = ::File.expand_path(display_path)
72
- FileUtils.mv(path, new_path)
73
- self.path = new_path
79
+ if ::File.exists?(path)
80
+ FileUtils.mv(path, new_path)
81
+ self.path = new_path
82
+ end
74
83
  end
75
84
 
76
85
  def dirty_content=(the_content)
@@ -161,6 +170,7 @@ module Glimmer
161
170
  line_indices_for_selection(caret_position, selection_count).reverse.each do | the_line_index |
162
171
  delta = 0
163
172
  the_line = old_lines[the_line_index]
173
+ return if the_line.nil?
164
174
  if the_line.strip.start_with?('# ')
165
175
  new_lines[the_line_index] = the_line.sub(/# /, '')
166
176
  delta -= 2
@@ -222,7 +232,7 @@ module Glimmer
222
232
  if the_line.to_s.start_with?(' ')
223
233
  new_lines[the_line_index] = the_line.sub(/ /, '')
224
234
  delta = -2
225
- elsif the_line.start_with?(' ')
235
+ elsif the_line&.start_with?(' ')
226
236
  new_lines[the_line_index] = the_line.sub(/ /, '')
227
237
  delta = -1
228
238
  end
@@ -1,8 +1,3 @@
1
- begin
2
- require 'puts_debuggerer' if ENV['puts_debuggerer'].to_s.downcase == 'true'
3
- rescue LoadError
4
- # no op
5
- end
6
1
  require 'fileutils'
7
2
  require 'os'
8
3
 
@@ -12,8 +7,6 @@ require 'models/glimmer/gladiator/command'
12
7
 
13
8
  require 'views/glimmer/gladiator/text_editor'
14
9
 
15
- java_import 'org.eclipse.swt.custom.TreeEditor'
16
-
17
10
  Clipboard.implementation = Clipboard::Java
18
11
  Clipboard.copy(Clipboard.paste) # pre-initialize library to avoid slowdown during use
19
12
 
@@ -24,19 +17,24 @@ module Glimmer
24
17
 
25
18
  COMMAND_KEY = OS.mac? ? :command : :ctrl
26
19
 
20
+ class << self
21
+ attr_accessor :drag_and_drop
22
+ attr_accessor :drag
23
+ end
24
+
27
25
  ## Add options like the following to configure CustomShell by outside consumers
28
26
  #
29
27
  # options :title, :background_color
30
28
  # option :width, 320
31
29
  # option :height, 240
32
-
30
+
33
31
  ## Uncomment before_body block to pre-initialize variables to use in body
34
32
  #
35
33
  #
36
34
  before_body {
37
35
  Display.setAppName('Gladiator')
38
36
  @display = display {
39
- on_event_keydown { |key_event|
37
+ on_swt_keydown { |key_event|
40
38
  if key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'f'
41
39
  if @text_editor&.text_widget&.getSelectionText && @text_editor&.text_widget&.getSelectionText&.size.to_i > 0
42
40
  @find_text.swt_widget.setText @text_editor.text_widget.getSelectionText
@@ -44,69 +42,93 @@ module Glimmer
44
42
  @find_text.swt_widget.selectAll
45
43
  @find_text.swt_widget.setFocus
46
44
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'c'
47
- Clipboard.copy(Gladiator::Dir.local_dir.selected_child.path)
45
+ Clipboard.copy(Dir.local_dir.selected_child.path)
48
46
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'g'
49
- Gladiator::Dir.local_dir.selected_child.find_previous
47
+ Dir.local_dir.selected_child.find_previous
50
48
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'w'
51
49
  @tab_folder.swt_widget.getItems.each do |tab_item|
52
50
  Dir.local_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
53
- tab_item.getData('proxy').dispose
51
+ tab_item.getData('proxy')&.dispose
54
52
  end
53
+ close_tab_folder
55
54
  @tab_item = @text_editor = Dir.local_dir.selected_child = nil
56
55
  @filter_text.swt_widget.selectAll
57
56
  @filter_text.swt_widget.setFocus
58
57
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :alt) && extract_char(key_event) == 'w'
59
58
  other_tab_items.each do |tab_item|
60
59
  Dir.local_dir.selected_child_path_history.delete(tab_item.getData('file_path'))
61
- tab_item.getData('proxy').dispose
60
+ tab_item.getData('proxy')&.dispose
62
61
  end
63
62
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'w'
64
63
  if selected_tab_item
65
64
  Dir.local_dir.selected_child_path_history.delete(Dir.local_dir.selected_child.path)
66
- selected_tab_item.getData('proxy').dispose
65
+ selected_tab_item.getData('proxy')&.dispose
66
+ close_tab_folder
67
67
  if selected_tab_item.nil?
68
68
  @tab_item = @text_editor = Dir.local_dir.selected_child = nil
69
69
  @filter_text.swt_widget.selectAll
70
70
  @filter_text.swt_widget.setFocus
71
71
  else
72
- @text_editor.text_widget.setFocus
72
+ @text_editor&.text_widget&.setFocus
73
73
  end
74
74
  end
75
75
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == ']'
76
76
  @tab_folder.swt_widget.setSelection((@tab_folder.swt_widget.getSelectionIndex() + 1) % @tab_folder.swt_widget.getItemCount) if @tab_folder.swt_widget.getItemCount > 0
77
- @text_editor.text_widget.setFocus
77
+ @text_editor&.text_widget&.setFocus
78
78
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == '['
79
79
  @tab_folder.swt_widget.setSelection((@tab_folder.swt_widget.getSelectionIndex() - 1) % @tab_folder.swt_widget.getItemCount) if @tab_folder.swt_widget.getItemCount > 0
80
- @text_editor.text_widget.setFocus
80
+ @text_editor&.text_widget&.setFocus
81
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == ']'
82
+ if @tab_folder2
83
+ if @tab_folder == @tab_folder1
84
+ @tab_folder = @tab_folder2
85
+ else
86
+ @tab_folder = @tab_folder1
87
+ end
88
+ @tab_item = @tab_folder.swt_widget.getData('selected_tab_item')
89
+ Dir.local_dir.selected_child = @tab_item&.swt_tab_item&.getData('file')
90
+ @tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
91
+ end
92
+ elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :ctrl) && extract_char(key_event) == '['
93
+ if @tab_folder2
94
+ if @tab_folder == @tab_folder2
95
+ @tab_folder = @tab_folder1
96
+ else
97
+ @tab_folder = @tab_folder2
98
+ end
99
+ @tab_item = @tab_folder.swt_widget.getData('selected_tab_item')
100
+ Dir.local_dir.selected_child = @tab_item&.swt_tab_item&.getData('file')
101
+ @tab_item&.swt_tab_item&.getData('text_editor')&.text_widget&.setFocus
102
+ end
81
103
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '1'
82
104
  @tab_folder.swt_widget.setSelection(0) if @tab_folder.swt_widget.getItemCount >= 1
83
- @text_editor.text_widget.setFocus
105
+ @text_editor&.text_widget&.setFocus
84
106
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '2'
85
107
  @tab_folder.swt_widget.setSelection(1) if @tab_folder.swt_widget.getItemCount >= 2
86
- @text_editor.text_widget.setFocus
108
+ @text_editor&.text_widget&.setFocus
87
109
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '3'
88
110
  @tab_folder.swt_widget.setSelection(2) if @tab_folder.swt_widget.getItemCount >= 3
89
- @text_editor.text_widget.setFocus
111
+ @text_editor&.text_widget&.setFocus
90
112
  @tab_folder.swt_widget.setSelection(3) if @tab_folder.swt_widget.getItemCount >= 4
91
- @text_editor.text_widget.setFocus
113
+ @text_editor&.text_widget&.setFocus
92
114
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '5'
93
115
  @tab_folder.swt_widget.setSelection(4) if @tab_folder.swt_widget.getItemCount >= 5
94
- @text_editor.text_widget.setFocus
116
+ @text_editor&.text_widget&.setFocus
95
117
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '4'
96
118
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '6'
97
119
  @tab_folder.swt_widget.setSelection(5) if @tab_folder.swt_widget.getItemCount >= 6
98
- @text_editor.text_widget.setFocus
120
+ @text_editor&.text_widget&.setFocus
99
121
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '7'
100
122
  @tab_folder.swt_widget.setSelection(6) if @tab_folder.swt_widget.getItemCount >= 7
101
- @text_editor.text_widget.setFocus
123
+ @text_editor&.text_widget&.setFocus
102
124
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '8'
103
125
  @tab_folder.swt_widget.setSelection(7) if @tab_folder.swt_widget.getItemCount >= 8
104
- @text_editor.text_widget.setFocus
126
+ @text_editor&.text_widget&.setFocus
105
127
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == '9'
106
128
  @tab_folder.swt_widget.setSelection(@tab_folder.swt_widget.getItemCount - 1) if @tab_folder.swt_widget.getItemCount > 0
107
- @text_editor.text_widget.setFocus
129
+ @text_editor&.text_widget&.setFocus
108
130
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'g'
109
- Gladiator::Dir.local_dir.selected_child.find_next
131
+ Dir.local_dir.selected_child.find_next
110
132
  elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY) && extract_char(key_event) == 'l'
111
133
  @line_number_text.swt_widget.selectAll
112
134
  @line_number_text.swt_widget.setFocus
@@ -119,7 +141,7 @@ module Glimmer
119
141
  elsif key_event.keyCode == swt(:esc)
120
142
  if @text_editor
121
143
  Dir.local_dir.selected_child_path = @text_editor.file.path
122
- @text_editor.text_widget.setFocus
144
+ @text_editor&.text_widget&.setFocus
123
145
  end
124
146
  end
125
147
  }
@@ -128,51 +150,79 @@ module Glimmer
128
150
  local_dir = ENV['LOCAL_DIR'] || '.'
129
151
  @config_file_path = ::File.join(local_dir, '.gladiator')
130
152
  @config = {}
131
- Gladiator::Dir.local_dir.all_children # pre-caches children
153
+ Dir.local_dir.all_children # pre-caches children
132
154
  }
133
155
 
134
156
  ## Uncomment after_body block to setup observers for widgets in body
135
157
  #
136
158
  after_body {
137
- observe(Gladiator::Dir.local_dir, 'children') do
159
+ observe(Dir.local_dir, 'children') do
138
160
  select_tree_item unless @rename_in_progress
139
161
  end
140
- observe(Gladiator::Dir.local_dir, 'selected_child') do
141
- select_tree_item unless @rename_in_progress
142
- selected_file = Gladiator::Dir.local_dir.selected_child
143
- found_tab_item = selected_tab_item
144
- if found_tab_item
145
- @tab_folder.swt_widget.setSelection(found_tab_item)
146
- @tab_item = found_tab_item.getData('tab_item')
147
- @text_editor = found_tab_item.getData('text_editor')
148
- elsif selected_file
149
- @tab_folder.content {
150
- @tab_item = tab_item { |the_tab_item|
151
- text selected_file.name
152
- fill_layout :horizontal
153
- @text_editor = the_text_editor = text_editor(file: selected_file)
154
- on_event_show {
155
- Gladiator::Dir.local_dir.selected_child = selected_file
156
- @tab_item = the_tab_item
157
- @text_editor = the_text_editor
158
- }
162
+ observe(Dir.local_dir, 'selected_child') do |selected_file|
163
+ if selected_file
164
+ if Gladiator.drag && !@tab_folder2
165
+ @tab_folder1 = @tab_folder
166
+ @tab_folder_sash_form.content {
167
+ @tab_folder = @tab_folder2 = tab_folder
168
+ @tab_folder.swt_widget.setData('proxy', @tab_folder)
159
169
  }
160
- @tab_item.swt_tab_item.setData('file_path', selected_file.path)
161
- @tab_item.swt_tab_item.setData('tab_item', @tab_item)
162
- @tab_item.swt_tab_item.setData('text_editor', @text_editor)
163
- @tab_item.swt_tab_item.setData('proxy', @tab_item)
164
- }
165
- @tab_folder.swt_widget.setSelection(@tab_item.swt_tab_item)
166
- body_root.pack_same_size
170
+ end
171
+ select_tree_item unless @rename_in_progress
172
+ found_tab_item = selected_tab_item
173
+ if found_tab_item
174
+ @tab_folder.swt_widget.setSelection(found_tab_item)
175
+ @tab_item = found_tab_item.getData('proxy')
176
+ @text_editor = found_tab_item.getData('text_editor')
177
+ @tab_folder.swt_widget.setData('selected_tab_item', @tab_item)
178
+ elsif selected_file
179
+ @tab_folder.content {
180
+ @tab_item = tab_item { |the_tab_item|
181
+ text selected_file.name
182
+ fill_layout :horizontal
183
+ @text_editor = the_text_editor = text_editor(file: selected_file)
184
+ @tab_folder.swt_widget.setData('selected_tab_item', @tab_item)
185
+ @text_editor.text_proxy.content {
186
+ on_focus_gained {
187
+ tab_folder = the_text_editor.swt_widget.getParent.getParent
188
+ @tab_folder = tab_folder.getData('proxy')
189
+ @tab_item = the_tab_item
190
+ @text_editor = the_text_editor
191
+ @tab_folder.swt_widget.setData('selected_tab_item', @tab_item)
192
+ @tab_folder.swt_widget.setSelection(@tab_item.swt_tab_item)
193
+ Dir.local_dir.selected_child = @tab_item.swt_tab_item.getData('file')
194
+ }
195
+ }
196
+ on_swt_show {
197
+ @tab_item = the_tab_item
198
+ @text_editor = the_text_editor
199
+ @tab_folder = @tab_item.swt_widget.getParent.getData('proxy')
200
+ @tab_folder.swt_widget.setData('selected_tab_item', @tab_item)
201
+ @tab_folder.swt_widget.setSelection(@tab_item.swt_tab_item)
202
+ Dir.local_dir.selected_child = selected_file
203
+ async_exec {
204
+ @text_editor&.text_widget&.setFocus
205
+ }
206
+ }
207
+ }
208
+ @tab_item.swt_tab_item.setData('file_path', selected_file.path)
209
+ @tab_item.swt_tab_item.setData('file', selected_file)
210
+ @tab_item.swt_tab_item.setData('text_editor', @text_editor)
211
+ @tab_item.swt_tab_item.setData('proxy', @tab_item)
212
+ }
213
+ @tab_folder.swt_widget.setSelection(@tab_item.swt_tab_item)
214
+ body_root.pack_same_size
215
+ end
216
+ @text_editor&.text_widget&.setFocus
167
217
  end
168
218
  end
169
- observe(Gladiator::Dir.local_dir, 'selected_child') do
219
+ observe(Dir.local_dir, 'selected_child') do
170
220
  save_config
171
221
  end
172
- observe(Gladiator::Dir.local_dir, 'selected_child.caret_position') do
222
+ observe(Dir.local_dir, 'selected_child.caret_position') do
173
223
  save_config
174
224
  end
175
- observe(Gladiator::Dir.local_dir, 'selected_child.top_index') do
225
+ observe(Dir.local_dir, 'selected_child.top_index') do
176
226
  save_config
177
227
  end
178
228
  load_config
@@ -183,15 +233,15 @@ module Glimmer
183
233
  #
184
234
  body {
185
235
  shell {
186
- text "Gladiator - #{::File.expand_path(Gladiator::Dir.local_dir.path)}"
187
- minimum_size 720, 450
236
+ text "Gladiator - #{::File.expand_path(Dir.local_dir.path)}"
237
+ minimum_size 520, 250
188
238
  size 1440, 900
189
239
  grid_layout 2, false
190
- on_event_close {
191
- Gladiator::Dir.local_dir.selected_child&.write_dirty_content
240
+ on_swt_close {
241
+ Dir.local_dir.selected_child&.write_dirty_content
192
242
  }
193
243
  on_widget_disposed {
194
- Gladiator::Dir.local_dir.selected_child&.write_dirty_content
244
+ Dir.local_dir.selected_child&.write_dirty_content
195
245
  }
196
246
  on_control_resized {
197
247
  save_config
@@ -209,7 +259,7 @@ module Glimmer
209
259
  }
210
260
  @filter_text = text {
211
261
  layout_data :fill, :center, true, false
212
- text bind(Gladiator::Dir.local_dir, 'filter')
262
+ text bind(Dir.local_dir, 'filter')
213
263
  on_key_pressed { |key_event|
214
264
  if key_event.keyCode == swt(:tab) ||
215
265
  key_event.keyCode == swt(:cr) ||
@@ -226,26 +276,43 @@ module Glimmer
226
276
  }
227
277
  layout_data(:fill, :fill, true, true)
228
278
  @list = list(:border, :h_scroll, :v_scroll) {
229
- #visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !!f}
230
- selection bind(Gladiator::Dir.local_dir, :filtered_path)
279
+ #visible bind(Dir, 'local_dir.filter') {|f| !!f}
280
+ selection bind(Dir.local_dir, :filtered_path)
231
281
  on_mouse_up {
232
- Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
282
+ Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
233
283
  }
234
284
  on_key_pressed { |key_event|
235
285
  if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
236
- Gladiator::Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
286
+ Dir.local_dir.selected_child_path = @list.swt_widget.getSelection.first
237
287
  @text_editor&.text_widget&.setFocus
238
288
  end
239
289
  }
290
+ drag_source(DND::DROP_COPY) {
291
+ transfer [TextTransfer.getInstance].to_java(Transfer)
292
+ on_drag_set_data { |event|
293
+ Gladiator.drag = true
294
+ list = event.widget.getControl
295
+ event.data = list.getSelection.first
296
+ }
297
+ }
240
298
  }
241
299
  @tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
242
- #visible bind(Gladiator::Dir, 'local_dir.filter') {|f| !f}
243
- items bind(Gladiator::Dir, :local_dir), tree_properties(children: :children, text: :name)
300
+ #visible bind(Dir, 'local_dir.filter') {|f| !f}
301
+ items bind(Dir, :local_dir), tree_properties(children: :children, text: :name)
302
+ drag_source(DND::DROP_COPY) {
303
+ transfer [TextTransfer.getInstance].to_java(Transfer)
304
+ on_drag_set_data { |event|
305
+ Gladiator.drag = true
306
+ tree = event.widget.getControl
307
+ tree_item = tree.getSelection.first
308
+ event.data = tree_item.getData.path
309
+ }
310
+ }
244
311
  menu {
245
312
  @open_menu_item = menu_item {
246
313
  text 'Open'
247
314
  on_widget_selected {
248
- Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
315
+ Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
249
316
  }
250
317
  }
251
318
  menu_item(:separator)
@@ -259,7 +326,7 @@ module Glimmer
259
326
  menu_item {
260
327
  text 'Refresh'
261
328
  on_widget_selected {
262
- Gladiator::Dir.local_dir.refresh
329
+ Dir.local_dir.refresh
263
330
  }
264
331
  }
265
332
  menu_item {
@@ -281,17 +348,21 @@ module Glimmer
281
348
  }
282
349
  }
283
350
  }
284
- on_event_menudetect { |event|
351
+ on_swt_menudetect { |event|
285
352
  path = extract_tree_item_path(@tree.swt_widget.getSelection.first)
286
353
  @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
287
354
  }
288
355
  on_mouse_up {
289
- Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
290
- @text_editor&.text_widget&.setFocus
356
+ if Gladiator.drag_and_drop
357
+ Gladiator.drag_and_drop = false
358
+ else
359
+ Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
360
+ @text_editor&.text_widget&.setFocus
361
+ end
291
362
  }
292
363
  on_key_pressed { |key_event|
293
364
  if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
294
- Gladiator::Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
365
+ Dir.local_dir.selected_child_path = extract_tree_item_path(@tree.swt_widget.getSelection&.first)
295
366
  @text_editor&.text_widget&.setFocus
296
367
  end
297
368
  }
@@ -325,7 +396,7 @@ module Glimmer
325
396
  background color(:widget_background)
326
397
  editable false
327
398
  caret nil
328
- text bind(Gladiator::Dir.local_dir, 'selected_child.path')
399
+ text bind(Dir.local_dir, 'selected_child.path')
329
400
  on_mouse_up {
330
401
  @file_path_label.swt_widget.selectAll
331
402
  }
@@ -343,7 +414,7 @@ module Glimmer
343
414
  layout_data(:fill, :fill, true, false) {
344
415
  minimum_width 400
345
416
  }
346
- text bind(Gladiator::Dir.local_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
417
+ text bind(Dir.local_dir, 'selected_child.line_number', on_read: :to_s, on_write: :to_i)
347
418
  on_key_pressed { |key_event|
348
419
  if key_event.keyCode == swt(:cr)
349
420
  @text_editor&.text_widget&.setFocus
@@ -364,14 +435,14 @@ module Glimmer
364
435
  layout_data(:fill, :fill, true, false) {
365
436
  minimum_width 400
366
437
  }
367
- text bind(Gladiator::Dir.local_dir, 'selected_child.find_text')
438
+ text bind(Dir.local_dir, 'selected_child.find_text')
368
439
  on_key_pressed { |key_event|
369
440
  if key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr)
370
441
  Dir.local_dir.selected_child.case_sensitive = !Dir.local_dir.selected_child.case_sensitive
371
- Gladiator::Dir.local_dir.selected_child&.find_next
442
+ Dir.local_dir.selected_child&.find_next
372
443
  end
373
444
  if key_event.keyCode == swt(:cr)
374
- Gladiator::Dir.local_dir.selected_child&.find_next
445
+ Dir.local_dir.selected_child&.find_next
375
446
  end
376
447
  }
377
448
  }
@@ -381,7 +452,7 @@ module Glimmer
381
452
  selection bind(Dir.local_dir, 'selected_child.case_sensitive')
382
453
  on_key_pressed { |key_event|
383
454
  if key_event.keyCode == swt(:cr)
384
- Gladiator::Dir.local_dir.selected_child&.find_next
455
+ Dir.local_dir.selected_child&.find_next
385
456
  end
386
457
  }
387
458
  }
@@ -399,39 +470,66 @@ module Glimmer
399
470
  layout_data(:fill, :fill, true, false) {
400
471
  minimum_width 300
401
472
  }
402
- text bind(Gladiator::Dir.local_dir, 'selected_child.replace_text')
473
+ text bind(Dir.local_dir, 'selected_child.replace_text')
403
474
  on_focus_gained {
404
- Gladiator::Dir.local_dir.selected_child&.ensure_find_next
475
+ Dir.local_dir.selected_child&.ensure_find_next
405
476
  }
406
477
  on_key_pressed { |key_event|
407
478
  if key_event.keyCode == swt(:cr)
408
- if Gladiator::Dir.local_dir.selected_child
409
- Command.do(Gladiator::Dir.local_dir.selected_child, :replace_next!)
479
+ if Dir.local_dir.selected_child
480
+ Command.do(Dir.local_dir.selected_child, :replace_next!)
410
481
  end
411
482
  end
412
483
  }
413
484
  }
414
485
  label
415
486
  }
416
- @tab_folder = tab_folder {
417
- layout_data(:fill, :fill, true, true)
487
+ @tab_folder_sash_form = sash_form {
488
+ layout_data(:fill, :fill, true, true) {
489
+ width_hint 640
490
+ height_hint 480
491
+ }
492
+ sash_width 10
493
+ @tab_folder = tab_folder {
494
+ drag_source(DND::DROP_COPY) {
495
+ transfer [TextTransfer.getInstance].to_java(Transfer)
496
+ event_data = nil
497
+ on_drag_start {|event|
498
+ Gladiator.drag = true
499
+ tab_folder = event.widget.getControl
500
+ tab_item = tab_folder.getItem(Point.new(event.x, event.y))
501
+ event_data = tab_item.getData('file_path')
502
+ }
503
+ on_drag_set_data { |event|
504
+ event.data = event_data
505
+ }
506
+ }
507
+ }
508
+ @tab_folder.swt_widget.setData('proxy', @tab_folder)
418
509
  }
419
510
  }
420
511
  }
421
512
  }
422
-
513
+
423
514
  def load_config
424
515
  if ::File.exists?(@config_file_path)
425
516
  config_yaml = ::File.read(@config_file_path)
426
517
  return if config_yaml.to_s.strip.empty?
427
518
  @config = YAML.load(config_yaml)
428
- @config[:open_file_paths].to_a.each do |file_path|
429
- Gladiator::Dir.local_dir.selected_child_path = file_path
519
+ open_file_paths1 = @config[:open_file_paths1] || @config[:open_file_paths]
520
+ open_file_paths2 = @config[:open_file_paths2]
521
+ open_file_paths1.to_a.each do |file_path|
522
+ Dir.local_dir.selected_child_path = file_path
430
523
  end
431
- Gladiator::Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
432
- 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]
433
- Gladiator::Dir.local_dir.selected_child&.top_index = @config[:top_index].to_i if @config[:top_index]
434
- body_root.on_event_show {
524
+ Gladiator.drag = true
525
+ open_file_paths2.to_a.each do |file_path|
526
+ Dir.local_dir.selected_child_path = file_path
527
+ end
528
+ Gladiator.drag = false
529
+ Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
530
+ Dir.local_dir.selected_child&.caret_position = Dir.local_dir.selected_child&.caret_position_for_caret_position_start_of_line(@config[:caret_position].to_i) if @config[:caret_position]
531
+ Dir.local_dir.selected_child&.top_index = @config[:top_index].to_i if @config[:top_index]
532
+ body_root.on_swt_show {
435
533
  swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
436
534
  swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
437
535
  @loaded_config = true
@@ -443,8 +541,12 @@ module Glimmer
443
541
 
444
542
  def save_config
445
543
  return unless @loaded_config
446
- child = Gladiator::Dir.local_dir.selected_child
544
+ child = Dir.local_dir.selected_child
447
545
  return if child.nil?
546
+ tab_folder1 = @tab_folder1 || @tab_folder
547
+ tab_folder2 = @tab_folder2
548
+ open_file_paths1 = tab_folder1&.swt_widget&.items&.to_a.map {|i| i.get_data('file_path')}
549
+ open_file_paths2 = tab_folder2&.swt_widget&.items&.to_a.map {|i| i.get_data('file_path')}
448
550
  @config = {
449
551
  selected_child_path: child.path,
450
552
  caret_position: child.caret_position,
@@ -453,7 +555,8 @@ module Glimmer
453
555
  shell_height: swt_widget&.getBounds&.height,
454
556
  shell_x: swt_widget&.getBounds&.x,
455
557
  shell_y: swt_widget&.getBounds&.y,
456
- open_file_paths: Dir.local_dir.selected_child_path_history,
558
+ open_file_paths1: open_file_paths1,
559
+ open_file_paths2: open_file_paths2,
457
560
  }
458
561
  config_yaml = YAML.dump(@config)
459
562
  ::File.write(@config_file_path, config_yaml) unless config_yaml.to_s.empty?
@@ -461,12 +564,31 @@ module Glimmer
461
564
  puts e.full_message
462
565
  end
463
566
 
567
+ def close_tab_folder
568
+ if @tab_folder2 && !selected_tab_item
569
+ if @tab_folder == @tab_folder2
570
+ @tab_folder2.swt_widget.dispose
571
+ @tab_folder = @tab_folder1
572
+ else
573
+ @tab_folder1.swt_widget.dispose
574
+ @tab_folder = @tab_folder1 = @tab_folder2
575
+ end
576
+ @tab_folder2 = nil
577
+
578
+ @tab_item = @tab_folder.swt_widget.getData('selected_tab_item')
579
+ @text_editor = @tab_item.swt_tab_item.getData('text_editor')
580
+ Dir.local_dir.selected_child = @tab_item.swt_tab_item.getData('file')
581
+
582
+ body_root.pack_same_size
583
+ end
584
+ end
585
+
464
586
  def selected_tab_item
465
- @tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == Gladiator::Dir.local_dir.selected_child&.path }
587
+ @tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == Dir.local_dir.selected_child&.path }
466
588
  end
467
589
 
468
590
  def other_tab_items
469
- @tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == Gladiator::Dir.local_dir.selected_child&.path }
591
+ @tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == Dir.local_dir.selected_child&.path }
470
592
  end
471
593
 
472
594
  def extract_tree_item_path(tree_item)
@@ -479,12 +601,13 @@ module Glimmer
479
601
  end
480
602
 
481
603
  def select_tree_item
482
- return unless Gladiator::Dir.local_dir.selected_child&.name
483
- tree_items_to_select = @tree.depth_first_search { |ti| ti.getData.path == Gladiator::Dir.local_dir.selected_child.path }
604
+ return unless Dir.local_dir.selected_child&.name
605
+ tree_items_to_select = @tree.depth_first_search { |ti| ti.getData.path == Dir.local_dir.selected_child.path }
484
606
  @tree.swt_widget.setSelection(tree_items_to_select)
485
607
  end
486
608
 
487
609
  def delete_tree_item(tree_item)
610
+ return if tree_item.nil?
488
611
  file = tree_item.getData
489
612
  parent_path = ::File.dirname(file.path)
490
613
  file.delete! # TODO consider supporting command undo/redo
@@ -496,6 +619,8 @@ module Glimmer
496
619
  # if file.is_a?(::File)
497
620
  # close tab
498
621
  # end
622
+ rescue => e
623
+ puts e.full_message
499
624
  end
500
625
 
501
626
  def rename_selected_tree_item
@@ -508,6 +633,7 @@ module Glimmer
508
633
  Dir.local_dir.pause_refresh
509
634
  tree_item = @tree.swt_widget.getSelection.first
510
635
  directory_path = extract_tree_item_path(tree_item)
636
+ return if directory_path.nil?
511
637
  if !::Dir.exist?(directory_path)
512
638
  tree_item = tree_item.getParentItem
513
639
  directory_path = ::File.dirname(directory_path)
@@ -530,6 +656,7 @@ module Glimmer
530
656
  end
531
657
  new_file_path = ::File.expand_path(::File.join(directory_path, 'new_file'))
532
658
  FileUtils.touch(new_file_path)
659
+ # TODO look into refreshing only the parent directory to avoid slowdown
533
660
  Dir.local_dir.refresh(async: false, force: true)
534
661
  new_tree_item = @tree.depth_first_search {|ti| ti.getData.path == new_file_path}.first
535
662
  @tree.swt_widget.showItem(new_tree_item)
@@ -5,10 +5,11 @@ module Glimmer
5
5
 
6
6
  options :file
7
7
 
8
- attr_reader :text_widget
8
+ attr_reader :text_proxy, :text_widget
9
9
 
10
10
  after_body {
11
11
  @text_widget = @text.swt_widget
12
+ @text_proxy = @text
12
13
  }
13
14
 
14
15
  body {
@@ -41,6 +42,19 @@ module Glimmer
41
42
  selection bind(file, 'selection')
42
43
  selection_count bind(file, 'selection_count')
43
44
  top_index bind(file, 'top_index')
45
+ drop_target(DND::DROP_COPY) {
46
+ transfer [TextTransfer.getInstance].to_java(Transfer)
47
+ on_drag_enter { |event|
48
+ event.detail = DND::DROP_COPY
49
+ }
50
+ on_drop { |event|
51
+ Gladiator.drag_and_drop = true
52
+ Dir.local_dir.selected_child = nil
53
+ Dir.local_dir.selected_child_path = event.data
54
+ Gladiator.drag = false
55
+ }
56
+ }
57
+
44
58
  on_focus_lost {
45
59
  file&.write_dirty_content
46
60
  }
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-cs-gladiator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.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-06-09 00:00:00.000000000 Z
11
+ date: 2020-07-30 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.8.0
18
+ version: 0.4.1
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.0.0
22
- name: glimmer
22
+ name: glimmer-dsl-swt
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.8.0
29
+ version: 0.4.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
@@ -100,20 +100,6 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
- - !ruby/object:Gem::Dependency
104
- requirement: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: 0.8.1
109
- name: puts_debuggerer
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: 0.8.1
117
103
  description: Gladiator (short for Glimmer Editor) is a Glimmer sample project under
118
104
  on-going development. It is not intended to be a full-fledged editor by any means,
119
105
  yet mostly a fun educational exercise in using Glimmer to build a text editor. Gladiator