Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Copies the policies defined in another container
        /// </summary>
        /// <param name='other'>
        /// A policy container from which to copy the policies
        /// </param>
        /// <remarks>
        /// Policies of this container are removed or replaced by policies defined in the
        /// provided container.
        /// </remarks>
        public void CopyFrom(PolicyContainer other)
        {
            if (other.policies == null && policies == null)
            {
                return;
            }

            // Add and update policies

            if (other.policies != null)
            {
                foreach (KeyValuePair <PolicyKey, object> p in other.policies)
                {
                    object oldVal;
                    if (policies == null || !policies.TryGetValue(p.Key, out oldVal) || oldVal == null || !oldVal.Equals(p.Value))
                    {
                        if (policies == null)
                        {
                            policies = new PolicyDictionary();
                        }
                        policies [p.Key] = p.Value;
                        OnPolicyChanged(p.Key.PolicyType, p.Key.Scope);
                    }
                }
            }

            // Remove policies

            if (policies != null)
            {
                foreach (PolicyKey k in policies.Keys.ToArray())
                {
                    if (other.policies == null || !other.policies.ContainsKey(k))
                    {
                        policies.Remove(k);
                        OnPolicyChanged(k.PolicyType, k.Scope);
                    }
                }
            }
        }