public void Update(IndentTheme active, IndentTheme previous)
 {
     if (active != null)
     {
         SelectItem(active.CaretHandler);
     }
 }
        private void LoadFromRegistry(RegistryKey reg)
        {
            Debug.Assert(reg != null, "reg cannot be null");

            lock (_Themes) {
                _Themes.Clear();
                DefaultTheme = new IndentTheme();
                foreach (var themeName in reg.GetSubKeyNames())
                {
                    if (CARETHANDLERS_SUBKEY_NAME.Equals(themeName, StringComparison.InvariantCulture))
                    {
                        continue;
                    }
                    var theme = IndentTheme.Load(reg, themeName);
                    if (theme.IsDefault)
                    {
                        DefaultTheme = theme;
                    }
                    else
                    {
                        _Themes[theme.ContentType] = theme;
                    }
                }

                Visible = (int)reg.GetValue("Visible", 1) != 0;
            }

            OnThemesChanged();
        }
 public void Update(IndentTheme active, IndentTheme previous)
 {
     if (active != null)
     {
         gridLineMode.SelectedObject = active.Behavior;
         lineTextPreview.Theme       = active;
         lineTextPreview.Invalidate();
     }
 }
 private void OnThemeChanged(IndentTheme theme)
 {
     if (theme != null)
     {
         var evt = ThemeChanged;
         if (evt != null)
         {
             evt(this, new ThemeEventArgs(theme));
         }
     }
 }
 public virtual LineFormat Clone(IndentTheme theme)
 {
     return(new LineFormat(theme)
     {
         FormatIndex = FormatIndex,
         Visible = Visible,
         LineStyle = LineStyle,
         LineColor = LineColor,
         HighlightStyle = HighlightStyle,
         HighlightColor = HighlightColor
     });
 }
 public override LineFormat Clone(IndentTheme theme)
 {
     return(new PageWidthMarkerFormat(theme)
     {
         FormatIndex = FormatIndex,
         Visible = Visible,
         LineColor = LineColor,
         LineStyle = LineStyle,
         HighlightColor = HighlightColor,
         HighlightStyle = HighlightStyle,
         Position = Position,
     });
 }
 public void Update(IndentTheme active, IndentTheme previous)
 {
     if (active != null)
     {
         foreach (var p in Presets)
         {
             p.Theme.LineFormats.Clear();
             foreach (var kv in active.LineFormats)
             {
                 p.Theme.LineFormats[kv.Key] = kv.Value;
             }
             p.Checked = p.Theme.Behavior.Equals(active.Behavior);
             p.Invalidate();
         }
     }
 }
 protected void UpdateDisplay(IndentTheme active, IndentTheme previous)
 {
     Suppress_cmbTheme_SelectedIndexChanged = true;
     try {
         if (active != null && cmbTheme.Items.Contains(active))
         {
             cmbTheme.SelectedItem = active;
         }
         else
         {
             cmbTheme.SelectedItem = null;
         }
     } finally {
         Suppress_cmbTheme_SelectedIndexChanged = false;
     }
     Child.Update(active, previous);
 }
Example #9
0
        /// <summary>
        /// Instantiates a new indent guide manager for a view.
        /// </summary>
        /// <param name="view">The text view to provide guides for.</param>
        /// <param name="service">The Indent Guide service.</param>
        public IndentGuideView(IWpfTextView view, IIndentGuide service)
        {
            View = view;

            if (!service.Themes.TryGetValue(View.TextDataModel.ContentType.DisplayName, out Theme))
            {
                Theme = service.DefaultTheme;
            }
            if (Theme != null && Theme.Behavior != null && Theme.Behavior.Disabled)
            {
                return;
            }

            GuideBrushCache = new Dictionary <System.Drawing.Color, Brush>();
            GlowEffectCache = new Dictionary <System.Drawing.Color, Effect>();

            View.Caret.PositionChanged += Caret_PositionChanged;
            View.LayoutChanged         += View_LayoutChanged;
            View.Options.OptionChanged += View_OptionChanged;

            Layer  = view.GetAdornmentLayer("IndentGuide");
            Canvas = new Canvas();
            Canvas.HorizontalAlignment = HorizontalAlignment.Stretch;
            Canvas.VerticalAlignment   = VerticalAlignment.Stretch;
            Layer.AddAdornment(AdornmentPositioningBehavior.OwnerControlled, null, null, Canvas, CanvasRemoved);

            Debug.Assert(Theme != null, "No themes loaded");
            if (Theme == null)
            {
                Theme = new IndentTheme();
            }
            service.ThemesChanged += new EventHandler(Service_ThemesChanged);

            Analysis = new DocumentAnalyzer(
                View.TextSnapshot,
                Theme.Behavior,
                View.Options.GetOptionValue(DefaultOptions.IndentSizeOptionId),
                View.Options.GetOptionValue(DefaultOptions.TabSizeOptionId)
                );

            GlobalVisible           = service.Visible;
            service.VisibleChanged += new EventHandler(Service_VisibleChanged);

            var t = AnalyzeAndUpdateAdornments();
        }
 public void Update(IndentTheme active, IndentTheme previous)
 {
     lstLocations.BeginUpdate();
     try {
         lstLocations.Items.Clear();
         if (active != null)
         {
             foreach (var item in active.PageWidthMarkers.OrderBy(i => i.Position))
             {
                 lstLocations.Items.Add(item);
             }
         }
     } finally {
         lstLocations.EndUpdate();
         gridLineStyle.SelectedObject = null;
         lstLocations.SelectedIndex   = (lstLocations.Items.Count > 0) ? 0 : -1;
     }
 }
        public static LineFormat FromInvariantStrings(IndentTheme theme, Dictionary <string, string> values)
        {
            var    subclass = typeof(LineFormat);
            string subclassName;

            if (values.TryGetValue("TypeName", out subclassName))
            {
                subclass = Type.GetType(subclassName, throwOnError: false) ?? typeof(LineFormat);
            }

            var inst = subclass.InvokeMember(null, BindingFlags.CreateInstance, null, null, new[] { theme }) as LineFormat;

            if (inst == null)
            {
                throw new InvalidOperationException("Unable to create instance of " + subclass.FullName);
            }

            foreach (var kv in values)
            {
                if (kv.Key == "TypeName")
                {
                    continue;
                }

                var prop = subclass.GetProperty(kv.Key);
                if (prop != null)
                {
                    try
                    {
                        prop.SetValue(inst, TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromInvariantString(kv.Value));
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error setting {0} to {1}:\n", kv.Key, kv.Value, ex);
                    }
                }
                else
                {
                    Trace.TraceWarning("Unable to find property {0} on type {1}", kv.Key, subclass.FullName);
                }
            }

            return(inst);
        }
