Add another delete option to shift all memories up

(not just to the next blank).

This changes the delete options in the context menu to be a submenu
with three options.

Resolves #779
This commit is contained in:
Dan Smith 2013-04-10 19:17:38 -07:00
parent 6fa8a3af9f
commit 40a67770f1
3 changed files with 42 additions and 22 deletions

View File

@ -523,12 +523,12 @@ class MemoryEditor(common.Editor):
return True # We changed memories
def _delete_rows_and_shift(self, paths):
def _delete_rows_and_shift(self, paths, all=False):
iter = self.store.get_iter(paths[0])
starting_loc, = self.store.get(iter, self.col(_("Loc")))
for i in range(0, len(paths)):
sd = shiftdialog.ShiftDialog(self.rthread)
sd.delete(starting_loc, quiet=True)
sd.delete(starting_loc, quiet=True, all=all)
sd.destroy()
self.prefill()
@ -779,6 +779,8 @@ class MemoryEditor(common.Editor):
changed = self._delete_rows(paths)
elif action == "delete_s":
changed = self._delete_rows_and_shift(paths)
elif action == "delete_sall":
changed = self._delete_rows_and_shift(paths, all=True)
elif action in ["move_up", "move_dn"]:
changed = self._move_up_down(paths, action)
elif action == "exchange":
@ -827,8 +829,11 @@ class MemoryEditor(common.Editor):
<menuitem action="edit"/>
<menuitem action="insert_prev"/>
<menuitem action="insert_next"/>
<menuitem action="delete"/>
<menuitem action="delete_s"/>
<menu action="deletes">
<menuitem action="delete"/>
<menuitem action="delete_s"/>
<menuitem action="delete_sall"/>
</menu>
<menuitem action="move_up"/>
<menuitem action="move_dn"/>
<menuitem action="exchange"/>
@ -850,8 +855,10 @@ class MemoryEditor(common.Editor):
("edit", _("Edit")),
("insert_prev", _("Insert row above")),
("insert_next", _("Insert row below")),
("delete", issingle and _("Delete") or _("Delete all")),
("delete_s", _("Delete (and shift up)")),
("deletes", _("Delete")),
("delete", issingle and _("this memory") or _("these memories")),
("delete_s", _("...and shift block up")),
("delete_sall", _("...and shift all memories up")),
("move_up", _("Move up")),
("move_dn", _("Move down")),
("exchange", _("Exchange memories")),

View File

@ -65,12 +65,15 @@ class ShiftDialog(gtk.Dialog):
count / len(memories))
i.number = dst
self.rthread.radio.set_memory(i)
if i.empty:
self.rthread.radio.erase_memory(i.number)
else:
self.rthread.radio.set_memory(i)
count += 1.0
return int(count)
def _get_mems_until_hole(self, start, endokay=False):
def _get_mems_until_hole(self, start, endokay=False, all=False):
mems = []
llimit, ulimit = self.rthread.radio.get_features().memory_bounds
@ -81,7 +84,7 @@ class ShiftDialog(gtk.Dialog):
number=pos), 0)
try:
mem = self.rthread.radio.get_memory(pos)
if mem.empty:
if mem.empty and not all:
break
except errors.InvalidMemoryLocation:
break
@ -109,9 +112,8 @@ class ShiftDialog(gtk.Dialog):
print "No memory list?"
return 0
def _delete_hole(self, start):
mems = self._get_mems_until_hole(start+1, endokay=True)
def _delete_hole(self, start, all=False):
mems = self._get_mems_until_hole(start+1, endokay=True, all=all)
if mems:
count = self._shift_memories(-1, mems)
self.rthread.radio.erase_memory(count+start)
@ -126,12 +128,12 @@ class ShiftDialog(gtk.Dialog):
else:
gobject.idle_add(self.set_response_sensitive, gtk.RESPONSE_OK, True)
def threadfn(self, newhole, func):
def threadfn(self, newhole, func, *args):
self.status("Waiting for radio to become available", 0)
self.rthread.lock()
try:
count = func(newhole)
count = func(newhole, *args)
except errors.InvalidMemoryLocation, e:
self.status(str(e), 0)
self.finished()
@ -145,13 +147,13 @@ class ShiftDialog(gtk.Dialog):
def insert(self, newhole, quiet=False):
self.quiet = quiet
self.thread = threading.Thread(target=self.threadfn,
args=(newhole,self._insert_hole))
args=(newhole, self._insert_hole))
self.thread.start()
gtk.Dialog.run(self)
def delete(self, newhole, quiet=False):
def delete(self, newhole, quiet=False, all=False):
self.quiet = quiet
self.thread = threading.Thread(target=self.threadfn,
args=(newhole,self._delete_hole))
args=(newhole, self._delete_hole, all))
self.thread.start()
gtk.Dialog.run(self)

View File

@ -50,16 +50,17 @@ class ShiftDialogTest(base.BaseTest):
radio.get_features().memory_bounds = (0, 5)
sd = shiftdialog.ShiftDialog(FakeRadioThread(radio))
getattr(sd, fn)(arg)
if isinstance(arg, tuple):
getattr(sd, fn)(*arg)
else:
getattr(sd, fn)(arg)
self.assertEqual(expected, sorted(radio._mems.keys()))
self.assertEqual(expected,
sorted([mem.number for mem in radio._mems.values()]))
def _test_delete_hole(self, starting, delete, expected):
self._test_hole('_delete_hole', starting, delete, expected)
def _test_delete_hole(self, starting, arg, expected):
self._test_hole('_delete_hole', starting, arg, expected)
def _test_insert_hole(self, starting, pos, expected):
self._test_hole('_insert_hole', starting, pos, expected)
@ -74,6 +75,16 @@ class ShiftDialogTest(base.BaseTest):
2,
[1, 2, 3, 4])
def test_delete_hole_with_all(self):
self._test_delete_hole([1, 2, 3, 5],
(2, True),
[1, 2, 4])
def test_delete_hole_with_all_full(self):
self._test_delete_hole([1, 2, 3, 4, 5],
(2, True),
[1, 2, 3, 4])
def test_insert_hole_with_space(self):
self._test_insert_hole([1, 2, 3, 5],
2,