@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
68 lines • 2.63 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToggleToolTipsTool = void 0;
/** @packageDocumentation
* @module Tools
*/
const core_frontend_1 = require("@itwin/core-frontend");
const parseToggle_1 = require("./parseToggle");
/** Augments tooltips with detailed information useful for debugging.
* @internal
*/
class DebugToolTipProvider {
static _instance;
async augmentToolTip(hit, tooltipPromise) {
// discard and overwrite
await tooltipPromise;
const keys = ["sourceId", "modelId", "subCategoryId", "tileId", "geometryClass"];
let html = "";
for (const key of keys) {
const value = hit[key];
if (undefined === value)
continue;
html = `${html + key}: ${value.toString()}<br>`;
}
const div = document.createElement("div");
div.innerHTML = html;
return div;
}
static setEnabled(enabled) {
if (undefined === enabled)
enabled = undefined === this._instance;
if (enabled) {
if (undefined === this._instance) {
this._instance = new DebugToolTipProvider();
core_frontend_1.IModelApp.viewManager.addToolTipProvider(this._instance);
}
}
else if (undefined !== this._instance) {
core_frontend_1.IModelApp.viewManager.dropToolTipProvider(this._instance);
this._instance = undefined;
}
}
}
/** Replaces the default tooltips displayed when mousing over elements to instead display information useful for debugging, including
* element, model, subcategory, and tile Ids as well as geometry class.
* @beta
*/
class ToggleToolTipsTool extends core_frontend_1.Tool {
static toolId = "ToggleToolTips";
static get minArgs() { return 0; }
static get maxArgs() { return 1; }
async run(enable) {
DebugToolTipProvider.setEnabled(enable);
return true;
}
async parseAndRun(...args) {
const enable = (0, parseToggle_1.parseToggle)(args[0]);
if (typeof enable !== "string")
await this.run(enable);
return true;
}
}
exports.ToggleToolTipsTool = ToggleToolTipsTool;
//# sourceMappingURL=ToolTipProvider.js.map