blob: 5943e3baec895d32cae137b6634ad33a49f88832 [file] [log] [blame]
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +00001import tkSimpleDialog
Guido van Rossum504b0bf1999-01-02 21:28:54 +00002
3###$ event <<find>>
4###$ win <Control-f>
5###$ unix <Control-u><Control-u><Control-s>
6
7###$ event <<find-again>>
8###$ win <Control-g>
9###$ win <F3>
10###$ unix <Control-u><Control-s>
11
12###$ event <<find-selection>>
13###$ win <Control-F3>
14###$ unix <Control-s>
15
16###$ event <<find-in-files>>
17###$ win <Alt-F3>
18
19###$ event <<replace>>
20###$ win <Control-h>
21
22###$ event <<goto-line>>
23###$ win <Alt-g>
24###$ unix <Alt-g>
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000025
26class SearchBinding:
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000027
Guido van Rossum504b0bf1999-01-02 21:28:54 +000028 windows_keydefs = {
29 '<<find-again>>': ['<Control-g>', '<F3>'],
30 '<<find-in-files>>': ['<Alt-F3>'],
31 '<<find-selection>>': ['<Control-F3>'],
32 '<<find>>': ['<Control-f>'],
33 '<<replace>>': ['<Control-h>'],
34 '<<goto-line>>': ['<Alt-g>'],
35 }
36
37 unix_keydefs = {
38 '<<find-again>>': ['<Control-u><Control-s>'],
Guido van Rossum5bfffbd1999-01-04 16:32:04 +000039 '<<find-in-files>>': ['<Alt-s>', '<Meta-s>'],
Guido van Rossum504b0bf1999-01-02 21:28:54 +000040 '<<find-selection>>': ['<Control-s>'],
41 '<<find>>': ['<Control-u><Control-u><Control-s>'],
Guido van Rossum4eac47c1999-01-04 21:18:40 +000042 '<<replace>>': ['<Control-r>'],
Guido van Rossum504b0bf1999-01-02 21:28:54 +000043 '<<goto-line>>': ['<Alt-g>', '<Meta-g>'],
44 }
45
46 menudefs = [
47 ('edit', [
48 None,
49 ('_Find...', '<<find>>'),
50 ('Find a_gain', '<<find-again>>'),
51 ('Find _selection', '<<find-selection>>'),
52 ('Find in Files...', '<<find-in-files>>'),
53 ('R_eplace...', '<<replace>>'),
54 ('Go to _line', '<<goto-line>>'),
55 ]),
56 ]
57
58 def __init__(self, editwin):
59 self.editwin = editwin
60
61 def find_event(self, event):
62 import SearchDialog
63 SearchDialog.find(self.editwin.text)
64 return "break"
65
66 def find_again_event(self, event):
67 import SearchDialog
68 SearchDialog.find_again(self.editwin.text)
69 return "break"
70
71 def find_selection_event(self, event):
72 import SearchDialog
73 SearchDialog.find_selection(self.editwin.text)
74 return "break"
75
76 def find_in_files_event(self, event):
77 import GrepDialog
78 GrepDialog.grep(self.editwin.text, self.editwin.io, self.editwin.flist)
79 return "break"
80
81 def replace_event(self, event):
82 import ReplaceDialog
83 ReplaceDialog.replace(self.editwin.text)
84 return "break"
85
86 def goto_line_event(self, event):
Guido van Rossum504b0bf1999-01-02 21:28:54 +000087 text = self.editwin.text
88 lineno = tkSimpleDialog.askinteger("Goto",
89 "Go to line number:",
90 parent=text)
91 if lineno is None:
92 return "break"
93 if lineno <= 0:
94 text.bell()
95 return "break"
96 text.mark_set("insert", "%d.0" % lineno)
97 text.see("insert")