Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record config preferences #104

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
(only-in srfi/13
string-contains-ci
string-null?)
"config.rkt"
"db.rkt"
"embed.rkt"
"files.rkt")
Expand Down Expand Up @@ -388,7 +389,7 @@
(define status-bar-position (make-parameter #f))
(define status-bar-size (make-parameter #f))
(define incoming-tags (make-parameter ""))
(define want-animation? (make-parameter #f))
(define want-animation? (make-parameter (hash-ref config-hash 'animation?)))

(define/contract (animation-callback canvas dc lst)
((is-a?/c canvas%) (is-a?/c dc<%>) (listof (is-a?/c bitmap%)) . -> . void?)
Expand Down
23 changes: 23 additions & 0 deletions config.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#lang racket/base
; config.rkt
(require json "files.rkt")
(provide (all-defined-out))

(define config-hash
(if (file-exists? config-file)
(let ([in (open-input-file config-file)])
(define js (read-json in))
(close-input-port in)
(hash-copy js))
(make-hasheq
'((animation? . #f)
(browse-regex? . #f)
(search-exact? . #f)
(search-type . "or")))))

(define (save-config)
(let ([out (open-output-file config-file
#:mode 'binary
#:exists 'truncate/replace)])
(write-json config-hash out)
(close-output-port out)))
1 change: 1 addition & 0 deletions files.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"Library/Application Support/ivy")]))

(define master-file (build-path ivy-path "catalog.sqlite"))
(define config-file (build-path ivy-path "config.rktd"))

; path for cached thumbnails
; - on *NIX, use ~/.cache/thumbnails/normal
Expand Down
15 changes: 9 additions & 6 deletions frame.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
txexpr
xml
"base.rkt"
"config.rkt"
"db.rkt"
"db-statistics.rkt"
"embed.rkt"
Expand Down Expand Up @@ -501,12 +502,14 @@
[checked (want-animation?)]
[callback (λ (i e)
(want-animation? (send i is-checked?))
(when (and (not (equal? (image-path) +root-path+))
(or (and (gif? (image-path))
(gif-animated? (image-path)))
(and (flif? (image-path))
(flif-animated? (image-path)))))
(load-image (image-path))))]))
(hash-set! config-hash 'animation? (want-animation?))
(save-config)
(when (and (not (equal? (image-path) +root-path+))
(or (and (gif? (image-path))
(gif-animated? (image-path)))
(and (flif? (image-path))
(flif-animated? (image-path)))))
(load-image (image-path))))]))

(define ivy-menu-bar-view-tag-browser
(new menu-item%
Expand Down
1 change: 1 addition & 0 deletions main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
txexpr
xml
"base.rkt"
"config.rkt"
"db.rkt"
"embed.rkt"
"error-log.rkt"
Expand Down
20 changes: 13 additions & 7 deletions search-dialog.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
racket/gui/base
racket/list
"base.rkt"
"config.rkt"
"db.rkt"
"search-results.rkt")
(provide search-tag-dialog
Expand All @@ -12,10 +13,7 @@
(define (ok-callback)
(send search-tag-dialog show #f)
(define tags (tfield->list search-tfield))
(define search-type
(string->symbol
(send type-rbox get-item-label
(send type-rbox get-selection))))
(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
Expand Down Expand Up @@ -82,9 +80,11 @@
(new check-box%
[parent checkbox-pane]
[label "Exact"]
[value #f]
[value (hash-ref config-hash 'search-exact?)]
[callback (λ (button event)
(exact-search? (send button get-value)))]))
(exact-search? (send button get-value))
(hash-set! config-hash 'search-exact? (exact-search?))
(save-config))]))

(define type-pane
(new pane%
Expand All @@ -96,7 +96,13 @@
[parent type-pane]
[label "Search type"]
[choices '("and" "or")]
[style '(horizontal)]))
[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%
Expand Down
13 changes: 8 additions & 5 deletions tag-browser.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
racket/string
(only-in srfi/13 string-contains-ci)
"base.rkt"
"config.rkt"
"db.rkt"
"embed.rkt"
"files.rkt"
Expand Down Expand Up @@ -233,11 +234,11 @@

; begin tag filtering/search definitions

(define use-regex? (make-parameter #f))
(define use-regex? (hash-ref config-hash 'browse-regex?))

(define (filter-query tfield)
(or (send (send tfield get-editor) get-text)
(if (use-regex?)
(if use-regex?
".*"
"")))

Expand All @@ -248,7 +249,7 @@

(define (filter-tags filter-str regex)
(λ (tag)
(if (use-regex?)
(if use-regex?
(regexp-match filter-str tag)
(string-contains-ci tag filter-str))))

Expand All @@ -263,9 +264,11 @@
(new check-box%
[parent tag-filter-layout]
[label "Regex"]
[value #f]
[value use-regex?]
[callback (λ (chk evt)
(use-regex? (not (use-regex?)))
(set! use-regex? (not use-regex?))
(hash-set! config-hash 'browse-regex? use-regex?)
(save-config)
(update-tag-browser))]))

; end tag filtering/search definitions
Expand Down