X-Git-Url: https://scm.cri.mines-paristech.fr/git/Plinn.git/blobdiff_plain/b5f944c62ef5fcb4cc038b68b281ca950d855ce1..077c4d9810b96d4b949e77f3daa0180c9d4a8c96:/HugePlinnFolder.py?ds=sidebyside diff --git a/HugePlinnFolder.py b/HugePlinnFolder.py index 563bf18..f2f5a92 100644 --- a/HugePlinnFolder.py +++ b/HugePlinnFolder.py @@ -150,34 +150,54 @@ class HugePlinnFolder(BTreeFolder2Base, PlinnFolder) : id2posUpdate = {} pos2idUpdate = {} - # moved before the firt item position if targetPos < minMovedPos : + # selection moved before the first item position for i, id in enumerate(ids) : pos = i + targetPos + 1 id2posUpdate[id] = pos pos2idUpdate[pos] = id - for id in IndexIterator(pos2id, maxMovedPos, start=targetPos+1): + for id in IndexIterator(pos2id, targetPos+1, maxMovedPos): pos = pos + 1 id2posUpdate[id] = pos pos2idUpdate[pos] = id elif targetPos > minMovedPos and targetPos < maxMovedPos : - print minMovedPos, maxMovedPos, targetPos - print "déposé entre la première et la dernière de la sélection" - raise NotImplementedError() + # selection moved between the first and last item positions + pos = minMovedPos + # move items placed between the first item position and the target position + for id in IndexIterator(pos2id, minMovedPos+1, targetPos) : + id2posUpdate[id] = pos + pos2idUpdate[pos] = id + pos += 1 + # move selected items + for id in ids : + id2posUpdate[id] = pos + pos2idUpdate[pos] = id + pos += 1 + # move items positioned between the target position and the moved item max position + for id in IndexIterator(pos2id, targetPos+1, maxMovedPos) : + id2posUpdate[id] = pos + pos2idUpdate[pos] = id + pos += 1 + else : - print minMovedPos, maxMovedPos, targetPos - print "déposé après la dernière" - raise NotImplementedError() + # selection moved after the last item position + pos = minMovedPos + for id in IndexIterator(pos2id, minMovedPos+1, targetPos) : + id2posUpdate[id] = pos + pos2idUpdate[pos] = id + pos += 1 + + pos = targetPos - len(ids) + 1 + for id in ids : + id2posUpdate[id] = pos + pos2idUpdate[pos] = id + pos +=1 id2pos.update(id2posUpdate) pos2id.update(pos2idUpdate) - - # just for debug - for pos in xrange(len(self)) : - assert pos2id.has_key(pos) - assert id2pos.has_key(pos2id[pos]) + if not suppress_events : for id, pos in id2posUpdate.items() : notify(ObjectPositionModified(self[id], self, pos)) @@ -194,24 +214,20 @@ class HugePlinnFolder(BTreeFolder2Base, PlinnFolder) : class IndexIterator : - def __init__(self, d, maxPos, start=0, length=None) : + def __init__(self, d, start, stop) : self.d = d self.pos = start - self.maxPos = maxPos - self.length = length - self.fetchedValuesCpt = 0 + self.stop = stop def __iter__(self) : return self def next(self) : try : - if self.pos > self.maxPos or \ - self.fetchedValuesCpt == self.length: + if self.pos > self.stop : raise StopIteration v = self.d[self.pos] self.pos = self.pos + 1 - self.fetchedValuesCpt = self.fetchedValuesCpt + 1 return v except KeyError : self.pos = self.pos + 1