1. Tobias Berling
  2. paste2

Commits

Tobias Berling  committed c6698a4

Added the paste2 gedit-commander module.

  • Participants
  • Parent commits 9e17cff
  • Branches default

Comments (0)

Files changed (2)

File gedit-commander-module/README

View file
+Copy paste2.py to ~/.gnome2/gedit/commander/modules and have fun.

File gedit-commander-module/paste2.py

View file
+import urllib
+import gtk
+
+import commander.commands as commands
+import commander.commands.completion
+import commander.commands.result
+import commander.commands.exceptions
+
+__commander_module__ = True
+
+def __default__(view, entry):
+    """paste2: paste selection or hole file"""
+    buf = view.get_buffer()
+    bounds = buf.get_selection_bounds()
+
+    # nothing selected -> select all
+    if not bounds:
+        bounds = buf.get_bounds()
+
+    text = bounds[0].get_text(bounds[1])
+ 
+    params = urllib.urlencode({'content': text})
+    f = urllib.urlopen("http://p2.karottika.de/", params)
+    url = f.read().strip()
+
+    lang = buf.get_language()
+    if lang:
+        url += '?%s' % lang.get_id()
+
+    prret = (yield commands.result.Prompt("Copy URL to Clipboard? [Y/n]", ('yes','no')))
+    if prret[0].strip().lower() in ['y', 'ye', 'yes', '']:
+        clipboard = gtk.Clipboard(selection='CLIPBOARD')
+        clipboard.set_text(url, len(url))
+       
+    entry.info_show('<u>%s</u>' % url, True)
+    yield commands.result.DONE
+