Ejemplo n.º 1
0
 def search(self, txt, case, dir, loop):
     """Search text in document."""
     buffer = self.ev.buffer
     flags = gtksv.SEARCH_TEXT_ONLY | gtksv.SEARCH_VISIBLE_ONLY
     if not case:
         flags = flags | gtksv.SEARCH_CASE_INSENSITIVE
     ibeg, iend = buffer.get_bounds()
     if dir > 0:
         iter = buffer.get_iter_at_mark(buffer.get_selection_bound())
         res = gtksv.iter_forward_search(iter, txt, flags, None)
         if res is None and loop:
             res = gtksv.iter_forward_search(ibeg, txt, flags, None)
     elif dir < 0:
         iter = buffer.get_iter_at_mark(buffer.get_insert())
         res = gtksv.iter_backward_search(iter, txt, flags, None)
         if res is None and loop:
             res = gtksv.iter_backward_search(iend, txt, flags, None)
     else:
         iter = buffer.get_iter_at_mark(buffer.get_insert())
         res = gtksv.iter_forward_search(iter, txt, flags, None)
         if res is None and loop:
             res = gtksv.iter_forward_search(ibeg, txt, flags, None)
     s = self.get_selection()
     s = "" if not s else s
     low = lambda x: x.decode('utf8').lower().encode('utf8')
     if res is not None:
         buffer.select_range(*res)
         self.ev.view.scroll_to_mark(buffer.get_insert(), 0.25, True)
     elif loop or (txt!=s and case) or (low(txt)!=low(s) and not case):
         buffer.place_cursor(iter)
     return
Ejemplo n.º 2
0
    def text_search(self, direction=True, mixed_case=True, text="t"):
        CASEFLAG = 0
        if mixed_case:
            CASEFLAG = gtksourceview.SEARCH_CASE_INSENSITIVE
        if direction:
            if self.current_iter.is_end():
                self.current_iter = self.start_iter.copy()
            found = gtksourceview.iter_forward_search(self.current_iter, text,
                                                      CASEFLAG, None)
        else:
            if self.current_iter.is_start():
                self.current_iter = self.end_iter.copy()
            found = gtksourceview.iter_backward_search(self.current_iter, text,
                                                       CASEFLAG, None)
        if found:
            self.match_start, self.match_end = found
            self.buf.apply_tag(self.found_text_tag, self.match_start,
                               self.match_end)
            self.buf.select_range(self.match_start, self.match_end)

            if direction:
                self.buf.place_cursor(self.match_start)
                self.grab_focus()
                self.current_iter = self.match_end.copy()
            else:
                self.buf.place_cursor(self.match_start)
                self.grab_focus()
                self.current_iter = self.match_start.copy()
            self.scroll_to_iter(self.match_start, 0, True, 0, 0.5)
            self.set_highlight_current_line(True)
        else:
            self.current_iter = self.start_iter.copy()
            self.set_highlight_current_line(False)
            self.match_start = self.match_end = None
Ejemplo n.º 3
0
    def text_search(self,direction=True,mixed_case=True,text="t"):
        CASEFLAG = 0
        if mixed_case:
            CASEFLAG = gtksourceview.SEARCH_CASE_INSENSITIVE
        if direction:
            if self.current_iter.is_end():
                self.current_iter = self.start_iter.copy()
            found = gtksourceview.iter_forward_search(self.current_iter,text,CASEFLAG, None)
        else:
            if self.current_iter.is_start():
                self.current_iter = self.end_iter.copy()
            found = gtksourceview.iter_backward_search(self.current_iter,text,CASEFLAG, None)
        if found:
            self.match_start,self.match_end = found
            self.buf.apply_tag(self.found_text_tag, self.match_start, self.match_end)
            self.buf.select_range(self.match_start,self.match_end)

            if direction:
                self.buf.place_cursor(self.match_start)
                self.grab_focus()
                self.current_iter = self.match_end.copy()
            else:
                self.buf.place_cursor(self.match_start)
                self.grab_focus()
                self.current_iter = self.match_start.copy()
            self.scroll_to_iter(self.match_start, 0, True, 0, 0.5)
            self.set_highlight_current_line(True)
        else:
            self.current_iter = self.start_iter.copy()
            self.set_highlight_current_line(False)
            self.match_start = self.match_end = None
