redcar 0.5.5dev → 0.5.6dev

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.
@@ -1,4 +1,3 @@
1
-
2
1
  require "java-mateview-#{Redcar::VERSION}"
3
2
 
4
3
  module JavaMateView
@@ -34,4 +33,4 @@ module JavaMateView
34
33
  end
35
34
  end
36
35
 
37
-
36
+
@@ -15,6 +15,7 @@ module Redcar
15
15
  end
16
16
 
17
17
  def each_file(&block)
18
+ file_index = 0
18
19
  Find.find(root_path) do |path|
19
20
  fullpath = File.expand_path(path)
20
21
  path = Pathname.new(fullpath)
@@ -22,24 +23,87 @@ module Redcar
22
23
  if path.directory?
23
24
  Find.prune if excluded_dirs.include?(path.basename.to_s) || is_excluded_pattern
24
25
  else
25
- if path.readable? && !skip_types.find { |st| path.send("#{st}?") }
26
- yield(path) unless path.read.is_binary_data? || excluded_files.include?(path.basename.to_s) || is_excluded_pattern
26
+ skipped = skip_types.find { |st| path.send("#{st}?") }
27
+ excluded = excluded_files.include?(path.basename.to_s) || is_excluded_pattern
28
+ unless !path.readable? || path.read.is_binary_data? || skipped || excluded
29
+ yield(FileResult.new(path, file_index))
30
+ file_index += 1
27
31
  end
28
32
  end
29
33
  end
30
34
  end
31
35
 
32
36
  def each_line(&block)
33
- file_no = 0
34
37
  each_file do |file|
35
- file_no += 1
36
- line_no = 0
37
38
  file.each_line do |line|
38
- line_no += 1
39
- yield(line, line_no, file, file_no)
39
+ yield(line)
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
+ class FileResult
45
+
46
+ attr_reader :path, :index, :lines
47
+
48
+ def initialize(path, index)
49
+ @path, @index = path, index
50
+ @lines = @path.read.split("\n")
51
+ end
52
+
53
+ def num
54
+ index + 1
55
+ end
56
+
57
+ def name
58
+ @project_path ||= Project::Manager.focussed_project.path
59
+ path.realpath.to_s.gsub("#{@project_path}/", '')
60
+ end
61
+
62
+ def each_line(&block)
63
+ lines.each_with_index do |text, index|
64
+ yield(LineResult.new(self, index, text))
65
+ end
66
+ end
67
+
68
+ def inspect
69
+ "#<FileResult path=#{path.to_s} index=#{index} lines=#{lines.size}>"
70
+ end
71
+
72
+ end
73
+
74
+ class LineResult
75
+
76
+ attr_reader :file, :index, :text
77
+
78
+ def initialize(file, index, text)
79
+ @file, @index, @text = file, index, text
80
+ end
81
+
82
+ def num
83
+ index + 1
84
+ end
85
+
86
+ def context(amount = 5)
87
+ before, after = Array.new, Array.new
88
+ if index > 0
89
+ from = (index - amount)
90
+ from = 0 if from < 0
91
+ before = ((from)..(index - 1)).collect { |b_index| LineResult.new(file, b_index, file.lines[b_index]) }
92
+ end
93
+ last_line_index = (file.lines.size - 1)
94
+ if index < last_line_index
95
+ to = (index + amount)
96
+ to = last_line_index if to > last_line_index
97
+ after = ((index + 1)..(to)).collect { |a_index| LineResult.new(file, a_index, file.lines[a_index]) }
98
+ end
99
+ { :before => before, :after => after }
100
+ end
101
+
102
+ def inspect
103
+ "#<LineResult index=#{index} file=#{file.to_s}>"
104
+ end
105
+
106
+ end
107
+
44
108
  end
45
109
  end
@@ -1,5 +1,3 @@
1
- * Reimplement with_context functionality in new ruby search
2
- * A line to summarize results, e.g. 18 lines matched in 5 files
3
1
  * Remember literal match, match case, and with context settings
4
2
  * Better handle long lines
5
3
  * Add stop searching functionality
@@ -21,6 +21,7 @@ module Redcar
21
21
  storage.set_default('excluded_dirs', ['.git', '.svn', '.redcar'])
22
22
  storage.set_default('excluded_files', [])
23
23
  storage.set_default('excluded_patterns', [/tags$/, /\.log$/])
