meld r1219 - trunk



Author: kaiw
Date: Sat Mar  7 09:25:53 2009
New Revision: 1219
URL: http://svn.gnome.org/viewvc/meld?rev=1219&view=rev

Log:
Focus Find dialog text entry, and prefill with selected text - Bug 572269

This improves the focus and selection behaviour of the text entry. The entry is
now prefilled with selected text from the active pane when Find is activated
with no existing dialog, and is focused and selected whenever Find is
activated.

Based on a patch by Toms BauÄis.


Modified:
   trunk/filediff.py

Modified: trunk/filediff.py
==============================================================================
--- trunk/filediff.py	(original)
+++ trunk/filediff.py	Sat Mar  7 09:25:53 2009
@@ -415,24 +415,44 @@
             if self.bufferdata[pane].filename:
                 self._open_files([self.bufferdata[pane].filename])
 
+    def get_selected_text(self):
+        """Returns selected text of active pane"""
+        pane = self._get_focused_pane()
+        if pane != -1:
+            buf = self.textbuffer[self._get_focused_pane()]
+            bounds = buf.get_selection_bounds()
+            if bounds:
+                return buf.get_text(bounds[0], bounds[1])
+        return None
+
     def on_find_activate(self, *args):
         self.keymask = 0
         self.queue_draw()
         if self.find_dialog:
-            self.find_dialog.widget.present()
+            self.find_dialog.raise_and_focus()
         else:
             class FindDialog(gnomeglade.Component):
-                def __init__(self, app):
+                def __init__(self, app, text=None):
                     self.parent = app
-                    self.pane = -1
                     gladefile = paths.share_dir("glade2/filediff.glade")
                     gnomeglade.Component.__init__(self, gladefile, "finddialog")
                     self.widget.set_transient_for(app.widget.get_toplevel())
                     self.gnome_entry_search_for.child.connect("activate", self.on_entry_search_for_activate)
+                    if text:
+                        self.gnome_entry_search_for.get_entry().set_text(text)
                     self.widget.show_all()
+                    self.raise_and_focus()
+
+                def raise_and_focus(self):
+                    entry = self.gnome_entry_search_for.get_entry()
+                    entry.grab_focus()
+                    entry.select_region(0, -1)
+                    self.widget.present()
+
                 def on_destroy(self, *args):
                     self.parent.find_dialog = None
                     self.widget.destroy()
+
                 def on_entry_search_for_activate(self, *args):
                     search_text = self.gnome_entry_search_for.get_active_text()
                     self.gnome_entry_search_for.prepend_text(search_text)
@@ -442,7 +462,7 @@
                         self.check_wrap.get_active(),
                         self.check_regex.get_active() )
                     return 1
-            self.find_dialog = FindDialog(self)
+            self.find_dialog = FindDialog(self, self.get_selected_text())
 
     def on_find_next_activate(self, *args):
         if self.last_search:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]