Ejemplo n.º 4
0
    def text_search(self,direction=True,mixed_case=True,text="t"):
        CASEFLAG = 0
        if mixed_case:
            CASEFLAG = gtksourceview.SEARCH_CASE_INSENSITIVE
        if direction:
            if self.current_iter.is_end():
                self.current_iter = self.start_iter.copy()
            found = gtksourceview.iter_forward_search(self.current_iter,text,CASEFLAG, None)
        else:
            if self.current_iter.is_start():
                self.current_iter = self.end_iter.copy()
            found = gtksourceview.iter_backward_search(self.current_iter,text,CASEFLAG, None)
        if found:
            # erase any existing hilighting tags
            try:
                self.buf.remove_tag(self.found_text_tag, self.match_start, self.match_end)
            except:
                pass
            self.match_start,self.match_end = found
            self.buf.apply_tag(self.found_text_tag, self.match_start, self.match_end)
            self.buf.select_range(self.match_start,self.match_end)
            self.grab_focus()
            if direction:
                self.current_iter = self.match_end.copy()
            else:
                self.current_iter = self.match_start.copy()
            self.scroll_to_iter(self.match_start, 0, True, 0, 0.5)

        else:
            self.current_iter = self.start_iter.copy()

            self.match_start = self.match_end = None
Ejemplo n.º 5
0
    def text_search(self,direction=True,mixed_case=True,text="t"):
        CASEFLAG = 0
        if mixed_case:
            CASEFLAG = gtksourceview.SEARCH_CASE_INSENSITIVE
        if direction:
            if self.current_iter.is_end():
                self.current_iter = self.start_iter.copy()
            found = gtksourceview.iter_forward_search(self.current_iter,text,CASEFLAG, None)
        else:
            if self.current_iter.is_start():
                self.current_iter = self.end_iter.copy()
            found = gtksourceview.iter_backward_search(self.current_iter,text,CASEFLAG, None)
        if found:
            # erase any existing highlighting tags
            try:
                self.buf.remove_tag(self.found_text_tag, self.match_start, self.match_end)
            except:
                pass
            self.match_start,self.match_end = found
            self.buf.apply_tag(self.found_text_tag, self.match_start, self.match_end)
            self.buf.select_range(self.match_start,self.match_end)
            self.grab_focus()
            if direction:
                self.current_iter = self.match_end.copy()
            else:
                self.current_iter = self.match_start.copy()
            self.scroll_to_iter(self.match_start, 0, True, 0, 0.5)

        else:
            self.current_iter = self.start_iter.copy()

            self.match_start = self.match_end = None
Ejemplo n.º 6
0
def replaceText(widget, event, data=None):
	if event == -1 or (event.type == gtk.gdk.KEY_RELEASE and \
	(gtk.gdk.keyval_name(event.keyval) == 'Return' or \
	 gtk.gdk.keyval_name(event.keyval) == 'KP_Enter')):
		a = config.cur_iter
		page = ui.getCurrentPage()
		view = page.get_data("view")
		b = view.get_buffer()
		mark = b.get_insert()
		iter = b.get_iter_at_mark(mark)
		search = data[4].get_text()
		flags = 0
		if data[0].get_active() == False:
			flags = gtksourceview2.SEARCH_CASE_INSENSITIVE
		backwards = False
		if data[2].get_active() == True:
			backwards = True
		warp = False
		if data[3].get_active() == True:
			warp = True
		if config.cur_iter == -1:
			config.cur_iter = iter
		sb = ui.getGui().get_object("statusbar1")
		if warp:
			try:
				if backwards:
					s, e = gtksourceview2.iter_backward_search( \
						config.cur_iter, search, flags, limit=None)
					config.cur_iter = s
				else:
					s, e = gtksourceview2.iter_forward_search( \
						config.cur_iter, search, flags, limit=None)
					config.cur_iter = e
			except:
				if backwards:
					iter = b.get_iter_at_offset(-1)
					config.cur_iter = iter
					try:
						s, e = gtksourceview2.iter_backward_search( \
							config.cur_iter, search, flags, limit=None)
						config.cur_iter = s
					except:
						config.cur_iter = a
						return
				else:
					iter = b.get_iter_at_line(0)
					config.cur_iter = iter
					try:
						s, e = gtksourceview2.iter_forward_search( \
							config.cur_iter, search, flags=0, limit=None)
						config.cur_iter = e
					except:
						config.cur_iter = a
						return
		else:
			if backwards:
				try:
					s, e = gtksourceview2.iter_backward_search( \
						config.cur_iter, search, flags, limit=None)
					config.cur_iter = s
				except:
					s = e = b.get_start_iter()
					b.select_range(s, e)
					misc.statusMessage(sb, _("'%s' not found.") % search)
					config.cur_iter = a
					return
			else:
				try:
					s, e = gtksourceview2.iter_forward_search( \
						config.cur_iter, search, flags, limit=None)
					config.cur_iter = e
				except:
					s = e = b.get_end_iter()
					b.select_range(s, e)
					misc.statusMessage(sb, _("'%s' not found.") % search)
					config.cur_iter = a
					return
		b.place_cursor(s)
		b.select_range(s, e)
		b.delete_selection(False, True)
		b.insert_at_cursor(data[5].get_text())