Simplify the way in which path prompts keep state

In the past, we kept the last path the user specified for a number of different
path types to pre-seed the path prompt. Now, we no longer distinguish between
types, and pre-seed with the last used directory regardless.
This commit is contained in:
Aldo Cortesi 2015-03-22 14:14:44 +13:00
parent 572000aa03
commit 200498e7aa
7 changed files with 16 additions and 26 deletions

View File

@ -31,8 +31,6 @@ class ConsoleState(flow.State):
self.view_mode = common.VIEW_LIST self.view_mode = common.VIEW_LIST
self.view_flow_mode = common.VIEW_FLOW_REQUEST self.view_flow_mode = common.VIEW_FLOW_REQUEST
self.last_script = ""
self.last_saveload = ""
self.flowsettings = weakref.WeakKeyDictionary() self.flowsettings = weakref.WeakKeyDictionary()
def add_flow_setting(self, flow, key, value): def add_flow_setting(self, flow, key, value):
@ -258,7 +256,6 @@ class ConsoleMaster(flow.FlowMaster):
self._run_script_method("error", s, f) self._run_script_method("error", s, f)
s.unload() s.unload()
self.refresh_flow(f) self.refresh_flow(f)
self.state.last_script = command
def set_script(self, command): def set_script(self, command):
if not command: if not command:
@ -266,7 +263,6 @@ class ConsoleMaster(flow.FlowMaster):
ret = self.load_script(command) ret = self.load_script(command)
if ret: if ret:
signals.status_message.send(message=ret) signals.status_message.send(message=ret)
self.state.last_script = command
def toggle_eventlog(self): def toggle_eventlog(self):
self.eventlog = not self.eventlog self.eventlog = not self.eventlog
@ -501,7 +497,6 @@ class ConsoleMaster(flow.FlowMaster):
self.help_context = flowview.help_context self.help_context = flowview.help_context
def _write_flows(self, path, flows): def _write_flows(self, path, flows):
self.state.last_saveload = path
if not path: if not path:
return return
path = os.path.expanduser(path) path = os.path.expanduser(path)
@ -527,7 +522,6 @@ class ConsoleMaster(flow.FlowMaster):
return ret or "Flows loaded from %s"%path return ret or "Flows loaded from %s"%path
def load_flows_path(self, path): def load_flows_path(self, path):
self.state.last_saveload = path
reterr = None reterr = None
try: try:
flow.FlowMaster.load_flows_file(self, path) flow.FlowMaster.load_flows_file(self, path)

View File

@ -193,7 +193,6 @@ def raw_format_flow(f, focus, extended, padding):
def save_data(path, data, master, state): def save_data(path, data, master, state):
if not path: if not path:
return return
state.last_saveload = path
path = os.path.expanduser(path) path = os.path.expanduser(path)
try: try:
with file(path, "wb") as f: with file(path, "wb") as f:
@ -205,7 +204,6 @@ def save_data(path, data, master, state):
def ask_save_path(prompt, data, master, state): def ask_save_path(prompt, data, master, state):
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = prompt, prompt = prompt,
text = state.last_saveload,
callback = save_data, callback = save_data,
args = (data, master, state) args = (data, master, state)
) )

View File

@ -113,13 +113,11 @@ class ConnectionItem(urwid.WidgetWrap):
if k == "a": if k == "a":
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Save all flows to", prompt = "Save all flows to",
text = self.state.last_saveload,
callback = self.master.save_flows callback = self.master.save_flows
) )
else: else:
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Save this flow to", prompt = "Save this flow to",
text = self.state.last_saveload,
callback = self.master.save_one_flow, callback = self.master.save_one_flow,
args = (self.flow,) args = (self.flow,)
) )
@ -152,7 +150,6 @@ class ConnectionItem(urwid.WidgetWrap):
else: else:
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Server replay path", prompt = "Server replay path",
text = self.state.last_saveload,
callback = self.master.server_playback_path callback = self.master.server_playback_path
) )
@ -218,7 +215,6 @@ class ConnectionItem(urwid.WidgetWrap):
elif key == "|": elif key == "|":
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Send flow to script", prompt = "Send flow to script",
text = self.state.last_script,
callback = self.master.run_script_once, callback = self.master.run_script_once,
args = (self.flow,) args = (self.flow,)
) )
@ -316,7 +312,6 @@ class FlowListBox(urwid.ListBox):
signals.status_prompt_path.send( signals.status_prompt_path.send(
self, self,
prompt = "Load flows", prompt = "Load flows",
text = self.master.state.last_saveload,
callback = self.master.load_flows_callback callback = self.master.load_flows_callback
) )
elif key == "n": elif key == "n":
@ -334,7 +329,6 @@ class FlowListBox(urwid.ListBox):
signals.status_prompt_path.send( signals.status_prompt_path.send(
self, self,
prompt = "Stream flows to", prompt = "Stream flows to",
text = self.master.state.last_saveload,
callback = self.master.start_stream_to_path callback = self.master.start_stream_to_path
) )
else: else:

View File

@ -771,7 +771,6 @@ class FlowView(urwid.WidgetWrap):
elif key == "W": elif key == "W":
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Save this flow", prompt = "Save this flow",
text = self.state.last_saveload,
callback = self.master.save_one_flow, callback = self.master.save_one_flow,
args = (self.flow,) args = (self.flow,)
) )
@ -786,7 +785,6 @@ class FlowView(urwid.WidgetWrap):
elif key == "|": elif key == "|":
signals.status_prompt_path.send( signals.status_prompt_path.send(
prompt = "Send flow to script", prompt = "Send flow to script",
text = self.state.last_script,
callback = self.master.run_script_once, callback = self.master.run_script_once,
args = (self.flow,) args = (self.flow,)
) )

View File

@ -341,7 +341,6 @@ class GridEditor(urwid.WidgetWrap):
signals.status_prompt_path.send( signals.status_prompt_path.send(
self, self,
prompt = "Read file", prompt = "Read file",
text = "",
callback = self.read_file callback = self.read_file
) )
elif key == "R": elif key == "R":
@ -349,7 +348,6 @@ class GridEditor(urwid.WidgetWrap):
signals.status_prompt_path.send( signals.status_prompt_path.send(
self, self,
prompt = "Read unescaped file", prompt = "Read unescaped file",
text = "",
callback = self.read_file, callback = self.read_file,
args = (True,) args = (True,)
) )

View File

@ -1,4 +1,5 @@
import time import time
import os.path
import urwid import urwid
@ -15,8 +16,12 @@ class ActionBar(urwid.WidgetWrap):
signals.status_prompt_path.connect(self.sig_path_prompt) signals.status_prompt_path.connect(self.sig_path_prompt)
signals.status_prompt_onekey.connect(self.sig_prompt_onekey) signals.status_prompt_onekey.connect(self.sig_prompt_onekey)
self.last_path = ""
self.prompting = False self.prompting = False
self.onekey = False self.onekey = False
self.pathprompt = False
def sig_message(self, sender, message, expire=None): def sig_message(self, sender, message, expire=None):
w = urwid.Text(message) w = urwid.Text(message)
@ -35,9 +40,13 @@ class ActionBar(urwid.WidgetWrap):
self._w = urwid.Edit(self.prep_prompt(prompt), text or "") self._w = urwid.Edit(self.prep_prompt(prompt), text or "")
self.prompting = (callback, args) self.prompting = (callback, args)
def sig_path_prompt(self, sender, prompt, text, callback, args=()): def sig_path_prompt(self, sender, prompt, callback, args=()):
signals.focus.send(self, section="footer") signals.focus.send(self, section="footer")
self._w = pathedit.PathEdit(self.prep_prompt(prompt), text) self._w = pathedit.PathEdit(
self.prep_prompt(prompt),
os.path.dirname(self.last_path)
)
self.pathprompt = True
self.prompting = (callback, args) self.prompting = (callback, args)
def sig_prompt_onekey(self, sender, prompt, keys, callback, args=()): def sig_prompt_onekey(self, sender, prompt, keys, callback, args=()):
@ -71,7 +80,7 @@ class ActionBar(urwid.WidgetWrap):
elif k in self.onekey: elif k in self.onekey:
self.prompt_execute(k) self.prompt_execute(k)
elif k == "enter": elif k == "enter":
self.prompt_execute() self.prompt_execute(self._w.get_edit_text())
else: else:
if common.is_keypress(k): if common.is_keypress(k):
self._w.keypress(size, k) self._w.keypress(size, k)
@ -84,12 +93,13 @@ class ActionBar(urwid.WidgetWrap):
def prompt_done(self): def prompt_done(self):
self.prompting = False self.prompting = False
self.onekey = False self.onekey = False
self.pathprompt = False
signals.status_message.send(message="") signals.status_message.send(message="")
signals.focus.send(self, section="body") signals.focus.send(self, section="body")
def prompt_execute(self, txt=None): def prompt_execute(self, txt):
if not txt: if self.pathprompt:
txt = self._w.get_edit_text() self.last_path = txt
p, args = self.prompting p, args = self.prompting
self.prompt_done() self.prompt_done()
msg = p(txt, *args) msg = p(txt, *args)

View File

@ -19,7 +19,6 @@ class Window(urwid.Frame):
signals.status_prompt_path.send( signals.status_prompt_path.send(
self, self,
prompt = "Client replay", prompt = "Client replay",
text = self.master.state.last_saveload,
callback = self.master.client_playback_path callback = self.master.client_playback_path
) )
else: else:
@ -102,7 +101,6 @@ class Window(urwid.Frame):
signals.status_prompt_path.send( signals.status_prompt_path.send(
self, self,
prompt = "Server replay path", prompt = "Server replay path",
text = self.master.state.last_saveload,
callback = self.master.server_playback_path callback = self.master.server_playback_path
) )
else: else: