13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-selection-TreeModel'>/**
</span> * Adds custom behavior for left/right keyboard navigation for use with a tree.
 * Depends on the view having an expand and collapse method which accepts a
 * record. This selection model is created by default for {@link Ext.tree.Panel}.
 */
Ext.define('Ext.selection.TreeModel', {
    extend: 'Ext.selection.RowModel',
    alias: 'selection.treemodel',
 
<span id='Ext-selection-TreeModel-cfg-pruneRemoved'>    /**
</span>     * @cfg {Boolean} pruneRemoved @hide
     */
 
    constructor: function(config) {
        this.callParent(arguments);
 
        // If pruneRemoved is required, we must listen to the *TreeStore* to know when nodes
        // are added and removed
        if (this.pruneRemoved) {
            this.pruneRemoved = false;
            this.pruneRemovedNodes = true;
        }
    },
 
<span id='Ext-selection-TreeModel-method-bindStore'>    // binds the store to the selModel.
</span>    bindStore: function(store, initial) {
        var me = this;
        me.callParent(arguments);
 
        // TreePanel should have injected a reference to the TreeStore so that we can
        // listen for node removal.
        if (me.pruneRemovedNodes) {
            me.view.mon(me.treeStore, {
                remove: me.onNodeRemove,
                scope: me
            });
        }
    },
 
<span id='Ext-selection-TreeModel-method-onNodeRemove'>    onNodeRemove: function(parent, node, isMove) {
</span>        // deselection of deleted records done in base Model class
        if (!isMove) {
            this.deselectDeletedRecords([node]);
        }
    },
 
<span id='Ext-selection-TreeModel-method-onKeyRight'>    onKeyRight: function(e, t) {
</span>        this.navExpand(e, t);
    },
    
<span id='Ext-selection-TreeModel-method-navExpand'>    navExpand: function(e, t) {
</span>        var focused = this.getLastFocused(),
            view    = this.view;
 
        if (focused) {
            // tree node is already expanded, go down instead
            // this handles both the case where we navigate to firstChild and if
            // there are no children to the nextSibling
            if (focused.isExpanded()) {
                this.onKeyDown(e, t);
            // if its not a leaf node, expand it
            } else if (focused.isExpandable()) {
                // If we are the normal side of a locking pair, only the tree view can do expanding
                if (!view.isTreeView) {
                    view = view.lockingPartner;
                }
 
                view.expand(focused);
            }
        }
    },
 
<span id='Ext-selection-TreeModel-method-onKeyLeft'>    onKeyLeft: function(e, t) {
</span>        this.navCollapse(e, t);
    },
    
<span id='Ext-selection-TreeModel-method-navCollapse'>    navCollapse: function(e, t) {
</span>        var me = this,
            focused = this.getLastFocused(),
            view    = this.view,
            parentNode;
 
        if (focused) {
            parentNode = focused.parentNode;
            // if focused node is already expanded, collapse it
            if (focused.isExpanded()) {
                // If we are the normal side of a locking pair, only the tree view can do collapsing
                if (!view.isTreeView) {
                    view = view.lockingPartner;
                }
 
                view.collapse(focused);
            // has a parentNode and its not root
            // TODO: this needs to cover the case where the root isVisible
            } else if (parentNode &amp;&amp; !parentNode.isRoot()) {
                // Select a range of records when doing multiple selection.
                if (e.shiftKey) {
                    me.selectRange(parentNode, focused, e.ctrlKey, 'up');
                    me.setLastFocused(parentNode);
                // just move focus, not selection
                } else if (e.ctrlKey) {
                    me.setLastFocused(parentNode);
                // select it
                } else {
                    me.select(parentNode);
                }
            }
        }
    },
 
<span id='Ext-selection-TreeModel-method-onKeySpace'>    onKeySpace: function(e, t) {
</span>        if (e.record.data.checked != null) {
            this.toggleCheck(e);
        } else {
            this.callParent(arguments);
        }
    },
 
<span id='Ext-selection-TreeModel-method-onKeyEnter'>    onKeyEnter: function(e, t) {
</span>        if (e.record.data.checked != null) {
            this.toggleCheck(e);
        } else {
            this.callParent(arguments);
        }
    },
 
<span id='Ext-selection-TreeModel-method-toggleCheck'>    toggleCheck: function(e) {
</span>        var view = this.view,
            selected = this.getLastSelected();
 
        e.stopEvent();
        if (selected) {
            // If we are the normal side of a locking pair, only the tree view can do on heckChange
            if (!view.isTreeView) {
                view = view.lockingPartner;
            }
 
            view.onCheckChange(selected);
        }
    }
});
</pre>
</body>
</html>