glimmer-cs-gladiator 0.7.0 → 0.8.1

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
@@ -0,0 +1,189 @@
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 GladiatorMenuBar
25
+ include Glimmer::UI::CustomWidget
26
+
27
+ options :gladiator, :editing
28
+
29
+ body {
30
+ menu_bar {
31
+ menu {
32
+ text '&File'
33
+
34
+ menu_item {
35
+ text 'New &Scratchpad'
36
+ accelerator COMMAND_KEY, :shift, :s
37
+ enabled editing
38
+ on_widget_selected {
39
+ project_dir.selected_child_path = ''
40
+ }
41
+ }
42
+ menu_item {
43
+ text 'Open &Project...'
44
+ accelerator COMMAND_KEY, :o
45
+ on_widget_selected {
46
+ gladiator.open_project
47
+ }
48
+ }
49
+ menu_item(:separator)
50
+ menu_item {
51
+ text '&Quit Project'
52
+ accelerator COMMAND_KEY, :alt, :q
53
+ on_widget_selected {
54
+ gladiator.save_config
55
+ project_dir.selected_child&.write_dirty_content
56
+ gladiator.body_root.close
57
+ }
58
+ }
59
+ }
60
+ if editing
61
+ menu {
62
+ text '&View'
63
+ menu {
64
+ text '&Split Pane'
65
+ menu { |menu_proxy|
66
+ text '&Orientation'
67
+ menu_item(:radio) {
68
+ text '&Horizontal'
69
+ selection bind(gladiator, :split_orientation,
70
+ on_read: ->(o) { gladiator.split_pane? && o == swt(:horizontal) },
71
+ on_write: ->(b) { b.nil? ? nil : (b ? swt(:horizontal) : swt(:vertical)) })
72
+ }
73
+ menu_item(:radio) {
74
+ text '&Vertical'
75
+ selection bind(gladiator, :split_orientation,
76
+ on_read: ->(o) { gladiator.split_pane? && o == swt(:vertical) },
77
+ on_write: ->(b) { b.nil? ? nil : (b ? swt(:vertical) : swt(:horizontal)) })
78
+ }
79
+ }
80
+ menu_item(:check) {
81
+ text '&Maximize Pane'
82
+ enabled bind(gladiator, :tab_folder2)
83
+ accelerator COMMAND_KEY, :shift, :m
84
+ selection bind(gladiator, :maximized_pane)
85
+ }
86
+ menu_item {
87
+ text 'Reset &Panes'
88
+ enabled bind(gladiator, :tab_folder2)
89
+ accelerator COMMAND_KEY, :shift, :p
90
+ on_widget_selected {
91
+ if gladiator.tab_folder2
92
+ gladiator.maximized_pane = false
93
+ gladiator.tab_folder_sash_form.weights = [1, 1]
94
+ end
95
+ }
96
+ }
97
+ menu_item {
98
+ text '&Unsplit'
99
+ enabled bind(gladiator, :tab_folder2)
100
+ accelerator COMMAND_KEY, :shift, :u
101
+ on_widget_selected {
102
+ if gladiator.tab_folder2
103
+ gladiator.maximized_pane = false
104
+ gladiator.navigate_to_next_tab_folder if gladiator.current_tab_folder != gladiator.tab_folder2
105
+ gladiator.close_all_tabs(gladiator.tab_folder2)
106
+ gladiator.split_orientation = nil
107
+ gladiator.body_root.pack_same_size
108
+ end
109
+ }
110
+ }
111
+ }
112
+ menu_item(:check) {
113
+ text '&Maximize Editor'
114
+ accelerator COMMAND_KEY, CONTROL_KEY, :m
115
+ selection bind(gladiator, :maximized_editor)
116
+ }
117
+ menu_item {
118
+ text '&Reset All'
119
+ accelerator COMMAND_KEY, CONTROL_KEY, :r
120
+ on_widget_selected {
121
+ gladiator.maximized_editor = false
122
+ gladiator.file_area_and_editor_area_sash_form.weights = [1, 5]
123
+ gladiator.side_bar_sash_form.weights = [1, 1]
124
+ unless gladiator.file_lookup_expand_item.swt_expand_item.get_expanded
125
+ gladiator.file_lookup_expand_item.swt_expand_item.set_expanded true
126
+ gladiator.file_lookup_expand_item.swt_expand_item.height = gladiator.file_lookup_expand_item_height if gladiator.file_lookup_expand_item_height
127
+ end
128
+ unless gladiator.file_explorer_expand_item.swt_expand_item.get_expanded
129
+ gladiator.file_explorer_expand_item.swt_expand_item.set_expanded true
130
+ gladiator.file_explorer_expand_item.swt_expand_item.height = gladiator.file_explorer_expand_item_height if gladiator.file_explorer_expand_item_height
131
+ end
132
+ }
133
+ }
134
+ }
135
+ menu {
136
+ text '&Run'
137
+ # menu_item {
138
+ # text 'Launch Glimmer &App'
139
+ # on_widget_selected {
140
+ # parent_path = project_dir.path
141
+ ## current_directory_name = ::File.basename(parent_path)
142
+ ## assumed_shell_script = ::File.join(parent_path, 'bin', current_directory_name)
143
+ ## assumed_shell_script = ::Dir.glob(::File.join(parent_path, 'bin', '*')).detect {|f| ::File.file?(f) && !::File.read(f).include?('#!/usr/bin/env')} if !::File.exist?(assumed_shell_script)
144
+ ## load assumed_shell_script
145
+ # FileUtils.cd(parent_path) do
146
+ # system 'glimmer run'
147
+ # end
148
+ # }
149
+ # }
150
+ menu_item {
151
+ text '&Ruby'
152
+ accelerator COMMAND_KEY, :shift, :r
153
+ on_widget_selected {
154
+ begin
155
+ project_dir.selected_child.run
156
+ rescue Exception => e
157
+ dialog {
158
+ text 'Run - Ruby - Error Encountered!'
159
+ label {
160
+ text e.full_message
161
+ }
162
+ }.open
163
+ end
164
+ }
165
+ }
166
+ }
167
+ end
168
+ menu {
169
+ text '&Help'
170
+ menu_item {
171
+ text '&About'
172
+ accelerator COMMAND_KEY, :shift, :a
173
+ on_widget_selected {
174
+ gladiator.display_about_dialog
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ def project_dir
182
+ gladiator.project_dir
183
+ end
184
+
185
+ end
186
+
187
+ end
188
+
189
+ end