diff --git a/lib/config.tcl b/lib/config.tcl index 4d8a42b..c4d0760 100644 --- a/lib/config.tcl +++ b/lib/config.tcl @@ -75,6 +75,9 @@ RB=ruby HTM=firefox HTML=firefox LUA=lua +\[Debug\] +debug=false +debugOut=stdout " proc Config::create {dir} { set cfgFile [open [file join $dir projman.ini] "w+"] @@ -131,3 +134,47 @@ proc Config::write {dir} { ini::commit $cfgFile ini::close $cfgFile } + +# Добавление перменной в список +# если отсутствует нужная секция то она будет добавлена. +proc Config::AddVariable {key value section} { + # Проверяем, существует ли уже такая переменная + if {[info exists ::cfgVariables($key)]} { + DebugPuts "The variable '$key' already exists: $::cfgVariables($key)" + return 0 + } + + # Добавляем в массив переменных + set ::cfgVariables($key) $value + + # Добавляем в список ключей секции + if {[info exists ::cfgINIsections($section)]} { + # Проверяем, нет ли уже такого ключа в секции + if {[lsearch -exact $::cfgINIsections($section) $key] == -1} { + lappend ::cfgINIsections($section) $key + } + } else { + set ::cfgINIsections($section) [list $key] + } + DebugPuts "Config::AddVariable: The variable '$key' has been added to the array 'cfgVariables'" + + return 1 +} + +# Проверяем наличие переменных в конфиге на основе "эталонного" списка +# и выставляем значение по умолчанию если в конфиге переменной нет +proc Config::CheckVariables {} { + set valList [split $::configDefault "\n"] + foreach item $valList { + if {[regexp -nocase -all -- {\[(\w+)\]} $item -> v1]} { + set section $v1 + } + if {[regexp {^([^=]+)=(.*)$} $item -> var value]} { + if ![info exists ::cfgVariables($var)] { + DebugPuts "Error in Config::CheckVariables: variable ::cfgVariables($var) not found" + Config::AddVariable "$var" "$value" "$section" + DebugPuts "Config::CheckVariables: The variable cfgVariables($var) setting to default value \"$value\"" + } + } + } +} diff --git a/lib/procedure.tcl b/lib/procedure.tcl index ee4c018..09e0828 100644 --- a/lib/procedure.tcl +++ b/lib/procedure.tcl @@ -1155,3 +1155,14 @@ proc Paste {} { SendEventToLatestTxtWidget <> } proc Undo {} { SendEventToLatestTxtWidget <> } proc Redo {} { SendEventToLatestTxtWidget <> } # ------------ + +proc DebugPuts {msg} { + global cfgVariables debugFlag + if ![info exists cfgVariables(debugFlag)] { + set cfgVariables(debugFlag) "true" + } + if {$cfgVariables(debugFlag) eq "true"} { + puts "$msg" + } +} + diff --git a/projman.tcl b/projman.tcl index babe817..f8cbf79 100755 --- a/projman.tcl +++ b/projman.tcl @@ -119,6 +119,7 @@ if {[file exists [file join $dir(cfg) projman.ini]] ==0} { Config::create $dir(cfg) } Config::read $dir(cfg) +Config::CheckVariables ::msgcat::mclocale $cfgVariables(locale)