glimmer-cs-gladiator 0.2.0 → 0.2.1

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: 9397375fcae09b0628d7cea62e30cf9e10e1bccc236a10717bf442824adf9bb4
4
- data.tar.gz: 46500cd7bcc7636295ea1466369f9ef4a819dac0f27e87615ffec510634ec078
3
+ metadata.gz: 46513e411ce6bac81dafe471f6f8bc7834df2c82c0309f0f1db03c98abf709d7
4
+ data.tar.gz: 54321b16f31848472e812d12b43a461bb4e45fb45dd3c400dc943c68ff0669ac
5
5
  SHA512:
6
- metadata.gz: f266d9d55637f38f001f6e80b553a704d85e809b3ccd9fd29ac942bf7ce1b747133964176a42d0cc4fa7e07474fed78c03cce611fadd7d90b0ee5206282d18ac
7
- data.tar.gz: 4a4f36dac54c4069ef32268342e2698092dff0b19df564e8173db73b63bfa1b515274eb54353ed09f6417afcfa2967f9e2b538caf980d88683d4cff6f753d629
6
+ metadata.gz: a807b9c57b441c9f9aa06c5a4662ae436c5ae2409e8343c3fba5b220bf933b29965fc4b205c5fc5479d42d4fdb5796505cf9f33d56da0419193d684e2def2f60
7
+ data.tar.gz: 4b37d08afb361322aabcf54a046dd9bb2e5db7d1b557409fc28d124918a8687e1079bd9927dd83fb149f4428ef3c5b9daf7903c17e5c896d07f150d3191b5333
data/README.md CHANGED
@@ -1,15 +1,18 @@
1
- # Gladiator (Glimmer Editor) 0.2.0 - Glimmer Custom Shell
1
+ # <img src='https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-gladiator/master/images/glimmer-cs-gladiator-logo.svg' height=85 /> Gladiator (Glimmer Editor) 0.2.1
2
+ ## [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 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,12 +29,13 @@ 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
36
  - Mac: Gladiator works best on the Mac.
37
+ - Windows: Gladiator works well on Windows.
33
38
  - 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.
35
39
 
36
40
  ## Pre-requisites
37
41
 
@@ -41,19 +45,47 @@ Gladiator currently supports the following text editing features:
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
+ If you are in a different directory from the project you would like to edit, then pass its path as an argument:
77
+
78
+ ```
79
+ gladiator relative-or-absolute-path/to/project
80
+ ```
81
+
82
+ Note: If you cloned this project and bundle installed, you may invoke via `bin/gladiator` instead.
83
+
84
+ 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):
85
+
86
+ ```
87
+ bin/gladiator relative-or-absolute-path/to/project
88
+ ```
57
89
 
58
90
  ### Glimmer Custom Shell Reuse
59
91
 
@@ -61,7 +93,7 @@ To reuse Gladiator as a Glimmer Custom Shell inside another Glimmer application,
61
93
  following to the application's `Gemfile`:
62
94
 
63
95
  ```
64
- gem 'glimmer-cs-gladiator', '0.2.0'
96
+ gem 'glimmer-cs-gladiator', '~> 0.2.1'
65
97
  ```
66
98
 
67
99
  Run:
@@ -70,7 +102,7 @@ Run:
70
102
  jruby -S bundle
