From 2a6b2511a3e445f479c35e13d503ec44b1ac06b7 Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Sat, 31 Aug 2013 12:03:14 +0000 Subject: [PATCH] Fixed. --- src/clojurefx/core.clj | 19 +++++++++---------- test/clojurefx/core_test.clj | 8 +++++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/clojurefx/core.clj b/src/clojurefx/core.clj index e29e534..6020583 100644 --- a/src/clojurefx/core.clj +++ b/src/clojurefx/core.clj @@ -11,20 +11,18 @@ Simple wrapper for Platform/runLater. You should use run-later. (defmacro run-later [& body] `(run-later* (fn [] ~@body))) -(declare ^:dynamic *nested?*) (defn run-now*" A modification of run-later waiting for the running method to return. You should use run-now. " [f] -(let [result (promise)] - (run-later - (deliver result (try (f) (catch Throwable e e)))) - @result)) +(if (= "JavaFX Application Thread" (.. Thread currentThread getName)) + (apply f []) + (let [result (promise)] + (run-later + (deliver result (try (f) (catch Throwable e e)))) + @result))) (defmacro run-now [& body] - (if *nested?* - `((fn [] ~@body)) - (binding [*nested?* true] - `(run-now* (fn [] ~@body))))) + `(run-now* (fn [] ~@body))) (defn- camel [in] (let [in (name in) @@ -106,7 +104,8 @@ Uses build and assigns the result to a symbol. ;; ### Event handling (defmacro add-listener " -Adds a listener to prop (\"Property\" gets added automatically) of obj, gets the value and passes it to fun. +Adds a listener to prop (\"Property\" gets added automatically) of obj, gets the value and passes it to fun.
+Example: `(add-listener inputfield focused #(println \"Focus change!\"))` "[obj prop fun] `(.. ~obj ~(symbol (str (name prop) "Property")) diff --git a/test/clojurefx/core_test.clj b/test/clojurefx/core_test.clj index 54c4716..28c3943 100644 --- a/test/clojurefx/core_test.clj +++ b/test/clojurefx/core_test.clj @@ -2,6 +2,8 @@ (:require [clojure.test :refer :all] [clojurefx.core :refer :all])) -(deftest a-test - (testing "FIXME, I fail." - (is (= 0 1)))) +(deftest runnow + (testing "Uses correct thread" + (is (= javafx.scene.Scene (type (build scene {}))))) + (testing "Nested run-nows" + (is (= javafx.scene.Scene (type (build scene {:root (build v-box {})}))))))