示例#1
0
        public static AutoSaver Start(Editor editor, string autoSaveFile)
        {
            AutoSaver saver = new AutoSaver(editor, autoSaveFile);

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

            return(saver);
        }
示例#2
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();
        }