Beispiel #1
0
        public override NSTableRowView RowViewForItem(NSOutlineView outlineView, NSObject item)
        {
            TreeRowView view = (TreeRowView)outlineView.MakeView("row", this);

            if (view == null)
            {
                view = new TreeRowView()
                {
                    owner      = owner,
                    Identifier = "row"
                }
            }
            ;
            view.Update((Node)item);
            return(view);
        }
    };
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            this.Window.EnsureCreated();

            treeViewController.OnExpand     = viewModel.OnExpandNode;
            treeViewController.OnCollapse   = viewModel.OnCollapseNode;
            treeViewController.OnSelect     = viewModel.OnSelect;
            treeViewController.OnCreateView = (col, node) => {
                TreeNodeView view = (TreeNodeView)treeView.MakeView("view", this);
                if (view == null)
                {
                    view = new TreeNodeView {
                        owner      = this,
                        Identifier = "view",
                        Menu       = new NSMenu {
                            Delegate = GetContextMenuDelegate()
                        }
                    }
                }
                ;
                view.Update(node);
                return(view);
            };
            treeViewController.OnCreateRowView = (node) => {
                TreeRowView view = (TreeRowView)treeView.MakeView("row", this);
                if (view == null)
                {
                    view = new TreeRowView {
                        owner      = this,
                        Identifier = "row"
                    }
                }
                ;
                view.Update(node);
                return(view);
            };
            treeViewController.OnUpdateRowView = (rowView, node) => {
                ((TreeRowView)rowView).Update(node);
            };


            stateHistoryController.OnSelect     = items => viewModel.OnChangeHistoryChangeSelection(items);
            stateHistoryController.OnCreateView = (historyItem, tableColumn) => {
                NSTextField MakeTextField(string viewId)
                {
                    NSTextField view = (NSTextField)stateHistoryView.MakeView(viewId, this);

                    if (view == null)
                    {
                        view = new NSTextField()
                        {
                            Identifier      = viewId,
                            Editable        = false,
                            Selectable      = false,
                            Bordered        = false,
                            BackgroundColor = NSColor.Clear
                        };
                        view.Cell.LineBreakMode = NSLineBreakMode.TruncatingTail;
                    }
                    return(view);
                }

                if (tableColumn == HistoryItemTimeColumn)
                {
                    var view = MakeTextField("timeView");
                    view.StringValue = historyItem.Time;
                    return(view);
                }
                else if (tableColumn == HistoryItemTextColumn)
                {
                    var view = MakeTextField("messageView");
                    view.StringValue = historyItem.Message;
                    return(view);
                }

                return(null);
            };
            stateHistoryController.OnUpdateView = (item, tableColumn, view, oldItem) => {
                if (tableColumn == HistoryItemTimeColumn)
                {
                    ((NSTextField)view).StringValue = item.Time;
                }
                else if (tableColumn == HistoryItemTextColumn)
                {
                    ((NSTextField)view).StringValue = item.Message;
                }
            };

            stateHistoryController.OnCreateRowView = (item, rowIndex) =>
            {
                return(new StateHistoryTableRowView {
                    owner = this, row = rowIndex, items = viewModel.ChangeHistoryItems
                });
            };


            var updateTree = Updaters.Create(
                () => viewModel.ObjectsTreeRoot,
                treeViewController.Update
                );

            var invalidateTree = Updaters.Create(
                () => viewModel.PaintNode,
                () => viewModel.ColorTheme,
                (_1, _2) => InvalidateTree()
                );

            var updateStateHistory = Updaters.Create(
                () => viewModel.ChangeHistoryItems,
                items =>
            {
                stateHistoryController.Update(items);
                UpdateStateHistoryTimeColumn(items);
            }
                );

            var invalidateStateHistory = Updaters.Create(
                () => viewModel.IsChangeHistoryItemBookmarked,
                () => viewModel.FocusedMessagePositionInChangeHistory,
                (_1, _2) => InvalidateStateHistoryTableView()
                );

            var updateProperties = Updaters.Create(
                () => viewModel.ObjectsProperties,
                properties => {
                propsDataSource.data = properties;
                propertiesView.ReloadData();
            }
                );

            var updateCurrentTime = Updaters.Create(
                () => viewModel.CurrentTimeLabelText,
                timeValue => currentTimeLabel.StringValue = timeValue
                );

            viewModel.ChangeNotification.CreateSubscription(() => {
                updateTree();
                invalidateTree();
                updateStateHistory();
                invalidateStateHistory();
                updateProperties();
                updateCurrentTime();
            });
        }

        void IView.Show()
        {
            ShowInternal();
        }

        void IView.ScrollStateHistoryItemIntoView(int itemIndex)
        {
            var items = viewModel.ChangeHistoryItems;

            if (items.Count == 0)
            {
                return;
            }
            stateHistoryView.ScrollRowToVisible(RangeUtils.PutInRange(0, items.Count - 1, itemIndex));
        }

        void InvalidateTree()
        {
            treeView.NeedsDisplay = true;
            var rows = treeView.RowsInRect(treeView.VisibleRect());

            for (var r = 0; r < rows.Length; ++r)
            {
                var rv = treeView.GetRowView(r + rows.Location, false);
                if (rv != null)
                {
                    rv.NeedsDisplay = true;
                }
                var nv = treeView.GetView(0, r + rows.Location, false);
                if (nv != null)
                {
                    nv.NeedsDisplay = true;
                }
            }
        }

        void UpdateStateHistoryTimeColumn(IReadOnlyList <IStateHistoryItem> items)
        {
            var widestCell = items.Select(
                (item, idx) => (item, idx)
                ).MaxByKey(
                i => i.item.Time.Length
                );

            if (widestCell.item != null)
            {
                var cellView = (NSTextField)stateHistoryView.GetView(1, widestCell.idx, makeIfNecessary: true);
                cellView.SizeToFit();
                historyItemTimeColumn.Width = cellView.Frame.Width + 10;
            }
            else
            {
                historyItemTimeColumn.Width = 0;
            }
        }

        void Presenters.Postprocessing.IPostprocessorVisualizerPresenter.Show()
        {
            ShowInternal();
        }