File: edittable.tcl

package info (click to toggle)
ewipe 1.2.0-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 604 kB
  • sloc: tcl: 5,289; sh: 8; makefile: 4
file content (188 lines) | stat: -rw-r--r-- 4,624 bytes parent folder | download | duplicates (7)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#                                                 #
#                  edittable.tcl                  #       
#                                                 #
#   Copyright (C) 1997-2000  Hiromasa Sekishita   #
#                                                 #
#              This program conforms              #
#      GNU GENERAL PUBLIC LICENSE Version 2.      # 
#                                                 #

proc ET_inittable {text} {
    global et_col
    global et_row
    global et_table

    set et_table {}
    if {$text != {}} {
	set n [llength $text]
	set et_col [llength [lindex $text 0]]
	
	lappend et_table [lindex $text 0]
	set et_row 1
	for {set i 1} {$i < $n} {incr i} {
	    set str [lindex $text $i]
	    if {$str != "|" && $str != "_"} {
		incr et_row
		set tcol {}
		for {set j 0} {$j < [expr $et_col * 2]} {incr j 2} {
		    lappend tcol [lindex $str [expr $j + 1]]
		}
		lappend et_table $tcol
	    }
	}
	if {$et_row == 1} {set et_row 2}
    } else {
	set et_col 3
	set et_row 3
	set et_table {}
    }
    for {set j 0} {$j < 12} {incr j} {
	for {set i 0} {$i < 11} {incr i} {
	    if {[winfo exists .table.c.e($i,$j)] == 1} {
		delete .table.c.e($i,$j)
	    }
	}
    }
    ET_maketable
}

proc ET_settable {} {
    global et_col
    global et_row
    global et_text
    
    set text {}
    append text "\n    "
    set def {}
    for {set i 0} {$i < $et_col} {incr i} {
	set s [.table.c.e($i,0) get]
	if {$s != "l" && $s != "c" && $s != "r"} {
	    set s c
	}
	lappend def $s
    }
    lappend text $def
    append text "\n    "
    lappend text "|"

    append text "\n    "
    for {set j 1} {$j < $et_row} {incr j} {
	set tablec {} 
	for {set i 0} {$i < $et_col} {incr i} {
	    lappend tablec "|"
	    lappend tablec [.table.c.e($i,$j) get]
	}
	lappend tablec "|"
	lappend text $tablec
	append text "\n    "
	lappend text "|"
	append text "\n    "
    }
    destroy .table
    set et_text $text
}

proc ET_maketable {} {
    global et_table
    global et_col
    global et_row

    set width [expr (600 - (5 * $et_col)) / $et_col]
    
    .table.c delete all
 
    for {set i 0} {$i < $et_col} {incr i} {
	if {[winfo exists .table.c.e($i,0)] == 1} {
	    .table.c.e($i,0) configure -width [expr $width / 7]
	} else {
	    entry .table.c.e($i,0) -width [expr $width / 7]
	    set str [lindex [lindex $et_table 0] $i] 
	    if {$str == {}} {set str c}
	    .table.c.e($i,0) insert 0 $str
	}
	set window [.table.c create window [expr $i * ($width + 5)] \
		10 -window .table.c.e($i,0) -anchor nw]
    }

    for {set j 1} {$j < $et_row} {incr j} {
	for {set i 0} {$i < $et_col} {incr i} {
	    if {[winfo exists .table.c.e($i,$j)] == 1} {
		.table.c.e($i,$j) configure -width [expr $width / 7]
	    } else {
		entry .table.c.e($i,$j) -width [expr $width / 7]
		set str [lindex [lindex $et_table $j] $i] 
 		.table.c.e($i,$j) insert 0 $str
	    }
	    set window [.table.c create window [expr $i * ($width + 5)] \
		    [expr $j * 25 + 20] -window .table.c.e($i,$j) -anchor nw]
	}
    }
}

proc edittable {text} {
    global et_col
    global et_row
    global et_text
    global message
    global Option
    
    toplevel .table
    wm title .table "table Editor"
    
    set et_text {}

    frame .table.fb1
    button .table.fb1.bo -text $message(ok) -command ET_settable
    button .table.fb1.bc -text $message(cancel) -command {destroy .table}

    if {$Option(lang) == "jpn"} {
	set btn(addrow) "ɲ"
	set btn(delrow) "Ժ"
	set btn(addcol) "ɲ"
	set btn(delcol) ""
    } elseif {$Option(lang) == "eng"} {
 	set btn(addrow) "addrow"
	set btn(delrow) "delrow"
	set btn(addcol) "addcolumn"
	set btn(delcol) "delcolumn"
    }
    
    frame .table.fb2
    button .table.fb2.bar -text $btn(addrow) -command {
	incr et_row
	if {$et_row > 11} {set et_row 11}
	ET_maketable
    }
    button .table.fb2.bdr -text $btn(delrow) -command {
	incr et_row -1
	if {$et_row < 2} {set et_row 2}
	ET_maketable
    }
    button .table.fb2.bac -text $btn(addcol) -command {
	incr et_col
	if {$et_col > 10} {set et_col 10}
	ET_maketable
    }
    button .table.fb2.bdc -text $btn(delcol) -command {
	incr et_col -1
	if {$et_col < 1} {set et_col 1}
	ET_maketable
    }
    canvas .table.c -height 310 -width 600
    pack .table.fb2.bar .table.fb2.bdr .table.fb2.bac .table.fb2.bdc \
	    -side left
    pack .table.fb1.bo .table.fb1.bc -side left
    pack .table.c .table.fb2 .table.fb1

    wm minsize .table 600 370
    wm maxsize .table 600 400
    
    ET_inittable $text
    
    update
    focus .table.c    
    grab .table
    tkwait window .table
    
    return $et_text
}