blob: 7988ebb07c5fd94476223cfad46b781d85356103 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# Copyright (C) 2007 Tresys Technology, LLC
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
namespace eval Apol_Goto {
variable dialog .apol_goto_dialog
variable line_num
}
proc Apol_Goto::goto {} {
variable dialog
if {![winfo exists $dialog]} {
_create_dialog
} else {
raise $dialog
variable entry
focus $entry
$entry selection range 0 end
}
}
########## private functions below ##########
proc Apol_Goto::_create_dialog {} {
variable dialog
Dialog $dialog -title "Goto Line" -separator 0 -parent . \
-default 0 -cancel 1 -modal none -homogeneous 1
set top_frame [$dialog getframe]
set entry_label [label $top_frame.l -text "Goto Line:" -anchor e]
variable entry [entry $top_frame.e -bg white \
-textvariable Apol_Goto::line_num -width 10]
pack $entry_label -side left -padx 5 -pady 5
pack $entry -side left -padx 5 -pady 5 -expand 1 -fill x
$dialog add -text "OK" -command [list Apol_Goto::_do_goto]
$dialog add -text "Cancel" -command [list destroy $dialog]
$entry selection range 0 end
focus $entry
$dialog draw
wm resizable $dialog 0 0
}
proc Apol_Goto::_do_goto {} {
set w [ApolTop::getCurrentTextWidget]
if {$w == {}} {
return
}
variable line_num
if {[string is integer -strict $line_num] != 1} {
tk_messageBox -icon error \
-type ok \
-title "Goto Line" \
-message "$line_num is not a valid line number."
} else {
$w tag remove sel 0.0 end
$w mark set insert ${line_num}.0
$w see ${line_num}.0
$w tag add sel $line_num.0 $line_num.end
focus $w
}
variable dialog
destroy $dialog
}
|