aboutsummaryrefslogtreecommitdiff
path: root/pd/tcl/dialog_find.tcl
blob: 92d58347790225ad0f3a13991bcdaf69ddbb8256 (plain)
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

package provide dialog_find 0.1

package require pd_bindings

namespace eval ::dialog_find:: {
    namespace export menu_dialog_find
}

# TODO figure out findagain
# TODO make targetlabel into a popup menu
# TODO make panel go away after a find

proc find_ok {mytoplevel} {::dialog_find::ok $mytoplevel} ;# TODO temp kludge
proc ::dialog_find::ok {mytoplevel} {
    # 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"
    } else {
        puts "search_window $search_window"
        set find_string [.find.entry get]
        if {$find_string ne ""} {
            pdsend "$search_window find $find_string"
        }
    }
}

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} {
    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 .]
        } else {
            foreach window $::menu_windowlist {
                if {[lindex $window 1] eq $focusedtoplevel} {
                    .find.frame.targetlabel configure -text [lindex $window 0]
                }
            }
        }
    }
}

# the find panel is opened from the menu and key bindings
proc ::dialog_find::menu_dialog_find {mytoplevel} {
    if {[winfo exists .find]} {
        wm deiconify .find
        raise .find
    } else {
        create_panel $mytoplevel
    }
}

proc ::dialog_find::create_panel {mytoplevel} {
    toplevel .find
    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"
    
    frame .find.frame
    pack .find.frame -side top -fill x -pady 7
    label .find.frame.searchin -text [_ "Search in"]
    label .find.frame.targetlabel -font "TkTextFont 14" 
    label .find.frame.for -text [_ "for:"]
    pack .find.frame.searchin .find.frame.targetlabel .find.frame.for -side left
    entry .find.entry -width 54 -font 18 -relief sunken \
        -highlightthickness 3 -highlightcolor blue
    focus .find.entry
    pack .find.entry -side top -padx 10
    
    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
    } else {
        pack .find.buttonframe .find.button -side right -padx 10 -pady 15
    }
    ::dialog_find::set_canvas_to_search $mytoplevel
}