glimmer-cs-gladiator 0.7.1 → 0.7.2

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: 42a4c55757f8f11ff94253067439895f7e1c0a1a1ebb3aaaf6d9d1d068ea82eb
4
- data.tar.gz: d09c688ba5042f0be4489347c6937780b5e06e815d8879499f30c73857a27969
3
+ metadata.gz: 55dd5d14035a4d76ce686365ba16ab6a49c8f1fcbef2298d171fdeea2b2777b8
4
+ data.tar.gz: 65e5240faa47773332187063daa9500441ecc2a8a6b117aee646f4bf47162588
5
5
  SHA512:
6
- metadata.gz: 6b3d619fbf4ad18ce233d86bfa6fcd902b3865e0177fac7021392354f72a07f0c93c47e70cb066a0e21c4358592f13b2f24dd66123d15c66eb971f6e2941ce57
7
- data.tar.gz: fa59fa6baab0ef8b35ff6864692739f98a6f515cc63a61320cb12c92141c810364570e880e923e657401e1c56a533d98abbcc89fb609ad02126a9da39ed05e5f
6
+ metadata.gz: 77ba3e5e51fc0b9a815ee753c1fbfe839714217a56259dd6a12b6646b08df28a33ecdf5c87dbe169e62fdfd4063d799378fcc7781c46623451ba2d6ac6055fbd
7
+ data.tar.gz: 20f95fcdaf04f39d4ce979e30846ab2442ac37d416830d63cc95413dd89942c426c36fbc98f2d6328f97e1717f08243cfa5dcb38cea79b0e89873315c4878f39
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.7.2
4
+
5
+ - Fallback font ("Courier") for text editor when "Consolas" is not available
6
+ - Refactor Gladiator Custom Shell to extract more Glimmer Custom Widgets from it like FileLookupList and FileExplorerTree
7
+ - Upgrade to glimmer-dsl-swt v4.18.0.2
8
+
3
9
  ## 0.7.1
4
10
 
5
11
  - Update View -> Reset All to also reset the File Lookup/File Explorer Sash Width and the Navigation Bar (expanding it)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src='https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-gladiator/master/images/glimmer-cs-gladiator-logo.svg' height=85 /> Gladiator 0.7.1 - [Ugliest Text Editor Ever!](https://www.reddit.com/r/ruby/comments/hgve8k/gladiator_glimmer_editor_ugliest_text_editor_ever/)
1
+ # <img src='https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-gladiator/master/images/glimmer-cs-gladiator-logo.svg' height=85 /> Gladiator 0.7.2 - [Ugliest Text Editor Ever!](https://www.reddit.com/r/ruby/comments/hgve8k/gladiator_glimmer_editor_ugliest_text_editor_ever/)
2
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-dsl-swt#custom-shell-gem)
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-cs-gladiator.svg)](http://badge.fury.io/rb/glimmer-cs-gladiator)
4
4
 
@@ -150,7 +150,7 @@ To reuse Gladiator as a Glimmer Custom Shell inside another Glimmer application,
150
150
  following to the application's `Gemfile`:
151
151
 
152
152
  ```
153
- gem 'glimmer-cs-gladiator', '>= 0.7.1'
153
+ gem 'glimmer-cs-gladiator', '>= 0.7.2'
154
154
  ```
155
155
 
156
156
  Run:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-cs-gladiator 0.7.1 ruby lib
5
+ # stub: glimmer-cs-gladiator 0.7.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-cs-gladiator".freeze
9
- s.version = "0.7.1"
9
+ s.version = "0.7.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Andy Maleh".freeze]
14
- s.date = "2021-01-15"
14
+ s.date = "2021-01-17"
15
15
  s.description = "Gladiator (short for Glimmer Editor) is a Glimmer sample project under on-going development. 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. Gladiator is also a personal tool for shaping an editor exactly the way I like. I leave building truly professional text editors to software tooling experts who would hopefully use Glimmer one day.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.executables = ["gladiator".freeze]
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
33
33
  "lib/models/glimmer/gladiator/dir.rb",
