diff --git a/packages/base/src/commands.ts b/packages/base/src/commands.ts index dbecafc4..86287a45 100644 --- a/packages/base/src/commands.ts +++ b/packages/base/src/commands.ts @@ -9,42 +9,11 @@ import { import { JupyterFrontEnd } from '@jupyterlab/application'; import { showErrorMessage, WidgetTracker } from '@jupyterlab/apputils'; import { ITranslator } from '@jupyterlab/translation'; -import { redoIcon, undoIcon } from '@jupyterlab/ui-components'; +import { CommandIDs, icons } from './constants'; import { LayerBrowserWidget } from './dialogs/layerBrowserDialog'; import { CreationFormDialog } from './dialogs/formdialog'; import { JupyterGISWidget } from './widget'; -import { geoJSONIcon } from './icons'; - -/** - * The command IDs. - */ -export namespace CommandIDs { - export const createNew = 'jupytergis:create-new-jGIS-file'; - export const redo = 'jupytergis:redo'; - export const undo = 'jupytergis:undo'; - - // Layers and sources commands - export const openLayerBrowser = 'jupytergis:openLayerBrowser'; - export const newGeoJSONLayer = 'jupytergis:newGeoJSONLayer'; - export const newVectorTileLayer = 'jupytergis:newVectorTileLayer'; - - // Sources only commands - export const newGeoJSONSource = 'jupytergis:newGeoJSONSource'; - export const removeSource = 'jupytergis:removeSource'; - export const renameSource = 'jupytergis:renameSource'; - - // Layers only commands - export const newVectorLayer = 'jupytergis:newVectorLayer'; - - export const renameLayer = 'jupytergis:renameLayer'; - export const removeLayer = 'jupytergis:removeLayer'; - export const renameGroup = 'jupytergis:renameGroup'; - export const removeGroup = 'jupytergis:removeGroup'; - - export const moveLayersToGroup = 'jupytergis:moveLayersToGroup'; - export const moveLayerToNewGroup = 'jupytergis:moveLayerToNewGroup'; -} /** * Add the commands to the application's command registry. @@ -73,7 +42,7 @@ export function addCommands( return current.context.model.sharedModel.redo(); } }, - icon: redoIcon + ...icons.get(CommandIDs.redo)?.icon }); commands.addCommand(CommandIDs.undo, { @@ -90,7 +59,7 @@ export function addCommands( return current.context.model.sharedModel.undo(); } }, - icon: undoIcon + ...icons.get(CommandIDs.undo) }); /** @@ -103,23 +72,23 @@ export function addCommands( ? tracker.currentWidget.context.model.sharedModel.editable : false; }, - iconClass: 'fa fa-book-open', execute: Private.createLayerBrowser( tracker, layerBrowserRegistry, formSchemaRegistry - ) + ), + ...icons.get(CommandIDs.openLayerBrowser) }); commands.addCommand(CommandIDs.newGeoJSONLayer, { - label: trans.__('New vector layer'), + label: trans.__('New geoJSON layer'), isEnabled: () => { return tracker.currentWidget ? tracker.currentWidget.context.model.sharedModel.editable : false; }, - icon: geoJSONIcon, - execute: Private.createGeoJSONLayer(tracker, formSchemaRegistry) + execute: Private.createGeoJSONLayer(tracker, formSchemaRegistry), + ...icons.get(CommandIDs.newGeoJSONLayer) }); commands.addCommand(CommandIDs.newVectorTileLayer, { @@ -129,8 +98,8 @@ export function addCommands( ? tracker.currentWidget.context.model.sharedModel.editable : false; }, - iconClass: 'fa fa-vector-square', - execute: Private.createVectorTileLayer(tracker, formSchemaRegistry) + execute: Private.createVectorTileLayer(tracker, formSchemaRegistry), + ...icons.get(CommandIDs.newVectorTileLayer) }); /** @@ -146,8 +115,8 @@ export function addCommands( ? tracker.currentWidget.context.model.sharedModel.editable : false; }, - icon: geoJSONIcon, - execute: Private.createGeoJSONSource(tracker, formSchemaRegistry) + execute: Private.createGeoJSONSource(tracker, formSchemaRegistry), + ...icons.get(CommandIDs.newGeoJSONSource)?.icon }); commands.addCommand(CommandIDs.removeSource, { @@ -314,8 +283,8 @@ export function addCommands( ? tracker.currentWidget.context.model.sharedModel.editable : false; }, - iconClass: 'fa fa-vector-square', - execute: Private.createVectorLayer(tracker, formSchemaRegistry) + execute: Private.createVectorLayer(tracker, formSchemaRegistry), + ...icons.get(CommandIDs.newVectorLayer) }); } diff --git a/packages/base/src/constants.ts b/packages/base/src/constants.ts new file mode 100644 index 00000000..b7ec06fc --- /dev/null +++ b/packages/base/src/constants.ts @@ -0,0 +1,58 @@ +import { LabIcon, redoIcon, undoIcon } from '@jupyterlab/ui-components'; +import { geoJSONIcon, rasterIcon } from './icons'; + +/** + * The command IDs. + */ +export namespace CommandIDs { + export const createNew = 'jupytergis:create-new-jGIS-file'; + export const redo = 'jupytergis:redo'; + export const undo = 'jupytergis:undo'; + + // Layers and sources commands + export const openLayerBrowser = 'jupytergis:openLayerBrowser'; + export const newGeoJSONLayer = 'jupytergis:newGeoJSONLayer'; + export const newVectorTileLayer = 'jupytergis:newVectorTileLayer'; + + // Sources only commands + export const newGeoJSONSource = 'jupytergis:newGeoJSONSource'; + export const removeSource = 'jupytergis:removeSource'; + export const renameSource = 'jupytergis:renameSource'; + + // Layers only commands + export const newVectorLayer = 'jupytergis:newVectorLayer'; + + export const renameLayer = 'jupytergis:renameLayer'; + export const removeLayer = 'jupytergis:removeLayer'; + export const renameGroup = 'jupytergis:renameGroup'; + export const removeGroup = 'jupytergis:removeGroup'; + + export const moveLayersToGroup = 'jupytergis:moveLayersToGroup'; + export const moveLayerToNewGroup = 'jupytergis:moveLayerToNewGroup'; +} + +interface IRegisteredIcon { + icon?: LabIcon; + iconClass?: string; +} + +const iconObject = { + RasterSource: { icon: rasterIcon }, + GeoJSONSource: { icon: geoJSONIcon }, + VectorTileSource: { iconClass: 'fa fa-vector-square' }, + RasterLayer: { icon: rasterIcon }, + [CommandIDs.redo]: { icon: redoIcon }, + [CommandIDs.undo]: { icon: undoIcon }, + [CommandIDs.openLayerBrowser]: { iconClass: 'fa fa-book-open' }, + [CommandIDs.newGeoJSONLayer]: { icon: geoJSONIcon }, + [CommandIDs.newVectorTileLayer]: { iconClass: 'fa fa-vector-square' }, + [CommandIDs.newGeoJSONSource]: { icon: geoJSONIcon }, + [CommandIDs.newVectorLayer]: { iconClass: 'fa fa-vector-square' } +}; + +/** + * The registered icons + */ +export const icons = new Map( + Object.entries(iconObject) +); diff --git a/packages/base/src/index.ts b/packages/base/src/index.ts index 2ada3d20..4abe1252 100644 --- a/packages/base/src/index.ts +++ b/packages/base/src/index.ts @@ -1,4 +1,5 @@ export * from './commands'; +export * from './constants'; export * from './dialogs/formdialog'; export * from './mainview'; export * from './tools'; diff --git a/packages/base/src/panelview/components/layers.tsx b/packages/base/src/panelview/components/layers.tsx index 5a081f33..3572bb13 100644 --- a/packages/base/src/panelview/components/layers.tsx +++ b/packages/base/src/panelview/components/layers.tsx @@ -15,7 +15,8 @@ import { } from '@jupyterlab/ui-components'; import { Panel } from '@lumino/widgets'; import React, { MouseEvent, useEffect, useState } from 'react'; -import { nonVisibilityIcon, rasterIcon, visibilityIcon } from '../../icons'; +import { icons } from '../../constants'; +import { nonVisibilityIcon, visibilityIcon } from '../../icons'; import { IControlPanelModel } from '../../types'; const LAYERS_PANEL_CLASS = 'jp-gis-layerPanel'; @@ -368,9 +369,9 @@ function LayerComponent(props: ILayerProps): JSX.Element { onClick={setSelection} onContextMenu={setSelection} > - {layer.type === 'RasterLayer' && ( + {icons.has(layer.type) && ( )} diff --git a/packages/base/src/panelview/components/sources.tsx b/packages/base/src/panelview/components/sources.tsx index ff13430a..3fd75735 100644 --- a/packages/base/src/panelview/components/sources.tsx +++ b/packages/base/src/panelview/components/sources.tsx @@ -8,7 +8,7 @@ import { DOMUtils } from '@jupyterlab/apputils'; import { LabIcon, ReactWidget } from '@jupyterlab/ui-components'; import { Panel } from '@lumino/widgets'; import React, { MouseEvent, useEffect, useState } from 'react'; -import { geoJSONIcon, rasterIcon } from '../../icons'; +import { icons } from '../../constants'; import { IControlPanelModel } from '../../types'; const SOURCES_PANEL_CLASS = 'jp-gis-sourcePanel'; @@ -294,21 +294,9 @@ function SourceComponent(props: ISourceProps): JSX.Element { onClick={setSelection} onContextMenu={setSelection} > - {source.type === 'RasterSource' && ( + {icons.has(source.type) && ( - )} - {source.type === 'GeoJSONSource' && ( - - )} - {source.type === 'VectorTileSource' && ( - )} diff --git a/packages/base/src/toolbar/widget.tsx b/packages/base/src/toolbar/widget.tsx index 2f0f4836..a28d2849 100644 --- a/packages/base/src/toolbar/widget.tsx +++ b/packages/base/src/toolbar/widget.tsx @@ -10,7 +10,7 @@ import { CommandRegistry } from '@lumino/commands'; import { Widget } from '@lumino/widgets'; import * as React from 'react'; -import { CommandIDs } from '../commands'; +import { CommandIDs } from '../constants'; import { UsersItem } from './usertoolbaritem'; export const TOOLBAR_SEPARATOR_CLASS = 'jGIS-Toolbar-Separator';