Specialize GridEditor into a number of subclasses.
This commit is contained in:
parent
5690e7c399
commit
65e88f49d4
|
@ -122,7 +122,7 @@ class StatusBar(common.WWrap):
|
||||||
if self.master.replacehooks.count():
|
if self.master.replacehooks.count():
|
||||||
r.append("[")
|
r.append("[")
|
||||||
r.append(("heading_key", "R"))
|
r.append(("heading_key", "R"))
|
||||||
r.append("eplace]")
|
r.append("eplacing]")
|
||||||
if self.master.client_playback:
|
if self.master.client_playback:
|
||||||
r.append("[")
|
r.append("[")
|
||||||
r.append(("heading_key", "cplayback"))
|
r.append(("heading_key", "cplayback"))
|
||||||
|
@ -547,8 +547,8 @@ class ConsoleMaster(flow.FlowMaster):
|
||||||
self.header = None
|
self.header = None
|
||||||
self.make_view()
|
self.make_view()
|
||||||
|
|
||||||
def view_grideditor(self, title, columns, value, callback, *args, **kwargs):
|
def view_grideditor(self, ge):
|
||||||
self.body = grideditor.GridEditor(self, title, columns, value, callback, *args, **kwargs)
|
self.body = ge
|
||||||
self.header = None
|
self.header = None
|
||||||
self.help_context = grideditor.help_context
|
self.help_context = grideditor.help_context
|
||||||
self.statusbar = StatusBar(self, self.footer_text_help)
|
self.statusbar = StatusBar(self, self.footer_text_help)
|
||||||
|
@ -710,7 +710,9 @@ class ConsoleMaster(flow.FlowMaster):
|
||||||
self.view_flowlist()
|
self.view_flowlist()
|
||||||
|
|
||||||
def set_replace(self, r):
|
def set_replace(self, r):
|
||||||
pass
|
self.replacehooks.clear()
|
||||||
|
for i in r:
|
||||||
|
self.replacehooks.add(*i)
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -791,10 +793,11 @@ class ConsoleMaster(flow.FlowMaster):
|
||||||
self.sync_list_view()
|
self.sync_list_view()
|
||||||
elif k == "R":
|
elif k == "R":
|
||||||
self.view_grideditor(
|
self.view_grideditor(
|
||||||
"Editing replacements",
|
grideditor.ReplaceEditor(
|
||||||
3,
|
self,
|
||||||
self.replacehooks.get_specs(),
|
self.replacehooks.get_specs(),
|
||||||
self.set_replace
|
self.set_replace
|
||||||
|
)
|
||||||
)
|
)
|
||||||
elif k == "s":
|
elif k == "s":
|
||||||
if self.script:
|
if self.script:
|
||||||
|
@ -934,3 +937,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||||
self.process_flow(f, r)
|
self.process_flow(f, r)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
import os, re
|
import os, re
|
||||||
import urwid
|
import urwid
|
||||||
import common
|
import common, grideditor
|
||||||
from .. import utils, encoding, flow
|
from .. import utils, encoding, flow
|
||||||
|
|
||||||
def _mkhelp():
|
def _mkhelp():
|
||||||
|
@ -395,7 +395,9 @@ class ConnectionView(common.WWrap):
|
||||||
conn.set_form_urlencoded(flow.ODict(lst))
|
conn.set_form_urlencoded(flow.ODict(lst))
|
||||||
|
|
||||||
def edit_form(self, conn):
|
def edit_form(self, conn):
|
||||||
self.master.view_grideditor("Editing form", 2, conn.get_form_urlencoded().lst, self.set_form, conn)
|
self.master.view_grideditor(
|
||||||
|
grideditor.URLEncodedFormEditor(self.master, conn.get_form_urlencoded().lst, self.set_form, conn)
|
||||||
|
)
|
||||||
|
|
||||||
def edit_form_confirm(self, key, conn):
|
def edit_form_confirm(self, key, conn):
|
||||||
if key == "y":
|
if key == "y":
|
||||||
|
@ -427,9 +429,9 @@ class ConnectionView(common.WWrap):
|
||||||
else:
|
else:
|
||||||
self.edit_form(conn)
|
self.edit_form(conn)
|
||||||
elif part == "h":
|
elif part == "h":
|
||||||
self.master.view_grideditor("Editing headers", 2, conn.headers.lst, self.set_headers, conn)
|
self.master.view_grideditor(grideditor.HeaderEditor(self.master, conn.headers.lst, self.set_headers, conn))
|
||||||
elif part == "q":
|
elif part == "q":
|
||||||
self.master.view_grideditor("Editing query", 2, conn.get_query().lst, self.set_query, conn)
|
self.master.view_grideditor(grideditor.QueryEditor(self.master, conn.get_query().lst, self.set_query, conn))
|
||||||
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||||
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
self.master.prompt_edit("URL", conn.get_url(), self.set_url)
|
||||||
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||||
|
|
|
@ -205,12 +205,11 @@ class GridListBox(urwid.ListBox):
|
||||||
|
|
||||||
|
|
||||||
class GridEditor(common.WWrap):
|
class GridEditor(common.WWrap):
|
||||||
def __init__(self, master, title, columns, value, callback, *cb_args, **cb_kwargs):
|
def __init__(self, master, value, callback, *cb_args, **cb_kwargs):
|
||||||
value = copy.deepcopy(value)
|
value = copy.deepcopy(value)
|
||||||
self.master, self.title, self.value, self.callback = master, title, value, callback
|
self.master, self.value, self.callback = master, value, callback
|
||||||
self.columns = columns
|
|
||||||
self.cb_args, self.cb_kwargs = cb_args, cb_kwargs
|
self.cb_args, self.cb_kwargs = cb_args, cb_kwargs
|
||||||
p = urwid.Text(title)
|
p = urwid.Text(self.title)
|
||||||
p = urwid.Padding(p, align="left", width=("relative", 100))
|
p = urwid.Padding(p, align="left", width=("relative", 100))
|
||||||
p = urwid.AttrWrap(p, "heading")
|
p = urwid.AttrWrap(p, "heading")
|
||||||
self.walker = GridWalker(self.value, self)
|
self.walker = GridWalker(self.value, self)
|
||||||
|
@ -273,3 +272,24 @@ class GridEditor(common.WWrap):
|
||||||
self.walker.start_edit()
|
self.walker.start_edit()
|
||||||
else:
|
else:
|
||||||
return self.w.keypress(size, key)
|
return self.w.keypress(size, key)
|
||||||
|
|
||||||
|
|
||||||
|
class QueryEditor(GridEditor):
|
||||||
|
title = "Editing query"
|
||||||
|
columns = 2
|
||||||
|
|
||||||
|
|
||||||
|
class HeaderEditor(GridEditor):
|
||||||
|
title = "Editing headers"
|
||||||
|
columns = 2
|
||||||
|
|
||||||
|
|
||||||
|
class URLEncodedFormEditor(GridEditor):
|
||||||
|
title = "Editing URL-encoded form"
|
||||||
|
columns = 2
|
||||||
|
|
||||||
|
|
||||||
|
class ReplaceEditor(GridEditor):
|
||||||
|
title = "Editing replacement patterns"
|
||||||
|
columns = 3
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ def urlencode(s):
|
||||||
"""
|
"""
|
||||||
Takes a list of (key, value) tuples and returns a urlencoded string.
|
Takes a list of (key, value) tuples and returns a urlencoded string.
|
||||||
"""
|
"""
|
||||||
|
s = [tuple(i) for i in s]
|
||||||
return urllib.urlencode(s, False)
|
return urllib.urlencode(s, False)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue