示例#1
0
        public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate)
        {
            // Better to check everything now and then work with valid data.

            ITextControl textControl = context.GetData(TextControlDataConstants.TEXT_CONTROL);

            if (textControl == null)
            {
                return(false);
            }

            if (textControl.IsReadOnly)
            {
                return(false);
            }

            if (textControl.Selection.IsDisjoint())
            {
                return(false);
            }

            IEquatableList <TextControlPosRange> equatableList = textControl.Selection.Ranges.Value;

            if (equatableList.Count > 1)
            {
                return(false);
            }

            ISolution solution = context.GetData(ProjectModelDataConstants.SOLUTION);

            if (solution == null)
            {
                return(false);
            }

            IPsiSourceFile psiSourceFile = textControl.Document.GetPsiSourceFile(solution);

            if (psiSourceFile == null)
            {
                return(false);
            }

            if (!psiSourceFile.IsValid())
            {
                return(false);
            }

            TextRange textRange =
                equatableList.Count == 1 ? equatableList[0].ToDocRangeNormalized() : new TextRange(textControl.Caret.Offset());
            DocumentRange range   = new DocumentRange(textControl.Document, textRange);
            ICSharpFile   psiFile = psiSourceFile.GetPsiFile <CSharpLanguage>(range) as ICSharpFile;

            if (psiFile == null)
            {
                return(false);
            }

            if (!psiFile.IsValid())
            {
                return(false);
            }

            if (context.GetData(UIDataConstants.PopupWindowContextSource) == null)
            {
                return(false);
            }

            return(true);
        }