Skip to content
Browse files

Fixed pref/atom binding test

  • Loading branch information...
1 parent 164073c commit 9007c2d0e3806a880d0f56026d1e26efc4579ef2 @daveray committed
Showing with 14 additions and 10 deletions.
  1. +1 −1 src/seesaw/examples/behave.clj
  2. +1 −1 src/seesaw/examples/xyz_panel.clj
  3. +10 −6 src/seesaw/pref.clj
  4. +2 −2 test/seesaw/test/pref.clj
View
2 src/seesaw/examples/behave.clj
@@ -31,5 +31,5 @@
pack!
show!)))
-(-main)
+;(-main)
View
2 src/seesaw/examples/xyz_panel.clj
@@ -56,5 +56,5 @@
:north "Demonstration of an xyz-panel with draggable widgets. Try dragging one!"
:center (make-panel))
:width 600 :height 600))))
-(-main)
+;(-main)
View
16 src/seesaw/pref.clj
@@ -24,6 +24,9 @@ namespace."
([ns]
`(preferences-node* ~ns)))
+(defn- serialize-value [v]
+ (binding [*print-dup* true] (pr-str v)))
+
(defn bind-preference-to-atom*
"Bind atom to preference by syncing it
with (java.util.prefs.Preferences/userRoot) for the specified
@@ -33,16 +36,17 @@ namespace."
key must be printable per PRINT-DUP and readable per READ-STRING for
it to be used with the preferences store."
[ns key atom]
- (let [v (read-string (.get (preferences-node ns) (pr-str key) (binding [*print-dup* true] (pr-str @atom))))]
- (when (not= @atom v)
- (reset! atom v))
+ (let [key (serialize-value key)
+ node (preferences-node ns)
+ v (read-string (.get node key (serialize-value @atom)))]
(doto atom
+ (reset! v)
(add-watch (keyword (gensym "pref-atom-watcher"))
(fn [k r o n]
+ (println k r o n ns)
(when (not= o n)
- (.put (preferences-node ns)
- (binding [*print-dup* true] (pr-str key))
- (binding [*print-dup* true] (pr-str n)))))))))
+ (.put node key (serialize-value n))
+ (.sync node)))))))
(defmacro bind-preference-to-atom
"Bind atom to preference by syncing it
View
4 test/seesaw/test/pref.clj
@@ -17,7 +17,7 @@
(it "should return an atom with nil as its default value"
(do (.remove (preferences-node) (pr-str "key"))
(let [atom (preference-atom "key")]
- (expect (= @atom nil)))))
+ (expect (nil? @atom)))))
(it "should return an atom with the specified default value"
(do (.remove (preferences-node) (pr-str "key"))
(let [atom (preference-atom "key" 'some-value)]
@@ -26,4 +26,4 @@
(do (.remove (preferences-node) (pr-str "key"))
(let [atom (preference-atom "key")]
(reset! atom 'new-value)
- (expect (= (read-string (.get (preferences-node) "key" "nil")) 'new-value))))))
+ (expect (= (read-string (.get (preferences-node) (pr-str "key") "nil")) 'new-value))))))

0 comments on commit 9007c2d

Please sign in to comment.
Something went wrong with that request. Please try again.