14
14
* limitations under the License.
15
15
*/
16
16
17
+ import * as path from "path" ;
17
18
import * as vscode from "vscode" ;
18
19
19
20
import {
@@ -39,7 +40,6 @@ export class MPQSelectionPanel
39
40
implements CircleGraphEvent
40
41
{
41
42
public static readonly viewType = "one.viewer.mpq" ;
42
-
43
43
public static panels : MPQSelectionPanel [ ] = [ ] ;
44
44
45
45
private _panel : vscode . WebviewPanel ;
@@ -54,6 +54,63 @@ export class MPQSelectionPanel
54
54
55
55
public static register ( _context : vscode . ExtensionContext ) : void { }
56
56
57
+ public static createOrShow (
58
+ extensionUri : vscode . Uri ,
59
+ args : MPQSelectionCmdOpenArgs ,
60
+ handler : MPQSelectionEvent | undefined
61
+ ) {
62
+ let column = args . panel . viewColumn ;
63
+ if ( column ) {
64
+ if ( column >= vscode . ViewColumn . One ) {
65
+ column = column + 1 ;
66
+ }
67
+ }
68
+
69
+ // search for existing panel
70
+ const oldPanel = MPQSelectionPanel . findSelPanel (
71
+ args . modelPath ,
72
+ args . document . uri . toString ( )
73
+ ) ;
74
+ if ( oldPanel ) {
75
+ oldPanel . _panel . reveal ( column ) ;
76
+ return ;
77
+ }
78
+
79
+ // Otherwise, create a new panel.
80
+ const lastSlash = args . modelPath . lastIndexOf ( path . sep ) + 1 ;
81
+ const fileNameExt = args . modelPath . substring ( lastSlash ) ;
82
+ const panel = vscode . window . createWebviewPanel (
83
+ MPQSelectionPanel . viewType ,
84
+ fileNameExt ,
85
+ column || vscode . ViewColumn . Two ,
86
+ { retainContextWhenHidden : true }
87
+ ) ;
88
+
89
+ const graphSelPanel = new MPQSelectionPanel (
90
+ panel ,
91
+ extensionUri ,
92
+ args ,
93
+ handler
94
+ ) ;
95
+
96
+ MPQSelectionPanel . panels . push ( graphSelPanel ) ;
97
+ graphSelPanel . loadContent ( ) ;
98
+ graphSelPanel . onForwardSelection ( args . names ) ;
99
+ }
100
+
101
+ private static findSelPanel (
102
+ docPath : string ,
103
+ id : string
104
+ ) : MPQSelectionPanel | undefined {
105
+ let result = undefined ;
106
+ MPQSelectionPanel . panels . forEach ( ( selpan ) => {
107
+ if ( docPath === selpan . _modelPath && id === selpan . _ownerId ) {
108
+ result = selpan ;
109
+ }
110
+ } ) ;
111
+ return result ;
112
+ }
113
+
57
114
private constructor (
58
115
panel : vscode . WebviewPanel ,
59
116
extensionUri : vscode . Uri ,
@@ -91,4 +148,15 @@ export class MPQSelectionPanel
91
148
public onViewMessage ( _message : any ) {
92
149
// TODO
93
150
}
151
+
152
+ public onForwardSelection ( selection : any ) {
153
+ let selections : string [ ] = [ ] ;
154
+ let items = selection as Array < string > ;
155
+ for ( let i = 0 ; i < items . length ; i ++ ) {
156
+ if ( items [ i ] . length > 0 ) {
157
+ selections . push ( items [ i ] ) ;
158
+ }
159
+ }
160
+ this . setSelection ( selections ) ;
161
+ }
94
162
}
0 commit comments