Created
July 13, 2009 04:52
-
-
Save kaiw/145938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gtk | |
import gio | |
import nautilus | |
# Diff browsers in priority order | |
diff_browsers = ("meld",) | |
# Version control history browsers in priority order | |
vc_browsers = ("giggle", "gitg") | |
def scan_apps(): | |
diff_browser, vc_browser = None, None | |
app_infos = gio.app_info_get_all() | |
app_execs = [info.get_executable() for info in app_infos] | |
# FIXME: This is an awfully hacky way to check for existence of an app | |
for browser in diff_browsers: | |
try: | |
index = app_execs.index(browser) | |
diff_browser = app_infos[index] | |
break | |
except ValueError: | |
pass | |
for browser in vc_browsers: | |
try: | |
index = app_execs.index(browser) | |
vc_browser = app_infos[index] | |
break | |
except ValueError: | |
pass | |
return diff_browser, vc_browser | |
class GitLocationWidget(nautilus.LocationWidgetProvider): | |
diff_browser, vc_browser = scan_apps() | |
def __init__(self): | |
if not self.diff_browser and not self.vc_browser: | |
self.get_widget = lambda *args: None | |
def get_widget(self, url, window): | |
location = gio.File(url) | |
child = location.get_child(".git") | |
if not child.query_exists(): | |
return None | |
path = location.get_path() | |
if not path: | |
return None | |
hbox = gtk.HBox(False, 6) | |
label = gtk.Label() | |
label.set_markup("Git repository") | |
label.props.xalign = 0.0 | |
hbox.pack_start(label) | |
if self.diff_browser: | |
view_button = gtk.Button("View differences") | |
view_button.connect("clicked", self.load_diff_browser, path) | |
hbox.pack_start(view_button, expand=False) | |
if self.vc_browser: | |
browse_button = gtk.Button("Browse history") | |
browse_button.connect("clicked", self.load_vc_browser, path) | |
hbox.pack_start(browse_button, expand=False) | |
hbox.show_all() | |
return hbox | |
def load_diff_browser(self, button, path): | |
self.diff_browser.launch([gio.File(path)]) | |
def load_vc_browser(self, button, path): | |
self.vc_browser.launch([gio.File(path)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment