Beispiel #1
0
        async Task UpdateStyleParent(WorkspaceObject owner, string mimeType, CancellationToken token)
        {
            var styleParent = owner as IPolicyProvider;

            RemovePolicyChangeHandler();

            if (string.IsNullOrEmpty(mimeType))
            {
                mimeType = "text/plain";
            }

            var mimeTypes = IdeServices.DesktopService.GetMimeTypeInheritanceChain(mimeType);

            if (styleParent != null)
            {
                policyContainer = styleParent.Policies;
            }
            else
            {
                policyContainer = MonoDevelop.Projects.Policies.PolicyService.DefaultPolicies;
            }
            var currentPolicy = policyContainer.Get <TextStylePolicy> (mimeTypes);

            policyContainer.PolicyChanged += HandlePolicyChanged;
            ((DefaultSourceEditorOptions)textEditor.Options).UpdateStylePolicy(currentPolicy);

            var context = await EditorConfigService.GetEditorConfigContext(textEditor.FileName, token);

            if (context == null)
            {
                return;
            }
            ((DefaultSourceEditorOptions)textEditor.Options).SetContext(context);
        }
Beispiel #2
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");
                var    ctx         = await EditorConfigService.GetEditorConfigContext(fileName);

                ((DefaultSourceEditorOptions)editor.Options).SetContext(ctx);
                test(editor);
            } finally {
                Directory.Delete(tempPath, true);
            }
        }
Beispiel #3
0
        async Task UpdateStyleParent(MonoDevelop.Projects.Project styleParent, string mimeType)
        {
            RemovePolicyChangeHandler();

            if (string.IsNullOrEmpty(mimeType))
            {
                mimeType = "text/plain";
            }

            var mimeTypes = DesktopService.GetMimeTypeInheritanceChain(mimeType);

            if (styleParent != null)
            {
                policyContainer = styleParent.Policies;
            }
            else
            {
                policyContainer = MonoDevelop.Projects.Policies.PolicyService.DefaultPolicies;
            }
            var currentPolicy = policyContainer.Get <TextStylePolicy> (mimeTypes);

            policyContainer.PolicyChanged += HandlePolicyChanged;

            var context = await EditorConfigService.GetEditorConfigContext(textEditor.FileName, default(CancellationToken));

            if (context == null)
            {
                return;
            }
            var options = DefaultSourceEditorOptions.Instance.WithTextStyle(currentPolicy);

            options.SetContext(context);
            textEditor.Options = options;
        }
Beispiel #4
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);
 }
Beispiel #5
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();
        }
        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);
        }