| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : editor.tol |
|---|
| 3 | # PURPOSE : This file contains a namespace called Editor with its functions. |
|---|
| 4 | # It's for creating a editor widget with TOL highlight syntax and |
|---|
| 5 | # managing its events. |
|---|
| 6 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | |
|---|
| 8 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 9 | # TESTING |
|---|
| 10 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | # Put if {1} for testing this file. |
|---|
| 12 | if { 0 } { |
|---|
| 13 | package require Tk |
|---|
| 14 | package require BWidget |
|---|
| 15 | package require rbc |
|---|
| 16 | Bitmap::use |
|---|
| 17 | |
|---|
| 18 | set toltk_script_path [file dirname [info script]] |
|---|
| 19 | set toltk_images_path [file join ${toltk_script_path} images] |
|---|
| 20 | |
|---|
| 21 | #source [file join $toltk_script_path "ctext.tcl"] |
|---|
| 22 | source [file join $toltk_script_path "supertext.tcl"] |
|---|
| 23 | Supertext::overrideTextCommand |
|---|
| 24 | source [file join $toltk_script_path "bystext.tcl"] |
|---|
| 25 | lappend ::Bitmap::path $toltk_images_path |
|---|
| 26 | |
|---|
| 27 | package require msgcat |
|---|
| 28 | namespace import ::msgcat::* |
|---|
| 29 | ::msgcat::mclocale es |
|---|
| 30 | ::msgcat::mcload [file join $toltk_script_path msgs] |
|---|
| 31 | |
|---|
| 32 | set home_path $env(HOME) |
|---|
| 33 | ::iniFile::Create [file join $home_path "tolcon.ini"] |
|---|
| 34 | proc startupResources { } { |
|---|
| 35 | global tcl_platform |
|---|
| 36 | global toltk_options |
|---|
| 37 | DynamicHelp::configure -background \#FFFFC0 |
|---|
| 38 | if [string equal $tcl_platform(platform) "windows"] { |
|---|
| 39 | set toltk_options(colors,SystemButtonFace) SystemButtonFace |
|---|
| 40 | set toltk_options(fonts,MenuNor) {Tahoma 8} |
|---|
| 41 | set toltk_options(fonts,Fixed) {{Courier New} 9} |
|---|
| 42 | set toltk_options(fonts,Title1) {Arial 9 bold} |
|---|
| 43 | set toltk_options(fonts,Label) {Arial 9} |
|---|
| 44 | font create Letra1 -family "Arial" -slant roman -size 8 |
|---|
| 45 | set toltk_options(relief,ridge) ridge |
|---|
| 46 | } else { |
|---|
| 47 | set toltk_options(colors,SystemButtonFace) #d4d4d4 |
|---|
| 48 | set toltk_options(fonts,MenuNor) {-*-helvetica-medium-r} |
|---|
| 49 | set toltk_options(fonts,Fixed) {Courier 10} |
|---|
| 50 | set toltk_options(fonts,Title1) {-*-helvetica-bold-r} |
|---|
| 51 | set toltk_options(fonts,Label) {-*-helvetica-medium-r} |
|---|
| 52 | set toltk_options(relief,ridge) raised |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | startupResources |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 60 | namespace eval ::Editor { |
|---|
| 61 | # |
|---|
| 62 | # PURPOSE: The purpose of this namespace is organize code and functions and |
|---|
| 63 | # manage common options for all editors such as last edited files, |
|---|
| 64 | # last directory opened, etc. |
|---|
| 65 | # A special namespace is created for each instance of editor. |
|---|
| 66 | # |
|---|
| 67 | # VARIABLES: |
|---|
| 68 | # options -> common options for all editor windows: |
|---|
| 69 | # geometry -> initial window editor geometry |
|---|
| 70 | # wm,state -> initial window editor state |
|---|
| 71 | # font -> editor's text widget font |
|---|
| 72 | # lastDir -> last directory used |
|---|
| 73 | # chEdited -> boolen for saving last edited files path |
|---|
| 74 | # numEdited -> number of last edited files path to save |
|---|
| 75 | # edited -> path of last edited files |
|---|
| 76 | # tmpOpt -> temporary array used to store the widgets and variables of |
|---|
| 77 | # the options dialog. |
|---|
| 78 | # num_editor -> incrementally number to identify each editor window |
|---|
| 79 | # typelist -> list of type files supported by editor |
|---|
| 80 | # defExt -> default extension for files managed by editor |
|---|
| 81 | # |
|---|
| 82 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 83 | variable options |
|---|
| 84 | variable num_editor 0 |
|---|
| 85 | variable typelist {{"Tol Files" {".tol"}} {"All Files" {"*"}}} |
|---|
| 86 | variable defExt .tol |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 91 | proc ::Editor::New {{path ""}} { |
|---|
| 92 | # |
|---|
| 93 | # PURPOSE: Creates a new editor window and an instance of it. This also |
|---|
| 94 | # initializes the instance and register the window in the project. |
|---|
| 95 | # |
|---|
| 96 | # PARAMETERS: |
|---|
| 97 | # path -> path of file to edit. If it isn't specified a new white document |
|---|
| 98 | # is created. |
|---|
| 99 | # |
|---|
| 100 | # RETURN: A instance of editor. |
|---|
| 101 | # |
|---|
| 102 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 103 | variable num_editor |
|---|
| 104 | incr num_editor |
|---|
| 105 | |
|---|
| 106 | set this [Create .editor$num_editor] |
|---|
| 107 | SetTraces $this |
|---|
| 108 | InitState $this new |
|---|
| 109 | update |
|---|
| 110 | if {$path == ""} { |
|---|
| 111 | CmdNew $this |
|---|
| 112 | } |
|---|
| 113 | return $this |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 118 | proc ::Editor::Open {{path ""} {run 0}} { |
|---|
| 119 | # |
|---|
| 120 | # PURPOSE: Opens a file in a editor window. If file is already opened it |
|---|
| 121 | # raises its window, else it creates a new editor window and an |
|---|
| 122 | # instance of it. |
|---|
| 123 | # |
|---|
| 124 | # PARAMETERS: |
|---|
| 125 | # path -> path of file to open. If it isn't specified it ask for it. |
|---|
| 126 | # run -> automatically once opened, compiles the file |
|---|
| 127 | # |
|---|
| 128 | # RETURN: A instance of editor. |
|---|
| 129 | # |
|---|
| 130 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 131 | if {$path != ""} { |
|---|
| 132 | #Comprobar si el archivo ya está abierto y si es así hacer un raise |
|---|
| 133 | foreach ins [namespace children ::Editor] { |
|---|
| 134 | upvar \#0 ${ins}::data data |
|---|
| 135 | if {[string equal $data(nameFile) $path]} { |
|---|
| 136 | #wm deiconify $data(f) |
|---|
| 137 | $data(f) raise |
|---|
| 138 | #focus $data(f) |
|---|
| 139 | return $ins |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | update |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | if {$path == ""} { |
|---|
| 146 | CmdOpen "" |
|---|
| 147 | } else { |
|---|
| 148 | set this [New $path] |
|---|
| 149 | GetFromFile $this $path $run |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | if {[info exists this]} { |
|---|
| 153 | return $this |
|---|
| 154 | } else { |
|---|
| 155 | return "" |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 161 | proc ::Editor::postEdited {m {ord 0}} { |
|---|
| 162 | # |
|---|
| 163 | # PURPOSE: Fills a menu with the last edited files, according to the |
|---|
| 164 | # information of 'options' variable. |
|---|
| 165 | # |
|---|
| 166 | # PARAMETERS: |
|---|
| 167 | # m -> menu's path that will have the list of last edited files |
|---|
| 168 | # ord -> flag that indicates if files must be shown sorted |
|---|
| 169 | # |
|---|
| 170 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 171 | variable options |
|---|
| 172 | $m delete 0 end |
|---|
| 173 | if $options(chEdited) { |
|---|
| 174 | set options(edited) [lrange $options(edited) 0 [expr $options(numEdited)-1]] |
|---|
| 175 | if $ord { |
|---|
| 176 | set lst [lsort -ascii $options(edited)] |
|---|
| 177 | } else { |
|---|
| 178 | set lst $options(edited) |
|---|
| 179 | } |
|---|
| 180 | foreach w $lst { |
|---|
| 181 | $m add command -label $w -command [list ::Editor::Open $w] |
|---|
| 182 | } |
|---|
| 183 | if [llength $lst] { |
|---|
| 184 | $m add separator |
|---|
| 185 | $m add command -label [mc "Clear"]\ |
|---|
| 186 | -command [list ::Editor::clearEdited] |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 192 | proc ::Editor::clearEdited {} { |
|---|
| 193 | # |
|---|
| 194 | # PURPOSE: Clears the list of last edited files |
|---|
| 195 | # |
|---|
| 196 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 197 | variable options |
|---|
| 198 | set options(edited) "" |
|---|
| 199 | ::iniFile::Write Editor recent $options(edited) |
|---|
| 200 | ::iniFile::Flush |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 204 | proc ::Editor::OnDelete {this} { |
|---|
| 205 | # |
|---|
| 206 | # PURPOSE: Procedure to check things before destroying editor window |
|---|
| 207 | # |
|---|
| 208 | # PARAMETERS: |
|---|
| 209 | # this -> Instance of editor |
|---|
| 210 | # |
|---|
| 211 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 212 | upvar \#0 ${this}::data data |
|---|
| 213 | if {[string equal [CheckOpen $this] "cancel"]} { |
|---|
| 214 | return 0 |
|---|
| 215 | } |
|---|
| 216 | destroy $data(f) |
|---|
| 217 | return 1 |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 221 | proc ::Editor::Configure {this} { |
|---|
| 222 | # |
|---|
| 223 | # PURPOSE: Configures editor |
|---|
| 224 | # |
|---|
| 225 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 226 | variable options |
|---|
| 227 | |
|---|
| 228 | set fnt $options(font) |
|---|
| 229 | |
|---|
| 230 | #puts "Configure con $fnt" |
|---|
| 231 | |
|---|
| 232 | if {[llength $fnt]>1} { |
|---|
| 233 | font configure ctfnBold -family [lindex $fnt 0] -size [lindex $fnt 1] |
|---|
| 234 | font configure ctfnNormal -family [lindex $fnt 0] -size [lindex $fnt 1] |
|---|
| 235 | } else { |
|---|
| 236 | font configure ctfnBold -family $fnt -size 9 |
|---|
| 237 | font configure ctfnNormal -family $fnt -size 9 |
|---|
| 238 | } |
|---|
| 239 | CmdRightMargin $this |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 243 | proc ::Editor::Destroy {this w} { |
|---|
| 244 | # |
|---|
| 245 | # PURPOSE: Deletes the instance of editor. Before this,writes the ini file. |
|---|
| 246 | # |
|---|
| 247 | # PARAMETERS: |
|---|
| 248 | # this -> Instance of editor |
|---|
| 249 | # |
|---|
| 250 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 251 | upvar \#0 ${this}::data data |
|---|
| 252 | #CheckOpen $this |
|---|
| 253 | if { [string equal $data(f) $w] } { |
|---|
| 254 | # guardamos variables en el .ini |
|---|
| 255 | #puts "estamos destruyendo y guardando en el ini" |
|---|
| 256 | WriteIni $this |
|---|
| 257 | namespace delete $this |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 263 | proc ::Editor::InitState {this from} { |
|---|
| 264 | # |
|---|
| 265 | # PURPOSE: Initializes some variables according to the state of editor. |
|---|
| 266 | # |
|---|
| 267 | # PARAMETERS: |
|---|
| 268 | # this -> Instance of editor |
|---|
| 269 | # from -> State that defines values for the variables |
|---|
| 270 | # |
|---|
| 271 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 272 | upvar \#0 ${this}::data data |
|---|
| 273 | |
|---|
| 274 | switch $from { |
|---|
| 275 | new { |
|---|
| 276 | set data(isSaved) 1 |
|---|
| 277 | set data(isCompiled) 0 |
|---|
| 278 | #If clipboard has something (to enable paste) |
|---|
| 279 | set data(clipboard) 0 |
|---|
| 280 | #If there is something selected (to enable cut, copy) |
|---|
| 281 | set data(selected) 0 |
|---|
| 282 | set data(nameFile) "" |
|---|
| 283 | # Time of last modification of file |
|---|
| 284 | set data(mTime) 0 |
|---|
| 285 | #pedro - balloon controller |
|---|
| 286 | set data(balloon) 0 |
|---|
| 287 | } |
|---|
| 288 | open { |
|---|
| 289 | if {[lsearch [::tol::info included] $data(nameFile)] != -1} { |
|---|
| 290 | set data(isCompiled) 1 |
|---|
| 291 | } else { |
|---|
| 292 | set data(isCompiled) 0 |
|---|
| 293 | } |
|---|
| 294 | set data(isSaved) 1 |
|---|
| 295 | # set data(nameFile) "" |
|---|
| 296 | } |
|---|
| 297 | save { |
|---|
| 298 | set data(isSaved) 1 |
|---|
| 299 | #set data(isCompiled) 0 |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | #pedro-controls balloon hlp |
|---|
| 303 | IniSupertext $this |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 308 | proc ::Editor::InsertFileHeader {this} { |
|---|
| 309 | # |
|---|
| 310 | # PURPOSE: |
|---|
| 311 | # |
|---|
| 312 | # PARAMETERS: |
|---|
| 313 | # |
|---|
| 314 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 315 | variable options |
|---|
| 316 | upvar \#0 ${this}::data data |
|---|
| 317 | if $options(chFileH) { |
|---|
| 318 | if [file exists $options(fileH)] { |
|---|
| 319 | ::BayesText::Open $data(txt) $options(fileH) |
|---|
| 320 | #Lo marcamos como guardado a pesar de no ser realmente cierto |
|---|
| 321 | set data(isSaved) 1 |
|---|
| 322 | tk::TextSetCursor $data(txt) end |
|---|
| 323 | } else { |
|---|
| 324 | #Sacar mensaje de que no existe el archivo especificado |
|---|
| 325 | tk_messageBox -type ok -icon warning \ |
|---|
| 326 | -parent $data(txt) -title [mc Warning] \ |
|---|
| 327 | -message "[mc "Header file %1\$s doesn't exist" $options(fileH)].\n\ |
|---|
| 328 | [mc "Check editor's options"]" |
|---|
| 329 | $data(txt) mark set insert 1.0 |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 335 | proc ::Editor::InsertFileFunction {this} { |
|---|
| 336 | # |
|---|
| 337 | # PURPOSE: |
|---|
| 338 | # |
|---|
| 339 | # PARAMETERS: |
|---|
| 340 | # |
|---|
| 341 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 342 | variable options |
|---|
| 343 | upvar \#0 ${this}::data data |
|---|
| 344 | |
|---|
| 345 | if [file exists $options(funcH)] { |
|---|
| 346 | ::BayesText::Open $data(txt) $options(funcH) $data(position) |
|---|
| 347 | #tk::TextSetCursor $data(txt) end |
|---|
| 348 | } else { |
|---|
| 349 | #Sacar mensaje de que no existe el archivo especificado |
|---|
| 350 | tk_messageBox -type ok -icon warning \ |
|---|
| 351 | -parent $data(txt) -title [mc Warning] \ |
|---|
| 352 | -message "[mc "Functions file header %1\$s doesn't exist" $options(funcH)].\n\ |
|---|
| 353 | [mc "Check editor's options"]" |
|---|
| 354 | } |
|---|
| 355 | $data(txt) mark set insert $data(position) |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | proc ::Editor::IniSupertext {this} { |
|---|
| 359 | upvar \#0 ${this}::data data |
|---|
| 360 | set Supertext::undo($data(txt,supertext)) {} |
|---|
| 361 | set Supertext::undoIndex($data(txt,supertext)) -1 |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 366 | proc ::Editor::SetTraces {this} { |
|---|
| 367 | # |
|---|
| 368 | # PURPOSE: Sets some traces of variables to control changes in editor widget |
|---|
| 369 | # |
|---|
| 370 | # PARAMETERS: |
|---|
| 371 | # this -> Instance of editor |
|---|
| 372 | # |
|---|
| 373 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 374 | upvar \#0 ${this}::data data |
|---|
| 375 | |
|---|
| 376 | trace variable ${this}::data(nameFile) w \ |
|---|
| 377 | [list ::Editor::TraceNameFile $this] |
|---|
| 378 | trace variable ${this}::data(selected) w \ |
|---|
| 379 | [list ::Editor::TraceSelected $this] |
|---|
| 380 | trace variable ${this}::data(isSaved) w \ |
|---|
| 381 | [list ::Editor::TraceSaved $this] |
|---|
| 382 | trace variable ${this}::data(isCompiled) w \ |
|---|
| 383 | [list ::Editor::TraceCompiled $this] |
|---|
| 384 | trace variable ${this}::data(position) w \ |
|---|
| 385 | [list ::Editor::TracePosition $this] |
|---|
| 386 | trace variable Supertext::undo($data(txt,supertext)) w \ |
|---|
| 387 | [list ::Editor::TraceUndo $this] |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | proc ::Editor::UpdateMarkPos { this h} { |
|---|
| 391 | #puts "UpdateMarkPos $this $h" |
|---|
| 392 | |
|---|
| 393 | variable options |
|---|
| 394 | upvar \#0 ${this}::data data |
|---|
| 395 | if $options(chLine) { |
|---|
| 396 | $data(txt,mark) configure -height $h |
|---|
| 397 | set xpos [expr $options(posLine) * [font measure ctfnNormal "/"]] |
|---|
| 398 | place $data(txt,mark) -in $data(txt) -x $xpos -y 0 |
|---|
| 399 | } else { |
|---|
| 400 | place forget $data(txt,mark) |
|---|
| 401 | } |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | proc ::Editor::OnConfigure { this w h } { |
|---|
| 405 | UpdateMarkPos $this $h |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 410 | proc ::Editor::Create {path} { |
|---|
| 411 | # |
|---|
| 412 | # PURPOSE: Creates a editor instance |
|---|
| 413 | # |
|---|
| 414 | # PARAMETERS: |
|---|
| 415 | # path -> editor's path (toplevel) |
|---|
| 416 | # |
|---|
| 417 | # RETURN: Editor's instance |
|---|
| 418 | # |
|---|
| 419 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 420 | variable options |
|---|
| 421 | |
|---|
| 422 | set this ::Editor::$path |
|---|
| 423 | if { [lsearch [namespace children ::Editor] $this] != -1 } { |
|---|
| 424 | error "$this already exists as a children of ::Editor" |
|---|
| 425 | } |
|---|
| 426 | namespace eval $this { |
|---|
| 427 | variable data |
|---|
| 428 | } |
|---|
| 429 | upvar \#0 ${this}::data data |
|---|
| 430 | |
|---|
| 431 | # create |
|---|
| 432 | set data(f) [set f [::project::CreateForm -width 575 -height 700 \ |
|---|
| 433 | -type Files \ |
|---|
| 434 | -iniconfig Editor \ |
|---|
| 435 | -closecmd [list ::Editor::OnDelete $this] \ |
|---|
| 436 | -helpkey "Tb4Eda"] ] |
|---|
| 437 | set f [$f getframe] |
|---|
| 438 | |
|---|
| 439 | # bind Destroy más abajo |
|---|
| 440 | set n_b [list \ |
|---|
| 441 | "bnew" "CmdNew" "[mc [list New white document]] (CTRL+N)" \ |
|---|
| 442 | "bopen" "CmdOpen" "[mc Open] (CTRL+A)" \ |
|---|
| 443 | "bsave" "CmdSave" "[mc Save] (CTRL+S)" \ |
|---|
| 444 | "sep1" "--" ""\ |
|---|
| 445 | "bcut" "CmdCut" "[mc Cut] (CTRL+X)" \ |
|---|
| 446 | "bcopy" "CmdCopy" "[mc Copy] (CTRL+C)" \ |
|---|
| 447 | "bpaste" "CmdPaste" "[mc Paste] (CTRL+V)" \ |
|---|
| 448 | "sep2" "--" ""\ |
|---|
| 449 | "bundo" "CmdUndo" "[mc Undo] (CTRL+Z)" \ |
|---|
| 450 | "bredo" "CmdRedo" "[mc Redo] (CTRL+Y)" \ |
|---|
| 451 | "sep3" "--" ""\ |
|---|
| 452 | "bfind" "CmdFind" "[mc Find] (CTRL+F)" \ |
|---|
| 453 | "findnext" "CmdFindNext" "[mc [list Find next]] (F3)" \ |
|---|
| 454 | "funsearch" "CmdSearch" "[mc {Search function}] (CTRL+G)" \ |
|---|
| 455 | "sep4" "--" ""\ |
|---|
| 456 | "unindent" "CmdUnIndent" "[mc Unindent] (CTRL+U)" \ |
|---|
| 457 | "indent" "CmdIndent" "[mc Indent] (CTRL+I)" \ |
|---|
| 458 | "sep5" "--" ""\ |
|---|
| 459 | "bprint" "CmdPrint" "[mc Print]" \ |
|---|
| 460 | "font" "CmdFont" "[mc Font] (CTRL+T)" \ |
|---|
| 461 | "sep6" "--" ""\ |
|---|
| 462 | "eval" "CmdCompile" "[mc Compile] (F11)" \ |
|---|
| 463 | "savecom" "CmdSaveCompile" "[mc [list Save and Compile]] (F9)" \ |
|---|
| 464 | "decom" "CmdDecompile" "[mc Decompile] (F8)" \ |
|---|
| 465 | "syntaxcheck" "CmdSyntaxCheck" "[mc [list Syntax check]] (F7)" \ |
|---|
| 466 | "refresh" "CmdRefresh" "[mc Refresh] (F5)"\ |
|---|
| 467 | "balloon" "CmdBalloon" "[mc BalloonHelp]" \ |
|---|
| 468 | "sep7" "--" ""\ |
|---|
| 469 | "tools" "CmdOptions" "[mc Options]"] |
|---|
| 470 | # botonera superior |
|---|
| 471 | set data(tb,frame) [frame $f.ftop -relief raised -bd 1] |
|---|
| 472 | foreach {n_img n_proc n_hint} $n_b { |
|---|
| 473 | if {[string equal $n_proc "--"]} { |
|---|
| 474 | Separator $f.ftop.$n_img -orient vertical |
|---|
| 475 | #pack $f.ftop.$n_img -side left -fill y |
|---|
| 476 | } else { |
|---|
| 477 | set data(tb,$n_img) [Button $f.ftop.$n_img\ |
|---|
| 478 | -image [::Bitmap::get ${n_img}] -relief link\ |
|---|
| 479 | -helptext $n_hint -bd 2\ |
|---|
| 480 | -command [list ::Editor::$n_proc $this]] |
|---|
| 481 | } |
|---|
| 482 | pack $f.ftop.$n_img -anchor nw -side left -pady 2 -fill y -padx 1 |
|---|
| 483 | } |
|---|
| 484 | #desactivamos botones de print y redo |
|---|
| 485 | #$data(tb,redo) configure -state disabled |
|---|
| 486 | $data(tb,bprint) configure -state disabled |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | # frame y label para barra de estado |
|---|
| 490 | set data(sb,frame) [frame $f.fop -relief groove -bd 1 -height 7] |
|---|
| 491 | set data(sb,posi) [label $f.fop.posi -relief groove -bd 1 -width 16] |
|---|
| 492 | set data(sb,comp) [label $f.fop.comp -text [mc "Not Compiled"] \ |
|---|
| 493 | -relief raised -bd 1 -width 16] |
|---|
| 494 | set data(sb,modi) [label $f.fop.modi -bd 1 -width 14] |
|---|
| 495 | set data(sb,nlin) [label $f.fop.nlin -relief groove -bd 1 -width 16] |
|---|
| 496 | set data(sb,rell) [label $f.fop.rell -relief groove -bd 1] |
|---|
| 497 | # texto y scroll |
|---|
| 498 | scrollbar $f.sy -command "$f.t yview" |
|---|
| 499 | scrollbar $f.sx -orient horizontal -command "$f.t xview" |
|---|
| 500 | |
|---|
| 501 | set data(txt) [::BayesText::CreateHLText $f.t tol \ |
|---|
| 502 | -background white -borderwidth 0 -wrap none\ |
|---|
| 503 | -foreground black -relief sunken \ |
|---|
| 504 | -yscrollcommand "$f.sy set" \ |
|---|
| 505 | -xscrollcommand "$f.sx set" \ |
|---|
| 506 | -preproc "::Editor::PreProc $this" \ |
|---|
| 507 | -linemap 0 -font $options(font)] |
|---|
| 508 | |
|---|
| 509 | bind $data(txt) <Configure> "::Editor::OnConfigure $this %w %h" |
|---|
| 510 | set data(txt,ctext) $data(txt).t |
|---|
| 511 | set data(txt,mark) [frame $f.mark -bg gray50 -width 1 \ |
|---|
| 512 | -cursor [$data(txt,ctext) cget -cursor]] |
|---|
| 513 | |
|---|
| 514 | set data(txt,supertext) __$data(txt,ctext) |
|---|
| 515 | |
|---|
| 516 | focus $data(txt,ctext) |
|---|
| 517 | # empaquetamos los label de estado |
|---|
| 518 | pack $f.fop.posi $f.fop.comp $f.fop.modi $f.fop.nlin -side left |
|---|
| 519 | pack $f.fop.rell -expand true -fill x |
|---|
| 520 | |
|---|
| 521 | grid $f.ftop - -sticky new |
|---|
| 522 | grid $f.t $f.sy -sticky news |
|---|
| 523 | grid $f.sx -sticky ew |
|---|
| 524 | grid $f.fop - -sticky ews |
|---|
| 525 | |
|---|
| 526 | grid rowconfigure $f 1 -weight 1 |
|---|
| 527 | grid columnconfigure $f 0 -weight 1 |
|---|
| 528 | |
|---|
| 529 | #Creación de un menú contextual |
|---|
| 530 | # leer del archivo de cinfiguracion para coger la fuente del texto |
|---|
| 531 | set m [menu $f.m -tearoff 0] |
|---|
| 532 | $m add command -label [mc "Save and Compile"] -accelerator F9 \ |
|---|
| 533 | -command [list ::Editor::CmdSaveCompile $this] |
|---|
| 534 | $m add command -label [mc "Decompile"] -accelerator F8 \ |
|---|
| 535 | -command [list ::Editor::CmdDecompile $this] |
|---|
| 536 | $m add command -label [mc "Syntax Check"] -accelerator F7 \ |
|---|
| 537 | -command [list ::Editor::CmdSyntaxCheck $this] |
|---|
| 538 | $m add command -label [mc "Compile"] -accelerator F11 \ |
|---|
| 539 | -command [list ::Editor::CmdCompile $this] |
|---|
| 540 | $m add command -label [mc "Refresh"] -accelerator F5 \ |
|---|
| 541 | -command [list ::Editor::CmdRefresh $this] |
|---|
| 542 | |
|---|
| 543 | $m add separator |
|---|
| 544 | $m add command -label "[mc Open]..." -accelerator CTRL+A \ |
|---|
| 545 | -command [list ::Editor::CmdOpen $this] |
|---|
| 546 | $m add command -label [mc "Save"] -accelerator CTRL+S \ |
|---|
| 547 | -command [list ::Editor::CmdSave $this] |
|---|
| 548 | $m add command -label "[mc [list Save as]] ..." \ |
|---|
| 549 | -command [list ::Editor::CmdSaveAs $this] |
|---|
| 550 | $m add separator |
|---|
| 551 | $m add command -label [ mc "Escape text" ]... \ |
|---|
| 552 | -command [ list ::BayesText::DlgEscapeText $data(txt) ] |
|---|
| 553 | $m add command -label "[mc Find]..." -accelerator CTRL+F \ |
|---|
| 554 | -command [list ::Editor::CmdFind $this] |
|---|
| 555 | $m add command -label [mc "Find next"] -accelerator F3 \ |
|---|
| 556 | -command [list ::Editor::CmdFindNext $this] |
|---|
| 557 | $m add command -label "[mc Replace]..." -accelerator CTRL+R \ |
|---|
| 558 | -command [list ::Editor::CmdReplace $this] |
|---|
| 559 | $m add command -label "[mc {Search function}]..." -accelerator CTRL+G \ |
|---|
| 560 | -command [list ::Editor::CmdSearch $this] |
|---|
| 561 | $m add separator |
|---|
| 562 | $m add command -label [mc "Insert function schema"] \ |
|---|
| 563 | -command [list ::Editor::InsertFileFunction $this] |
|---|
| 564 | $m add command -label "[mc Font]..." -accelerator CTRL+T \ |
|---|
| 565 | -command [list ::Editor::CmdFont $this] |
|---|
| 566 | $m add check -label [mc "Show right margin line"] -variable ::Editor::options(chLine) \ |
|---|
| 567 | -command [list ::Editor::CmdRightMargin $this] |
|---|
| 568 | set me [menu $f.m.edit -tearoff 0] |
|---|
| 569 | $m add cascade -label [mc "Edit"] -menu $me |
|---|
| 570 | $me add command -label [mc "Undo"] -accelerator CTRL+Z \ |
|---|
| 571 | -command [list ::Editor::CmdUndo $this] |
|---|
| 572 | $me add command -label [mc "Cut"] -accelerator CTRL+X \ |
|---|
| 573 | -command [list ::Editor::CmdCut $this] |
|---|
| 574 | $me add command -label [mc "Copy"] -accelerator CTRL+C \ |
|---|
| 575 | -command [list ::Editor::CmdCopy $this] |
|---|
| 576 | $me add command -label [mc "Paste"] -accelerator CTRL+V \ |
|---|
| 577 | -command [list ::Editor::CmdPaste $this] |
|---|
| 578 | $me add command -label [mc "Select all"] -accelerator CTRL+E \ |
|---|
| 579 | -command [list ::Editor::CmdSelectAll $this] |
|---|
| 580 | |
|---|
| 581 | bind $data(txt,ctext) <Button-3> "tk_popup $m %X %Y" |
|---|
| 582 | #pedro |
|---|
| 583 | #$data(txt,ctext) tag bind Text <Enter> [list ::Editor::BalloonHlp $this] |
|---|
| 584 | #set data(menu) [::BayesText::MenuCreate $data(txt)] |
|---|
| 585 | set data(menu) $m |
|---|
| 586 | #Quitar los eventos que pueden dar conflictos |
|---|
| 587 | bind Text <Control-a> "" |
|---|
| 588 | # necesario para q al escribir el simbolo del euro no ejecute tb el comando |
|---|
| 589 | #bind Text <Control-e> "::Editor::CmdSelectAll $this" |
|---|
| 590 | bind Text <Control-f> "" |
|---|
| 591 | bind Text <Control-i> "" |
|---|
| 592 | bind Text <Control-n> "" |
|---|
| 593 | bind Text <Control-t> "" |
|---|
| 594 | |
|---|
| 595 | # eventos asociados al formulario |
|---|
| 596 | bind $data(txt) <F1> "::Editor::CmdHelpEditor $this ; break" |
|---|
| 597 | bind $data(txt) <F3> "Editor::CmdFindNext $this ; break" |
|---|
| 598 | bind $data(txt) <F5> "::Editor::CmdRefresh $this ; break" |
|---|
| 599 | bind $data(txt) <F7> "::Editor::CmdSyntaxCheck $this ; break" |
|---|
| 600 | bind $data(txt) <F8> "::Editor::CmdDecompile $this ; break" |
|---|
| 601 | bind $data(txt) <F9> "Editor::CmdSaveCompile $this ; break" |
|---|
| 602 | bind $data(txt) <F11> "Editor::CmdCompile $this ; break" |
|---|
| 603 | bind $data(txt) <Control-KeyRelease> "::Editor::OnControlKey $this %K %k ; break" |
|---|
| 604 | bind $data(f) <Destroy> +[list ::Editor::Destroy $this %W] |
|---|
| 605 | Configure $this |
|---|
| 606 | $data(f) bind <Control-F4> "$data(f) kill; break" |
|---|
| 607 | #BalloonHelp para Sintaxis de funciones al escribir |
|---|
| 608 | bind $data(txt) <parenleft> [list ::Editor::AnalyzeCurrentText $this] |
|---|
| 609 | bind $data(txt) <parenright> [list destroy $data(txt).balloon] |
|---|
| 610 | bind $data(txt) <BackSpace> [list destroy $data(txt).balloon] |
|---|
| 611 | bind $data(txt) <Return> [list destroy $data(txt).balloon] |
|---|
| 612 | bind $data(txt) <Escape> [list destroy $data(txt).balloon] |
|---|
| 613 | bind $data(txt) <Any-Leave> [list destroy $data(txt).balloon] |
|---|
| 614 | return $this |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | #pedro-start |
|---|
| 618 | |
|---|
| 619 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 620 | proc ::Editor::AnalyzeCurrentText { this } { |
|---|
| 621 | # |
|---|
| 622 | #PURPOSE: Verifica si el texto escrito pertenece a alguna funcion definida |
|---|
| 623 | # , se muestra la sintaxis y su descripcion como BalloonHlp. |
|---|
| 624 | # Se activa cuando el usuario pulsa "(". El balloon creado se destruye |
|---|
| 625 | # con backspace o ")". Ver Binds. |
|---|
| 626 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 627 | upvar \#0 ${this}::data data |
|---|
| 628 | #Guardo posicion del cursor |
|---|
| 629 | set origen [$data(txt) index insert] |
|---|
| 630 | set def $origen |
|---|
| 631 | set anatext " " |
|---|
| 632 | #descompongo el index de origen en partes |
|---|
| 633 | set invariante [lindex [split $origen .] 0 ] |
|---|
| 634 | set variante [lindex [split $origen .] 1 ] |
|---|
| 635 | set a 1; |
|---|
| 636 | |
|---|
| 637 | # Verifico que no estemos en el index n,0 |
|---|
| 638 | if { $variante == 0 } { |
|---|
| 639 | return |
|---|
| 640 | } |
|---|
| 641 | set def 1 |
|---|
| 642 | # Recorro hacia atras a partir del insert index para obtener index de la ultima |
|---|
| 643 | # letra de la palabra inmediatamente detras del "(" |
|---|
| 644 | while { [expr ![regexp {[A-Za-z0-9]} $anatext]] && $variante > 0 && $def > 0} { |
|---|
| 645 | set def [expr $variante -$a] |
|---|
| 646 | set anatext [$data(txt) get "$invariante.$def"] |
|---|
| 647 | incr a |
|---|
| 648 | } |
|---|
| 649 | # Encuentro la letra, obtener nombre de la funcion con wordstart y wordend. |
|---|
| 650 | set ori [$data(txt) index "$invariante.$def wordstart"] |
|---|
| 651 | set end [$data(txt) index "$invariante.$def wordend"] |
|---|
| 652 | set word [$data(txt) get $ori $end] |
|---|
| 653 | |
|---|
| 654 | # procedimiento para establecer posicion del BalloonHelp bajo el Cursor |
|---|
| 655 | set lineinfox [lindex [$data(txt) dlineinfo $origen] 2] |
|---|
| 656 | # hallo el total de caracteres en la linea con la segunda parte del insert index |
|---|
| 657 | set totalchars [lindex [split [$data(txt) index "$invariante.end"] . ] 1] |
|---|
| 658 | # Necesito convertir el indice del cursor en coordenadas de pantalla [pixelx pixely] |
|---|
| 659 | # posicion del "(" MULT por largo de linea en pixeles ENTRE total de letras. |
|---|
| 660 | # más posicion relativa de la ventana = posicion en X |
|---|
| 661 | set posicionbichox [expr (round(($variante * $lineinfox) / $totalchars)) + \ |
|---|
| 662 | ([winfo rootx $data(txt)])] |
|---|
| 663 | |
|---|
| 664 | # Posicion de linea + alto de linea + posicion relativa de la ventana = Posicion Y |
|---|
| 665 | set posicionbichoy [expr ([lindex [$data(txt) dlineinfo $origen] 1]) + \ |
|---|
| 666 | ([lindex [$data(txt) dlineinfo $origen] 3]) + \ |
|---|
| 667 | ([winfo rooty $data(txt)])] |
|---|
| 668 | |
|---|
| 669 | # Ejecuto un BalloonHlp usando los 3 ultimos parametros opcionales. |
|---|
| 670 | ::Editor::BalloonHlp $this $data(txt) $word 1 $posicionbichox $posicionbichoy 1 |
|---|
| 671 | #Ayuda creada. |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | |
|---|
| 675 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 676 | proc ::Editor::BalloonHlp {this w arg {fixed 0} {posx 0} {posy 0} {special 0}} { |
|---|
| 677 | # PURPOSE: Look for Tol value of the compiled variable and display balloon text |
|---|
| 678 | # If availiable. |
|---|
| 679 | # ARGS : Instance, Window, VarName |
|---|
| 680 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 681 | upvar \#0 ${this}::data data |
|---|
| 682 | #el segundo condicional impide que se cree el balloon si existe otro |
|---|
| 683 | if { ($data(balloon) == 1 && [expr !([winfo exist $data(txt).balloon])]) || \ |
|---|
| 684 | $special == 1} { |
|---|
| 685 | #creacion del toplevel para mostrar ayuda |
|---|
| 686 | set definition [::TclInfoVar "Anything" $arg] |
|---|
| 687 | #Continuamos mostrando solo si la variable tiene algo. |
|---|
| 688 | if { [llength $definition] < 1 } { |
|---|
| 689 | return |
|---|
| 690 | } else { |
|---|
| 691 | set top $w.balloon |
|---|
| 692 | catch {destroy $top} |
|---|
| 693 | toplevel $top -bd 1 -bg black |
|---|
| 694 | wm overrideredirect $top 1 |
|---|
| 695 | #obtengo info de la variable |
|---|
| 696 | set cont [lindex $definition end-2] |
|---|
| 697 | set desc [lindex $definition end] |
|---|
| 698 | set information "$arg: \n Valor: $desc \n Definicion: $cont" |
|---|
| 699 | #Crear Helpwindow |
|---|
| 700 | font create Letra1 -family "Arial" -slant roman -size 8 |
|---|
| 701 | pack [message $top.txt -aspect 10000 -bg lightyellow \ |
|---|
| 702 | -font Letra1 -text $information] |
|---|
| 703 | #Fixed 1 para invocado por text, Fixed 0 por defecto, obedece al raton. |
|---|
| 704 | if { $fixed != 1} { |
|---|
| 705 | #Si el balloon es invocado por el raton, obedecemos a posicion del raton. |
|---|
| 706 | # A partir de la posicion del raton, modificamos vars para poner el toplevel |
|---|
| 707 | # amarillo en un lugar diferente al cursor, nunca sobre el. |
|---|
| 708 | set wmx [winfo pointerx $w] |
|---|
| 709 | set wmy [winfo pointery $w] |
|---|
| 710 | incr wmx 40 |
|---|
| 711 | set wmy [expr $wmy - 40] |
|---|
| 712 | } else { |
|---|
| 713 | #Si el Balloon es invocado por el texto, obedecemos a la posicion del indice. |
|---|
| 714 | set wmx $posx |
|---|
| 715 | set wmy $posy |
|---|
| 716 | } |
|---|
| 717 | #muestro |
|---|
| 718 | wm geometry $top \ |
|---|
| 719 | [winfo reqwidth $top.txt]x[winfo reqheight $top.txt]+$wmx+$wmy |
|---|
| 720 | raise $top |
|---|
| 721 | font delete Letra1 |
|---|
| 722 | } |
|---|
| 723 | } |
|---|
| 724 | } |
|---|
| 725 | #pedro-end |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 729 | proc ::Editor::OnControlKey {this keysym keycode} { |
|---|
| 730 | # |
|---|
| 731 | # PURPOSE: Control the "Control + Key Press" |
|---|
| 732 | # |
|---|
| 733 | # PARAMETERS: this -> Instance of editor |
|---|
| 734 | # keysym -> The keysym corresponding to the event, |
|---|
| 735 | # substituted as a textual string |
|---|
| 736 | # keycode -> The keycode field from the event |
|---|
| 737 | # |
|---|
| 738 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 739 | #puts "PLATFORM: $::tcl_platform(platform)" |
|---|
| 740 | switch [string toupper $keysym] { |
|---|
| 741 | A { ::Editor::CmdOpen $this } |
|---|
| 742 | E { ::Editor::CmdSelectAll $this } |
|---|
| 743 | F { ::Editor::CmdFind $this } |
|---|
| 744 | G { ::Editor::CmdSearch $this } |
|---|
| 745 | I { ::Editor::CmdIndent $this } |
|---|
| 746 | N { ::Editor::CmdNew $this } |
|---|
| 747 | R { ::Editor::CmdReplace $this } |
|---|
| 748 | S { ::Editor::CmdSave $this } |
|---|
| 749 | T { ::Editor::CmdFont $this } |
|---|
| 750 | U { ::Editor::CmdUnIndent $this } |
|---|
| 751 | X { ::Editor::CmdCut $this } |
|---|
| 752 | Y { ::Editor::CmdRedo $this } |
|---|
| 753 | Z { ::Editor::CmdUndo $this } |
|---|
| 754 | C { if { [string equal $::tcl_platform(platform) "unix"] } { |
|---|
| 755 | ::Editor::CmdCopy $this |
|---|
| 756 | } elseif { [string equal $::tcl_platform(platform) "windows"] } { |
|---|
| 757 | switch $keysym { |
|---|
| 758 | C { |
|---|
| 759 | ::Editor::CmdCopy $this } |
|---|
| 760 | } |
|---|
| 761 | } |
|---|
| 762 | } |
|---|
| 763 | V { if { [string equal $::tcl_platform(platform) "unix"] } { |
|---|
| 764 | ::Editor::CmdPaste $this |
|---|
| 765 | } elseif { [string equal $::tcl_platform(platform) "windows"] } { |
|---|
| 766 | switch $keysym { |
|---|
| 767 | V { |
|---|
| 768 | ::Editor::CmdPaste $this } |
|---|
| 769 | } |
|---|
| 770 | } |
|---|
| 771 | } |
|---|
| 772 | } |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 777 | proc ::Editor::TracePosition {this name1 name2 op} { |
|---|
| 778 | # |
|---|
| 779 | # PURPOSE: Sets position of cursor and lines info in status bar each time var |
|---|
| 780 | # 'position' changes. |
|---|
| 781 | # |
|---|
| 782 | # PARAMETERS: |
|---|
| 783 | # this -> Instance of editor |
|---|
| 784 | # name1, name2, op -> |
|---|
| 785 | # Name1 and name2 give the name(s) for the variable being accessed: if the |
|---|
| 786 | # variable is a scalar then name1 gives the variable's name and name2 is |
|---|
| 787 | # an empty string; if the variable is an array element then name1 gives |
|---|
| 788 | # the name of the array and name2 gives the index into the array; if an |
|---|
| 789 | # entire array is being deleted and the trace was registered on the |
|---|
| 790 | # overall array, rather than a single element, then name1 gives the array |
|---|
| 791 | # name and name2 is an empty string. Name1 and name2 are not necessarily |
|---|
| 792 | # the same as the name used in the trace variable command: the upvar |
|---|
| 793 | # command allows a procedure to reference a variable under a different |
|---|
| 794 | # name. Op indicates what operation is being performed on the variable, |
|---|
| 795 | # and is one of r, w, or u. |
|---|
| 796 | # |
|---|
| 797 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 798 | upvar \#0 ${this}::data data |
|---|
| 799 | |
|---|
| 800 | set pos [split $data(position) .] |
|---|
| 801 | set text "[mc Lin]. [lindex $pos 0] [mc Col]. [lindex $pos 1]" |
|---|
| 802 | $data(sb,posi) configure -text $text |
|---|
| 803 | set pos [split [Supertext::text_index $data(txt) end] .] |
|---|
| 804 | $data(sb,nlin) configure -text "[lindex $pos 0] [mc lines]" |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 809 | proc ::Editor::TraceNameFile {this name1 name2 op} { |
|---|
| 810 | # |
|---|
| 811 | # PURPOSE: Sets edited file name each time var 'nameFile' changes. |
|---|
| 812 | # |
|---|
| 813 | # PARAMETERS: |
|---|
| 814 | # this -> Instance of editor |
|---|
| 815 | # name1, name2, op -> see above |
|---|
| 816 | # |
|---|
| 817 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 818 | upvar \#0 ${this}::data data |
|---|
| 819 | |
|---|
| 820 | if {$data(nameFile) != ""} { |
|---|
| 821 | set data(labelWindow) $data(nameFile) |
|---|
| 822 | } else { |
|---|
| 823 | set data(labelWindow) "untitled.tol" |
|---|
| 824 | } |
|---|
| 825 | $data(f) configure -title "$data(labelWindow) - [mc [list Bayes Editor]]" |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 830 | proc ::Editor::TraceSaved {this name1 name2 op} { |
|---|
| 831 | # |
|---|
| 832 | # PURPOSE: Sets saved/not saved info in status bar each time var 'isSaved' |
|---|
| 833 | # changes. |
|---|
| 834 | # |
|---|
| 835 | # PARAMETERS: |
|---|
| 836 | # this -> Instance of editor |
|---|
| 837 | # name1, name2, op -> see above |
|---|
| 838 | # |
|---|
| 839 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 840 | upvar \#0 ${this}::data data |
|---|
| 841 | |
|---|
| 842 | if $data(isSaved) { |
|---|
| 843 | $data(sb,modi) configure -text [mc "Saved"] -relief groove |
|---|
| 844 | #$data(tb,save) configure -state disabled |
|---|
| 845 | } else { |
|---|
| 846 | $data(sb,modi) configure -text [mc "Not Saved"] -relief raised |
|---|
| 847 | #$data(tb,save) configure -state normal |
|---|
| 848 | } |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 853 | proc ::Editor::TraceSelected {this name1 name2 op} { |
|---|
| 854 | # |
|---|
| 855 | # PURPOSE: Sets ??? each time var 'selected' changes. |
|---|
| 856 | # |
|---|
| 857 | # PARAMETERS: |
|---|
| 858 | # this -> Instance of editor |
|---|
| 859 | # name1, name2, op -> see above |
|---|
| 860 | # |
|---|
| 861 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 862 | upvar \#0 ${this}::data data |
|---|
| 863 | if $data(selected) { |
|---|
| 864 | # $data(tb,cut) configure -state normal |
|---|
| 865 | # $data(tb,copy) configure -state normal |
|---|
| 866 | } else { |
|---|
| 867 | # $data(tb,cut) configure -state disabled |
|---|
| 868 | # $data(tb,copy) configure -state disabled |
|---|
| 869 | } |
|---|
| 870 | } |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 874 | proc ::Editor::TraceCompiled {this name1 name2 op} { |
|---|
| 875 | # |
|---|
| 876 | # PURPOSE: Sets compiled/not compiled info in status bar each time var |
|---|
| 877 | # 'isCompiled' changes. |
|---|
| 878 | # |
|---|
| 879 | # PARAMETERS: |
|---|
| 880 | # this -> Instance of editor |
|---|
| 881 | # name1, name2, op -> see above |
|---|
| 882 | # |
|---|
| 883 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 884 | upvar \#0 ${this}::data data |
|---|
| 885 | |
|---|
| 886 | if {$data(isCompiled) eq 2} { |
|---|
| 887 | $data(sb,comp) configure -text [mc "Compiling"] -relief solid |
|---|
| 888 | $data(tb,savecom) configure -state disabled |
|---|
| 889 | $data(menu) entryconfigure 0 -state disabled |
|---|
| 890 | } else { |
|---|
| 891 | $data(tb,savecom) configure -state normal |
|---|
| 892 | $data(menu) entryconfigure 0 -state normal |
|---|
| 893 | if {$data(isCompiled) eq 1} { |
|---|
| 894 | $data(sb,comp) configure -text [mc "Compiled"] -relief groove |
|---|
| 895 | } else { |
|---|
| 896 | $data(sb,comp) configure -text [mc "Not Compiled"] -relief raised |
|---|
| 897 | } |
|---|
| 898 | } |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 904 | proc ::Editor::TraceUndo {this name1 name2 op} { |
|---|
| 905 | # |
|---|
| 906 | # PURPOSE: Enables/disables undo button in toolbar each time value of undo |
|---|
| 907 | # index changes. (see supertext.tcl) |
|---|
| 908 | # |
|---|
| 909 | # PARAMETERS: |
|---|
| 910 | # this -> Instance of editor |
|---|
| 911 | # name1, name2, op -> see above |
|---|
| 912 | # |
|---|
| 913 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 914 | upvar \#0 ${this}::data data |
|---|
| 915 | #if {[llength $Supertext::undo($data(txt,supertext))]} |
|---|
| 916 | if { $::Supertext::undoIndex($data(txt,supertext)) != -1 } { |
|---|
| 917 | # $data(tb,undo) configure -state normal |
|---|
| 918 | } else { |
|---|
| 919 | # $data(tb,undo) configure -state disabled |
|---|
| 920 | } |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | proc ::Editor::InsertText {this new_text {pos end} } { |
|---|
| 924 | upvar \#0 ${this}::data data |
|---|
| 925 | $data(txt) insert $pos $new_text |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | proc ::Editor::GetText {this} { |
|---|
| 929 | upvar \#0 ${this}::data data |
|---|
| 930 | return $data(txt,ctext) |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | proc ::Editor::PreProc {this args} { |
|---|
| 934 | upvar \#0 ${this}::data data |
|---|
| 935 | set command [lindex $args 0] |
|---|
| 936 | switch $command { |
|---|
| 937 | insert { |
|---|
| 938 | set data(isSaved) 0 |
|---|
| 939 | set data(position) [Supertext::text_index $data(txt) insert] |
|---|
| 940 | } |
|---|
| 941 | delete { |
|---|
| 942 | set data(isSaved) 0 |
|---|
| 943 | set data(position) [Supertext::text_index $data(txt) insert] |
|---|
| 944 | } |
|---|
| 945 | tag { |
|---|
| 946 | if {[string equal [lindex $args 2] "sel"]} { |
|---|
| 947 | switch [lindex $args 1] { |
|---|
| 948 | add {set data(selected) 1} |
|---|
| 949 | remove {set data(selected) 0} |
|---|
| 950 | } |
|---|
| 951 | } |
|---|
| 952 | } |
|---|
| 953 | mark { |
|---|
| 954 | if {[string equal [lindex $args 2] "anchor"]} { |
|---|
| 955 | set data(position) [Supertext::text_index $data(txt) insert] |
|---|
| 956 | } |
|---|
| 957 | } |
|---|
| 958 | see { |
|---|
| 959 | set data(position) [Supertext::text_index $data(txt) insert] |
|---|
| 960 | } |
|---|
| 961 | undo { |
|---|
| 962 | set data(position) [Supertext::text_index $data(txt) insert] |
|---|
| 963 | } |
|---|
| 964 | } |
|---|
| 965 | #Tolcon_Trace $args |
|---|
| 966 | } |
|---|
| 967 | |
|---|
| 968 | |
|---|
| 969 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 970 | # File management commands (new, open, save, save as...) |
|---|
| 971 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 972 | |
|---|
| 973 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 974 | proc ::Editor::CmdNew {this} { |
|---|
| 975 | # |
|---|
| 976 | # PURPOSE: Cleans editor to edit a new white document |
|---|
| 977 | # |
|---|
| 978 | # PARAMETERS: |
|---|
| 979 | # this -> Instance of editor |
|---|
| 980 | # |
|---|
| 981 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 982 | upvar \#0 ${this}::data data |
|---|
| 983 | |
|---|
| 984 | if [string equal [CheckOpen $this] "cancel"] return |
|---|
| 985 | $data(txt) delete 1.0 end |
|---|
| 986 | InitState $this new |
|---|
| 987 | InsertFileHeader $this |
|---|
| 988 | } |
|---|
| 989 | |
|---|
| 990 | |
|---|
| 991 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 992 | proc ::Editor::UpdateListEdited {path} { |
|---|
| 993 | # |
|---|
| 994 | # PURPOSE: Updates list of last edited files adding a new file path. |
|---|
| 995 | # |
|---|
| 996 | # PARAMETERS: |
|---|
| 997 | # path -> path of the last edited file |
|---|
| 998 | # |
|---|
| 999 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1000 | variable options |
|---|
| 1001 | # guardamos el ultimo directorio abierto |
|---|
| 1002 | set options(lastDir) [file dirname $path] |
|---|
| 1003 | if { [set idx [lsearch $options(edited) $path]] == -1 } { |
|---|
| 1004 | set options(edited) [linsert $options(edited) 0 $path] |
|---|
| 1005 | } else { |
|---|
| 1006 | set ll "" |
|---|
| 1007 | lappend ll $path |
|---|
| 1008 | set i 0 |
|---|
| 1009 | foreach f $options(edited) { |
|---|
| 1010 | if {$i != $idx} { |
|---|
| 1011 | lappend ll $f |
|---|
| 1012 | } |
|---|
| 1013 | incr i |
|---|
| 1014 | } |
|---|
| 1015 | set options(edited) $ll |
|---|
| 1016 | } |
|---|
| 1017 | set options(edited) [lrange $options(edited) 0 [expr $options(numEdited)-1]] |
|---|
| 1018 | } |
|---|
| 1019 | |
|---|
| 1020 | |
|---|
| 1021 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1022 | proc ::Editor::CmdOpen {{this ""}} { |
|---|
| 1023 | # |
|---|
| 1024 | # PURPOSE: Asks for a file path and if it's given opens it into the editor |
|---|
| 1025 | # window. |
|---|
| 1026 | # |
|---|
| 1027 | # PARAMETERS: |
|---|
| 1028 | # this -> Instance of editor |
|---|
| 1029 | # |
|---|
| 1030 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1031 | variable options |
|---|
| 1032 | variable typelist |
|---|
| 1033 | variable defExt |
|---|
| 1034 | |
|---|
| 1035 | if {$this == ""} { |
|---|
| 1036 | set parent . |
|---|
| 1037 | } else { |
|---|
| 1038 | upvar \#0 ${this}::data data |
|---|
| 1039 | set parent $data(txt) |
|---|
| 1040 | if [string equal [CheckOpen $this] "cancel"] return |
|---|
| 1041 | } |
|---|
| 1042 | |
|---|
| 1043 | set path [tk_getOpenFile -title [mc "Open"] \ |
|---|
| 1044 | -parent $parent -initialdir $options(lastDir) \ |
|---|
| 1045 | -defaultextension $defExt -filetypes $typelist] |
|---|
| 1046 | |
|---|
| 1047 | if {$path != ""} { |
|---|
| 1048 | # abrimos solo si no esta ya abierto |
|---|
| 1049 | foreach ins [namespace children ::Editor] { |
|---|
| 1050 | upvar \#0 ${ins}::data data |
|---|
| 1051 | if {[string equal $data(nameFile) $path]} { |
|---|
| 1052 | $data(f) raise |
|---|
| 1053 | set resp [tk_messageBox -type ok -icon warning \ |
|---|
| 1054 | -message [mc "The file is already opened!"] ] |
|---|
| 1055 | return |
|---|
| 1056 | } |
|---|
| 1057 | } |
|---|
| 1058 | if {$this == ""} { |
|---|
| 1059 | set this [New $path] |
|---|
| 1060 | } |
|---|
| 1061 | GetFromFile $this $path |
|---|
| 1062 | } |
|---|
| 1063 | } |
|---|
| 1064 | |
|---|
| 1065 | |
|---|
| 1066 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1067 | proc ::Editor::GetFromFile {this path {run 0}} { |
|---|
| 1068 | # |
|---|
| 1069 | # PURPOSE: Loads a file into the editor window. |
|---|
| 1070 | # |
|---|
| 1071 | # PARAMETERS: |
|---|
| 1072 | # this -> Instance of editor |
|---|
| 1073 | # path -> file's path |
|---|
| 1074 | # |
|---|
| 1075 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1076 | upvar \#0 ${this}::data data |
|---|
| 1077 | |
|---|
| 1078 | $data(txt) delete 1.0 end |
|---|
| 1079 | if [::BayesText::Open $data(txt) $path] { |
|---|
| 1080 | set data(nameFile) $path |
|---|
| 1081 | set data(mTime) [file mtime $path] |
|---|
| 1082 | UpdateListEdited $path |
|---|
| 1083 | # Guardamos en el ini por si se cae el interface para que guarde |
|---|
| 1084 | # la lista de archivos recientes |
|---|
| 1085 | WriteIni $this |
|---|
| 1086 | } else { |
|---|
| 1087 | set data(nameFile) "" |
|---|
| 1088 | } |
|---|
| 1089 | $data(f) raise |
|---|
| 1090 | InitState $this open |
|---|
| 1091 | tk::TextSetCursor $data(txt) 1.0 |
|---|
| 1092 | if { $run } { |
|---|
| 1093 | CmdSaveCompile $this |
|---|
| 1094 | } |
|---|
| 1095 | } |
|---|
| 1096 | |
|---|
| 1097 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1098 | proc ::Editor::CheckAll {} { |
|---|
| 1099 | # |
|---|
| 1100 | # PURPOSE: Checks for files opened if anyone has changed and asks for saving. |
|---|
| 1101 | # |
|---|
| 1102 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1103 | foreach ins [namespace children ::Editor] { |
|---|
| 1104 | if {[CheckOpen $ins] eq "cancel"} { |
|---|
| 1105 | return cancel |
|---|
| 1106 | } |
|---|
| 1107 | } |
|---|
| 1108 | } |
|---|
| 1109 | |
|---|
| 1110 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1111 | proc ::Editor::CheckOpen {this {type "yesnocancel"}} { |
|---|
| 1112 | # |
|---|
| 1113 | # PURPOSE: Checks if a file has changed and asks for saving. |
|---|
| 1114 | # |
|---|
| 1115 | # PARAMETERS: |
|---|
| 1116 | # this -> Instance of editor |
|---|
| 1117 | # type -> type of messageBox to ask. (yesnocancel by default) |
|---|
| 1118 | # |
|---|
| 1119 | # RETURN: Returns user answer for saving. |
|---|
| 1120 | # |
|---|
| 1121 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1122 | upvar \#0 ${this}::data data |
|---|
| 1123 | |
|---|
| 1124 | # comprobamos si necesita ser guardado |
|---|
| 1125 | if { !$data(isSaved)} { |
|---|
| 1126 | if {$data(nameFile) != ""} { |
|---|
| 1127 | set name $data(nameFile) |
|---|
| 1128 | } else { |
|---|
| 1129 | set name "untitled.tol" |
|---|
| 1130 | } |
|---|
| 1131 | # preguntamos por conformidad |
|---|
| 1132 | set parent $data(txt) |
|---|
| 1133 | set rq [tk_messageBox -type $type -icon warning -title [mc "Warning"]\ |
|---|
| 1134 | -parent $parent -message "[mc "File %1\$s has changed!" $name].\n\ |
|---|
| 1135 | [mc "Do you want to save changes?"]"] |
|---|
| 1136 | switch -exact $rq { |
|---|
| 1137 | yes { |
|---|
| 1138 | if {$data(nameFile) != "" } { |
|---|
| 1139 | FileSave $this $data(nameFile) |
|---|
| 1140 | set data(mTime) [file mtime $data(nameFile)] |
|---|
| 1141 | } else { |
|---|
| 1142 | CmdSaveAs $this $data(nameFile) |
|---|
| 1143 | set data(mTime) [file mtime $data(nameFile)] |
|---|
| 1144 | } |
|---|
| 1145 | } |
|---|
| 1146 | cancel {return cancel} |
|---|
| 1147 | default {return ok} |
|---|
| 1148 | } |
|---|
| 1149 | } |
|---|
| 1150 | return ok |
|---|
| 1151 | } |
|---|
| 1152 | |
|---|
| 1153 | |
|---|
| 1154 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1155 | proc ::Editor::CmdSave {this} { |
|---|
| 1156 | # |
|---|
| 1157 | # PURPOSE: Saves text actually opened in the editor. If doesn't have a name, |
|---|
| 1158 | # asks for ti (CmdSaveAs). |
|---|
| 1159 | # |
|---|
| 1160 | # PARAMETERS: |
|---|
| 1161 | # this -> Instance of editor |
|---|
| 1162 | # |
|---|
| 1163 | # RETURN: Returns 1 if file has been saved correctly or 0 if not. |
|---|
| 1164 | # |
|---|
| 1165 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1166 | upvar \#0 ${this}::data data |
|---|
| 1167 | |
|---|
| 1168 | if {$data(nameFile) == ""} { |
|---|
| 1169 | set ok [CmdSaveAs $this] |
|---|
| 1170 | } else { |
|---|
| 1171 | if { $data(mTime) eq [file mtime $data(nameFile)] } { |
|---|
| 1172 | set ok [FileSave $this $data(nameFile)] |
|---|
| 1173 | set data(mTime) [file mtime $data(nameFile)] |
|---|
| 1174 | } else { |
|---|
| 1175 | set parent $data(txt) |
|---|
| 1176 | set msg "[mc File] $data(nameFile) [mc {has been changed externally!}] \ |
|---|
| 1177 | \n[mc {Do you want to rewrite it and save new changes?}]" |
|---|
| 1178 | set rq [tk_messageBox -type okcancel -icon warning -title [mc "Warning"]\ |
|---|
| 1179 | -parent $parent -message $msg] |
|---|
| 1180 | set ok -1 |
|---|
| 1181 | switch -exact $rq { |
|---|
| 1182 | ok { |
|---|
| 1183 | set ok [FileSave $this $data(nameFile)] |
|---|
| 1184 | # updates the modification time |
|---|
| 1185 | set data(mTime) [file mtime $data(nameFile)] |
|---|
| 1186 | } |
|---|
| 1187 | } |
|---|
| 1188 | } |
|---|
| 1189 | } |
|---|
| 1190 | return $ok |
|---|
| 1191 | } |
|---|
| 1192 | |
|---|
| 1193 | |
|---|
| 1194 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1195 | proc ::Editor::CmdSaveAs {this {nf ""}} { |
|---|
| 1196 | # |
|---|
| 1197 | # PURPOSE: Saves text actually opened in editor asking for the user to select |
|---|
| 1198 | # a file to save it. |
|---|
| 1199 | # |
|---|
| 1200 | # PARAMETERS: |
|---|
| 1201 | # this -> Instance of editor |
|---|
| 1202 | # nf -> name of file proposed |
|---|
| 1203 | # |
|---|
| 1204 | # RETURN: Returns 1 if file has been saved correctly or 0 if not. |
|---|
| 1205 | # |
|---|
| 1206 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1207 | variable options |
|---|
| 1208 | variable typelist |
|---|
| 1209 | variable defExt |
|---|
| 1210 | upvar \#0 ${this}::data data |
|---|
| 1211 | |
|---|
| 1212 | if {$nf == ""} { |
|---|
| 1213 | set dir $options(lastDir) |
|---|
| 1214 | set fil "" |
|---|
| 1215 | } else { |
|---|
| 1216 | set dir "[file dirname $nf]" |
|---|
| 1217 | set fil "[file tail $nf]" |
|---|
| 1218 | } |
|---|
| 1219 | set path [tk_getSaveFile -title [mc "Save as"] -initialdir $dir \ |
|---|
| 1220 | -initialfile $fil -parent $data(txt) \ |
|---|
| 1221 | -defaultextension $defExt -filetypes $typelist] |
|---|
| 1222 | if {![string equal $path ""] } { |
|---|
| 1223 | set ok [FileSave $this $path] |
|---|
| 1224 | set data(mTime) [file mtime $data(nameFile)] |
|---|
| 1225 | } else { |
|---|
| 1226 | set ok 0 |
|---|
| 1227 | } |
|---|
| 1228 | return $ok |
|---|
| 1229 | } |
|---|
| 1230 | |
|---|
| 1231 | |
|---|
| 1232 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1233 | proc ::Editor::FileSave { this path } { |
|---|
| 1234 | # |
|---|
| 1235 | # PURPOSE: Saves text actually opened in editor in a text file. |
|---|
| 1236 | # |
|---|
| 1237 | # PARAMETERS: |
|---|
| 1238 | # this -> Instance of editor |
|---|
| 1239 | # path -> name of file |
|---|
| 1240 | # |
|---|
| 1241 | # RETURN: Returns 1 if file has been saved correctly or 0 if not. |
|---|
| 1242 | # |
|---|
| 1243 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1244 | variable options |
|---|
| 1245 | upvar \#0 ${this}::data data |
|---|
| 1246 | |
|---|
| 1247 | if [::BayesText::Save $data(txt) $path] { |
|---|
| 1248 | set data(nameFile) $path |
|---|
| 1249 | InitState $this save |
|---|
| 1250 | # guardamos el ultimo directorio utilizado |
|---|
| 1251 | set options(lastDir) [file dirname $path] |
|---|
| 1252 | UpdateListEdited $path |
|---|
| 1253 | set ok 1 |
|---|
| 1254 | } else { |
|---|
| 1255 | set ok 0 |
|---|
| 1256 | } |
|---|
| 1257 | return $ok |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1261 | # Comandos de edición (deshacer, cortar, copiar, pegar, buscar, remplazar,...) |
|---|
| 1262 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1263 | proc ::Editor::CmdUndo {this} { |
|---|
| 1264 | upvar \#0 ${this}::data data |
|---|
| 1265 | $data(txt) undo |
|---|
| 1266 | } |
|---|
| 1267 | |
|---|
| 1268 | proc ::Editor::CmdRedo {this} { |
|---|
| 1269 | upvar \#0 ${this}::data data |
|---|
| 1270 | # $data(txt) redo |
|---|
| 1271 | Tolcon_Trace "---------------------------" |
|---|
| 1272 | } |
|---|
| 1273 | |
|---|
| 1274 | proc ::Editor::CmdCut {this} { |
|---|
| 1275 | upvar \#0 ${this}::data data |
|---|
| 1276 | ::BayesText::Cut $data(txt) |
|---|
| 1277 | } |
|---|
| 1278 | |
|---|
| 1279 | proc ::Editor::CmdCopy {this} { |
|---|
| 1280 | upvar \#0 ${this}::data data |
|---|
| 1281 | ::BayesText::Copy $data(txt) |
|---|
| 1282 | } |
|---|
| 1283 | |
|---|
| 1284 | proc ::Editor::CmdPaste {this} { |
|---|
| 1285 | upvar \#0 ${this}::data data |
|---|
| 1286 | ::BayesText::Paste $data(txt) |
|---|
| 1287 | } |
|---|
| 1288 | |
|---|
| 1289 | proc ::Editor::CmdSelectAll {this} { |
|---|
| 1290 | upvar \#0 ${this}::data data |
|---|
| 1291 | ::BayesText::SelectAll $data(txt) |
|---|
| 1292 | } |
|---|
| 1293 | |
|---|
| 1294 | proc ::Editor::CmdHelpEditor {this} { |
|---|
| 1295 | upvar \#0 ${this}::data data |
|---|
| 1296 | ShowHelp Tb4Eda |
|---|
| 1297 | } |
|---|
| 1298 | |
|---|
| 1299 | proc ::Editor::CmdFind {this} { |
|---|
| 1300 | upvar \#0 ${this}::data data |
|---|
| 1301 | ::BayesText::FindShow $data(txt,ctext) |
|---|
| 1302 | } |
|---|
| 1303 | |
|---|
| 1304 | proc ::Editor::CmdSearch {this} { |
|---|
| 1305 | upvar \#0 ${this}::data data |
|---|
| 1306 | :::BayesText::SearchShow $data(txt) |
|---|
| 1307 | } |
|---|
| 1308 | |
|---|
| 1309 | proc ::Editor::CmdFindNext {this {txt ""}} { |
|---|
| 1310 | upvar \#0 ${this}::data data |
|---|
| 1311 | eval ::BayesText::FindShow $data(txt,ctext) 1 {$txt} |
|---|
| 1312 | } |
|---|
| 1313 | |
|---|
| 1314 | proc ::Editor::CmdReplace {this} { |
|---|
| 1315 | upvar \#0 ${this}::data data |
|---|
| 1316 | ::BayesText::ReplaceShow $data(txt,ctext) |
|---|
| 1317 | } |
|---|
| 1318 | |
|---|
| 1319 | proc ::Editor::CmdIndent {this} { |
|---|
| 1320 | upvar \#0 ${this}::data data |
|---|
| 1321 | variable options |
|---|
| 1322 | ::BayesText::Indent $data(txt,ctext) $options(charsIndent) |
|---|
| 1323 | } |
|---|
| 1324 | |
|---|
| 1325 | proc ::Editor::CmdUnIndent {this} { |
|---|
| 1326 | upvar \#0 ${this}::data data |
|---|
| 1327 | variable options |
|---|
| 1328 | ::BayesText::UnIndent $data(txt,ctext) $options(charsIndent) |
|---|
| 1329 | } |
|---|
| 1330 | |
|---|
| 1331 | |
|---|
| 1332 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1333 | # Comandos |
|---|
| 1334 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1335 | proc ::Editor::CmdFont {this} { |
|---|
| 1336 | variable options |
|---|
| 1337 | global toltk_options |
|---|
| 1338 | upvar \#0 ${this}::data data |
|---|
| 1339 | set fnt [::BayesText::FontChange $data(txt)] |
|---|
| 1340 | if {$fnt != ""} { |
|---|
| 1341 | set options(font) $fnt |
|---|
| 1342 | font configure ctfnBold -family [lindex $fnt 0] -size [lindex $fnt 1] |
|---|
| 1343 | font configure ctfnNormal -family [lindex $fnt 0] -size [lindex $fnt 1] |
|---|
| 1344 | UpdateMarkPos $this [winfo height $data(txt)] |
|---|
| 1345 | } |
|---|
| 1346 | } |
|---|
| 1347 | |
|---|
| 1348 | proc ::Editor::CmdPrint {this} { |
|---|
| 1349 | upvar \#0 ${this}::data data |
|---|
| 1350 | global tcl_platform |
|---|
| 1351 | if { [string equal $tcl_platform(platform) "windows"] } { |
|---|
| 1352 | #int PrintCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) |
|---|
| 1353 | # printer open |
|---|
| 1354 | # printer styledialog |
|---|
| 1355 | # printer jobdialog |
|---|
| 1356 | # puts "print from [printer getattr firstpage] to [printer getattr lastpage]" |
|---|
| 1357 | # printer opendoc |
|---|
| 1358 | # printer openpage |
|---|
| 1359 | # printer test ; # funcion que usa para imprimir |
|---|
| 1360 | # printer text [$data(txt) get 1.0 end] |
|---|
| 1361 | # printer closepage |
|---|
| 1362 | # printer closedoc |
|---|
| 1363 | # printer close |
|---|
| 1364 | } |
|---|
| 1365 | } |
|---|
| 1366 | |
|---|
| 1367 | proc ::Editor::CmdSaveCompile {this} { |
|---|
| 1368 | upvar \#0 ${this}::data data |
|---|
| 1369 | |
|---|
| 1370 | #Si se está compilando no hago nada |
|---|
| 1371 | if {$data(isCompiled) eq 2} { return } |
|---|
| 1372 | set ok [CmdSave $this] |
|---|
| 1373 | if {$ok} { |
|---|
| 1374 | CmdCompileFile $this |
|---|
| 1375 | } |
|---|
| 1376 | } |
|---|
| 1377 | |
|---|
| 1378 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1379 | proc ::Editor::CmdCompileFile {this} { |
|---|
| 1380 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1381 | upvar \#0 ${this}::data data |
|---|
| 1382 | #Si se está compilando no hago nada |
|---|
| 1383 | if {$data(isCompiled) eq 2} { return } |
|---|
| 1384 | $data(tb,balloon) configure -state disabled |
|---|
| 1385 | #set check [::BayesText::TolFileSyntaxCheck $data(nameFile)] |
|---|
| 1386 | set check 1 |
|---|
| 1387 | if {$check} { |
|---|
| 1388 | set data(isCompiled) 2 |
|---|
| 1389 | ::TolConsole::Include $data(nameFile) |
|---|
| 1390 | set data(isCompiled) 1 |
|---|
| 1391 | |
|---|
| 1392 | #pedro-start |
|---|
| 1393 | # Mapear contenido de texto de la instancia y generar ayudas dinamicas |
|---|
| 1394 | # Puede tomar entre 5 y 10 segundos |
|---|
| 1395 | #::Editor::VariableMap $this |
|---|
| 1396 | set data(balloon) 1 |
|---|
| 1397 | ::Editor::CmdBalloon $this |
|---|
| 1398 | update idletasks |
|---|
| 1399 | #pedro-fin |
|---|
| 1400 | |
|---|
| 1401 | } else { |
|---|
| 1402 | # hay errores |
|---|
| 1403 | tk_messageBox -type ok -icon warning -title [mc Editor] -parent $data(txt) \ |
|---|
| 1404 | -message "[mc {Syntax errors in file}]\n\ |
|---|
| 1405 | [mc {Look over output window}]" |
|---|
| 1406 | } |
|---|
| 1407 | } |
|---|
| 1408 | |
|---|
| 1409 | #pedro-start |
|---|
| 1410 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1411 | proc ::Editor::wordindexes {s} { |
|---|
| 1412 | # PURPOSE: Divide un texto en palabras, devuelve los indices de inicio y final de |
|---|
| 1413 | # cada palabra. |
|---|
| 1414 | # Subtract whole words from a paragraph, returns a pair of index values |
|---|
| 1415 | # indicating where the word starts and where it ends. |
|---|
| 1416 | # |
|---|
| 1417 | # ARGS: user defined text widget |
|---|
| 1418 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1419 | set i 0 |
|---|
| 1420 | set res {} |
|---|
| 1421 | foreach c [split $s ""] { |
|---|
| 1422 | if {$c!=" " && $i==[string wordstart $s $i] && [regexp {[A-Za-z]} $c]} { |
|---|
| 1423 | lappend res $i [string wordend $s $i] |
|---|
| 1424 | } |
|---|
| 1425 | incr i |
|---|
| 1426 | } |
|---|
| 1427 | set res |
|---|
| 1428 | } |
|---|
| 1429 | |
|---|
| 1430 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1431 | proc ::Editor::VariableMap {this} { |
|---|
| 1432 | # PURPOSE: Creates a tag inside the editor instance for each word in the tol text |
|---|
| 1433 | # excluding comment lines, virtually fragmenting the editor window in |
|---|
| 1434 | # about 6000 - 15000 pieces, depends on the amount of words. |
|---|
| 1435 | # Bind two mouse events to each tag created using <Enter> and <Leave>, |
|---|
| 1436 | # this way we call the process BalloonHlp to display the help text. |
|---|
| 1437 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1438 | # Creamos un tag por cada palabra que se encuentre dentro del texto tol |
|---|
| 1439 | # excluyendo las lineas comentadas. A cada rango encontrado se le |
|---|
| 1440 | # hace un Bind a dos eventos del raton; <enter> y <leave> para entonces |
|---|
| 1441 | # llamar a BalloonHlp y mostrar la ayuda. |
|---|
| 1442 | # |
|---|
| 1443 | # ARGS: Instance of Editor / Instancia del Editor |
|---|
| 1444 | # |
|---|
| 1445 | # |
|---|
| 1446 | # TODO: 1) Tol is marvelous, did you know you can actually create 2 variables |
|---|
| 1447 | # with identical names differing only in the grammar type?.. example.. |
|---|
| 1448 | # Real a1 = 2; |
|---|
| 1449 | # Set a1 = SetOfText("",""); |
|---|
| 1450 | # (This will create 2 separate variables with the same name.. amazing huh?) |
|---|
| 1451 | # This is PERFECLTY possible in our amazing language, wich SUCKS for |
|---|
| 1452 | # the purpuse of this procedure... that is, because analyzed text is |
|---|
| 1453 | # arbitrary. With no reading rules, i can't really determine the |
|---|
| 1454 | # variable type before calling BalloonHlp. If two variables happen to |
|---|
| 1455 | # have the same name, the ::TclInfoVar loop function will catch the info |
|---|
| 1456 | # on the last valid grammar type in the checklist (See Editor::BalloonHlp |
|---|
| 1457 | # for more details). |
|---|
| 1458 | # |
|---|
| 1459 | # The idea would be to determine the grammar type before calling BalloonHlp. |
|---|
| 1460 | # I ain't genious enought to take it that far out.... yet. :-D |
|---|
| 1461 | # |
|---|
| 1462 | # 2) I managed to exclude comment lines from being parsed as valid tags. |
|---|
| 1463 | # If you can manage to exclude text or quote delimited expressions |
|---|
| 1464 | # from the loop, you're my geek... and offcourse, you defenetly have |
|---|
| 1465 | # more free time than me. Good Luck. |
|---|
| 1466 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1467 | upvar \#0 ${this}::data data |
|---|
| 1468 | # Luego de compilar, obtengo la lista de variables creadas. |
|---|
| 1469 | # "const" sera lista de palabras que nunca seran variables |
|---|
| 1470 | set const [list Anything Code Complex CDate CTimeSet Date Matrix Polyn \ |
|---|
| 1471 | Ratio Ration Real Serie Set Special Struct Text TimeSet PolMatrix] |
|---|
| 1472 | |
|---|
| 1473 | #Obtener lista de variables y funciones ya compiladas desde editor |
|---|
| 1474 | #controla el numero de linea mientras recorre el txt del editor |
|---|
| 1475 | set linenum 0 |
|---|
| 1476 | |
|---|
| 1477 | foreach line [split [$data(txt) get 1.0 end-1c] \n] { |
|---|
| 1478 | incr linenum 1 |
|---|
| 1479 | if { [string range $line 0 1] != "//" && [regexp "//" $line] == "0" } { |
|---|
| 1480 | foreach {from to} [::Editor::wordindexes $line] { |
|---|
| 1481 | #guardar palabra e indices |
|---|
| 1482 | set word [string range $line $from [expr $to-1]] |
|---|
| 1483 | set verif [lsearch -exact $const "$word"] |
|---|
| 1484 | if { $verif == "-1" } { |
|---|
| 1485 | #solo se crea tag si no pertenece a ningun nombre de variable |
|---|
| 1486 | set num [expr rand()] |
|---|
| 1487 | #numero aleatorio para complementar nombres de tags repetidos |
|---|
| 1488 | set to [expr $to-1] |
|---|
| 1489 | #crear tag con nombre y rango dentro del text |
|---|
| 1490 | $data(txt) tag add "$word$num" "$linenum.$from" "$linenum.$to" |
|---|
| 1491 | #Crear bind a eventos para cada tag creado |
|---|
| 1492 | $data(txt) tag bind "$word$num" <Enter> "after 1500 [list ::Editor::BalloonHlp $this $data(txt) $word]" |
|---|
| 1493 | $data(txt) tag bind "$word$num" <Leave> "destroy $data(txt).balloon" |
|---|
| 1494 | #Subrayo las variables Definidas |
|---|
| 1495 | #if { [llength [::TclInfoVar "Anything" "$word" ]] > 0 } { |
|---|
| 1496 | #$data(txt) tag configure "$word$num" -underline 1 } |
|---|
| 1497 | update idletasks |
|---|
| 1498 | } |
|---|
| 1499 | } |
|---|
| 1500 | } |
|---|
| 1501 | } |
|---|
| 1502 | # - fin |
|---|
| 1503 | } |
|---|
| 1504 | |
|---|
| 1505 | |
|---|
| 1506 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1507 | proc ::Editor::CmdCompile {this} { |
|---|
| 1508 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1509 | upvar \#0 ${this}::data data |
|---|
| 1510 | |
|---|
| 1511 | set idxs [$data(txt) tag ranges sel] |
|---|
| 1512 | Tolcon_Trace "idxs = $idxs" |
|---|
| 1513 | # Si hay seleccion evaluo texto seleccionado, sino incluyo el archivo |
|---|
| 1514 | if [llength $idxs] { |
|---|
| 1515 | ::TolConsole::EvalExpr [$data(txt) get [lindex $idxs 0] [lindex $idxs 1]] |
|---|
| 1516 | } else { |
|---|
| 1517 | CmdSaveCompile $this |
|---|
| 1518 | } |
|---|
| 1519 | } |
|---|
| 1520 | |
|---|
| 1521 | |
|---|
| 1522 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1523 | proc ::Editor::CmdDecompile {this} { |
|---|
| 1524 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1525 | upvar \#0 ${this}::data data |
|---|
| 1526 | if {$data(isCompiled) eq 1} { |
|---|
| 1527 | ::TolInspector::DecompileFile $data(nameFile) |
|---|
| 1528 | } |
|---|
| 1529 | } |
|---|
| 1530 | |
|---|
| 1531 | |
|---|
| 1532 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1533 | proc ::Editor::CmdSyntaxCheck {this} { |
|---|
| 1534 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1535 | upvar \#0 ${this}::data data |
|---|
| 1536 | ::BayesText::TolSyntaxCheck $data(txt) [ file dir $data(nameFile) ] |
|---|
| 1537 | } |
|---|
| 1538 | |
|---|
| 1539 | |
|---|
| 1540 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1541 | proc ::Editor::CmdRefresh {this} { |
|---|
| 1542 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1543 | upvar \#0 ${this}::data data |
|---|
| 1544 | |
|---|
| 1545 | foreach tag [$data(txt) tag names] { |
|---|
| 1546 | $data(txt) tag remove $tag 1.0 end |
|---|
| 1547 | } |
|---|
| 1548 | update idletasks |
|---|
| 1549 | $data(txt) highlight 1.0 end |
|---|
| 1550 | } |
|---|
| 1551 | |
|---|
| 1552 | |
|---|
| 1553 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1554 | proc ::Editor::CmdRightMargin {this} { |
|---|
| 1555 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1556 | upvar \#0 ${this}::data data |
|---|
| 1557 | UpdateMarkPos $this [winfo height $data(txt)] |
|---|
| 1558 | } |
|---|
| 1559 | |
|---|
| 1560 | |
|---|
| 1561 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1562 | proc ::Editor::CmdOptions {this} { |
|---|
| 1563 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1564 | upvar \#0 ${this}::data data |
|---|
| 1565 | OptionsCreate $this $data(txt) |
|---|
| 1566 | } |
|---|
| 1567 | |
|---|
| 1568 | |
|---|
| 1569 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1570 | proc ::Editor::CmdBalloon {this} { |
|---|
| 1571 | # PURPOSE: Balloon Control |
|---|
| 1572 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1573 | upvar \#0 ${this}::data data |
|---|
| 1574 | |
|---|
| 1575 | if { $data(balloon) != 1 } { |
|---|
| 1576 | #Reconfigure |
|---|
| 1577 | $data(tb,balloon) configure -state disabled |
|---|
| 1578 | #Recalculate values |
|---|
| 1579 | ::Editor::VariableMap $this |
|---|
| 1580 | #flag |
|---|
| 1581 | set data(balloon) 1 |
|---|
| 1582 | #reconfigure |
|---|
| 1583 | $data(tb,balloon) configure -image [::Bitmap::get "balloon_enable"] |
|---|
| 1584 | $data(tb,balloon) configure -state normal |
|---|
| 1585 | } else { |
|---|
| 1586 | #destroy tag & binds |
|---|
| 1587 | $data(tb,balloon) configure -state disabled |
|---|
| 1588 | set tagnames [$data(txt) tag names] |
|---|
| 1589 | set limit [llength $tagnames] |
|---|
| 1590 | for {set x 6} {$x < $limit} {incr x} { |
|---|
| 1591 | $data(txt) tag delete [lindex $tagnames $x] |
|---|
| 1592 | #puts "tag eliminada" |
|---|
| 1593 | } |
|---|
| 1594 | set data(balloon) 0 |
|---|
| 1595 | $data(tb,balloon) configure -image [::Bitmap::get "balloon_disable"] |
|---|
| 1596 | $data(tb,balloon) configure -state normal |
|---|
| 1597 | } |
|---|
| 1598 | } |
|---|
| 1599 | |
|---|
| 1600 | |
|---|
| 1601 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1602 | proc ::Editor::OptionsCreate {this path} { |
|---|
| 1603 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1604 | set dialog [Dialog $path.d -title [mc "Editor Options"]\ |
|---|
| 1605 | -modal local -parent $path] |
|---|
| 1606 | wm resizable $dialog 0 0 |
|---|
| 1607 | wm protocol $dialog WM_DELETE_WINDOW [list ::Editor::OptionsDestroy $this $dialog] |
|---|
| 1608 | set w [$dialog getframe] |
|---|
| 1609 | set w_tabset [NoteBook $w.nb -tabbevelsize 8 -tabpady {2 6} -font {Arial 8}] |
|---|
| 1610 | #insertar tabset |
|---|
| 1611 | set num_i 0 |
|---|
| 1612 | foreach lab_i [list Headers Others] { |
|---|
| 1613 | $w_tabset insert $num_i $lab_i -text " [mc $lab_i] " -background \#d9d9d9 |
|---|
| 1614 | set tab_i [$w_tabset getframe $lab_i] |
|---|
| 1615 | $tab_i configure -borderwidth 2 -background \#d9d9d9 |
|---|
| 1616 | incr num_i |
|---|
| 1617 | set f$num_i [frame $tab_i.f] |
|---|
| 1618 | pack $tab_i.f -fill both -expand yes |
|---|
| 1619 | } |
|---|
| 1620 | $w_tabset raise [$w_tabset pages 0] |
|---|
| 1621 | |
|---|
| 1622 | OptionsGet $this |
|---|
| 1623 | OptionsCreateHeaders $this $f1 |
|---|
| 1624 | OptionsCreateOthers $this $f2 |
|---|
| 1625 | |
|---|
| 1626 | OptionsCheck $this |
|---|
| 1627 | |
|---|
| 1628 | set w_bbox \ |
|---|
| 1629 | [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \ |
|---|
| 1630 | -homogeneous false] |
|---|
| 1631 | $w_bbox add -text [mc "Accept"] -relief link \ |
|---|
| 1632 | -helptext [mc "OK"] \ |
|---|
| 1633 | -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \ |
|---|
| 1634 | -command [list ::Editor::OptionsOK $this $dialog] |
|---|
| 1635 | $w_bbox add -text [mc "Cancel"] -relief link \ |
|---|
| 1636 | -helptext [mc "Cancel"]\ |
|---|
| 1637 | -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \ |
|---|
| 1638 | -command [list ::Editor::OptionsDestroy $this $dialog] |
|---|
| 1639 | $w_bbox add -text [mc "Apply"] -relief link \ |
|---|
| 1640 | -helptext [mc "Apply"]\ |
|---|
| 1641 | -image [::Bitmap::get apply] -compound left -padx 5 -pady 1 \ |
|---|
| 1642 | -command [list ::Editor::OptionsDestroy $this $dialog] |
|---|
| 1643 | |
|---|
| 1644 | pack $w_bbox -fill x -expand false -side bottom |
|---|
| 1645 | $w_tabset compute_size |
|---|
| 1646 | pack $w_tabset -fill both -expand true |
|---|
| 1647 | |
|---|
| 1648 | bind $dialog <F1> "ShowHelp Tb4Eda ; break" |
|---|
| 1649 | $dialog draw |
|---|
| 1650 | } |
|---|
| 1651 | |
|---|
| 1652 | |
|---|
| 1653 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1654 | proc ::Editor::OptionsCreateHeaders {this w} { |
|---|
| 1655 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1656 | variable tmpOpt |
|---|
| 1657 | |
|---|
| 1658 | TitleFrame $w.tf1 -text [mc "Files of headers"] |
|---|
| 1659 | set f1 [$w.tf1 getframe] |
|---|
| 1660 | |
|---|
| 1661 | checkbutton $f1.chFileH -text [mc "Insert header in new files"]\ |
|---|
| 1662 | -variable ::Editor::tmpOpt(var,chFileH)\ |
|---|
| 1663 | -command [list ::Editor::OptionsCheckHeaderFileInsert $this] |
|---|
| 1664 | label $f1.lFileH -text [mc "Files Header"] |
|---|
| 1665 | set tmpOpt(widget,eFileH) [entry $f1.eFileH -width 50\ |
|---|
| 1666 | -textvariable ::Editor::tmpOpt(var,fileH)] |
|---|
| 1667 | set tmpOpt(widget,bFileH) [::Objects::ChooseFileCreate ::Editor::tmpOpt(var,fileH) $f1.bFileH] |
|---|
| 1668 | |
|---|
| 1669 | label $f1.lFuncH -text [mc "Functions Header"] |
|---|
| 1670 | entry $f1.eFuncH -width 50 -textvariable ::Editor::tmpOpt(var,funcH) |
|---|
| 1671 | ::Objects::ChooseFileCreate ::Editor::tmpOpt(var,funcH) $f1.bFuncH |
|---|
| 1672 | |
|---|
| 1673 | |
|---|
| 1674 | frame $f1.f -width 25 |
|---|
| 1675 | |
|---|
| 1676 | grid $f1.f $f1.chFileH - - -sticky nw -padx 2 |
|---|
| 1677 | grid ^ $f1.lFileH $f1.eFileH $f1.bFileH -sticky nw -padx 2 |
|---|
| 1678 | grid ^ $f1.lFuncH $f1.eFuncH $f1.bFuncH -sticky nw -padx 2 |
|---|
| 1679 | grid rowconfigure $f1 0 -weight 1 |
|---|
| 1680 | grid columnconfigure $f1 3 -weight 1 |
|---|
| 1681 | |
|---|
| 1682 | grid $w.tf1 -sticky news -padx 2 |
|---|
| 1683 | |
|---|
| 1684 | grid rowconfigure $w 1 -weight 1 |
|---|
| 1685 | grid rowconfigure $w 2 -weight 2 |
|---|
| 1686 | grid columnconfigure $w 0 -weight 1 |
|---|
| 1687 | } |
|---|
| 1688 | |
|---|
| 1689 | |
|---|
| 1690 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1691 | proc ::Editor::OptionsCreateOthers {this w} { |
|---|
| 1692 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1693 | variable tmpOpt |
|---|
| 1694 | |
|---|
| 1695 | TitleFrame $w.tf1 -text [mc "General Options"] |
|---|
| 1696 | set f1 [$w.tf1 getframe] |
|---|
| 1697 | |
|---|
| 1698 | checkbutton $f1.chEdited -text [mc "Files edited recently"]\ |
|---|
| 1699 | -variable ::Editor::tmpOpt(var,chEdited)\ |
|---|
| 1700 | -command [list ::Editor::OptionsCheckEdited $this] |
|---|
| 1701 | |
|---|
| 1702 | set tmpOpt(widget,edited) [SpinBox $f1.sbEdited -justify right -width 4 \ |
|---|
| 1703 | -editable 0 -range {0 40} \ |
|---|
| 1704 | -textvariable ::Editor::tmpOpt(var,numEdited)] |
|---|
| 1705 | label $f1.lFiles -text [mc files] |
|---|
| 1706 | |
|---|
| 1707 | checkbutton $f1.chLine -text [mc "Show line at"] \ |
|---|
| 1708 | -variable ::Editor::tmpOpt(var,chLine) |
|---|
| 1709 | SpinBox $f1.sbLinePos -justify right -width 4 \ |
|---|
| 1710 | -editable 0 -range {20 100} \ |
|---|
| 1711 | -textvariable ::Editor::tmpOpt(var,posLine) |
|---|
| 1712 | label $f1.lChars -text [mc characters] |
|---|
| 1713 | |
|---|
| 1714 | label $f1.lCharsIndent -text [mc "Characters to indent"] |
|---|
| 1715 | SpinBox $f1.sbCharsIndent -justify right -width 4 \ |
|---|
| 1716 | -editable 0 -range {1 8} \ |
|---|
| 1717 | -textvariable ::Editor::tmpOpt(var,charsIndent) |
|---|
| 1718 | |
|---|
| 1719 | frame $f1.f -width 25 |
|---|
| 1720 | |
|---|
| 1721 | grid $f1.f $f1.chEdited $f1.sbEdited $f1.lFiles -sticky nw -padx 2 |
|---|
| 1722 | grid ^ $f1.chLine $f1.sbLinePos $f1.lChars -sticky nw -padx 2 |
|---|
| 1723 | grid ^ $f1.lCharsIndent $f1.sbCharsIndent -sticky nw -padx 2 |
|---|
| 1724 | grid rowconfigure $f1 2 -weight 1 |
|---|
| 1725 | grid columnconfigure $f1 3 -weight 1 |
|---|
| 1726 | |
|---|
| 1727 | grid $w.tf1 -sticky news -padx 2 |
|---|
| 1728 | |
|---|
| 1729 | grid rowconfigure $w 1 -weight 1 |
|---|
| 1730 | grid rowconfigure $w 2 -weight 2 |
|---|
| 1731 | grid columnconfigure $w 0 -weight 1 |
|---|
| 1732 | } |
|---|
| 1733 | |
|---|
| 1734 | |
|---|
| 1735 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1736 | proc ::Editor::OptionsGet {this} { |
|---|
| 1737 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1738 | variable options |
|---|
| 1739 | variable tmpOpt |
|---|
| 1740 | set tmpOpt(var,chEdited) $options(chEdited) |
|---|
| 1741 | set tmpOpt(var,numEdited) $options(numEdited) |
|---|
| 1742 | set tmpOpt(var,chFileH) $options(chFileH) |
|---|
| 1743 | set tmpOpt(var,fileH) $options(fileH) |
|---|
| 1744 | set tmpOpt(var,funcH) $options(funcH) |
|---|
| 1745 | set tmpOpt(var,chLine) $options(chLine) |
|---|
| 1746 | set tmpOpt(var,posLine) $options(posLine) |
|---|
| 1747 | set tmpOpt(var,charsIndent) $options(charsIndent) |
|---|
| 1748 | } |
|---|
| 1749 | |
|---|
| 1750 | |
|---|
| 1751 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1752 | proc ::Editor::OptionsSet {this} { |
|---|
| 1753 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1754 | variable options |
|---|
| 1755 | variable tmpOpt |
|---|
| 1756 | |
|---|
| 1757 | regsub -all var, [array names ::Editor::tmpOpt var,*] "" optNames |
|---|
| 1758 | #Tolcon_Trace "$optNames" |
|---|
| 1759 | foreach it $optNames { |
|---|
| 1760 | set options($it) $tmpOpt(var,$it) |
|---|
| 1761 | } |
|---|
| 1762 | } |
|---|
| 1763 | |
|---|
| 1764 | |
|---|
| 1765 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1766 | proc ::Editor::OptionsCheck {this} { |
|---|
| 1767 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1768 | OptionsCheckEdited $this |
|---|
| 1769 | OptionsCheckHeaderFileInsert $this |
|---|
| 1770 | } |
|---|
| 1771 | |
|---|
| 1772 | |
|---|
| 1773 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1774 | proc ::Editor::OptionsCheckEdited {this} { |
|---|
| 1775 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1776 | variable tmpOpt |
|---|
| 1777 | if {!$tmpOpt(var,chEdited)} { |
|---|
| 1778 | $tmpOpt(widget,edited) configure -state disabled |
|---|
| 1779 | } else { |
|---|
| 1780 | $tmpOpt(widget,edited) configure -state normal |
|---|
| 1781 | } |
|---|
| 1782 | } |
|---|
| 1783 | |
|---|
| 1784 | |
|---|
| 1785 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1786 | proc ::Editor::OptionsCheckHeaderFileInsert {this} { |
|---|
| 1787 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1788 | variable tmpOpt |
|---|
| 1789 | if {!$tmpOpt(var,chFileH)} { |
|---|
| 1790 | $tmpOpt(widget,eFileH) configure -state disabled |
|---|
| 1791 | $tmpOpt(widget,bFileH) configure -state disabled |
|---|
| 1792 | } else { |
|---|
| 1793 | $tmpOpt(widget,eFileH) configure -state normal |
|---|
| 1794 | $tmpOpt(widget,bFileH) configure -state normal |
|---|
| 1795 | } |
|---|
| 1796 | } |
|---|
| 1797 | |
|---|
| 1798 | |
|---|
| 1799 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1800 | proc ::Editor::OptionsDestroy {this dialog} { |
|---|
| 1801 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1802 | variable tmpOpt |
|---|
| 1803 | array unset tmpOpt |
|---|
| 1804 | destroy $dialog |
|---|
| 1805 | } |
|---|
| 1806 | |
|---|
| 1807 | |
|---|
| 1808 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1809 | proc ::Editor::OptionsApply {this} { |
|---|
| 1810 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1811 | OptionsSet $this |
|---|
| 1812 | CmdRightMargin $this |
|---|
| 1813 | } |
|---|
| 1814 | |
|---|
| 1815 | |
|---|
| 1816 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1817 | proc ::Editor::OptionsOK {this dialog} { |
|---|
| 1818 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1819 | OptionsApply $this |
|---|
| 1820 | OptionsDestroy $this $dialog |
|---|
| 1821 | } |
|---|
| 1822 | |
|---|
| 1823 | |
|---|
| 1824 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1825 | # INIFILE |
|---|
| 1826 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1827 | |
|---|
| 1828 | |
|---|
| 1829 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1830 | proc ::Editor::ReadIni {} { |
|---|
| 1831 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1832 | variable options |
|---|
| 1833 | global toltk_options |
|---|
| 1834 | |
|---|
| 1835 | set rini ::iniFile::Read |
|---|
| 1836 | set options(chFileH) [$rini Editor insertFileH 0] |
|---|
| 1837 | set options(fileH) [$rini Editor fileH ""] |
|---|
| 1838 | set options(funcH) [$rini Editor funcH ""] |
|---|
| 1839 | set options(chEdited) [$rini Editor saveRecent 1] |
|---|
| 1840 | set options(numEdited) [$rini Editor numRecent 8] |
|---|
| 1841 | set options(edited) [$rini Editor recent {}] |
|---|
| 1842 | set options(font) [$rini Editor font $toltk_options(fonts,Fixed)] |
|---|
| 1843 | set options(lastDir) [$rini Editor lastDir ""] |
|---|
| 1844 | set options(chLine) [$rini Editor chLine 1] |
|---|
| 1845 | set options(posLine) [$rini Editor posLine 78] |
|---|
| 1846 | # ticket https://www.tol-project.org/ticket/1168 |
|---|
| 1847 | set cindent [$rini Editor charsIndent -1] |
|---|
| 1848 | if { $cindent == -1 } { |
|---|
| 1849 | # no aparecia la clave charsIndent, pregunto por la vieja |
|---|
| 1850 | set options(charsIndent) [$rini Editor charsIdent 2] |
|---|
| 1851 | } else { |
|---|
| 1852 | # aparecia la clave, hay que pasar al nombre Indent |
|---|
| 1853 | set options(charsIndent) $cindent |
|---|
| 1854 | } |
|---|
| 1855 | } |
|---|
| 1856 | |
|---|
| 1857 | |
|---|
| 1858 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1859 | proc ::Editor::WriteIni {this} { |
|---|
| 1860 | # |
|---|
| 1861 | # PURPOSE: Write common Editor options to .ini file |
|---|
| 1862 | # |
|---|
| 1863 | # PARAMETERS: |
|---|
| 1864 | # this -> Instance of editor |
|---|
| 1865 | # |
|---|
| 1866 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1867 | variable options |
|---|
| 1868 | upvar \#0 ${this}::data data |
|---|
| 1869 | set wini ::iniFile::Write |
|---|
| 1870 | |
|---|
| 1871 | $wini Editor insertFileH $options(chFileH) |
|---|
| 1872 | $wini Editor fileH $options(fileH) |
|---|
| 1873 | $wini Editor funcH $options(funcH) |
|---|
| 1874 | $wini Editor saveRecent $options(chEdited) |
|---|
| 1875 | $wini Editor numRecent $options(numEdited) |
|---|
| 1876 | $wini Editor recent $options(edited) |
|---|
| 1877 | $wini Editor font $options(font) |
|---|
| 1878 | $wini Editor lastDir $options(lastDir) |
|---|
| 1879 | $wini Editor chLine $options(chLine) |
|---|
| 1880 | $wini Editor posLine $options(posLine) |
|---|
| 1881 | $wini Editor charsIndent $options(charsIndent) |
|---|
| 1882 | ::iniFile::Flush |
|---|
| 1883 | } |
|---|
| 1884 | |
|---|
| 1885 | ::Editor::ReadIni |
|---|