24
+ storage.set_default('context_lines', 2)
24
25
  storage.save
25
26
  end
26
27
  end
@@ -26,6 +26,9 @@ module Redcar
26
26
 
27
27
  execute("$('#cached_query').val(\"#{escape_javascript(@query)}\");")
28
28
  execute("$('#results').html(\"<div id='no_results'>Searching...</div>\");")
29
+ execute("$('#results_summary').hide();")
30
+ execute("$('#file_results_count').html(0);")
31
+ execute("$('#line_results_count').html(0);")
29
32
  search_in_background
30
33
 
31
34
  nil
@@ -78,33 +81,43 @@ module Redcar
78
81
  @thread = nil
79
82
 
80
83
  @thread = Thread.new do
81
- found_lines = false
82
- last_file = nil
84
+ matched_lines = false
85
+ last_matching_line = nil
83
86
 
84
- @file_index, @line_index = 0, 0
85
-
86
- Redcar::FileParser.new(@project_path, @settings).each_line do |line, line_no, file, file_no|
87
+ Redcar::FileParser.new(@project_path, @settings).each_line do |line|
87
88
  next unless matching_line?(line)
88
89
 
89
90
  # Add an initial <tr></tr> so that tr:last can be used
90
91
  execute("if ($('#results table').size() == 0) { $('#results').html(\"<table><tr></tr></table>\"); }")
92
+ execute("if ($('#results_summary').first().is(':hidden')) { $('#results_summary').show(); }")
93
+
94
+ parsing_new_file = (!last_matching_line || last_matching_line.file != line.file)
91
95
 
92
- if last_file != file # new file
93
- file_name = file.realpath.to_s.gsub("#{@project_path}/", '')
94
- @file_index, @file_name = ((@file_index || 0) + 1), file_name
95
- execute("$('#results table tr:last').after(\"<tr><td class='break' colspan='2'></td></tr>\");") unless last_file.nil?
96
+ if parsing_new_file
97
+ execute("$('#file_results_count').html(parseInt($('#file_results_count').html()) + 1);")
98
+ execute("$('#results table tr:last').after(\"<tr><td class='break' colspan='2'></td></tr>\");") if matched_lines
99
+ @file = line.file
96
100
  execute("$('#results table tr:last').after(\"#{escape_javascript(render('_file_heading'))}\");")
97
101
  @line_index = 0 # reset line row styling
98
102
  end
99
103
 
100
- @line_index, @line_no, @line = ((@line_index || 0) + 1), line_no, line
101
- execute("$('#results table tr:last').after(\"#{escape_javascript(render('_file_line'))}\");")
104
+ if @with_context && !parsing_new_file && (line.num - last_matching_line.num) > (@settings['context_lines'] * 2)
105
+ divider = "<tr class='divider'><td class='line_num file_#{@line.file.num}'>...</td><td></td></tr>"
106
+ execute("$('#results table tr:last').after(\"#{divider}\");")
107
+ end
108
+
109
+ context = line.context(@settings['context_lines']) if @with_context
110
+ context[:before].each { |b_line| render_line(b_line) } if @with_context
111
+ render_line(line)
112
+ context[:after].each { |a_line| render_line(a_line) } if @with_context
102
113
 
103
- found_lines = true
104
- last_file = file
114
+ execute("$('#line_results_count').html(parseInt($('#line_results_count').html()) + 1);")
115
+
116
+ matched_lines = true
117
+ last_matching_line = line
105
118
  end
106
119
 
107
- if found_lines
120
+ if matched_lines
108
121
  # Remove the blank tr we added initially
109
122
  execute("$('#results table tr:first').remove();")
110
123
  else
@@ -120,12 +133,20 @@ module Redcar
120
133
  def matching_line?(line)
121
134
  regexp_text = @literal_match ? Regexp.escape(@query) : @query
122
135
  regexp = @match_case ? /#{regexp_text}/ : /#{regexp_text}/i
123
- line =~ regexp
136
+ line.text =~ regexp
124
137
  end
125
138
 
126
- def escape_javascript(javascript)
139
+ def escape_javascript(text)
127
140
  escape_map = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
