# Description: advanced searching dialog procs command_search lappend menu(extras) command Search "/search" proc command_search {window line} { [namespace qualifiers [namespace origin command_search]]::SearchWindow set line [string trim $line] if {$line != ""} { .search.middle.pattern delete 0 end .search.middle.pattern insert 0 $line DoSearchWindow search } } proc SearchWindow {} { if {[winfo exists .search]} { wm deiconify .search raise .search focus .search.middle.pattern return } global prefs search toplevel .search wm title .search "RoxIRC Advanced Search" wm iconname .searc "Search \[RoxIRC\]" wm protocol .search WM_DELETE_WINDOW "[namespace current]::DoSearchWindow close" frame .search.bottom -bd [.search cget -bd] -relief raised button .search.bottom.save -text Save -command "SaveContents .search.top.text" button .search.bottom.done -text Done -command "[namespace current]::DoSearchWindow close" frame .search.middle -relief sunken -bd 1 button .search.middle.search -text Search -command "[namespace current]::DoSearchWindow search" tk_optionMenu .search.middle.opt search(opt) {} .search.middle.opt configure -width 15 -font [.search.middle.search cget -font] -bd 2 .search.middle.opt.menu configure -font [.search.middle.search cget -font] radiobutton .search.middle.r1 -text "Regexp" -variable search(type) -value regexp -font [.search.middle.search cget -font] radiobutton .search.middle.r2 -text "Exact" -variable search(type) -value exact -font [.search.middle.search cget -font] entry .search.middle.pattern -font [.search.middle.search cget -font] frame .search.top -class Textborder -relief sunken text .search.top.text -xscrollcommand ".search.top.scrollx set" -yscrollcommand ".search.top.scrolly set" -wrap none -state disabled scrollbar .search.top.scrollx -orient h -command ".search.top.text xview" scrollbar .search.top.scrolly -orient v -command ".search.top.text yview" pack .search.bottom.save -side left -padx 4 pack .search.bottom.done -side right -padx 4 pack .search.bottom -side bottom -fill x -ipadx 4 -ipady 3 pack .search.middle -side bottom -fill x -ipadx 4 -ipady 4 -padx 2 -pady 2 pack .search.middle.opt -side left -padx 4 pack .search.middle.r1 -side left pack .search.middle.r2 -side left -padx 4 pack .search.middle.pattern -side left -expand 1 -fill x pack .search.middle.search -side right -padx 4 pack .search.top -side top -fill both -expand 1 grid .search.top.text -sticky nesw -row 0 -column 0 grid .search.top.scrollx -row 1 -column 0 -sticky ew grid .search.top.scrolly -row 0 -column 1 -sticky ns grid rowconfigure .search.top 0 -weight 1 grid columnconfigure .search.top 0 -weight 1 bind .search.top.text "[namespace current]::DoSearchWindow double %x %y; break" bind .search ".search.bottom.done invoke" bind .search.middle.pattern ".search.middle.search invoke" bind .search.middle.pattern {HistoryUp %W} bind .search.middle.pattern {HistoryDown %W} bind .search "[namespace current]::DoSearchWindow refreshopts" array set ::history ".search,list {} .search,cur -1" array set search [list found {} type exact opt "All Windows"] wm withdraw .search update idletasks wm geometry .search [expr {round([winfo width .0] * .900)}]x[expr {round([winfo height .0] * .700)}] wm deiconify .search focus .search.middle.pattern } proc DoSearchWindow {cmd args} { global info search switch -exact -- $cmd { refreshopts { .search.middle.opt.menu delete 0 end foreach x {"All Windows" "All Channels" "All Chats"} {.search.middle.opt.menu add radiobutton -variable search(opt) -value $x -label $x} foreach x [activechannelwindows] {.search.middle.opt.menu add radiobutton -variable search(opt) -value $info(channel,$x) -label $info(channel,$x)} foreach x [querywindows] {.search.middle.opt.menu add radiobutton -variable search(opt) -value $info(nick,$x) -label $info(nick,$x)} foreach x [dccwindows] {.search.middle.opt.menu add radiobutton -variable search(opt) -value =$:dcc($x,nick) -label =$:dcc($x,nick)} .search.middle.opt.menu add radiobutton -variable search(opt) -value Status -label Status } search { .search.top.text configure -state normal .search.top.text delete 0.0 end foreach x [textwindows] {$info(text,$x) tag remove search 1.0 end} set s [string trim [.search.middle.pattern get]] set search(found) {} if {$s == ""} { .search.top.text configure -state disabled return } AddToHistory .search $s switch -exact -- $search(opt) { "All Windows" {set wins [textwindows]} "All Channels" {set wins [channelwindows]} "All Chats" {set wins [concat [querywindows] [dccwindows]]} default {set wins [windowname $search(opt)]} } foreach x $wins { set pos 1.0 while {[set f [$info(text,$x) search -forward -$search(type) -nocase -elide -count len -- $s $pos end]] != ""} { set pos [$info(text,$x) index $f+${len}c] $info(text,$x) tag add search $f $pos lappend search(found) [list $x [lindex [split $f .] 0]] } } set search(found) [lsort -unique $search(found)] foreach x $search(found) { .search.top.text insert end \n[$info(text,[lindex $x 0]) get "[lindex $x 1].0 linestart" "[lindex $x 1].0 lineend"] } .search.top.text delete 1.0 1.0+1l .search.top.text configure -state disabled } double { set i [lindex [split [.search.top.text index @[lindex $args 0],[lindex $args 1]] .] 0] if {$i == ""} {return} set i [lindex $search(found) [expr {$i - 1}]] set w [lindex $i 0] catch { raise $w focus $w $info(text,$w) see [lindex $i 1].0 bind $w "$info(text,$w) see end; bind $w {}" } } close { foreach x [textwindows] {$info(text,$x) tag remove search 1.0 end} destroy .search set search(found) {} } } } proc unload {} { catch {[namespace current]::DoSearchWindow close} array unset ::history .search,* catch {unset ::search} }