Not logged in
Check-in [55ef717bf9]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: * moved todo.txt to file tod_txt.tcl * improved todo.txt * program title depends on class
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 55ef717bf9e7ca3e18e69a939b62b1cf70c036cb
User & Date: ramsan 2019-10-07 13:37:38
Context
2019-10-07
18:54
improved ramtodo check-in: 4723fd7f81 user: ramsan tags: trunk
13:37
* moved todo.txt to file tod_txt.tcl * improved todo.txt * program title depends on class check-in: 55ef717bf9 user: ramsan tags: trunk
2019-10-03
18:23
* implementing todo.txt * added numeration to headers in markdown check-in: 962ac2c6ec user: ramsan tags: trunk
Changes

Changes to RamDebugger.tcl.

8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
....
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
        set after 0
    } else {
        set after 200
    }
    dict set markdown_data after_id [after $after [list RamDebugger::markdown_latex_formulae]]
}

#################################################################################
#    todo.txt
#################################################################################

proc RamDebugger::process_todo_txt_end_edit { accept_cancel } {
    variable text
    variable process_todo_txt_data
    
    $text tag remove editing $e1 $e2
    
    if { $accept_cancel eq "cancel" } {
        lassign [$text tag range editing] e1 e2
        regexp {^\d+} $e1 line
        set line [lindex [dict get $process_todo_txt_data lines] [expr {$line-1}]]
        $text remove $e1 $e2
        process_todo_txt_insert_line -idx $e1 $line
    }
    $text configure -state disabled
}

proc RamDebugger::process_todo_txt_keys { args } {
    variable text
    variable last_selection
    variable last_selection_doing
    variable process_todo_txt_data

    set optional {
        { -dobreak boolean 1 }
    }
    set compulsory "what key"
    parse_args $optional $compulsory $args
    
    if { [$text cget -state] ne "disabled" } {
        lassign [$text tag range editing] e1 e2
        if { $e1 ne "" } {
            set idx [$text index insert]
            if { [$text compare $idx < $e1] || [$text compare $idx > $e2] } {
                process_todo_txt_end_edit cancel
            }
        }
    }
    
    switch $what {
        Control-KeyPress {
            return
        }
        BR1 {
            set idx [$text index $key]
            lassign [$text tag range sel] sel1 sel2
            if { $sel1 ne "" && [$text compare $idx >= $sel1] && [$text compare $idx <= $sel2] } {
                $text tag add sel "$sel1 linestart" "$sel2 lineend"
            } else {
                $text tag add sel "$idx linestart" "$idx lineend"
            }
            if { $dobreak } { return -code break }
        }
        Selection {
            set sel1 [lindex [$text tag range sel] 0]
            set sel2 [lindex [$text tag range sel] end]
            if { $sel1 eq "" } { return }
            set last_selectionL [list $sel1 $sel2]
            if { $last_selectionL eq [set! last_selection] } { return }
            
            if { [set! last_selection_doing] == 1 } { return }
            set last_selection_doing 1
            
            $text tag remove sel 1.0 end
            set idx1_start ""
            set idx1 $sel1
            foreach "key value idx" [$text dump -tag $sel1 $sel2] {
                if { $key eq "tagon" && $value eq "lines" } {
                    set idx1 $idx
                } elseif { $key eq "tagoff" && $value eq "lines" } {
                    $text tag add sel "$idx1 linestart" "$idx lineend"
                    set idx1 ""
                }
            }
            if { $idx1 ne "" } {
                $text tag add sel "$idx1 linestart" "$sel2 lineend"
            }
            set sel1 [lindex [$text tag range sel] 0]
            set sel2 [lindex [$text tag range sel] end]
            set last_selection [list $sel1 $sel2]
            set last_selection_doing 0
            
            if { $dobreak } { return -code break }
        }
        KeyPress - Shift-KeyPress {
            if { [$text cget -state] eq "disabled" } {
                lassign [$text tag range sel] sel1 sel2
                if { $sel1 ne "" } {
                    $text mark set insert $sel1
                }
                switch $key {
                    Up - Down {

                        if { $what eq "Shift-KeyPress" } {
                            return 
                        }
                        set idx [$text index insert]
                        while 1 {
                            if { $key eq "Up" } {
                                set idx [$text index "$idx -1l"]
                            } else {
                                set idx [$text index "$idx +1l"]
                            }
                            if { [$text compare "$idx linestart" == "1.0"] } { break }
                            if { [lsearch [$text tag names $idx] title] != -1 } { continue }
                            if { [lsearch [$text tag names $idx] lines] == -1 } {
                                break
                            }
                            if { [$text compare "$idx linestart" == "end-1l"] } {
                                set idx [$text index "$idx-1l"]
                                break
                            }
                            break
                        }
                        if { [lsearch [$text tag names $idx] lines] == -1 } {
                            if { $dobreak } { return -code break }
                            return
                        }
                        $text mark set insert $idx
                        $text tag remove sel 1.0 end
                        $text tag add sel "$idx linestart" "$idx lineend"
                        if { $dobreak } { return -code break }
                    }
                    e {
                        $text tag remove sel 1.0 end
                        $text configure -state normal
                        set idx [$text index insert]
                        $text tag add editing "$idx linestart" "$idx lineend"
                        $text tag configure editing -borderwidth 1 -background #f0f0f0
                        $text mark set insert "insert lineend"
                    }
                    f {
                        set w [dict_getd $process_todo_txt_data search_widget ""]
                        if { $w ne "" } {
                            tk::TabToWindow $w
                        }
                    }
                }
                if { $dobreak } { return -code break }
            } else {
                switch $key {
                    Up - Down {
                        process_todo_txt_end_edit accept
                        if { $dobreak } { return -code break }
                    }
                    Return {
                        process_todo_txt_end_edit accept
                        if { $dobreak } { return -code break }
                    }
                    Escape {
                        process_todo_txt_end_edit cancel
                        if { $dobreak } { return -code break }
                    }
                }
            }
        }
    }
}

proc RamDebugger::process_todo_txt_insert_line { args } {
    variable text
    
    set optional {
        { -curr_project project ""  }
        { -idx idx "end" }
        { -search string "" }
    }
    set compulsory "line"
    parse_args $optional $compulsory $args
    
    set today [clock format [clock seconds] -format "%Y-%m-%d"]
    
    lassign $line lineN completion completion_date priority \
        start_date project due_date txt
    
    if { $search ne "" && ![string match -nocase *$search* $txt] } { return "" }
    
    if { $project ne $curr_project } {
        $text insert end "\n$project\n" title
    }
    if { $completion } {
        set tag completed
    } elseif { $due_date eq "" || $due_date > $today } {
        set tag normal
    } elseif { $due_date == $today } {
        set tag today
    } else {
        set tag old
    }
    $text insert $idx "$txt\n" "$tag lines"

    return $project
}

proc RamDebugger::process_todo_txt_end {} {
    variable text

    set ipos [lsearch [bindtags $text] todo.txt]
    if { $ipos != -1 } {
        bindtags $text [lreplace [bindtags $text] $ipos $ipos]
    }
    $text configure -state normal
}

proc RamDebugger::process_todo_txt_save {} {
    variable process_todo_txt_data
    
    if { [dict_getd $process_todo_txt_data normal_edit 0] } {
        return continue
    } else {
        return break
    }
}

proc RamDebugger::process_todo_search {} {
    variable process_todo_txt_data
    variable process_todo_txt_str
    
    after cancel [dict_getd $process_todo_txt_data afterid 0]
    set a [after 200 [list RamDebugger::process_todo_txt -search $process_todo_txt_str]]
    dict set process_todo_txt_data afterid $a
}

proc RamDebugger::process_todo_txt { args } {
    variable text
    variable mainframe
    variable currentfile
    variable currentfileIsModified
    variable process_todo_txt_data
    
    set optional {
        { -search search "" }
    }
    set compulsory ""
    parse_args $optional $compulsory $args
    
    if { [lsearch [bindtags $text] todo.txt] == -1 } {
        bindtags $text [linsert [bindtags $text]  0 todo.txt]
    }
    bind todo.txt <KeyPress> [list RamDebugger::process_todo_txt_keys KeyPress %K]
    bind todo.txt <Shift-KeyPress> [list RamDebugger::process_todo_txt_keys Shift-KeyPress %K]
    bind todo.txt <Control-KeyPress> [list RamDebugger::process_todo_txt_keys Control-KeyPress %K]
    bind todo.txt <ButtonRelease-1> [list RamDebugger::process_todo_txt_keys BR1 @%x,%y]
    bind todo.txt <<Selection>> [list RamDebugger::process_todo_txt_keys Selection ""]
    
    $mainframe showtoolbar 2 1
    set f [$mainframe gettoolbar 2]
    
    if { ![winfo exists $f.l] } {
        ttk::label $f.l -text [_ "Search"]:
        ttk::combobox $f.e1 -width 30 -textvariable ::RamDebugger::process_todo_txt_str
        dict set process_todo_txt_data search_widget $f.e1
        
        bind $f.e1 <Tab> "[list focus $text]; break"
        
        # to avoid problems with paste, that sometimes pastes too to the main window
        bind $f.e1 <<Paste>> "[bind [winfo class $f.e1] <<Paste>>]; break"
        trace add variable ::RamDebugger::process_todo_txt_str write \
            "[list RamDebugger::process_todo_search];#"
        
        grid $f.l $f.e1 -sticky ew
        grid columnconfigure $f 1 -weight 0
    }
    set currentfileIsModified_save $currentfileIsModified

    if { ![dict exists $process_todo_txt_data lines] } {
        set data ""
        set on 1
        foreach "key value index" [$text dump 1.0 end] {
            switch $key {
                text {
                    if { $on } {
                        append data $value
                    }
                }
                tagon {
                    if { $value eq "title" } {
                        set on 0
                    }
                }
                tagoff {
                    if { $value eq "title" } {
                        set on 1
                    }
                }
            }
        }
        
        lassign "" lines
        set idx 1
        foreach line [split [string trim $data] \n] {
            set rest $line
            lassign "" project completion_date priority start_date due_date
            set completion 0
            if { [regexp {^\s*x\s+([-\w]+)\s*(.)} $rest {} completion_date r] } {
                set completion 1
                set rest $r
            }
            if { [regexp {^\s*\(([A-Z])\)\s+(.*)} $rest {} priority r] } {
                set rest $r
            }
            if { [regexp {^\s*(\d{4}\-\d{2}\-\d{2})\s+(.*)} $rest {} start_date r] } {
                set rest $r
            }
            regexp {(\+\w+)} $line {} project
            regexp {due:(\d{4}\-\d{2}\-\d{2})} $line {} due_date
            lappend lines [list $idx $completion $completion_date $priority $start_date \
                    $project $due_date $line]
            incr idx
        }
    } else {
        set lines [dict get $process_todo_txt_data lines]
    }
    set lines [lsort -decreasing -index 4 $lines]
    set lines [lsort -index 5 $lines]
    
    set fontbold [font actual [$text cget -font]]
    set ipos [lsearch $fontbold -weight]
    set fontbold [lreplace $fontbold $ipos+1 $ipos+1 bold]
    
    $text tag configure title -font $fontbold
    $text tag configure lines -lmargin1 10
    $text tag configure completed -foreground grey -overstrike 1
    $text tag configure today -foreground green
    $text tag configure old -foreground red
      
    $text configure -state normal
    $text delete 1.0 end
    set projectG "--------"
    foreach line $lines {
        set projectG [process_todo_txt_insert_line -curr_project \
                $projectG -search $search $line]
    }
    $text tag add sel 1.0 "1.0 lineend"
    $text mark set insert 1.0
    $text configure -state disabled
    process_todo_txt_keys -dobreak 0 KeyPress Down
    
    if { $currentfileIsModified && !$currentfileIsModified_save } {
        MarkAsNotModified
    }
    dict set process_todo_txt_data lines $lines
}

#################################################################################
#    AddFileTypeMenu
#################################################################################

proc RamDebugger::AddFileTypeMenu_do { descmenu_new } {
    variable mainframe
    
................................................................................
}

proc RamDebugger::set_title { title } {
    variable iswince
    variable text
    
    if { !$iswince } {
        wm title [winfo toplevel $text] "RamDebugger      $title"
    } else {
        wm title [winfo toplevel $text] "R - $title"
    }
}

proc RamDebugger::update_wrap_indicators_idle {} {
    variable update_wrap_indicators_after







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







8894
8895
8896
8897
8898
8899
8900



























































































































































































































































































































































8901
8902
8903
8904
8905
8906
8907
....
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
        set after 0
    } else {
        set after 200
    }
    dict set markdown_data after_id [after $after [list RamDebugger::markdown_latex_formulae]]
}




























































































































































































































































































































































#################################################################################
#    AddFileTypeMenu
#################################################################################

proc RamDebugger::AddFileTypeMenu_do { descmenu_new } {
    variable mainframe
    
................................................................................
}

proc RamDebugger::set_title { title } {
    variable iswince
    variable text
    
    if { !$iswince } {
        wm title [winfo toplevel $text] "$::className      $title"
    } else {
        wm title [winfo toplevel $text] "R - $title"
    }
}

proc RamDebugger::update_wrap_indicators_idle {} {
    variable update_wrap_indicators_after

Changes to scripts/tclIndex.

169
170
171
172
173
174
175

176
177
178
179
180
181
182
...
218
219
220
221
222
223
224

225
226
227
228
229
230
231
...
290
291
292
293
294
295
296


297
298
299
300
301
302
303
304
305
306
307





308
309
310
311
312
313
314
...
332
333
334
335
336
337
338















339
340
341
342
343
344
345
346
347
348
349
350
set auto_index(::RamDebugger::ToggleTransientWin) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::AddAlwaysOnTopFlag) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::InvokeAllDisplayVarWindows) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindow_contextual) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindow_contextual_do) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::entry_PSx) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::entry_T) [list source [file join $dir HelperWindows.tcl]]

set auto_index(::RamDebugger::entry_PSx_nprint) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::OpenXMLViewer) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::OpenXMLViewer_do) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindow) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindowDo) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayBreakpointsWindowSetCond) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayBreakpointsWindow) [list source [file join $dir HelperWindows.tcl]]
................................................................................
set auto_index(::RamDebugger::inline_replace) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::inline_replace_end) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::textPaste_insert_after) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_add_colon) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_add_open_brace) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_increase_selection) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_get_selection) [list source [file join $dir HelperWindows.tcl]]

set auto_index(::RamDebugger::Search_goHome) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::_search_BP1) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_toggle_regexp_mode) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::OpenProgram) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::_OpenProgram_puts) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::revalforTkcon) [list source [file join $dir HelperWindows.tcl]]
................................................................................
set auto_index(Insert\ rectangular\ text) [list source [file join $dir Macros_default.tcl]]
set auto_index(Kill\ rectangular\ text) [list source [file join $dir Macros_default.tcl]]
set auto_index(Macro\ regsub) [list source [file join $dir Macros_default.tcl]]
set auto_index(Comment\ header) [list source [file join $dir Macros_default.tcl]]
set auto_index(Mark\ translation\ strings) [list source [file join $dir Macros_default.tcl]]
set auto_index(Convert\ GiD\ help\ Strings) [list source [file join $dir Macros_default.tcl]]
set auto_index(Background\ color\ region) [list source [file join $dir Macros_default.tcl]]


