Skip to content
This repository
Browse code

Use icons instead of text for doc-lb list items, so they are easier t…

…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...
commit 1e5b9a9cf6d99ed004181b779f29d8121909565c 1 parent ef12a4d
Andy Fingerhut authored May 14, 2012
1  project.clj
@@ -18,4 +18,5 @@
18 18
   :jvm-opts ~(if (= (System/getProperty "os.name") "Mac OS X") ["-Xdock:name=Clj-NS-Browser"] [])
19 19
   :java-source-paths ["src"]
20 20
   :java-source-path "src"
  21
+  :resource-paths ["resource"]
21 22
   :main clj-ns-browser.core)
BIN  resource/icon-comments.png
BIN  resource/icon-doc.png
BIN  resource/icon-examples.png
BIN  resource/icon-meta.png
BIN  resource/icon-see-also.png
BIN  resource/icon-source.png
BIN  resource/icon-value.png
79  src/clj_ns_browser/browser.clj
@@ -209,11 +209,52 @@
209 209
                                               :special-forms ns-special-forms %1 %2 %3)
210 210
                             })
211 211
 
212  
-(def doc-lb-value-list ["Doc" "Source" "Examples"
  212
+;; Create maps from names of doc-lb entries to files containing icon
  213
+;; images, and the other direction (to efficiently map selections back
  214
+;; to names, which are used everywhere else in the code).
  215
+
  216
+;;(def icon-dir "file:/Users/jafinger/clj/clj-ns-browser/resources/")
  217
+;;
  218
+;;(def name-to-icon-desc
  219
+;;  {"Doc" (str icon-dir "icon-doc.png"),
  220
+;;   "Source" (str icon-dir "icon-source.png"),
  221
+;;   "Examples" (str icon-dir "icon-examples.png"),
  222
+;;   "Comments" (str icon-dir "icon-comments.png"),
  223
+;;   "See alsos" (str icon-dir "icon-see-also.png"),
  224
+;;   "Value" (str icon-dir "icon-value.png"),
  225
+;;   "Meta" (str icon-dir "icon-meta.png")})
  226
+
  227
+(def name-to-icon-desc
  228
+  {"Doc" (str (clojure.java.io/resource "icon-doc.png")),
  229
+   "Source" (str (clojure.java.io/resource "icon-source.png")),
  230
+   "Examples" (str (clojure.java.io/resource "icon-examples.png")),
  231
+   "Comments" (str (clojure.java.io/resource "icon-comments.png")),
  232
+   "See alsos" (str (clojure.java.io/resource "icon-see-also.png")),
  233
+   "Value" (str (clojure.java.io/resource "icon-value.png")),
  234
+   "Meta" (str (clojure.java.io/resource "icon-meta.png"))})
  235
+
  236
+(defn update-vals-in-map [m f]
  237
+  (reduce (fn [m [k v]]
  238
+            (assoc m k (f v)))
  239
+          m m))
  240
+
  241
+(def name-to-icon (update-vals-in-map name-to-icon-desc icon))
  242
+
  243
+(def icon-desc-to-name (set/map-invert name-to-icon-desc))
  244
+
  245
+(defn icon-to-name [i]
  246
+  (icon-desc-to-name (str i)))
  247
+
  248
+(def doc-lb-name-list ["Doc" "Source" "Examples"
213 249
                         "Comments" "See alsos" "Value" "Meta"])
  250
+(def doc-lb-value-list (map name-to-icon doc-lb-name-list))
214 251
 (def doc-lb-value-set (set doc-lb-value-list))
215 252
 (def doc-lb-cur-order (atom doc-lb-value-list))
216 253
 
  254
+;; Needed for handling drag and drop to reorder items in the doc-lb
  255
+;; listbox.
  256
+(def icon-flavor (seesaw.dnd/local-object-flavor javax.swing.ImageIcon))
  257
+
217 258
 
218 259
 (def all-buttons-with-atoms
219 260
   "Used to auto-generate atoms and '-atom' keywords"
@@ -608,7 +649,7 @@
608 649
              :drop-mode :insert
609 650
              :transfer-handler
610 651
              (seesaw.dnd/default-transfer-handler
611  
-               :import [seesaw.dnd/string-flavor
  652
+               :import [icon-flavor
612 653
                         (fn [{:keys [target data drop? drop-location] :as m}]
613 654
                           ;; Ignore anything dropped onto the list that is
614 655
                           ;; not in the original set of list elements.
@@ -622,7 +663,7 @@
622 663
                               (reset! doc-lb-cur-order new-order)
623 664
                               (config! target :model new-order))))]
624 665
                :export {:actions (constantly :copy)
625  
-                        :start   (fn [c] [seesaw.dnd/string-flavor (selection c)])}))
  666
+                        :start   (fn [c] [icon-flavor (selection c)])}))
626 667
     (config! (id :edit-btn) :enabled? false)
627 668
     (config! (id :browse-btn) :enabled? false)
628 669
     (config! (id :clojuredocs-online-rb) :selected? true)
@@ -653,7 +694,7 @@
653 694
     (config! (id :doc-ta) :text "                                                                        ")
654 695
     (selection! (id :ns-cbx) "loaded")
655 696
     (selection! (id :vars-cbx) "Vars - public")
656  
-    (selection! (id :doc-lb) "Doc")))
  697
+    (selection! (id :doc-lb) (name-to-icon "Doc"))))
657 698
 
658 699
 
