예제 #1
0
    def on_drag_data_received(self, iconview, dragcontext, x, y, selectiondata,
                              info, time):
        assert selectiondata.get_target().name() in URI_TARGET_NAMES
        names = unpack_urilist(selectiondata.get_data())
        files = [LocalFile(uri) for uri in names if uri.startswith('file://')]
        action = dragcontext.get_selected_action()
        logger.debug('Drag received %s, %s', action, files)

        if action == Gdk.DragAction.MOVE:
            self._move_files(files)
        elif action == Gdk.DragAction.ASK:
            menu = Gtk.Menu()

            item = Gtk.MenuItem.new_with_mnemonic(
                _('_Move Here'))  # T: popup menu action on drag-drop of a file
            item.connect('activate', lambda o: self._move_files(files))
            menu.append(item)

            item = Gtk.MenuItem.new_with_mnemonic(
                _('_Copy Here'))  # T: popup menu action on drag-drop of a file
            item.connect('activate', lambda o: self._copy_files(files))
            menu.append(item)

            menu.append(Gtk.SeparatorMenuItem())
            item = Gtk.MenuItem.new_with_mnemonic(
                _('Cancel'))  # T: popup menu action on drag-drop of a file
            # cancel action needs no action
            menu.append(item)

            menu.show_all()
            gtk_popup_at_pointer(menu)
        else:
            # Assume Gdk.DragAction.COPY or Gdk.DragAction.DEFAULT
            # on windows we get "0" which is not mapped to any action
            self._copy_files(files)
예제 #2
0
	def on_drag_data_received(self, iconview, dragcontext, x, y, selectiondata, info, time):
		assert selectiondata.target in URI_TARGET_NAMES
		names = unpack_urilist(selectiondata.data)
		files = [File(uri) for uri in names if uri.startswith('file://')]
		action = dragcontext.action
		logger.debug('Drag received %s, %s', action, files)

		if action == gtk.gdk.ACTION_MOVE:
			self._move_files(files)
		elif action == gtk.gdk.ACTION_ASK:
			menu = gtk.Menu()

			item = gtk.MenuItem(_('_Move Here')) # T: popup menu action on drag-drop of a file
			item.connect('activate', lambda o: self._move_files(files))
			menu.append(item)

			item = gtk.MenuItem(_('_Copy Here')) # T: popup menu action on drag-drop of a file
			item.connect('activate', lambda o: self._copy_files(files))
			menu.append(item)

			menu.append(gtk.SeparatorMenuItem())
			item = gtk.MenuItem(_('Cancel')) # T: popup menu action on drag-drop of a file
			# cancel action needs no action
			menu.append(item)

			menu.show_all()
			menu.popup(None, None, None, 1, time)
		else:
			# Assume gtk.gdk.ACTION_COPY or gtk.gdk.ACTION_DEFAULT
			# on windows we get "0" which is not mapped to any action
			self._copy_files(files)
예제 #3
0
    def on_drag_data_received(self, iconview, dragcontext, x, y, selectiondata,
                              info, time):
        assert selectiondata.target in URI_TARGET_NAMES
        names = unpack_urilist(selectiondata.data)
        files = [File(uri) for uri in names if uri.startswith('file://')]
        action = dragcontext.action
        logger.debug('Drag received %s, %s', action, files)

        if action == gtk.gdk.ACTION_MOVE:
            self._move_files(files)
        elif action == gtk.gdk.ACTION_ASK:
            menu = gtk.Menu()

            item = gtk.MenuItem(
                _('_Move Here'))  # T: popup menu action on drag-drop of a file
            item.connect('activate', lambda o: self._move_files(files))
            menu.append(item)

            item = gtk.MenuItem(
                _('_Copy Here'))  # T: popup menu action on drag-drop of a file
            item.connect('activate', lambda o: self._copy_files(files))
            menu.append(item)

            menu.append(gtk.SeparatorMenuItem())
            item = gtk.MenuItem(
                _('Cancel'))  # T: popup menu action on drag-drop of a file
            # cancel action needs no action
            menu.append(item)

            menu.show_all()
            menu.popup(None, None, None, 1, time)
        else:
            # Assume gtk.gdk.ACTION_COPY or gtk.gdk.ACTION_DEFAULT
            # on windows we get "0" which is not mapped to any action
            self._copy_files(files)
