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

Find text #83

Merged
merged 5 commits into from
Feb 9, 2012
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
34 changes: 30 additions & 4 deletions src/clooj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
[clooj.search]
[clooj.help :only (arglist-from-caret-pos show-tab-help setup-tab-help
setup-completion-list help-handle-caret-move
find-focused-text-pane)]
find-focused-text-pane safe-resolve
token-from-caret-pos)]
[clooj.project :only (add-project load-tree-selection
load-expanded-paths load-project-set
save-expanded-paths
Expand All @@ -53,7 +54,8 @@
scroll-to-caret when-lets
constrain-to-parent make-split-pane
gen-map on-click
remove-text-change-listeners get-text-str)]
remove-text-change-listeners get-text-str
scroll-to-line get-directories)]
[clooj.indent :only (setup-autoindent fix-indent-selected-lines)]
[clooj.style :only (get-monospaced-fonts show-font-window)])
(:require [clojure.main :only (repl repl-prompt)]
Expand Down Expand Up @@ -649,7 +651,29 @@
(update-project-tree (:docs-tree app))
(restart-doc app f))))))


(defn- dir-rank [dir]
(get {"src" 0 "test" 1 "lib" 2} (.getName dir) 100))

(defn- find-file [project-path relative-file-path]
(let [classpath-dirs (sort-by dir-rank < (get-directories (File. project-path)))
file-candidates (map
#(File. (str (.getAbsolutePath %) File/separatorChar relative-file-path))
classpath-dirs)]
(first (filter #(and (.exists %) (.isFile %)) file-candidates))))

(defn goto-definition [ns app]
(let [text-comp (:doc-text-area app)
pos (.getCaretPosition text-comp)
text (.getText text-comp)
src-file (:file (meta (safe-resolve (find-ns (symbol ns)) (token-from-caret-pos ns text pos))))
line (:line (meta (safe-resolve (find-ns (symbol ns)) (token-from-caret-pos ns text pos))))
project-path (first (get-selected-projects app))
file (find-file project-path src-file)]
(when (and file line)
(when (not= file @(:file app))
(restart-doc app file)
(set-tree-selection (:docs-tree app) (.getAbsolutePath file)))
(scroll-to-line text-comp line))))

(defn make-menus [app]
(when (is-mac)
Expand All @@ -676,7 +700,8 @@
["Fix indentation" "F" "cmd1 BACK_SLASH" #(fix-indent-selected-lines (:doc-text-area app))]
["Indent lines" "I" "cmd1 CLOSE_BRACKET" #(indent (:doc-text-area app))]
["Unindent lines" "D" "cmd1 OPEN_BRACKET" #(indent (:doc-text-area app))]
["Name search/docs" "S" "TAB" #(show-tab-help app (find-focused-text-pane app) inc)])
["Name search/docs" "S" "TAB" #(show-tab-help app (find-focused-text-pane app) inc)]
["Goto definition" "G" "F3" #(goto-definition (get-file-ns app) app)])
(add-menu menu-bar "REPL" "R"
["Evaluate here" "E" "cmd1 ENTER" #(send-selected-to-repl app)]
["Evaluate entire file" "F" "cmd1 E" #(send-doc-to-repl app)]
Expand Down Expand Up @@ -770,3 +795,4 @@
; []
; (.setVisible (@current-app :frame) false)
; (startup))

6 changes: 4 additions & 2 deletions src/clooj/help.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
(java.awt Color Point)
(java.util Vector)
(javax.swing DefaultListCellRenderer ListSelectionModel)
(javax.swing.event ListSelectionListener))
(javax.swing.event ListSelectionListener)
(java.io File))
(:use [clooj.brackets :only (find-enclosing-brackets)]
[clooj.repl :only (get-file-ns get-repl-ns)]
[clooj.utils :only (attach-action-keys attach-child-action-keys
on-click awt-event when-lets get-text-str)]
[clooj.project :only (get-selected-projects)]
[clojure.repl :only (source-fn)])
(:require [clojure.string :as string]))

Expand Down Expand Up @@ -347,4 +349,4 @@
(.ensureIndexIsVisible l (.getSelectedIndex l))
(show-help-text app (.getSelectedValue l))))))
(on-click 2 #(when-let [text-pane (find-focused-text-pane app)]
(update-token app text-pane)))))
(update-token app text-pane)))))
10 changes: 4 additions & 6 deletions src/clooj/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(:use [clooj.utils :only (attach-child-action-keys attach-action-keys
awt-event recording-source-reader
get-line-of-offset get-line-start-offset
append-text when-lets get-text-str)]
append-text when-lets get-text-str get-directories)]
[clooj.brackets :only (find-line-group find-enclosing-brackets)]
[clojure.pprint :only (pprint)]
[clooj.project :only (get-temp-file)])
Expand Down Expand Up @@ -49,12 +49,10 @@
(when project-path
(let [project-dir (File. project-path)]
(when (and (.exists project-dir) (.isDirectory project-dir))
(let [sub-dirs (filter #(and (.isDirectory %)
(not (.startsWith (.getName %) ".")))
(.listFiles project-dir))]
(let [sub-dirs (get-directories project-dir)]
(concat sub-dirs
(filter #(.endsWith (.getName %) ".jar")
(mapcat #(.listFiles %) (file-seq project-dir)))))))))
(filter #(.endsWith (.getName %) ".jar")
(mapcat #(.listFiles %) (file-seq project-dir)))))))))

(defn selfish-class-loader [url-array parent]
(proxy [URLClassLoader] [url-array nil]
Expand Down
8 changes: 6 additions & 2 deletions src/clooj/search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@

(defn start-find [app]
(let [sta (app :search-text-area)
arg (app :arglist-label)]
arg (app :arglist-label)
dta (:doc-text-area app)
sel-text (.getSelectedText dta)]
(.setVisible arg false)
(doto sta
(.setVisible true)
(.requestFocus)
(.selectAll))))
(.selectAll))
(if (not (empty? sel-text))
(.setText sta sel-text))))

(defn stop-find [app]
(let [sta (app :search-text-area)
Expand Down
14 changes: 13 additions & 1 deletion src/clooj/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
; [email protected]

(ns clooj.utils
(:import (java.util UUID)
(:require [clojure.string :as string :only (join split)])
(:import (java.util UUID)
(java.awt FileDialog Point Window)
(java.awt.event ActionListener MouseAdapter)
(java.util.prefs Preferences)
Expand Down Expand Up @@ -196,6 +197,12 @@
(.setViewPosition v
(Point. 0 (min (- l h) (max 0 (- (.y r) (/ h 2)))))))))

(defn scroll-to-line [text-comp line]
(let [text (.getText text-comp)
pos (inc (.length (string/join "\n" (take (dec line) (string/split text #"\n")))))]
(.setCaretPosition text-comp pos)
(scroll-to-pos text-comp pos)))

(defn scroll-to-caret [text-comp]
(scroll-to-pos text-comp (.getCaretPosition text-comp)))

Expand Down Expand Up @@ -387,6 +394,11 @@
(.setDialogTitle title))
(if (= JFileChooser/APPROVE_OPTION (.showOpenDialog fc parent))
(.getSelectedFile fc)))))

(defn get-directories [path]
(filter #(and (.isDirectory %)
(not (.startsWith (.getName %) ".")))
(.listFiles path)))

;; tree seq on widgets (awt or swing)

Expand Down