1 from configHandler
import idleConf
5 def __init__(self
, text
, output_sep
= "\n"):
8 self
.history_prefix
= None
9 self
.history_pointer
= None
10 self
.output_sep
= output_sep
11 self
.cyclic
= idleConf
.GetOption("main", "History", "cyclic", 1, "bool")
12 text
.bind("<<history-previous>>", self
.history_prev
)
13 text
.bind("<<history-next>>", self
.history_next
)
15 def history_next(self
, event
):
19 def history_prev(self
, event
):
23 def _get_source(self
, start
, end
):
24 # Get source code from start index to end index. Lines in the
25 # text control may be separated by sys.ps2 .
26 lines
= self
.text
.get(start
, end
).split(self
.output_sep
)
27 return "\n".join(lines
)
29 def _put_source(self
, where
, source
):
30 output
= self
.output_sep
.join(source
.split("\n"))
31 self
.text
.insert(where
, output
)
33 def history_do(self
, reverse
):
34 nhist
= len(self
.history
)
35 pointer
= self
.history_pointer
36 prefix
= self
.history_prefix
37 if pointer
is not None and prefix
is not None:
38 if self
.text
.compare("insert", "!=", "end-1c") or \
39 self
._get
_source
("iomark", "end-1c") != self
.history
[pointer
]:
40 pointer
= prefix
= None
41 if pointer
is None or prefix
is None:
42 prefix
= self
._get
_source
("iomark", "end-1c")
57 if pointer
< 0 or pointer
>= nhist
:
59 if not self
.cyclic
and pointer
< 0:
62 if self
._get
_source
("iomark", "end-1c") != prefix
:
63 self
.text
.delete("iomark", "end-1c")
64 self
._put
_source
("iomark", prefix
)
65 pointer
= prefix
= None
67 item
= self
.history
[pointer
]
68 if item
[:nprefix
] == prefix
and len(item
) > nprefix
:
69 self
.text
.delete("iomark", "end-1c")
70 self
._put
_source
("iomark", item
)
72 self
.text
.mark_set("insert", "end-1c")
73 self
.text
.see("insert")
74 self
.text
.tag_remove("sel", "1.0", "end")
75 self
.history_pointer
= pointer
76 self
.history_prefix
= prefix
78 def history_store(self
, source
):
79 source
= source
.strip()
83 self
.history
.remove(source
)
86 self
.history
.append(source
)
87 self
.history_pointer
= None
88 self
.history_prefix
= None