Commit c3990f9c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Make tabs work with hidden private classes.

Previously tabs for private classes didn't open when they were hidden in tree.
Now each tree has two separate methods:

- getNodeByUrl - to geth the actual node.
- getRecordByUrl - to get the data (which in case of classtree also searches within
  hidden classes).

To support this, both logic classes return list of private nodes in addition to
the root node.
parent 3e486572
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -163,20 +163,25 @@ Ext.define('Docs.controller.Tabs', {
     * @private
     */
    addTabFromTree: function(url, opts) {
        opts = opts || { animate: true, activate: true };
        var tree = this.getTree(url);
        var treeRecord = tree.findRecordByUrl(url);
        if (treeRecord && treeRecord.raw) {
        if (treeRecord) {
            this.addTab(treeRecord, opts);
        }
    },

    // Adds new tab, no questions asked
    addTab: function(tab, opts) {
        opts = opts || { animate: true, activate: true };
        // Init scrollstate when tab opened.
            if (!this.scrollState[url]) {
                this.scrollState[url] = 0;
        if (!this.scrollState[tab.url]) {
            this.scrollState[tab.url] = 0;
        }
        this.getDoctabs().addTab({
                href: treeRecord.raw.url,
                text: treeRecord.raw.text,
                iconCls: treeRecord.raw.iconCls
            href: tab.url,
            text: tab.text,
            iconCls: tab.iconCls
        }, opts);
        }
    },

    // Determines tree from an URL
+21 −5
Original line number Diff line number Diff line
@@ -78,24 +78,40 @@ Ext.define('Docs.view.DocTree', {
     * @param {String} url
     */
    selectUrl: function(url) {
        var r = this.findRecordByUrl(url);
        if (r) {
            r.bubble(function(n) {
        var node = this.findNodeByUrl(url);
        if (node) {
            node.bubble(function(n) {
                n.expand();
            });
            this.getSelectionModel().select(r);
            this.getSelectionModel().select(node);
        }
        else {
            this.getSelectionModel().deselectAll();
        }
    },

    findRecordByUrl: function(url) {
    /**
     * Given URL, returns corresponding treenode.
     * @param {String} url
     * @return {Ext.data.Model}
     */
    findNodeByUrl: function(url) {
        return this.getRootNode().findChildBy(function(n) {
            return url === n.raw.url;
        }, this, true);
    },

    /**
     * Like #findNodeByUrl, but instead of the node itself, returns
     * the raw data within the node.
     * @param {String} url
     * @return {Object}
     */
    findRecordByUrl: function(url) {
        var n = this.findNodeByUrl(url);
        return n ? n.raw : undefined;
    },

    handleBeforeExpandCollapse: function(node) {
        if(this.getView().isAnimating(node)) {
            return false;
+14 −3
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ Ext.define('Docs.view.cls.InheritanceLogic', {
            children: [],
            text: 'Root'
        };
        this.privates = [];

        this.subclasses = this.buildLookupTable(this.classes);
        Ext.Array.forEach(this.classes, this.addClass, this);
@@ -20,7 +21,10 @@ Ext.define('Docs.view.cls.InheritanceLogic', {
            this.stripPrivateClasses(this.root);
        }
        this.sortTree(this.root);
        return this.root;
        return {
            root: this.root,
            privates: this.privates
        };
    },

    sortTree: function(node) {
@@ -85,8 +89,15 @@ Ext.define('Docs.view.cls.InheritanceLogic', {
    stripPrivateClasses: function(node) {
        node.children = Ext.Array.filter(node.children, function(child) {
            this.stripPrivateClasses(child);
            // Remove private class unless it has non-private subclasses
            return !(child.cls === "private" && child.children.length === 0);
            // Remove private class unless it has non-private subclasses.
            // As a side-effect add private class to this.privates list.
            if (child.cls === "private" && child.children.length === 0) {
                this.privates.push(child);
                return false;
            }
            else {
                return true;
            }
        }, this);
    }

+9 −2
Original line number Diff line number Diff line
@@ -6,7 +6,9 @@ Ext.define('Docs.view.cls.PackageLogic', {

    /**
     * Creates the tree.
     * @return {Object} the tree.
     * @return {Object} Object with two fields:
     * @return {Object} return.root Root node
     * @return {Object[]} return.privates Array of hidden nodes
     */
    create: function() {
        this.root = {
@@ -14,9 +16,13 @@ Ext.define('Docs.view.cls.PackageLogic', {
            text: 'Root'
        };
        this.packages = {"": this.root};
        this.privates = [];
        Ext.Array.forEach(this.classes, this.addClass, this);
        this.sortTree(this.root);
        return this.root;
        return {
            root: this.root,
            privates: this.privates
        };
    },

    // Sorts all child nodes, and recursively all child packages.
@@ -41,6 +47,7 @@ Ext.define('Docs.view.cls.PackageLogic', {
    // package; otherwise create the package first.
    addClass: function(cls) {
        if (cls["private"] && !this.showPrivateClasses) {
            this.privates.push(this.classNode(cls));
            return;
        }
        if (this.packages[cls.name]) {
+26 −4
Original line number Diff line number Diff line
@@ -95,18 +95,21 @@ Ext.define('Docs.view.cls.Tree', {
            // remember the current selection
            var selected = this.getSelectionModel().getLastSelected();
            // create new treestructure
            var root = tree.create();
            this.expandLonelyNode(root);
            this.setRootNode(root);
            var nodes = tree.create();
            this.expandLonelyNode(nodes.root);
            this.setRootNode(nodes.root);
            this.initNodeLinks();

            // re-establish the previous selection
            selected && this.selectUrl(selected.raw.url);
        }
        else {
            this.root = tree.create();
            var nodes = tree.create();
            this.root = nodes.root;
            this.expandLonelyNode(this.root);
        }
        // remember hidden nodes
        this.privates = nodes.privates;
    },

    // When only one expandable node at root level, expand it
@@ -117,5 +120,24 @@ Ext.define('Docs.view.cls.Tree', {
        if (expandableNodes.length == 1) {
            expandableNodes[0].expanded = true;
        }
    },

    /**
     * Returns node data, looking also from private nodes.
     * @param {String} url
     * @return {Object}
     */
    findRecordByUrl: function(url) {
        return this.callParent([url]) || this.findPrivateRecordByUrl(url);
    },

    findPrivateRecordByUrl: function(url) {
        var ps = this.privates;
        for (var i=0; i<ps.length; i++) {
            if (ps[i].url === url) {
                return ps[i];
            }
        }
        return undefined;
    }
});