[kupfer] browser: Implement copying with Ctrl+C



commit a42edac636ee70bf3a3951cb828bb7f7eafab869
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Dec 26 01:20:38 2009 +0100

    browser: Implement copying with Ctrl+C
    
    Let Ctrl+C copy the current pane's current selection to clipboard (if
    it has a text representation).
    
    Text is the only thing we handle right now, which means we can copy
    URLs, texts and file paths.

 kupfer/browser.py   |   26 ++++++++++++++++++++++++++
 kupfer/interface.py |    5 +++++
 2 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/browser.py b/kupfer/browser.py
index 15d95d3..9748bca 100644
--- a/kupfer/browser.py
+++ b/kupfer/browser.py
@@ -13,6 +13,7 @@ import gio
 import gobject
 
 from kupfer import data, icons, scheduler, relevance
+from kupfer import interface
 from kupfer import keybindings
 from kupfer import pretty
 
@@ -756,6 +757,8 @@ class Interface (gobject.GObject):
 		self.entry.connect("activate", self._activate, None)
 		self.entry.connect("key-press-event", self._entry_key_press)
 		self.entry.connect("key-release-event", self._entry_key_release)
+		self.entry.connect("copy-clipboard", self._entry_copy_clipboard)
+		self.entry.connect("cut-clipboard", self._entry_cut_clipboard)
 		self.entry.connect("paste-clipboard", self._entry_paste_clipboard)
 
 		# set up panewidget => self signals
@@ -957,8 +960,31 @@ class Interface (gobject.GObject):
 			return False
 		return True
 
+	def _entry_copy_clipboard(self, entry):
+		# Copy current selection to clipboard
+		# delegate to text entry when in text mode
+
+		if self.get_in_text_mode():
+			return False
+		selection = self.current.get_current()
+		if selection is None:
+			return False
+		textrep = interface.get_text_representation(selection)
+		if textrep is None:
+			return False
+		clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
+		clipboard.set_text(textrep)
+		return True
+
+	def _entry_cut_clipboard(self, entry):
+		if not self._entry_copy_clipboard(entry):
+			return False
+		self.reset_current()
+		self.reset()
+
 	def _entry_paste_clipboard(self, entry):
 		if not self.get_in_text_mode():
+			self.reset()
 			self.try_enable_text_mode()
 
 	def reset_text(self):
diff --git a/kupfer/interface.py b/kupfer/interface.py
index 74f5a25..a66d574 100644
--- a/kupfer/interface.py
+++ b/kupfer/interface.py
@@ -8,3 +8,8 @@ class TextRepresentation (object):
 		"""The default implementation returns the represented object"""
 		return self.object
 
+def get_text_representation(obj):
+	try:
+		return obj.get_text_representation()
+	except AttributeError:
+		return None



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]