*! version 1.0.0 STB-43 dm57 ** Author: John R. Gleason, Syracuse University, Syracuse NY, USA ** (loesljrg@ican.net) program define notedit version 5.0 macro drop DB* global DB_DBuf 5 /* Depth of notes buffer display window */ local varlist opt parse "`*'" global DB_var "_dta `varlist'" global DB_ex "exit 3000" window control button "Exit" 282 4 40 10 DB_ex global DB_NC1 "Notes category:" global DB_sc "CatSel" window control button "Select" 65 13 40 10 DB_sc window control scombo DB_var 5 13 55 85 DB_ncat window control static DB_NC1 5 3 55 10 global DB_NC2 "Data Notes" window control static DB_NC2 119 3 40 10 window control static DBntN 121 13 30 10 blackframe window control static DBntN 122 14 28 8 center global DB_Disp "Display" window control button "Display" 121 25 30 8 DB_Disp global DB_NC3 "Buffer Notes" window control static DB_NC3 223 3 50 10 window control static DBntM 226 13 30 10 blackframe window control static DBntM 227 14 28 8 center global DB_Sav "Save" window control button "<-- Save <--" 161 13 55 10 DB_Sav global DB_Brows 0 window control check "Browse" 174 3 40 8 DB_Brows global DB_Stat " " window control static DB_Stat 162 25 100 8 left global DB_no0 "Notes Buffer" window control static DB_no0 5 44 317 59 blackframe window control static DB_no0 130 41 55 9 center window control edit 65 50 200 8 DB_buf1 window control edit 65 60 200 8 DB_buf2 window control edit 65 70 200 8 DB_buf3 window control edit 65 80 200 8 DB_buf4 window control edit 65 90 200 8 DB_buf5 window control radbegin "" 270 50 15 8 DB_Bptr window control radio "" 270 60 15 8 DB_Bptr window control radio "" 270 70 15 8 DB_Bptr window control radio "" 270 80 15 8 DB_Bptr window control radend "" 270 90 15 8 DB_Bptr window control static DB_Buf1 46 50 15 8 right window control static DB_Buf2 46 60 15 8 right window control static DB_Buf3 46 70 15 8 right window control static DB_Buf4 46 80 15 8 right window control static DB_Buf5 46 90 15 8 right global DB_Top "Scroll 0" window control button "Top" 8 47 30 8 DB_Top global DB_PgUp "Scroll -$DB_DBuf" window control button "PgUp" 8 56 30 8 DB_PgUp global DB_Up "Scroll -1" window control button "Up" 8 65 30 8 DB_Up global DB_Dn "Scroll 1" window control button "Dn" 8 74 30 8 DB_Dn global DB_PgDn "Scroll $DB_DBuf" window control button "PgDn" 8 83 30 8 DB_PgDn global DB_Bot "Scroll 10000" window control button "Bottom" 8 92 30 8 DB_Bot global DB_Ins "InsDel 1" window control button "Insert" 289 65 30 8 DB_Ins global DB_Del "InsDel -1" window control button "Delete" 289 74 30 8 DB_Del global DB_DFrg "DeFrag" window control button "Compact Buffer" 5 32 55 10 DB_DFrg global DB_ClBf "ClrBuf" window control button "Clear Buffer" 267 32 55 10 DB_ClBf global DBntN 0 global DBntM 0 Draw 1 capture noi window dialog "Stata Notes Editor" . . 330 117 macro drop DB* exit 0 end program define CatSel Huh $DB_ncat if _rc { exit } mac drop DBnt* ClrBuf local j 0 global DBntN : char $DB_ncat[note0] if "$DBntN" != "" { local i 0 while `i' < $DBntN { local i = `i' + 1 local t : char $DB_ncat[note`i'] if "`t'" != "" { local j = `j' + 1 global DBnt`j' "`t'" } } } global DBntN `j' global DBntM `j' Draw 1 end program define ClrBuf global DB_Stat " " local t $DBntN mac drop DBnt* global DBntN `t' global DBntM 0 Draw 1 end program define UpDate global DB_Stat " " local m 0 local i 0 while `i' < $DB_DBuf { local i = `i' + 1 local j ${DB_Buf`i'} parse "${DB_buf`i'}", parse(" ") if "`*'" != "" | "${DBnt`j'}" != "" { global DBnt`j' "`*'" local m `j' } } if `m' > $DBntM { global DBntM `m' } end program define DeFrag UpDate local i 1 local j 0 while `i' <= $DBntM { local t "${DBnt`i'}" if trim("`t'") != "" { local j = `j' + 1 if `i' > `j' { global DBnt`j' "`t'" global DBnt`i' /* clear unused notes */ } } local i = `i' + 1 } global DBntM `j' Draw 1 end program define Scroll UpDate local t `1' if "`1'" == "10000" { local t = $DBntM-$DB_DBuf+1 } else if "`1'" != "0" { local t = `1' + $DB_Buf1 } local t = max(1, `t') Draw `t' end program define Draw local i `1' local j 0 while `j' < $DB_DBuf { local j = `j' + 1 /* the trailing blank is important! */ global DB_buf`j' "${DBnt`i'} " global DB_Buf`j' `i' local i = `i' + 1 } end program define InsDel if $DB_Buf1 > $DBntM { exit } UpDate local t ${DB_Buf$DB_Bptr} local i1 `t' local stop $DBntM if `1' == 1 { /* insert */ local stop `t' local i1 = $DBntM + 1 } local i2 = `1' + `i1' while `i1' != `stop' { local i1 = -(`1') + `i1' local i2 = `1' + `i1' global DBnt`i2' "${DBnt`i1'}" } if `1' == 1 { global DBnt`t' } else { global DBnt`stop' } global DBntM = `1' + $DBntM Draw $DB_Buf1 end program define Save if $DB_Brows { window stopbox stop "Can't Save in Browse Mode" exit } Huh $DB_ncat if _rc { exit } DeFrag local t = max($DBntN, $DBntM) local i 0 while `i' < `t' { local i = `i' + 1 if `i' > $DBntM { char $DB_ncat[note`i'] } else { parse "${DBnt`i'}", parse(" ") local a while "`1'" != "" { if "`1'" == "TS" { local 1 = substr("$S_DATE $S_TIME", 1, 17) } local a "`a'`1' " mac shift } char $DB_ncat[note`i'] "`a'" } } char $DB_ncat[note0] $DBntM global DBntN $DBntM if $DBntM { global DB_Stat "$DB_ncat: $DBntM notes saved" } else { global DB_Stat "$DB_ncat: all notes dropped" } end program define Huh cap confirm number 1 if "$DB_ncat" == "_dta" { exit } local varlist "req ex max(1)" qui cap parse "`*'" if !_rc { qui cap parse "`varlist'", parse(" ") } if _rc { window stopbox stop "Invalid notes category:" "$DB_ncat" } else { global DB_ncat "`varlist'" } end program define Display Huh $DB_ncat if _rc { exit } if $DBntN { di in ye "$DB_ncat:" local i 1 while `i' <= $DBntN { local b : char $DB_ncat[note`i'] if "`b'" != "" { di in gr %4.0g " `i'. ", "`b'" } local i = `i' + 1 } } end