34
34
  "lib/models/glimmer/gladiator/file.rb",
35
35
  "lib/views/glimmer/gladiator.rb",
36
+ "lib/views/glimmer/gladiator/file_explorer_tree.rb",
37
+ "lib/views/glimmer/gladiator/file_lookup_list.rb",
36
38
  "lib/views/glimmer/gladiator/text_editor.rb"
37
39
  ]
38
40
  s.homepage = "http://github.com/AndyObtiva/glimmer-cs-gladiator".freeze
@@ -44,14 +46,14 @@ Gem::Specification.new do |s|
44
46
  s.specification_version = 4
45
47
 
46
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<glimmer-dsl-swt>.freeze, [">= 4.18.0.0", "< 5.0.0.0"])
49
+ s.add_runtime_dependency(%q<glimmer-dsl-swt>.freeze, [">= 4.18.0.2", "< 5.0.0.0"])
48
50
  s.add_runtime_dependency(%q<filewatcher>.freeze, ["~> 1.1.1"])
49
51
  s.add_runtime_dependency(%q<clipboard>.freeze, ["~> 1.3.5"])
50
52
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
51
53
  s.add_development_dependency(%q<jeweler>.freeze, ["= 2.3.9"])
52
54
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
53
55
  else
54
- s.add_dependency(%q<glimmer-dsl-swt>.freeze, [">= 4.18.0.0", "< 5.0.0.0"])
56
+ s.add_dependency(%q<glimmer-dsl-swt>.freeze, [">= 4.18.0.2", "< 5.0.0.0"])
55
57
  s.add_dependency(%q<filewatcher>.freeze, ["~> 1.1.1"])
56
58
  s.add_dependency(%q<clipboard>.freeze, ["~> 1.3.5"])
57
59
  s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
@@ -59,7 +61,7 @@ Gem::Specification.new do |s|
59
61
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
60
62
  end
61
63
  else
62
- s.add_dependency(%q<glimmer-dsl-swt>.freeze, [">= 4.18.0.0", "< 5.0.0.0"])
64
+ s.add_dependency(%q<glimmer-dsl-swt>.freeze, [">= 4.18.0.2", "< 5.0.0.0"])
63
65
  s.add_dependency(%q<filewatcher>.freeze, ["~> 1.1.1"])
64
66
  s.add_dependency(%q<clipboard>.freeze, ["~> 1.3.5"])
65
67
  s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
@@ -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
  require 'fileutils'
2
23
  require 'os'
3
24
 
@@ -6,6 +27,8 @@ require 'models/glimmer/gladiator/file'
6
27
  require 'models/glimmer/gladiator/command'
7
28
 
8
29
  require 'views/glimmer/gladiator/text_editor'
30
+ require 'views/glimmer/gladiator/file_lookup_list'
31
+ require 'views/glimmer/gladiator/file_explorer_tree'
9
32
 
10
33
  Clipboard.implementation = Clipboard::Java
11
34
  Clipboard.copy(Clipboard.paste) # pre-initialize library to avoid slowdown during use
@@ -57,7 +80,7 @@ module Glimmer
57
80
  pane_count && pane_count > 1
58
81
  end
59
82
 
60
- attr_reader :find_text, :filter_text, :rename_in_progress, :line_number_text, :file_tree, :split_orientation
83
+ attr_reader :find_text, :filter_text, :line_number_text, :split_orientation
61
84
  attr_accessor :current_tab_item, :current_tab_folder, :current_text_editor, :tab_folder1, :tab_folder2, :maximized_pane, :maximized_editor
62
85
  alias maximized_pane? maximized_pane
63
86
  alias maximized_editor? maximized_editor
@@ -102,7 +125,7 @@ module Glimmer
102
125
  #
103
126
  after_body {
104
127
  observe(project_dir, 'children') do
105
- select_tree_item unless @rename_in_progress || Gladiator.startup
128
+ @file_explorer_tree.select_tree_item unless Gladiator.startup
106
129
  end
107
130
  observe(project_dir, 'selected_child') do |selected_file|
108
131
  if selected_file
@@ -114,7 +137,7 @@ module Glimmer
114
137
  }
