Added assert and Scheduler, and started adding proper test frameworks
[tcl-tlc.git] / scripts / application.itk
blobde7eb781067883b8e7622989f56a71a0585738c4
1 # vim: ft=tcl ts=4 shiftwidth=4 foldmethod=marker foldmarker=<<<,>>>
3 proc tlc::application {pathName args} {
4         uplevel tlc::Application $pathName $args
8 class tlc::Application {
9         inherit tlc::Module tlc::Baselog
11         constructor {args} {}
12         destructor {
13                 if {$armed && $::errorInfo != ""} {
14                         log error "\nerror constructing Application: $errmsg\n$::errorInfo"
15                 }
16                 exit 0
17         }
19         public {
20                 variable debug                  0
21                 variable confirm_close  unsaved
22         }
24         protected {
25                 variable armed                  1
26                 variable unsaved_info   ""
28                 method confirm_close    {}
29         }
33 body tlc::Application::constructor {args} { #<<<1
34         eval itk_initialize $args
36         namespace eval $this {}
38         tlc::Gate ${this}::unsaved_info unsaved_info -mode "or"
40         configure -onclose [code $this confirm_close]
42         namespace import ::blt::*
44         wm withdraw .
46         tlc::Confirm .confirm -title "Confirm Action"
47         tlc::Deny .deny -title "Permission Denied"
48         tlc::Getinf .getinf -title "Question"
49         tlc::Infowin    .nfo    -title "Information"
51         set armed       0
55 body tlc::Application::confirm_close {} { #<<<1
56         if {$confirm_close == "unsaved"} {
57                 if {
58                         ![${this}::unsaved_info state] 
59                         || [.confirm ask "You have unsaved information!\nAre you sure you want to exit?" Yes No] == "Yes"
60                 } {
61                         delete object $this
62                 }
63         } elseif {$confirm_close} {
64                 if {[.confirm ask "Are you sure you want to exit?" Yes No] == "Yes"} {
65                         delete object $this
66                 }
67         } else {
68                 delete object $this
69         }