Statistics
| Branch: | Revision:

root / src / tkenv / tkenvrc.tcl @ fbe00e73

History | View | Annotate | Download (5.17 KB)

1 01873262 Georg Kunz
#=================================================================
2
#  TKENVRC.TCL - part of
3
#
4
#                     OMNeT++/OMNEST
5
#            Discrete System Simulation in C++
6
#
7
#=================================================================
8
9
#----------------------------------------------------------------#
10
#  Copyright (C) 1992-2008 Andras Varga
11
#
12
#  This file is distributed WITHOUT ANY WARRANTY. See the file
13
#  `license' for details on this and other legal matters.
14
#----------------------------------------------------------------#
15
16
17
18
# save_tkenvrc --
19
#
20
#
21
proc save_tkenvrc {fname savesettings saveinspectors atexit {comment ""}} {
22
    global config fonts defaultfonts
23
24
    if [catch {
25
        set fout [open $fname w]
26
        puts $fout $comment
27
        if {$savesettings} {
28
            foreach key {
29
                updatefreq_fast_ms
30
                updatefreq_express_ms
31
                stepdelay
32
                use_mainwindow
33
                event_banners
34
                init_banners
35
                short_banners
36
                animation_enabled
37
                nexteventmarkers
38
                senddirect_arrows
39
                anim_methodcalls
40
                methodcalls_delay
41
                animation_msgnames
42
                animation_msgclassnames
43
                animation_msgcolors
44
                penguin_mode
45
                showlayouting
46
                layouterchoice
47
                arrangevectorconnections
48
                iconminsize
49
                bubbles
50
                animation_speed
51
                expressmode_autoupdate
52
                stoponmsgcancel
53
            } {
54
                set value [opp_getsimoption $key]
55
                puts $fout "option $key\t{$value}"
56
            }
57
58
            store_mainwin_geom
59
            foreach key [lsort [array names config]] {
60
                set value $config($key)
61
                puts $fout "config $key\t{$value}"
62
            }
63
64
            foreach key [lsort [array names fonts]] {
65
                if {[info exists defaultfonts($key)] && $fonts($key)!=$defaultfonts($key)} {
66
                    set value $fonts($key)
67
                    puts $fout "fonts $key\t{$value}"
68
                }
69
            }
70
        }
71
72
        if {$saveinspectors} {
73
            puts $fout [inspectorlist_tkenvrc_get_contents $atexit]
74
        }
75
76
        close $fout
77
78
    } err] {
79
       tk_messageBox -icon error -type ok -message "Error: $err" -title {Error}
80
       return
81
    }
82
}
83
84
proc store_mainwin_geom {} {
85
    global config
86
87
    set state [wm state .]
88
    set geom [wm geometry .]
89
    if {$state=="zoomed"} {
90
        # Workaround: with zoomed (maximized) windows, wm geometry returns the
91
        # the original (unzoomed) position but the zoomed size! We want to store
92
        # unzoomed size+position so that the window can be restored (unzoomed)
93
        # properly. Unfortunately the original size is lost forever, so we just
94
        # put in the default size instead.
95
        # Note: another command, "winfo geometry", would return the zoomed size
96
        # and the zoomed position, but it's even less use to us here.
97
        regsub {[0-9]+x[0-9]+(.*)} $geom {640x480\1} geom
98
    }
99
    set config(mainwin-state) $state
100
    set config(mainwin-geom) $geom
101
}
102
103
# load_tkenvrc --
104
#
105
#
106
proc load_tkenvrc {fname} {
107
    global config fonts
108
109
    if [catch {open $fname r} fin] {
110
        return
111
    }
112
113
    inspectorlist_tkenvrc_reset
114
115
    set lineno 1
116
    while {[gets $fin line] >= 0} {
117
        if {$line == ""} {incr lineno; continue}
118
        if [string match {#*} $line] {incr lineno; continue}
119
120
        if [catch {
121
            set cat [lindex $line 0]
122
            if {$cat == "inspector"} {
123
                inspectorlist_tkenvrc_process_line $line
124
            } elseif {$cat == "option"} {
125
                set key [lindex $line 1]
126
                set value [lindex $line 2]
127
                catch {opp_setsimoption $key $value}  ;# catch: ignore obsolete entries
128
            } elseif {$cat == "config"} {
129
                set key [lindex $line 1]
130
                set value [lindex $line 2]
131
                set config($key) $value
132
            } elseif {$cat == "fonts"} {
133
                set key [lindex $line 1]
134
                set value [lindex $line 2]
135
                set value [actualFont [fixupFontName $value]] ;# some validation
136
                if {$value!=""} {
137
                    set fonts($key) $value
138
                }
139
            } elseif {[llength $line]==4} {
140
                # old tkenvrc, patch it up
141
                inspectorlist_tkenvrc_process_line [concat "inspector" $line]
142
            }
143
        }] {
144
            tk_messageBox -icon warning -type ok -title {Error reading .tkenvrc} -message "$fname line $lineno is invalid, ignoring"
145
        }
146
        incr lineno
147
    }
148
    close $fin
149
150
    opp_updateinspectors
151
    inspectorlist_openinspectors
152
    reflectSettingsInGui
153
}
154
155
156
# reflectSettingsInGui --
157
#
158
#
159
proc reflectSettingsInGui {} {
160
   global config fonts
161
162
   catch {wm state . $config(mainwin-state)}
163
   catch {wm geometry . $config(mainwin-geom)}
164
165
   catch {.main.text config -wrap $config(editor-wrap)}
166
167
   applyFont Text $fonts(text)
168
   applyFont Listbox $fonts(listbox)
169
   applyFont TreeView $fonts(listbox)
170
171
   toggle_treeview
172
   toggle_treeview
173
   toggle_timeline
174
   toggle_timeline
175
}