Exemplo n.º 1
0
        public DocumentView()
        {
            AvaloniaXamlLoader.Load(this);

            _editor = this.FindControl <RoslynCodeEditor>("Editor");

            _editor.FontFamily = GetPlatformFontFamily();

            DataContextChanged += OnDataContextChanged;
        }
Exemplo n.º 2
0
#pragma warning disable CS8618 // Non-nullable field is uninitialized.
        public DocumentView()
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
        {
            AvaloniaXamlLoader.Load(this);

            _editor = this.FindControl <RoslynCodeEditor>("Editor");

            _editor.FontFamily = GetPlatformFontFamily();

            DataContextChanged += OnDataContextChanged;
        }
Exemplo n.º 3
0
        public DocumentView()
        {
            AvaloniaXamlLoader.Load(this);

            _editor = this.FindControl <RoslynCodeEditor>("Editor");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                _editor.FontFamily = "Consolas";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                _editor.FontFamily = "Menlo";
            }
            else
            {
                _editor.FontFamily = "Monospace";
            }

            DataContextChanged += OnDataContextChanged;
        }
Exemplo n.º 4
0
        public static void InitEditor()
        {
            lock (initLocked)
            {
                if (isInited)
                {
                    return;
                }
                isInited = true;
                InitScriptOptions();
                RoslynHostReferences roslynHostReferences;
                if (scriptOptions == null)
                {
                    roslynHostReferences = RoslynHostReferences.NamespaceDefault.With(
                        assemblyReferences: new[]
                    {
                        Assembly.GetExecutingAssembly(),
                        Assembly.GetCallingAssembly(),
                        typeof(MainController).Assembly,
                        typeof(object).Assembly
                    });
                }
                else
                {
                    roslynHostReferences = RoslynHostReferences.NamespaceDefault.With(
                        references: scriptOptions.MetadataReferences.Where(a => !(a is UnresolvedMetadataReference)),
                        imports: scriptOptions.Imports,
                        assemblyReferences: new[]
                    {
                        Assembly.GetExecutingAssembly(),
                        Assembly.GetCallingAssembly(),
                        typeof(MainController).Assembly,
                        typeof(object).Assembly
                    });
                }
                roslynHost = new CustomHost(
                    globalType,
                    additionalAssemblies: new[]
                {
                    Assembly.Load("RoslynPad.Roslyn.Windows"),
                    Assembly.Load("RoslynPad.Editor.Windows")
                },
                    references: roslynHostReferences);
                if (instance == null)
                {
                    CreateEditorInstance();
                }
                instance.Invoke((Action)(() =>
                {
                    roslynCodeEditor = new RoslynCodeEditor
                    {
                        FontFamily = new System.Windows.Media.FontFamily("Consolas")
                    };

                    docId = roslynCodeEditor.Initialize(roslynHost,
                                                        new ClassificationHighlightColors(),
                                                        Directory.GetCurrentDirectory(),
                                                        string.Empty);

                    if (!Directory.Exists("Code"))
                    {
                        Directory.CreateDirectory("Code");
                    }

                    if (File.Exists("Code\\_last"))
                    {
                        roslynCodeEditor.Text = File.ReadAllText("Code\\_last");
                    }

                    instance.elementHost1.Child = roslynCodeEditor;

                    foreach (var item in Directory.EnumerateFiles("Code"))
                    {
                        instance.comboBox1.Items.Add(item.Substring(5));
                    }

                    instance.comboBox1.SelectedIndexChanged += (_, __) =>
                    {
                        if (File.Exists($"Code\\{instance.comboBox1.Text}"))
                        {
                            Code = File.ReadAllText($"Code\\{instance.comboBox1.Text}");
                        }
                    };
                    //AppDomain.CurrentDomain.AssemblyResolve += (a, b) =>
                    //{
                    //    var asms = AppDomain.CurrentDomain.GetAssemblies();
                    //    var fasms = asms.Where(a => a.FullName == b.Name).ToArray();
                    //    if (fasms.Length > 0) return fasms[0];
                    //    else
                    //    {
                    //        string asmName;
                    //        if (b.Name.IndexOf(',') > 0)
                    //            asmName = b.Name.Substring(0, b.Name.IndexOf(','));
                    //        else asmName = b.Name;
                    //        var dinfo = Directory.CreateDirectory("Plugins");
                    //        foreach (var item in dinfo.EnumerateFiles("*.dll", SearchOption.AllDirectories))
                    //        {
                    //            if (item.Name == asmName)
                    //            {
                    //                return assemblyLoadContext.LoadFromAssemblyPath(item.FullName);
                    //            }
                    //        }
                    //    }
                    //    return null;
                    //};
                }));
            }
        }