Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-06 Thread Corbin Dunn
Mario,

On Oct 5, 2009, at 4:44 PM, Mario Kušnjer wrote:

 Hello to the list !
 
 Request for help regarding a little problem.
 So I have this piece of code:
 
 - (IBAction)addNewItem:(id)sender
 {
   if ([lsOutlineView selectedRow]  0)
   {
   [sourceListLevelZero addObject:[Parent new]];
   [lsOutlineView reloadItem:nil reloadChildren:YES];
   [lsOutlineView expandItem:nil expandChildren:YES];
   [lsOutlineView selectRowIndexes:[NSIndexSet 
 indexSetWithIndex:[lsOutlineView rowForItem:[Parent new]]] 
 byExtendingSelection:NO];
   }
   ...
 }

In addition to what others said, your main misunderstanding is two things:

1. The outlineview identifies unique objects by the pointer address, not 
isEqual. Thus this line creates a new Parent object:

   [sourceListLevelZero addObject:[Parent new]];

and this line creates a new (different) Parent object:

 [lsOutlineView rowForItem:[Parent new]]]

2. I highly recommend reading up on memory management in Cocoa (unless you are 
creating a GC application). The [Parent new] lines are leaking memory. new is a 
shortcut for 'alloc/init' and returns a retained object.

corbin___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-06 Thread Mario Kušnjer

Hi all !

Thanks for your replies everybody !
I have reviewed my code according to yours inputs and I found where  
the problem was.

Here's the reviewed code:

if ([lsOutlineView selectedRow]  0)
{
Parent *parent = [Parent new];  --- create new Parent 
object
NSLog(@1 - %@, parent);

		[sourceListLevelZero addObject:parent];		---	add newly created  
Parent object to the root array
		[lsOutlineView reloadItem:nil reloadChildren:YES];		---	reload  
outline view


		NSUInteger index = [lsOutlineView rowForItem:parent];		---	get the  
row index of the newly created Parent object from the outline view

NSLog(@2 - %i, index);

		NSMutableIndexSet *indexSet = [NSMutableIndexSet new];		---	create  
new empty NSMutableIndexSet object

NSLog(@3 - %@, indexSet);

		[indexSet addIndex:index];		---	add row index of the Parent object  
to the indexSet

NSLog(@4 - %@, indexSet);

		[lsOutlineView expandItem:nil expandChildren:YES];		---	expand the  
root array objects and all of their children
		[lsOutlineView selectRowIndexes:indexSet byExtendingSelection:NO];		 
---	select row with index number from the indexSet without multiple  
row selection


[parent release];   --- release parent object
[indexSet release]; --- release indexSet
}

I assume this is correct way now because it works fine.
If someone has some objections, please state your comment, I am  
interested to hear (learn).


I will (when I make this code actually do something useful) post a  
link to the list for the entire source code so anyone interested to  
review it (and point out my mistakes) will

be most welcome.
Since I have no idea how to use Instruments (and until I do) this will  
be very helpful to me in future learning.


Thanks again.
Bye !


Mario Kušnjer
mario.kusn...@sb.t-com.hr
+385957051982
mariokusn...@skype

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-06 Thread Mario Kušnjer

Again me !
Just a little update !
I packed previous code in combined message calls.
Here's how it looks now:

if ([lsOutlineView selectedRow]  0)
{
Parent *parent = [Parent new];  --- create new Parent 
object
		[sourceListLevelZero addObject:parent];		---	add newly created  
Parent object to root array

[lsOutlineView reloadItem:nil reloadChildren:YES];
[lsOutlineView expandItem:nil expandChildren:YES];  
		[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[lsOutlineView rowForItem:parent]] byExtendingSelection:NO];		---	 
select row according to index from indexSet created with row index of  
outline view for item - parent

[parent release];   --- release Parent object
}

Again this works fine.
Ok, that's it.
Bye !


Mario Kušnjer
mario.kusn...@sb.t-com.hr
+385957051982
mariokusn...@skype

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSOutlineView - Automatically select newly added item - Help needed

2009-10-05 Thread Mario Kušnjer

Hello to the list !

Request for help regarding a little problem.
So I have this piece of code:

- (IBAction)addNewItem:(id)sender
{
if ([lsOutlineView selectedRow]  0)
{
[sourceListLevelZero addObject:[Parent new]];
[lsOutlineView reloadItem:nil reloadChildren:YES];
[lsOutlineView expandItem:nil expandChildren:YES];
		[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[lsOutlineView rowForItem:[Parent new]]] byExtendingSelection:NO];

}
...
}

