Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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;
                }
            }));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 public virtual bool CanHandle(TextEditor editor)
 {
     return(DesktopService.GetMimeTypeIsSubtype(editor.MimeType, MimeType));
 }
Ejemplo n.º 9
0
 public bool CanFormat(string mimeType)
 {
     return(DesktopService.GetMimeTypeIsSubtype(mimeType, "application/xml"));
 }