zim-wiki team mailing list archive
-
zim-wiki team
-
Mailing list archive
-
Message #04070
Patch for Drag and Drop Support of PageLink from PathBar into PageView
Hello Jaap + List,
please find attached a small patch (against zim-0.65.tar.gz) that
enables Drag and Drop support from the PathBar into the PageView - a
link to the dragged Page is inserted then.
That was a feature which I did miss up to now - to be able to directly
add a page link into a page by drag and dropping one of the just visited
pages from the PathBar at the top. This is especially useful if the page
you are editing right now and the ones which you have visited before are
located far away from each other in the page index, but you want to link
them.
Kind regards,
Klaus
--
Klaus Holler <kho@xxxxxx>
diff --git a/zim/gui/pathbar.py b/zim/gui/pathbar.py
index dfed74a..4650f55 100644
--- a/zim/gui/pathbar.py
+++ b/zim/gui/pathbar.py
@@ -5,14 +5,19 @@
import gtk
import gobject
+import logging
-from zim.gui.widgets import encode_markup_text
+from zim.gui.clipboard import \
+ INTERNAL_PAGELIST_TARGET_NAME, INTERNAL_PAGELIST_TARGET, \
+ pack_urilist
+from zim.gui.widgets import encode_markup_text
# Constants
DIR_FORWARD = 1
DIR_BACKWARD = -1
+logger = logging.getLogger('zim.gui')
class ScrolledHBox(gtk.HBox):
'''This class provides a widget that behaves like a HBox when there is
@@ -419,6 +424,9 @@ class PathBar(ScrolledHBox):
button.connect('popup-menu', self.on_button_popup_menu)
button.connect('button-release-event', self.do_button_release_event)
# TODO Drag n drop support also nice to have
+ button.connect('drag-data-get', self.on_drag_data_get)
+ button.drag_source_set(gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET,),
+ gtk.gdk.ACTION_LINK)
button.show()
self.add(button)
@@ -478,6 +486,13 @@ class PathBar(ScrolledHBox):
menu.popup(None, None, None, 3, 0)
return True
+ def on_drag_data_get(self, button, context, selectiondata, info, time):
+ assert selectiondata.target == INTERNAL_PAGELIST_TARGET_NAME
+ path = button.zim_path
+ logger.debug('Drag data requested from PathBar, we have internal path "%s"', path.name)
+ data = pack_urilist((path.name,))
+ selectiondata.set(INTERNAL_PAGELIST_TARGET_NAME, 8, data)
+
def get_selected_path(self):
'''Returns path currently selected or None'''
if self._selected: