static int FindPrevWordStart(TextEditor editor, int offset) { while (--offset >= 0) { var c = editor.GetCharAt(offset); //Only legal characters in template Shortcut //LetterOrDigit make sense //in theory we should probably just support LetterOrDigit and _ if (!char.IsLetterOrDigit(c)) { //_ to allow underscore naming convention //# is because there are #if templates //~ because disctructor template //@ some Razor templates start with @ if (c == '_' || c == '#' || c == '~' || c == '@') { continue; } // '-' because CSS property names templates include them if (c == '-' && DesktopService.GetMimeTypeIsSubtype(editor.MimeType, "text/x-css")) { continue; } break; } } return(++offset); }
public static IEnumerable <CodeTemplate> GetCodeTemplates(string mimeType) { var savedTemplates = templates; if (savedTemplates == null || string.IsNullOrEmpty(mimeType)) { return(new CodeTemplate [0]); } return(savedTemplates.ToArray().Where(t => t != null && DesktopService.GetMimeTypeIsSubtype(mimeType, t.MimeType))); }
static int DeleteTemplateShortcutBeforeCaret(TextEditor editor) { int offset = editor.CaretOffset; int start = FindPrevWordStart(editor, offset); // HTML snippets include the opening '<', so ensure that we remove the old one if present if (start > 0 && '<' == editor.GetCharAt(start - 1) && DesktopService.GetMimeTypeIsSubtype(editor.MimeType, "text/x-html")) { start -= 1; } editor.RemoveText(start, offset - start); return(start); }
public static IEnumerable <CodeTemplate> GetCodeTemplates(string mimeType) { var savedTemplates = templates; if (savedTemplates == null || string.IsNullOrEmpty(mimeType)) { return(new CodeTemplate [0]); } return(savedTemplates.ToArray().Where(delegate(CodeTemplate t) { try { return t != null && DesktopService.GetMimeTypeIsSubtype(mimeType, t.MimeType); } catch (Exception) { // required for some unit tests return t != null && mimeType == t.MimeType; } })); }
public bool Supports(string fileName) { if (fileExtensions != null && fileExtensions.Length > 0) { string ext = System.IO.Path.GetExtension(fileName); return(fileExtensions.Any(fe => string.Compare(fe, ext, StringComparison.OrdinalIgnoreCase) == 0)); } if (mimeTypes != null && mimeTypes.Length > 0) { string mt = DesktopService.GetMimeTypeForUri(fileName); foreach (string t in mimeTypes) { if (DesktopService.GetMimeTypeIsSubtype(mt, t)) { return(true); } } return(false); } // No constraints on the file return(true); }
public bool Supports(string fileName) { if (fileExtensions != null && fileExtensions.Length > 0) { string ext = System.IO.Path.GetExtension(fileName); return(((IList)fileExtensions).Contains(ext)); } if (mimeTypes != null && mimeTypes.Length > 0) { string mt = DesktopService.GetMimeTypeForUri(fileName); foreach (string t in mimeTypes) { if (DesktopService.GetMimeTypeIsSubtype(mt, t)) { return(true); } } return(false); } // No constraints on the file return(true); }
public override bool Evaluate(NodeElement conditionNode) { if (fileName == null) { return(false); } string[] fileExtensions = conditionNode.GetAttribute("fileExtensions").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] mimeTypes = conditionNode.GetAttribute("mimeTypes").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] names = conditionNode.GetAttribute("name").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (fileExtensions.Length > 0) { string ext = System.IO.Path.GetExtension(fileName); if (fileExtensions.Any(fe => string.Compare(fe, ext, StringComparison.OrdinalIgnoreCase) == 0)) { return(true); } } if (mimeTypes.Length > 0) { if (mimeTypes.Any(t => DesktopService.GetMimeTypeIsSubtype(mimeType, t))) { return(true); } } if (names.Length > 0) { string name = System.IO.Path.GetFileName(fileName); if (names.Any(fn => string.Compare(fn, name, StringComparison.OrdinalIgnoreCase) == 0)) { return(true); } } return(false); }
public virtual bool CanHandle(TextEditor editor) { return(DesktopService.GetMimeTypeIsSubtype(editor.MimeType, MimeType)); }
public bool CanFormat(string mimeType) { return(DesktopService.GetMimeTypeIsSubtype(mimeType, "application/xml")); }