本文整理汇总了C#中ParseItem.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# ParseItem.FindType方法的具体用法?C# ParseItem.FindType怎么用?C# ParseItem.FindType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseItem
的用法示例。
在下文中一共展示了ParseItem.FindType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckItem
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
{
if (item.Text.TrimStart(':').StartsWith("-"))
return ItemCheckResult.Continue;
ParseItem next = item.NextSibling;
//ParseItem prev = item.PreviousSibling;
SimpleSelector sel = item.FindType<SimpleSelector>();
//if (item.Text == ":hover" && prev != null && _invalids.Contains(prev.Text))
//{
// string error = string.Format(Resources.ValidationHoverOrder, prev.Text);
// context.AddError(new SimpleErrorTag(item, error, CssErrorFlags.TaskListError | CssErrorFlags.UnderlineRed));
//}
if (next != null)
{
if (next.Text.StartsWith(":") && item.IsPseudoElement() && !next.IsPseudoElement())
{
string error = string.Format(Resources.ValidationPseudoOrder, item.Text, next.Text);
context.AddError(new SimpleErrorTag(item, error, CssErrorFlags.TaskListError | CssErrorFlags.UnderlineRed));
}
else if (!next.Text.StartsWith(":") && item.AfterEnd == next.Start)
{
string error = string.Format(Resources.BestPracticePseudosAfterOtherSelectors, next.Text);
context.AddError(new SimpleErrorTag(next, error));
}
}
return ItemCheckResult.Continue;
}
示例2: GetCompletionContext
public CssCompletionContext GetCompletionContext(ParseItem item, int position)
{
if (item.FindType<AttributeSelector>() != null)
return null;
return new CssCompletionContext((CssCompletionContextType)601, item.Start, item.Length, null);
}
示例3: CheckItem
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context)
{
if (!WESettings.Instance.Css.ValidateZeroUnit)
return ItemCheckResult.Continue;
NumericalValue number = (NumericalValue)item;
UnitValue unit = number as UnitValue;
if (unit == null || context == null || item.FindType<Declaration>() == null)
return ItemCheckResult.Continue;
// The 2nd and 3rd arguments to hsl() require units even when zero
var function = unit.Parent.Parent as FunctionColor;
if (function != null && function.FunctionName.Text.StartsWith("hsl", StringComparison.OrdinalIgnoreCase))
{
var arg = unit.Parent as FunctionArgument;
if (arg != function.Arguments[0])
return ItemCheckResult.Continue;
}
if (number.Number.Text == "0" && unit.UnitType != UnitType.Unknown && unit.UnitType != UnitType.Time)
{
string message = string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.BestPracticeZeroUnit, unit.UnitToken.Text);
context.AddError(new SimpleErrorTag(number, message));
}
return ItemCheckResult.Continue;
}
示例4: GetSmartTagActions
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
{
RuleSet rule = item.FindType<RuleSet>();
if (rule == null || !rule.Block.IsValid || UsageRegistry.IsRuleUsed(rule))
yield break;
yield return new RemoveCssRuleSmartTagAction(itemTrackingSpan, rule);
}
示例5: GetSmartTagActions
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
{
RuleSet rule = item.FindType<RuleSet>();
if (rule == null || !rule.IsValid || !rule.Block.IsValid)
yield break;
yield return new SortSmartTagAction(rule, itemTrackingSpan, view);
}
示例6: GetSmartTagActions
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
{
LessRuleBlock rule = item.FindType<LessRuleBlock>();
if (!item.IsValid || rule == null)
yield break;
yield return new LessExtractVariableSmartTagAction(itemTrackingSpan, item, "@");
}
示例7: GetCompletionContext
public CssCompletionContext GetCompletionContext(ParseItem item, int position)
{
RuleSet rule = item.FindType<RuleSet>();
if (rule != null && rule.Parent is LessRuleBlock)
{
return new CssCompletionContext(CssCompletionContextType.Invalid, item.Start, item.Length, item);
}
return null;
}
示例8: SchemaLookup
private bool SchemaLookup(ParseItem item)
{
if (item is ClassSelector || item is IdSelector || item is ItemName || item.Parent is RuleBlock || item.Parent is StyleSheet)
return false;
ICssSchemaInstance schema = CssSchemaManager.SchemaManager.GetSchemaRootForBuffer(TextView.TextBuffer);
Declaration dec = item.FindType<Declaration>();
if (dec != null && dec.PropertyName != null)
return OpenReferenceUrl(schema.GetProperty, dec.PropertyName.Text, "http://realworldvalidator.com/css/properties/");
PseudoClassFunctionSelector pseudoClassFunction = item.FindType<PseudoClassFunctionSelector>();
if (pseudoClassFunction != null)
return OpenReferenceUrl(schema.GetPseudo, pseudoClassFunction.Colon.Text + pseudoClassFunction.Function.FunctionName.Text + ")", "http://realworldvalidator.com/css/pseudoclasses/");
PseudoElementFunctionSelector pseudoElementFunction = item.FindType<PseudoElementFunctionSelector>();
if (pseudoElementFunction != null)
return OpenReferenceUrl(schema.GetPseudo, pseudoElementFunction.DoubleColon.Text + pseudoElementFunction.Function.FunctionName.Text + ")", "http://realworldvalidator.com/css/pseudoelements/");
PseudoElementSelector pseudoElement = item.FindType<PseudoElementSelector>();
if (pseudoElement != null && pseudoElement.PseudoElement != null)
return OpenReferenceUrl(schema.GetPseudo, pseudoElement.DoubleColon.Text + pseudoElement.PseudoElement.Text, "http://realworldvalidator.com/css/pseudoelements/");
PseudoClassSelector pseudoClass = item.FindType<PseudoClassSelector>();
if (pseudoClass != null && pseudoClass.PseudoClass != null)
return OpenReferenceUrl(schema.GetPseudo, pseudoClass.Colon.Text + pseudoClass.PseudoClass.Text, "http://realworldvalidator.com/css/pseudoclasses/");
AtDirective directive = item.FindType<AtDirective>();
if (directive != null)
return OpenReferenceUrl(schema.GetAtDirective, directive.At.Text + directive.Keyword.Text, "http://realworldvalidator.com/css/atdirectives/");
return false;
}
示例9: GetSmartTagActions
public IEnumerable<ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
{
UrlItem url = (UrlItem)item;
if (!url.IsValid || url.UrlString == null || !url.UrlString.Text.Contains(";base64,"))
yield break;
CComment comment = url.NextSibling as CComment;
if (comment != null && comment.CommentText != null)
{
string path = comment.CommentText.Text.Trim();
yield return new UpdateEmbedSmartTagAction(itemTrackingSpan, path);
}
else
{
RuleBlock rule = item.FindType<RuleBlock>();
Declaration dec = item.FindType<Declaration>();
if (rule == null || dec == null || dec.PropertyName == null)
yield break;
foreach (Declaration sibling in rule.Declarations.Where(d => d.PropertyName != null && d != dec))
{
if (sibling.PropertyName.Text == "*" + dec.PropertyName.Text || sibling.PropertyName.Text == "_" + dec.PropertyName.Text)
{
var visitor = new CssItemCollector<UrlItem>();
sibling.Accept(visitor);
UrlItem siblingUrl = visitor.Items.FirstOrDefault();
if (siblingUrl != null && siblingUrl.UrlString != null)
{
yield return new UpdateEmbedSmartTagAction(itemTrackingSpan, siblingUrl.UrlString.Text);
break;
}
}
}
}
}
示例10: UpdateVendorValues
private void UpdateVendorValues(ParseItem item)
{
if (!WESettings.GetBoolean(WESettings.Keys.SyncVendorValues))
return;
Declaration dec = item.FindType<Declaration>();
if (dec != null && Cache.Contains(dec) && !dec.IsVendorSpecific())
{
// Find all vendor specifics that isn't the standard property.
var matches = Cache.Where(d => d.IsValid && d != dec && d.Parent == dec.Parent && GetStandardName(d) == dec.PropertyName.Text && d.PropertyName.Text != dec.PropertyName.Text);
// Undo sometimes messes with the positions, so we have to make this check before proceeding.
if (!matches.Any() || dec.Text.Length < dec.Colon.AfterEnd - dec.Start || dec.Colon.AfterEnd < dec.Start)
return;
string text = dec.Text.Substring(dec.Colon.AfterEnd - dec.Start, dec.AfterEnd - dec.Colon.AfterEnd);
using (ITextEdit edit = _buffer.CreateEdit())
{
foreach (Declaration match in matches.Reverse())
{
SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, match.Colon.AfterEnd, match.AfterEnd - match.Colon.AfterEnd);
if (span.GetText() != text)
edit.Replace(span, text);
}
edit.Apply();
}
}
}
示例11: GetEntriesAndPoint
private static Tuple<ParseItem, ICssCompletionListEntry> GetEntriesAndPoint(ParseItem item, SnapshotPoint point, ICssSchemaInstance schema)
{
// Declaration
Declaration dec = item.FindType<Declaration>();
if (dec != null && dec.PropertyName != null && dec.PropertyName.ContainsRange(point.Position, 1))
{
return Tuple.Create<ParseItem, ICssCompletionListEntry>(dec.PropertyName, schema.GetProperty(dec.PropertyName.Text));
}
if (dec != null && dec.IsValid && dec.Values.TextStart <= point.Position && dec.Values.TextAfterEnd >= point.Position)
{
var entry = schema.GetProperty(dec.PropertyName.Text);
if (entry != null)
{
var list = schema.GetPropertyValues(entry.DisplayText);
var theOne = dec.StyleSheet.ItemFromRange(point.Position, 0);
return Tuple.Create<ParseItem, ICssCompletionListEntry>(theOne,
list.SingleOrDefault(r => r.DisplayText.Equals(theOne.Text, StringComparison.OrdinalIgnoreCase)));
}
}
// Pseudo class
PseudoClassSelector pseudoClass = item.FindType<PseudoClassSelector>();
if (pseudoClass != null)
{
return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoClass, schema.GetPseudo(pseudoClass.Text));
}
// Pseudo class function
PseudoClassFunctionSelector pseudoClassFunction = item.FindType<PseudoClassFunctionSelector>();
if (pseudoClassFunction != null)
{
return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoClassFunction, schema.GetPseudo(pseudoClassFunction.Text));
}
// Pseudo element
PseudoElementSelector pseudoElement = item.FindType<PseudoElementSelector>();
if (pseudoElement != null)
{
return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoElement, schema.GetPseudo(pseudoElement.Text));
}
// Pseudo element function
PseudoElementFunctionSelector pseudoElementFunction = item.FindType<PseudoElementFunctionSelector>();
if (pseudoElementFunction != null)
{
return Tuple.Create<ParseItem, ICssCompletionListEntry>(pseudoElementFunction, schema.GetPseudo(pseudoElementFunction.Text));
}
// @-directive
AtDirective atDirective = item.Parent as AtDirective;
if (atDirective != null && atDirective.Keyword != null)
{
return Tuple.Create<ParseItem, ICssCompletionListEntry>(atDirective.Keyword, schema.GetAtDirective("@" + atDirective.Keyword.Text));
}
return null;
}
示例12: UpdateEmbeddedImageValues
private void UpdateEmbeddedImageValues(ParseItem item)
{
if (!WESettings.Instance.Css.SyncBase64ImageValues)
return;
Declaration dec = item.FindType<Declaration>();
if (dec != null && Cache.Contains(dec))
{
var url = (UrlItem)dec.Values.First();
if (!url.IsValid || url.UrlString == null || url.UrlString.Text.Contains(";base64,"))
return;
var matches = Cache.Where(d => d.IsValid && d != dec && d.Parent == dec.Parent &&
(d.Values[0].NextSibling as CComment) != null);
// Undo sometimes messes with the positions, so we have to make this check before proceeding.
if (!matches.Any() || dec.Text.Length < dec.Colon.AfterEnd - dec.Start || dec.Colon.AfterEnd < dec.Start)
return;
string urlText = url.UrlString.Text.Trim('\'', '"');
string filePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(_buffer.GetFileName()), urlText));
string b64UrlText = FileHelpers.ConvertToBase64(filePath);
string b64Url = url.Text.Replace(urlText, b64UrlText);
IEnumerable<Tuple<SnapshotSpan, string>> changes = matches.Reverse().SelectMany(match =>
{
ParseItem value = match.Values[0];
CComment comment = value.NextSibling as CComment;
SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, comment.CommentText.Start, comment.CommentText.Length);
url = (UrlItem)value;
SnapshotSpan b64Span = new SnapshotSpan(_buffer.CurrentSnapshot, url.Start, url.Length);
return new[] { new Tuple<SnapshotSpan, string>(span, urlText), new Tuple<SnapshotSpan, string>(b64Span, b64Url) };
});
Dispatcher.CurrentDispatcher.InvokeAsync(() =>
{
using (ITextEdit edit = _buffer.CreateEdit())
{
foreach (Tuple<SnapshotSpan, string> change in changes)
{
SnapshotSpan currentSpan = change.Item1.TranslateTo(_buffer.CurrentSnapshot, SpanTrackingMode.EdgeExclusive);
edit.Replace(currentSpan, change.Item2);
}
edit.Apply();
}
});
}
}