glimmer-cs-gladiator 0.6.2 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,244 @@
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module Glimmer
23
+ class Gladiator
24
+ class FileExplorerTree
25
+ include Glimmer::UI::CustomWidget
26
+
27
+ options :gladiator, :foreground_color
28
+
29
+ body {
30
+ tree {
31
+ #visible bind(self, 'project_dir.filter') {|f| !f}
32
+ items bind(self, :project_dir), tree_properties(children: :children, text: :name)
33
+ foreground foreground_color
34
+ drag_source(:drop_copy) {
35
+ transfer :text
36
+ on_drag_set_data { |event|
37
+ Gladiator.drag = true
38
+ tree = event.widget.getControl
39
+ tree_item = tree.getSelection.first
40
+ event.data = tree_item.getData.path
41
+ }
42
+ }
43
+
44
+ menu {
45
+ @open_menu_item = menu_item {
46
+ text 'Open'
47
+ on_widget_selected {
48
+ project_dir.selected_child_path = extract_tree_item_path(swt_widget.getSelection.first)
49
+ }
50
+ }
51
+ menu_item(:separator)
52
+ menu_item {
53
+ text 'Delete'
54
+ on_widget_selected {
55
+ tree_item = swt_widget.getSelection.first
56
+ delete_tree_item(tree_item)
57
+ }
58
+ }
59
+ menu_item {
60
+ text 'Refresh'
61
+ on_widget_selected {
62
+ project_dir.refresh
63
+ }
64
+ }
65
+ menu_item {
66
+ text 'Rename'
67
+ on_widget_selected {
68
+ rename_selected_tree_item
69
+ }
70
+ }
71
+ menu_item {
72
+ text 'New Directory'
73
+ on_widget_selected {
74
+ add_new_directory_to_selected_tree_item
75
+ }
76
+ }
77
+ menu_item {
78
+ text 'New File'
79
+ on_widget_selected {
80
+ add_new_file_to_selected_tree_item
81
+ }
82
+ }
83
+ }
84
+
85
+ on_swt_menudetect { |event|
86
+ path = extract_tree_item_path(swt_widget.getSelection.first)
87
+ @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
88
+ }
89
+ on_mouse_up {
90
+ if Gladiator.drag_and_drop
91
+ Gladiator.drag_and_drop = false
92
+ else
93
+ project_dir.selected_child_path = extract_tree_item_path(swt_widget.getSelection&.first)
94
+ gladiator.current_text_editor&.text_widget&.setFocus
95
+ end
96
+ }
97
+ on_key_pressed { |key_event|
98
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
99
+ project_dir.selected_child_path = extract_tree_item_path(swt_widget.getSelection&.first)
100
+ gladiator.current_text_editor&.text_widget&.setFocus
101
+ end
102
+ }
103
+ on_paint_control {
104
+ root_item = swt_widget.getItems.first
105
+ if root_item && !root_item.getExpanded
106
+ root_item.setExpanded(true)
107
+ end
108
+ }
109
+
110
+ }
111
+ }
112
+
113
+ def project_dir
114
+ gladiator.project_dir
115
+ end
116
+
117
+ def current_text_editor
118
+ gladiator.current_text_editor
119
+ end
120
+
121
+ def extract_tree_item_path(tree_item)
122
+ return if tree_item.nil?
123
+ if tree_item.getParentItem
124
+ ::File.join(extract_tree_item_path(tree_item.getParentItem), tree_item.getText)
125
+ else
126
+ project_dir.path
127
+ end
128
+ end
129
+
130
+ def select_tree_item
131
+ return unless project_dir.selected_child&.name
132
+ tree_items_to_select = body_root.depth_first_search { |ti| ti.getData.path == project_dir.selected_child.path }
133
+ swt_widget.setSelection(tree_items_to_select)
134
+ end
135
+
136
+ def delete_tree_item(tree_item)
137
+ return if tree_item.nil?
138
+ file = tree_item.getData
139
+ parent_path = ::File.dirname(file.path)
140
+ if file.is_a?(Gladiator::Dir)
141
+ file_paths = file.all_children.select {|f| f.is_a?(Gladiator::File)}.map(&:path)
142
+ file.remove_all_observers
143
+ else
144
+ file_paths = [file.path]
145
+ end
146
+ file_paths.each do |file_path|
147
+ found_tab_item = gladiator.find_tab_item(file_path)
148
+ if found_tab_item
149
+ project_dir.selected_child_path_history.delete(found_tab_item.getData('file_path'))
150
+ found_tab_item.getData('proxy')&.dispose
151
+ end
152
+ end
153
+ file.delete! # TODO consider supporting command undo/redo
154
+ project_dir.refresh(async: false)
155
+ parent_tree_item = body_root.depth_first_search {|ti| ti.getData.path == parent_path}.first
156
+ swt_widget.showItem(parent_tree_item)
157
+ parent_tree_item.setExpanded(true)
158
+ rescue => e
159
+ puts e.full_message
160
+ end
161
+
162
+ def add_new_directory_to_selected_tree_item
163
+ project_dir.pause_refresh
164
+ tree_item = swt_widget.getSelection.first
165
+ directory_path = extract_tree_item_path(tree_item)
166
+ return if directory_path.nil?
167
+ if !::Dir.exist?(directory_path)
168
+ tree_item = tree_item.getParentItem
169
+ directory_path = ::File.dirname(directory_path)
170
+ end
171
+ new_directory_path = ::File.expand_path(::File.join(directory_path, 'new_directory'))
172
+ FileUtils.mkdir_p(new_directory_path)
173
+ project_dir.refresh(async: false, force: true)
174
+ new_tree_item = body_root.depth_first_search {|ti| ti.getData.path == new_directory_path}.first
175
+ swt_widget.showItem(new_tree_item)
176
+ rename_tree_item(new_tree_item)
177
+ end
178
+
179
+ def add_new_file_to_selected_tree_item
180
+ project_dir.pause_refresh
181
+ tree_item = swt_widget.getSelection.first
182
+ directory_path = extract_tree_item_path(tree_item)
183
+ if !::Dir.exist?(directory_path)
184
+ tree_item = tree_item.getParentItem
185
+ directory_path = ::File.dirname(directory_path)
186
+ end
187
+ new_file_path = ::File.expand_path(::File.join(directory_path, 'new_file'))
188
+ FileUtils.touch(new_file_path)
189
+ # TODO look into refreshing only the parent directory to avoid slowdown
190
+ project_dir.refresh(async: false, force: true)
191
+ new_tree_item = body_root.depth_first_search {|ti| ti.getData.path == new_file_path}.first
192
+ swt_widget.showItem(new_tree_item)
193
+ rename_tree_item(new_tree_item, true)
194
+ end
195
+
196
+ def rename_selected_tree_item
197
+ project_dir.pause_refresh
198
+ tree_item = swt_widget.getSelection.first
199
+ rename_tree_item(tree_item)
200
+ end
201
+
202
+ def rename_tree_item(tree_item, new_file = false)
203
+ original_file = tree_item.getData
204
+ current_file = project_dir.selected_child_path == original_file.path
205
+ found_tab_item = gladiator.find_tab_item(original_file.path)
206
+ found_text_editor = found_tab_item&.getData('text_editor')
207
+ body_root.edit_tree_item(
208
+ tree_item,
209
+ after_write: -> (edited_tree_item) {
210
+ file = edited_tree_item.getData
211
+ file_path = file.path
212
+ file.name
213
+ if ::File.file?(file_path)
214
+ if new_file
215
+ project_dir.selected_child_path = file_path
216
+ else
217
+ found_text_editor&.file = file
218
+ found_tab_item&.setData('file', file)
219
+ found_tab_item&.setData('file_path', file.path)
220
+ found_tab_item&.setText(file.name)
221
+ body_root.pack_same_size
222
+ if current_file
223
+ project_dir.selected_child_path = file_path
224
+ else
225
+ selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
226
+ end
227
+ async_exec {
228
+ swt_widget.showItem(edited_tree_item)
229
+ }
230
+ end
231
+ end
232
+ project_dir.resume_refresh
233
+ },
234
+ after_cancel: -> {
235
+ project_dir.resume_refresh
236
+ }
237
+ )
238
+ end
239
+
240
+ end
241
+
242
+ end
243
+
244
+ end
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module Glimmer
23
+ class Gladiator
24
+ class FileLookupList
25
+ include Glimmer::UI::CustomWidget
26
+
27
+ options :gladiator, :foreground_color
28
+
29
+ body {
30
+ list(:border, :h_scroll, :v_scroll) {
31
+ selection bind(project_dir, :filtered_path)
32
+ # visible bind(project_dir, 'filter') {|f| pd swt_widget&.get_shell&.get_data('proxy'); swt_widget&.get_shell&.get_data('proxy')&.pack_same_size; !!f}
33
+ foreground foreground_color
34
+ on_mouse_up {
35
+ project_dir.selected_child_path = swt_widget.getSelection.first
36
+ }
37
+ on_key_pressed { |key_event|
38
+ if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
39
+ project_dir.selected_child_path = swt_widget.getSelection.first
40
+ current_text_editor&.text_widget&.setFocus
41
+ end
42
+ }
43
+ drag_source(DND::DROP_COPY) {
44
+ transfer :text
45
+ on_drag_set_data { |event|
46
+ Gladiator.drag = true
47
+ list = event.widget.getControl
48
+ event.data = list.getSelection.first
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ def project_dir
55
+ gladiator.project_dir
56
+ end
57
+
58
+ def current_text_editor
59
+ gladiator.current_text_editor
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2020-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
1
22
  module Glimmer
2
23
  class Gladiator
3
24
  class TextEditor
@@ -7,6 +28,10 @@ module Glimmer
7
28
 
8
29
  attr_reader :text_proxy
9
30
 
31
+ before_body {
32
+ @font_name = display.get_font_list(nil, true).map(&:name).include?('Consolas') ? 'Consolas' : 'Courier'
33
+ }
34
+
10
35
  after_body {
11
36
  load_content
12
37
  }
@@ -18,7 +43,7 @@ module Glimmer
18
43
  @line_numbers_text = styled_text(:multi, :border) {
19
44
  layout_data(:right, :fill, false, true)
20
45
  text ' '*4
21
- font name: 'Consolas', height: OS.mac? ? 15 : 12
46
+ font name: @font_name, height: OS.mac? ? 15 : 12
22
47
  background color(:widget_background)
23
48
  foreground :dark_blue
24
49
  top_margin 5
@@ -39,7 +64,7 @@ module Glimmer
39
64
 
40
65
  @text_proxy = send(text_widget_keyword) { |the_text|
41
66
  layout_data :fill, :fill, true, true
42
- font name: 'Consolas', height: OS.mac? ? 15 : 12
67
+ font name: @font_name, height: OS.mac? ? 15 : 12
43
68
  foreground rgb(75, 75, 75)
44
69
  focus true
45
70
  top_margin 5
@@ -108,8 +133,6 @@ module Glimmer
108
133
  on_verify_key { |key_event|
109
134
  if (Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'z') || (key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'y')
110
135
  key_event.doit = !Command.redo(file)
111
- elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'r'
112
- project_dir.selected_child.run
113
136
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'z'
114
137
  key_event.doit = !Command.undo(file)
115
138
  elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'a'
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.6.2
4
+ version: 0.7.2
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-12-07 00:00:00.000000000 Z
11
+ date: 2021-01-17 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: 4.17.10.3
18
+ version: 4.18.0.2
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 5.0.0.0
22
22
  name: glimmer-dsl-swt
23
- prerelease: false
24
23
  type: :runtime
24
+ prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.17.10.3
29
+ version: 4.18.0.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.0.0.0
@@ -37,8 +37,8 @@ dependencies:
37
37
  - !ruby/object:Gem::Version
38
38
  version: 1.1.1
39
39
  name: filewatcher
40
- prerelease: false
41
40
  type: :runtime
41
+ prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
@@ -51,8 +51,8 @@ dependencies:
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.3.5
53
53
  name: clipboard
54
- prerelease: false
55
54
  type: :runtime
55
+ prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
@@ -65,8 +65,8 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: 3.5.0
67
67
  name: rspec
68
- prerelease: false
69
68
  type: :development
69
+ prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
@@ -79,8 +79,8 @@ dependencies:
79
79
  - !ruby/object:Gem::Version
80
80
  version: 2.3.9
81
81
  name: jeweler
82
- prerelease: false
83
82
  type: :development
83
+ prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - '='
@@ -93,8 +93,8 @@ dependencies:
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  name: simplecov
96
- prerelease: false
97
96
  type: :development
97
+ prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="
@@ -114,16 +114,21 @@ extra_rdoc_files:
114
114
  - LICENSE.txt
115
115
  - README.md
116
116
  files:
117
+ - CHANGELOG.md
117
118
  - LICENSE.txt
118
119
  - README.md
119
120
  - VERSION
120
121
  - bin/gladiator
121
122
  - bin/gladiator_runner.rb
123
+ - glimmer-cs-gladiator.gemspec
124
+ - images/glimmer-cs-gladiator-logo.png
122
125
  - lib/glimmer-cs-gladiator.rb
123
126
  - lib/models/glimmer/gladiator/command.rb
124
127
  - lib/models/glimmer/gladiator/dir.rb
125
128
  - lib/models/glimmer/gladiator/file.rb
126
129
  - lib/views/glimmer/gladiator.rb
130
+ - lib/views/glimmer/gladiator/file_explorer_tree.rb
131
+ - lib/views/glimmer/gladiator/file_lookup_list.rb
127
132
  - lib/views/glimmer/gladiator/text_editor.rb
128
133
  homepage: http://github.com/AndyObtiva/glimmer-cs-gladiator
129
134
  licenses:
@@ -144,8 +149,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
149
  - !ruby/object:Gem::Version
145
150
  version: '0'
146
151
  requirements: []
147
- rubygems_version: 3.1.4
152
+ rubygems_version: 3.0.6
148
153
  signing_key:
149
154
  specification_version: 4
150
- summary: Gladiator (Glimmer Editor) - Glimmer Custom Shell
155
+ summary: Gladiator (Glimmer Editor) - Glimmer Custom Shell - Text Editor Built in
156
+ Ruby
151
157
  test_files: []