[nautilus] add 'Copy Web Link' feature
This commit is contained in:
parent
93f4c7555c
commit
8aa8f1e5fe
2
README
2
README
|
@ -38,6 +38,7 @@ SparkleShare currently requires:
|
||||||
- gvfs >= 1.3
|
- gvfs >= 1.3
|
||||||
- intltool
|
- intltool
|
||||||
- nautilus-python
|
- nautilus-python
|
||||||
|
- pygtk
|
||||||
|
|
||||||
Run the service:
|
Run the service:
|
||||||
|
|
||||||
|
@ -68,6 +69,7 @@ To build SparkleShare you need:
|
||||||
- monodevelop >= 2.0
|
- monodevelop >= 2.0
|
||||||
- ndesk-dbus-devel >= 0.6
|
- ndesk-dbus-devel >= 0.6
|
||||||
- ndesk-dbus-glib-devel >= 0.6
|
- ndesk-dbus-glib-devel >= 0.6
|
||||||
|
- nautilus-python-devel
|
||||||
|
|
||||||
You can build and install SparkleShare like this:
|
You can build and install SparkleShare like this:
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ import time
|
||||||
import gio
|
import gio
|
||||||
import nautilus
|
import nautilus
|
||||||
|
|
||||||
|
import pygtk
|
||||||
|
pygtk.require('2.0')
|
||||||
|
import gtk
|
||||||
|
|
||||||
SPARKLESHARE_PATH = os.path.join (os.path.expanduser ('~'), "SparkleShare")
|
SPARKLESHARE_PATH = os.path.join (os.path.expanduser ('~'), "SparkleShare")
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
@ -62,7 +66,33 @@ class SparkleShareExtension (nautilus.MenuProvider):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def compare_versions (self, menu, file_reference):
|
def copy_web_link (self, menu, file_reference):
|
||||||
|
|
||||||
|
path = file_reference.get_path ()
|
||||||
|
|
||||||
|
# Get the remote url used for the repo
|
||||||
|
url_command = os.popen ("git config --get remote.origin.url")
|
||||||
|
url = url_command.readline ().strip ()
|
||||||
|
|
||||||
|
# Strip the unneeded parts
|
||||||
|
url = url.lstrip ("ssh://git")
|
||||||
|
url = url.lstrip ("@")
|
||||||
|
url = url.rstrip (".git")
|
||||||
|
|
||||||
|
# Format the right web url depending on the service
|
||||||
|
relative_path = path.lstrip (SPARKLESHARE_PATH)
|
||||||
|
repo_name = relative_path [:relative_path.find ("/")]
|
||||||
|
relative_path = relative_path.lstrip (repo_name)
|
||||||
|
|
||||||
|
if "gitorious.org" in url:
|
||||||
|
url = "http://" + url + "/blobs/master" + relative_path
|
||||||
|
if "github.com" in url:
|
||||||
|
url = "http://" + url + "/blobs/master" + relative_path
|
||||||
|
|
||||||
|
clipboard = gtk.clipboard_get ()
|
||||||
|
clipboard.set_text (url)
|
||||||
|
clipboard.store ()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,6 +108,12 @@ class SparkleShareExtension (nautilus.MenuProvider):
|
||||||
if not (file_reference.get_path ().startswith (SPARKLESHARE_PATH)):
|
if not (file_reference.get_path ().startswith (SPARKLESHARE_PATH)):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
web_link_menu_item = nautilus.MenuItem ("Nautilus::CopyWebLink", _("Copy Web Link"),
|
||||||
|
_("Copy the web address of this file to the clipboard"))
|
||||||
|
|
||||||
|
web_link_menu_item.connect ("activate", self.copy_web_link, file_reference)
|
||||||
|
|
||||||
|
|
||||||
epochs = ["", "", "", "", "", "", "", "", "", ""]
|
epochs = ["", "", "", "", "", "", "", "", "", ""]
|
||||||
commit_hashes = ["", "", "", "", "", "", "", "", "", ""]
|
commit_hashes = ["", "", "", "", "", "", "", "", "", ""]
|
||||||
|
|
||||||
|
@ -97,8 +133,9 @@ class SparkleShareExtension (nautilus.MenuProvider):
|
||||||
epochs [i] = line.strip ("\n")
|
epochs [i] = line.strip ("\n")
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# Only work if there is history
|
||||||
if i < 2:
|
if i < 2:
|
||||||
return
|
return web_link_menu_item,
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for line in hash_command.readlines ():
|
for line in hash_command.readlines ():
|
||||||
|
@ -129,9 +166,5 @@ class SparkleShareExtension (nautilus.MenuProvider):
|
||||||
|
|
||||||
earlier_version_menu_item.set_submenu (submenu)
|
earlier_version_menu_item.set_submenu (submenu)
|
||||||
|
|
||||||
# compare_versions_menu_item = nautilus.MenuItem ("Nautilus::CompareVersions", "Compare Versions",
|
|
||||||
# "Compare two versions of this document at any point in time")
|
|
||||||
|
|
||||||
# compare_versions_menu_item = menu_item.connect ("activate", self.compare_versions, file_reference)
|
return earlier_version_menu_item, web_link_menu_item
|
||||||
|
|
||||||
return earlier_version_menu_item,
|
|
||||||
|
|
Loading…
Reference in a new issue