📄 notes.tcl
字号:
set selection [$w.contact.box curselection] set ::notes::selectedcontact $selection set ::notes::selected "-1" set contact [lindex $::notes::contacts $selection] $w.right.notes.box delete 0 end if { [file exists [file join $HOME notes ${contact}_note.xml]] } { ::notes::get_Note $contact foreach note $::notes::notes { set subject [lindex $note 2] $w.right.notes.box insert end "$subject" } } else { set ::notes::notes "" } set ::notes::email $contact set nickname "[trunc [::abook::getDisplayNick $contact] $w 410 sboldf]" $w.right.contact.right.txt configure -text "$contact\n$nickname" -font sboldf $w.right.button.new configure -state normal $w.right.note.txt configure -state normal $w.right.note.txt delete 0.0 end $w.right.note.txt configure -state disabled $w.right.subject.txt configure -state normal $w.right.subject.txt delete 0.0 end $w.right.subject.txt configure -state disabled $w.right.info.date configure -text "[trans clicktoadd]" $w.right.button.edit configure -state disabled $w.right.button.delete configure -state disabled #Add binding for the subject and note field bind $w.right.subject.txt <Button1-ButtonRelease> "::notes::Note_New" bind $w.right.note.txt <Button1-ButtonRelease> "::notes::Note_New" ::notes::Update_Contact_Background }#//////////////////////////////////////////////////////////////# When we delete a note proc Note_Delete { } { global HOME set w ".notemanager" set selection $::notes::selected set ::notes::notes [lreplace $::notes::notes $selection $selection] ::notes::Notes_Save ::notes::Update_Notes $w.right.notes.box selection set $selection if { $selection == [.notemanager.right.notes.box size] } { $w.right.button.edit configure -state disabled $w.right.button.delete configure -state disabled } if { [.notemanager.right.notes.box size] == 0 } { file delete [file join $HOME notes ${::notes::email}_note.xml] set idx [lsearch $::notes::contactswithnotes $::notes::email] set ::notes::contactswithnotes [lreplace $::notes::contactswithnotes $idx $idx] } }#//////////////////////////////////////////////////////////////# When we edit a note proc Note_Edit { } { set w ".notemanager" #Remove binding on theses 2 textbox bind $w.right.subject.txt <Button1-ButtonRelease> "" bind $w.right.note.txt <Button1-ButtonRelease> "" $w.right.notes.box configure -state disabled $w.contact.box configure -state disabled $w.right.note.txt configure -state normal $w.right.subject.txt configure -state normal $w.right.info.date configure -text "[trans editcontent]" pack forget $w.right.button.delete pack forget $w.right.button.new pack forget $w.right.button.edit pack configure $w.right.button.save_edit -side right -padx 3 -pady 3 pack configure $w.right.button.cancel -side right -padx 3 -pady 3 } proc Note_SaveEdit { } { set w ".notemanager" set selection $::notes::selected set contact $::notes::email set created "[lindex [lindex $::notes::notes $selection] 0]" set modified "[clock format [clock seconds] -format "%D - %T"]" set subject "[.notemanager.right.subject.txt get 1.0 1.end]" set note "[.notemanager.right.note.txt get 0.0 {end - 1 chars}]" if { $subject == "" } { $w.right.warning.txt configure -text "[trans subjectrequired]" -foreground red } else { set ::notes::notes [lreplace $::notes::notes $selection $selection [list "$created" "$modified" "$subject" "$note"]] ::notes::Notes_Save ::notes::Update_Notes ::notes::Notes_Selected_Note choose $::notes::selected } bind $w.right.subject.txt <Button1-ButtonRelease> "::notes::Note_New" bind $w.right.note.txt <Button1-ButtonRelease> "::notes::Note_New" }#//////////////////////////////////////////////////////////////# When we create a new note proc Note_New { } { set w ".notemanager" #Remove binding on theses 2 textbox bind $w.right.subject.txt <Button1-ButtonRelease> "" bind $w.right.note.txt <Button1-ButtonRelease> "" $w.right.notes.box configure -state disabled $w.contact.box configure -state disabled $w.right.note.txt configure -state normal $w.right.note.txt delete 0.0 end $w.right.subject.txt configure -state normal $w.right.subject.txt delete 0.0 end $w.right.info.date configure -text "[trans inserttextnote]" pack forget $w.right.button.delete pack forget $w.right.button.new pack forget $w.right.button.edit pack configure $w.right.button.save -side right -padx 3 -pady 3 pack configure $w.right.button.cancel -side right -padx 3 -pady 3 focus $w.right.subject.txt } proc Note_SaveNew { } { set w ".notemanager" set contact $::notes::email set time "[clock format [clock seconds] -format "%D - %T"]" set subject "[$w.right.subject.txt get 1.0 1.end]" set note "[.notemanager.right.note.txt get 0.0 {end - 1 chars}]" if { $subject == "" } { $w.right.warning.txt configure -text "[trans subjectrequired]" -foreground red -font sboldf } else { set ::notes::notes [lappend ::notes::notes [list "$time" "$time" "$subject" "$note"]] ::notes::Notes_Save ::notes::Update_Notes ::notes::Notes_Selected_Note last if { [lsearch $::notes::contactswithnotes $::notes::email] == -1 } { set ::notes::contactswithnotes [lappend ::notes::contactswithnotes $::notes::email] } } bind $w.right.subject.txt <Button1-ButtonRelease> "::notes::Note_New" bind $w.right.note.txt <Button1-ButtonRelease> "::notes::Note_New" }#//////////////////////////////////////////////////////////////# When we cancel what we were doing (editing or creating a note) proc Note_Cancel { } { set w ".notemanager" pack forget $w.right.button.save pack forget $w.right.button.save_edit pack forget $w.right.button.cancel pack configure $w.right.button.edit -side left -padx 3 -pady 3 pack configure $w.right.button.delete -side right -padx 3 -pady 3 pack configure $w.right.button.new -side right -padx 3 -pady 3 $w.right.notes.box configure -state normal $w.contact.box configure -state normal $w.right.warning.txt configure -text "" bind $w.right.subject.txt <Button1-ButtonRelease> "::notes::Note_New" bind $w.right.note.txt <Button1-ButtonRelease> "::notes::Note_New" ::notes::Update_Notes ::notes::Notes_Selected_Note choose $::notes::selected }#//////////////////////////////////////////////////////////////# Save all the notes of a contact proc Notes_Save { } { global HOME set email $::notes::email set w ".notemanager" set file [file join $HOME notes ${email}_note.xml] if { ![file isdirectory [file join $HOME notes]] } { file mkdir [file join $HOME notes] } set file_id [open $file w] fconfigure $file_id -encoding utf-8 puts $file_id "<?xml version=\"1.0\"?>\n\n<notes>\n" foreach note $::notes::notes { set created [lindex $note 0] set modified [lindex $note 1] set subject [lindex $note 2] set content [lindex $note 3] puts -nonewline $file_id "\t<note>\n\t\t<created>$created</created>\n\t\t<modified>$modified</modified>\n\t\t<subject>$subject</subject>\n\t\t<content>$content</content>\n\t</note>\n" } puts $file_id "</notes>" close $file_id $w.right.subject.txt configure -state disabled $w.right.note.txt configure -state disabled pack forget $w.right.button.save pack forget $w.right.button.save_edit pack forget $w.right.button.cancel pack configure $w.right.button.edit -side left -padx 3 -pady 3 pack configure $w.right.button.delete -side right -padx 3 -pady 3 pack configure $w.right.button.new -side right -padx 3 -pady 3 $w.right.notes.box configure -state normal $w.contact.box configure -state normal $w.right.warning.txt configure -text "" ::notes::Notes_Selected_Note }#//////////////////////////////////////////////////////////////# Update the display of the notes proc Update_Notes { } { global HOME set w ".notemanager" set contact $::notes::email $w.right.notes.box delete 0 end if { [file exists [file join $HOME notes ${contact}_note.xml]] } { ::notes::get_Note $contact foreach note $::notes::notes { set subject [lindex $note 2] $w.right.notes.box insert end "$subject" } } else { set ::notes::notes "" } }#//////////////////////////////////////////////////////////////# Update the background of the items of the contact listproc Update_Contact_Background { } { for {set i 0} {$i< [llength $::notes::contacts]} {incr i} { if { $i == $::notes::selectedcontact } { .notemanager.contact.box itemconfigure $i -background gray } elseif { [lsearch $::notes::contactswithnotes [lindex $::notes::contacts $i]] != -1 } { .notemanager.contact.box itemconfigure $i -background #DDF3FE } else { .notemanager.contact.box itemconfigure $i -background white } } }#//////////////////////////////////////////////////////////////#proc HideContact { } { set w ".notemanager" pack forget $w.contact #pack configure $w.right -side right -fill both -expand true# wm geometry $w 550x526 $w.right.contact.left.showhide configure -image show bind $w.right.contact.left.showhide <Button1-ButtonRelease> "::notes::ShowContact" }proc ShowContact { } { set w ".notemanager" pack configure $w.contact -side left -fill y# wm geometry $w 660x526 $w.right.contact.left.showhide configure -image hide bind $w.right.contact.left.showhide <Button1-ButtonRelease> "::notes::HideContact" }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -