Ejemplo n.º 1
0
        protected override void OnDispose()
        {
            if (IsDisposed)
            {
                return;
            }

            textBufferRegistration?.Dispose();
            textBufferRegistration = null;

            // Parity behavior with the old editor
            if (autoSaveTask != null)
            {
                autoSaveTask.Wait(TimeSpan.FromSeconds(5));
            }
            RemoveAutoSaveTimer();
            if (!string.IsNullOrEmpty(FilePath))
            {
                AutoSave.RemoveAutoSaveFile(FilePath);
            }

            UnsubscribeFromEvents();

            if (policyContainer != null)
            {
                policyContainer.PolicyChanged -= PolicyChanged;
            }
            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                EditorConfigService.RemoveEditConfigContext(FilePath).Ignore();
            }

            base.OnDispose();
        }
Ejemplo n.º 2
0
        protected override void OnFileNameChanged()
        {
            base.OnFileNameChanged();

            if (TextDocument == null)
            {
                return;
            }

            UpdateTextBufferRegistration();

            warnOverwrite = false;

            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                EditorConfigService.RemoveEditConfigContext(TextDocument.FilePath).Ignore();
                editorConfigContext = null;
            }

            if (FilePath != TextDocument.FilePath && !string.IsNullOrEmpty(TextDocument.FilePath))
            {
                AutoSave.RemoveAutoSaveFile(TextDocument.FilePath);
            }

            if (FilePath != null)             // Happens when a file is converted to an untitled file, but even in that case the text editor should be associated with the old location, otherwise typing can be messed up due to change of .editconfig settings etc.
            {
                TextDocument.Rename(FilePath);
            }

            // update the file type condition with the new path
            fileTypeCondition.SetFileName(FilePath);

            // TODO: Actually implement file rename support. Below is from old editor.
            //       Need to remove or update mimeType field, too.

            //if (this.WorkbenchWindow?.Document != null)
            //	textEditor.InitializeExtensionChain (this.WorkbenchWindow.Document);

            UpdateTextEditorOptions(null, null);
        }
Ejemplo n.º 3
0
        async Task UpdateTextEditorOptionsAsync()
        {
            UpdateLineNumberMarginOption();

            var foldMargin = PropertyService.Get <bool> ("ShowFoldMargin");

            Imports.OutliningManagerService.GetOutliningManager(TextView).Enabled = foldMargin;

            var newPolicyContainer = (Owner as IPolicyProvider)?.Policies;

            if (newPolicyContainer != policyContainer)
            {
                if (policyContainer != null)
                {
                    policyContainer.PolicyChanged -= PolicyChanged;
                }
                policyContainer = newPolicyContainer;
            }
            if (policyContainer != null)
            {
                policyContainer.PolicyChanged += PolicyChanged;
            }

            var newEditorConfigContext = await EditorConfigService.GetEditorConfigContext(FilePath, default);

            if (newEditorConfigContext != editorConfigContext)
            {
                if (editorConfigContext != null)
                {
                    editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                }
                editorConfigContext = newEditorConfigContext;
            }
            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync += UpdateOptionsFromEditorConfigAsync;
            }

            await UpdateOptionsFromEditorConfigAsync(null, null);
        }
Ejemplo n.º 4
0
        async Task UpdateTextEditorOptionsAsync()
        {
            UpdateLineNumberMarginOption();

            var newPolicyContainer = (Owner as IPolicyProvider)?.Policies;

            if (newPolicyContainer != policyContainer)
            {
                if (policyContainer != null)
                {
                    policyContainer.PolicyChanged -= PolicyChanged;
                }
                policyContainer = newPolicyContainer;
            }
            if (policyContainer != null)
            {
                policyContainer.PolicyChanged += PolicyChanged;
            }

            UpdateOptionsFromPolicy();

            var newEditorConfigContext = await EditorConfigService.GetEditorConfigContext(FilePath, default);

            if (newEditorConfigContext != editorConfigContext)
            {
                if (editorConfigContext != null)
                {
                    editorConfigContext.CodingConventionsChangedAsync -= UpdateOptionsFromEditorConfigAsync;
                }
                editorConfigContext = newEditorConfigContext;
            }
            if (editorConfigContext != null)
            {
                editorConfigContext.CodingConventionsChangedAsync += UpdateOptionsFromEditorConfigAsync;
            }

            await UpdateOptionsFromEditorConfigAsync(null, null);
        }