Пример #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
Пример #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
Пример #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:
            # 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
Пример #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
Пример #5
0
def replaceAll(widget, data=None):
	page = ui.getCurrentPage()
	view = page.get_data("view")
	b = view.get_buffer()
	mark = b.get_insert()
	iter = b.get_iter_at_mark(mark)
	search = widget.get_text()
	flags = 0
	repls=[]
	if data[0].get_active() == False:
		flags = gtksourceview2.SEARCH_CASE_INSENSITIVE
	if config.cur_iter == -1:
		config.cur_iter = iter
	sb = ui.getGui().get_object("statusbar1")
	s = b.get_start_iter()
	b.begin_user_action()
	b.place_cursor(s)
	rpls=0
	config.cur_iter = b.get_iter_at_line(0)
	while config.cur_iter <= b.get_end_iter():
		try:
			s, e = gtksourceview2.iter_forward_search( \
				config.cur_iter, search, flags, limit=None)
			e.forward_line()
		except:
			iter = b.get_iter_at_offset(0)
			config.cur_iter = iter
			try:
				s, e = gtksourceview2.iter_forward_search( \
					config.cur_iter, search, flags=0, limit=None)
				e.forward_line()
			except:
				misc.statusMessage(sb, _("A total of %s replacements made.") % rpls)
				return
		if s.get_line() not in repls:
			repls.append(s.get_line())
			rpls = rpls + 1
			b.delete(s, e)
			b.insert(s, data[5].get_text()+"\n")
			config.cur_iter = s
	b.end_user_action()
	misc.statusMessage(sb, _("A total of %s replacements made.") % rpls)
Пример #6
0
  def Afold_from_search(self, action, window):
    view = window.get_active_view()
    document = window.get_active_document()    
    buffer = view.get_buffer()

    search, flags = document.get_search_text()
    if not search or search == window.get_data("SearchFold")['search']:
      if weird.folded(buffer):
        return self.Aunfold(action, window)
      else:              
        left = weird.getInsertMark(buffer)
        right = weird.getSelectionMark(buffer)
        if left.equal(right):
          insert = left
          line = weird.getLine(buffer, insert)
          boundaries = weird.getLineBoundaries(line)

          left = weird.nextMark(insert, boundaries)
          right = weird.previousMark(insert, boundaries)

        search, flags = buffer.get_text(left, right), 0

    if flags & 0b100:
      flags = 0
    else:
      flags = gtksourceview2.SEARCH_CASE_INSENSITIVE

    window.set_data("SearchFold", {'search': search})

    start = buffer.get_start_iter()
    start.set_line_offset(0)
    while start:
      hit = gtksourceview2.iter_forward_search(start, search, flags)
      if hit:
        hit[0].set_line_offset(0)
        hit[1].forward_line()
        stop = hit[0]
        next = hit[1]
      else:
        stop = buffer.get_end_iter()
        next = None

      buffer.apply_tag(weird.fold(buffer), start, stop)
      start = next

    view.scroll_to_cursor()
Пример #7
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())