[alacarte] Fix several drag-and-drop usability issues



commit 0f6a88025f13e02433f004bb88c1daefb6f18eb1
Author: Lars Kruse <devel sumpfralle de>
Date:   Mon Aug 22 21:05:48 2011 +0200

    Fix several drag-and-drop usability issues
    
    1) drag and drop of an item from the item pane "into" a menu item of the
    item pane
    
    2) moving a separator item from the item pane "into" a menu item of the
    "menu pane"
    
    3) dragging an item from the item pane to another position in the item
    pane (between two other items)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=611278

 Alacarte/MainWindow.py |   28 +++++++++++++++++++++-------
 Alacarte/MenuEditor.py |   22 ++++++++++++++++------
 2 files changed, 37 insertions(+), 13 deletions(-)
---
diff --git a/Alacarte/MainWindow.py b/Alacarte/MainWindow.py
index b43ed32..c9595dd 100644
--- a/Alacarte/MainWindow.py
+++ b/Alacarte/MainWindow.py
@@ -422,7 +422,9 @@ class MainWindow:
 		drop_info = treeview.get_dest_row_at_pos(x, y)
 		if drop_info:
 			path, position = drop_info
-			types = (Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE, Gtk.TREE_VIEW_DROP_INTO_OR_AFTER)
+			types_before = (Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE, Gtk.TREE_VIEW_DROP_INTO_OR_AFTER)
+			types_into = (Gtk.TREE_VIEW_DROP_INTO_OR_BEFORE, Gtk.TREE_VIEW_DROP_INTO_OR_AFTER)
+			types_after = (Gtk.TREE_VIEW_DROP_AFTER, Gtk.TREE_VIEW_DROP_INTO_OR_AFTER)
 			if position not in types:
 				context.finish(False, False, etime)
 				return False
@@ -437,6 +439,8 @@ class MainWindow:
 				elif item.get_type() == gmenu.TYPE_DIRECTORY:
 					if self.editor.moveMenu(item, new_parent) == False:
 						self.loadUpdates()
+				elif item.get_type() == gmenu.TYPE_SEPARATOR:
+					self.editor.moveSeparator(item, new_parent)
 				else:
 					context.finish(False, False, etime) 
 				context.finish(True, True, etime)
@@ -521,22 +525,32 @@ class MainWindow:
 			if self.drag_data == None:
 				return False
 			item = self.drag_data
+			# by default we assume, that the items stays in the same menu
+			destination = item.get_parent()
 			if drop_info:
 				path, position = drop_info
-				if position in types:
-					before = items[path][3]
+				target = items[path][3]
+				# move the item to the directory, if the item was dropped into it
+				if (target.get_type() == gmenu.TYPE_DIRECTORY) and (position in types_into):
+					# append the selected item to the choosen menu
+					destination = target
+				elif position in types_before:
+					before = target
+				elif position in types_after:
+					after = target
 				else:
-					after = items[path][3]
+					# this does not happen
+					pass
 			else:
 				path = (len(items) - 1,)
 				after = items[path][3]
 			if item.get_type() == gmenu.TYPE_ENTRY:
-				self.editor.moveItem(item, item.get_parent(), before, after)
+				self.editor.moveItem(item, destination, before, after)
 			elif item.get_type() == gmenu.TYPE_DIRECTORY:
-				if self.editor.moveMenu(item, item.get_parent(), before, after) == False:
+				if self.editor.moveMenu(item, destination, before, after) == False:
 					self.loadUpdates()
 			elif item.get_type() == gmenu.TYPE_SEPARATOR:
-				self.editor.moveSeparator(item, item.get_parent(), before, after)
+				self.editor.moveSeparator(item, destination, before, after)
 			context.finish(True, True, etime)
 		elif selection.target == 'text/plain':
 			if selection.data == None:
diff --git a/Alacarte/MenuEditor.py b/Alacarte/MenuEditor.py
index 1cd84ed..8914039 100644
--- a/Alacarte/MenuEditor.py
+++ b/Alacarte/MenuEditor.py
@@ -330,8 +330,15 @@ class MenuEditor:
 		self.save()
 
 	def moveSeparator(self, separator, new_parent, before=None, after=None):
+		undo = []
+		# remove the original separator if its parent is not the new destination
+		if separator.get_parent() != new_parent:
+			self.deleteSeparator(separator)
+			undo.append(separator)
+		# this adds the new separator to the specified position
 		self.__positionItem(new_parent, separator, before, after)
-		self.__addUndo([self.__getMenu(new_parent),])
+		undo.append(self.__getMenu(new_parent))
+		self.__addUndo(undo)
 		self.save()
 
 	def deleteItem(self, item):
@@ -657,18 +664,21 @@ class MenuEditor:
 		self.__addXmlFilename(xml_parent, dom, file_id, 'Exclude')
 
 	def __positionItem(self, parent, item, before=None, after=None):
-		if not before and not after:
-			return
 		if after:
 			index = parent.contents.index(after) + 1
 		elif before:
 			index = parent.contents.index(before)
+		else:
+			# append the item to the list
+			index = len(parent.contents)
 		contents = parent.contents
 		#if this is a move to a new parent you can't remove the item
-		try:
+		if item in contents:
+			# decrease the destination index, if we shorten the list
+			if (before and (contents.index(item) < index)) \
+					or (after and (contents.index(item) < index - 1)):
+				index -= 1
 			contents.remove(item)
-		except:
-			pass
 		contents.insert(index, item)
 		layout = self.__createLayout(contents)
 		dom = self.__getMenu(parent).dom



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