set auto_index(activate_deactivate_debug_lines) [list source [file join $dir Macros_default.tcl]]
set auto_index(Activate\ debug\ lines) [list source [file join $dir Macros_default.tcl]]
set auto_index(Toggle\ debug\ lines) [list source [file join $dir Macros_default.tcl]]
set auto_index(ddp) [list source [file join $dir Macros_default.tcl]]
set auto_index(send_draw_point_to_gidpost) [list source [file join $dir Macros_default.tcl]]
set auto_index(send_draw_box_to_gidpost) [list source [file join $dir Macros_default.tcl]]
set auto_index(Debug\ box\ GiD\ Post) [list source [file join $dir Macros_default.tcl]]
set auto_index(Debug\ point\ GiD\ Post) [list source [file join $dir Macros_default.tcl]]
set auto_index(Open\ comment\ file) [list source [file join $dir Macros_default.tcl]]
set auto_index(Edit\ comment\ file) [list source [file join $dir Macros_default.tcl]]
set auto_index(open_comment_file) [list source [file join $dir Macros_default.tcl]]





set auto_index(info_fullargs) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::menubutton_button) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::adapt_text_length) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::_adapt_text_length_do) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::add_contextual_menu_to_entry) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::text_entry_bindings) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::text_entry_insert) [list source [file join $dir mini_compass_utils.tcl]]
................................................................................
set auto_index(::cu::file::execute) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::profileprocs::StartProfiling) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::EndProfiling) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::OpenGUI) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::OpenGUI_do) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::_addrecursivepercent) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::FillTree) [list source [file join $dir ProfileProcs.tcl]]















set auto_index(::RamDebugger::DisplayWindowsHierarchyInfo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyInfoDo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyInfoDo2) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsToggleLongShortText) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyDoDraw) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyDo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyFind) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsPickWindow) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsPickWindowDo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyCancel) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyDoChangeFontSize) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchy) [list source [file join $dir WindowsHierarchy.tcl]]







>







 







>







 







>
>











>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
set auto_index(::RamDebugger::ToggleTransientWin) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::AddAlwaysOnTopFlag) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::InvokeAllDisplayVarWindows) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindow_contextual) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindow_contextual_do) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::entry_PSx) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::entry_T) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::PrintElements100000) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::entry_PSx_nprint) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::OpenXMLViewer) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::OpenXMLViewer_do) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindow) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayVarWindowDo) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayBreakpointsWindowSetCond) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::DisplayBreakpointsWindow) [list source [file join $dir HelperWindows.tcl]]
................................................................................
set auto_index(::RamDebugger::inline_replace) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::inline_replace_end) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::textPaste_insert_after) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_add_colon) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_add_open_brace) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_increase_selection) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_get_selection) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_paste_selection) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_goHome) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::_search_BP1) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search_toggle_regexp_mode) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::Search) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::OpenProgram) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::_OpenProgram_puts) [list source [file join $dir HelperWindows.tcl]]
set auto_index(::RamDebugger::revalforTkcon) [list source [file join $dir HelperWindows.tcl]]
................................................................................
set auto_index(Insert\ rectangular\ text) [list source [file join $dir Macros_default.tcl]]
set auto_index(Kill\ rectangular\ text) [list source [file join $dir Macros_default.tcl]]
set auto_index(Macro\ regsub) [list source [file join $dir Macros_default.tcl]]
set auto_index(Comment\ header) [list source [file join $dir Macros_default.tcl]]
set auto_index(Mark\ translation\ strings) [list source [file join $dir Macros_default.tcl]]
set auto_index(Convert\ GiD\ help\ Strings) [list source [file join $dir Macros_default.tcl]]
set auto_index(Background\ color\ region) [list source [file join $dir Macros_default.tcl]]
set auto_index(Background\ color\ default) [list source [file join $dir Macros_default.tcl]]
set auto_index(background_color_region) [list source [file join $dir Macros_default.tcl]]
set auto_index(activate_deactivate_debug_lines) [list source [file join $dir Macros_default.tcl]]
set auto_index(Activate\ debug\ lines) [list source [file join $dir Macros_default.tcl]]
set auto_index(Toggle\ debug\ lines) [list source [file join $dir Macros_default.tcl]]
set auto_index(ddp) [list source [file join $dir Macros_default.tcl]]
set auto_index(send_draw_point_to_gidpost) [list source [file join $dir Macros_default.tcl]]
set auto_index(send_draw_box_to_gidpost) [list source [file join $dir Macros_default.tcl]]
set auto_index(Debug\ box\ GiD\ Post) [list source [file join $dir Macros_default.tcl]]
set auto_index(Debug\ point\ GiD\ Post) [list source [file join $dir Macros_default.tcl]]
set auto_index(Open\ comment\ file) [list source [file join $dir Macros_default.tcl]]
set auto_index(Edit\ comment\ file) [list source [file join $dir Macros_default.tcl]]
set auto_index(open_comment_file) [list source [file join $dir Macros_default.tcl]]
set auto_index(Open\ XML\ viewer) [list source [file join $dir Macros_default.tcl]]
set auto_index(Words\ to\ c\ array) [list source [file join $dir Macros_default.tcl]]
set auto_index(Words\ to\ c\ arrayL) [list source [file join $dir Macros_default.tcl]]
set auto_index(c_string_region) [list source [file join $dir Macros_default.tcl]]
set auto_index(set!) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(info_fullargs) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::menubutton_button) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::adapt_text_length) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::_adapt_text_length_do) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::add_contextual_menu_to_entry) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::text_entry_bindings) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::cu::text_entry_insert) [list source [file join $dir mini_compass_utils.tcl]]
................................................................................
set auto_index(::cu::file::execute) [list source [file join $dir mini_compass_utils.tcl]]
set auto_index(::profileprocs::StartProfiling) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::EndProfiling) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::OpenGUI) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::OpenGUI_do) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::_addrecursivepercent) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::profileprocs::FillTree) [list source [file join $dir ProfileProcs.tcl]]
set auto_index(::RamDebugger::process_todo_txt_edit) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_end_edit) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_keys_after) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_keys) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::split_task) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::set_sorting_line) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_insert_line) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_end) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_save) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_search) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_help_menu_destroy) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_help_menu_insert) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt_help_menu) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_toggle_view) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::process_todo_txt) [list source [file join $dir todo_txt.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyInfo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyInfoDo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyInfoDo2) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsToggleLongShortText) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyDoDraw) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyDo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyFind) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsPickWindow) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsPickWindowDo) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyCancel) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchyDoChangeFontSize) [list source [file join $dir WindowsHierarchy.tcl]]
set auto_index(::RamDebugger::DisplayWindowsHierarchy) [list source [file join $dir WindowsHierarchy.tcl]]

Added scripts/todo_txt.tcl.



















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129

#################################################################################
#   process_todo_txt, process_todo_txt_edit, process_todo_txt_help_menu,
#   process_todo_txt_save, process_todo_txt_save_file
#   process_todo_txt_modify, process_todo_txt_modify_property
#################################################################################

# this comes from external ramdebugger
proc RamDebugger::process_todo_txt_save {} {
    variable process_todo_txt_data
    
    if { [dict_getd $process_todo_txt_data normal_edit 0] } {
        return continue
    } else {
        return break
    }
}

