@@ -7,40 +7,13 @@ import {
7
7
SelectionType
8
8
} from '@jupytergis/schema' ;
9
9
import { JupyterFrontEnd } from '@jupyterlab/application' ;
10
- import { WidgetTracker } from '@jupyterlab/apputils' ;
10
+ import { showErrorMessage , WidgetTracker } from '@jupyterlab/apputils' ;
11
11
import { ITranslator } from '@jupyterlab/translation' ;
12
- import { redoIcon , undoIcon } from '@jupyterlab/ui-components' ;
13
12
13
+ import { CommandIDs , icons } from './constants' ;
14
14
import { LayerBrowserWidget } from './dialogs/layerBrowserDialog' ;
15
15
import { CreationFormDialog } from './dialogs/formdialog' ;
16
16
import { JupyterGISWidget } from './widget' ;
17
- import { geoJSONIcon } from './icons' ;
18
-
19
- /**
20
- * The command IDs.
21
- */
22
- export namespace CommandIDs {
23
- export const createNew = 'jupytergis:create-new-jGIS-file' ;
24
- export const redo = 'jupytergis:redo' ;
25
- export const undo = 'jupytergis:undo' ;
26
-
27
- export const openLayerBrowser = 'jupytergis:openLayerBrowser' ;
28
-
29
- export const newGeoJSONLayer = 'jupytergis:newGeoJSONLayer' ;
30
- export const newGeoJSONSource = 'jupytergis:newGeoJSONSource' ;
31
-
32
- export const newVectorTileLayer = 'jupytergis:newVectorTileLayer' ;
33
-
34
- export const newVectorLayer = 'jupytergis:newVectorLayer' ;
35
-
36
- export const renameLayer = 'jupytergis:renameLayer' ;
37
- export const removeLayer = 'jupytergis:removeLayer' ;
38
- export const renameGroup = 'jupytergis:renameGroup' ;
39
- export const removeGroup = 'jupytergis:removeGroup' ;
40
-
41
- export const moveLayersToGroup = 'jupytergis:moveLayersToGroup' ;
42
- export const moveLayerToNewGroup = 'jupytergis:moveLayerToNewGroup' ;
43
- }
44
17
45
18
/**
46
19
* Add the commands to the application's command registry.
@@ -69,7 +42,7 @@ export function addCommands(
69
42
return current . context . model . sharedModel . redo ( ) ;
70
43
}
71
44
} ,
72
- icon : redoIcon
45
+ ... icons . get ( CommandIDs . redo ) ?. icon
73
46
} ) ;
74
47
75
48
commands . addCommand ( CommandIDs . undo , {
@@ -86,24 +59,99 @@ export function addCommands(
86
59
return current . context . model . sharedModel . undo ( ) ;
87
60
}
88
61
} ,
89
- icon : undoIcon
62
+ ... icons . get ( CommandIDs . undo )
90
63
} ) ;
91
64
65
+ /**
66
+ * SOURCES and LAYERS creation commands.
67
+ */
92
68
commands . addCommand ( CommandIDs . openLayerBrowser , {
93
69
label : trans . __ ( 'Open Layer Browser' ) ,
94
70
isEnabled : ( ) => {
95
71
return tracker . currentWidget
96
72
? tracker . currentWidget . context . model . sharedModel . editable
97
73
: false ;
98
74
} ,
99
- iconClass : 'fa fa-book-open' ,
100
75
execute : Private . createLayerBrowser (
101
76
tracker ,
102
77
layerBrowserRegistry ,
103
78
formSchemaRegistry
104
- )
79
+ ) ,
80
+ ...icons . get ( CommandIDs . openLayerBrowser )
81
+ } ) ;
82
+
83
+ commands . addCommand ( CommandIDs . newGeoJSONLayer , {
84
+ label : trans . __ ( 'New geoJSON layer' ) ,
85
+ isEnabled : ( ) => {
86
+ return tracker . currentWidget
87
+ ? tracker . currentWidget . context . model . sharedModel . editable
88
+ : false ;
89
+ } ,
90
+ execute : Private . createGeoJSONLayer ( tracker , formSchemaRegistry ) ,
91
+ ...icons . get ( CommandIDs . newGeoJSONLayer )
105
92
} ) ;
106
93
94
+ commands . addCommand ( CommandIDs . newVectorTileLayer , {
95
+ label : trans . __ ( 'New vector tile layer' ) ,
96
+ isEnabled : ( ) => {
97
+ return tracker . currentWidget
98
+ ? tracker . currentWidget . context . model . sharedModel . editable
99
+ : false ;
100
+ } ,
101
+ execute : Private . createVectorTileLayer ( tracker , formSchemaRegistry ) ,
102
+ ...icons . get ( CommandIDs . newVectorTileLayer )
103
+ } ) ;
104
+
105
+ /**
106
+ * SOURCES only commands.
107
+ */
108
+ commands . addCommand ( CommandIDs . newGeoJSONSource , {
109
+ label : args =>
110
+ args . from === 'contextMenu'
111
+ ? trans . __ ( 'GeoJSON' )
112
+ : trans . __ ( 'Add GeoJSON data from file' ) ,
113
+ isEnabled : ( ) => {
114
+ return tracker . currentWidget
115
+ ? tracker . currentWidget . context . model . sharedModel . editable
116
+ : false ;
117
+ } ,
118
+ execute : Private . createGeoJSONSource ( tracker , formSchemaRegistry ) ,
119
+ ...icons . get ( CommandIDs . newGeoJSONSource ) ?. icon
120
+ } ) ;
121
+
122
+ commands . addCommand ( CommandIDs . removeSource , {
123
+ label : trans . __ ( 'Remove Source' ) ,
124
+ execute : ( ) => {
125
+ const model = tracker . currentWidget ?. context . model ;
126
+ Private . removeSelectedItems ( model , 'source' , selection => {
127
+ if ( ! ( model ?. getLayersBySource ( selection ) . length ?? true ) ) {
128
+ model ?. sharedModel . removeSource ( selection ) ;
129
+ } else {
130
+ showErrorMessage (
131
+ 'Remove source error' ,
132
+ 'The source is used by a layer.'
133
+ ) ;
134
+ }
135
+ } ) ;
136
+ }
137
+ } ) ;
138
+
139
+ commands . addCommand ( CommandIDs . renameSource , {
140
+ label : trans . __ ( 'Rename Source' ) ,
141
+ execute : async ( ) => {
142
+ const model = tracker . currentWidget ?. context . model ;
143
+ await Private . renameSelectedItem ( model , 'source' , ( sourceId , newName ) => {
144
+ const source = model ?. getSource ( sourceId ) ;
145
+ if ( source ) {
146
+ source . name = newName ;
147
+ model ?. sharedModel . updateSource ( sourceId , source ) ;
148
+ }
149
+ } ) ;
150
+ }
151
+ } ) ;
152
+ /**
153
+ * LAYERS and LAYER GROUPS only commands.
154
+ */
107
155
commands . addCommand ( CommandIDs . removeLayer , {
108
156
label : trans . __ ( 'Remove Layer' ) ,
109
157
execute : ( ) => {
@@ -228,48 +276,15 @@ export function addCommands(
228
276
}
229
277
} ) ;
230
278
231
- commands . addCommand ( CommandIDs . newGeoJSONLayer , {
232
- label : trans . __ ( 'New vector layer' ) ,
233
- isEnabled : ( ) => {
234
- return tracker . currentWidget
235
- ? tracker . currentWidget . context . model . sharedModel . editable
236
- : false ;
237
- } ,
238
- iconClass : 'fa fa-vector-square' ,
239
- execute : Private . createGeoJSONLayer ( tracker , formSchemaRegistry )
240
- } ) ;
241
-
242
279
commands . addCommand ( CommandIDs . newVectorLayer , {
243
280
label : trans . __ ( 'New vector layer' ) ,
244
281
isEnabled : ( ) => {
245
282
return tracker . currentWidget
246
283
? tracker . currentWidget . context . model . sharedModel . editable
247
284
: false ;
248
285
} ,
249
- iconClass : 'fa fa-vector-square' ,
250
- execute : Private . createVectorLayer ( tracker , formSchemaRegistry )
251
- } ) ;
252
-
253
- commands . addCommand ( CommandIDs . newVectorTileLayer , {
254
- label : trans . __ ( 'New vector tile layer' ) ,
255
- isEnabled : ( ) => {
256
- return tracker . currentWidget
257
- ? tracker . currentWidget . context . model . sharedModel . editable
258
- : false ;
259
- } ,
260
- iconClass : 'fa fa-vector-square' ,
261
- execute : Private . createVectorTileLayer ( tracker , formSchemaRegistry )
262
- } ) ;
263
-
264
- commands . addCommand ( CommandIDs . newGeoJSONSource , {
265
- label : trans . __ ( 'Add GeoJSON data from file' ) ,
266
- isEnabled : ( ) => {
267
- return tracker . currentWidget
268
- ? tracker . currentWidget . context . model . sharedModel . editable
269
- : false ;
270
- } ,
271
- icon : geoJSONIcon ,
272
- execute : Private . createGeoJSONSource ( tracker , formSchemaRegistry )
286
+ execute : Private . createVectorLayer ( tracker , formSchemaRegistry ) ,
287
+ ...icons . get ( CommandIDs . newVectorLayer )
273
288
} ) ;
274
289
}
275
290
0 commit comments