Skip to content

Commit

Permalink
Use icons instead of text for doc-lb list items, so they are easier t…
Browse files Browse the repository at this point in the history
…o visually separate

I put the icon images in a new resource directory.  I believe the
project.clj change I made is specific to Leiningen version 2.  It
doesn't seem to work for Leiningen version 1.
  • Loading branch information
jafingerhut committed May 17, 2012
1 parent ef12a4d commit 1e5b9a9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 18 deletions.
1 change: 1 addition & 0 deletions project.clj
Expand Up @@ -18,4 +18,5 @@
:jvm-opts ~(if (= (System/getProperty "os.name") "Mac OS X") ["-Xdock:name=Clj-NS-Browser"] [])
:java-source-paths ["src"]
:java-source-path "src"
:resource-paths ["resource"]
:main clj-ns-browser.core)
Binary file added resource/icon-comments.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/icon-doc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/icon-examples.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/icon-meta.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/icon-see-also.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/icon-source.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/icon-value.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 61 additions & 18 deletions src/clj_ns_browser/browser.clj
Expand Up @@ -209,11 +209,52 @@
:special-forms ns-special-forms %1 %2 %3)
})

(def doc-lb-value-list ["Doc" "Source" "Examples"
;; Create maps from names of doc-lb entries to files containing icon
;; images, and the other direction (to efficiently map selections back
;; to names, which are used everywhere else in the code).

;;(def icon-dir "file:/Users/jafinger/clj/clj-ns-browser/resources/")
;;
;;(def name-to-icon-desc
;; {"Doc" (str icon-dir "icon-doc.png"),
;; "Source" (str icon-dir "icon-source.png"),
;; "Examples" (str icon-dir "icon-examples.png"),
;; "Comments" (str icon-dir "icon-comments.png"),
;; "See alsos" (str icon-dir "icon-see-also.png"),
;; "Value" (str icon-dir "icon-value.png"),
;; "Meta" (str icon-dir "icon-meta.png")})

(def name-to-icon-desc
{"Doc" (str (clojure.java.io/resource "icon-doc.png")),
"Source" (str (clojure.java.io/resource "icon-source.png")),
"Examples" (str (clojure.java.io/resource "icon-examples.png")),
"Comments" (str (clojure.java.io/resource "icon-comments.png")),
"See alsos" (str (clojure.java.io/resource "icon-see-also.png")),
"Value" (str (clojure.java.io/resource "icon-value.png")),
"Meta" (str (clojure.java.io/resource "icon-meta.png"))})

(defn update-vals-in-map [m f]
(reduce (fn [m [k v]]
(assoc m k (f v)))
m m))

(def name-to-icon (update-vals-in-map name-to-icon-desc icon))

(def icon-desc-to-name (set/map-invert name-to-icon-desc))

(defn icon-to-name [i]
(icon-desc-to-name (str i)))

(def doc-lb-name-list ["Doc" "Source" "Examples"
"Comments" "See alsos" "Value" "Meta"])
(def doc-lb-value-list (map name-to-icon doc-lb-name-list))
(def doc-lb-value-set (set doc-lb-value-list))
(def doc-lb-cur-order (atom doc-lb-value-list))

;; Needed for handling drag and drop to reorder items in the doc-lb
;; listbox.
(def icon-flavor (seesaw.dnd/local-object-flavor javax.swing.ImageIcon))


(def all-buttons-with-atoms
"Used to auto-generate atoms and '-atom' keywords"
Expand Down Expand Up @@ -608,7 +649,7 @@
:drop-mode :insert
:transfer-handler
(seesaw.dnd/default-transfer-handler
:import [seesaw.dnd/string-flavor
:import [icon-flavor
(fn [{:keys [target data drop? drop-location] :as m}]
;; Ignore anything dropped onto the list that is
;; not in the original set of list elements.
Expand All @@ -622,7 +663,7 @@
(reset! doc-lb-cur-order new-order)
(config! target :model new-order))))]
:export {:actions (constantly :copy)
:start (fn [c] [seesaw.dnd/string-flavor (selection c)])}))
:start (fn [c] [icon-flavor (selection c)])}))
(config! (id :edit-btn) :enabled? false)
(config! (id :browse-btn) :enabled? false)
(config! (id :clojuredocs-online-rb) :selected? true)
Expand Down Expand Up @@ -653,7 +694,7 @@
(config! (id :doc-ta) :text " ")
(selection! (id :ns-cbx) "loaded")
(selection! (id :vars-cbx) "Vars - public")
(selection! (id :doc-lb) "Doc")))
(selection! (id :doc-lb) (name-to-icon "Doc"))))


