redcar 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +24 -0
- data/Rakefile +85 -2
- data/lib/json/CHANGES +166 -0
- data/lib/json/COPYING +58 -0
- data/lib/json/GPL +340 -0
- data/lib/json/README +358 -0
- data/lib/json/Rakefile +292 -0
- data/lib/json/TODO +1 -0
- data/lib/json/VERSION +1 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
- data/lib/json/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
- data/lib/json/benchmarks/generator2_benchmark.rb +222 -0
- data/lib/json/benchmarks/generator_benchmark.rb +224 -0
- data/lib/json/benchmarks/ohai.json +1216 -0
- data/lib/json/benchmarks/ohai.ruby +1 -0
- data/lib/json/benchmarks/parser2_benchmark.rb +251 -0
- data/lib/json/benchmarks/parser_benchmark.rb +259 -0
- data/lib/json/bin/edit_json.rb +9 -0
- data/lib/json/bin/prettify_json.rb +75 -0
- data/lib/json/data/example.json +1 -0
- data/lib/json/data/index.html +38 -0
- data/lib/json/data/prototype.js +4184 -0
- data/lib/json/ext/json/ext/generator/extconf.rb +16 -0
- data/lib/json/ext/json/ext/generator/generator.c +1323 -0
- data/lib/json/ext/json/ext/generator/generator.h +170 -0
- data/lib/json/ext/json/ext/parser/extconf.rb +15 -0
- data/lib/json/ext/json/ext/parser/parser.c +1935 -0
- data/lib/json/ext/json/ext/parser/parser.h +71 -0
- data/lib/json/ext/json/ext/parser/parser.rl +792 -0
- data/lib/json/install.rb +26 -0
- data/lib/json/lib/json.rb +10 -0
- data/lib/json/lib/json/Array.xpm +21 -0
- data/lib/json/lib/json/FalseClass.xpm +21 -0
- data/lib/json/lib/json/Hash.xpm +21 -0
- data/lib/json/lib/json/Key.xpm +73 -0
- data/lib/json/lib/json/NilClass.xpm +21 -0
- data/lib/json/lib/json/Numeric.xpm +28 -0
- data/lib/json/lib/json/String.xpm +96 -0
- data/lib/json/lib/json/TrueClass.xpm +21 -0
- data/lib/json/lib/json/add/core.rb +148 -0
- data/lib/json/lib/json/add/rails.rb +58 -0
- data/lib/json/lib/json/common.rb +397 -0
- data/lib/json/lib/json/editor.rb +1371 -0
- data/lib/json/lib/json/ext.rb +15 -0
- data/lib/json/lib/json/json.xpm +1499 -0
- data/lib/json/lib/json/pure.rb +77 -0
- data/lib/json/lib/json/pure/generator.rb +452 -0
- data/lib/json/lib/json/pure/parser.rb +307 -0
- data/lib/json/lib/json/version.rb +8 -0
- data/lib/json/tests/fixtures/fail1.json +1 -0
- data/lib/json/tests/fixtures/fail10.json +1 -0
- data/lib/json/tests/fixtures/fail11.json +1 -0
- data/lib/json/tests/fixtures/fail12.json +1 -0
- data/lib/json/tests/fixtures/fail13.json +1 -0
- data/lib/json/tests/fixtures/fail14.json +1 -0
- data/lib/json/tests/fixtures/fail18.json +1 -0
- data/lib/json/tests/fixtures/fail19.json +1 -0
- data/lib/json/tests/fixtures/fail2.json +1 -0
- data/lib/json/tests/fixtures/fail20.json +1 -0
- data/lib/json/tests/fixtures/fail21.json +1 -0
- data/lib/json/tests/fixtures/fail22.json +1 -0
- data/lib/json/tests/fixtures/fail23.json +1 -0
- data/lib/json/tests/fixtures/fail24.json +1 -0
- data/lib/json/tests/fixtures/fail25.json +1 -0
- data/lib/json/tests/fixtures/fail27.json +2 -0
- data/lib/json/tests/fixtures/fail28.json +2 -0
- data/lib/json/tests/fixtures/fail3.json +1 -0
- data/lib/json/tests/fixtures/fail4.json +1 -0
- data/lib/json/tests/fixtures/fail5.json +1 -0
- data/lib/json/tests/fixtures/fail6.json +1 -0
- data/lib/json/tests/fixtures/fail7.json +1 -0
- data/lib/json/tests/fixtures/fail8.json +1 -0
- data/lib/json/tests/fixtures/fail9.json +1 -0
- data/lib/json/tests/fixtures/pass1.json +56 -0
- data/lib/json/tests/fixtures/pass15.json +1 -0
- data/lib/json/tests/fixtures/pass16.json +1 -0
- data/lib/json/tests/fixtures/pass17.json +1 -0
- data/lib/json/tests/fixtures/pass2.json +1 -0
- data/lib/json/tests/fixtures/pass26.json +1 -0
- data/lib/json/tests/fixtures/pass3.json +6 -0
- data/lib/json/tests/test_json.rb +361 -0
- data/lib/json/tests/test_json_addition.rb +162 -0
- data/lib/json/tests/test_json_encoding.rb +68 -0
- data/lib/json/tests/test_json_fixtures.rb +34 -0
- data/lib/json/tests/test_json_generate.rb +122 -0
- data/lib/json/tests/test_json_rails.rb +144 -0
- data/lib/json/tests/test_json_unicode.rb +76 -0
- data/lib/json/tools/fuzz.rb +139 -0
- data/lib/json/tools/server.rb +61 -0
- data/lib/redcar.rb +5 -3
- data/lib/redcar/runner.rb +1 -5
- data/lib/redcar_quick_start.rb +2 -7
- data/plugins/application/features/support/env.rb +6 -1
- data/plugins/application/lib/application/command/history.rb +5 -0
- data/plugins/application/lib/application/dialog.rb +1 -1
- data/plugins/application_swt/lib/application_swt.rb +0 -1
- data/plugins/application_swt/lib/application_swt/html_tab.rb +4 -2
- data/plugins/application_swt/lib/application_swt/menu.rb +3 -1
- data/plugins/application_swt/lib/application_swt/swt_wrapper.rb +4 -0
- data/plugins/core/lib/core.rb +1 -0
- data/plugins/core/lib/core/has_spi.rb +10 -0
- data/plugins/edit_view/features/new_tab.feature +0 -1
- data/plugins/edit_view/features/step_definitions/tab_steps.rb +1 -1
- data/plugins/edit_view/lib/edit_view.rb +13 -0
- data/plugins/edit_view/lib/edit_view/document/command.rb +1 -1
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +4 -0
- data/plugins/html_view/assets/redcar.css +2 -1
- data/plugins/html_view/lib/html_view.rb +19 -6
- data/plugins/html_view/lib/html_view/html_tab.rb +2 -2
- data/plugins/project/lib/project.rb +11 -0
- data/plugins/project/lib/project/dir_controller.rb +252 -2
- data/plugins/project/lib/project/dir_mirror.rb +53 -5
- data/plugins/project/lib/project/manager.rb +5 -1
- data/plugins/project/views/bulk_rename.html.erb +162 -0
- data/plugins/redcar/redcar.rb +22 -2
- data/plugins/runnables/icons/cog.png +0 -0
- data/plugins/runnables/lib/runnables.rb +99 -0
- data/plugins/runnables/plugin_no_load.rb +9 -0
- data/plugins/tree/lib/tree.rb +61 -0
- data/plugins/tree/lib/tree/controller.rb +53 -4
- data/plugins/tree/lib/tree/mirror.rb +56 -16
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +250 -24
- metadata +2700 -2604
- data/plugins/application_swt/lib/application_swt/notebook/drag_and_drop_listener.rb +0 -71
|
@@ -211,6 +211,10 @@ module Redcar
|
|
|
211
211
|
@mate_text.get_control.set_focus
|
|
212
212
|
end
|
|
213
213
|
|
|
214
|
+
def is_current?
|
|
215
|
+
EditView.current == @mate_text.get_control
|
|
216
|
+
end
|
|
217
|
+
|
|
214
218
|
def has_focus?
|
|
215
219
|
focus_control = ApplicationSWT.display.get_focus_control
|
|
216
220
|
focus_control == @mate_text.get_control
|
|
@@ -3,6 +3,14 @@ require 'html_view/html_tab'
|
|
|
3
3
|
|
|
4
4
|
module Redcar
|
|
5
5
|
class HtmlView
|
|
6
|
+
def self.default_css_path
|
|
7
|
+
File.expand_path(File.join(Redcar.root, %w(plugins html_view assets redcar.css)))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.jquery_path
|
|
11
|
+
File.expand_path(File.join(Redcar.root, %w(plugins html_view assets jquery-1.4.min.js)))
|
|
12
|
+
end
|
|
13
|
+
|
|
6
14
|
attr_reader :controller
|
|
7
15
|
|
|
8
16
|
def initialize(html_tab)
|
|
@@ -18,13 +26,14 @@ module Redcar
|
|
|
18
26
|
controller_action("index")
|
|
19
27
|
end
|
|
20
28
|
|
|
21
|
-
def controller_action(action_name,
|
|
22
|
-
|
|
29
|
+
def controller_action(action_name, params=nil)
|
|
30
|
+
text = nil
|
|
23
31
|
begin
|
|
32
|
+
action_method_arity = controller.method(action_name).arity
|
|
24
33
|
text = if action_method_arity == 0
|
|
25
34
|
controller.send(action_name)
|
|
26
35
|
elsif action_method_arity == 1
|
|
27
|
-
controller.send(action_name,
|
|
36
|
+
controller.send(action_name, params)
|
|
28
37
|
end
|
|
29
38
|
rescue => e
|
|
30
39
|
text = <<-HTML
|
|
@@ -32,7 +41,11 @@ module Redcar
|
|
|
32
41
|
#{e.message}
|
|
33
42
|
HTML
|
|
34
43
|
end
|
|
35
|
-
|
|
44
|
+
if text
|
|
45
|
+
unless @html_tab.controller.browser.disposed
|
|
46
|
+
@html_tab.controller.browser.set_text(text.to_s + setup_javascript_listeners)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
36
49
|
end
|
|
37
50
|
|
|
38
51
|
def contents=(source)
|
|
@@ -45,7 +58,7 @@ module Redcar
|
|
|
45
58
|
def function(args)
|
|
46
59
|
func_name = args.to_a.first
|
|
47
60
|
func_args = args.to_a.last.to_a
|
|
48
|
-
controller.send(func_name.to_sym, *func_args)
|
|
61
|
+
JSON(controller.send(func_name.to_sym, *func_args))
|
|
49
62
|
end
|
|
50
63
|
|
|
51
64
|
attr_accessor :controller
|
|
@@ -59,7 +72,7 @@ module Redcar
|
|
|
59
72
|
(controller.methods - Object.new.methods).each do |method_name|
|
|
60
73
|
method = []
|
|
61
74
|
method << " #{method_name.gsub(/_(\w)/) { |a| $1.upcase}}: function() {"
|
|
62
|
-
method << " rubyCall(\"#{method_name}\", Array.prototype.slice.call(arguments));"
|
|
75
|
+
method << " return eval(rubyCall(\"#{method_name}\", Array.prototype.slice.call(arguments)));"
|
|
63
76
|
method << " }"
|
|
64
77
|
methods << method.join("\n")
|
|
65
78
|
end
|
|
@@ -13,8 +13,8 @@ module Redcar
|
|
|
13
13
|
@html_view = HtmlView.new(self)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def controller_action(action,
|
|
17
|
-
notify_listeners(:controller_action, action,
|
|
16
|
+
def controller_action(action, params)
|
|
17
|
+
notify_listeners(:controller_action, action, params)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -124,5 +124,16 @@ module Redcar
|
|
|
124
124
|
end
|
|
125
125
|
@lost_application_focus = nil
|
|
126
126
|
end
|
|
127
|
+
|
|
128
|
+
def config_dir
|
|
129
|
+
File.join(path, ".redcar")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def config_file(name)
|
|
133
|
+
file_path = File.join(config_dir, name.to_s)
|
|
134
|
+
if File.exist?(file_path)
|
|
135
|
+
YAML.load(File.read(file_path))
|
|
136
|
+
end
|
|
137
|
+
end
|
|
127
138
|
end
|
|
128
139
|
end
|
|
@@ -2,13 +2,263 @@
|
|
|
2
2
|
module Redcar
|
|
3
3
|
class Project
|
|
4
4
|
class DirController
|
|
5
|
-
|
|
5
|
+
include Redcar::Tree::Controller
|
|
6
|
+
|
|
7
|
+
def activated(tree, node)
|
|
6
8
|
if node.leaf?
|
|
7
9
|
FileOpenCommand.new(node.path).run
|
|
8
10
|
end
|
|
9
11
|
end
|
|
12
|
+
|
|
13
|
+
class DragController
|
|
14
|
+
include Redcar::Tree::Controller::DragController
|
|
15
|
+
|
|
16
|
+
attr_reader :tree
|
|
17
|
+
|
|
18
|
+
def initialize(tree)
|
|
19
|
+
@tree = tree
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reorderable?
|
|
23
|
+
false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def can_drop?(nodes, target, position)
|
|
27
|
+
nodes.all? {|node| droppable?(node, target)}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def do_drop(nodes, target, position)
|
|
31
|
+
paths = nodes.map {|node| node.path }
|
|
32
|
+
non_nested_paths = remove_nested_paths(paths)
|
|
33
|
+
non_nested_paths.each do |path|
|
|
34
|
+
dir = target ? target.directory : tree.tree_mirror.path
|
|
35
|
+
unless File.dirname(path) == dir
|
|
36
|
+
FileUtils.mv(path, dir)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
tree.refresh
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def droppable?(from_node, target_node)
|
|
45
|
+
# you can always drop into the top level of the tree
|
|
46
|
+
return true if target_node == nil
|
|
47
|
+
|
|
48
|
+
# can't drop a file/dir onto itself
|
|
49
|
+
return false if from_node.path == target_node.path
|
|
50
|
+
|
|
51
|
+
# can't drop a directory into its children
|
|
52
|
+
!child_of?(from_node.path, target_node.path)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def child_of?(path, possible_child_path)
|
|
56
|
+
possible_child_path =~ /^#{Regexp.escape(path)}\//
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Removes paths which are children of higher level paths also being
|
|
60
|
+
# dragged.
|
|
61
|
+
def remove_nested_paths(paths)
|
|
62
|
+
sorted = paths.sort
|
|
63
|
+
keep = [sorted.first]
|
|
64
|
+
sorted[1..-1].each do |path|
|
|
65
|
+
unless child_of?(keep.last, path)
|
|
66
|
+
keep << path
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
keep
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def drag_controller(tree)
|
|
74
|
+
DragController.new(tree)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def right_click(tree, node)
|
|
78
|
+
controller = self
|
|
79
|
+
|
|
80
|
+
menu = Menu::Builder.build do
|
|
81
|
+
item("New File") { controller.new_file(tree, node) }
|
|
82
|
+
item("New Directory") { controller.new_dir(tree, node) }
|
|
83
|
+
separator
|
|
84
|
+
if tree.selection.length > 1
|
|
85
|
+
dirs = tree.selection.map {|node| node.parent_dir }
|
|
86
|
+
if dirs.uniq.length == 1
|
|
87
|
+
item("Bulk Rename") { controller.rename(tree, node) }
|
|
88
|
+
end
|
|
89
|
+
else
|
|
90
|
+
item("Rename") { controller.rename(tree, node) }
|
|
91
|
+
end
|
|
92
|
+
item("Delete") { controller.delete(tree, node) }
|
|
93
|
+
separator
|
|
94
|
+
if DirMirror.show_hidden_files?
|
|
95
|
+
item("Hide Hidden Files") do
|
|
96
|
+
DirMirror.show_hidden_files = false
|
|
97
|
+
tree.refresh
|
|
98
|
+
end
|
|
99
|
+
else
|
|
100
|
+
item("Show Hidden Files") do
|
|
101
|
+
DirMirror.show_hidden_files = true
|
|
102
|
+
tree.refresh
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
Application::Dialog.popup_menu(menu, :pointer)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def new_file(tree, node)
|
|
111
|
+
enclosing_dir = node ? node.directory : tree.tree_mirror.path
|
|
112
|
+
new_file_name = uniq_name(enclosing_dir, "New File")
|
|
113
|
+
new_file_path = File.join(enclosing_dir, new_file_name)
|
|
114
|
+
FileUtils.touch(new_file_path)
|
|
115
|
+
tree.refresh
|
|
116
|
+
tree.expand(node)
|
|
117
|
+
new_file_node = DirMirror::Node.create_from_path(new_file_path)
|
|
118
|
+
tree.edit(new_file_node)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def new_dir(tree, node)
|
|
122
|
+
enclosing_dir = node ? node.directory : tree.tree_mirror.path
|
|
123
|
+
new_dir_name = uniq_name(enclosing_dir, "New Directory")
|
|
124
|
+
new_dir_path = File.join(enclosing_dir, new_dir_name)
|
|
125
|
+
FileUtils.mkdir(new_dir_path)
|
|
126
|
+
tree.refresh
|
|
127
|
+
tree.expand(node)
|
|
128
|
+
new_dir_node = DirMirror::Node.create_from_path(new_dir_path)
|
|
129
|
+
tree.edit(new_dir_node)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def rename(tree, node)
|
|
133
|
+
nodes = tree.selection
|
|
134
|
+
if nodes.length == 1
|
|
135
|
+
single_rename(tree, node)
|
|
136
|
+
else
|
|
137
|
+
bulk_rename(tree, nodes)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def single_rename(tree, node)
|
|
142
|
+
if node.text =~ /^(.*)\.[^\.]+$/
|
|
143
|
+
tree.edit(node, 0, $1.length)
|
|
144
|
+
else
|
|
145
|
+
tree.edit(node)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def bulk_rename(tree, nodes)
|
|
150
|
+
tab = Redcar.app.focussed_window.new_tab(HtmlTab)
|
|
151
|
+
controller = BulkRenameController.new(tab, tree, nodes)
|
|
152
|
+
tab.html_view.controller = controller
|
|
153
|
+
tab.focus
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
class BulkRenameController
|
|
157
|
+
attr_reader :pairs, :match_pattern, :replace_pattern
|
|
158
|
+
|
|
159
|
+
def initialize(tab, tree, nodes)
|
|
160
|
+
@tab = tab
|
|
161
|
+
@tree = tree
|
|
162
|
+
@pairs = nodes.map {|node| [node, File.basename(node.path)] }
|
|
163
|
+
@match_pattern = ""
|
|
164
|
+
@replace_pattern = ""
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def title
|
|
168
|
+
"Bulk Rename"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def index
|
|
172
|
+
rhtml = ERB.new(File.read(File.join(File.dirname(__FILE__), "..", "..", "views", "bulk_rename.html.erb")))
|
|
173
|
+
rhtml.result(binding)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def refresh(new_match_pattern, new_replace_pattern)
|
|
177
|
+
begin
|
|
178
|
+
@match_pattern = /#{new_match_pattern}/
|
|
179
|
+
rescue
|
|
180
|
+
return []
|
|
181
|
+
end
|
|
182
|
+
@replace_pattern = new_replace_pattern
|
|
183
|
+
result = @pairs.map do |node, _|
|
|
184
|
+
old_name = File.basename(node.path)
|
|
185
|
+
new_name = transform_name(old_name)
|
|
186
|
+
new_path = File.join(File.dirname(node.path), new_name)
|
|
187
|
+
conflicts = (File.exist?(new_path) and new_name != old_name)
|
|
188
|
+
legal = (new_name != "" and legal_path?(new_path))
|
|
189
|
+
[new_name, conflicts, legal]
|
|
190
|
+
end
|
|
191
|
+
result
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def submit(params)
|
|
195
|
+
p [:submit, params]
|
|
196
|
+
@pairs.each do |node, _|
|
|
197
|
+
old_name = File.basename(node.path)
|
|
198
|
+
new_name = transform_name(old_name)
|
|
199
|
+
next if old_name == new_name
|
|
200
|
+
new_path = File.join(File.dirname(node.path), new_name)
|
|
201
|
+
FileUtils.mv(node.path, new_path)
|
|
202
|
+
end
|
|
203
|
+
@tab.close
|
|
204
|
+
@tree.refresh
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
private
|
|
208
|
+
|
|
209
|
+
def transform_name(old_name)
|
|
210
|
+
old_name.sub(match_pattern, replace_pattern)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def legal_path?(path)
|
|
214
|
+
return true if File.exist?(path)
|
|
215
|
+
|
|
216
|
+
begin
|
|
217
|
+
FileUtils.touch(path)
|
|
218
|
+
FileUtils.rm(path)
|
|
219
|
+
return true
|
|
220
|
+
rescue Errno::ENOENT
|
|
221
|
+
return false
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def delete(tree, _)
|
|
227
|
+
nodes = tree.selection
|
|
228
|
+
basenames = nodes.map {|node| File.basename(node.path) }
|
|
229
|
+
msg = "Really delete #{basenames.join(", ")}?"
|
|
230
|
+
result = Application::Dialog.message_box(msg, :type => :question, :buttons => :yes_no)
|
|
231
|
+
if result == :yes
|
|
232
|
+
nodes.each do |node|
|
|
233
|
+
FileUtils.rm_rf(node.path)
|
|
234
|
+
end
|
|
235
|
+
tree.refresh
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def edited(tree, node, text)
|
|
240
|
+
new_path = File.expand_path(File.join(File.dirname(node.path), text))
|
|
241
|
+
return if node.path == new_path
|
|
242
|
+
|
|
243
|
+
FileUtils.mv(node.path, new_path)
|
|
244
|
+
tree.refresh
|
|
245
|
+
new_node = DirMirror::Node.create_from_path(new_path)
|
|
246
|
+
tree.select(new_node)
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
private
|
|
250
|
+
|
|
251
|
+
def uniq_name(path, name)
|
|
252
|
+
return name unless File.exist?(File.join(path, name))
|
|
253
|
+
i = 1
|
|
254
|
+
loop do
|
|
255
|
+
new_name = name + " #{i}"
|
|
256
|
+
return new_name unless File.exist?(File.join(path, new_name))
|
|
257
|
+
i += 1
|
|
258
|
+
end
|
|
259
|
+
end
|
|
10
260
|
end
|
|
11
261
|
end
|
|
12
262
|
end
|
|
13
263
|
|
|
14
|
-
|
|
264
|
+
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
module Redcar
|
|
3
3
|
class Project
|
|
4
4
|
class DirMirror
|
|
5
|
+
class << self
|
|
6
|
+
attr_accessor :show_hidden_files
|
|
7
|
+
|
|
8
|
+
def show_hidden_files?
|
|
9
|
+
show_hidden_files
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
5
13
|
include Redcar::Tree::Mirror
|
|
6
14
|
attr_reader :path
|
|
7
15
|
|
|
@@ -23,22 +31,46 @@ module Redcar
|
|
|
23
31
|
@changed
|
|
24
32
|
end
|
|
25
33
|
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
# Drag and drop is allowed in Dir trees
|
|
35
|
+
def drag_and_drop?
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The files and directories in the top of the directory.
|
|
29
40
|
def top
|
|
30
41
|
@changed = false
|
|
31
42
|
Node.create_all_from_path(@path)
|
|
32
43
|
end
|
|
33
44
|
|
|
45
|
+
# We specify a :file data type to take advantage of OS integration.
|
|
46
|
+
def data_type
|
|
47
|
+
:file
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Return the Node for this path.
|
|
51
|
+
#
|
|
52
|
+
# @return [Node]
|
|
53
|
+
def from_data(path)
|
|
54
|
+
Node.create_from_path(path)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Turn the nodes into data.
|
|
58
|
+
def to_data(nodes)
|
|
59
|
+
nodes.map {|node| node.path }
|
|
60
|
+
end
|
|
61
|
+
|
|
34
62
|
class Node
|
|
35
|
-
|
|
36
63
|
include Redcar::Tree::Mirror::NodeMirror
|
|
37
64
|
|
|
38
65
|
attr_reader :path
|
|
39
66
|
|
|
40
67
|
def self.create_all_from_path(path)
|
|
41
|
-
Dir
|
|
68
|
+
fs = Dir.glob(path + "/*", File::FNM_DOTMATCH)
|
|
69
|
+
fs = fs.reject {|f| [".", ".."].include?(File.basename(f))}
|
|
70
|
+
unless DirMirror.show_hidden_files?
|
|
71
|
+
fs = fs.reject {|f| File.basename(f) =~ /^\./ }
|
|
72
|
+
end
|
|
73
|
+
fs.sort_by do |fn|
|
|
42
74
|
File.basename(fn).downcase
|
|
43
75
|
end.sort_by do |path|
|
|
44
76
|
File.directory?(path) ? -1 : 1
|
|
@@ -70,9 +102,25 @@ module Redcar
|
|
|
70
102
|
end
|
|
71
103
|
|
|
72
104
|
def leaf?
|
|
105
|
+
file?
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def file?
|
|
73
109
|
File.file?(@path)
|
|
74
110
|
end
|
|
75
111
|
|
|
112
|
+
def directory?
|
|
113
|
+
File.directory?(@path)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def parent_dir
|
|
117
|
+
File.dirname(@path)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def directory
|
|
121
|
+
directory? ? @path : File.dirname(@path)
|
|
122
|
+
end
|
|
123
|
+
|
|
76
124
|
def children
|
|
77
125
|
Node.create_all_from_path(@path)
|
|
78
126
|
end
|