659 700
 (defn init-after-bind
@@ -687,7 +728,7 @@
687 728
          ))
688 729
      (selection! (id :ns-cbx) "loaded")
689 730
      (selection! (id :vars-cbx) "Vars - public")
690  
-     (selection! (id :doc-lb) "Doc"))))
  731
+     (selection! (id :doc-lb) (name-to-icon "Doc")))))
691 732
 
692 733
 
693 734
 (defn bind-all
@@ -907,15 +948,16 @@
907 948
                        (b/selection (id :doc-lb) {:multi? true})
908 949
                        vars-lb-refresh-atom])
909 950
       (b/filter (fn [[doc-tf doc-lb]]
910  
-;;                  (printf "(class doc-lb)=%s doc-lb='%s'\n"
911  
-;;                          (class doc-lb) (seq doc-lb))
  951
+;;                  (printf "(class doc-lb)=%s (seq doc-lb)='%s' (map ... doc-lb)='%s'\n"
  952
+;;                          (class doc-lb) (seq doc-lb)
  953
+;;                          (seq (map icon-to-name doc-lb)))
912 954
 ;;                  (flush)
913 955
                   (not (or (nil? doc-tf)  (= "" doc-tf)
914 956
                            (nil? doc-lb) (= "" doc-lb)))))
915 957
       (b/transform
916 958
         (fn [[doc-tf doc-lb]]
917 959
           (future
918  
-            (let [s (render-doc-text doc-tf doc-lb)]
  960
+            (let [s (render-doc-text doc-tf (map icon-to-name doc-lb))]
919 961
               (when-not (= s (config (id :doc-ta) :text))
920 962
                 (invoke-soon (config! (id :doc-ta) :text s))))))))
921 963
     ;;
@@ -950,18 +992,18 @@
950 992
     ;; new text in doc-ta => dis/enable browser button
951 993
     (b/bind
952 994
       (id :doc-ta)
953  
-      (b/transform (fn [o] (selection (id :doc-lb))))
  995
+      (b/transform (fn [o] (map icon-to-name
  996
+                                (selection (id :doc-lb) {:multi? true}))))
954 997
       (b/transform (fn [o]
955  
-        (case o
956  
-          ("Examples" "See alsos" "Comments")
  998
+        (if (empty? (set/intersection (set o)
  999
+                                      #{"Examples" "See alsos" "Comments"}))
  1000
+          (invoke-soon (config! (id :browse-btn) :enabled? true))
957 1001
           (if-let [fqn (config (id :doc-tf) :text)]
958 1002
             (future
959 1003
               (let [url (clojuredocs-url fqn)
960 1004
                     r (if url true false)]
961 1005
                 (invoke-soon
962  
-                 (config! (id :browse-btn) :enabled? r)))))
963  
-
964  
-          (invoke-soon (config! (id :browse-btn) :enabled? true))))))
  1006
+                 (config! (id :browse-btn) :enabled? r)))))))))
965 1007
     ;;
966 1008
     (b/bind
967 1009
       (apply b/funnel [(id :doc-tf)
@@ -971,7 +1013,7 @@
971 1013
 ;;                     (printf "update edit-btn: (class o)=%s o='%s'\n"
972 1014
 ;;                             (class o) (seq o))
973 1015
 ;;                     (flush)
974  
-                     (let [doc-set (set o)]
  1016
+                     (let [doc-set (set (map icon-to-name o))]
975 1017
                        (or (doc-set "Source") (doc-set "All")))))
976 1018
       (b/transform (fn [o]
977 1019
         (when o (if (meta-when-file (config (id :doc-tf) :text))
@@ -985,7 +1027,8 @@
985 1027
     (b/bind
986 1028
       (apply b/funnel [(id :doc-tf)
987 1029
                        (b/selection (id :doc-lb) {:multi? true})])
988  
-      (b/transform (fn [[doc-tf doc-lb]] [(config (id :doc-tf) :text) doc-lb]))
  1030
+      (b/transform (fn [[doc-tf doc-lb]] [(config (id :doc-tf) :text)
  1031
+                                          (map icon-to-name doc-lb)]))
989 1032
       (b/transform (fn [[fqn doc-lb-sel]]
990 1033
                      (let [doc-set (set doc-lb-sel)]
991 1034
                        (if (or (doc-set "Value") (doc-set "All"))
@@ -1003,7 +1046,7 @@
1003 1046
       (b/selection (id :doc-lb) {:multi? true})
1004 1047
       (b/transform (fn [o] 
1005 1048
         (when (= (.getName (type (id :doc-ta))) "org.fife.ui.rsyntaxtextarea.RSyntaxTextArea")
1006  
-          (let [selected-set (set o)]
  1049
+          (let [selected-set (set (map icon-to-name o))]
1007 1050
             (if (= selected-set
1008 1051
                    (set/intersection selected-set
1009 1052
                                      #{"Source" "Examples" "Meta"}))
@@ -1015,7 +1058,7 @@
1015 1058
       (id :browse-btn-atom)
1016 1059
       (b/notify-soon)
1017 1060
       (b/transform (fn [& oo]
1018  
-        (let [o (selection (id :doc-lb))]
  1061
+        (let [o (icon-to-name (selection (id :doc-lb)))]
1019 1062
           (when-let [fqn (config (id :doc-tf) :text)]
1020 1063
             (future
1021 1064
               (case o

0 notes on commit 1e5b9a9

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