Ejemplo n.º 1
0
 protected override void OnContentNameChanged()
 {
     base.OnContentNameChanged();
     if (ContentName != textEditorImpl.ContentName && !string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     if (textEditorImpl.ContentName != null)
     {
         EditorConfigService.RemoveEditConfigContext(textEditorImpl.ContentName);
     }
     textEditorImpl.ContentName = this.ContentName;
     if (this.WorkbenchWindow?.Document != null)
     {
         textEditor.InitializeExtensionChain(this.WorkbenchWindow.Document);
     }
     UpdateTextEditorOptions(null, null);
 }
Ejemplo n.º 2
0
        protected override void OnDispose()
        {
            if (isDisposed)
            {
                return;
            }

            isDisposed = true;

            HasUnsavedChangesChanged -= TextEditorViewContent_HasUnsavedChangesChanged;

            if (textEditorImpl != null)
            {
                if (autoSaveTask != null)
                {
                    autoSaveTask.Wait(TimeSpan.FromSeconds(5));
                }
                RemoveAutoSaveTimer();
                if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
                {
                    AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
                }

                EditorConfigService.RemoveEditConfigContext(textEditor.FileName).Ignore();
                textEditorImpl.DirtyChanged -= HandleDirtyChanged;
                textEditor.MimeTypeChanged  -= UpdateTextEditorOptions;
                textEditor.TextChanged      -= HandleTextChanged;
                textEditorImpl.DirtyChanged -= ViewContent_DirtyChanged;;

                DefaultSourceEditorOptions.Instance.Changed -= UpdateTextEditorOptions;
                textEditor.Dispose();
            }
            RemovePolicyChangeHandler();

            editorOptionsUpdateCancellationSource?.Cancel();

            base.OnDispose();
        }
        public override void Dispose()
        {
            if (isDisposed)
            {
                return;
            }

            base.Dispose();

            isDisposed = true;
            EditorConfigService.RemoveEditConfigContext(textEditor.FileName).Ignore();
            CancelDocumentParsedUpdate();
            textEditorImpl.ViewContent.DirtyChanged -= HandleDirtyChanged;
            textEditor.MimeTypeChanged -= UpdateTextEditorOptions;
            textEditor.TextChanged     -= HandleTextChanged;
            textEditorImpl.ViewContent.ContentNameChanged -= ViewContent_ContentNameChanged;
            textEditorImpl.ViewContent.DirtyChanged       -= ViewContent_DirtyChanged;;

            DefaultSourceEditorOptions.Instance.Changed -= UpdateTextEditorOptions;
            RemovePolicyChangeHandler();
            RemoveAutoSaveTimer();
            textEditor.Dispose();
        }
Ejemplo n.º 4
0
        static async Task InvokeEditConfigTest(string editConfig, Action <TextEditor> test)
        {
            string tempPath;
            int    i = 0;

            while (true)
            {
                tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                if (!File.Exists(tempPath))
                {
                    break;
                }
                if (i++ > 100)
                {
                    Assert.Fail("Can't create random path.");
                }
            }

            Directory.CreateDirectory(tempPath);
            try {
                string editorConfigFile = Path.Combine(tempPath, ".editorconfig");
                File.WriteAllText(editorConfigFile, editConfig);
                var    editor      = TextEditorFactory.CreateNewEditor();
                var    viewContent = editor.GetViewContent();
                string fileName    = Path.Combine(tempPath, "a.cs");
                try {
                    using (var ctx = await EditorConfigService.GetEditorConfigContext(fileName)) {
                        ((DefaultSourceEditorOptions)editor.Options).SetContext(ctx);
                        test(editor);
                    }
                } finally {
                    await EditorConfigService.RemoveEditConfigContext(fileName);
                }
            } finally {
                Directory.Delete(tempPath, true);
            }
        }
        protected override async void OnContentNameChanged()
        {
            base.OnContentNameChanged();
            if (ContentName != textEditorImpl.ContentName && !string.IsNullOrEmpty(textEditorImpl.ContentName))
            {
                AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
            }
            if (textEditorImpl.ContentName != null && textEditorImpl.ContentName != this.ContentName)
            {
                EditorConfigService.RemoveEditConfigContext(textEditorImpl.ContentName).Ignore();
                var context = await EditorConfigService.GetEditorConfigContext(textEditor.FileName, default(CancellationToken));

                if (context != null)
                {
                    ((DefaultSourceEditorOptions)textEditor.Options).SetContext(context);
                }
            }
            textEditorImpl.ContentName = this.ContentName;
            if (this.WorkbenchWindow?.Document != null)
            {
                textEditor.InitializeExtensionChain(this.WorkbenchWindow.Document);
            }
            UpdateTextEditorOptions(null, null);
        }