# Path: meld/misc.py
#     def select(rlist, wlist, xlist, timeout):
# def shelljoin( command ):
#     def quote(s):
# def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=()):
# def open_uri(uri, timestamp=0):
# def position_menu_under_widget(menu, widget):
# def make_tool_button_widget(label):
# def gdk_to_cairo_color(color):
# def all_equal(alist):
# def shorten_names(*names):
#             def firstpart(alist):
# def read_pipe_iter(command, errorstream, yield_interval=0.1, workdir=None):
#         def __init__(self):
#         def __del__(self):
#         def __call__(self):
# def write_pipe(command, text, error=None):
# def commonprefix(dirs):
# def copy2(src, dst):
# def copytree(src, dst):
# def shell_escape(glob_pat):
# def shell_to_regex(pat):
#     class sentinel(object):
# 
# Path: meld/paths.py
# def locale_dir(*args): # i18n files
# def help_dir(*args): # help
# def share_dir(*args):
# def ui_dir(*args):
# def icon_dir(*args):


import gtk
import re
from meld import misc
from meld import paths
from . import gnomeglade
from gettext import gettext as _
    def on_find_entry__activate(self, entry):
        self.find_next_button.activate()

    def on_replace_entry__activate(self, entry):
        self.replace_button.activate()

    def on_find_next_button__clicked(self, button):
        self._find_text()

    def on_find_previous_button__clicked(self, button):
        self._find_text(backwards=True)

    def on_replace_button__clicked(self, entry):
        buf = self.textview.get_buffer()
        oldsel = buf.get_selection_bounds()
        match = self._find_text(0)
        newsel = buf.get_selection_bounds()
        # only replace if there is a match at the cursor and it was already selected
        if match and oldsel and oldsel[0].equal(newsel[0]) and oldsel[1].equal(newsel[1]):
            buf.begin_user_action()
            buf.delete_selection(False,False)
            buf.insert_at_cursor( self.replace_entry.get_text() )
            self._find_text( 0 )
            buf.end_user_action()

    def on_replace_all_button__clicked(self, entry):
        buf = self.textview.get_buffer()
        saved_insert = buf.create_mark(None, buf.get_iter_at_mark(buf.get_insert()), True)
        buf.begin_user_action()
        while self._find_text(0):

# Path: meld/misc.py
#     def select(rlist, wlist, xlist, timeout):
# def shelljoin( command ):
#     def quote(s):
# def run_dialog( text, parent=None, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK, extrabuttons=()):
# def open_uri(uri, timestamp=0):
# def position_menu_under_widget(menu, widget):
# def make_tool_button_widget(label):
# def gdk_to_cairo_color(color):
# def all_equal(alist):
# def shorten_names(*names):
#             def firstpart(alist):
# def read_pipe_iter(command, errorstream, yield_interval=0.1, workdir=None):
#         def __init__(self):
#         def __del__(self):
#         def __call__(self):
# def write_pipe(command, text, error=None):
# def commonprefix(dirs):
# def copy2(src, dst):
# def copytree(src, dst):
# def shell_escape(glob_pat):
# def shell_to_regex(pat):
#     class sentinel(object):
# 
# Path: meld/paths.py
# def locale_dir(*args): # i18n files
# def help_dir(*args): # help
# def share_dir(*args):
# def ui_dir(*args):
# def icon_dir(*args):


# Path: meld/ui/findbar.py
import gtk
import re
from meld import misc
from meld import paths
from . import gnomeglade
from gettext import gettext as _

    def on_find_entry__activate(self, entry):
        self.find_next_button.activate()

    def on_replace_entry__activate(self, entry):
        self.replace_button.activate()

    def on_find_next_button__clicked(self, button):
        self._find_text()

    def on_find_previous_button__clicked(self, button):
        self._find_text(backwards=True)

    def on_replace_button__clicked(self, entry):
        buf = self.textview.get_buffer()
        oldsel = buf.get_selection_bounds()
        match = self._find_text(0)
        newsel = buf.get_selection_bounds()
        # only replace if there is a match at the cursor and it was already selected
        if match and oldsel and oldsel[0].equal(newsel[0]) and oldsel[1].equal(newsel[1]):
            buf.begin_user_action()
            buf.delete_selection(False,False)
            buf.insert_at_cursor( self.replace_entry.get_text() )
            self._find_text( 0 )
            buf.end_user_action()

    def on_replace_all_button__clicked(self, entry):
        buf = self.textview.get_buffer()
        saved_insert = buf.create_mark(None, buf.get_iter_at_mark(buf.get_insert()), True)
        buf.begin_user_action()
        while self._find_text(0):

            buf.delete_selection(False,False)