Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Integrate the new finder code into the SnapOpen dialog.

  • Loading branch information...
commit 60321c6decf3ac2417a239ed5df105b5cf74da30 1 parent cf7ff1c
Hongli Lai authored
Showing with 19 additions and 33 deletions.
  1. +6 −3 snapopen/FileFinder.py
  2. +13 −30 snapopen/__init__.py
9 snapopen/FileFinder.py
View
@@ -18,7 +18,10 @@ def relpath(path, start):
class FileFinder:
def __init__(self, directory, pattern = None):
self.directory = os.path.normcase(os.path.normpath(directory))
- self.pattern = pattern
+ if pattern:
+ self.pattern = pattern.lower()
+ else:
+ self.pattern = None
def start(self, callback):
self._traverse(self.directory, set(), None, callback)
@@ -36,7 +39,7 @@ def _traverse(self, directory, dirs_seen, ignore_file, callback):
ignore_file = IgnoreFile(directory, lines, ignore_file)
except (IOError):
pass
- for entry in entries:
+ for entry in sorted(entries):
if entry.startswith('.'):
# Ignore hidden files.
continue
@@ -54,5 +57,5 @@ def _traverse(self, directory, dirs_seen, ignore_file, callback):
self._traverse(norm_path, dirs_seen, ignore_file, callback)
else:
rel_path = relpath(norm_path, self.directory)
- if not self.pattern or fnmatch.fnmatch(rel_path, self.pattern):
+ if not self.pattern or fnmatch.fnmatch(rel_path.lower(), self.pattern):
callback(rel_path)
43 snapopen/__init__.py
View
@@ -8,6 +8,8 @@
import os, os.path, gobject, urllib
from gtk import gdk
+from FileFinder import FileFinder
+
# set this to true for gedit versions before 2.16
pre216_version = False
@@ -135,44 +137,25 @@ def on_pattern_entry( self, widget, event ):
self.open_selected_item( event )
return
pattern = self._glade_entry_name.get_text()
- pattern = pattern.replace(" ","*")
- # modify lines below as needed, these defaults work pretty well
- filefilter = " | grep -s -v \"/\.\" 2>/dev/null"
- cmd = ""
- if self._show_hidden:
- filefilter = ""
+ # TODO: respect self._show_hidden
+ # TODO: respect max_result
+
+ self._liststore.clear()
if len(pattern) > 0:
- cmd = ('cd "%(path)s"' +
- ' && find . -maxdepth 10 -depth -type f -iwholename "*%(pattern)s*"' +
- ' | grep -v -E "(/\.|~$)" 2>/dev/null' + # ignore hidden and backup files
- ' | head -n %(max_results)d' +
- ' | sort') % \
- { 'path' : self._shell_escape(self._rootdir),
- 'pattern' : self._shell_escape(pattern),
- 'max_results' : max_result + 1 }
+ def callback(filename):
+ name = os.path.basename(filename)
+ self._liststore.append([name, filename])
+
self._snapopen_window.set_title("Searching ... ")
+ finder = FileFinder(self._rootdir, "*" + pattern + "*")
+ finder.start(callback)
else:
self._snapopen_window.set_title("Enter pattern ... ")
- #print cmd
-
- self._liststore.clear()
- maxcount = 0
- hits = os.popen(cmd).readlines()
- for file in hits:
- file = file.rstrip().replace("./", "") #remove cwd prefix
- name = os.path.basename(file)
- self._liststore.append([name, file])
- if maxcount > max_result:
- break
- maxcount = maxcount + 1
- if maxcount > max_result:
- oldtitle = oldtitle + " * too many hits"
self._snapopen_window.set_title(oldtitle)
-
+
selected = []
self._hit_list.get_selection().selected_foreach(self.foreach, selected)
-
if len(selected) == 0:
iter = self._liststore.get_iter_first()
if iter != None:
Please sign in to comment.
Something went wrong with that request. Please try again.