128
- javascript.to_s.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { escape_map[$1] }
141
+ text.to_s.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { escape_map[$1] }
142
+ end
143
+
144
+ def render_line(line)
145
+ @line_index += 1
146
+ @line, @file = line, line.file
147
+ execute("if ($('#results tr.file_#{@file.num}.line_#{@line.num}').size() == 0) {
148
+ $('#results table tr:last').after(\"#{escape_javascript(render('_file_line'))}\");
149
+ }")
129
150
  end
130
151
  end
131
152
  end
@@ -92,6 +92,7 @@
92
92
 
93
93
  #results_container {
94
94
  margin-top: 95px;
95
+ margin-bottom: 25px;
95
96
  }
96
97
 
97
98
  #no_results,
@@ -113,7 +114,7 @@
113
114
  }
114
115
 
115
116
  #results .filename,
116
- #results .line_no {
117
+ #results .line_num {
117
118
  background-color: #eee;
118
119
  padding: 3px 10px;
119
120
  }
@@ -145,7 +146,7 @@
145
146
  height: 16px;
146
147
  }
147
148
 
148
- #results .line_no {
149
+ #results .line_num {
149
150
  text-align: right;
150
151
  padding: 0 5px;
151
152
  min-width: 20px;
@@ -153,7 +154,11 @@
153
154
  font-size: 13px;
154
155
  }
155
156
 
156
- #results .divider .line_no {
157
+ #results .divider .line_num {
158
+ cursor: default;
159
+ }
160
+
161
+ #results .divider .line_num {
157
162
  text-align: center;
158
163
  background-color: #fff;
159
164
  }
@@ -173,11 +178,7 @@
173
178
  font-size: 13px;
174
179
  }
175
180
 
176
- #results .divider .text {
177
- background-color: #fff;
178
- }
179
-
180
- #results .nomatch .line_no,
181
+ #results .nomatch .line_num,
181
182
  #results .nomatch .text {
182
183
  color: #aaa;
183
184
  }
@@ -192,3 +193,21 @@
192
193
  margin: 0 30px;
193
194
  padding: 15px;
194
195
  }
196
+
197
+ #results_summary {
198
+ position: fixed;
199
+ bottom: 0;
200
+ left: 0;
201
+ right: 0;
202
+ }
203
+
204
+ #results_summary .text {
205
+ width: 300px;
206
+ margin: 0 auto;
207
+ background-color: #eee;
208
+ border: 1px solid #ddd;
209
+ text-align: center;
210
+ border-top-left-radius: 1em;
211
+ border-top-right-radius: 1em;
212
+ padding: 3px 5px;
213
+ }
@@ -2,9 +2,9 @@
2
2
 
3
3
  <tr>
4
4
  <td class="file_heading" colspan="2">
5
- <a class="expand_collapse" data-file_index="<%= @file_index %>">
5
+ <a class="expand_collapse" data-file_num="<%= @file.num %>">
6
6
  <img src="<%= image_path %>/expanded.png" />
7
- <%= CGI::escapeHTML(@file_name) %>
7
+ <%= CGI::escapeHTML(@file.name) %>
8
8
  </a>
9
9
  </td>
10
10
  </tr>
@@ -1,6 +1,6 @@
1
- <tr class="result line_for_<%= @file_index %> <%= (@line_index % 2 == 0 ? 'even' : 'odd') %>" data-href='<%= CGI::escapeHTML(@file_name) %>' data-line_no='<%= @line_no %>'>
2
- <td class='line_no'><%= @line_no %></td>
1
+ <tr class="result file_<%= @file.num %> line_<%= @line.num %> <%= (@line_index % 2 == 0 ? 'even' : 'odd') %>" data-href='<%= CGI::escapeHTML(@file.name) %>' data-line_num='<%= @line.num %>'>
2
+ <td class='line_num'><%= @line.num %></td>
3
3
  <% regexp_text = CGI.escapeHTML((@literal_match ? Regexp.escape(@query) : @query)) %>
