From 200498e7aa57effd7158c8d735f95c6556203a07 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 22 Mar 2015 14:14:44 +1300 Subject: [PATCH] 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. --- libmproxy/console/__init__.py | 6 ------ libmproxy/console/common.py | 2 -- libmproxy/console/flowlist.py | 6 ------ libmproxy/console/flowview.py | 2 -- libmproxy/console/grideditor.py | 2 -- libmproxy/console/statusbar.py | 22 ++++++++++++++++------ libmproxy/console/window.py | 2 -- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index d8eb8a41f..34abe6f4f 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -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) diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index e4ecde916..c0593af48 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -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) ) diff --git a/libmproxy/console/flowlist.py b/libmproxy/console/flowlist.py index f39188bb7..946bd97b2 100644 --- a/libmproxy/console/flowlist.py +++ b/libmproxy/console/flowlist.py @@ -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: diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index b9d5fbcac..d63b8a8cc 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -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,) ) diff --git a/libmproxy/console/grideditor.py b/libmproxy/console/grideditor.py index e7c9854be..dc3bad0eb 100644 --- a/libmproxy/console/grideditor.py +++ b/libmproxy/console/grideditor.py @@ -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,) ) diff --git a/libmproxy/console/statusbar.py b/libmproxy/console/statusbar.py index 7ff26b155..30819188e 100644 --- a/libmproxy/console/statusbar.py +++ b/libmproxy/console/statusbar.py @@ -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) diff --git a/libmproxy/console/window.py b/libmproxy/console/window.py index 87f06637a..d686f61dd 100644 --- a/libmproxy/console/window.py +++ b/libmproxy/console/window.py @@ -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: