-
Notifications
You must be signed in to change notification settings - Fork 3
/
search-dialog.rkt
142 lines (131 loc) · 4.49 KB
/
search-dialog.rkt
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#lang racket/base
; search-dialog.rkt
(require racket/class
racket/gui/base
racket/list
"base.rkt"
"config.rkt"
"db.rkt"
"search-results.rkt")
(provide search-tag-dialog
search-tfield)
(define (ok-callback)
(send search-tag-dialog show #f)
(define tags (tfield->list search-tfield))
(define search-type (string->symbol (hash-ref config-hash 'search-type)))
; make sure there aren't any nonexistant files in the database
(clean-db!)
(define imgs
(if (empty? tags)
; table-column: (or/c (listof path?) empty?)
(table-column 'images 'Path)
(if (exact-search?)
(search-db-exact search-type tags)
(search-db-inexact search-type tags))))
(define exclude-tags (tfield->list exclude-tfield))
(cond [(empty? imgs)
(display-nil-results-alert)
(send (send search-tfield get-editor) select-all)
(send search-tag-dialog center 'both)
(send search-tag-dialog show #t)]
[else
(if (empty? exclude-tags)
(display-tags (sort imgs path<?))
(if (exact-search?)
(display-tags (sort (exclude-search-exact imgs exclude-tags) path<?))
(display-tags (sort (exclude-search-inexact imgs exclude-tags) path<?))))]))
(define search-tag-dialog
(new dialog%
[label "Ivy - Search Tags"]
[width 400]
[height 100]
[style '(close-button)]))
(define search-tfield
(new text-field%
[parent search-tag-dialog]
[label "Search tags: "]
[callback
(λ (tf evt)
(when (and
(eq? (send evt get-event-type) 'text-field-enter)
(not (string-null? (send tf get-value))))
(ok-callback)))]))
(define exclude-tfield
(new text-field%
[parent search-tag-dialog]
[label "Exclude tags: "]
[callback
(λ (tf evt)
(when (and
(eq? (send evt get-event-type) 'text-field-enter)
(not (string-null? (send tf get-value))))
(ok-callback)))]))
(define modifier-hpanel
(new horizontal-panel%
[parent search-tag-dialog]
[alignment '(center center)]
[stretchable-height #f]))
(define checkbox-pane
(new pane%
[parent modifier-hpanel]
[alignment '(right center)]))
(define exact-checkbox
(new check-box%
[parent checkbox-pane]
[label "Exact"]
[value (hash-ref config-hash 'search-exact?)]
[callback (λ (button event)
(exact-search? (send button get-value))
(hash-set! config-hash 'search-exact? (exact-search?))
(save-config))]))
(define type-pane
(new pane%
[parent modifier-hpanel]
[alignment '(center center)]))
(define type-rbox
(new radio-box%
[parent type-pane]
[label "Search type"]
[choices '("and" "or")]
[selection (let ([s (hash-ref config-hash 'search-type)])
(if (string=? s "and") 0 1))]
[style '(horizontal)]
[callback (λ (rbox evt)
(define search-type (send rbox get-item-label (send rbox get-selection)))
(hash-set! config-hash 'search-type search-type)
(save-config))]))
(define button-hpanel
(new horizontal-panel%
[parent search-tag-dialog]
[alignment '(right center)]
[stretchable-height #f]))
; make the button position consistent with the host system
; e.g. A Windows host will have the Ok button before Cancel
; while on *NIX it will be the other way around
(void
(cond [(system-position-ok-before-cancel?)
(new button%
[parent button-hpanel]
[label "&Ok"]
[callback
(λ (button event)
(unless (string-null? (send search-tfield get-value))
(ok-callback)))])
(new button%
[parent button-hpanel]
[label "&Cancel"]
[callback (λ (button event)
(send search-tag-dialog show #f))])]
[else
(new button%
[parent button-hpanel]
[label "&Cancel"]
[callback (λ (button event)
(send search-tag-dialog show #f))])
(new button%
[parent button-hpanel]
[label "&Ok"]
[callback
(λ (button event)
(unless (string-null? (send search-tfield get-value))
(ok-callback)))])]))