Hi, <br><br>I have changed a few things in viewsource.py, and i am posting the diff file, <br>the issue still remains the same although i have changed view type from gtksourceview2 to gtk.textview. <br><br>--------------------------- git diff file.------------------------<br>
<br>diff --git a/install/lib/python2.6/site-packages/jarabe/view/viewsource.py b/install/lib/python2.6/site-packages/jarabe/view/viewsource.py<br>index 524db9e..24e361c 100644<br>--- a/install/lib/python2.6/site-packages/jarabe/view/viewsource.py<br>
+++ b/install/lib/python2.6/site-packages/jarabe/view/viewsource.py<br>@@ -321,18 +321,18 @@ class Toolbar(gtk.Toolbar):<br> search_item.show()<br> search_entry.show()<br> <br>- _search_prev = ToolButton('go-previous-paired')<br>
- _search_prev.set_tooltip(_('Previous'))<br>- # self._search_prev.connect('clicked', self._search_prev_cb)<br>- self.insert(_search_prev, -1)<br>- _search_prev.show()<br>+ self._search_prev = ToolButton('go-previous-paired')<br>
+ self._search_prev.set_tooltip(_('Previous'))<br>+ self._search_prev.connect('clicked', self._search_prev_cb)<br>+ self.insert(self._search_prev, -1)<br>+ self._search_prev.show()<br>
<br>- _search_next = ToolButton('go-next-paired')<br>- _search_next.set_tooltip(_('Next'))<br>- #self._search_next.connect('clicked', self._search_next_cb)<br>- self.insert(_search_next, -1)<br>
- _search_next.show()<br>- #self._update_search_buttons()<br>+ self._search_next = ToolButton('go-next-paired')<br>+ self._search_next.set_tooltip(_('Next'))<br>+ self._search_next.connect('clicked', self._search_next_cb)<br>
+ self.insert(self._search_next, -1)<br>+ self._search_next.show()<br>+ self._update_search_buttons()<br> <br> <br> stop = ToolButton(icon_name='dialog-cancel')<br>@@ -343,10 +343,30 @@ class Toolbar(gtk.Toolbar):<br>
<br> def _search_entry_activate_cb(self, entry):<br> self.viewer.set_search_text(entry.props.text)<br>+ self._update_search_buttons()<br> <br> def _search_entry_changed_cb(self, entry):<br> self.viewer.set_search_text(entry.props.text)<br>
- <br>+ self._update_search_buttons()<br>+<br>+ def _search_prev_cb(self, button):<br>+ self.viewer.search_next('backward')<br>+ self._update_search_buttons()<br>+<br>+ def _search_next_cb(self, button):<br>
+ self.viewer.search_next('forward')<br>+ self._update_search_buttons()<br>+<br>+ def _update_search_buttons(self,):<br>+ if len(self.viewer.search_text) == 0:<br>+ self._search_prev.props.sensitive = False<br>
+ self._search_next.props.sensitive = False<br>+ else:<br>+ prev = self.viewer.get_next_result('backward')<br>+ next = self.viewer.get_next_result('forward')<br>+ self._search_prev.props.sensitive = prev != None<br>
+ self._search_next.props.sensitive = next != None<br>+<br> def _add_separator(self, expand=False):<br> separator = gtk.SeparatorToolItem()<br> separator.props.draw = False<br>@@ -452,22 +472,88 @@ class SourceDisplay(gtk.ScrolledWindow):<br>
self._buffer = gtksourceview2.Buffer()<br> self._buffer.set_highlight_syntax(True)<br> <br>- self._source_view = gtksourceview2.View(self._buffer)<br>- self._source_view.set_editable(False)<br>
- self._source_view.set_cursor_visible(True)<br>- self._source_view.set_show_line_numbers(True)<br>- self._source_view.set_show_right_margin(True)<br>- self._source_view.set_right_margin_position(80)<br>
+ self.search_text = ' '<br>+<br>+ #self._source_view = gtksourceview2.View(self._buffer)<br>+ #self._source_view.set_editable(False)<br>+ #self._source_view.set_cursor_visible(True)<br>
+ #self._source_view.set_show_line_numbers(True)<br>+ #self._source_view.set_show_right_margin(True)<br>+ #self._source_view.set_right_margin_position(80)<br> #self._source_view.set_highlight_current_line(True) #FIXME: Ugly color<br>
- self._source_view.modify_font(_SOURCE_FONT)<br>- self.add(self._source_view)<br>- self._source_view.show()<br>+ #self._source_view.modify_font(_SOURCE_FONT)<br>+ # self.add(self._source_view)<br>
+ # self._source_view.show()<br>+ <br>+ self._textview = gtk.TextView(self._buffer)<br>+ self.add(self._textview)<br>+ self._tagtable = gtk.TextTagTable()<br>+ hilite_tag = gtk.TextTag('search-hilite')<br>
+ hilite_tag.props.background = '#FFFFB0'<br>+ self._tagtable.add(hilite_tag)<br>+ select_tag = gtk.TextTag('search-select')<br>+ select_tag.props.background = '#B0B0FF'<br>
+ self._tagtable.add(select_tag)<br>+ <br>+ scroll = gtk.ScrolledWindow()<br>+ scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)<br>+ scroll.add(self._textview)<br> <br>+ self._textview.show()<br>
+ <br> self._file_path = None<br> <br> def set_search_text(self, text):<br> self.search_text = text<br>+ buffer = self._textview.get_buffer()<br> <br>+ start, end = buffer.get_bounds()<br>
+ # buffer.remove_tag_by_name('search-hilite', start, end)<br>+ # buffer.remove_tag_by_name('search-select', start, end)<br>+ <br>+ iter = buffer.get_start_iter()<br>+ while True:<br>
+ next = iter.forward_search(text, 0)<br>+ if next is None: break<br>+ start, end = next<br>+ buffer.apply_tag_by_name('search-hilite', start, end)<br>+ iter = end<br>
+<br>+ if self.get_next_result('current'):<br>+ self.search_next('current')<br>+ elif self.get_next_result('backward'):<br>+ self.search_next('backward')<br>
+<br>+ def get_next_result(self, dir):<br>+ buffer = self._textview.get_buffer()<br>+ <br>+ if dir == 'forward':<br>+ iter = buffer.get_iter_at_mark(buffer.get_insert())<br>+ iter.forward_char()<br>
+ else:<br>+ iter = buffer.get_iter_at_mark(buffer.get_insert())<br>+ <br>+ if dir == 'backward':<br>+ return iter.backward_search(self.search_text, 0)<br>+ else:<br>
+ return iter.forward_search(self.search_text, 0)<br>+<br>+ def search_next(self, dir): <br>+ next = self.get_next_result(dir)<br>+ if next:<br>+ buffer = self._textview.get_buffer()<br>
+<br>+ start, end = buffer.get_bounds()<br>+ buffer.remove_tag_by_name('search-select', start, end)<br>+<br>+ start, end = next<br>+ buffer.apply_tag_by_name('search-select', start, end)<br>
+ <br>+ buffer.place_cursor(start)<br>+ <br>+ self._textview.scroll_to_iter(start, 0.1)<br>+ self._textview.scroll_to_iter(end, 0.1)<br>+<br> <br><br><br><br>----------------------------------<br>
<br>Regards <br><br>Shan<br><br><br><br><br><div class="gmail_quote">On Mon, Sep 27, 2010 at 8:25 PM, Tomeu Vizoso <span dir="ltr"><<a href="mailto:tomeu@sugarlabs.org">tomeu@sugarlabs.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Mon, Sep 27, 2010 at 16:36, Shanjit Singh Jajmann<br>
<<a href="mailto:shanjit@dev.seeta.in">shanjit@dev.seeta.in</a>> wrote:<br>
> Team,<br>
><br>
> I am working on <a href="http://bugs.sugarlabs.org/ticket/398" target="_blank">http://bugs.sugarlabs.org/ticket/398</a> : Regarding the search<br>
> box, i have tried to introduce the same functionality as in the 'Log'<br>
> activity, in the toolbar of viewsource (jarabe/view/viewscreen.py), however<br>
> i have run into some searching and highlighting issues regarding working<br>
<br>
</div>Without knowing which are the issues is a bit hard to know how to<br>
help. Can you be more explicit and also post the patch?<br>
<br>
Regards,<br>
<br>
Tomeu<br>
<div class="im"><br>
> with gtksourceview used in the sourceview function of the same file. Could<br>
> you please provide some pointers on how to achieve the searching and<br>
> highlighting ? (i could not get the bounds of the buffer created, start,end<br>
> . The highlight function has me confused as it isn't working) or any other<br>
> approach if possible.<br>
><br>
> Regards<br>
> Shan<br>
><br>
</div>> _______________________________________________<br>
> Sugar-devel mailing list<br>
> <a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
> <a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
><br>
><br>
</blockquote></div><br>