예제 #4
0
	def do_drag_data_received(self, dragcontext, x, y, selectiondata, info, time):
		assert selectiondata.get_target().name() == PAGELIST_TARGET_NAME
		data = selectiondata.get_data()
		logger.debug('Drag data recieved: %r', data)
		if data is None:
			data = zim.gui.clipboard._internal_selection_data # HACK issue #390
			zim.gui.clipboard._internal_selection_data = None
			logger.debug('Got data via workaround: %s', data)

		names = unpack_urilist(data)
		assert len(names) == 1, 'Could not get pagenames from: %r' % data
		if '?' in names[0]:
			notebookname, path = names[0].split('?', 1)
			if notebookname in (self.notebook.name, self.notebook.interwiki):
				source = Path(path)
			else:
				return None # TODO: move here from other notebook - might need dialog to confirm ?
		else:
			source = Path(names[0])

		dest_row = self.get_dest_row_at_pos(x, y)
		if dest_row:
			treepath, position = dest_row
		else:
			dragcontext.finish(False, False, time) # NOK
			return
		model = self.get_model()
		iter = model.get_iter(treepath)
		path = model.get_indexpath(iter)

		if position == Gtk.TreeViewDropPosition.BEFORE:
			logger.debug('Dropped %s before %s', source, path)
			dest = path.parent + source.basename
		elif position == Gtk.TreeViewDropPosition.AFTER:
			logger.debug('Dropped %s after %s', source, path)
			dest = path.parent + source.basename
		else:
			# Gtk.TreeViewDropPosition.INTO_OR_BEFORE
			# or Gtk.TreeViewDropPosition.INTO_OR_AFTER
			logger.debug('Dropped %s into %s', source, path)
			dest = path + source.basename

		if path == source or dest == source:
			# TODO - how to get the row image float back like when drop is not allowed ?
			if path == source:
				logger.debug('Dropped page onto itself')
			else:
				logger.debug('Paths have same namespace, no reordering')
			dragcontext.finish(False, False, time) # NOK
			return

		try:
			self.notebook.move_page(source, dest, update_links=True)
		except:
			logger.exception('Failed to move page %s -> %s', source, dest)
			dragcontext.finish(False, False, time) # NOK
		else:
			dragcontext.finish(True, False, time) # OK
예제 #5
0
    def do_drag_data_received(self, dragcontext, x, y, selectiondata, info,
                              time):
        assert selectiondata.get_target().name(
        ) == INTERNAL_PAGELIST_TARGET_NAME
        data = selectiondata.get_data()
        if data is None:
            data = zim.gui.clipboard._internal_selection_data  # HACK issue #390
            zim.gui.clipboard._internal_selection_data = None

        names = unpack_urilist(data)
        assert len(names) == 1
        source = Path(names[0])

        dest_row = self.get_dest_row_at_pos(x, y)
        if dest_row:
            treepath, position = dest_row
        else:
            dragcontext.finish(False, False, time)  # NOK
            return
        model = self.get_model()
        iter = model.get_iter(treepath)
        path = model.get_indexpath(iter)

        if position == Gtk.TreeViewDropPosition.BEFORE:
            logger.debug('Dropped %s before %s', source, path)
            dest = path.parent + source.basename
        elif position == Gtk.TreeViewDropPosition.AFTER:
            logger.debug('Dropped %s after %s', source, path)
            dest = path.parent + source.basename
        else:
            # Gtk.TreeViewDropPosition.INTO_OR_BEFORE
            # or Gtk.TreeViewDropPosition.INTO_OR_AFTER
            logger.debug('Dropped %s into %s', source, path)
            dest = path + source.basename

        if path == source or dest == source:
            # TODO - how to get the row image float back like when drop is not allowed ?
            if path == source:
                logger.debug('Dropped page onto itself')
            else:
                logger.debug('Paths have same namespace, no reordering')
            dragcontext.finish(False, False, time)  # NOK
            return

        try:
            self.notebook.move_page(source, dest, update_links=True)
        except:
            logger.exception('Failed to move page %s -> %s', source, dest)
            dragcontext.finish(False, False, time)  # NOK
        else:
            dragcontext.finish(True, False, time)  # OK
