public void Add()
        {
            var window = new AddEditHighlighterWindow();
            var data = new AddEditHighlighter(window, false);
            window.DataContext = data;
            window.Owner = Application.Current.MainWindow;

            var dialogResult = window.ShowDialog();
            if (dialogResult != null && (bool)dialogResult)
            {
                var highlighter = Construct(data);

                if (highlighter != null)
                {
                    var service = ServiceLocator.Instance.Get<IHighlightingService<IHighlighter>>();
                    service?.Highlighters.Add(highlighter);
                }
            }
        }
        public void Add()
        {
            var window = new AddEditHighlighterWindow();
            var data   = new AddEditHighlighter(window, false);

            window.DataContext = data;
            window.Owner       = Application.Current.MainWindow;

            var dialogResult = window.ShowDialog();

            if (dialogResult != null && (bool)dialogResult)
            {
                var highlighter = Construct(data);

                if (highlighter != null)
                {
                    var service = ServiceLocator.Instance.Get <IHighlightingService <IHighlighter> >();
                    service?.Highlighters.Add(highlighter);
                }
            }
        }
        public void Edit(IHighlighter highlighter)
        {
            Debug.Assert(highlighter != null, "Highlighter must be supplied for editing.");

            var window = new AddEditHighlighterWindow();
            var data   = new AddEditHighlighter(window, false);

            window.DataContext = data;
            window.Owner       = Application.Current.MainWindow;

            data.Name    = highlighter.Name;
            data.Pattern = highlighter.Pattern;
            data.Mode    = highlighter.Mode;
            data.Field   = highlighter.Field;

            if (highlighter.Style?.Background != null)
            {
                data.OverrideBackgroundColour = true;
                data.BackgroundColour         = (Color)highlighter.Style.Background;
            }
            else
            {
                data.OverrideBackgroundColour = false;
                data.BackgroundColourIndex    = 1;
            }

            if (highlighter.Style?.Foreground != null)
            {
                data.OverrideForegroundColour = true;
                data.ForegroundColour         = (Color)highlighter.Style.Foreground;
            }
            else
            {
                data.OverrideForegroundColour = false;
                data.ForegroundColourIndex    = 0;
            }

            var dialogResult = window.ShowDialog();

            if (dialogResult != null && (bool)dialogResult)
            {
                highlighter.Name    = data.Name;
                highlighter.Pattern = data.Pattern;
                highlighter.Mode    = data.Mode;
                highlighter.Field   = data.Field;

                if (highlighter.Style == null && (data.OverrideBackgroundColour || data.OverrideForegroundColour))
                {
                    highlighter.Style = new HighlighterStyle();
                }

                if (highlighter.Style != null)
                {
                    highlighter.Style.Background = data.OverrideBackgroundColour
                                                       ? (Color?)data.BackgroundColour
                                                       : null;
                    highlighter.Style.Foreground = data.OverrideForegroundColour
                                                       ? (Color?)data.ForegroundColour
                                                       : null;
                }
            }
        }
        public void Edit(IHighlighter highlighter)
        {
            Debug.Assert(highlighter != null, "Highligher must be supplied for editing.");

            AddEditHighlighterWindow window = new AddEditHighlighterWindow();
            AddEditHighlighter data = new AddEditHighlighter(window, false);
            window.DataContext = data;
            window.Owner = Application.Current.MainWindow;

            data.Name = highlighter.Name;
            data.Pattern = highlighter.Pattern;
            data.Mode = highlighter.Mode;
            data.Field = highlighter.Field;

            if (highlighter.Style != null && highlighter.Style.Background != null)
            {
                data.OverrideBackgroundColour = true;
                data.BackgroundColour = (Color)highlighter.Style.Background;
            }
            else
            {
                data.OverrideBackgroundColour = false;
                data.BackgroundColourIndex = 1;
            }

            if (highlighter.Style != null && highlighter.Style.Foreground != null)
            {
                data.OverrideForegroundColour = true;
                data.ForegroundColour = (Color)highlighter.Style.Foreground;
            }
            else
            {
                data.OverrideForegroundColour = false;
                data.ForegroundColourIndex = 0;
            }

            bool? dialogResult = window.ShowDialog();

            if (dialogResult != null && (bool)dialogResult)
            {
                highlighter.Name = data.Name;
                highlighter.Pattern = data.Pattern;
                highlighter.Mode = data.Mode;
                highlighter.Field = data.Field;

                if (highlighter.Style == null && (data.OverrideBackgroundColour || data.OverrideForegroundColour))
                {
                    highlighter.Style = new HighlighterStyle();
                }

                if (highlighter.Style != null)
                {
                    highlighter.Style.Background = data.OverrideBackgroundColour
                                                       ? (Color?)data.BackgroundColour
                                                       : null;
                    highlighter.Style.Foreground = data.OverrideForegroundColour
                                                       ? (Color?)data.ForegroundColour
                                                       : null;
                }
            }
        }