From d1dddc096b19152e20a0283062462eceb28665ad Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 22 Jun 2010 00:46:36 +0100 Subject: [PATCH] Start of the Nautilus extension --- .../sparkleshare-nautilus-extension.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 SparkleShare/Nautilus/sparkleshare-nautilus-extension.py diff --git a/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py new file mode 100644 index 00000000..c37d8bea --- /dev/null +++ b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py @@ -0,0 +1,63 @@ +# SparkleShare, an instant update workflow to Git. +# Copyright (C) 2010 Hylke Bons +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import gio +import nautilus +import os + +SPARKLESHARE_DIR = os.path.expanduser ('~') + '/SparkleShare' + +class SparkleShareExtension (nautilus.MenuProvider): + + def __init__ (self): + + name = 'Loaded Nautilus SparkleShareExtension.' + + + def get_file_items (self, window, files): + + # Only work when one file is selected + if len (files) != 1: + return + + # Get info about the selected file + file_reference = gio.File (files [0].get_uri ()) + + # Only work if in a SparkleShare repo + if file_reference.get_path () [:len(SPARKLESHARE_DIR)] != SPARKLESHARE_DIR: + return + + submenu = nautilus.Menu () + + # Create the submenu for the nautilus context menu + item = nautilus.MenuItem ('Nautilus::OpenOlderVersion', 'Open Older Version', + 'Make a copy of an older version of this document in SparkleShare') + item.set_submenu (submenu) + + os.chdir (file_reference.get_parent ().get_path ()) + command = os.popen ("git log --pretty=oneline") + + for line in command.readlines (): + submenu.append_item (nautilus.MenuItem ('Nautilus::Version', line, + 'Select to open a copy of this version')) + + item_open_log = nautilus.MenuItem ('Nautilus::OpenEventLog', 'Open Event Log' + file_reference.get_path (), + 'Open the event log for this document to see more versions') + + submenu.append_item(item_open_log) + + return item,