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_flow_mode = common.VIEW_FLOW_REQUEST
self.last_script = ""
self.last_saveload = ""
self.flowsettings = weakref.WeakKeyDictionary()
def add_flow_setting(self, flow, key, value):
@ -258,7 +256,6 @@ class ConsoleMaster(flow.FlowMaster):
self._run_script_method("error", s, f)
s.unload()
self.refresh_flow(f)
self.state.last_script = command
def set_script(self, command):
if not command:
@ -266,7 +263,6 @@ class ConsoleMaster(flow.FlowMaster):
ret = self.load_script(command)
if ret:
signals.status_message.send(message=ret)
self.state.last_script = command
def toggle_eventlog(self):
self.eventlog = not self.eventlog
@ -501,7 +497,6 @@ class ConsoleMaster(flow.FlowMaster):
self.help_context = flowview.help_context
def _write_flows(self, path, flows):
self.state.last_saveload = path
if not path:
return
path = os.path.expanduser(path)
@ -527,7 +522,6 @@ class ConsoleMaster(flow.FlowMaster):
return ret or "Flows loaded from %s"%path
def load_flows_path(self, path):
self.state.last_saveload = path
reterr = None
try:
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):
if not path:
return
state.last_saveload = path
path = os.path.expanduser(path)
try:
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):
signals.status_prompt_path.send(
prompt = prompt,
text = state.last_saveload,
callback = save_data,
args = (data, master, state)
)

View File

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

View File

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

View File

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

View File

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

View File

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