Example #12
0
        /// <summary>
        /// Raised when the theme is updated.
        /// </summary>
        async void Service_ThemesChanged(object sender, EventArgs e)
        {
            var service = (IIndentGuide)sender;

            if (!service.Themes.TryGetValue(View.TextDataModel.ContentType.DisplayName, out Theme))
            {
                Theme = service.DefaultTheme;
            }

            Analysis = new DocumentAnalyzer(
                View.TextSnapshot,
                Theme.Behavior,
                View.Options.GetOptionValue(DefaultOptions.IndentSizeOptionId),
                View.Options.GetOptionValue(DefaultOptions.TabSizeOptionId)
                );
            GuideBrushCache.Clear();
            GlowEffectCache.Clear();

            await AnalyzeAndUpdateAdornments();
        }
 public void Update(IndentTheme active, IndentTheme previous)
 {
     if (active != null)
     {
         int previousIndex = lstOverrides.SelectedIndex;
         lstOverrides.SelectedItem = null;    // ensure a change event occurs
         if (0 <= previousIndex && previousIndex < lstOverrides.Items.Count)
         {
             lstOverrides.SelectedIndex = previousIndex;
         }
         else if (lstOverrides.Items.Count > 0)
         {
             lstOverrides.SelectedIndex = 0;
         }
         else
         {
             lstOverrides.SelectedIndex = -1;
         }
     }
 }
        public void Load(IVsSettingsReader reader)
        {
            lock (_Themes) {
                _Themes.Clear();
                DefaultTheme = new IndentTheme();

                string themeKeysString;
                reader.ReadSettingString("Themes", out themeKeysString);

                foreach (var key in themeKeysString.Split(';'))
                {
                    if (string.IsNullOrWhiteSpace(key))
                    {
                        continue;
                    }

                    try {
                        var theme = IndentTheme.Load(reader, key);
                        if (theme.IsDefault)
                        {
                            DefaultTheme = theme;
                        }
                        else
                        {
                            _Themes[theme.ContentType] = theme;
                        }
                    } catch (Exception ex) {
                        Trace.WriteLine(string.Format("IndentGuide::LoadSettingsFromXML: {0}", ex));
                    }
                }

                int tempInt;
                reader.ReadSettingLong("Visible", out tempInt);
                Visible = (tempInt != 0);
            }

            OnThemesChanged();
        }
 private void btnCustomizeThisContentType_Click(object sender, EventArgs e)
 {
     try {
         IndentTheme theme;
         if (!Service.Themes.TryGetValue(CurrentContentType, out theme))
         {
             if (ActiveTheme == null)
             {
                 theme = new IndentTheme();
             }
             else
             {
                 theme = ActiveTheme.Clone();
             }
             theme.ContentType = CurrentContentType;
             Service.Themes[CurrentContentType] = theme;
             UpdateThemeList();
         }
         cmbTheme.SelectedItem = theme;
     } catch (Exception ex) {
         Trace.WriteLine(string.Format("IndentGuide::btnCustomizeThisContentType_Click: {0}", ex));
     }
 }
 public LineFormat(IndentTheme theme)
     : this()
 {
     Theme = theme;
 }
 public PageWidthMarkerFormat(IndentTheme theme)
     : this()
 {
     Theme = theme;
 }
 public ThemeEventArgs(IndentTheme theme)
     : base()
 {
     Theme = theme;
 }
 internal PageWidthMarkerGetter(IndentTheme theme)
 {
     Theme = theme;
 }