git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frederick Akalin <akalin@akalin.cx>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Frederick Akalin <akalin@akalin.cx>
Subject: [PATCH] gtksourceview2 support for gitview
Date: Fri,  5 Oct 2007 00:20:49 -0700	[thread overview]
Message-ID: <1191568849-6923-1-git-send-email-akalin@akalin.cx> (raw)

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>
---
 contrib/gitview/gitview |   53 +++++++++++++++++++++++++++-------------------
 1 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/contrib/gitview/gitview b/contrib/gitview/gitview
index 5931766..449ee69 100755
--- a/contrib/gitview/gitview
+++ b/contrib/gitview/gitview
@@ -28,11 +28,19 @@ 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):
 
 	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):
 		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):
 		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"))
-- 
1.5.3.3

                 reply	other threads:[~2007-10-05  7:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1191568849-6923-1-git-send-email-akalin@akalin.cx \
    --to=akalin@akalin.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).