Пример #1
0
        public ResourceTableDelegate(IHostResourceProvider hostResources, ResourceTableDataSource resourceTableDatasource)
        {
            if (hostResources == null)
            {
                throw new ArgumentNullException(nameof(hostResources));
            }

            this.datasource    = resourceTableDatasource;
            this.hostResources = hostResources;
        }
        private void Initialize(IHostResourceProvider hostResources, object selectedValue)
        {
            this.selectedValue = selectedValue;
            Frame = new CGRect(10, 35, 630, 305);

            var FrameHeightHalf = (Frame.Height - 32) / 2;
            var FrameWidthHalf  = (Frame.Width - 32) / 2;
            var FrameWidthThird = (Frame.Width - 32) / 3;

            this.progressIndicator = new NSProgressIndicator(new CGRect(FrameWidthThird, FrameHeightHalf, 32, 32))
            {
                Hidden = true,
                Style  = NSProgressIndicatorStyle.Spinning,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };
            AddSubview(this.progressIndicator);

            this.resourceTable = new FirstResponderTableView {
                AutoresizingMask = NSViewResizingMask.WidthSizable,
                HeaderView       = null,
            };

            this.dataSource = new ResourceTableDataSource(viewModel);
            var resourceTableDelegate = new ResourceTableDelegate(hostResources, dataSource);

            resourceTableDelegate.ResourceSelected += (sender, e) => {
                this.previewPanel.SelectedResource = SelectedResource;

                this.selectedValue = BrushPropertyViewModel.GetCommonBrushForResource(SelectedResource);

                ResourceSelected?.Invoke(this, EventArgs.Empty);
            };
            this.resourceTable.Delegate   = resourceTableDelegate;
            this.resourceTable.DataSource = dataSource;

            NSTableColumn resourceImages = new NSTableColumn(ResourceImageColId)
            {
                Title = Properties.Resources.ResourceTableImageColumnTitle, Width = 32
            };

            this.resourceTable.AddColumn(resourceImages);

            NSTableColumn resourceTypes = new NSTableColumn(ResourceTypeColId)
            {
                Title = Properties.Resources.ResourceTableTypeColumnTitle, Width = 150
            };

            this.resourceTable.AddColumn(resourceTypes);

            NSTableColumn resourceName = new NSTableColumn(ResourceNameColId)
            {
                Title = Properties.Resources.ResourceTableNameColumnTitle, Width = 150
            };

            resourceTable.AddColumn(resourceName);

            NSTableColumn resourceValue = new NSTableColumn(ResourceValueColId)
            {
                Title = Properties.Resources.ResourceTableValueColumnTitle, Width = 45
            };

            this.resourceTable.AddColumn(resourceValue);

            this.resourceTable.DoubleClick += (object sender, EventArgs e) => {
                DoubleClicked?.Invoke(this, EventArgs.Empty);
            };

            // create a table view and a scroll view
            this.tableContainer = new NSScrollView(new CGRect(0, 0, resourceTable.TableColumns()[0].Width + resourceTable.TableColumns()[1].Width + resourceTable.TableColumns()[2].Width + 10, Frame.Height))
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            this.tableContainer.DocumentView = resourceTable;
            AddSubview(this.tableContainer);

            this.previewPanel = new RequestResourcePreviewPanel(hostResources, new CGRect(Frame.Width - FrameWidthThird, 0, FrameWidthThird, Frame.Height));
            AddSubview(this.previewPanel);

            this.AddConstraints(new[] {
                NSLayoutConstraint.Create(this.tableContainer, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, -190f),
                NSLayoutConstraint.Create(this.tableContainer, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, 0f),
            });

            ReloadData();
        }