diff options
author | Lars Kruse <[email protected]> | 2011-08-22 21:05:48 +0200 |
---|---|---|
committer | Alexei Sorokin <[email protected]> | 2016-08-22 23:03:31 +0300 |
commit | 2d90080dcec1decf459c8e7d676b987f33aea316 (patch) | |
tree | a356fdb9a129eaa23abeaf3d0d71037a0e39b712 /Mozo/MenuEditor.py | |
parent | 35c489c60bb9f7d608ad770c5902cf35d1ffb8df (diff) | |
download | mozo-2d90080dcec1decf459c8e7d676b987f33aea316.tar.bz2 mozo-2d90080dcec1decf459c8e7d676b987f33aea316.tar.xz |
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
Diffstat (limited to 'Mozo/MenuEditor.py')
-rw-r--r-- | Mozo/MenuEditor.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Mozo/MenuEditor.py b/Mozo/MenuEditor.py index af7ee4f..79aaf1e 100644 --- a/Mozo/MenuEditor.py +++ b/Mozo/MenuEditor.py @@ -343,8 +343,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): @@ -690,18 +697,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 |