(defn init-after-bind
Expand Down Expand Up @@ -687,7 +728,7 @@
))
(selection! (id :ns-cbx) "loaded")
(selection! (id :vars-cbx) "Vars - public")
(selection! (id :doc-lb) "Doc"))))
(selection! (id :doc-lb) (name-to-icon "Doc")))))


(defn bind-all
Expand Down Expand Up @@ -907,15 +948,16 @@
(b/selection (id :doc-lb) {:multi? true})
vars-lb-refresh-atom])
(b/filter (fn [[doc-tf doc-lb]]
;; (printf "(class doc-lb)=%s doc-lb='%s'\n"
;; (class doc-lb) (seq doc-lb))
;; (printf "(class doc-lb)=%s (seq doc-lb)='%s' (map ... doc-lb)='%s'\n"
;; (class doc-lb) (seq doc-lb)
;; (seq (map icon-to-name doc-lb)))
;; (flush)
(not (or (nil? doc-tf) (= "" doc-tf)
(nil? doc-lb) (= "" doc-lb)))))
(b/transform
(fn [[doc-tf doc-lb]]
(future
(let [s (render-doc-text doc-tf doc-lb)]
(let [s (render-doc-text doc-tf (map icon-to-name doc-lb))]
(when-not (= s (config (id :doc-ta) :text))
(invoke-soon (config! (id :doc-ta) :text s))))))))
;;
Expand Down Expand Up @@ -950,18 +992,18 @@
;; new text in doc-ta => dis/enable browser button
(b/bind
(id :doc-ta)
(b/transform (fn [o] (selection (id :doc-lb))))
(b/transform (fn [o] (map icon-to-name
(selection (id :doc-lb) {:multi? true}))))
(b/transform (fn [o]
(case o
("Examples" "See alsos" "Comments")
(if (empty? (set/intersection (set o)
#{"Examples" "See alsos" "Comments"}))
(invoke-soon (config! (id :browse-btn) :enabled? true))
(if-let [fqn (config (id :doc-tf) :text)]
(future
(let [url (clojuredocs-url fqn)
r (if url true false)]
(invoke-soon
(config! (id :browse-btn) :enabled? r)))))

(invoke-soon (config! (id :browse-btn) :enabled? true))))))
(config! (id :browse-btn) :enabled? r)))))))))
;;
(b/bind
(apply b/funnel [(id :doc-tf)
Expand All @@ -971,7 +1013,7 @@
;; (printf "update edit-btn: (class o)=%s o='%s'\n"
;; (class o) (seq o))
;; (flush)
(let [doc-set (set o)]
(let [doc-set (set (map icon-to-name o))]
(or (doc-set "Source") (doc-set "All")))))
(b/transform (fn [o]
(when o (if (meta-when-file (config (id :doc-tf) :text))
Expand All @@ -985,7 +1027,8 @@
(b/bind
(apply b/funnel [(id :doc-tf)
(b/selection (id :doc-lb) {:multi? true})])
(b/transform (fn [[doc-tf doc-lb]] [(config (id :doc-tf) :text) doc-lb]))
(b/transform (fn [[doc-tf doc-lb]] [(config (id :doc-tf) :text)
(map icon-to-name doc-lb)]))
(b/transform (fn [[fqn doc-lb-sel]]
(let [doc-set (set doc-lb-sel)]
(if (or (doc-set "Value") (doc-set "All"))
Expand All @@ -1003,7 +1046,7 @@
(b/selection (id :doc-lb) {:multi? true})
(b/transform (fn [o]
(when (= (.getName (type (id :doc-ta))) "org.fife.ui.rsyntaxtextarea.RSyntaxTextArea")
(let [selected-set (set o)]
(let [selected-set (set (map icon-to-name o))]
(if (= selected-set
(set/intersection selected-set
#{"Source" "Examples" "Meta"}))
Expand All @@ -1015,7 +1058,7 @@
(id :browse-btn-atom)
(b/notify-soon)
(b/transform (fn [& oo]
(let [o (selection (id :doc-lb))]
(let [o (icon-to-name (selection (id :doc-lb)))]
(when-let [fqn (config (id :doc-tf) :text)]
(future
(case o
Expand Down

0 comments on commit 1e5b9a9

Please sign in to comment.