Exemple #1
0
        public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
        {
            Declaration dec = (Declaration)item;

            if (!item.IsValid || position > dec.Colon.Start || !EnsureInitialized(itemTrackingSpan.TextBuffer))
            {
                yield break;
            }

            Microsoft.CSS.Core.TreeItems.RuleBlock rule = dec.FindType <RuleBlock>();
            if (!rule.IsValid)
            {
                yield break;
            }

            if (!dec.IsVendorSpecific())
            {
                IEnumerable <Declaration> vendors = VendorHelpers.GetMatchingVendorEntriesInRule(dec, rule, _schema);
                if (vendors.Any(v => v.Start > dec.Start))
                {
                    yield return(new VendorOrderSmartTagAction(itemTrackingSpan, vendors.Last(), dec));
                }
            }
            else
            {
                ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, _schema);
                if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText))
                {
                    yield return(new MissingStandardSmartTagAction(itemTrackingSpan, dec, entry.DisplayText));
                }
            }
        }
Exemple #2
0
        public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
        {
            Declaration dec = (Declaration)item;

            if (!item.IsValid || position > dec.Colon.Start || !view.TextBuffer.ContentType.IsOfType("css"))
            {
                yield break;
            }

            RuleBlock rule = dec.FindType <RuleBlock>();

            if (!rule.IsValid)
            {
                yield break;
            }

            ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaRootForBuffer(view.TextBuffer);

            if (!dec.IsVendorSpecific())
            {
                IEnumerable <Declaration> vendors = VendorHelpers.GetMatchingVendorEntriesInRule(dec, rule, schema);
                if (vendors.Any(v => v.Start > dec.Start))
                {
                    yield return(new VendorOrderSmartTagAction(itemTrackingSpan, vendors.Last(), dec, view));
                }
            }
            else
            {
                ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, schema);
                if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText))
                {
                    yield return(new MissingStandardSmartTagAction(itemTrackingSpan, dec, entry.DisplayText, view));
                }
            }
        }
Exemple #3
0
        public static IEnumerable<string> GetMissingVendorSpecifics(this Declaration declaration, ICssSchemaInstance schema)
        {
            RuleBlock rule = declaration.FindType<RuleBlock>();
            IEnumerable<string> possible = GetPossibleVendorSpecifics(declaration, schema);

            foreach (string item in possible)
            {
                if (!rule.GetDeclarations().Any(d => d.PropertyName != null && d.PropertyName.Text == item))
                    yield return item;
            }
        }
Exemple #4
0
        public override void Invoke()
        {
            RuleBlock     rule      = _declaration.FindType <RuleBlock>();
            StringBuilder sb        = new StringBuilder();
            string        separator = rule.Text.Contains("\r") || rule.Text.Contains("\n") ? Environment.NewLine : " ";

            foreach (var entry in _prefixes)
            {
                sb.Append(entry + _declaration.Text + separator);
            }

            EditorExtensionsPackage.DTE.UndoContext.Open(DisplayText);
            _span.TextBuffer.Replace(_span.GetSpan(_span.TextBuffer.CurrentSnapshot), sb.ToString() + _declaration.Text);
            if (separator == Environment.NewLine)
            {
                EditorExtensionsPackage.ExecuteCommand("Edit.FormatSelection");
            }
            EditorExtensionsPackage.DTE.UndoContext.Close();
        }
