Merge pull request #2289 from cortesi/flowrevert

command: flow.revert
This commit is contained in:
Aldo Cortesi
2017-04-29 12:30:23 +12:00
committed by GitHub
4 changed files with 28 additions and 8 deletions

View File

@@ -63,4 +63,19 @@ class Core:
if f.killable:
f.kill()
updated.append(f)
ctx.log.alert("Killed %s flows." % len(updated))
ctx.master.addons.trigger("update", updated)
# FIXME: this will become view.revert later
@command.command("flow.revert")
def revert(self, flows: typing.Sequence[flow.Flow]) -> None:
"""
Revert flow changes.
"""
updated = []
for f in flows:
if f.modified():
f.revert()
updated.append(f)
ctx.log.alert("Reverted %s flows." % len(updated))
ctx.master.addons.trigger("update", updated)

View File

@@ -141,14 +141,7 @@ class FlowItem(urwid.WidgetWrap):
def keypress(self, xxx_todo_changeme, key):
(maxcol,) = xxx_todo_changeme
key = common.shortcuts(key)
if key == "V":
if not self.flow.modified():
signals.status_message.send(message="Flow not modified.")
return
self.flow.revert()
signals.flowlist_change.send(self)
signals.status_message.send(message="Reverted.")
elif key == "|":
if key == "|":
signals.status_prompt_path.send(
prompt = "Send flow to script",
callback = self.master.run_script_once,

View File

@@ -166,6 +166,7 @@ def default_keymap(km):
km.add("v", "set console_order_reversed=toggle", context="flowlist")
km.add("U", "flow.mark @all false", context="flowlist")
km.add("w", "console.command 'save.file @shown '", context="flowlist")
km.add("V", "flow.revert @focus", context="flowlist")
km.add("X", "flow.kill @focus", context="flowlist")
km.add("z", "view.remove @all", context="flowlist")
km.add("Z", "view.remove @hidden", context="flowlist")

View File

@@ -50,3 +50,14 @@ def test_kill():
assert f.killable
sa.kill([f])
assert not f.killable
def test_revert():
sa = core.Core()
with taddons.context():
f = tflow.tflow()
f.backup()
f.request.content = b"bar"
assert f.modified()
sa.revert([f])
assert not f.modified()