Skip to content

Commit

Permalink
Update File Search plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Nov 29, 2010
1 parent 25730f6 commit 059425e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugins/file-search.glade
Expand Up @@ -203,6 +203,7 @@
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="activates_default">True</property>
<signal name="changed" handler="on_cboSearchDirectoryEntry_changed" last_modification_time="Thu, 06 Aug 2009 17:34:02 GMT"/>
</widget>
</child>
</widget>
Expand Down
56 changes: 51 additions & 5 deletions plugins/file-search.py
Expand Up @@ -47,6 +47,7 @@
import gconf
import pango
import errno
import dircache

ui_str = """<ui>
<menubar name="MenuBar">
Expand Down Expand Up @@ -449,10 +450,12 @@ def __init__ (self, query, resultHandler):
findCmd += ["(", "!", "-path", "*/CVS/*", "!", "-path", "*/.svn/*", "!", "-path", "*/.git/*", "!", "-path", "*/RCS/*", ")"]
if query.selectFileTypes:
fileTypeList = query.parseFileTypeString()
findCmd += ["(", "-false"]
for t in fileTypeList:
findCmd += ["-o", "-name", t]
findCmd += [")"]
if fileTypeList:
findCmd += ["("]
for t in fileTypeList:
findCmd += ["-name", t, "-o"]
findCmd.pop()
findCmd += [")"]
findCmd += ["-xtype", "f", "-print"]

self.cmdRunner = RunCommand(findCmd, self, gobject.PRIORITY_DEFAULT_IDLE)
Expand Down Expand Up @@ -480,6 +483,11 @@ def handleFinished (self):
#print "find finished (%d files found)" % len(self.files)
self.cmdRunner = None

if self.cancelled:
self.resultHandler.handleFinished()
self.files = []
return

self.files.sort(pathCompare)

for f in self.files:
Expand Down Expand Up @@ -517,6 +525,7 @@ def __init__(self, plugin, window):
self._lastTypes = RecentList(self.gclient, "recent_types")

self._lastDir = None
self._autoCompleteList = None

self._lastClickIter = None # TextIter at position of last right-click or last popup menu

Expand Down Expand Up @@ -639,6 +648,29 @@ def on_cboSearchTextEntry_changed (self, textEntry):
def on_cbSelectFileTypes_toggled (self, checkbox):
self.tree.get_widget('cboFileTypeList').set_sensitive( checkbox.get_active() )

def on_cboSearchDirectoryEntry_changed (self, entry):
text = entry.get_text()
if text and self._autoCompleteList != None:
path = os.path.dirname(text)
start = os.path.basename(text)

self._autoCompleteList.clear()
try:
files = dircache.listdir(path)[:]
except OSError:
return
dircache.annotate(path, files)
for f in files:
if f.startswith(".") and not(start.startswith(".")):
# show hidden dirs only if explicitly requested by user
continue
if f.startswith(start) and f.endswith("/"):
if path == "/":
match = path + f
else:
match = path + os.sep + f
self._autoCompleteList.append([match])

def on_btnBrowse_clicked (self, button):
fileChooser = gtk.FileChooserDialog(title="Select directory to search in",
parent=self._dialog,
Expand Down Expand Up @@ -686,7 +718,7 @@ def openSearchDialog (self, searchText = None):
# otherwise, try to use directory of that file
currFileDir = self._window.get_active_tab().get_document().get_uri()
if currFileDir != None and currFileDir.startswith("file:///"):
searchDir = os.path.dirname(currFileDir[7:])
searchDir = urllib.unquote(os.path.dirname(currFileDir[7:]))
else:
# there's no file open => fall back to Gedit's current working dir
pass
Expand All @@ -696,6 +728,13 @@ def openSearchDialog (self, searchText = None):
# ... and display that in the text field:
self.tree.get_widget('cboSearchDirectoryEntry').set_text(searchDir)

# Set up autocompletion for search directory:
completion = gtk.EntryCompletion()
self.tree.get_widget('cboSearchDirectoryEntry').set_completion(completion)
self._autoCompleteList = gtk.ListStore(str)
completion.set_model(self._autoCompleteList)
completion.set_text_column(0)

# Fill the drop-down part of the text field with recent dirs:
cboLastDirs = self.tree.get_widget('cboSearchDirectoryList')
cboLastDirs.set_model(self._lastDirs.store)
Expand Down Expand Up @@ -960,6 +999,9 @@ def on_row_activated (self, widget, path, col):
currView = gedit.tab_get_from_document(currDoc).get_view()
currView.scroll_to_cursor()

# workaround to scroll to cursor position when opening file into window of "Unnamed Document":
gobject.idle_add(scrollToCursorCb, currView)

def on_btnClose_clicked (self, button):
self.destroy()

Expand Down Expand Up @@ -1016,6 +1058,10 @@ def onPopupMenuItemActivate (self, treeview, path):
clipboard.store()


def scrollToCursorCb (view):
view.scroll_to_cursor()
return False

def resultSearchCb (model, column, key, it):
"""Callback function for searching in result list"""
lineText = model.get_value(it, column)
Expand Down

0 comments on commit 059425e

Please sign in to comment.