Example #1
0
        private TextEditorBase GetTextEditorByExtension(string FileName)
        {
            // We cache the list, so create only once
            if (TextEditors.Count() == 0)
            {
                var list = from type in typeof(TextEditorBase).Assembly.GetTypes()
                           where type.IsSubclassOf(typeof(TextEditorBase))
                           select type;


                foreach (Type t in list)
                {
                    if (t != typeof(PlugInTextEditorWrapper))
                    {
                        TextEditorBase TE = (TextEditorBase)Activator.CreateInstance(t);
                        TextEditors.Add(TE);
                    }
                }
            }

            // Add all plugins TextEditors
            ObservableList <PlugInWrapper> PlugInsList = App.LocalRepository.GetSolutionPlugIns();

            foreach (PlugInWrapper PW in PlugInsList)
            {
                foreach (PlugInTextFileEditorBase TE in PW.TextEditors())
                {
                    PlugInTextEditorWrapper w = new PlugInTextEditorWrapper(TE);
                    PlugInTextEditorWrapper f = (PlugInTextEditorWrapper)TextEditors.Where(x => x is PlugInTextEditorWrapper ? ((PlugInTextEditorWrapper)x).GetEditorID() == w.GetEditorID() : false).FirstOrDefault();
                    if (f == null)
                    {
                        TextEditors.Add(w);
                    }
                }
            }

            //TODO: if there is more than one let the user pick
            string ext = Path.GetExtension(FileName).ToLower();

            foreach (TextEditorBase TE in TextEditors)
            {
                if (TE.Extensions != null)
                {
                    if (TE.Extensions.Contains(ext))
                    {
                        return(TE);
                    }
                }
            }

            return(null);
        }