#if UNITY_2019_4_OR_NEWER
using System;
using System.Collections.Generic;
using System.Linq;
using StansAssets.Foundation.Editor;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace StansAssets.Plugins.Editor
{
///
/// Base class for Plugin Preferences Window
///
public abstract class PackagePreferencesWindow
{
TabController m_TabController;
///
/// Structure describing a Unity Package.
///
protected abstract UnityEditor.PackageManager.PackageInfo GetPackageInfo();
///
/// Gets Path used to place the SettingsProvider in the tree view of the Preferences or Project Settings window.
/// The path should be unique among all other settings paths and should use "/" as its separator.
///
protected abstract string SettingsPath { get; }
///
/// Gets the Scope of the SettingsProvider. The Scope determines whether the SettingsProvider appears
/// in the Preferences window (SettingsScope.User) or the Settings window (SettingsScope.Project).
///
protected abstract SettingsScope Scope { get; }
///
/// Add tab to the window top bar.
///
/// Tab label.
/// Tab content.
/// Will throw tab with the same label was already added.
protected void AddTab(string label, VisualElement content)
{
m_TabController.AddTab(label, content);
}
///
/// Activate tab by name
///
/// Early specified tab name
protected void ActivateTab(string name)
{
m_TabController.ActivateTab(name);
}
///
/// Set the flexible growth property of tabs content container
///
///
protected void ContentContainerFlexGrow(StyleFloat styleFloat)
{
m_TabController.ContentContainerFlexGrow(styleFloat);
}
///
/// Overrides SettingsProvider.OnActivate.
///
protected abstract void OnActivate(string searchContext, VisualElement rootElement);
///
/// Overrides SettingsProvider.OnDeactivate.
///
protected abstract void OnDeactivate();
void OnActivateWindow(string searchContext, VisualElement rootElement)
{
UIToolkitEditorUtility.CloneTreeAndApplyStyle(rootElement,
$"{PluginsDevKitPackage.UIToolkitPath}/SettingsWindow/PackageSettingsWindow");
// Hide search bar from PackageSettingsWindow. In preferences we already have search bar
// and it's value in "searchContext" parameter
var searchBar = rootElement.Q();
if (searchBar != null)
{
searchBar.style.visibility = Visibility.Hidden;
}
var packageInfo = GetPackageInfo();
rootElement.Q