Exemple #5
0
        private bool HandleDeclaration(Direction direction, Declaration declaration)
        {
            RuleBlock rule = declaration.FindType <RuleBlock>();

            if (rule == null || rule.Text.IndexOfAny(new[] { '\r', '\n' }) == -1 || (direction == Direction.Up && rule.Declarations.First() == declaration) || (direction == Direction.Down && rule.Declarations.Last() == declaration))
            {
                return(false);
            }

            Declaration sibling = null;
            string      text    = null;

            if (direction == Direction.Up)
            {
                sibling = rule.Declarations.ElementAt(rule.Declarations.IndexOf(declaration) - 1);
                text    = declaration.Text + sibling.Text;
            }
            else
            {
                sibling = rule.Declarations.ElementAt(rule.Declarations.IndexOf(declaration) + 1);
                text    = sibling.Text + declaration.Text;
            }

            EditorExtensionsPackage.DTE.UndoContext.Open("Move CSS declaration");

            using (ITextEdit edit = _textView.TextBuffer.CreateEdit())
            {
                int start = Math.Min(declaration.Start, sibling.Start);
                int end   = Math.Max(declaration.AfterEnd, sibling.AfterEnd);
                edit.Replace(start, end - start, text);
                edit.Apply();

                if (direction == Direction.Up)
                {
                    _textView.Caret.MoveTo(new SnapshotPoint(_textView.TextBuffer.CurrentSnapshot, sibling.Start + 1));
                }

                EditorExtensionsPackage.DTE.ExecuteCommand("Edit.FormatSelection");
                EditorExtensionsPackage.DTE.UndoContext.Close();
            }

            return(true);
        }
Exemple #6
0
        public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
        {
            Declaration dec = (Declaration)item;

            if (context == null || !dec.IsValid)
            {
                return(ItemCheckResult.Continue);
            }

            RuleBlock rule = dec.FindType <RuleBlock>();

            if (!rule.IsValid)
            {
                return(ItemCheckResult.Continue);
            }

            if (!dec.IsVendorSpecific())
            {
                ICssSchemaInstance schema = CssEditorChecker.GetSchemaForItem(context, item);
                bool hasVendor            = VendorHelpers.HasVendorLaterInRule(dec, schema);
                if (hasVendor)
                {
                    context.AddError(new SimpleErrorTag(dec.PropertyName, Resources.BestPracticeStandardPropertyOrder));
                    return(ItemCheckResult.CancelCurrentItem);
                }
            }
            else
            {
                ICssCompletionListEntry entry = VendorHelpers.GetMatchingStandardEntry(dec, context);
                if (entry != null && !rule.Declarations.Any(d => d.PropertyName != null && d.PropertyName.Text == entry.DisplayText))
                {
                    if (entry.DisplayText != "filter" && entry.DisplayText != "zoom" && entry.DisplayText != "behavior")
                    {
                        string message = string.Format(CultureInfo.InvariantCulture, Resources.BestPracticeAddMissingStandardProperty, entry.DisplayText);
                        context.AddError(new SimpleErrorTag(dec.PropertyName, message));
                        return(ItemCheckResult.CancelCurrentItem);
                    }
                }
            }

            return(ItemCheckResult.Continue);
        }
        private bool HandleDeclaration(Direction direction, Declaration declaration)
        {
            RuleBlock rule = declaration.FindType<RuleBlock>();
            if (rule == null || rule.Text.IndexOfAny(new[] { '\r', '\n' }) == -1 || (direction == Direction.Up && rule.Declarations.First() == declaration) || (direction == Direction.Down && rule.Declarations.Last() == declaration))
                return false;

            Declaration sibling = null;
            string text = null;

            if (direction == Direction.Up)
            {
                sibling = rule.Declarations.ElementAt(rule.Declarations.IndexOf(declaration) - 1);
                text = declaration.Text + sibling.Text;
            }
            else
            {
                sibling = rule.Declarations.ElementAt(rule.Declarations.IndexOf(declaration) + 1);
                text = sibling.Text + declaration.Text;
            }

            EditorExtensionsPackage.DTE.UndoContext.Open("Move CSS declaration");

            using (ITextEdit edit = _textView.TextBuffer.CreateEdit())
            {
                int start = Math.Min(declaration.Start, sibling.Start);
                int end = Math.Max(declaration.AfterEnd, sibling.AfterEnd);
                edit.Replace(start, end - start, text);
                edit.Apply();

                if (direction == Direction.Up)
                    _textView.Caret.MoveTo(new SnapshotPoint(_textView.TextBuffer.CurrentSnapshot, sibling.Start + 1));

                EditorExtensionsPackage.DTE.ExecuteCommand("Edit.FormatSelection");
                EditorExtensionsPackage.DTE.UndoContext.Close();
            }

            return true;
        }