proc RamDebugger::process_todo_txt_end {} {
    variable text
    variable mainframe
    
    $mainframe showtoolbar 2 0
    
    set ipos [lsearch [bindtags $text] todo.txt]
    if { $ipos != -1 } {
        bindtags $text [lreplace [bindtags $text] $ipos $ipos]
    }
    set ipos [lsearch [bindtags $text] todo.txtA]
    if { $ipos != -1 } {
        bindtags $text [lreplace [bindtags $text] $ipos $ipos]
    }
    $text configure -state normal
}

proc RamDebugger::process_todo_set_normal_edit {} {
    variable text
    variable files
    variable currentfile
    variable process_todo_txt_data
    
    process_todo_txt_end
    
    $text delete 1.0 end
    $text insert end [string map [list "\t" "        "] $files($currentfile)]
    $text tag add normal 1.0 end
    
    dict set process_todo_txt_data normal_edit 1
    MarkAsNotModified
}

# this is internal
proc RamDebugger::process_todo_txt_save_file {} {
    variable files
    variable filesmtime
    variable currentfile
    variable currentfile_endline
    variable options
    variable process_todo_txt_data
    
    set lines [lsort -integer -index 0 [dict get $process_todo_txt_data lines]]

    set files($currentfile) ""
    foreach line $lines {
        append files($currentfile) [string trim [lindex $line 7]] "\n"
    }

    set err [catch { _savefile_only -file_has_been_read 1 \
                -file_endline $currentfile_endline \
                $currentfile $files($currentfile)} errstring]
    if { $err } {
        tk_messageBox -message [_ "Could not save file '%s' (%s)" $currentfile $errstring]
    } else {
        MarkAsNotModified
        set filesmtime($currentfile) [file mtime $currentfile]
        add_to_recent_files $currentfile
        set options(defaultdir) [file dirname $currentfile]
        RamDebugger::VCS::indicator_update
        SetMessage [_ "Saved file '%s'" $currentfile]
    }
}

proc RamDebugger::process_todo_txt_modify { args } {
    variable process_todo_txt_data
    
    set optional {
        { -save boolean 1 }
    }
    set compulsory "lineN txt"
    parse_args $optional $compulsory $args
    
    set lines [dict get $process_todo_txt_data lines]
    
    if { $lineN eq "" } {
        set idxP [llength $lines]
        set numP [expr {$idxP+1}]
    } else {
        set idxP [lsearch -index 0 $lines $lineN]   
        set numP $lineN
    }
    set d [set_sorting_line $numP $txt]
    if { $lineN eq "" } {
        dict lappend process_todo_txt_data undo_stack [list c]
        lappend lines [dict get $d line]
    } else {
        set old_line [lindex $lines $idxP]
        dict lappend process_todo_txt_data undo_stack [list m $old_line]
        lset lines $idxP [dict get $d line]
    }
    dict lappend process_todo_txt_data stack_idx ""
    dict set process_todo_txt_data lines $lines
    
    set projects [dict get $process_todo_txt_data projects]
    set contexts [dict get $process_todo_txt_data contexts]
    lappend projects {*}[dict get $d projects]
    lappend contexts {*}[dict get $d contexts] 
    dict set process_todo_txt_data projects [lsort -unique -dictionary $projects]
    dict set process_todo_txt_data contexts [lsort -unique -dictionary $contexts]
    
    if { $save } {
        process_todo_txt_save_file
    }
}

proc RamDebugger::process_todo_txt_modify_property { args } {
    variable process_todo_txt_data
    variable text
    
    set optional {
        { -increase "" 0 }
        { -decrease "" 0 }
        { -remove "" 0 }
    }
    set compulsory "property"
    parse_args $optional $compulsory $args
    
    set lineNList ""
    foreach "sel1 sel2" [$text tag ranges sel] {
        regexp {^\d+} $sel1 l1
        regexp {^\d+} $sel1 l2
        for { set i $l1 } { $i <= $l2 } { incr i } {
            set lineN [dict_getd $process_todo_txt_data text_line_to_line $i ""]
            if { $lineN ne "" } {
                lappend lineNList $lineN
            }
        }
    }
    if { [llength $lineNList] == 0 } { return }
    
    for { set i 0 } { $i < [llength $lineNList] } { incr i } {
        set idxP [lsearch -index 0 [dict get $process_todo_txt_data lines] [lindex $lineNList $i]]
        set line [lindex [dict get $process_todo_txt_data lines] $idxP]
        set d [split_task [lindex $line 7]]
        set txt [dict get $d txtF]
        switch $property {
            priority {
                if { [dict get $d completion] } {
                    continue
                }
                if { [dict exists $d priority] } {
                    if { $remove } {
                        dict unset d priority
                    } else {
                        set p [scan [dict get $d priority] %c]
                        if { $increase } {
                            incr p -1
                        } elseif { $decrease } {
                            incr p 1
                        }
                        if { $p < [scan A %c] } {
                            set p [scan A %c]
                        } elseif { $p > [scan Z %c] } {
                            set p [scan Z %c]
                        }
                        dict set d priority [format %c $p]
                    }
                }
                if { [dict exists $d priority] } {
                    set p [dict get $d priority]
                    if { [dict exists $d priority_idxs] } {
                        set txt [string replace $txt {*}[dict get $d priority_idxs] "($p) "]
                    } else {
                        set txt "($p) $txt"
                    }
                } elseif { [dict exists $d priority_idxs] } {
                    set txt [string replace $txt {*}[dict get $d priority_idxs] ""]
                }
            }                
            due_date {
                if { [dict exists $d due_date] } {
                    if { $remove } {
                        dict unset d due_date
                    } else {
                        set date [dict get $d due_date]
                        if { $increase } {
                            set date [clock format [clock add [clock scan $date] 1 day] -format "%Y-%m-%d"]
                        } elseif { $decrease } {
                            set date [clock format [clock add [clock scan $date] -1 day] -format "%Y-%m-%d"]
                        }
                        dict set d due_date $date
                    }
                } elseif { !$remove } {
                    dict set d due_date [clock format [clock seconds] -format "%Y-%m-%d"]
                }
                if { [dict exists $d due_date] } {
                    set date "due:[dict get $d due_date]"
                    if { [dict exists $d due_date_idxs] } {
                        set txt [string replace $txt {*}[dict get $d due_date_idxs] "$date "]
                    } else {
                        set txt "$txt $date"
                    }
                } elseif { [dict exists $d due_date_idxs] } {
                    set txt [string replace {*}[dict get $d due_date_idxs] ""]
                }
            }
        }
        process_todo_txt_modify -save 0 $lineN $txt
    }
    process_todo_txt_save_file
    process_todo_txt
    return -code break
}

