1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import * as go from '../release/go-module.js';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export class RealtimeDragSelectingTool extends go.DragSelectingTool {
|
23 | private _originalSelection: go.Set<go.Part> = new go.Set<go.Part>();
|
24 | private _temporarySelection: go.Set<go.Part> = new go.Set<go.Part>();
|
25 |
|
26 | |
27 |
|
28 |
|
29 | public doActivate(): void {
|
30 | super.doActivate();
|
31 |
|
32 | this._originalSelection = this.diagram.selection.copy();
|
33 |
|
34 | this._temporarySelection.clear();
|
35 | this.diagram.raiseDiagramEvent('ChangingSelection');
|
36 | }
|
37 |
|
38 | |
39 |
|
40 |
|
41 | public doDeactivate(): void {
|
42 | this.diagram.raiseDiagramEvent('ChangedSelection');
|
43 | this._originalSelection.clear();
|
44 | this._temporarySelection.clear();
|
45 | super.doDeactivate();
|
46 | }
|
47 |
|
48 | |
49 |
|
50 |
|
51 | public doCancel(): void {
|
52 | const orig = this._originalSelection;
|
53 | orig.each(function(p) { p.isSelected = true; });
|
54 | this._temporarySelection.each(function(p) { if (!orig.contains(p)) p.isSelected = false; });
|
55 | super.doCancel();
|
56 | }
|
57 |
|
58 | |
59 |
|
60 |
|
61 | public doMouseMove(): void {
|
62 | if (this.isActive) {
|
63 | super.doMouseMove();
|
64 | this.selectInRect(this.computeBoxBounds());
|
65 | }
|
66 | }
|
67 |
|
68 | |
69 |
|
70 |
|
71 | public doKeyDown(): void {
|
72 | if (this.isActive) {
|
73 | super.doKeyDown();
|
74 | this.selectInRect(this.computeBoxBounds());
|
75 | }
|
76 | }
|
77 |
|
78 | |
79 |
|
80 |
|
81 | public doKeyUp(): void {
|
82 | if (this.isActive) {
|
83 | super.doKeyUp();
|
84 | this.selectInRect(this.computeBoxBounds());
|
85 | }
|
86 | }
|
87 |
|
88 | |
89 |
|
90 |
|
91 |
|
92 | public selectInRect(r: go.Rect): void {
|
93 | const diagram = this.diagram;
|
94 | const orig = this._originalSelection;
|
95 | const temp = this._temporarySelection;
|
96 | const e = diagram.lastInput;
|
97 | const found = diagram.findPartsIn(r, this.isPartialInclusion);
|
98 | if (e.control || e.meta) {
|
99 | if (e.shift) {
|
100 | temp.each(function(p: go.Part) { if (!found.contains(p)) p.isSelected = orig.contains(p); });
|
101 | found.each(function(p: go.Part) { p.isSelected = false; temp.add(p); });
|
102 | } else {
|
103 | temp.each(function(p: go.Part) { if (!found.contains(p)) p.isSelected = orig.contains(p); });
|
104 | found.each(function(p: go.Part) { p.isSelected = !orig.contains(p); temp.add(p); });
|
105 | }
|
106 | } else if (e.shift) {
|
107 | temp.each(function(p: go.Part) { if (!found.contains(p)) p.isSelected = orig.contains(p); });
|
108 | found.each(function(p: go.Part) { p.isSelected = true; temp.add(p); });
|
109 | } else {
|
110 | temp.each(function(p: go.Part) { if (!found.contains(p)) p.isSelected = false; });
|
111 | orig.each(function(p: go.Part) { if (!found.contains(p)) p.isSelected = false; });
|
112 | found.each(function(p: go.Part) { p.isSelected = true; temp.add(p); });
|
113 | }
|
114 | }
|
115 | }
|