PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/netbeans/plugins/org-enclojure-plugin/src/main/clojure/org/enclojure/ide/nb/actions/token_navigator.clj

https://github.com/EricThorsen/enclojure
Clojure | 58 lines | 37 code | 6 blank | 15 comment | 2 complexity | d201e772add77a3223238e91032c3f7d MD5 | raw file
  1. (comment
  2. ;*******************************************************************************
  3. ;* Copyright (c) ThorTech, L.L.C.. All rights reserved.
  4. ;* The use and distribution terms for this software are covered by the
  5. ;* GNU General Public License, version 2
  6. ;* (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) with classpath
  7. ;* exception (http://www.gnu.org/software/classpath/license.html)
  8. ;* which can be found in the file GPL-2.0+ClasspathException.txt at the root
  9. ;* of this distribution.
  10. ;* By using this software in any fashion, you are agreeing to be bound by
  11. ;* the terms of this license.
  12. ;* You must not remove this notice, or any other, from this software.
  13. ;*******************************************************************************
  14. ;* Author: Narayan Singhal
  15. ;*******************************************************************************
  16. )
  17. (ns org.enclojure.ide.nb.actions.token-navigator
  18. (:use
  19. org.enclojure.ide.navigator.token-nav
  20. )
  21. (:require
  22. [org.enclojure.commons.c-slf4j :as logger]
  23. )
  24. (:import
  25. (javax.swing JEditorPane)
  26. (java.util.logging Level)
  27. (java.awt EventQueue)
  28. (org.netbeans.api.lexer TokenHierarchy TokenSequence Token)
  29. (org.openide.windows TopComponent)
  30. (org.openide.cookies EditorCookie)
  31. ))
  32. ; setup logging
  33. (logger/ensure-logger)
  34. (defn editor-cookie [nodes]
  35. (when (= (alength nodes) 1)
  36. (. (aget nodes 0) (getCookie (identity EditorCookie)))))
  37. (defn current-editor-pane
  38. "Get the current JEditorPane."
  39. ([nodes]
  40. (when-let [ec (editor-cookie nodes)]
  41. (aget (.getOpenedPanes ec) 0)))
  42. ([]
  43. (current-editor-pane (-> (TopComponent/getRegistry) .getActivatedNodes))))
  44. (defn current-editor-pane-awt []
  45. "Get the current JEditorPane in AWT thread"
  46. (let [pane (atom nil)]
  47. (EventQueue/invokeAndWait
  48. #(swap! pane (fn [_] (current-editor-pane))))
  49. @pane))
  50. (defn current-editor-pane-doc []
  51. "Get the current doc"
  52. (.getDocument (current-editor-pane-awt)))