示例#1
0
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            this.graphicsResources = new GraphicsResources(
                viewModel,
                (fontData) => new LJD.Font(fontData.Name ?? "monaco",
                                           (float)NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                textFormat: null,
                images: (
                    error: new LJD.Image(NSImage.ImageNamed("ErrorLogSeverity.png")),
                    warn: new LJD.Image(NSImage.ImageNamed("WarnLogSeverity.png")),
                    bookmark: new LJD.Image(NSImage.ImageNamed("Bookmark.png")),
                    focusedMark: new LJD.Image(NSImage.ImageNamed("FocusedMsg.png"))
                    ),
                graphicsForMeasurmentFactory: () => graphicsForMeasurment
                );
            this.viewDrawing = new ViewDrawing(viewModel,
                                               graphicsResources,
                                               1f,
                                               () => 0,
                                               () => viewWidth
                                               );
            this.drawingPerfCounters       = new Profiling.Counters(viewModel.Trace, "drawing");
            this.graphicsCounters          = LJD.Graphics.CreateCounters(drawingPerfCounters);
            this.controlPaintTimeCounter   = this.drawingPerfCounters.AddCounter("paint", unit: "ms");
            this.controlPaintWidthCounter  = this.drawingPerfCounters.AddCounter("width", unit: "pixel");
            this.controlPaintHeightCounter = this.drawingPerfCounters.AddCounter("height", unit: "pixel");
            var viewUpdater = Updaters.Create(
                () => viewModel.ViewLines,
                () => viewModel.FocusedMessageMark,
                (_1, _2) => { this.InnerView.NeedsDisplay = true; }
                );
            var emptyViewMessageUpdater = Updaters.Create(
                () => viewModel.EmptyViewMessage,
                value => {
                drawDropMessage         = value;
                DragDropIconView.Hidden = value == null;
            }
                );
            var vScrollUpdater = Updaters.Create(
                () => viewModel.VerticalScrollerPosition,
                value => {
                VertScroller.Enabled        = value.HasValue;
                VertScroller.KnobProportion = 0.0001f;
                VertScroller.DoubleValue    = value.GetValueOrDefault();
            }
                );

            viewModel.ChangeNotification.CreateSubscription(() => {
                viewUpdater();
                emptyViewMessageUpdater();
                vScrollUpdater();
            });
        }
示例#2
0
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            var prototypeStringFormat = (StringFormat)StringFormat.GenericDefault.Clone();

            prototypeStringFormat.SetTabStops(0, new float[] { 20 });
            prototypeStringFormat.FormatFlags |=
                StringFormatFlags.MeasureTrailingSpaces |
                StringFormatFlags.NoFontFallback;                 // this is to treat \0002 and \0003 as regular characters

            graphicsResources = new GraphicsResources(viewModel,
                                                      fontData => new LJD.Font(GetFontFamily(fontData.Name).Name, ToFontEmSize(fontData.Size)),
                                                      textFormat: new LJD.StringFormat(prototypeStringFormat),
                                                      (error: new LJD.Image(Properties.Resources.ErrorLogSeverity),
                                                       warn: new LJD.Image(Properties.Resources.WarnLogSeverity),
                                                       bookmark: new LJD.Image(Properties.Resources.Bookmark),
                                                       focusedMark: new LJD.Image(Properties.Resources.FocusedMsg)),
                                                      () => new LJD.Graphics(this.CreateGraphics(), ownsGraphics: true)
                                                      );

            viewDrawing = new ViewDrawing(
                viewModel,
                graphicsResources,
                dpiScale: UIUtils.Dpi.Scale(1f),
                scrollPosXSelector: () => scrollPosXCache,
                viewWidthSelector: () => viewWidthCache
                );

            viewWidthCache = this.ClientRectangle.Width;

            var viewUpdater = Updaters.Create(
                () => viewModel.ViewLines,
                () => viewModel.FocusedMessageMark,
                (_1, _2) =>
            {
                Invalidate();
            }
                );
            var vScrollerUpdater = Updaters.Create(
                () => viewModel.VerticalScrollerPosition,
                value =>
            {
                scrollBarsInfo.scrollSize.Height = value != null ? ScrollBarsInfo.virtualVScrollSize : 0;
                SetScrollPos(posY: (int)(value.GetValueOrDefault() * (double)(ScrollBarsInfo.virtualVScrollSize - ClientRectangle.Height + 1)));
            }
                );
            var emptyViewMessageUpdater = Updaters.Create(
                () => viewModel.EmptyViewMessage,
                value =>
            {
                if (emptyMessagesCollectionMessage == null)
                {
                    Controls.Add(emptyMessagesCollectionMessage = new EmptyMessagesCollectionMessage {
                        Dock = DockStyle.Fill
                    });
                }
                emptyMessagesCollectionMessage.Visible = value != null;
                emptyMessagesCollectionMessage.SetMessage(value ?? "");
            }
                );

            viewModel.ChangeNotification.CreateSubscription(() =>
            {
                viewUpdater();
                vScrollerUpdater();
                emptyViewMessageUpdater();
            });
        }