# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
import omni.ext
import omni.kit.ui

from .inspector_window import InspectorWindow


class InspectorExtension(omni.ext.IExt):
    """The entry point for Inspector Window"""

    MENU_PATH = "Window/Inspector"

    def on_startup(self):
        editor_menu = omni.kit.ui.get_editor_menu()
        if editor_menu:
            self._menu = editor_menu.add_item(InspectorExtension.MENU_PATH, self.show_window, toggle=True, value=True)

        self.show_window(None, True)

    def on_shutdown(self):
        self._menu = None
        self._window.destroy()
        self._window = None

    def _visiblity_changed_fn(self, visible):
        editor_menu = omni.kit.ui.get_editor_menu()
        if editor_menu:
            editor_menu.set_value(InspectorExtension.MENU_PATH, visible)

    def show_window(self, menu, value):
        if value:
            self._window = InspectorWindow()
        elif self._window:
            self._window.destroy()
            self._window = None
