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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
# =============================================================================
#
# File: HistEntry.tcl
# Project: TkDesk
#
# Started: 28.01.97
# Changed: 28.01.97
# Author: cb
#
#
# Copyright (C) 1997 Christian Bolik
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
# See the file "COPYING" in the base directory of this distribution
# for more.
#
# -----------------------------------------------------------------------------
#
# Sections:
#s itcl_class dsk_HistEntry
#s method config {config}
#s method ok_pressed {}
#s method add_pressed {}
#s method histmenu {}
#s proc id {}
#
# -----------------------------------------------------------------------------
#
# =============================================================================
#
# Class: dsk_HistEntry
# Desc: Creates a dialog window with a text entry field plus
# attached history.
#
# Methods:
# Procs:
# Publics:
#
itcl_class dsk_HistEntry {
inherit Toplevel
constructor {args} {
global tkdesk [set this]
eval configure $args
if {$tkdesk(tcl_version) < 8.0} {
Toplevel::constructor
}
wm withdraw $top
frame $top.f -bd 1 -relief raised
pack $top.f -fill both -expand yes
frame $top.fl
pack $top.fl -in $top.f -fill x
label $top.label -text $label
pack $top.label -in $top.fl -side left \
-padx $tkdesk(pad) -pady $tkdesk(pad)
set [set this](cbvar) $checkvalue
if {$checklabel != ""} {
checkbutton $top.cbBrowser -text $checklabel \
-variable [set this](cbvar)
pack $top.cbBrowser -in $top.fl -side right \
-padx $tkdesk(pad) -pady $tkdesk(pad)
}
frame $top.fe
pack $top.fe -in $top.f -fill both -expand yes
entry $top.entry -width 40 -bd 2 -relief sunken \
-exportselection no
set sel ""
if {$entrydefault != ""} {
$top.entry insert end $entrydefault
$top.entry icursor end
$top.entry xview end
} elseif {$history != "" && $sel == ""} {
$top.entry insert end [$history last]
$top.entry icursor end
$top.entry xview end
}
pack $top.entry -in $top.fe -fill x -expand yes -side left \
-padx $tkdesk(pad) -pady $tkdesk(pad) -ipady 2
bind $top.entry <Visibility> {%W selection range 0 end}
bind $top.entry <Return> "$top.bOK.button invoke"
bind $top.entry <Escape> "$top.bCancel.button invoke"
bind $top.entry <Control-c> "$top.bCancel.button invoke; break"
bind $top.entry <Menu> "$this _entry_popup"
bind $top.entry <3> "$this _entry_popup"
cb_bindForCompletion $top.entry <Control-Tab>
blt_drag&drop target $top.entry handler file \
"dd_handle_text $top.entry %v 1"
if {$history != ""} {
menubutton $top.mbHist -bd 2 -relief raised \
-bitmap @$tkdesk(library)/cb_tools/bitmaps/combo.xbm \
-menu $top.mbHist.menu
pack $top.mbHist -in $top.fe -side right \
-padx $tkdesk(pad) -pady $tkdesk(pad) -ipadx 2 -ipady 2
menu $top.mbHist.menu -postcommand "$this histmenu"
# add dummy entry to work around bug in pre Tk 4.0p2:
$top.mbHist.menu add command -label "dummy"
$history changed
}
frame $top.fb -bd 1 -relief raised
pack $top.fb -fill x
cb_button $top.bOK -text " OK " \
-underline 3 -default 1 -command "
set tkdesk(geometry,hist_entry) \[wm geometry $top\]
set [set this](entry) \[$top.entry get\]
destroy $top
update idletasks
$this ok_pressed
"
cb_button $top.bApply -text " Apply " \
-underline 1 -command "
set [set this](entry) \[$top.entry get\]
$this ok_pressed 0
"
if $noapply {
$top.bApply.button config -state disabled
}
if {$addbutton != ""} {
set i 0
while {[string index $addbutton $i] == " "} {incr i}
set sc [string index $addbutton $i]
cb_button $top.bAdd -text $addbutton \
-underline $i -command "
set tkdesk(geometry,hist_entry) \[wm geometry $top\]
set [set this](entry) \[$top.entry get\]
destroy $top
update idletasks
$this add_pressed
"
cb_addShortcutBinding $top.entry $top.bAdd.button "$sc"
}
cb_button $top.bCancel -text " Cancel " \
-underline 1 -command "
set tkdesk(geometry,hist_entry) \[wm geometry $top\]
itcl::delete object $this
"
pack $top.bOK $top.bApply -in $top.fb -side left \
-padx $tkdesk(pad) -pady $tkdesk(pad)
if {$addbutton != ""} {
pack $top.bAdd -in $top.fb -side left \
-padx $tkdesk(pad) -pady $tkdesk(pad)
}
pack $top.bCancel -in $top.fb -side left \
-padx $tkdesk(pad) -pady $tkdesk(pad)
cb_addShortcutBinding $top.entry $top.bOK.button "o"
cb_addShortcutBinding $top.entry $top.bCancel.button "c"
if !$noapply {
cb_addShortcutBinding $top.entry $top.bApply.button "a"
}
bind $top <Any-Enter> "focus $top.entry"
wm minsize $top 348 117
if {$title == ""} {
set title $label
}
wm title $top $title
wm protocol $top WM_DELETE_WINDOW "$top.bCancel.button invoke"
if ![info exists tkdesk(geometry,hist_menu)] {
set tkdesk(geometry,hist_menu) ""
}
dsk_place_window $top hist_entry "" 0 1
wm deiconify $top
if !$nograb {
grab $top
set old_focus [focus]
focus -force $top.entry
tkwait window $top
catch {focus -force $old_focus}
}
}
destructor {
#after 10 rename $this-top {} ;# delete this name
#catch {destroy $this} ;# destroy associated window
}
#
# ----- Methods and Procs -------------------------------------------------
#
method config {args} {
eval configure $args
}
method ok_pressed {{delete 1}} {
global [set this]
if {$callback != ""} {
eval $callback \
[list [set [set this](entry)]] [set [set this](cbvar)]
}
if $delete {
itcl::delete object $this ;#???
}
}
method add_pressed {} {
global [set this]
if {$addcallback != ""} {
eval $addcallback \
[list [set [set this](entry)]] [set [set this](cbvar)]
}
itcl::delete object $this ;#???
}
method histmenu {} {
global tkdesk
catch "$top.mbHist.menu delete 0 last"
if $tkdesk(sort_history) {
set l [lsort [$history get]]
} else {
set l [$history get]
}
set ne 0
set menu $top.mbHist.menu
foreach ent $l {
$menu add command -label $ent \
-command "$top.entry delete 0 end ;\
$top.entry insert end [list $ent]" \
-font [cb_font $tkdesk(font,entries)]
incr ne
if {$ne > $tkdesk(_max_menu_entries)} {
set om $menu
$menu add cascade -label "More..." \
-menu [set menu $menu.c$ne]
catch {destroy $menu}; menu $menu; set ne 0
foreach b [bind $om] {bind $menu $b [bind $om $b]}
}
}
}
method _entry_popup {} {
if {$entrypopupproc != ""} {
$entrypopupproc $top.entry
}
}
proc id {} {
set i $id
incr id
return $i
}
#
# ----- Variables ---------------------------------------------------------
#
common id 0
public variable label "dummy"
public variable title ""
public variable checklabel ""
public variable checkvalue 0
public variable entrydefault ""
public variable entrypopupproc ""
public variable history ""
public variable callback ""
public variable addbutton ""
public variable addcallback ""
public variable nograb 0
public variable noapply 0
}
|