Example #1
0
        private async Task Initialize(string sourceText, string guid, Shortcut[] additionalShortcuts)
        {
            this.Guid = guid;

            EditorControl = this.FindControl <MarkdownSourceEditorControl>("EditorControl");

            await EditorControl.SetText(sourceText);

            OriginalText      = EditorControl.Text.ToString();
            OriginalDocument  = EditorControl.Document;
            LastSavedText     = OriginalText;
            OriginalTimeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            StatusBar = this.FindControl <StatusBar>("StatusBar");

            SaveHistoryContainer = this.FindControl <SaveHistoryContainer>("SaveHistoryContainer");
            PreviewPanel         = this.FindControl <MarkdownCanvasControl>("PreviewPanel");

            this.MarkdownRenderer = PreviewPanel.Renderer;

            this.MarkdownRenderer.ImageUriResolver = (a, b) => AsynchronousImageCache.ImageUriResolverAsynchronous(a, b);

            this.MarkdownRenderer.ImageMultiplier = 1.33;

            AsynchronousImageCache.CacheUpdated += this.CacheUpdated;

            this.DetachedFromVisualTree += (s, e) =>
            {
                AsynchronousImageCache.CacheUpdated -= this.CacheUpdated;
            };

            SettingsContainer = new SettingsContainer(additionalShortcuts)
            {
                Margin = new Thickness(10, 0, 0, 10), IsVisible = false
            };
            Grid.SetRow(SettingsContainer, 2);
            this.FindControl <Grid>("ContainerGrid").Children.Add(SettingsContainer);

            EditorControl.ClearUndoStack();

            this.CompilationErrorChecker = PreviewUpdater.Attach(this);

            string autosaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Assembly.GetEntryAssembly().GetName().Name);

            Directory.CreateDirectory(Path.Combine(autosaveDirectory, Guid));
            AutoSaveFile   = Path.Combine(autosaveDirectory, Guid, "autosave_" + System.Guid.NewGuid().ToString("N") + ".cs");
            SaveDirectory  = Path.Combine(autosaveDirectory, Guid);
            this.AutoSaver = AutoSaver.Start(this, AutoSaveFile);

            InputHandler = new InputHandler(this, EditorControl);

            OpenSidePanel();
        }
Example #2
0
        public static PreviewUpdater Attach(Editor editor)
        {
            PreviewUpdater checker = new PreviewUpdater(editor);

            editor.DetachedFromLogicalTree += (s, e) =>
            {
                checker.ExitHandle.Set();
                checker.LoopThread.Join();
            };

            return(checker);
        }