Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Integrate the new finder code into the SnapOpen dialog.

  • Loading branch information...
commit 60321c6decf3ac2417a239ed5df105b5cf74da30 1 parent cf7ff1c
Hongli Lai authored

Showing 2 changed files with 19 additions and 33 deletions. Show diff stats Hide diff stats

  1. +6 3 snapopen/FileFinder.py
  2. +13 30 snapopen/__init__.py
9 snapopen/FileFinder.py
@@ -18,7 +18,10 @@ def relpath(path, start):
18 18 class FileFinder:
19 19 def __init__(self, directory, pattern = None):
20 20 self.directory = os.path.normcase(os.path.normpath(directory))
21   - self.pattern = pattern
  21 + if pattern:
  22 + self.pattern = pattern.lower()
  23 + else:
  24 + self.pattern = None
22 25
23 26 def start(self, callback):
24 27 self._traverse(self.directory, set(), None, callback)
@@ -36,7 +39,7 @@ def _traverse(self, directory, dirs_seen, ignore_file, callback):
36 39 ignore_file = IgnoreFile(directory, lines, ignore_file)
37 40 except (IOError):
38 41 pass
39   - for entry in entries:
  42 + for entry in sorted(entries):
40 43 if entry.startswith('.'):
41 44 # Ignore hidden files.
42 45 continue
@@ -54,5 +57,5 @@ def _traverse(self, directory, dirs_seen, ignore_file, callback):
54 57 self._traverse(norm_path, dirs_seen, ignore_file, callback)
55 58 else:
56 59 rel_path = relpath(norm_path, self.directory)
57   - if not self.pattern or fnmatch.fnmatch(rel_path, self.pattern):
  60 + if not self.pattern or fnmatch.fnmatch(rel_path.lower(), self.pattern):
58 61 callback(rel_path)
43 snapopen/__init__.py
@@ -8,6 +8,8 @@
8 8 import os, os.path, gobject, urllib
9 9 from gtk import gdk
10 10
  11 +from FileFinder import FileFinder
  12 +
11 13 # set this to true for gedit versions before 2.16
12 14 pre216_version = False
13 15
@@ -135,44 +137,25 @@ def on_pattern_entry( self, widget, event ):
135 137 self.open_selected_item( event )
136 138 return
137 139 pattern = self._glade_entry_name.get_text()
138   - pattern = pattern.replace(" ","*")
139 140
140   - # modify lines below as needed, these defaults work pretty well
141   - filefilter = " | grep -s -v \"/\.\" 2>/dev/null"
142   - cmd = ""
143   - if self._show_hidden:
144   - filefilter = ""
  141 + # TODO: respect self._show_hidden
  142 + # TODO: respect max_result
  143 +
  144 + self._liststore.clear()
145 145 if len(pattern) > 0:
146   - cmd = ('cd "%(path)s"' +
147   - ' && find . -maxdepth 10 -depth -type f -iwholename "*%(pattern)s*"' +
148   - ' | grep -v -E "(/\.|~$)" 2>/dev/null' + # ignore hidden and backup files
149   - ' | head -n %(max_results)d' +
150   - ' | sort') % \
151   - { 'path' : self._shell_escape(self._rootdir),
152   - 'pattern' : self._shell_escape(pattern),
153   - 'max_results' : max_result + 1 }
  146 + def callback(filename):
  147 + name = os.path.basename(filename)
  148 + self._liststore.append([name, filename])
  149 +
154 150 self._snapopen_window.set_title("Searching ... ")
  151 + finder = FileFinder(self._rootdir, "*" + pattern + "*")
  152 + finder.start(callback)
155 153 else:
156 154 self._snapopen_window.set_title("Enter pattern ... ")
157   - #print cmd
158   -
159   - self._liststore.clear()
160   - maxcount = 0
161   - hits = os.popen(cmd).readlines()
162   - for file in hits:
163   - file = file.rstrip().replace("./", "") #remove cwd prefix
164   - name = os.path.basename(file)
165   - self._liststore.append([name, file])
166   - if maxcount > max_result:
167   - break
168   - maxcount = maxcount + 1
169   - if maxcount > max_result:
170   - oldtitle = oldtitle + " * too many hits"
171 155 self._snapopen_window.set_title(oldtitle)
172   -
  156 +
173 157 selected = []
174 158 self._hit_list.get_selection().selected_foreach(self.foreach, selected)
175   -
176 159 if len(selected) == 0:
177 160 iter = self._liststore.get_iter_first()
178 161 if iter != None:

0 comments on commit 60321c6

Please sign in to comment.
Something went wrong with that request. Please try again.