cappuccino / cappuccino

Web Application Framework in JavaScript and Objective-J
https://cappuccino.dev/
GNU Lesser General Public License v2.1
2.21k stars 333 forks source link

CPTableView formatting and fixes [+1] #1892

Closed cacaodev closed 9 years ago

cacaodev commented 11 years ago

There might be a "breaking change" here, in commit be7f6ae. I didn't mention it in the commit message because i wanted your input first. Previously, -reloadData was reloading everything: the views, the data and performing various tasks needed to setup the view. Now it just fetches the data from the model and applies it to the view. Except when the number of rows changed: in this case we reload the views like we did before meaning that when calling -reloadData from the controller after a row insertion/removal, there should be no change. To be sure nothing breaks, i would like to know how you use -reloadData in your controllers and if you need the views to be reloaded even when the number of rows in the content did not change.

There is one situation I can think of where reloading the views might be useful but i don't think anyone ever tested it. It's when using view-based tables with the delegate for creating views. You may want to initiate a remote request to fetch some data (lazy loading) and then create a view in the delegate based on the content. In this case, you need to tell the table to reload one or more specific views when the data is received. If we do this, we will need a new implementation, not the previous reloadData (renamed _reloadDataViews here) . This method was not fetching the views from the delegate, instead, we were just enqueuing the views in the cache and redistributing them with new values and new frames, which is not enough.

cappbot commented 11 years ago

Milestone: Someday. Label: #new. What's next? A reviewer should examine this issue.

ahankinson commented 11 years ago

Looks like it fails the unit testing. Could you have a look at the Travis error and either verify the test, or fix the commit?

The Travis error is:

CPTableViewTest..
addFailure test=[CPTableViewTest testNumberOfRowsChangedSelectionNotification]: didChange notifications when selected rows disappear expected:<2> but was:<1>
Trace not implemented
.
addError test=[CPTableViewTest testEditCell]: Cannot read property "37802" from undefined
    at script(/home/travis/build/cappuccino/cappuccino/narwhal/packages/narwhal-lib/lib/narwhal/sandbox.js:118)
    at script(/home/travis/build/cappuccino/cappuccino/narwhal/packages/narwhal-lib/lib/narwhal/sandbox.js:241)
    at script.narwhal(/home/travis/build/cappuccino/cappuccino/narwhal/narwhal.js:290)
...

-#new +feature +AppKit +#needs-improvement

cappbot commented 11 years ago

Milestone: Someday. Labels: #needs-improvement, AppKit, feature. What's next? The code for this issue has problems with formatting or fails a capp_lint check, has bugs, or has non-optimal logic or algorithms. It should be improved upon.

ahankinson commented 11 years ago

-#needs-improvement +#accepted +#ready-to-commit

cappbot commented 11 years ago

Milestone: Someday. Labels: #accepted, #ready-to-commit, AppKit, feature. What's next? The changes for this issue are ready to be committed by a member of the core team.

aljungberg commented 11 years ago

This looks great. Any chance I could prevail on you to merge in the latest master (or rebase) so we can get a clean commit?

assignee=aljungberg milestone=0.9.7

cappbot commented 11 years ago

Assignee: aljungberg. Milestone: 0.9.7. Labels: #accepted, #ready-to-commit, AppKit, feature. What's next? The changes for this issue are ready to be committed by aljungberg.

aljungberg commented 10 years ago

-#ready-to-commit

cappbot commented 10 years ago

Assignee: aljungberg. Milestone: 0.9.7. Labels: #accepted, AppKit, feature. What's next? A reviewer should examine this issue.

cappbot commented 10 years ago

Assignee: aljungberg. Milestone: 0.9.8. Labels: #accepted, AppKit, feature. What's next? A reviewer should examine this issue.

cappbot commented 10 years ago

Assignee: aljungberg. Milestone: 0.9.9. Labels: #accepted, AppKit, feature. What's next? A reviewer should examine this issue.

cacaodev commented 10 years ago

This branch is no longer mergeable, mainly because of master changes in CPTableColumnHeader class

I will open individual issues for the fixes that have no dependencies.

cacaodev commented 10 years ago

