private void ShowRefactoringAdvice(IHighlighter highlighter, InplaceRefactoringInfo refactoringInfo)
        {
            sequentialLifetimes.Next(refactoringLifetime =>
            {
                var message = GetMessage();
                var options = GetOptions(refactoringInfo);
                agent.ShowBalloon(refactoringLifetime, string.Empty, message, options, new[] { "Cancel" }, false,
                                  balloonLifetime =>
                {
                    currentHighlighter = highlighter;

                    agent.ButtonClicked.Advise(balloonLifetime, _ => sequentialLifetimes.TerminateCurrent());
                    agent.BalloonOptionClicked.Advise(balloonLifetime, tag =>
                    {
                        // Terminate first. This kills the balloon window before we start
                        // the refactoring UI. If we start the refactoring UI first, I think
                        // it picks up the balloon window as its parent, and it closes when
                        // the balloon closes
                        sequentialLifetimes.TerminateCurrent();

                        var action = tag as Action;
                        if (action != null)
                        {
                            action();
                        }
                    });
                });
            });
        }
        private IList <BalloonOption> GetOptions(InplaceRefactoringInfo refactoringInfo)
        {
            var applyRefactoringMessage = "Apply refactoring";

            switch (refactoringInfo.Type)
            {
            case InplaceRefactoringType.Rename:
                applyRefactoringMessage = "Apply rename refactoring (Alt+Enter)";
                break;

            case InplaceRefactoringType.ChangeSignature:
                applyRefactoringMessage = "Apply change signature refactoring (Alt+Enter)";
                break;

            case InplaceRefactoringType.MoveStaticMembers:
                applyRefactoringMessage = "Apply move static members refactoring (Alt+Enter)";
                break;
            }

            // ReSharper disable ConvertToLambdaExpression
            Action applyRefactoringAction = () =>
            {
                ReadLockCookie.GuardedExecute(() =>
                {
                    Lifetimes.Using(l =>
                    {
                        // I think this will fail if the cursor moves out of the refactoring range
                        var dataRules = DataRules.AddRule("DoInplaceRefactoringContextActionBase",
                                                          DataConstants.SOLUTION, solution);
                        var dataContext = actionManager.DataContexts.CreateOnSelection(l, dataRules);
                        RefactoringActionUtil.ExecuteRefactoring(dataContext,
                                                                 refactoringInfo.CreateRefactoringWorkflow());
                    });
                });
            };
            // ReSharper restore ConvertToLambdaExpression

            var options = new List <BalloonOption>
            {
                new BalloonOption(applyRefactoringMessage, applyRefactoringAction),
                new BalloonOption("Just edit the code without help")
            };

            return(options);
        }