public bool Present(IMenuItemDescriptor descriptor, IOccurrence occurrence,
                            OccurrencePresentationOptions occurrencePresentationOptions)
        {
            var unityOccurrence = (occurrence as UnityAssetOccurrence).NotNull("occurrence as UnityAssetOccurrence != null");

            var displayText = GetDisplayText(unityOccurrence) + OccurrencePresentationUtil.TextContainerDelimiter;

            descriptor.Text = displayText;
            OccurrencePresentationUtil.AppendRelatedFile(descriptor, unityOccurrence.SourceFile.DisplayName.Replace('\\', '/'));

            descriptor.Icon = UnityFileTypeThemedIcons.FileUnity.Id;
            return(true);
        }
Exemplo n.º 2
0
        public override void OnClick(CodeInsightsHighlighting highlighting, ISolution solution)
        {
            if (highlighting is UnityInspectorCodeInsightsHighlighting unityInspectorCodeInsightsHighlighting)
            {
                Shell.Instance.GetComponent <JetPopupMenus>().Show(solution.GetLifetime(),
                                                                   JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems, (lifetime, menu) =>
                {
                    var presentationType = unityInspectorCodeInsightsHighlighting.UnityPresentationType;
                    var initValue        = unityInspectorCodeInsightsHighlighting.ConstantValue;
                    var declaredElement  = (highlighting.DeclaredElement as IClrDeclaredElement).NotNull("declaredElement != null");

                    if (!declaredElement.IsValid())
                    {
                        return;
                    }

                    var result = GetAssetGuidAndPropertyName(solution, declaredElement);
                    if (!result.HasValue)
                    {
                        return;
                    }


                    var valuesCache = solution.GetComponent <UnitySceneDataLocalCache>();
                    var values      = valuesCache.GetPropertyValues(result.Value.guid, result.Value.propertyName);

                    menu.Caption.Value = WindowlessControlAutomation.Create("Inspector values");
                    menu.KeyboardAcceleration.Value = KeyboardAccelerationFlags.QuickSearch;

                    var valuesToShow = values.Where(t => !IsSameWithInitializer(t.Value, presentationType, initValue)).Take(POP_UP_MAX_COUNT);
                    foreach (var valueWithLocation in valuesToShow)
                    {
                        var value = valueWithLocation.Value;
                        if (ShouldShowUnknownPresentation(presentationType))
                        {
                            menu.ItemKeys.Add(valueWithLocation);
                        }
                        else
                        {
                            menu.ItemKeys.Add(valueWithLocation);
                        }
                    }

                    menu.DescribeItem.Advise(lifetime, e =>
                    {
                        var value = (e.Key as MonoBehaviourPropertyValueWithLocation).NotNull("value != null");

                        string shortPresentation;
                        if (ShouldShowUnknownPresentation(presentationType))
                        {
                            shortPresentation = "...";
                        }
                        else
                        {
                            if (!declaredElement.IsValid())
                            {
                                return;
                            }

                            using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet())
                            {
                                var type          = declaredElement.Type();
                                shortPresentation = GetPresentation(value, presentationType, type, solution,
                                                                    declaredElement.Module, true);
                            }
                        }

                        e.Descriptor.Text = shortPresentation;
                        OccurrencePresentationUtil.AppendRelatedFile(e.Descriptor, value.File.DisplayName.Replace("\\", "/"));

                        e.Descriptor.Icon  = UnityFileTypeThemedIcons.FileUnity.Id;
                        e.Descriptor.Style = MenuItemStyle.Enabled;
                    });

                    menu.ItemClicked.Advise(lifetime, key =>
                    {
                        if (!myConnectionTracker.IsConnectionEstablished())
                        {
                            ShowNotification();
                            return;
                        }

                        var value = (key as MonoBehaviourPropertyValueWithLocation).NotNull("value != null");

                        UnityEditorFindUsageResultCreator.CreateRequestAndShow(myUnityHost, solution.SolutionDirectory, myUnitySceneDataLocalCache,
                                                                               value.Value.MonoBehaviour, value.File);
                    });
                });
            }
        }