4
- <% text = CGI.escapeHTML(@line.strip).gsub((@match_case ? /(#{regexp_text})/ : /(#{regexp_text})/i)) { "<span>#{$1}</span>" } %>
4
+ <% text = CGI.escapeHTML(@line.text).gsub((@match_case ? /(#{regexp_text})/ : /(#{regexp_text})/i)) { "<span>#{$1}</span>" } %>
5
5
  <td class='text'><pre><%= text %></pre></td>
6
6
  </tr>
@@ -37,8 +37,8 @@
37
37
  <label for="literal_match">Literal Match</label>
38
38
  <input type="checkbox" id="match_case" <%="checked=checked" if @match_case %>>
39
39
  <label for="match_case">Match case</label>
40
- <!-- <input type="checkbox" id="with_context" <%="checked=checked" if @with_context %>>
41
- <label for="with_context">With context</label> -->
40
+ <input type="checkbox" id="with_context" <%="checked=checked" if @with_context %>>
41
+ <label for="with_context">With context</label>
42
42
  </td>
43
43
  <td></td>
44
44
  </tr>
@@ -54,6 +54,12 @@
54
54
  </div>
55
55
  </div>
56
56
 
57
+ <div id="results_summary" style="display: none;">
58
+ <div class="text">
59
+ <span id="line_results_count">0</span> lines matched in <span id="file_results_count">0</span> files
60
+ </div>
61
+ </div>
62
+
57
63
  <script type="text/javascript">
58
64
  $(document).ready(function() {
59
65
  $('#query').trigger('focus');
@@ -108,7 +114,7 @@
108
114
  try {
109
115
  if ($("#literal_match").attr('checked')) { var literal_match = 'true'; } else { var literal_match = 'false'; }
110
116
  if ($("#match_case").attr('checked')) { var match_case = 'true'; } else { var match_case = 'false'; }
111
- Controller.openFile($(this).attr('data-href'), $(this).attr('data-line_no'), $("#cached_query").val(), literal_match, match_case);
117
+ Controller.openFile($(this).attr('data-href'), $(this).attr('data-line_num'), $("#cached_query").val(), literal_match, match_case);
112
118
  } catch(e) {
113
119
  alert(e.message);
114
120
  }
@@ -117,13 +123,13 @@
117
123
  // need to use live here so that results added will be caught
118
124
  $('.expand_collapse').live('click', function(ev) {
119
125
  ev.preventDefault();
120
- var file_index = $(this).attr('data-file_index');
121
- if ($(".line_for_" + file_index).first().is(":visible")) {
126
+ var file_num = $(this).attr('data-file_num');
127
+ if ($(".file_" + file_num).first().is(":visible")) {
122
128
  $('img', this).attr('src', '<%= image_path %>/collapsed.png');
123
- $(".line_for_" + file_index).hide();
129
+ $(".file_" + file_num).hide();
124
130
  } else {
125
131
  $('img', this).attr('src', '<%= image_path %>/expanded.png');
126
- $(".line_for_" + file_index).show();
132
+ $(".file_" + file_num).show();
127
133
  }
128
134
  });
129
135
  });
@@ -5,9 +5,10 @@ module Redcar
5
5
  yield
6
6
  rescue => e
7
7
  message = "Error in: " + (text || e.message)
8
- puts message
9
- puts e.class.to_s + ": " + e.message
10
- puts e.backtrace
8
+ $stderr.puts message
9
+ $stderr.puts e.class.to_s + ": " + e.message
10
+ $stderr.puts e.backtrace
11
+ return if Redcar.no_gui_mode?
11
12
  Application::Dialog.message_box(
12
13
  message,
13
14
  :type => :error, :buttons => :ok)
@@ -38,6 +38,8 @@ module Redcar
38
38
  #
39
39
  # Possible values and their implications:
40
40
  # :new - can be passed to index_add, index_ignore
41
+ # :unmerged - The file is in a conflicted state.
42
+ # Can be passed to index_save or index_delete
41
43
  # :indexed - can be passed to index_revert, index_unsave
42
44
  # :deleted - can be passed to index_restore, index_unsave
43
45
  # :missing - can be passed to index_restore, index_delete
@@ -35,7 +35,10 @@ module Swt
35
35
 
36
36
  module DND
37
37
  import org.eclipse.swt.dnd.DND
38
- import org.eclipse.swt.dnd.Clipboard
38
+
39
+ # Only load Clipboard in full running mode.
40
+ import org.eclipse.swt.dnd.Clipboard unless Redcar.no_gui_mode?
41
+
39
42
  import org.eclipse.swt.dnd.Transfer
40
43
  import org.eclipse.swt.dnd.TextTransfer
41
44
  import org.eclipse.swt.dnd.FileTransfer
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redcar
3
3
  version: !ruby/object:Gem::Version
4
- hash: -769080784
4
+ hash: 35899764
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 5dev
10
- version: 0.5.5dev
9
+ - 6dev
10
+ version: 0.5.6dev
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Lucraft
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-06 00:00:00 +01:00
18
+ date: 2010-09-07 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency