| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : iniFile.tcl |
|---|
| 3 | # PURPOSE : This file contains a namespace called ::iniFile with its |
|---|
| 4 | # functions. It's for managing ini files, adding an abstraction |
|---|
| 5 | # layer over iniparseBys.tcl. |
|---|
| 6 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 10 | namespace eval ::iniFile { |
|---|
| 11 | # |
|---|
| 12 | # PURPOSE: The purpose of this namespace is organize code and functions. |
|---|
| 13 | # |
|---|
| 14 | # VARIABLES: |
|---|
| 15 | # idIni -> identifier of ini file |
|---|
| 16 | # idGCF -> array of identifiers of graphics configuration files |
|---|
| 17 | # |
|---|
| 18 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 19 | variable idIni |
|---|
| 20 | variable idGCF |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 25 | proc ::iniFile::Create {fileName} { |
|---|
| 26 | # |
|---|
| 27 | # PURPOSE: |
|---|
| 28 | # |
|---|
| 29 | # PARAMETERS: |
|---|
| 30 | # |
|---|
| 31 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 32 | variable idIni |
|---|
| 33 | #Tolcon_Trace "::iniFile::Create fileName: $fileName" |
|---|
| 34 | set idIni [iniparse:openfile $fileName] |
|---|
| 35 | #Tolcon_Trace "idIni: $idIni" |
|---|
| 36 | #bind . <Destroy> [list ::iniFile::Destroy %W] |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 41 | proc ::iniFile::CloseAll {} { |
|---|
| 42 | # |
|---|
| 43 | # PURPOSE: |
|---|
| 44 | # |
|---|
| 45 | # PARAMETERS: |
|---|
| 46 | # |
|---|
| 47 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 48 | variable idIni |
|---|
| 49 | variable idGCF |
|---|
| 50 | |
|---|
| 51 | iniparse:closefile $idIni |
|---|
| 52 | foreach it [array names idGCF] { |
|---|
| 53 | iniparse:closefile $idGCF($it) |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 59 | proc ::iniFile::SetGCF {key fileName} { |
|---|
| 60 | # |
|---|
| 61 | # PURPOSE: |
|---|
| 62 | # |
|---|
| 63 | # PARAMETERS: |
|---|
| 64 | # |
|---|
| 65 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 66 | #Tolcon_Trace "::iniFile::SetGCF key: $key, fileName: $fileName" |
|---|
| 67 | variable idIni |
|---|
| 68 | variable idGCF |
|---|
| 69 | if [string equal $fileName ""] { |
|---|
| 70 | set idGCF($key) $idIni |
|---|
| 71 | } else { |
|---|
| 72 | if { [info exist idGCF($key)] && ![string equal $idGCF($key) $idIni] } { |
|---|
| 73 | iniparse:closefile $idGCF($key) |
|---|
| 74 | } |
|---|
| 75 | set idGCF($key) [iniparse:openfile $fileName] |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 81 | proc ::iniFile::SaveGCF {key fileName} { |
|---|
| 82 | # |
|---|
| 83 | # PURPOSE: |
|---|
| 84 | # |
|---|
| 85 | # PARAMETERS: |
|---|
| 86 | # |
|---|
| 87 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 88 | #Tolcon_Trace "::iniFile::SaveGCF key: $key, fileName: $fileName" |
|---|
| 89 | variable idGCF |
|---|
| 90 | ::iniFile::SetGCF $key $fileName |
|---|
| 91 | |
|---|
| 92 | if {![string equal $fileName ""]} { |
|---|
| 93 | iniparse:closefile $idGCF($key) |
|---|
| 94 | set idGCF($key) [iniparse:openfile $fileName] |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 100 | proc ::iniFile::Read {key item {valueini {}}} { |
|---|
| 101 | # |
|---|
| 102 | # PURPOSE: |
|---|
| 103 | # |
|---|
| 104 | # PARAMETERS: |
|---|
| 105 | # |
|---|
| 106 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 107 | #Tolcon_Trace "::iniFile::Read key: $key, item: $item, valueini: $valueini" |
|---|
| 108 | variable idIni |
|---|
| 109 | set value [readini $idIni $key $item] |
|---|
| 110 | if {$value == "" } { |
|---|
| 111 | set value $valueini |
|---|
| 112 | } |
|---|
| 113 | return $value |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 118 | proc ::iniFile::ReadGCF {key item {valueini {}}} { |
|---|
| 119 | # |
|---|
| 120 | # PURPOSE: |
|---|
| 121 | # |
|---|
| 122 | # PARAMETERS: |
|---|
| 123 | # |
|---|
| 124 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 125 | #Tolcon_Trace "::iniFile::ReadGCF key: $key, item: $item, valueini: $valueini" |
|---|
| 126 | variable idGCF |
|---|
| 127 | set value [readini $idGCF($key) $key $item] |
|---|
| 128 | if {$value == "" } { |
|---|
| 129 | set value $valueini |
|---|
| 130 | } |
|---|
| 131 | return $value |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 136 | proc ::iniFile::Write {key item value} { |
|---|
| 137 | # |
|---|
| 138 | # PURPOSE: |
|---|
| 139 | # |
|---|
| 140 | # PARAMETERS: |
|---|
| 141 | # |
|---|
| 142 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 143 | #Tolcon_Trace "::iniFile::Write key: $key, item: $item, value: $value" |
|---|
| 144 | variable idIni |
|---|
| 145 | writeini $idIni $key $item $value |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 150 | proc ::iniFile::WriteGCF {key item value} { |
|---|
| 151 | # |
|---|
| 152 | # PURPOSE: |
|---|
| 153 | # |
|---|
| 154 | # PARAMETERS: |
|---|
| 155 | # |
|---|
| 156 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 157 | #Tolcon_Trace "::iniFile::WriteGCF key: $key, item: $item, value: $value" |
|---|
| 158 | variable idGCF |
|---|
| 159 | writeini $idGCF($key) $key $item $value |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 164 | proc ::iniFile::Flush {} { |
|---|
| 165 | # |
|---|
| 166 | # PURPOSE: |
|---|
| 167 | # |
|---|
| 168 | # PARAMETERS: |
|---|
| 169 | # |
|---|
| 170 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 171 | variable idIni |
|---|
| 172 | iniparse:flushfile $idIni |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 177 | proc ::iniFile::FlushGCF {key} { |
|---|
| 178 | # |
|---|
| 179 | # PURPOSE: |
|---|
| 180 | # |
|---|
| 181 | # PARAMETERS: |
|---|
| 182 | # |
|---|
| 183 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 184 | variable idGCF |
|---|
| 185 | after idle iniparse:flushfile $idGCF($key) |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 189 | proc ::iniFile::ReadWMState {iniReader section} { |
|---|
| 190 | # |
|---|
| 191 | # PURPOSE: |
|---|
| 192 | # |
|---|
| 193 | # PARAMETERS: |
|---|
| 194 | # iniReader -> |
|---|
| 195 | # section -> |
|---|
| 196 | # |
|---|
| 197 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 198 | set state [$iniReader $section wm,state normal] |
|---|
| 199 | set state [expr {$state eq "zoomed" && $::tcl_platform(platform) eq "windows" ? \ |
|---|
| 200 | $state : "normal" }] |
|---|
| 201 | expr {$state eq "withdrawn" ? "normal" : $state} |
|---|
| 202 | } |
|---|