aboutsummaryrefslogtreecommitdiff
path: root/pd/tcl/dialog_find.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'pd/tcl/dialog_find.tcl')
-rw-r--r--pd/tcl/dialog_find.tcl71
1 files changed, 47 insertions, 24 deletions
diff --git a/pd/tcl/dialog_find.tcl b/pd/tcl/dialog_find.tcl
index 92d58347..c7a708ae 100644
--- a/pd/tcl/dialog_find.tcl
+++ b/pd/tcl/dialog_find.tcl
@@ -4,42 +4,62 @@ package provide dialog_find 0.1
package require pd_bindings
namespace eval ::dialog_find:: {
+ # store the state of the "Match whole word only" check box
+ variable wholeword_button 0
+ # if the search hasn't changed, then the Find button sends "findagain"
+ variable previous_wholeword_button 0
+ variable previous_findstring ""
+
namespace export menu_dialog_find
}
-# TODO figure out findagain
-# TODO make targetlabel into a popup menu
-# TODO make panel go away after a find
+# TODO make find panel as small as possible, being topmost means its findable
+# TODO (GNOME/Windows) find panel should retain focus after a find
+# TODO (Mac OS X) hide panel after success, but stay if the find was unsuccessful
-proc find_ok {mytoplevel} {::dialog_find::ok $mytoplevel} ;# TODO temp kludge
proc ::dialog_find::ok {mytoplevel} {
+ variable wholeword_button
+ variable previous_wholeword_button
+ variable previous_findstring
# find will be on top, so use the previous window that was on top
set search_window [lindex [wm stackorder .] end-1]
- if {$search_window eq "."} {
- puts "search pd window not implemented yet"
+ puts "search_window $search_window"
+ set findstring [.find.entry get]
+ if {$findstring eq ""} {return}
+ if {$search_window eq ".pdwindow"} {
+ set matches [.pdwindow.text search -all -nocase -- $findstring 0.0]
+ .pdwindow.text tag delete sel
+ foreach match $matches {
+ .pdwindow.text tag add sel $match "$match wordend"
+ }
+ .pdwindow.text see [lindex $matches 0]
} else {
- puts "search_window $search_window"
- set find_string [.find.entry get]
- if {$find_string ne ""} {
- pdsend "$search_window find $find_string"
+ if {$findstring eq $previous_findstring \
+ && $wholeword_button == $previous_wholeword_button} {
+ pdsend "$search_window findagain"
+ } else {
+ # TODO switch back to this for 0.43:
+ #pdsend "$search_window find $findstring $wholeword_button"
+ pdsend "$search_window find $findstring"
+ set previous_findstring $findstring
+ set previous_wholeword_button $wholeword_button
}
}
}
-proc find_cancel {mytoplevel} {::dialog_find::cancel $mytoplevel} ;# TODO temp kludge
proc ::dialog_find::cancel {mytoplevel} {
wm withdraw .find
}
proc ::dialog_find::set_canvas_to_search {mytoplevel} {
+ # TODO rewrite using global $::focused_window
if {[winfo exists .find.frame.targetlabel]} {
set focusedtoplevel [winfo toplevel [lindex [wm stackorder .] end]]
if {$focusedtoplevel eq ".find"} {
set focusedtoplevel [winfo toplevel [lindex [wm stackorder .] end-1]]
}
- # TODO this text should be based on $::menu_windowlist
- if {$focusedtoplevel eq "."} {
- .find.frame.targetlabel configure -text [wm title .]
+ if {$focusedtoplevel eq ".pdwindow"} {
+ .find.frame.targetlabel configure -text [wm title .pdwindow]
} else {
foreach window $::menu_windowlist {
if {[lindex $window 1] eq $focusedtoplevel} {
@@ -51,26 +71,25 @@ proc ::dialog_find::set_canvas_to_search {mytoplevel} {
}
# the find panel is opened from the menu and key bindings
-proc ::dialog_find::menu_dialog_find {mytoplevel} {
+proc ::dialog_find::menu_find_dialog {mytoplevel} {
if {[winfo exists .find]} {
wm deiconify .find
raise .find
} else {
- create_panel $mytoplevel
+ create_dialog $mytoplevel
}
}
-proc ::dialog_find::create_panel {mytoplevel} {
- toplevel .find
+proc ::dialog_find::create_dialog {mytoplevel} {
+ toplevel .find -class DialogWindow
wm title .find [_ "Find"]
wm geometry .find =475x125+150+150
- wm resizable .find 0 0
- if {[catch {wm attributes .find -topmost}]} {puts stderr ".find -topmost failed"}
.find configure
- ::pd_bindings::panel_bindings .find "find"
+ if {$::windowingsystem eq "aqua"} {$mytoplevel configure -menu .menubar}
+ ::pd_bindings::dialog_bindings .find "find"
frame .find.frame
- pack .find.frame -side top -fill x -pady 7
+ pack .find.frame -side top -fill x -pady 1
label .find.frame.searchin -text [_ "Search in"]
label .find.frame.targetlabel -font "TkTextFont 14"
label .find.frame.for -text [_ "for:"]
@@ -80,15 +99,19 @@ proc ::dialog_find::create_panel {mytoplevel} {
focus .find.entry
pack .find.entry -side top -padx 10
+ checkbutton .find.wholeword -variable ::dialog_find::wholeword_button \
+ -text [_ "Match whole word only"] -anchor w
+ pack .find.wholeword -side top -padx 30 -pady 3 -fill x
+
frame .find.buttonframe -background yellow
button .find.button -text [_ "Find"] -default active -width 9 \
-command "::dialog_find::ok $mytoplevel"
if {$::windowingsystem eq "x11"} {
button .find.close -text [_ "Close"] -default normal -width 9 \
-command "::dialog_find::cancel $mytoplevel"
- pack .find.buttonframe .find.button .find.close -side right -padx 10 -pady 15
+ pack .find.buttonframe .find.button .find.close -side right -padx 10 -pady 3
} else {
- pack .find.buttonframe .find.button -side right -padx 10 -pady 15
+ pack .find.buttonframe .find.button -side right -padx 10 -pady 3
}
::dialog_find::set_canvas_to_search $mytoplevel
}