1# $id$
2
3#
4# if you're running tkabber under the tkcon package
5#
6#     http://tkcon.sourceforge.net
7#
8# e.g.,
9#
10#     % tkcon.tcl -name tkabber -exec "" -root .tkconn -main "source tkabber.tcl"
11#
12# or if tkcon is installed as a Tcl package and can be sourced via
13# [package require] (tkcon isn't loaded at start, so it doesn't waste resources
14# if it's unneeded)
15#
16
17if {[lempty [package versions tkcon]] && \
18	[llength [info commands ::tkcon::*]] <= 0} {
19    return
20}
21
22namespace eval tkcon {
23    variable onceP 1
24    variable showP 0
25}
26
27proc tkcon::add_tkcon_to_tkabber_menu {args} {
28    catch {
29        set menu [.mainframe getmenu debug]
30	$menu add checkbutton -label [::msgcat::mc "Show TkCon console"] \
31	      -command  [namespace current]::show_console \
32	      -variable [namespace current]::showP
33	show_console
34    }
35}
36
37proc tkcon::show_console {} {
38    variable onceP
39    variable showP
40
41    if {[llength [info commands ::tkcon::*]] <= 0} {
42	package require tkcon
43    }
44
45    if {$showP} {
46	tkcon show
47
48	if {$onceP} {
49	    wm protocol $::tkcon::PRIV(root) WM_DELETE_WINDOW \
50		    [namespace current]::hide_console
51	    set onceP 0
52	}
53    } else {
54	tkcon hide
55    }
56}
57
58proc tkcon::hide_console {} {
59    variable showP
60
61    tkcon hide
62    set showP 0
63}
64
65hook::add finload_hook [namespace current]::tkcon::add_tkcon_to_tkabber_menu
66
67