예제 #1
0
        public void Execute(ISolution solution, ITextControl textControl)
        {
            var jetPopupMenus = solution.GetPsiServices().GetComponent <JetPopupMenus>();
            var cache         = solution.GetComponent <SpecflowStepsDefinitionsCache>();

            jetPopupMenus.ShowModal(JetPopupMenu.ShowWhen.AutoExecuteIfSingleEnabledItem,
                                    (lifetime, menu) =>
            {
                menu.Caption.Value = WindowlessControlAutomation.Create("Where to create the step ?");
                // FIXME: use class instead of files
                var project           = _reference.GetProject();
                var projectReferences = project?.GetAllModuleReferences().OfType <SimpleProjectToProjectReference>().ToList();

                var availableSteps = cache.AllBindingTypes
                                     .SelectMany(e => e.Value.Select(v => (fullClassName: e.Key, sourceFile: v)))
                                     .Where(e =>
                {
                    var(_, sourceFile) = e;
                    if (ReferenceEquals(sourceFile.GetProject(), project))
                    {
                        return(true);
                    }
                    if (projectReferences?.Any(x => x.Name == sourceFile.GetProject()?.Name) == true)
                    {
                        return(true);
                    }
                    return(false);
                })
                                     .Select(e => new AvailableBindingClass(e.sourceFile, e.fullClassName));
                // FIXME: Remove full qualifier when not needed

                menu.ItemKeys.AddRange(availableSteps);
                menu.DescribeItem.Advise(lifetime, e =>
                {
                    var key            = (AvailableBindingClass)e.Key;
                    e.Descriptor.Icon  = BulbThemedIcons.RedBulb.Id;
                    e.Descriptor.Style = MenuItemStyle.Enabled;
                    e.Descriptor.Text  = new RichText(key.FullClassName);
                });
                menu.ItemClicked.Advise(lifetime, key =>
                {
                    var targetFile = (AvailableBindingClass)key;
                    AddSpecflowStep(targetFile.SourceFile, _reference.GetStepKind(), _reference.GetStepText());
                });
                menu.PopupWindowContextSource = textControl.PopupWindowContextFactory.ForCaret();
            });
예제 #2
0
        //------------------------------------------------------------------------------------------------------------------------
        public static void PromptToOpenOrCreateClassFiles(Action <JetPopupMenus, JetPopupMenu, JetPopupMenu.ShowWhen> menuDisplayer, Lifetime lifetime, IDataContext context, ISolution solution
                                                          , IProject project, IClrTypeName clrTypeClassName, IList <TestCopProjectItem> targetProjects
                                                          , List <IClrDeclaredElement> preferred, List <IClrDeclaredElement> fullList)
        {
            var autoExecuteIfSingleEnabledItem = JetPopupMenu.ShowWhen.AutoExecuteIfSingleEnabledItem;
            var menuItems = new List <SimpleMenuItem>();

            if (preferred.Count > 0)
            {
                AppendNavigateToMenuItems(lifetime, solution, preferred, menuItems);
            }
            else
            {
                AppendNavigateToMenuItems(lifetime, solution, fullList, menuItems);
            }

            MoveBestMatchesToTopWhenSwitchingFromTestToCode(menuItems, project, targetProjects, clrTypeClassName);

            if (clrTypeClassName != null)
            {
                if (DeriveRelatedFileNameAndAddCreateMenus(context, lifetime, project, targetProjects, menuItems, clrTypeClassName))
                {
                    autoExecuteIfSingleEnabledItem = JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems;
                }
            }

            var menus = Shell.Instance.GetComponent <JetPopupMenus>();
            var menu  = menus.Create();

            menu.Caption.Value = WindowlessControlAutomation.Create("Switch to:");
            menu.SetItems(menuItems.ToArray());

            PositionPopMenuCorrectly(context, lifetime, menu);

            menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);
            menu.NoItemsBanner = WindowlessControlAutomation.Create("No destinations found.");

            menuDisplayer.Invoke(menus, menu, autoExecuteIfSingleEnabledItem);
        }
 private void OpenFileSelectionModal(JetPopupMenus jetPopupMenus, ITextControl textControl, ISet <SpecflowStepsDefinitionsCache.AvailableBindingClass> availableBindingClasses, GherkinStepKind getStepKind, string getStepText)
 {
     jetPopupMenus.ShowModal(JetPopupMenu.ShowWhen.AutoExecuteIfSingleEnabledItem,
                             (lifetime, menu) =>
     {
         menu.Caption.Value = WindowlessControlAutomation.Create("Where to create the step ?");
         menu.ItemKeys.AddRange(availableBindingClasses);
         menu.DescribeItem.Advise(lifetime, e =>
         {
             var key            = (SpecflowStepsDefinitionsCache.AvailableBindingClass)e.Key;
             e.Descriptor.Icon  = PsiCSharpThemedIcons.Csharp.Id;
             e.Descriptor.Style = MenuItemStyle.Enabled;
             e.Descriptor.Text  = new RichText(key.SourceFile.DisplayName);
         });
         menu.ItemClicked.Advise(lifetime, e =>
         {
             var availableBindingClass = (SpecflowStepsDefinitionsCache.AvailableBindingClass)e;
             AddSpecflowStep(availableBindingClass.SourceFile, availableBindingClass.ClassClrName, getStepKind, getStepText);
         });
         menu.PopupWindowContextSource = textControl.PopupWindowContextFactory.ForCaret();
     });
 }
        public void Execute(ISolution solution, ITextControl textControl)
        {
            var jetPopupMenus = solution.GetPsiServices().GetComponent <JetPopupMenus>();
            var cache         = solution.GetComponent <SpecflowStepsDefinitionsCache>();

            jetPopupMenus.ShowModal(JetPopupMenu.ShowWhen.AutoExecuteIfSingleEnabledItem,
                                    (lifetime, menu) =>
            {
                menu.Caption.Value = WindowlessControlAutomation.Create("Where to create the step ?");

                var availableSteps  = cache.GetBindingTypes(_reference.GetElement().GetPsiModule());
                var filesPerClasses = new OneToSetMap <string, SpecflowStepsDefinitionsCache.AvailableBindingClass>();
                foreach (var availableBindingClass in availableSteps)
                {
                    filesPerClasses.Add(availableBindingClass.ClassClrName, availableBindingClass);
                }

                menu.ItemKeys.AddRange(filesPerClasses);
                menu.DescribeItem.Advise(lifetime, e =>
                {
                    var(classClrFullName, _) = (KeyValuePair <string, ISet <SpecflowStepsDefinitionsCache.AvailableBindingClass> >)e.Key;

                    e.Descriptor.Icon  = PsiSymbolsThemedIcons.Class.Id;
                    e.Descriptor.Style = MenuItemStyle.Enabled;

                    var clrTypeName           = new ClrTypeName(classClrFullName);
                    e.Descriptor.Text         = new RichText(clrTypeName.ShortName, DeclaredElementPresenterTextStyles.ParameterInfo.GetStyle(DeclaredElementPresentationPartKind.Type));
                    e.Descriptor.ShortcutText = clrTypeName.GetNamespaceName();
                });
                menu.ItemClicked.Advise(lifetime, key =>
                {
                    var(_, availableBindingClasses) = (KeyValuePair <string, ISet <SpecflowStepsDefinitionsCache.AvailableBindingClass> >)key;
                    OpenFileSelectionModal(jetPopupMenus, textControl, availableBindingClasses, _reference.GetStepKind(), _reference.GetStepText());
                });
                menu.PopupWindowContextSource = textControl.PopupWindowContextFactory.ForCaret();
            });
        }
예제 #5
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);
                    });
                });
            }
        }