OutlineView | OutlineView for SwiftUI on macOS | Frontend Framework library
kandi X-RAY | OutlineView Summary
kandi X-RAY | OutlineView Summary
OutlineView is a SwiftUI view for macOS, which allows you to display hierarchical visual layouts (like directories and files) that can be expanded and collapsed. It provides a convenient wrapper around AppKit's NSOutlineView, similar to SwiftUI's OutlineGroup embedded in a List or a List with children. OutlineView provides it's own scroll view and doesn't have to be embedded in a List.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of OutlineView
OutlineView Key Features
OutlineView Examples and Code Snippets
Community Discussions
Trending Discussions on OutlineView
QUESTION
First of all, sorry for my English, I'll try my best to make it clear.(Edited with @Chip Jarred's suggestion,I've made some changes to simplify my question)
What I managed to do is achieving NSOutlineview drag & drop method, using .gap style(I just want to use this style!):
...ANSWER
Answered 2021-Apr-10 at 21:31After doing some research, I found multiple reports of a bug with NSTableView
when using the .gap
dragging style. It would seem that NSOutlineView
is inheriting that bug. In any case, I found a work-around.
The problem is that when you drag below the last top-level item, the item
and childIndex
passed to outlineView(_:acceptDrop:item:childIndex)
are always nil
and 0
, which are exactly the same values you get when dragging to the top of list. The only way I could find to differentiate between the two cases was to use the draggingLocation
from NSDraggingInfo
to compare against the first item's cell frame, and use that to translate the index
.
QUESTION
I want to print an NSOutlineView. The view is a subview of a window on screen. I noticed the NSView api call printView. So I tried it in a simple minded fashion. In my AppDelegate I have a call:
...ANSWER
Answered 2021-Feb-08 at 19:25Dark mode causes some issues with printing. The easiest workaround is to create a separate, programmatic view with forced light appearance, clone the required content and then print that view.
view.appearance = NSAppearance(named: .aqua)
QUESTION
I use a NSOutlineView that auto saves expanded state. If I manually reload data when dataSource updates, the func outlineView(_ outlineView: NSOutlineView, itemForPersistentObject object: Any) -> Any?
datasource method is not called anymore and every cell collapses. Any idea why this might happen?
Tried to reloadItem with nil send as param but still no good.
I use this for persisting expanded rows:
...ANSWER
Answered 2020-Aug-11 at 08:52IMHO autosaving is sort of half-baked feature and it doesn't work as expected. In other words, it's implemented in a way that it restores the state when your application launches (just once) and then you're on your own.
Implement your own one utilizing outlineViewItemDidExpand(_:)
& outlineViewItemDidCollapse(_:)
(especially when we're reloading, ...).
Couple of tricks you can use if you do not want to implement custom autosaving. But I wouldn't rely on them.
First trick - tell the NSOutlineView to reload persistent stateNSOutlineView
inherits from the NSTableView
and the autosaveName
property documentation says:
If you change the value of this property to a new name, the table reads in any saved information and sets the order and width of this table view’s columns to match. Setting the name to
nil
removes any previously stored state from the user defaults.
What is inaccurate here - setting it to nil
doesn't remove previously stored expanded items state for NSOutlineView
. We can use it to force the NSOutlineView
to reload expanded items state:
QUESTION
I have a window with 3 NSViewControllers in a splitview - effectively a 3 level master detail. Inside each are, in order, an OutlineView, TableView and a details view (with lots of controls).
When someone clicks on a row in the middle TableView, SelectionDidChange
fires, and I call LoadData
on the details view controller.
I now want the details form to get focus - specifically an NSTextView
on that form. So in LoadData
, I call TextView.BecomeFirstResponder()
,
which returns true.
But focus stays firmly on the TableView, and does not move to the details view. If I press a key, it goes to the TableView which uses it to select another row.
Is there something simple I am missing? When one of the controls on the details view has focus, I can definitely move focus between controls, but not from another view controller.
Thx. Paul,
...ANSWER
Answered 2020-Aug-08 at 06:29Assuming your view controller view and TextView
are already in window view hierarchy, do the following:
QUESTION
I've started a new macOS project (currently on Big Sur beta 3), and the NSOutlineView
nodes seem to be broken. Can't tell if this is me or the os.
Here's a sample project that demonstrates the issue. And an image...
As you can see, the cell is overlapping the expansion chevrons. Clicking on either chevron restores the first row to the proper layout, but not the second. Also, the autosave methods persistentObjectForItem
and itemForPersistentObject
are never called.
The test project is super simple--all I did was add the SourceView
component from the view library to the default app project and hook up the delegate/data source to the view controller. Also checked Autosave Expanded Items
in IB and put a name in the Autosave
field. Here's the entirety of the controller code:
ANSWER
Answered 2020-Jul-29 at 08:00What is a source list? It's NSOutlineView
(which is a subclass of
NSTableView
) with a special
treatment. Finder screenshot:
To create a source list, all you have to do is to set the
selectionHighlightStyle
property to
.sourceList
. The documentation says:
The source list style of NSTableView. On 10.5, a light blue gradient is used to highlight selected rows.
What it does exactly? Jump to Definition in Xcode and read comments (not included in the docs):
The source list style of NSTableView. On 10.10 and higher, a blur selection is used to highlight rows. Prior to that, a light blue gradient was used. Note: Cells that have a drawsBackground property should have it set to NO. Otherwise, they will draw over the highlighting that NSTableView does. Setting this style will have the side effect of setting the background color to the "source list" background color. Additionally in NSOutlineView, the following properties are changed to get the standard "source list" look: indentationPerLevel, rowHeight and intercellSpacing. After calling setSelectionHighlightStyle: one can change any of the other properties as required. In 10.11, if the background color has been changed from the "source list" background color to something else, the table will no longer draw the selection as a source list blur style, and instead will do a normal blue highlight.
Since you're on Big Sur, be aware that the SelectionHighlightStyle.sourceList
is deprecated.
One should use style
& effectiveStyle
.
Xcode:
- New project
- macOS & App (Storyboard & AppKit App Delegate & Swift)
- Main.storyboard
- Add Source List control
- Position & fix constraints
- Set delegate & dataSource to ViewController
- Enable Autosave Expanded Items
- Set Autosave to whatever you want (I have
FinderLikeSidebar
there)- Choose wisely because the expansion state is saved in the user defaults
under the
NSOutlineView Items FinderLikeSidebar
key
- Choose wisely because the expansion state is saved in the user defaults
under the
- Create
@IBOutlet var outlineView: NSOutlineView!
- Add another Text Table Cell View (no image)
- Set identifier to
GroupCell
- Set identifier to
- Add Source List control
- ViewController.swift
- Commented code below
As you can see, it's almost Finder like - 2nd level is still indented. The reason for this is that the Documents node is expandable (has children). I have them here to demonstrate autosaving.
Just remove them if you'd like to move all 2nd level nodes to the left.
ViewController.swift codeThere's not much to say about it except - read comments :)
QUESTION
So I've created an NSOutlineView
to display the file & directory list in a hierarchical way. I'm building a BitTorrent client (stating so the class names make sense).
As you can see, this is pretty much how the outline view looks:
The problem is associated with the Name column. In the name column, for each row, I have a checkbox and a text field side by side. This will help you get a clearer idea:
Now, I use bindings to get the value for each textfield. However, since there are 2 views (checkbox and textfield) that needs to bound to the same NSTableCellView
, I'm returning a struct, from the data source, containing 2 values: a string for the text field (which holds the file/directory name), and a boolean for enabling/disabling the checkbox.
To handle the outline view (especially its data), I've set its class to TorrentContent
, which is defined as below:
ANSWER
Answered 2020-Apr-10 at 09:57Cocoa Bindings uses Key Value Observing (KVO) and the observed object must be KVO compatible. See Using Key-Value Observing in Swift.
You can only use key-value observing with classes that inherit from NSObject.
Mark properties that you want to observe through key-value observing with both the @objc attribute and the dynamic modifier.
Solution A: Return a KVO compatble object from outlineView(_:objectValueFor:byItem:)
Solution B: Don't use Cocoa Bindings. Create a subclass of NSTableCellView
and add a enabledCheckbox
outlet. Set the values in outlineView(_:viewFor:item:)
.
QUESTION
I am attempting to understand how Swift handles for-in loops.
Overview: we are iterating over the rows of an NSOutlineView
. If a condition is met, we expand the item, which obviously changes the overall row count of the outlineView.
Pre-Condition: the OutlineView has 5 "root" items. Each of those has 5 child items.
Example ...ANSWER
Answered 2020-Apr-10 at 07:400 ..< self.numberOfRows
is a Range
and in particular a Sequence
. Iterating over a sequence is done by creating an iterator, and then calling its next()
method until the iterator is exhausted, compare IteratorProtocol
:
Whenever you use a for-in loop with an array, set, or any other collection or sequence, you’re using that type’s iterator. Swift uses a sequence’s or collection’s iterator internally to enable the for-in loop language construct.
So
QUESTION
I have an NSOutlineView where I'm trying to implement "search & replace" ability but the problem is that all nodes are not getting expanding.
...ANSWER
Answered 2020-Mar-22 at 15:48Recursion, expand the parent before expanding the node:
QUESTION
I am trying to make a file browser in my app that opens in a side panel (with a split view controller).
The source is a URL brought by a prepareForSegue method in the previous viewController.
Each time the vc loads i have the fatal error :
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
The compiler locates the error to where i declare :
outlineView.delegate = self outlineView.dataSource = self
I tried : 1. Undoing and redoing all my outlets connections, by code, by storyboard 2. Reconnecting delegates and datasource by code, by storyboard 3. I thought maybe something was wrong in my datasource method and i rewrote it 5 times 4. I tried to put my setDelegatesAndDatasource method in the viewDidAppear too, thinking it was a problem of view life cycle
I can't understand what's going on. Thanks for your help.
'''
...ANSWER
Answered 2020-Mar-01 at 17:48The prepareForSegue
code reveals the mistake:
You are setting echo
in prepareForSegue
. This causes to call the property observer didSet
. However at this moment the view is not loaded yet and force unwrapping the type crashes.
The solution is to move the code in didSet
into viewDidLoad
and viewWillAppear
and delete the property observer. Nevertheless I recommend to optional bind window
QUESTION
I want to implement drag and drop with NSOutlineView similar Mac Finder application. With my current implementation, drag and drop session validates drop to children of each parent. I don't want that. I only want to drop child from one parent to another parent. like moving file from one folder to another folder in Finder. How to do that? below is a sample code with my drag and drop code included.
...ANSWER
Answered 2020-Feb-20 at 22:55Here you go:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install OutlineView
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page