Commits

Steve Borho committed 1e86a65

history: add a combo box to filter text entry

This allows the user to quickly retrieve previous filtered views.

Fixes #748

Comments (0)

Files changed (1)

tortoisehg/hgtk/history.py

             if reload:
                 self.reload_log()
 
+    def filter_entry_changed(self, entrycombo, filtercombo):
+        row = entrycombo.get_active()
+        if row < 0:
+            return
+        mode, text, display = entrycombo.get_model()[row]
+        filtercombo.set_active(mode)
+        entrycombo.child.set_text(text)
+        self.activate_filter(text, mode)
+
     def filter_entry_activated(self, entry, combo):
         'User pressed enter in the filter entry'
-        opts = {}
         mode = combo.get_active()
         text = entry.get_text()
         if not text:
             return
+        row = [mode, text, combo.get_active_text()] 
+        model = self.entrycombo.get_model()
+        for r in model:
+            if r[0] == row[0] and r[1] == row[1]:
+                break
+        else:
+            self.entrycombo.get_model().append( row )
+        self.activate_filter(text, mode)
+
+    def activate_filter(self, text, mode):
+        opts = {}
         if mode == 0: # Rev Range
             try:
                 opts['revlist'] = cmdutil.revrange(self.repo, [text])
             self.pats = []
 
         opts = self.opts
+        if 'bundle' in opts:
+            self.set_bundlefile(opts['bundle'])
+            self.bundle_autoreject = True
         if opts['filehist']:
+            file = opts['filehist']
+            opts['pats'] = [file]
             self.custombutton.set_active(True)
             self.filter = 'custom'
             self.filtercombo.set_active(1)
-            self.filterentry.set_text(opts['filehist'])
-            opts['pats'] = [opts['filehist']]
+            self.filterentry.set_text(file)
+            self.filter_entry_activated(self.filterentry, self.filtercombo)
         elif self.pats:
             self.custombutton.set_active(True)
             self.filter = 'custom'
             self.filtercombo.set_active(1)
             self.filterentry.set_text(', '.join(self.pats))
             opts['pats'] = self.pats
-        if 'bundle' in opts:
-            self.set_bundlefile(opts['bundle'])
-            self.bundle_autoreject = True
+            self.filter_entry_activated(self.filterentry, self.filtercombo)
         else:
             self.reload_log(**opts)
 
         self.filtercombo = filtercombo
         filterbox.append_widget(filtercombo, padding=0)
 
-        entry = gtk.Entry()
+        searchlist = gtk.ListStore(int, # filtercombo value
+                                   str, # search string (utf-8)
+                                   str) # mode string (utf-8)
+        entrycombo = gtk.ComboBoxEntry(searchlist, 1)
+        cell = gtk.CellRendererText()
+        entrycombo.pack_end(cell, False)
+        entrycombo.add_attribute(cell, 'text', 2)
+        entry = entrycombo.child
         entry.connect('activate', self.filter_entry_activated, filtercombo)
+        entrycombo.connect('changed', self.filter_entry_changed, filtercombo)
+        self.entrycombo = entrycombo
         self.filterentry = entry
-        filterbox.append_widget(entry, expand=True, padding=0)
+        filterbox.append_widget(entrycombo, expand=True, padding=0)
 
         midpane = gtk.VBox()
         midpane.pack_start(syncbox, False)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.