It's mergeable after all. What's left :

Dogild commented 9 years ago

Any news for this PR ?

cacaodev commented 9 years ago

I am not near my machine currently so I can't check it again with recent master changes. Last news was: everything works except removeTableColumn: hard error located in the -load method and related to the run loop (cf ojunit and manual test) I could use some help here because I am i bit a court d'idees.

Dogild commented 9 years ago

I'll take a look this week ;)

Dogild commented 9 years ago

In this part of the code :

- (void)removeTableColumn:(CPTableColumn)aTableColumn
{
    if ([aTableColumn tableView] !== self)
        return;

    var index = [_tableColumns indexOfObjectIdenticalTo:aTableColumn];

    if (index === CPNotFound)
        return;

    // we defer the actual removal until the end of the runloop in order to keep a reference to the column.
    [_differedColumnDataToRemove addObject:{"column":aTableColumn, "shouldBeHidden": [aTableColumn isHidden]}];

    [aTableColumn setHidden:YES];
    [aTableColumn setTableView:nil];

    var tableColumnUID = [aTableColumn UID];

    if (_objectValues[tableColumnUID])
        _objectValues[tableColumnUID] = nil;

    if (_dirtyTableColumnRangeIndex < 0)
        _dirtyTableColumnRangeIndex = index;
    else
        _dirtyTableColumnRangeIndex = MIN(index, _dirtyTableColumnRangeIndex);

    [_tableColumns removeObject:aTableColumn];
    [self _reloadDataViewsImmediately];
}

We call [_tableColumns removeObject:aTableColumn];. We should call this method at this end of the method - (void)load, otherwise the indexes of the array of tableColum is totally messed up when unloading and reloading the dataViews.

I would suggest to do that here (load method) :

if (removeCount)
    {
        var removeIndexes = [CPIndexSet indexSet];

        for (var i = 0; i < removeCount; i++)
        {
            var data = _differedColumnDataToRemove[i],
                tableColumn = data.column,
                columnIdx = [_tableColumns indexOfObject:tableColumn];

            if (columnIdx !== CPNotFound)
                [removeIndexes addIndex:columnIdx];
        }

        // FIXME: do we also need to remove non exposed rows that may stay in the cache ?
        [self _unloadDataViewsInRows:_exposedRows columns:removeIndexes];

        // Here we can loop on the removeIndexes and call the method - (void)removeTableColumn:(CPTableColumn)aTableColumn

        [_differedColumnDataToRemove removeAllObjects];
    }

What do you think ?

cacaodev commented 9 years ago

Hi Dogild, thanks for this, i will take a look asap.

cacaodev commented 9 years ago

This PR is almost done, finally. Thanks doglid for your help. -removeTableColumn now works like before.

What's left in my opinion:

Dogild commented 9 years ago

Sounds good, the tests pass again ! Let me know when you think it's ready so I can try it on our app ;)

cacaodev commented 9 years ago

For me it's ready, at least to be reviewed. The only thing i'd like to improve is the last item in my previous message: a user call to -reloadData should recreate the views (currently they are mixed). This could be useful in a situation where views are dynamically created based on a criteria and this criteria changes, for example a table with remote data.

It's not a regression so imo we can do this later.

Dogild commented 9 years ago

I tried it on our application, I didn't have any bugs yet.

Dogild commented 9 years ago

Any chance to have the feature to have selectable CPTextField (non-editable) in a cell-based CPTableView when selecting a row is not allowed (like in iMessage, to copy and past messages) ?

Dogild commented 9 years ago

My bad, it works as in cocoa already !

Dogild commented 9 years ago

Well actually not really, you have to select the row and then you can select the text

Dogild commented 9 years ago

Fixed here : https://github.com/cappuccino/cappuccino/pull/2231

daboe01 commented 9 years ago

+#ready-to-commit

cappbot commented 9 years ago

Assignee: aljungberg. Milestone: 0.9.9. Labels: #accepted, #ready-to-commit, AppKit, feature. What's next? The changes for this issue are ready to be committed by aljungberg.

primalmotion commented 9 years ago

I think we need to get done with this one once for all.

