Ejemplo n.º 1
0
        public override bool ShouldSelectItem(NSOutlineView outlineView, NSObject item)
        {
            var animator = outlineView.Animator as NSOutlineView;

            if (outlineView.IsItemExpanded(item))
            {
                animator.CollapseItem(item, false);
            }
            else
            {
                animator.ExpandItem(item, false);
            }

            return(false);
        }
        public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
        {
            GetVMGroupCellItendifiterFromFacade(item, out EditorViewModel evm, out PanelGroupViewModel group, out var cellIdentifier);

            if (group != null)
            {
                var categoryContainer = (CategoryContainerControl)outlineView.MakeView(CategoryIdentifier, this);
                if (categoryContainer == null)
                {
                    categoryContainer = new CategoryContainerControl(this.hostResources, outlineView)
                    {
                        Identifier = CategoryIdentifier,
                        TableView  = outlineView,
                    };
                }

                ((UnfocusableTextField)categoryContainer.Subviews[1]).StringValue = group.Category;

                if (this.dataSource.DataContext.GetIsExpanded(group.Category))
                {
                    SynchronizationContext.Current.Post(s => {
                        outlineView.ExpandItem(item);
                    }, null);
                }

                return(categoryContainer);
            }

            NSView editorOrContainer = null;

            if (this.firstCache.TryGetValue(cellIdentifier, out IEditorView editor))
            {
                this.firstCache.Remove(cellIdentifier);
                editorOrContainer = (editor.NativeView is PropertyEditorControl) ? new EditorContainer(this.hostResources, editor)
                {
                    Identifier = cellIdentifier
                } : editor.NativeView;
            }
            else
            {
                editorOrContainer = GetEditor(cellIdentifier, evm, outlineView);
                editor            = ((editorOrContainer as EditorContainer)?.EditorView) ?? editorOrContainer as IEditorView;
            }

            if (editorOrContainer is EditorContainer ec)
            {
                ec.ViewModel = evm;
                ec.Label     = evm.Name;

#if DEBUG // Currently only used to highlight which controls haven't been implemented
                if (editor == null)
                {
                    ec.LabelTextColor = NSColor.Red;
                }
#endif
            }

            if (editor != null)
            {
                var ovm = evm as ObjectPropertyViewModel;
                if (ovm != null && editorOrContainer is EditorContainer container)
                {
                    if (container.LeftEdgeView == null)
                    {
                        if (ovm.CanDelve)
                        {
                            container.LeftEdgeView = outlineView.MakeView("NSOutlineViewDisclosureButtonKey", outlineView);
                        }
                    }
                    else if (!ovm.CanDelve)
                    {
                        container.LeftEdgeView = null;
                    }
                }
                else if (!(editorOrContainer is EditorContainer))
                {
                    editor.ViewModel = evm;
                }

                bool openObjectRow = ovm != null && outlineView.IsItemExpanded(item);
                if (!openObjectRow)
                {
                    var parent = outlineView.GetParent(item);
                    openObjectRow = (parent != null && ((NSObjectFacade)parent).Target is ObjectPropertyViewModel);
                }

                SetRowValueBackground(editorOrContainer, openObjectRow);

                // Force a row update due to new height, but only when we are non-default
                if (editor.IsDynamicallySized)
                {
                    nint index = outlineView.RowForItem(item);
                    outlineView.NoteHeightOfRowsWithIndexesChanged(new NSIndexSet(index));
                }
            }
            else if (editorOrContainer is PanelHeaderEditorControl header)
            {
                header.ViewModel = this.dataSource.DataContext;
            }

            return(editorOrContainer);
        }
Ejemplo n.º 3
0
            /// <inheritdoc />
            public override bool ShouldEditTableColumn(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
            {
                DebugDelegatePrint("***************** SHOULD EDIT CALLED");
                var canEdit = MenuLayoutCommandGroup.EditLongNameCommand.CanExecute(ViewModel.HostPCMenuLayout);

                if (canEdit)
                {
                    var treeNode = item as NSTreeNode;
                    EditingColumn = (EditableOutlineViewColumn)outlineView.TableColumns().ToList().IndexOf(tableColumn);
                    var    editingObject = treeNode.RepresentedObject as FileNodeViewModel;
                    string initialValue  = null;
                    int    maxLength     = -1;
                    switch (EditingColumn)
                    {
                    case EditableOutlineViewColumn.LongName:
                        canEdit      = true;
                        initialValue = editingObject.LongName;
                        maxLength    = INTV.LtoFlash.Model.FileSystemConstants.MaxLongNameLength;
                        break;

                    case EditableOutlineViewColumn.ShortName:
                        canEdit      = true;
                        initialValue = editingObject.ShortName;
                        maxLength    = INTV.LtoFlash.Model.FileSystemConstants.MaxShortNameLength;
                        break;

                    default:
                        ErrorReporting.ReportError("Unsupported edit column");
                        break;
                    }
                    if (InPlaceEditor == null)
                    {
                        InPlaceEditor = new TextCellInPlaceEditor(outlineView);
                    }
                    InPlaceEditor.EditingObject    = editingObject;
                    InPlaceEditor.InitialValue     = initialValue;
                    InPlaceEditor.MaxLength        = maxLength;
                    InPlaceEditor.IsValidCharacter = (c) => INTV.Core.Model.Grom.Characters.Contains(c);
                    InPlaceEditor.EditorClosed    += InPlaceEditor_EditorClosed;
                    InPlaceEditor.BeginEdit();
                }
                else if ((SingleInstanceApplication.Current.LastKeyPressed == TextCellInPlaceEditor.ReturnKey) && (SingleInstanceApplication.Current.LastKeyPressedTimestamp != ReturnKeyTimestamp))
                {
                    // return was pressed -- do we need to check for <enter> vs. <return> (on laptops, Fn+return)?
                    ReturnKeyTimestamp = SingleInstanceApplication.Current.LastKeyPressedTimestamp;
                    if (!outlineView.IsExpandable(item) && DownloadCommandGroup.DownloadAndPlayCommand.CanExecute(ViewModel))
                    {
                        var program = ViewModel.HostPCMenuLayout.CurrentSelection as ProgramViewModel;
                        if ((program != null) && DownloadCommandGroup.DownloadAndPlayCommand.CanExecute(ViewModel))
                        {
                            DownloadCommandGroup.DownloadAndPlay(ViewModel.ActiveLtoFlashDevice.Device, program.ProgramDescription);
                        }
                    }
                    else
                    {
                        // On a directory. If so, toggle state.
                        if (outlineView.IsItemExpanded(item))
                        {
                            outlineView.CollapseItem(item);
                        }
                        else
                        {
                            outlineView.ExpandItem(item);
                        }
                    }
                }
                return(canEdit);
            }