proc RamDebugger::process_todo_txt_edit { args } {
    variable text
    variable process_todo_txt_data
    
    set optional {
        { -append "" 0 }
    }
    set compulsory ""
    parse_args $optional $compulsory $args
    
    $text configure -state normal
    set idx [$text index insert]
    
    regexp {^\d+} $idx line_num
    
    set lineN [dict_getd $process_todo_txt_data text_line_to_line $line_num ""]
    if { $lineN eq "" } {
        return
    }
    set idxP [lsearch -index 0 [dict get $process_todo_txt_data lines] $lineN]
    set line [lindex [dict get $process_todo_txt_data lines] $idxP]
    
    if { $append } {
        set list [dict keys [dict get $process_todo_txt_data text_line_to_line]]
        set max [lindex [lsort -integer $list] end]
        for { set i $max } { $i >= $line_num } { incr i -1 } {
            set lineN [dict_getd $process_todo_txt_data text_line_to_line $i ""]
            if { $lineN eq "" } { continue } 
            dict set process_todo_txt_data text_line_to_line [expr {$i+1}] $lineN
        }
        dict set process_todo_txt_data text_line_to_line $line_num ""
        
        set d [split_task [lindex $line 7]]
        set txt ""
        if { [dict exists $d priority] } {
            append txt "([dict get $d priority]) "
        }
        set today [clock format [clock seconds] -format "%Y-%m-%d"]
        append txt "$today "
        foreach project [dict_getd $d projects ""] {
            append txt "$project "
        }
        foreach context [dict_getd $d contexts ""] {
            append txt "$context "
        }
        set line [list 0 "" "" "" "" "" $txt]
        
        lset line 0 ""
        lset line 1 0
        lset line 2 ""
        lset line 4 $today
        lset line 6 ""
        lset line 7 $txt
    }

    $text tag remove sel 1.0 end
    $text tag add noediting 1.0 end
    
    if { !$append } {
        $text delete "$idx linestart" "$idx lineend+1c"
    }
    set idx [$text index "$idx linestart"]
    process_todo_txt_insert_line -idx $idx -full $line
    
    $text tag add editing $idx "$idx lineend+1c"
    if { !$append } {
        $text mark set insert "$idx lineend"
    } else {
        set txt [$text get $idx "$idx lineend+1c"]
        if { [regexp -indices {[+@]} $txt idxs] } {
            $text mark set insert "$idx +[lindex $idxs 0]c"
        } else {
            $text mark set insert "$idx lineend"
        }
    }
    $text tag configure noediting -background #dddddd
    $text tag configure editing -borderwidth 1 -background #ffffff -foreground black
    $text tag raise editing
}

proc RamDebugger::process_todo_txt_end_edit { accept_cancel } {
    variable text
    variable process_todo_txt_data

    lassign [$text tag range editing] e1 e2
    if { $e1 eq "" } {
        $text tag remove noediting 1.0 end
        $text tag remove editing 1.0 end
        $text configure -state disabled
        process_todo_txt_keys -dobreak 0 Selection ""
        return
    }
    set idx [$text index $e1]
    regexp {^\d+} $idx line_num
    set lineN [dict get $process_todo_txt_data text_line_to_line $line_num]
    
    if { $accept_cancel eq "cancel" } {
        lassign [$text tag range editing] e1 e2
        if { $e1 ne "" } {
            $text delete $e1 $e2
        }
        if { $lineN ne "" } {
            set idxP [lsearch -index 0 [dict get $process_todo_txt_data lines] $lineN]
            set line [lindex [dict get $process_todo_txt_data lines] $idxP]
            set idx [$text index "$idx linestart"]
            process_todo_txt_insert_line -idx $idx $line
            $text mark set insert $idx
        }
    } else {
        lassign [$text tag range editing] e1 e2
        if { $e1 ne "" } {
            set txt [string trim [$text get $e1 $e2]]
            process_todo_txt_modify $lineN $txt
        }
    }
    $text tag remove noediting 1.0 end
    $text tag remove editing 1.0 end
    $text configure -state disabled
    process_todo_txt_keys -dobreak 0 Selection ""
}

proc RamDebugger::process_todo_txt_keys_after { args } {
    variable text
    
    if { [$text cget -state] ne "disabled" } {
        lassign [$text tag range editing] e1 e2
        if { $e1 ne "" } {
            set idx [$text index insert]
            if { [$text compare $idx < $e1] || [$text compare $idx > $e2] } {
                process_todo_txt_end_edit accept
            }
        }
    }
    process_todo_txt_help_menu $text
}

proc RamDebugger::process_todo_txt_keys { args } {
    variable text
    variable last_selection
    variable last_selection_doing
    variable process_todo_txt_data

    set optional {
        { -dobreak boolean 1 }
    }
    set compulsory "what key"
    parse_args $optional $compulsory $args
       
    switch $what {
        Control-KeyPress {
            return
        }
        BR1 {
            set idx [$text index $key]
            if { [$text cget -state] ne "disabled" } {
                lassign [$text tag range editing] e1 e2
                if { $e1 eq "" || [$text compare $idx < $e1] || [$text compare $idx > $e2] } {
                    process_todo_txt_end_edit accept
                    return -code break
                } else {
                    return
                }
            }
            lassign [$text tag range sel] sel1 sel2
            if { $sel1 ne "" && [$text compare $idx >= $sel1] && [$text compare $idx <= $sel2] } {
                $text tag add sel "$sel1 linestart" "$sel2 lineend"
            } else {
                $text tag add sel "$idx linestart" "$idx lineend"
            }
            if { $dobreak } { return -code break }
        }
        DBR1 {
            if { [$text cget -state] ne "disabled" } {
                return
            }
            process_todo_txt_edit
        }
        Selection {
            if { [$text cget -state] ne "disabled" } {
                return
            }
            set sel1 [lindex [$text tag ranges sel] 0]
            set sel2 [lindex [$text tag ranges sel] end]
            if { $sel1 eq "" } { 
                set sel1 [$text index insert]
                set sel2 $sel1
                set idx1 ""
            } else {
                set idx1 $sel1   
            }
            set last_selectionL [list $sel1 $sel2]
            if { $last_selectionL eq [set! last_selection] } { return }
            
            if { [set! last_selection_doing] == 1 } { return }
            set last_selection_doing 1
            
            $text tag remove sel 1.0 end
            lassign "0 0" has_selection has_finished
            foreach "idx1 idx2" [$text tag ranges lines] {
                regexp {^\d+} $idx1 l1
                regexp {^\d+} $idx2 l2
                for { set i $l1 } { $i <= $l2 } { incr i } {
                    if { [$text compare $i.0 >= "$sel1 linestart"] } {
                        if { [$text compare $i.0 <= $sel2] } {
                            $text tag add sel "$i.0" "$i.0 lineend"
                            set has_selection 1
                        } else {
                            if { !$has_selection } {
                                $text tag add sel "$i.0" "$i.0 lineend"
                            }
                            set has_finished 1
                            break
                        }
                    }
                }
                if { $has_finished } {
                    break
                }
            }
            set sel1 [lindex [$text tag range sel] 0]
            set sel2 [lindex [$text tag range sel] end]
            set last_selection [list $sel1 $sel2]
            set last_selection_doing 0
            
            if { $dobreak } { return -code break }
        }
        KeyPress - Shift-KeyPress {
            if { [$text cget -state] eq "disabled" } {
                lassign [$text tag range sel] sel1 sel2
                if { $sel1 ne "" } {
                    $text mark set insert $sel1
                }
                switch $key {
                    F2 {
                        return
                    }
                    Up - Down {
#                         if { $what eq "Shift-KeyPress" } {
#                             return 
#                         }
                        set idx [$text index insert]
                        while 1 {
                            if { $key eq "Up" } {
                                set idx [$text index "$idx -1l"]
                            } else {
                                set idx [$text index "$idx +1l"]
                            }
                            if { [$text compare "$idx linestart" == "1.0"] } { break }
                            if { [lsearch [$text tag names $idx] title] != -1 } { continue }
                            if { [lsearch [$text tag names $idx] lines] == -1 } {
                                break
                            }
                            if { [$text compare "$idx linestart" == "end-1l"] } {
                                set idx [$text index "$idx-1l"]
                                break
                            }
                            break
                        }
                        if { [lsearch [$text tag names $idx] lines] == -1 } {
                            if { $dobreak } { return -code break }
                            return
                        }
                        $text mark set insert $idx
                        if { $what ne "Shift-KeyPress" } {
                            $text tag remove sel 1.0 end
                        }
                        $text tag add sel "$idx linestart" "$idx lineend"
                        if { $dobreak } { return -code break }
                    }
                    e {
                        process_todo_txt_edit
                    }
                    n {
                        process_todo_txt_edit -append
                    }
                    f - Tab {
                        set w [dict_getd $process_todo_txt_data search_widget ""]
                        if { $w ne "" } {
                            tk::TabToWindow $w
                        }
                    }
                }
                if { $dobreak } { return -code break }
            } else {
                switch $key {
                    Up - Down {
                        process_todo_txt_end_edit accept
                        if { $dobreak } { return -code break }
                    }
                    Return {
                        process_todo_txt_end_edit accept
                        if { $dobreak } { return -code break }
                    }
                    Escape {
                        process_todo_txt_end_edit cancel
                        if { $dobreak } { return -code break }
                    }
                    BackSpace {
                        set idx [$text index insert]
                        lassign [$text tag range editing] e1 e2
                        if { [$text compare $idx <= $e1] } {
                            if { $dobreak } { return -code break }
                        }
                    }
                }
            }
        }
    }
}