@cacaodev can you make it mergeable, and ping me once ok, so I can merge it in? Thanks

cacaodev commented 9 years ago

I'll merge this but first I need to know @Dogild what behavior you expect with #2231 : 1- Select the row AND edit the text 2- Just edit the text (make the textfield FR) without selecting the row (selectedRow unchanged).

Dogild commented 9 years ago

@cacaodev In cocoa, when you set the selectionStyle to CPTableViewSelectionHighlightStyleNone you can still focus elements in a row.

Normally, to focus a CPTextField, there are two steps, the first one is to select the row (it becomes blue) and then you can focus a CPTextField. With the style set to None, you will focus the CPTextField (or another CPView) after the firstClick.

cacaodev commented 9 years ago

@Dogild OK but what I want to know is that if you want the row to be the selectedRow in the TableView when the text field if focused (even if it is not visually selected of course) or not.

Dogild commented 9 years ago

I don't know how cocoa reacts with this situation. We need to try...I guess it updates the selectedRow.

primalmotion commented 9 years ago

@cacaodev can we get rid of this one once for all :)

Can you make it mergeable and then tell me? I'll merge it right away

Thanks

+#needs-improvement -#ready-to-commit

cappbot commented 9 years ago

Assignee: aljungberg. Milestone: 0.9.9. Labels: #accepted, #needs-improvement, AppKit, feature. What's next? The code for this issue has problems with formatting or fails a capp_lint check, has bugs, or has non-optimal logic or algorithms. It should be improved upon.

daboe01 commented 9 years ago

hi @cacaodev, i need this one badly ;-) +1

cappbot commented 9 years ago

Assignee: aljungberg. Milestone: 0.9.9. Vote: 1. Labels: #accepted, #needs-improvement, AppKit, feature. What's next? The code for this issue has problems with formatting or fails a capp_lint check, has bugs, or has non-optimal logic or algorithms. It should be improved upon.

cacaodev commented 9 years ago

@primalmotion @daboe01 : hey guys, sorry for the delay but I don't have much time currently to work on this. I'll have a look when I can. If someone want to finish the work, you can merge it, fix the conflicts, and then fix issues with highlighting. From what i remember, in some situations the highlighted state was not correctly set on the main cell view or subviews.

cacaodev commented 9 years ago

@Dogild : can you re-apply e56cc85e963a (i'm not sure what to check) and then i think that's it.

Dogild commented 9 years ago

Let me try that asap ;)

primalmotion commented 9 years ago

@cacaodev awesome

@Dogild I have no doubt you'll tell me when you 're done :)

Dogild commented 9 years ago

@primalmotion I'm kinda in a middle of a huge big thing ... :p

Dogild commented 9 years ago

@primalmotion @cacaodev Archipel and Nuage works and not crash with this PR. @cacaodev #e56cc85 is still good in the PR

primalmotion commented 9 years ago

@cacaodev can you sum up what this PR actually does? Thanks!

Antoine Mercadal

On Jan 29, 2015, at 13:09, Alexandre Wilhelm notifications@github.com wrote:

@primalmotion @cacaodev Archipel and Nuage works and not crash with this PR. @cacaodev #e56cc85 is still good in the PR

— Reply to this email directly or view it on GitHub.

cacaodev commented 9 years ago

@primalmotion New features are: new methods -enumerateAvailableViewsUsingblock: and -preparedViewAtColumn:row: Then there are a lot of bug fixes related to column d&d, minor fixes for content bindings and setDataView: Internally, the code is rearranged and simplified thanks to the new view enumeration order (row -> column) and editing for both view-based and cell-based is now unified.

primalmotion commented 9 years ago

finally merged!

Thanks!

+#fixed

cappbot commented 9 years ago

Assignee: aljungberg. Milestone: 0.9.9. Vote: 1. Labels: #fixed, AppKit, feature. What's next? This issue is considered successfully resolved.

cacaodev commented 9 years ago

There is a style issue with this commit. A lot of brackets are not correctly aligned. It may be because of a setting in my merging tool. Sorry for that. I believe the only solution is to manually fix this (capp_lint does not detect that). I'll do it.