예제 #6
0
    def do_drag_data_received(self, dragcontext, x, y, selectiondata, info,
                              time):
        assert selectiondata.target == INTERNAL_PAGELIST_TARGET_NAME
        names = unpack_urilist(selectiondata.data)
        assert len(names) == 1
        source = Path(names[0])

        dest_row = self.get_dest_row_at_pos(x, y)
        if dest_row:
            treepath, position = dest_row
        else:
            dragcontext.finish(False, False, time)  # NOK
            return
        model = self.get_model()
        iter = model.get_iter(treepath)
        path = model.get_indexpath(iter)

        if position == gtk.TREE_VIEW_DROP_BEFORE:
            logger.debug('Dropped %s before %s', source, path)
            dest = path.parent + source.basename
        elif position == gtk.TREE_VIEW_DROP_AFTER:
            logger.debug('Dropped %s after %s', source, path)
            dest = path.parent + source.basename
        else:
            # gtk.TREE_VIEW_DROP_INTO_OR_BEFORE
            # or gtk.TREE_VIEW_DROP_INTO_OR_AFTER
            logger.debug('Dropped %s into %s', source, path)
            dest = path + source.basename

        if path == source or dest == source:
            # TODO - how to get the row image float back like when drop is not allowed ?
            if path == source:
                logger.debug('Dropped page onto itself')
            else:
                logger.debug('Paths have same namespace, no reordering')
            dragcontext.finish(False, False, time)  # NOK
            return

        try:
            notebook = self.ui.notebook  # XXX
            notebook.move_page(source, dest, update_links=True)
        except:
            logger.exception('Failed to move page %s -> %s', source, dest)
            dragcontext.finish(False, False, time)  # NOK
        else:
            dragcontext.finish(True, False, time)  # OK
예제 #7
0
	def do_drag_data_received(self, dragcontext, x, y, selectiondata, info, time):
		assert selectiondata.target == INTERNAL_PAGELIST_TARGET_NAME
		names = unpack_urilist(selectiondata.data)
		assert len(names) == 1
		source = Path(names[0])

		dest_row = self.get_dest_row_at_pos(x, y)
		if dest_row:
			treepath, position = dest_row
		else:
			dragcontext.finish(False, False, time) # NOK
			return
		model = self.get_model()
		iter = model.get_iter(treepath)
		path = model.get_indexpath(iter)

		if position == gtk.TREE_VIEW_DROP_BEFORE:
			logger.debug('Dropped %s before %s', source, path)
			dest = path.parent + source.basename
		elif position == gtk.TREE_VIEW_DROP_AFTER:
			logger.debug('Dropped %s after %s', source, path)
			dest = path.parent + source.basename
		else:
			# gtk.TREE_VIEW_DROP_INTO_OR_BEFORE
			# or gtk.TREE_VIEW_DROP_INTO_OR_AFTER
			logger.debug('Dropped %s into %s', source, path)
			dest = path + source.basename

		if path == source or dest == source:
			# TODO - how to get the row image float back like when drop is not allowed ?
			if path == source:
				logger.debug('Dropped page onto itself')
			else:
				logger.debug('Paths have same namespace, no reordering')
			dragcontext.finish(False, False, time) # NOK
			return

		if self.ui.do_move_page(source, dest, update_links=True):
			dragcontext.finish(True, False, time) # OK
		else:
			dragcontext.finish(False, False, time) # NOK