Permalink
Browse files

Fixed the navigator panel. Needs more testing.

  • Loading branch information...
EricThorsen committed Aug 27, 2010
1 parent a6525b9 commit b5145178572640c1f9a81272c37330b8c6b5dfb1
@@ -22,6 +22,8 @@
)
(:require
[org.enclojure.commons.c-slf4j :as logger]
+ [org.enclojure.ide.nb.editor.completion.symbol-caching :as symbol-caching]
+ [org.enclojure.ide.nb.editor.utils :as editor-utils]
)
(:import (java.util.logging Level)
(java.awt.event MouseAdapter ActionListener)
@@ -323,14 +325,20 @@
(actionPerformed [action-event]
(.setModel jtree (tree-model-3 @data sort-fn)))))
+; This is gross
+(def --nav-panel-fn-- (atom {}))
+(def --symbol-cache-fn-- (atom nil))
+
(defn create-navigator-tree [jpanel open-file-fn]
+ (logger/info "Navigator create tree {} !!!!!!!!!!!" jpanel)
(let [data-ref (atom {})
jtree (get-tree-proxy)
mypanel (CljNavigatorViewPanel.)
alpha-sort-btn (.jToggleButtonAlphaSort mypanel)
source-sort-btn (.jToggleButtonSortPos mypanel)
expand-all-btn (.jToggleButtonExpandAll mypanel)]
- (do
+ (logger/info "Navigator create tree calling the do section")
+ (do
(.addActionListener alpha-sort-btn
(add-action-listener-for-sort alpha-sort-btn jtree
data-ref (get-sort-keyfn :name)))
@@ -346,18 +354,11 @@
(.add
mypanel
BorderLayout/CENTER))
- (fn [data]
- (logger/info "Context changed {}" data)
- (when data
- (swap! data-ref (fn [_] data))
- (.setModel jtree (tree-model-3 data -default-sort-))))))
-
-(def obj (atom nil))
-
-(defn new-context [context]
- (swap! obj (fn [_] context))
- (logger/info "Got new context {} str {}" (class context) (str context))
- (.getPrimaryFile (first context)))
+ (fn [data]
+ (logger/info "Context changed {}" data)
+ (when data
+ (swap! data-ref (fn [_] data))
+ (.setModel jtree (tree-model-3 data -default-sort-))))))
(defn navigator
[title data]
@@ -406,6 +407,38 @@
(.setVisible true))
{:tree jtree :nav-panel mypanel}))
+(defn new-context [jpanel context]
+ (logger/info "Nav got {} {}" (class jpanel) (hash jpanel))
+ (let [nav-panel-fn (or (@--nav-panel-fn-- (hash jpanel))
+ (swap! --nav-panel-fn--
+ (fn [m] (assoc m (hash jpanel)
+ (create-navigator-tree jpanel editor-utils/open-editor-file)))))]
+ (logger/info "Nav panel is now {}" nav-panel-fn)
+ (when context
+ (let [file (.getPrimaryFile (first context))
+ _ (logger/info "Nav got file {}" file)
+ _ (logger/info "Nav looking for file {}" (.getPath file))
+ syms (symbol-caching/get-nav-data-for file)
+ _ (logger/info "Nav got symbol count {}" (count syms))]
+ (nav-panel-fn syms)))))
+
+; (let [nav-panel-fn (or (@--nav-panel-fn-- jpanel)
+; (first (vals
+; (swap! --nav-panel-fn--
+; (fn [_] {jpanel
+; (create-navigator-tree
+; jpanel editor-utils/open-editor-file)})))))]
+ ; (logger/info "Nav got new context {} str {}" (class (first context)) (str context))
+ ; (logger/info "Nav nav-panel-fn {}" nav-panel-fn)
+ ; (when context
+ ; (let [file (.getPrimaryFile (first context))
+; _ (logger/info "Nav got file {}" file)
+; _ (logger/info "Nav looking for file {}" (.getPath file))
+; syms (symbol-caching/get-nav-data-for file)
+; _ (logger/info "Nav got symbol count {}" (count syms))]
+; (nav-panel-fn syms)))))
+
+
;(defn test-nav []
; (navigator "Testing navigator"
; (get-nav-data-for (:file (utils/get-current-editor-data)))))
@@ -47,7 +47,7 @@
[classpath]
(let [new-entries
(reduce
- #(assoc %1 (str %2) classpath) {} (.getRoots classpath))]
+ #(assoc %1 (.getPath %2) classpath) {} (.getRoots classpath))]
(dosync
(commute
-source-roots-
@@ -9,33 +9,22 @@
import clojure.lang.RT;
import clojure.lang.Var;
import java.awt.BorderLayout;
-import java.io.File;
import java.util.Collection;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.netbeans.spi.navigator.NavigatorPanel;
-import org.openide.filesystems.FileObject;
-import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
-import javax.swing.tree.DefaultTreeCellRenderer;
@SuppressWarnings("unchecked")
public class ClojureNavigatorPanel implements NavigatorPanel {
- private IFn _contextChanged = null;
- private IFn _openFileFn = (IFn)RT.var("org.enclojure.ide.nb.editor.utils"
- ,"open-editor-file");
private Var _checkNewContextFn =
RT.var("org.enclojure.ide.navigator.views.navigator-panel",
"new-context");
- private IFn _getDataForFileFn =
- (IFn)RT.var("org.enclojure.ide.nb.editor.completion.symbol-caching"
- , "get-nav-data-for");
-
/** holds UI of this panel */
private JComponent panelUI;
@@ -61,17 +50,7 @@ public String getDisplayName() {
public JComponent getComponent() {
if (panelUI == null) {
- Var createNavigationTree =
- RT.var("org.enclojure.ide.navigator.views.navigator-panel",
- "create-navigator-tree");
panelUI = new JPanel(new BorderLayout());
- try {
- _contextChanged = (IFn) createNavigationTree.invoke(panelUI,_openFileFn);
- // You can override requestFocusInWindow() on the component if desired.
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
- }
- // You can override requestFocusInWindow() on the component if desired.
}
return panelUI;
}
@@ -104,42 +83,12 @@ public Lookup getLookup () {
/************* non - public part ************/
private void setNewContent (Collection newData) {
- try {
- // Node[] activatedNodes = TopComponent.getRegistry().getActivatedNodes();
- // if(activatedNodes != null && activatedNodes.length > 0)
- // {
- // EditorCookie ec = activatedNodes[0].getLookup().lookup(EditorCookie.class);
- // if(ec != null)
- // {
- // Document document = ec.getDocument();
- // DataObject dataObject = NbEditorUtilities.getDataObject(document);
- // if(dataObject != null)
- // {
- // FileObject fileObject = (FileObject) dataObject.files().toArray()[0];
- // int i;
- // i = 100;
- // }
- // }
- // }
-// for (Object object : newData.toArray()) {
-// if (object instanceof FileObject) {
-// FileObject fileObject = (FileObject) object;
-// File file = FileUtil.toFile(fileObject);
try {
- FileObject f = (FileObject) ((IFn) _checkNewContextFn).invoke(newData);
- File file = FileUtil.toFile(f);
- if (_contextChanged != null) {
- Object sampleData = _getDataForFileFn.invoke(file);
- _contextChanged.invoke(sampleData);
- }
+ _checkNewContextFn.invoke(panelUI,newData);
+
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
-// }
-// }
- } catch (Exception ex) {
- Exceptions.printStackTrace(ex);
- }
}
/** Accessor for listener to context */
@@ -51,6 +51,8 @@ public void restored() {
LOG.log(Level.INFO, "Enclojure module restored.");
+ requireFn.invoke(Symbol.create("org.enclojure.ide.navigator.CljClassVisitor"));
+ LOG.log(Level.INFO, "Enclojure CljClassVisitor.");
requireFn.invoke(Symbol.create("org.enclojure.ide.nb.classpaths.resource-tracking"));
requireFn.invoke(Symbol.create("org.enclojure.ide.nb.editor.completion.symbol-caching"));
requireFn.invoke(Symbol.create("org.enclojure.ide.nb.classpaths.listeners"));

0 comments on commit b514517

Please sign in to comment.