proc RamDebugger::split_task { txt } {
    
    set d ""
    set txt [string trim $txt]
    
    if { [regexp -indices {^\s*(x)\s} $txt all_idxs c_idxs] } {
        dict set d completion 1
        dict set d completion_idxs $c_idxs
        set start [expr {[lindex $all_idxs 1]+1}]

        if { [regexp -start $start -indices {\A\s*(\d{4}\-\d{2}\-\d{2})\s} $txt all_idxs d_idxs] } {
            dict set d completion_date [string range $txt {*}$d_idxs]
            dict set d completion_date_idxs $d_idxs
            set start [expr {[lindex $all_idxs 1]+1}]
        }
    } else {
        dict set d completion 0
        set start 0
    }
    if { [regexp -start $start -indices {\A\s*(\(([A-Z])\)\s)} $txt all_idxs pF_idxs p_idxs] } {
        dict set d priority [string range $txt {*}$p_idxs]
        dict set d priority_idxs $pF_idxs
        set start [expr {[lindex $all_idxs 1]+1}]
    }
    if { [regexp -start $start -indices {\A\s*(\d{4}\-\d{2}\-\d{2})\s} $txt all_idxs d_idxs] } {
        dict set d start_date [string range $txt {*}$d_idxs]
        dict set d start_date_idxs $d_idxs
        set start [expr {[lindex $all_idxs 1]+1}]
    }

    dict set d projects [regexp -inline -all {[+][^+\s]+} $txt]
    dict set d contexts [regexp -inline -all {[@][^@\s]+} $txt]

    if { [regexp -start $start -indices {due:(\d{4}\-\d{2}\-\d{2})} $txt all_idxs d_idxs] } {
        dict set d due_date [string range $txt {*}$d_idxs]
        dict set d due_date_idxs $all_idxs
    }
    dict set d txtF $txt
    dict set d txtS [string trim [string range $txt $start end]]
    return $d    
}

proc RamDebugger::set_sorting_line { idx txt } {
    
    set d [split_task $txt]
    
    if { ![dict exists $d priority] } {
        dict set d priority ZZ
    }
    dict set d project [lindex [dict_getd $d projects ""] 0]
    if { [dict get $d project] eq "" } {
        dict set d project +ZZZZZZZ
    }
    dict set d line [list $idx \
            [dict get $d completion] \
            [dict_getd $d completion_date ""] \
            [dict_getd $d priority ""] \
            [dict_getd $d start_date ""] \
            [dict_getd $d project ""] \
            [dict_getd $d due_date ""] \
            $txt]
    dict set d projects [dict_getd $d projects ""]
    dict set d contexts [dict_getd $d contexts ""]
    return $d
}

proc RamDebugger::process_todo_txt_insert_line { args } {
    variable text
    variable process_todo_txt_data
    variable process_todo_txt_view_create_date
    variable process_todo_txt_view_completed
    
    set optional {
        { -orderby_txt orderby_txt ""  }
        { -idx idx "end" }
        { -search string "" }
        { -full "" 0 }
    }
    set compulsory "line"
    parse_args $optional $compulsory $args
    
    set today [clock format [clock seconds] -format "%Y-%m-%d"]
    
    lassign $line lineN completion completion_date priority \
        start_date project due_date txt
    
    if { $search ne "" && ![string match -nocase *$search* $txt] } { return }
    
    if { !$full } {
        set d [split_task $txt]
        if { $process_todo_txt_view_completed == 0 && [dict get $d completion] } {
            return
        }
        if { $process_todo_txt_view_create_date == 0 } {
            set txt ""
            if { [dict get $d completion] } {
                append txt "x "
            }
            if { [dict exists $d priority] } {
                append txt "([dict get $d priority]) "
            }
            append txt [dict get $d txtS]
        }
    }
    
    if { $orderby_txt ne "" } {
        $text insert end "\n$orderby_txt\n" title
    }
    if { $completion } {
        set tag completed
    } elseif { $due_date eq "" || $due_date > $today } {
        set tag normal
    } elseif { $due_date == $today } {
        set tag today
    } else {
        set tag old
    }
    if { $idx eq "end" } { set idx "end-1c" }
    set idx [$text index $idx]
    $text insert $idx "$txt\n" "$tag lines"
    
    regexp {^\d+} $idx line_num
    dict set process_todo_txt_data text_line_to_line $line_num $lineN
}

proc RamDebugger::process_todo_search { w } {
    variable process_todo_txt_data
    variable process_todo_txt_str
    
    process_todo_txt_help_menu $w
    
    after cancel [dict_getd $process_todo_txt_data afterid 0]
    set a [after 200 [list RamDebugger::process_todo_txt -search $process_todo_txt_str]]
    dict set process_todo_txt_data afterid $a
}

proc RamDebugger::process_todo_txt_help_menu_destroy { w } {
    
    destroy $w.t
    set ipos [lsearch [bindtags $w] MM]
    if { $ipos != -1 } {
        bindtags $w [lreplace [bindtags $w] $ipos $ipos]
    }
}