115
138
  body_root.pack_same_size
116
139
  end
117
- select_tree_item unless @rename_in_progress || Gladiator.startup
140
+ @file_explorer_tree.select_tree_item unless Gladiator.startup
118
141
  found_tab_item = selected_tab_item
119
142
  if found_tab_item
120
143
  @current_tab_folder.swt_widget.setSelection(found_tab_item)
@@ -442,28 +465,8 @@ module Glimmer
442
465
  }
443
466
  }
444
467
 
445
- @file_lookup_list = list(:border, :h_scroll, :v_scroll) {
468
+ @file_lookup_list = file_lookup_list(gladiator: self, foreground_color: @default_foreground) {
446
469
  layout_data :fill, :fill, true, true
447
- #visible bind(self, 'project_dir.filter') {|f| !!f}
448
- selection bind(project_dir, :filtered_path)
449
- foreground @default_foreground
450
- on_mouse_up {
451
- project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
452
- }
453
- on_key_pressed { |key_event|
454
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
455
- project_dir.selected_child_path = @file_lookup_list.swt_widget.getSelection.first
456
- @current_text_editor&.text_widget&.setFocus
457
- end
458
- }
459
- drag_source(DND::DROP_COPY) {
460
- transfer [TextTransfer.getInstance].to_java(Transfer)
461
- on_drag_set_data { |event|
462
- Gladiator.drag = true
463
- list = event.widget.getControl
464
- event.data = list.getSelection.first
465
- }
466
- }
467
470
  }
468
471
  }
469
472
 
@@ -503,84 +506,8 @@ module Glimmer
503
506
  text 'File Explorer'
504
507
  height display.bounds.height
505
508
 
506
- @file_tree = tree(:virtual, :border, :h_scroll, :v_scroll) {
509
+ @file_explorer_tree = file_explorer_tree(gladiator: self, foreground_color: @default_foreground) {
507
510
  layout_data :fill, :fill, true, true
508
- #visible bind(self, 'project_dir.filter') {|f| !f}
509
- items bind(self, :project_dir), tree_properties(children: :children, text: :name)
510
- foreground @default_foreground
511
- drag_source(DND::DROP_COPY) {
512
- transfer [TextTransfer.getInstance].to_java(Transfer)
513
- on_drag_set_data { |event|
514
- Gladiator.drag = true
515
- tree = event.widget.getControl
516
- tree_item = tree.getSelection.first
517
- event.data = tree_item.getData.path
518
- }
519
- }
520
- menu {
521
- @open_menu_item = menu_item {
522
- text 'Open'
523
- on_widget_selected {
524
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
525
- }
526
- }
527
- menu_item(:separator)
528
- menu_item {
529
- text 'Delete'
530
- on_widget_selected {
531
- tree_item = @file_tree.swt_widget.getSelection.first
532
- delete_tree_item(tree_item)
533
- }
534
- }
535
- menu_item {
536
- text 'Refresh'
537
- on_widget_selected {
538
- project_dir.refresh
539
- }
540
- }
541
- menu_item {
542
- text 'Rename'
543
- on_widget_selected {
544
- rename_selected_tree_item
545
- }
546
- }
547
- menu_item {
548
- text 'New Directory'
549
- on_widget_selected {
550
- add_new_directory_to_selected_tree_item
551
- }
552
- }
553
- menu_item {
554
- text 'New File'
555
- on_widget_selected {
556
- add_new_file_to_selected_tree_item
557
- }
558
- }
559
- }
560
- on_swt_menudetect { |event|
561
- path = extract_tree_item_path(@file_tree.swt_widget.getSelection.first)
562
- @open_menu_item.swt_widget.setEnabled(!::Dir.exist?(path)) if path
563
- }
564
- on_mouse_up {
565
- if Gladiator.drag_and_drop
566
- Gladiator.drag_and_drop = false
567
- else
568
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
569
- @current_text_editor&.text_widget&.setFocus
570
- end
571
- }
572
- on_key_pressed { |key_event|
573
- if Glimmer::SWT::SWTProxy.include?(key_event.keyCode, :cr)
574
- project_dir.selected_child_path = extract_tree_item_path(@file_tree.swt_widget.getSelection&.first)
575
- @current_text_editor&.text_widget&.setFocus
576
- end
577
- }
578
- on_paint_control {
579
- root_item = @file_tree.swt_widget.getItems.first
580
- if root_item && !root_item.getExpanded
581
- root_item.setExpanded(true)
582
- end
583
- }
584
511
  }
585
512
  }
