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

Addition of "Choose Theme" menu item #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The source code editor offers a few simple things to make writing clojure code e
* Press ctrl-ENTER to send either the nearest root form or the selected text to the REPL.
* Double-click a paren to highlight a form
* Source files are continuously saved in the background to prevent accidental loss of your work in the event of a crash.
* Syntax highlighting (using the [RSyntaxTextArea](http://fifesoft.com/rsyntaxtextarea/) library)
* Customizable syntax highlighting (using the [RSyntaxTextArea](http://fifesoft.com/rsyntaxtextarea/) library)

### clojure projects
Each clojure project corresponds to a project directory somewhere in the file system, containing a src directory. Inside the src directory is the source code hierarchy, composed of directories and .clj files. Note this directory structure is completely compatible with the lein and cake clojure build programs and you are encouraged to use one of these from the command line in conjunction with the clooj editor. Clicking different source files in the projects tree will automatically change the source file currently being edited, as well as switch the REPL to the appropriate namespace.
Expand Down
10 changes: 6 additions & 4 deletions src/clooj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
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)]
[clooj.style :only (get-monospaced-fonts show-font-window show-theme-window load-theme)]
[clooj.navigate :only (attach-navigation-keys)])
(:require [clojure.main :only (repl repl-prompt)]
[clojure.set])
Expand Down Expand Up @@ -92,7 +92,7 @@
token-type)))]
(.. rsta getDocument (setTokenMakerFactory tmf))
rsta))

(defn make-text-area [wrap]
(doto (RSyntaxTextArea.)
(.setAnimateBracketMatching false)
Expand Down Expand Up @@ -737,7 +737,8 @@
["Increase font size" nil "cmd1 PLUS" #(grow-font app)]
["Decrease font size" nil "cmd1 MINUS" #(shrink-font app)]
["Choose font..." nil nil #(apply show-font-window
app set-font @current-font)])))
app set-font @current-font)]
["Choose theme..." nil nil #(show-theme-window app)])))


(defn add-visibility-shortcut [app]
Expand Down Expand Up @@ -777,7 +778,8 @@
(let [tree (app :docs-tree)]
(load-expanded-paths tree)
(load-tree-selection tree))
(load-font app)))
(load-font app)
(load-theme app)))

(defn -show []
(reset! embedded true)
Expand Down
49 changes: 46 additions & 3 deletions src/clooj/style.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

(ns clooj.style
(:import
(java.io FileInputStream)
(javax.swing JComboBox JFrame JList JScrollPane JSplitPane
ListSelectionModel SpringLayout)
ListSelectionModel SpringLayout JOptionPane)
(javax.swing.text SimpleAttributeSet StyleConstants)
(java.awt Color Font FontMetrics GraphicsEnvironment)
(java.awt.image BufferedImage)
(javax.swing.event ListSelectionListener)
(org.fife.ui.rsyntaxtextarea Theme)
(java.util Vector))
(:use [clooj.utils :only (constrain-to-parent make-split-pane)]))
(:use [clooj.utils :only (constrain-to-parent make-split-pane choose-file
awt-event write-value-to-prefs clooj-prefs
read-value-from-prefs)]))

(def graphics-object
(memoize (fn [] (.createGraphics
Expand Down Expand Up @@ -89,4 +93,43 @@
(when-not @font-window
(reset! font-window (create-font-window app set-font init-name init-size)))
(.show @font-window))


;; theme (optional)
(defonce current-theme (atom nil))

(defn set-theme [app apply-to]
(if @current-theme (.apply @current-theme (get app apply-to))))

(defn refresh-theme [app]
(do
(set-theme app :doc-text-area)
(set-theme app :repl-out-text-area)
(set-theme app :repl-in-text-area)
(set-theme app :help-text-area)))

(defn swap-theme [input-stream]
(swap! current-theme
(fn [old-value new-value]
(let [new-theme (Theme/load (FileInputStream. new-value))]
(write-value-to-prefs clooj-prefs "app-theme" new-value)
new-theme))
input-stream))

(defn load-theme [app]
(try
(let [theme-file (read-value-from-prefs clooj-prefs "app-theme")]
(swap-theme theme-file)
(refresh-theme app))
(catch Exception e (println "pref not set, this is ok"))))

(defn show-theme-window [app]
(try
(when-let [dir (choose-file (app :frame) "Select a theme file" "" true)]
(awt-event
(let [path (.getAbsolutePath dir)]
(swap-theme path)
(refresh-theme app))))
(catch Exception e (do (JOptionPane/showMessageDialog nil
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JOptionPane is not ever displayed. I copied this code from somewhere else in Clooj. It doesn't work there either I believe. I haven't taken the time yet to figure out why it is not ever rendering...

"Invalid theme file."
"Oops" JOptionPane/ERROR_MESSAGE)
(.printStackTrace e)))))