# HG changeset patch # User Sune Foldager <c...@cyanite.org> # Date 1259794483 -3600 # Node ID 6b4329af5ba0e9f8e309e47b4090ac0f0160af3f # Parent 050c73f8d76e8091a03182a22584c69a5c270198 demo of MQ patch moving code
diff --git a/tortoisehg/hgtk/thgmq.py b/tortoisehg/hgtk/thgmq.py --- a/tortoisehg/hgtk/thgmq.py +++ b/tortoisehg/hgtk/thgmq.py @@ -7,6 +7,7 @@ import os import gtk +import gtk.keysyms import gobject import pango @@ -151,6 +152,61 @@ self.list.connect('row-activated', self.list_row_activated) self.list.connect('size-allocate', self.list_size_allocated) + def list_move_item(list, oldpos, newpos): + olditem = list[oldpos] + del list[oldpos] + list.insert(newpos, olditem) + + def move_patch(model, oldidx, newidx): + # Update series + oldrow = model[oldidx] + newrow = model[newidx] + p = self.repo.mq + list_move_item(p.full_series, p.find_series(oldrow[MQ_NAME]), + p.find_series(newrow[MQ_NAME])) + p.series_dirty = True + p.save_dirty() + + # Update TreeView + if newidx < oldidx: + model.move_before(oldrow.iter, newrow.iter) + else: + model.move_after(oldrow.iter, newrow.iter) + for i in xrange(min(oldidx, newidx), max(oldidx, newidx) + 1): + model[i][MQ_INDEX] = i-2 + + event_keys = [gtk.keysyms.Up, gtk.keysyms.Down, + gtk.keysyms.Page_Up, gtk.keysyms.Page_Down] + + def keypress(tv, event): + # Look for shift + arrow/page up/down + if (event.state & gtk.gdk.SHIFT_MASK) != gtk.gdk.SHIFT_MASK: + return False + kv = event.keyval + if kv not in event_keys: + return False + + # Calculate rows to be moved between, and move the patch + oldrow = tv.get_cursor()[0][0] + model = tv.get_model() + minval = self.separator_pos + 1 + maxval = len(model) - 1 + if kv == gtk.keysyms.Up: + newrow = oldrow - 1 + elif kv == gtk.keysyms.Down: + newrow = oldrow + 1 + elif kv == gtk.keysyms.Page_Up: + newrow = minval + elif kv == gtk.keysyms.Page_Down: + newrow = maxval + else: + return False + if newrow != oldrow and newrow >= minval and newrow <= maxval: + move_patch(model, oldrow, newrow) + return True + + self.list.connect('key-press-event', keypress) + self.cols = {} self.cells = {} @@ -247,7 +303,8 @@ # insert separator if top: - self.model.insert_after(top, (INDEX_SEPARATOR, None, None, None, None)) + row = self.model.insert_after(top, (INDEX_SEPARATOR, None, None, None, None)) + self.separator_pos = self.model.get_path(row)[0] # restore patch selection if selname: ------------------------------------------------------------------------------ Join us December 9, 2009 for the Red Hat Virtual Experience, a free event focused on virtualization and cloud computing. Attend in-depth sessions from your desk. Your couch. Anywhere. http://p.sf.net/sfu/redhat-sfdev2dev _______________________________________________ Tortoisehg-develop mailing list Tortoisehg-develop@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop