Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new 10.6 delegate methods to NSBrowserDelegate #281

Merged
merged 17 commits into from
Aug 19, 2024
Merged

Conversation

gcasa
Copy link
Member

@gcasa gcasa commented Jul 19, 2024

The purpose of this branch is to add the NSBrowserDelegate methods defined in the documentation for macOS 10.6+ here...

https://developer.apple.com/documentation/appkit/nsbrowserdelegate/1407572-browser?language=objc

The test for this branch is here...

https://github.com/gcasa/NSBrowser_test

@gcasa gcasa marked this pull request as ready for review July 25, 2024 12:23
@gcasa gcasa requested a review from fredkiefer as a code owner July 25, 2024 12:23
@gcasa
Copy link
Member Author

gcasa commented Jul 25, 2024

Here is the browser with an item-based delegate on mac...
browser_106_delegate_macos

Here is the browser with an item-based delegate on gnustep...
broser_106_delegate_gs

And, of course, here is Gorm to demonstrate that the previous implementation still works...
gorm_browser

@gcasa
Copy link
Member Author

gcasa commented Jul 25, 2024

I am going to do some cleanup, also there are some trivial changes needed to support loading an NSViewController if one is necessary for the title view, etc.

@gcasa
Copy link
Member Author

gcasa commented Jul 25, 2024

I believe that support for the following delegate methods should be left for a separate PR:

- (BOOL) browser: (NSBrowser *)browser
  shouldEditItem: (id)item;
- (id) browser: (NSBrowser *)browser
       setObjectValue: (id)object
       forItem: (id)item;
- (NSViewController *) browser: (NSBrowser *)browser
                       previewViewControllerForLeafItem: (id)item;
- (NSViewController *) browser: (NSBrowser *)browser
                       headerViewControllerForItem: (id)item;
- (void) browser: (NSBrowser *)browser
         didChangeLastColumn: (NSInteger)oldLastColumn
        toColumn: (NSInteger)column;

As they might require significant changes to how NSBrowser is implemented. I am researching this now to see if it's possible in the current implementation.

@gcasa
Copy link
Member Author

gcasa commented Jul 26, 2024

The code to call the delegate method

- (NSViewController *) browser: (NSBrowser *)browser
                       headerViewControllerForItem: (id)item;

has been implemented. The rest will have to wait for a separate PR as the ones involved in editing will require a more substantial change. The other two are not strictly necessary as GS doesn't currently support column re-arrangement in NSBrowser and the leaf preview is optional.

@gcasa
Copy link
Member Author

gcasa commented Jul 26, 2024

@fredkiefer Please review when possible. GC

@gcasa gcasa requested a review from rfm July 26, 2024 22:40
Copy link
Member

@fredkiefer fredkiefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this code will work in the most common case. I am unsure whether it is overall the correct solution. It might well be that I am missing some concept here.

Headers/AppKit/NSBrowser.h Show resolved Hide resolved
Source/NSBrowser.m Show resolved Hide resolved
Source/NSBrowser.m Show resolved Hide resolved
Source/NSBrowser.m Outdated Show resolved Hide resolved
if (matrix != nil)
{
NSArray *selectedCells = [matrix selectedCells];
if (selectedCells != nil && [selectedCells count] > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole logic of this method seems strange to me. What is your intention here?
This will work for some very common cases, for example when a new column needs to be loaded because we double click on an item in the column before. But I am not sure that every time we need to load a new column there is always exactly one item selected in the previous column.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to find the item that needs to be loaded for a given column. When multiple items are selected it will show nothing on macOS. I will make changes to make this code behave similarly. See below this screenshot from macOS:

multiple_selection_macos

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation does not match the description you give above. For multiple selections the first gets used.

Source/NSBrowser.m Show resolved Hide resolved
@gcasa
Copy link
Member Author

gcasa commented Jul 27, 2024

Multiple selection works just as on macOS:
multiple_selection_browser_gs
For comparison:
multiple_selection_macos

@gcasa
Copy link
Member Author

gcasa commented Jul 31, 2024

I think that this code will work in the most common case. I am unsure whether it is overall the correct solution. It might well be that I am missing some concept here.

I am actually unsure how it's not the correct solution.

@gcasa
Copy link
Member Author

gcasa commented Jul 31, 2024

Also...

  1. what is the complex case here?
  2. even if it does only handle the "simple case" it is infinitely better to be able to do that than to handle NONE of them that use this type of delegate.

@gcasa
Copy link
Member Author

gcasa commented Aug 4, 2024

I am going to enhance the test to see if I can address any of the other possible use-cases.

@gcasa
Copy link
Member Author

gcasa commented Aug 4, 2024

@fredkiefer I have added extra data to the test. I believe that the changes I have made should cover most, if not all cases. Please take a look.

@gcasa
Copy link
Member Author

gcasa commented Aug 8, 2024

@fredkiefer Are there any additional changes you feel are necessary here?

@gcasa
Copy link
Member Author

gcasa commented Aug 18, 2024

@fredkiefer The behavior here matches that on macOS. Do you have any final review comments?

Copy link
Member

@fredkiefer fredkiefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fix these minor issues and then the code should be ready for a merge.

Headers/AppKit/NSBrowser.h Outdated Show resolved Hide resolved
if (matrix != nil)
{
NSArray *selectedCells = [matrix selectedCells];
if (selectedCells != nil && [selectedCells count] > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation does not match the description you give above. For multiple selections the first gets used.

@gcasa
Copy link
Member Author

gcasa commented Aug 18, 2024

As you can see from the above it does seem to function properly. The _itemForColumn: method gets the list for the current column based on the previous column's selection. So given this, I believe it is okay to merge. I am going to do that.

@gcasa gcasa merged commit 97ea7c5 into master Aug 19, 2024
4 checks passed
@gcasa gcasa deleted the NSBrowser_branch branch August 19, 2024 01:08
@fredkiefer
Copy link
Member

As you can see from the above it does seem to function properly. The _itemForColumn: method gets the list for the current column based on the previous column's selection. So given this, I believe it is okay to merge. I am going to do that.

In the discussion before this one, which you marked as resolved you wrote:

The idea is to find the item that needs to be loaded for a given column. When multiple items are selected it will show nothing on macOS. I will make changes to make this code behave similarly.

I don't see in the code how the case of multiple selection gets handled in this way. This is a minor issue, so merging was fine, still it would have been nice to get a real answer to this question.

@gcasa
Copy link
Member Author

gcasa commented Aug 19, 2024

As you can see from the above it does seem to function properly. The _itemForColumn: method gets the list for the current column based on the previous column's selection. So given this, I believe it is okay to merge. I am going to do that.

In the discussion before this one, which you marked as resolved you wrote:

The idea is to find the item that needs to be loaded for a given column. When multiple items are selected it will show nothing on macOS. I will make changes to make this code behave similarly.

I don't see in the code how the case of multiple selection gets handled in this way. This is a minor issue, so merging was fine, still it would have been nice to get a real answer to this question.

I apologize. If you run the test and select two things in a column the column next to it shows nothing. This is the correct behavior. I will take a look and provide a better explanation of this. I am not in front of my computer right now.

-browser:selectRow:inColumn: [NSMatrix-selectCellAtRow:column:]</p>
*/
- (void) selectRow: (NSInteger)row inColumn: (NSInteger)column
- (void) selectRow: (NSInteger)row inColumn: (NSInteger)column
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fredkiefer I believe this is the method where a multiple selection causes the last column to be unloaded. The method you commented on earlier is responsible for getting the selection of the previous column so that the current column knows what to display (based on the children it retrieves).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants