Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unregister maplayers itemsProvider and widget control on terminate #3003

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@itwin/map-layers",
"comment": "Unregister maplayers itemsProvider and widget control on terminate.",
"type": "none"
}
],
"packageName": "@itwin/map-layers"
}
19 changes: 13 additions & 6 deletions extensions/map-layers/src/mapLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { IModelApp, UserPreferencesAccess } from "@itwin/core-frontend";
import { MapLayersUiItemsProvider, MapLayersWidgetControl } from "./ui/MapLayersUiItemsProvider";
import { MapLayersUiItemsProvider } from "./ui/MapLayersUiItemsProvider";
import { UiItemsManager } from "@itwin/appui-abstract";
import { ConfigurableUiManager } from "@itwin/appui-react";

/** MapLayersUI is use when the package is used as a dependency to another app.
* '''ts
Expand All @@ -16,6 +15,7 @@ import { ConfigurableUiManager } from "@itwin/appui-react";
export class MapLayersUI {
private static _defaultNs = "mapLayers";
private static _uiItemsProvider: MapLayersUiItemsProvider;
private static _itemsProviderRegistered?: boolean;

private static _iTwinConfig?: UserPreferencesAccess;
public static get iTwinConfig(): UserPreferencesAccess | undefined { return this._iTwinConfig; }
Expand All @@ -40,15 +40,22 @@ export class MapLayersUI {

// _uiItemsProvider always created to provide access to localization.
MapLayersUI._uiItemsProvider = new MapLayersUiItemsProvider(IModelApp.localization);
if (registerItemsProvider)
if (registerItemsProvider) {
UiItemsManager.register(MapLayersUI._uiItemsProvider);
else
ConfigurableUiManager.registerControl(MapLayersWidgetControl.id, MapLayersWidgetControl);
}
MapLayersUI._itemsProviderRegistered = registerItemsProvider;
}

/** Unregisters the GeoTools internationalization service namespace */
/** Unregisters internationalization service namespace and UiItemManager / control */
public static terminate() {
IModelApp.localization.unregisterNamespace(this.localizationNamespace);

if (MapLayersUI._itemsProviderRegistered !== undefined) {
if (MapLayersUI._itemsProviderRegistered) {
UiItemsManager.unregister(MapLayersUI._uiItemsProvider.id);
}
MapLayersUI._itemsProviderRegistered = undefined;
}
}

/** The internationalization service namespace. */
Expand Down
2 changes: 1 addition & 1 deletion extensions/map-layers/src/test/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class TestUtils {
public static async initialize() {
if (!TestUtils._uiComponentsInitialized) {

await MapLayersUI.initialize(true);
await MapLayersUI.initialize(false);
TestUtils._uiComponentsInitialized = true;
}
}
Expand Down