Browse Source

gtksourceview2 support for gitview

Added support for gtksourceview2 module (pygtksourceview 1.90.x) in
gitview.  Also refactored code that creates the source buffer and view.

Signed-off-by: Frederick Akalin <akalin@akalin.cx>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
maint
Frederick Akalin 18 years ago committed by Shawn O. Pearce
parent
commit
24ccd8b88e
  1. 53
      contrib/gitview/gitview

53
contrib/gitview/gitview

@ -27,12 +27,20 @@ import math @@ -27,12 +27,20 @@ import math
import string
import fcntl

try:
import gtksourceview2
have_gtksourceview2 = True
except ImportError:
have_gtksourceview2 = False

try:
import gtksourceview
have_gtksourceview = True
except ImportError:
have_gtksourceview = False
print "Running without gtksourceview module"

if not have_gtksourceview2 and not have_gtksourceview:
print "Running without gtksourceview2 or gtksourceview module"

re_ident = re.compile('(author|committer) (?P<ident>.*) (?P<epoch>\d+) (?P<tz>[+-]\d{4})')

@ -58,6 +66,26 @@ def show_date(epoch, tz): @@ -58,6 +66,26 @@ def show_date(epoch, tz):

return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(secs))

def get_source_buffer_and_view():
if have_gtksourceview2:
buffer = gtksourceview2.Buffer()
slm = gtksourceview2.LanguageManager()
gsl = slm.get_language("diff")
buffer.set_highlight_syntax(True)
buffer.set_language(gsl)
view = gtksourceview2.View(buffer)
elif have_gtksourceview:
buffer = gtksourceview.SourceBuffer()
slm = gtksourceview.SourceLanguagesManager()
gsl = slm.get_language_from_mime_type("text/x-patch")
buffer.set_highlight(True)
buffer.set_language(gsl)
view = gtksourceview.SourceView(buffer)
else:
buffer = gtk.TextBuffer()
view = gtk.TextView(buffer)
return (buffer, view)


class CellRendererGraph(gtk.GenericCellRenderer):
"""Cell renderer for directed graph.
@ -582,17 +610,7 @@ class DiffWindow(object): @@ -582,17 +610,7 @@ class DiffWindow(object):
hpan.pack1(scrollwin, True, True)
scrollwin.show()

if have_gtksourceview:
self.buffer = gtksourceview.SourceBuffer()
slm = gtksourceview.SourceLanguagesManager()
gsl = slm.get_language_from_mime_type("text/x-patch")
self.buffer.set_highlight(True)
self.buffer.set_language(gsl)
sourceview = gtksourceview.SourceView(self.buffer)
else:
self.buffer = gtk.TextBuffer()
sourceview = gtk.TextView(self.buffer)

(self.buffer, sourceview) = get_source_buffer_and_view()

sourceview.set_editable(False)
sourceview.modify_font(pango.FontDescription("Monospace"))
@ -956,16 +974,7 @@ class GitView(object): @@ -956,16 +974,7 @@ class GitView(object):
vbox.pack_start(scrollwin, expand=True, fill=True)
scrollwin.show()

if have_gtksourceview:
self.message_buffer = gtksourceview.SourceBuffer()
slm = gtksourceview.SourceLanguagesManager()
gsl = slm.get_language_from_mime_type("text/x-patch")
self.message_buffer.set_highlight(True)
self.message_buffer.set_language(gsl)
sourceview = gtksourceview.SourceView(self.message_buffer)
else:
self.message_buffer = gtk.TextBuffer()
sourceview = gtk.TextView(self.message_buffer)
(self.message_buffer, sourceview) = get_source_buffer_and_view()

sourceview.set_editable(False)
sourceview.modify_font(pango.FontDescription("Monospace"))

Loading…
Cancel
Save