proc RamDebugger::process_todo_txt_help_menu_insert { w txt } {

    if { [winfo class $w] eq "Text" } {
        set idx [$w index insert]
        set txtW [$w get "$idx linestart" "$idx"]
    } else {
        set txtW [$w get]
    }
    if {![regexp {^(\s*)([(][A-Z]?)$} $txtW {} start] && 
        ![regexp {^(.*)([+@][^+@ \t]*)$} $txtW {} start] } {
        process_todo_txt_help_menu_destroy $w
        return
    }
    if { [winfo class $w] eq "Text" } {
        set tags [$w tag names "$idx linestart"]
        $w delete "$idx linestart" "$idx"
        $w insert "$idx linestart" $start$txt $tags
        $w mark set insert "$idx linestart +[string length $start$txt]c"
    } else {
        $w delete 0 end
        $w insert end $start$txt
        $w icursor end
    }
    process_todo_txt_help_menu_destroy $w
}

proc RamDebugger::process_todo_txt_help_menu { w } {
    variable process_todo_txt_data
    
    if { [$w cget -state] eq "disabled" } { return }
        
    if { [winfo class $w] eq "Text" } {
        set idx [$w index insert]
        set txt [$w get "$idx linestart" "$idx"]
    } else {
        set txt [$w get]
    }
    if { [regexp -indices {^\s*([(][A-Z]?)$} $txt {} idxs] } {
        set prefix [string range $txt {*}$idxs]
    } elseif { [regexp -indices {([+@][^+@ \t]*)$} $txt {} idxs] } {
        set prefix [string range $txt {*}$idxs]
    } else {
        process_todo_txt_help_menu_destroy $w
        return
    }
    
    if { [regexp {\(.*} $prefix] } {
        set list [list (A) (B) (C) (D) (E) (F)]
    } elseif { [string match @* $prefix] } {
        set list [dict get $process_todo_txt_data contexts]
    } else {
        set list [dict get $process_todo_txt_data projects] 
    }
    
    if { $prefix in $list } {
        process_todo_txt_help_menu_destroy $w
        return
    }
    
    if { [lsearch [bindtags $w] MM] == -1 } {
        bindtags $w [linsert [bindtags $w] 0 MM]
    }
        
    if { ![winfo exists $w.t] } {
        toplevel $w.t
        wm attributes $w.t -topmost 1
        wm overrideredirect $w.t 1
    }
    if { [winfo class $w] eq "Text" } {
        set bbox [$w bbox "$idx linestart + [lindex $idxs 0]c"]
    } else {
        set bbox [$w bbox [lindex $idxs 0]]
    }
    set x [expr {[winfo rootx $w]+[lindex $bbox 0]}]
    set y [expr {[winfo rooty $w]+[expr {[lindex $bbox 1]+[lindex $bbox 3]}]}]
    wm geometry $w.t +$x+$y
        
    destroy {*}[winfo children $w.t]
    set idx 1
    foreach p $list {
        if { [string match $prefix* $p] == 0 } { continue }
        set b [button $w.t.b$idx -text $p -bd 1 -relief ridge -padx 0 -pady 0 \
                -anchor w -command \
                [list RamDebugger::process_todo_txt_help_menu_insert $w $p]]
        bind $b <Return> [list $b invoke]
        bind $b <Escape> [list RamDebugger::process_todo_txt_help_menu_destroy $w]
        if { $idx > 1 } {
            set b_prev $w.t.b[expr {$idx-1}]
            bind $b_prev <Down> [list focus $b]
            bind $b <Up> [list focus $b_prev]
        }
        grid $b -sticky ew
        incr idx
    }
    if { $idx == 1 } {
        process_todo_txt_help_menu_destroy $w
        return
    }
    bind MM <Down> "[list focus $w.t.b1]; break"
    bind MM <Up> "[list focus $w.t.b[expr {$idx-1}]]; break"
}

proc RamDebugger::process_todo_toggle_view { what toggle } {
    variable text
    variable process_todo_txt_view_create_date
    variable process_todo_txt_view_completed
    
    if { [$text cget -state] ne "disabled" } {
        return
    }
    if { $toggle } {
        switch $what {
            create_date {
                if { $process_todo_txt_view_create_date } {
                    set process_todo_txt_view_create_date 0
                } else {
                    set process_todo_txt_view_create_date 1
                }
            }
            view_completed {
                if { $process_todo_txt_view_completed } {
                    set process_todo_txt_view_completed 0
                } else {
                    set process_todo_txt_view_completed 1
                }
            }
        }
    }
    process_todo_txt
    return -code break
}

#################################################################################
#    process_todo_txt main function
#################################################################################

proc RamDebugger::process_todo_txt { args } {
    variable text
    variable mainframe
    variable files
    variable currentfile
    variable currentfileIsModified
    variable process_todo_txt_data
    variable process_todo_txt_view_create_date
    variable process_todo_txt_view_completed
    variable process_todo_txt_order
    
    set optional {
        { -search search "-" }
        { -order order "-" }
    }
    set compulsory ""
    parse_args $optional $compulsory $args
    
    if { ![info exists process_todo_txt_data] } {
        set process_todo_txt_data ""
    }
    if { ![dict exists $process_todo_txt_data normal_edit] } {
        dict set process_todo_txt_data normal_edit 0
    }
    if { [dict get $process_todo_txt_data normal_edit] } {
        return
    }
    
    if { $search ne "-" } {
        dict set process_todo_txt_data search $search
    } else {
        set search [dict_getd $process_todo_txt_data search ""]
    }
    if { $order ne "-" } {
        dict set process_todo_txt_data order $order
    } else {
        set order [dict_getd $process_todo_txt_data order "project_priority"]  
    }
    
    dict set process_todo_txt_data order_labels [dict create \
            project_priority [dict create n [_ "Project+priority"] acc Control-Key-1] \
            project_creationdate [dict create n [_ "Project+creation date"] acc Control-Key-2] \
            creationdate [dict create n [_ "Creation date"] acc Control-Key-3] \
            priority [dict create n [_ "Priority"] acc Control-Key-4] \
            ]
    
    dict set process_todo_txt_data menu [list \
            [dict create n [_ "View create date"] var process_todo_txt_view_create_date \
                acc Control-d cmd "process_todo_toggle_view create_date 0" \
                cmd_acc "process_todo_toggle_view create_date 1"] \
            [dict create n [_ "View completed"] var process_todo_txt_view_completed \
                acc Control-c cmd "process_todo_toggle_view view_completed 0" \
                cmd_acc "process_todo_toggle_view view_completed 1"] \
            [dict create] \
            [dict create n [_ "Increase priority"] acc Control-Up \
                cmd "process_todo_txt_modify_property -increase priority"] \
            [dict create n [_ "Decrease priority"] acc Control-Down \
                cmd "process_todo_txt_modify_property -decrease priority"] \
            [dict create n [_ "Remove priority"] acc Control-Left,Control-Right \
                cmd "process_todo_txt_modify_property -remove priority"] \
            [dict create n [_ "Increase due date"] acc Control-Shift-Up \
                cmd "process_todo_txt_modify_property -increase due_date"] \
            [dict create n [_ "Decrease due date"] acc Control-Shift-Down \
                cmd "process_todo_txt_modify_property -decrease due_date"] \
            [dict create n [_ "Remove due date"] acc Control-Shift-Left,Control-Shift-Right \
                cmd "process_todo_txt_modify_property -remove due_date"] \
            [dict create] \
            [dict create n [_ "Normal edition"]  \
                cmd "RamDebugger::process_todo_set_normal_edit"] \
            ]
    
    if { ![info exists process_todo_txt_view_create_date] } {
        set process_todo_txt_view_create_date 1
    }
    if { ![info exists process_todo_txt_view_completed] } {
        set process_todo_txt_view_completed 1
    }
    
    set process_todo_txt_order [dict get $process_todo_txt_data order_labels $order n]
    
    if { [lsearch [bindtags $text] todo.txt] == -1 } {
        bindtags $text [linsert [bindtags $text] 0 todo.txt]
        bindtags $text [list {*}[bindtags $text] todo.txtA]
    }
    bind todo.txt <KeyPress> [list RamDebugger::process_todo_txt_keys KeyPress %K]
    bind todo.txt <Shift-KeyPress> [list RamDebugger::process_todo_txt_keys Shift-KeyPress %K]
    bind todo.txt <Control-KeyPress> [list RamDebugger::process_todo_txt_keys Control-KeyPress %K]
    bind todo.txt <ButtonRelease-1> [list RamDebugger::process_todo_txt_keys BR1 @%x,%y]
    bind todo.txt <Double-ButtonRelease-1> [list RamDebugger::process_todo_txt_keys DBR1 @%x,%y]
    bind todo.txt <<Selection>> [list RamDebugger::process_todo_txt_keys Selection ""]
    bind todo.txtA <KeyPress> [list RamDebugger::process_todo_txt_keys_after]
        
    dict for "n v" [dict get $process_todo_txt_data order_labels] {
        set cmd [list RamDebugger::process_todo_txt -order $n]
        bind todo.txt <[dict get $v acc]> "$cmd;break"
    }
    foreach d [dict get $process_todo_txt_data menu] {
        if { ![dict exists $d acc] } { continue }
        if { [dict exists $d cmd_acc] } {
            set cmd RamDebugger::[dict get $d cmd_acc]
        } else {
            set cmd RamDebugger::[dict get $d cmd]
        }
        foreach acc [split [dict get $d acc] ","] {
            bind todo.txt <$acc> "$cmd"
        }
    }
    
    $mainframe showtoolbar 2 1
    set f [$mainframe gettoolbar 2]
    
    if { ![winfo exists $f.l] } {
        ttk::label $f.l -text [_ "Search"]:
        ttk::entry $f.e1 -width 30 -textvariable ::RamDebugger::process_todo_txt_str
        dict set process_todo_txt_data search_widget $f.e1
        
        bind $f.e1 <Tab> "[list focus $text]; break"
        bind $f.e1 <Escape> "[list $f.e1 delete 0 end]; break"
        
        # to avoid problems with paste, that sometimes pastes too to the main window
        bind $f.e1 <<Paste>> "[bind [winfo class $f.e1] <<Paste>>]; break"
        trace add variable ::RamDebugger::process_todo_txt_str write \
            "[list RamDebugger::process_todo_search $f.e1];#"
        
        ttk::menubutton $f.m -textvariable RamDebugger::process_todo_txt_order -menu $f.m.mb
        menu $f.m.mb
        
        dict for "n v" [dict get $process_todo_txt_data order_labels] {
            set cmd [list RamDebugger::process_todo_txt -order $n]
            $f.m.mb add command -label [dict get $v n] -acc [dict get $v acc] \
                -command $cmd
            bind $f.e1 <[dict get $v acc]> "$cmd;break"
        }
        
        ttk::menubutton $f.m2 -text [_ "Tasks"] -menu $f.m2.mb
        menu $f.m2.mb
        
        foreach d [dict get $process_todo_txt_data menu] {
            if { [dict exists $d var] } {
                $f.m2.mb add checkbutton
            } elseif { [dict exists $d cmd] } {
                $f.m2.mb add command
            } else {
                $f.m2.mb add separator
                continue
            }
            set acc [dict_getd $d acc ""]
            foreach "n v" [list Control Ctrl Shift \u21e7 Left \u2190 Up \u2191 \
                    Right \u2192 Down \u2193] {
                regsub -all $n $acc $v acc
            }
            
            $f.m2.mb entryconfigure end -label [dict get $d n] -acc $acc \
                -command RamDebugger::[dict get $d cmd]
            if { [dict exists $d var] } {
                $f.m2.mb entryconfigure end -variable RamDebugger::[dict get $d var]
            }
            if { [dict exists $d acc] } {
                if { [dict exists $d cmd_acc] } {
                    set cmd RamDebugger::[dict get $d cmd_acc]
                } else {
                    set cmd RamDebugger::[dict get $d cmd]
                }
                foreach acc [split [dict get $d acc] ","] {
                    bind $f.e1 <$acc> "$cmd"
                }
            }
        }
        grid $f.l $f.e1 $f.m $f.m2 -sticky ew
        grid columnconfigure $f 1 -weight 0
    }
    set currentfileIsModified_save $currentfileIsModified

    lassign "" lineNList currentN
    if { ![dict exists $process_todo_txt_data lines] } {
#         lassign "" data projects contexts
#         set on 1
#         foreach "key value index" [$text dump 1.0 end] {
#             switch $key {
#                 text {
#                     if { $on } {
#                         append data $value
#                     }
#                 }
#                 tagon {
#                     if { $value eq "title" } {
#                         set on 0
#                     }
#                 }
#                 tagoff {
#                     if { $value eq "title" } {
#                         set on 1
#                     }
#                 }
#             }
#         }
        
        set data [string map [list "\t" "        "] $files($currentfile)]
        
        lassign "" lines projects contexts
        set idx 1
        foreach txt [split [string trim $data] \n] {
            set d [set_sorting_line $idx $txt]
            lappend lines [dict get $d line]
            lappend projects {*}[dict get $d projects]
            lappend contexts {*}[dict get $d contexts]
            incr idx
        }
        dict set process_todo_txt_data projects [lsort -unique -dictionary $projects]
        dict set process_todo_txt_data contexts [lsort -unique -dictionary $contexts]
    } else {
        set lines [dict get $process_todo_txt_data lines]
        foreach "sel1 sel2" [$text tag ranges sel] {
            regexp {^\d+} $sel1 l1
            regexp {^\d+} $sel2 l2
            for { set i $l1 } { $i <= $l2 } { incr i } {
                set lineN [dict_getd $process_todo_txt_data text_line_to_line $i ""]
                if { $lineN ne "" } {
                    lappend lineNList $lineN
                }
            }
        }
        set idx [$text index insert]
        if { $idx ne "" } {
            regexp {^\d+} $idx l1
            set currentN [dict_getd $process_todo_txt_data text_line_to_line $l1 ""]
        }
    }
    switch $order {
        project_priority {
            set lines [lsort -nocase -index 3 $lines]
            set lines [lsort -nocase -index 5 $lines]
            set orderby 5
        }
        project_creationdate {
            set lines [lsort -nocase -decreasing -index 4 $lines]
            set lines [lsort -nocase -index 5 $lines]
            set orderby 5
        }
        creationdate {
            set lines [lsort -nocase -index 3 $lines]
            set lines [lsort -nocase -decreasing -index 4 $lines]
            set orderby 4
        }
        priority {
            set lines [lsort -nocase -decreasing -index 4 $lines]
            set lines [lsort -nocase -index 3 $lines]
            set orderby 3
        }
    }
    set lines [lsort -nocase -index 1 $lines]
    
    set fontbold [font actual [$text cget -font]]
    set ipos [lsearch $fontbold -weight]
    set fontbold [lreplace $fontbold $ipos+1 $ipos+1 bold]
    
    $text tag configure title -font $fontbold
    $text tag configure lines -lmargin1 10
    $text tag configure completed -foreground grey -overstrike 1
    $text tag configure today -foreground green
    $text tag configure old -foreground red
      
    $text configure -state normal
    $text delete 1.0 end
    lassign "0 0" has_selection has_insert
    foreach line $lines {
        set orderby_txt [lindex $line $orderby]
        if { ![info exists orderby_txt_prev] || $orderby_txt ne $orderby_txt_prev } {
            set orderby_txt_prev $orderby_txt
            if { $orderby_txt eq "+ZZZZZZZ" || $orderby_txt eq "ZZ" } {
                set orderby_txt [_ "NONE"]
            }
        } else {
            set orderby_txt ""
        }
        if { [lindex $line 1] } {
            if { ![info exists orderby_txt_prevC] } {
                set orderby_txt [_ "Completed"]
                set orderby_txt_prevC 1
            } else {
                set orderby_txt ""
            }
        }
        process_todo_txt_insert_line -orderby_txt \
            $orderby_txt -search $search $line
        set idx [$text index end-2c]
        if { [lindex $line 0] in $lineNList } {
            $text tag add sel "$idx linestart" "$idx lineend"
            set has_selection 1
        }
        if { [lindex $line 0] == $currentN } {
            $text mark set insert "$idx linestart"
            set has_insert 1
        } 
    }
    if { !$has_selection } {
        $text tag add sel 1.0 "1.0 lineend"
    }
    if { !$has_insert } {
        $text mark set insert 1.0
    }
    $text see insert
    $text configure -state disabled
    process_todo_txt_keys -dobreak 0 Selection ""
    
    if { $currentfileIsModified && !$currentfileIsModified_save } {
        MarkAsNotModified
    }
    dict set process_todo_txt_data lines $lines
}