public override nfloat GetSizeToFitColumnWidth(NSOutlineView outlineView, nint column) { var columns = outlineView.TableColumns(); var col = columns[column]; var columnWidth = col.MinWidth; for (nint row = 0; row < outlineView.RowCount; row++) { var rowView = outlineView.GetRowView(row, true); var columnView = rowView.ViewAtColumn(column); var width = columnView.Frame.Width; if (column == 0) { width += columnView.Frame.X; } if (width > columnWidth) { columnWidth = NMath.Min(width, col.MaxWidth); } } return(columnWidth); }
/// <inheritdoc /> public override string ToolTipForCell(NSOutlineView outlineView, NSCell cell, ref CGRect rect, NSTableColumn tableColumn, NSObject item, CGPoint mouseLocation) { var toolTip = string.Empty; var treeNode = item as NSTreeNode; var mouseOverObject = treeNode.RepresentedObject as FileNodeViewModel; var whichColumn = outlineView.TableColumns().ToList().IndexOf(tableColumn); switch (whichColumn) { case 0: if ((mouseOverObject != null) && !string.IsNullOrEmpty(mouseOverObject.IconTipStrip)) { toolTip = mouseOverObject.IconTipStrip; } break; } return(toolTip); }
// the table is looking for this method, picks it up automagically public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item) { var facade = (NSObjectFacade)item; var vm = facade.Target as PropertyViewModel; var group = facade.Target as IGroupingList <string, EditorViewModel>; string cellIdentifier = (group == null) ? vm.GetType().Name : group.Key; // Let's make the columns look pretty if (!goldenRatioApplied) { int middleColumnWidth = 5; nfloat rightColumnWidth = (outlineView.Frame.Width - middleColumnWidth) / 1.618f; nfloat leftColumnWidth = outlineView.Frame.Width - rightColumnWidth - middleColumnWidth; outlineView.TableColumns()[0].Width = leftColumnWidth; outlineView.TableColumns()[1].Width = rightColumnWidth; goldenRatioApplied = true; } // Setup view based on the column switch (tableColumn.Identifier) { case PropertyEditorPanel.PropertyListColId: var view = (UnfocusableTextField)outlineView.MakeView("label", this); if (view == null) { view = new UnfocusableTextField { Identifier = "label", Alignment = NSTextAlignment.Right, }; } view.StringValue = ((group == null) ? vm.Property.Name + ":" : group.Key) ?? String.Empty; // Set tooltips only for truncated strings var stringWidth = view.AttributedStringValue.Size.Width + 30; if (stringWidth > tableColumn.Width) { view.ToolTip = vm.Property.Name; } return(view); case PropertyEditorPanel.PropertyEditorColId: if (vm == null) { return(null); } var editor = (PropertyEditorControl)outlineView.MakeView(cellIdentifier + "edits", this); if (editor == null) { editor = GetEditor(vm, outlineView); // If still null we have no editor yet. if (editor == null) { return(new NSView()); } } // we must reset these every time, as the view may have been reused editor.TableRow = outlineView.RowForItem(item); // Force a row update due to new height, but only when we are non-default if (editor.TriggerRowChange) { outlineView.NoteHeightOfRowsWithIndexesChanged(new NSIndexSet(editor.TableRow)); } return(editor); } throw new Exception("Unknown column identifier: " + tableColumn.Identifier); }
/// <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); }