586
513
 
@@ -602,13 +529,7 @@ module Glimmer
602
529
  }
603
530
 
604
531
  }
605
-
606
- # TODO see if you could replace some of this with Glimmer DSL/API syntax
607
- @file_tree_editor = TreeEditor.new(@file_tree.swt_widget);
608
- @file_tree_editor.horizontalAlignment = swt(:left);
609
- @file_tree_editor.grabHorizontal = true;
610
- @file_tree_editor.minimumHeight = 20;
611
-
532
+
612
533
  }
613
534
 
614
535
  @editor_area_composite = composite {
@@ -1058,125 +979,6 @@ module Glimmer
1058
979
  async_exec { body_root.pack_same_size }
1059
980
  end
1060
981
 
1061
- def extract_tree_item_path(tree_item)
1062
- return if tree_item.nil?
1063
- if tree_item.getParentItem
1064
- ::File.join(extract_tree_item_path(tree_item.getParentItem), tree_item.getText)
1065
- else
1066
- project_dir.path
1067
- end
1068
- end
1069
-
1070
- def select_tree_item
1071
- return unless project_dir.selected_child&.name
1072
- tree_items_to_select = @file_tree.depth_first_search { |ti| ti.getData.path == project_dir.selected_child.path }
1073
- @file_tree.swt_widget.setSelection(tree_items_to_select)
1074
- end
1075
-
1076
- def delete_tree_item(tree_item)
1077
- return if tree_item.nil?
1078
- file = tree_item.getData
1079
- parent_path = ::File.dirname(file.path)
1080
- if file.is_a?(Gladiator::Dir)
1081
- file_paths = file.all_children.select {|f| f.is_a?(Gladiator::File)}.map(&:path)
1082
- file.remove_all_observers
1083
- else
1084
- file_paths = [file.path]
1085
- end
1086
- file_paths.each do |file_path|
1087
- found_tab_item = find_tab_item(file_path)
1088
- if found_tab_item
1089
- project_dir.selected_child_path_history.delete(found_tab_item.getData('file_path'))
1090
- found_tab_item.getData('proxy')&.dispose
1091
- end
1092
- end
1093
- file.delete! # TODO consider supporting command undo/redo
1094
- project_dir.refresh(async: false)
1095
- parent_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == parent_path}.first
1096
- @file_tree.swt_widget.showItem(parent_tree_item)
1097
- parent_tree_item.setExpanded(true)
1098
- rescue => e
1099
- puts e.full_message
1100
- end
1101
-
1102
- def add_new_directory_to_selected_tree_item
1103
- project_dir.pause_refresh
1104
- tree_item = @file_tree.swt_widget.getSelection.first
1105
- directory_path = extract_tree_item_path(tree_item)
1106
- return if directory_path.nil?
1107
- if !::Dir.exist?(directory_path)
1108
- tree_item = tree_item.getParentItem
1109
- directory_path = ::File.dirname(directory_path)
1110
- end
1111
- new_directory_path = ::File.expand_path(::File.join(directory_path, 'new_directory'))
1112
- FileUtils.mkdir_p(new_directory_path)
1113
- project_dir.refresh(async: false, force: true)
1114
- new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_directory_path}.first
1115
- @file_tree.swt_widget.showItem(new_tree_item)
1116
- rename_tree_item(new_tree_item)
1117
- end
1118
-
1119
- def add_new_file_to_selected_tree_item
1120
- project_dir.pause_refresh
1121
- tree_item = @file_tree.swt_widget.getSelection.first
1122
- directory_path = extract_tree_item_path(tree_item)
1123
- if !::Dir.exist?(directory_path)
1124
- tree_item = tree_item.getParentItem
1125
- directory_path = ::File.dirname(directory_path)
1126
- end
1127
- new_file_path = ::File.expand_path(::File.join(directory_path, 'new_file'))
1128
- FileUtils.touch(new_file_path)
1129
- # TODO look into refreshing only the parent directory to avoid slowdown
1130
- project_dir.refresh(async: false, force: true)
1131
- new_tree_item = @file_tree.depth_first_search {|ti| ti.getData.path == new_file_path}.first
1132
- @file_tree.swt_widget.showItem(new_tree_item)
1133
- rename_tree_item(new_tree_item, true)
1134
- end
1135
-
1136
- def rename_selected_tree_item
1137
- project_dir.pause_refresh
1138
- tree_item = @file_tree.swt_widget.getSelection.first
1139
- rename_tree_item(tree_item)
1140
- end
1141
-
1142
- def rename_tree_item(tree_item, new_file = false)
1143
- original_file = tree_item.getData
1144
- current_file = project_dir.selected_child_path == original_file.path
1145
- found_tab_item = find_tab_item(original_file.path)
1146
- found_text_editor = found_tab_item&.getData('text_editor')
1147
- @file_tree.edit_tree_item(
1148
- tree_item,
1149
- after_write: -> (edited_tree_item) {
1150
- file = edited_tree_item.getData
1151
- file_path = file.path
1152
- file.name
1153
- if ::File.file?(file_path)
1154
- if new_file
1155
- project_dir.selected_child_path = file_path
1156
- else
1157
- found_text_editor&.file = file
1158
- found_tab_item&.setData('file', file)
1159
- found_tab_item&.setData('file_path', file.path)
1160
- found_tab_item&.setText(file.name)
1161
- body_root.pack_same_size
1162
- if current_file
1163
- project_dir.selected_child_path = file_path
1164
- else
1165
- selected_tab_item&.getData('text_editor')&.text_widget&.setFocus
1166
- end
1167
- async_exec {
1168
- @file_tree.swt_widget.showItem(edited_tree_item)
1169
- }
1170
- end
1171
- end
1172
- project_dir.resume_refresh
1173
- },
1174
- after_cancel: -> {
1175
- project_dir.resume_refresh
1176
- }
1177
- )
1178
- end
1179
-
1180
982
  def extract_char(event)
1181
983
  event.keyCode.chr
1182
984
  rescue => e
@@ -1360,8 +1162,8 @@ module Glimmer
1360
1162
  @file_explorer_expand_item.swt_expand_item.height = @file_explorer_expand_item_height if @file_explorer_expand_item_height
1361
1163
  @side_bar_sash_form.weights = [@file_lookup_expand_bar_height, @file_explorer_expand_bar_height]
1362
1164
  end
1363
- select_tree_item unless rename_in_progress
1364
- file_tree.swt_widget.setFocus
1165
+ @file_explorer_tree.select_tree_item
1166
+ @file_explorer_tree.swt_widget.setFocus
1365
1167
  elsif key_event.keyCode == swt(:esc)
1366
1168
  if current_text_editor
1367
1169
  project_dir.selected_child_path = current_text_editor.file.path
@@ -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
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.7.1
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: 2021-01-15 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.18.0.0
18
+ version: 4.18.0.2
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 5.0.0.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.18.0.0
29
+ version: 4.18.0.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 5.0.0.0
@@ -127,6 +127,8 @@ files:
127
127
  - lib/models/glimmer/gladiator/dir.rb
128
128
  - lib/models/glimmer/gladiator/file.rb
129
129
  - lib/views/glimmer/gladiator.rb
130
+ - lib/views/glimmer/gladiator/file_explorer_tree.rb
131
+ - lib/views/glimmer/gladiator/file_lookup_list.rb
130
132
  - lib/views/glimmer/gladiator/text_editor.rb
131
133
  homepage: http://github.com/AndyObtiva/glimmer-cs-gladiator
132
134
  licenses: