mirror of
https://github.com/git/git.git
synced 2024-12-18 06:14:59 +08:00
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>
This commit is contained in:
parent
fdfeb87c14
commit
24ccd8b88e
@ -27,12 +27,20 @@ import math
|
|||||||
import string
|
import string
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
|
try:
|
||||||
|
import gtksourceview2
|
||||||
|
have_gtksourceview2 = True
|
||||||
|
except ImportError:
|
||||||
|
have_gtksourceview2 = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import gtksourceview
|
import gtksourceview
|
||||||
have_gtksourceview = True
|
have_gtksourceview = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
have_gtksourceview = False
|
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})')
|
re_ident = re.compile('(author|committer) (?P<ident>.*) (?P<epoch>\d+) (?P<tz>[+-]\d{4})')
|
||||||
|
|
||||||
@ -58,6 +66,26 @@ def show_date(epoch, tz):
|
|||||||
|
|
||||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(secs))
|
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):
|
class CellRendererGraph(gtk.GenericCellRenderer):
|
||||||
"""Cell renderer for directed graph.
|
"""Cell renderer for directed graph.
|
||||||
@ -582,17 +610,7 @@ class DiffWindow(object):
|
|||||||
hpan.pack1(scrollwin, True, True)
|
hpan.pack1(scrollwin, True, True)
|
||||||
scrollwin.show()
|
scrollwin.show()
|
||||||
|
|
||||||
if have_gtksourceview:
|
(self.buffer, sourceview) = get_source_buffer_and_view()
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
sourceview.set_editable(False)
|
sourceview.set_editable(False)
|
||||||
sourceview.modify_font(pango.FontDescription("Monospace"))
|
sourceview.modify_font(pango.FontDescription("Monospace"))
|
||||||
@ -956,16 +974,7 @@ class GitView(object):
|
|||||||
vbox.pack_start(scrollwin, expand=True, fill=True)
|
vbox.pack_start(scrollwin, expand=True, fill=True)
|
||||||
scrollwin.show()
|
scrollwin.show()
|
||||||
|
|
||||||
if have_gtksourceview:
|
(self.message_buffer, sourceview) = get_source_buffer_and_view()
|
||||||
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)
|
|
||||||
|
|
||||||
sourceview.set_editable(False)
|
sourceview.set_editable(False)
|
||||||
sourceview.modify_font(pango.FontDescription("Monospace"))
|
sourceview.modify_font(pango.FontDescription("Monospace"))
|
||||||
|
Loading…
Reference in New Issue
Block a user