71
103
  ```
72
104
 
73
- And, then instantiate the Gladiator custom shell in your Glimmer application via the `gladiator` keyword.
105
+ 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
106
 
75
107
  ## Env Var Options
76
108
 
@@ -93,6 +125,7 @@ It currently remembers:
93
125
  - Last opened file
94
126
  - Caret position
95
127
  - Top line position
128
+ - Opened tabs
96
129
 
97
130
  ## Gotcha
98
131
 
@@ -121,3 +154,5 @@ The signal TERM is in use by the JVM and will not work correctly on this platfor
121
154
 
122
155
  Copyright (c) 2020 Andy Maleh. See LICENSE.txt for
123
156
  further details.
157
+
158
+ 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.2.0
1
+ 0.2.1
@@ -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'
@@ -223,7 +223,7 @@ module Glimmer
223
223
  if the_line.to_s.start_with?(' ')
224
224
  new_lines[the_line_index] = the_line.sub(/ /, '')
225
225
  delta = -2
226
- elsif the_line.start_with?(' ')
226
+ elsif the_line&.start_with?(' ')
227
227
  new_lines[the_line_index] = the_line.sub(/ /, '')
228
228
  delta = -1
229
229
  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,12 +17,17 @@ 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
  #
@@ -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_event_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
240
  on_event_close {
191
- Gladiator::Dir.local_dir.selected_child&.write_dirty_content
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 {
@@ -286,12 +353,16 @@ module Glimmer
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,38 +470,58 @@ 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
519
  @config[:open_file_paths].to_a.each do |file_path|
429
- Gladiator::Dir.local_dir.selected_child_path = file_path
520
+ Dir.local_dir.selected_child_path = file_path
430
521
  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]
522
+ Dir.local_dir.selected_child_path = @config[:selected_child_path] if @config[:selected_child_path]
523
+ 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]
524
+ Dir.local_dir.selected_child&.top_index = @config[:top_index].to_i if @config[:top_index]
434
525
  body_root.on_event_show {
435
526
  swt_widget.setSize(@config[:shell_width], @config[:shell_height]) if @config[:shell_width] && @config[:shell_height]
436
527
  swt_widget.setLocation(@config[:shell_x], @config[:shell_y]) if @config[:shell_x] && @config[:shell_y]
@@ -443,7 +534,7 @@ module Glimmer
443
534
 
444
535
  def save_config
445
536
  return unless @loaded_config
446
- child = Gladiator::Dir.local_dir.selected_child
537
+ child = Dir.local_dir.selected_child
447
538
  return if child.nil?
448
539
  @config = {
449
540
  selected_child_path: child.path,
@@ -461,12 +552,31 @@ module Glimmer
461
552
  puts e.full_message
462
553
  end
463
554
 
555
+ def close_tab_folder
556
+ if @tab_folder2 && !selected_tab_item
557
+ if @tab_folder == @tab_folder2
558
+ @tab_folder2.swt_widget.dispose
559
+ @tab_folder = @tab_folder1
560
+ else
561
+ @tab_folder1.swt_widget.dispose
562
+ @tab_folder = @tab_folder1 = @tab_folder2
563
+ end
564
+ @tab_folder2 = nil
565
+
566
+ @tab_item = @tab_folder.swt_widget.getData('selected_tab_item')
567
+ @text_editor = @tab_item.swt_tab_item.getData('text_editor')
568
+ Dir.local_dir.selected_child = @tab_item.swt_tab_item.getData('file')
569
+
570
+ body_root.pack_same_size
571
+ end
572
+ end
573
+
464
574
  def selected_tab_item
465
- @tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == Gladiator::Dir.local_dir.selected_child&.path }
575
+ @tab_folder.swt_widget.getItems.detect { |ti| ti.getData('file_path') == Dir.local_dir.selected_child&.path }
466
576
  end
467
577
 
468
578
  def other_tab_items
469
- @tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == Gladiator::Dir.local_dir.selected_child&.path }
579
+ @tab_folder.swt_widget.getItems.reject { |ti| ti.getData('file_path') == Dir.local_dir.selected_child&.path }
470
580
  end
471
581
 
472
582
  def extract_tree_item_path(tree_item)
@@ -479,8 +589,8 @@ module Glimmer
479
589
  end
480
590
 
481
591
  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 }
592
+ return unless Dir.local_dir.selected_child&.name
593
+ tree_items_to_select = @tree.depth_first_search { |ti| ti.getData.path == Dir.local_dir.selected_child.path }
484
594
  @tree.swt_widget.setSelection(tree_items_to_select)
485
595
  end
486
596
 
@@ -497,6 +607,8 @@ module Glimmer
497
607
  # if file.is_a?(::File)
498
608
  # close tab
499
609
  # end
610
+ rescue => e
611
+ puts e.full_message
500
612
  end
501
613
 
502
614
  def rename_selected_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,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.2.0
4
+ version: 0.2.1
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-15 00:00:00.000000000 Z
11
+ date: 2020-07-11 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.1.0
18
+ version: 0.1.3
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.0.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.1.0
29
+ version: 0.1.3
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