It is the last line that trouble's me.
It should select newly added item in the list (right ?), but it does  
not !

Or am I doing something wrong (very likely !) ?

Ok, so you got it by now that I am trying to get the behavior that  
when user clicks add button new item that appears in the list  
automatically gets selected.


Thanks for help
Bye

Mario Kušnjer
mario.kusn...@sb.t-com.hr
+385957051982
mariokusn...@skype

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-05 Thread Stamenkovic Florijan


On Oct 05, 2009, at 19:44, Mario Kušnjer wrote:


Hello to the list !

Request for help regarding a little problem.
So I have this piece of code:

- (IBAction)addNewItem:(id)sender
{
if ([lsOutlineView selectedRow]  0)
{
[sourceListLevelZero addObject:[Parent new]];
[lsOutlineView reloadItem:nil reloadChildren:YES];
[lsOutlineView expandItem:nil expandChildren:YES];


Can't comment on this part as I am not exactly sure what you are  
doing. However note that in the first line of the block above you are  
most probably retaining an object twice. This is not a leak if you  
insist on garbage collection, but otherwise it is.


		[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[lsOutlineView rowForItem:[Parent new]]] byExtendingSelection:NO];


Well, assuming that you wanted to select the Parent item you added to  
the sourceListLevelZero, you should query the outline for the row  
index of *that* item, and not of a new Parent. Besides that to me the  
line makes sense...


HTH,
F


}
...
}

It is the last line that trouble's me.
It should select newly added item in the list (right ?), but it does  
not !

Or am I doing something wrong (very likely !) ?

Ok, so you got it by now that I am trying to get the behavior that  
when user clicks add button new item that appears in the list  
automatically gets selected.


Thanks for help
Bye


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-05 Thread Colin Howarth

On 6 Oct, 2009, at 01:44, Mario Kušnjer wrote:
...

		[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[lsOutlineView rowForItem:[Parent new]]] byExtendingSelection:NO];



It is the last line that trouble's me.
It should select newly added item in the list (right ?), but it does  
not !


without trying to understand what's happening, or supposed to, you  
could also (in cases like this) try TEMPORARILY unravelling your  
method calls. Like this:


Parent *parent = [Parent new];

int index = [lsOutlineView rowForItem: parent];

NSArray *indices = [NSIndexSet indexSetWithIndex: index];

[IsOutlineView selectRowIndexes: indices byExtendingSelection:NO];


 where I don't know what the actual classes are 


Then you can check these intermediate steps, to see they're doing what  
you think they should.


Then you can wrap it all up again once you've fixed it, to save screen  
space :-)


--colin___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-05 Thread Graham Cox


On 06/10/2009, at 10:44 AM, Mario Kušnjer wrote:


[sourceListLevelZero addObject:[Parent new]];


		[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[lsOutlineView rowForItem:[Parent new]]] byExtendingSelection:NO];



Assuming -addObject: in the first line adds the object to the end of  
the array, just do this:



[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[sourceListLevelZero count] - 1] byExtendingSelection:NO];



This generalises to any position - just find the index of the object  
you just added.


--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSOutlineView - Automatically select newly added item - Help needed

2009-10-05 Thread Charles Srstka

On Oct 5, 2009, at 7:49 PM, Colin Howarth wrote:


On 6 Oct, 2009, at 01:44, Mario Kušnjer wrote:
...

		[lsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex: 
[lsOutlineView rowForItem:[Parent new]]] byExtendingSelection:NO];



It is the last line that trouble's me.
It should select newly added item in the list (right ?), but it  
does not !


without trying to understand what's happening, or supposed to, you  
could also (in cases like this) try TEMPORARILY unravelling your  
method calls. Like this:


Parent *parent = [Parent new];

int index = [lsOutlineView rowForItem: parent];

NSArray *indices = [NSIndexSet indexSetWithIndex: index];

[IsOutlineView selectRowIndexes: indices byExtendingSelection:NO];


 where I don't know what the actual classes are 


Then you can check these intermediate steps, to see they're doing  
what you think they should.


Then you can wrap it all up again once you've fixed it, to save  
screen space :-)


Note that if your NSOutlineView is using an NSTreeController rather  
than a custom data source, rowForItem: still won't work.


Charles___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com