示例#1
0
        private DateTime GetTimeOfItem(object item)
        {
            FieldLogItemViewModel flItem = item as FieldLogItemViewModel;

            if (flItem != null)
            {
                return(flItem.Time);
            }
            DebugMessageViewModel dbgItem = item as DebugMessageViewModel;

            if (dbgItem != null)
            {
                return(dbgItem.Time);
            }
            throw new ArgumentException("Unsupported item type.");               // Should never happen
        }
示例#2
0
        private void UpdateScrollmap()
        {
            if (logItemsHostPanel == null)
            {
                // SmoothVirtualizingPanel_Loaded wasn't called yet. Remember to update the scroll
                // map when it will be called.
                scrollmapUpdatePending = true;
                return;
            }
            if (logItemsScroll == null)
            {
                return;
            }

            bool showWarningsErrors = App.Settings.ShowWarningsErrorsInScrollBar;
            bool showSelection      = App.Settings.ShowSelectionInScrollBar;

            if (!showWarningsErrors && !showSelection)
            {
                // Nothing to display, but clear anything that may already be there
                ClearScrollmap();
                return;
            }

            double itemOffset = 0;
            double itemHeight = logItemsHostPanel.ItemHeight;

            bool scrollBarVisible = logItemsScroll.ComputedVerticalScrollBarVisibility == Visibility.Visible;

            if (scrollBarVisible)
            {
                ScrollBar sb = logItemsScroll.FindVisualChild <ScrollBar>(d => AutomationProperties.GetAutomationId(d) == "VerticalScrollBar");
                if (sb != null)
                {
                    Grid g = sb.FindVisualChild <Grid>();
                    if (g != null && g.RowDefinitions.Count == 3)
                    {
                        itemOffset = g.RowDefinitions[0].ActualHeight + 2;
                        itemHeight = (g.RowDefinitions[1].ActualHeight - 4) / LogItemsList.Items.Count;
                    }
                }
            }
            else
            {
                return;
            }

            StreamGeometry warningGeometry = new StreamGeometry();

            warningGeometry.FillRule = FillRule.Nonzero;
            StreamGeometry errorGeometry = new StreamGeometry();

            errorGeometry.FillRule = FillRule.Nonzero;
            StreamGeometry criticalGeometry = new StreamGeometry();

            criticalGeometry.FillRule = FillRule.Nonzero;
            StreamGeometry selectionGeometry = new StreamGeometry();

            selectionGeometry.FillRule = FillRule.Nonzero;

            StreamGeometryContext warningCtx   = warningGeometry.Open();
            StreamGeometryContext errorCtx     = errorGeometry.Open();
            StreamGeometryContext criticalCtx  = criticalGeometry.Open();
            StreamGeometryContext selectionCtx = selectionGeometry.Open();

            HashSet <object> selectedItems = new HashSet <object>(LogItemsList.SelectedItems.OfType <object>());

            for (int index = 0; index < LogItemsList.Items.Count; index++)
            {
                if (showWarningsErrors)
                {
                    FieldLogItemViewModel flItem = LogItemsList.Items[index] as FieldLogItemViewModel;
                    if (flItem != null)
                    {
                        if (flItem.Priority >= FieldLogPriority.Warning)
                        {
                            double y = Math.Round(itemOffset + (index + 0.5) * itemHeight);

                            StreamGeometryContext ctx;
                            if (flItem.Priority == FieldLogPriority.Warning)
                            {
                                ctx = warningCtx;
                            }
                            else if (flItem.Priority == FieldLogPriority.Error)
                            {
                                ctx = errorCtx;
                            }
                            else if (flItem.Priority == FieldLogPriority.Critical)
                            {
                                ctx = criticalCtx;
                            }
                            else
                            {
                                continue;
                            }

                            ctx.BeginFigure(new Point(0, y - 2), true, true);
                            ctx.PolyLineTo(new Point[]
                            {
                                new Point(3, y - 2),
                                new Point(3, y + 2),
                                new Point(0, y + 2)
                            }, false, false);
                        }
                    }
                }

                if (showSelection)
                {
                    if (selectedItems.Contains(LogItemsList.Items[index]))
                    {
                        double y = Math.Round(itemOffset + (index + 0.5) * itemHeight);
                        selectionCtx.BeginFigure(new Point(4, y - 1), true, true);
                        selectionCtx.PolyLineTo(new Point[]
                        {
                            new Point(7, y - 1),
                            new Point(7, y + 1),
                            new Point(4, y + 1)
                        }, false, false);
                    }
                }
            }

            warningCtx.Close();
            warningGeometry.Freeze();
            errorCtx.Close();
            errorGeometry.Freeze();
            criticalCtx.Close();
            criticalGeometry.Freeze();
            selectionCtx.Close();
            selectionGeometry.Freeze();

            WarningMap.Data   = warningGeometry;
            ErrorMap.Data     = errorGeometry;
            CriticalMap.Data  = criticalGeometry;
            SelectionMap.Data = selectionGeometry;
        }