Editing in a tableview without selecting

2009-11-01 Thread Ben Haller
  Hi all.  I've got an NSTableView that I'd like to be editable.   
Even if I return YES from -tableView:shouldSelectRow: and YES from  
tableView:shouldEditTableColumn:row:, however, editing does not  
actually commence.  The row selects, and I've confirmed with logs that  
both delegate methods are indeed getting called; the tableView seems  
to just decide not to start editing after all.  No other console logs  
appear, so it's not a raise.  Simply not implementing the two delegate  
methods mentioned above does not make any difference.  The object  
value for cell that should enter editing is an NSString, and its cell  
is an NSTextFieldCell.  Is there some additional step I have to take  
to make editing actually commence?


  The tableview is set up in code.  What appear to be custom  
subclasses in this code are all #defined back to their superclasses,  
and all of the code for these classes if #if 0'ed out, so this code is  
really using only the Cocoa classes:


#define AKVariableStoreTableView NSTableView
#define AKTextFieldCell NSTextFieldCell
#define AKSwatchCell NSTextFieldCell
#define AKDividerCell NSTextFieldCell

+ (NSTableColumn *)columnObjectForIdentifier:(NSString *)identifier
{
	NSTableColumn *column = [[NSTableColumn alloc]  
initWithIdentifier:identifier];


if (identifier == nameColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] 
initTextCell:@""];

[column setMinWidth:AKNameColumnWidth];
[column setMaxWidth:AKNameColumnWidth];

		[cell setFont:[NSFont  
antikytheraFontOfSize:AK_VARIABLE_STORE_VARIABLE_FONT_SIZE]];


[column setDataCell:cell];
}
else if (identifier == equalsColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] 
initTextCell:@""];

[column setMinWidth:AKEqualsColumnWidth];
[column setMaxWidth:AKEqualsColumnWidth];

[cell setAlignment:NSCenterTextAlignment];
		[cell setFont:[NSFont  
antikytheraFontOfSize:AK_VARIABLE_STORE_VALUE_FONT_SIZE]];


[column setDataCell:cell];
}
else if (identifier == valueColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] 
initTextCell:@""];

[column setMinWidth:AKValueColumnWidth];
[column setMaxWidth:AKValueColumnWidth];

[cell setAlignment:NSRightTextAlignment];
		[cell setFont:[NSFont  
antikytheraFontOfSize:AK_VARIABLE_STORE_VALUE_FONT_SIZE]];


[column setDataCell:cell];
}
else if (identifier == swatchColumnID)
{
AKSwatchCell *cell = [[AKSwatchCell alloc] initImageCell:nil];

[column setMinWidth:AKSwatchColumnWidth];
[column setMaxWidth:AKSwatchColumnWidth];

[column setDataCell:cell];
}
else if (identifier == descriptionColumnID)
{
AKTextFieldCell *cell = [[AKTextFieldCell alloc] 
initTextCell:@""];

[column setMinWidth:AKDescriptionColumnWidth];
[column setMaxWidth:1000];

[cell setTextColor:[NSColor grayColor]];
[cell setAlignment:NSRightTextAlignment];
		[cell setFont:[NSFont  
antikytheraFontOfSize:AK_VARIABLE_STORE_DESCRIPTION_FONT_SIZE]];


[column setDataCell:cell];
}

return column;
}

#define AK_VARIABLE_STORE_INSET 15

- (NSTableView *)makeTableViewWithWidth:(int)width
{
if (!tableView)
{
		NSRect tableViewFrame = NSMakeRect(AK_VARIABLE_STORE_INSET,  
AK_VARIABLE_STORE_INSET, width, 100);


		tableView = [[AKVariableStoreTableView alloc]  
initWithFrame:tableViewFrame];


// Set up behavior
[tableView setAllowsColumnReordering:NO];
[tableView setAllowsColumnResizing:NO];
[tableView setAllowsColumnSelection:NO];
[tableView setAllowsEmptySelection:YES];
[tableView setAllowsMultipleSelection:NO];
[tableView setAllowsTypeSelect:NO];
[tableView setAllowsColumnReordering:NO];
[tableView setAutosaveTableColumns:NO];
		[tableView  
setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];

[tableView setAutosaveTableColumns:NO];

// Set up appearance
[tableView setBackgroundColor:[NSColor windowBackgroundColor]];
[tableView setGridStyleMask:NSTableViewGridNone];
[tableView setIntercellSpacing:NSMakeSize(0.0, 1.0)];
[tableView setRowHeight:18];
 

Re: Editing in a tableview without selecting

2009-11-01 Thread Ben Haller

On 1-Nov-09, at 12:42 PM, Ben Haller wrote:

 Hi all.  I've got an NSTableView that I'd like to be editable.   
Even if I return YES from -tableView:shouldSelectRow: and YES from  
tableView:shouldEditTableColumn:row:, however, editing does not  
actually commence.  The row selects, and I've confirmed with logs  
that both delegate methods are indeed getting called; the tableView  
seems to just decide not to start editing after all.  No other  
console logs appear, so it's not a raise.  Simply not implementing  
the two delegate methods mentioned above does not make any  
difference.  The object value for cell that should enter editing is  
an NSString, and its cell is an NSTextFieldCell.  Is there some  
additional step I have to take to make editing actually commence?


  The title of this thread is a bit wrong, sorry about that.  I was  
originally trying to figure out a way to allow editing without  
selecting, but when I realized I couldn't get editing to happen at  
all, in any case whatsoever, my focus shifted.  :->  I am letting the  
row get selected as normal, and it seems to be selected correctly, as  
my first message says.


Ben Haller
Stick Software

___

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: Asynchronous downloading again

2009-11-01 Thread Jens Alfke


On Oct 31, 2009, at 6:50 PM, DKJ wrote:

All of the files have to be downloaded before the app can do  
anything. I get the connectionDidFinishLoading delegate method of my  
one and only NSURLConnection to call a downloadFinished method at  
the end of the synchronous downloads, so the app knows everything is  
in place and can start processing the files.


All NSURLConnection delegate methods are called on the main thread.  
(Actually on the same thread from which you started the  
NSURLConnection.) This is true of pretty much everything in Cocoa: the  
only time any of your code runs on a different thread is when you  
explicitly request it, by using NSThread or NSOperationQueue (or the  
dispatcher API in 10.6.)


Don't go back to using synchronous connections. They will block the  
main thread, and there's no sense in using two different techniques to  
solve the same problem.


Your approach of starting each connection when the previous one  
finishes is fine. If all of these downloads are coming from the same  
server, and you can't do anything till they're all done, you're  
probably not going to gain anything by doing them in parallel: either  
way, the limiting factor will be the speed of the user's Internet  
connection.


—Jens___

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: Bold and Italic For Dictionary Font Attributes (Hillegass Chapter 20, Challenge 2)

2009-11-01 Thread Jens Alfke


On Oct 31, 2009, at 12:44 PM, Russell Finn wrote:


-- i.e. key, object, key, object; this is what I tried to correct this
in my post, as shown above.


Yeah, sorry about that; my mistake. (I'm so used to using my $dict,  
which puts the keys/values in the 'correct' order...)


—Jens

___

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


objectAtIndex

2009-11-01 Thread Nava Carmon

Hi,

When I ran Build and Analyze on my code, it has pointed as a possible  
leak the following statement:


NSObject *anObject = [anArray objectAtIndex:i];

anObject wasn't released and here's the question: whether anObject is  
a copy of actual object, that is a member of anArray or it's the  
object itself?


Should I release it?

Thanks,
Nava
___

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: objectAtIndex

2009-11-01 Thread Bryan Henry
That line alone does not indicate any memory leaks occurring due to  
over-retaining objects. You'll need to provide more context (the  
surrounding code, etc).


The object returned by -[NSArray objectAtIndex:] is the actual object  
(ie. pointer to the actual object's space in memory) stored in the  
array, not a copy. When you add objects to an array, as well, the  
object stored in the array is not a copy but the object itself.


- Bryan

On Nov 1, 2009, at 2:44:07 PM, Nava Carmon wrote:


Hi,

When I ran Build and Analyze on my code, it has pointed as a  
possible leak the following statement:


NSObject *anObject = [anArray objectAtIndex:i];

anObject wasn't released and here's the question: whether anObject  
is a copy of actual object, that is a member of anArray or it's the  
object itself?


Should I release it?

Thanks,
Nava
___

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/bryanhenry%40mac.com

This email sent to bryanhe...@mac.com


___

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: objectAtIndex

2009-11-01 Thread Sherm Pendley
On Sun, Nov 1, 2009 at 2:44 PM, Nava Carmon  wrote:
>
> NSObject *anObject = [anArray objectAtIndex:i];
...
> Should I release it?

No. You didn't create anObject with +alloc or a method beginning with
-copy, nor did you send it a -retain message. Therefore you do not own
it and must not release it.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
___

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


Does [NSNetService getInputStream:outputStream:] really return retain objects and where does it say that

2009-11-01 Thread Markus Spoettl

Hi,

  I'm puzzled by a comment in the WiTap iPhone SDK example project  
that I can't confirm through documentation or header comments. The  
method and comment is this (AppController.m line 214 onwards):


- (void) browserViewController:(BrowserViewController *)bvc  
didResolveInstance:(NSNetService *)netService

{
  if (!netService) {
[self setup];
return;
  }

// note the following method returns _inStream and _outStream with a  
retain count that the caller must eventually release
  if (![netService getInputStream:&_inStream  
outputStream:&_outStream]) {

[self _showAlert:@"Failed connecting to server"];
return;
  }

  [self openStreams];
}

Note the comment above "if (![netService getInputStream...".

The documentation doesn't back this assertion, neither does the header  
comment in NSNetServices.h. According to the memory management rules  
the method should return autoreleased streams.


Sure enough the author of the example project believes what he says  
because the project doesn't retain the streams anywhere. And  
surprisingly the project doesn't crash which if should at some point  
if the streams where auto-released - so they must be retained.


So, am I blind? I can't find where it says they are.

Looking a bit further the same kind of comment pops up in on other  
example too (Cocoa SimpleNetworkStream) where it also references a  
radar (rdar://problem/6868813), so this is known. Why not add a note  
to  getInputStream:outputStream: then?


Regards
Markus
--
__
Markus Spoettl



smime.p7s
Description: S/MIME cryptographic signature
___

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: Editing in a tableview without selecting

2009-11-01 Thread Scott
 I'm new to Obj-c / Cocoa but this was helpful in figuring out editable
 table views I was trying to create with IB. Maybe it can help you in
 your case.

 http://www.idevgames.com/forum/showpost.php?p=94784&postcount=3

 I know I wasn't putting a dictionary object into an array with the
 same identifier that I had created in IB. So I could "edit" my data in
 my tableview but as soon as I was done editing it never updated my
 array so it my data never changed.
___

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: Editing in a tableview without selecting

2009-11-01 Thread Ben Haller

On 1-Nov-09, at 4:22 PM, Scott Waters wrote:


I'm new to Obj-c / Cocoa but this was helpful in figuring out editable
table views I was trying to create with IB. Maybe it can help you in
your case.

http://www.idevgames.com/forum/showpost.php?p=94784&postcount=3

I know I wasn't putting a dictionary object into an array with the
same identifier that I had created in IB. So I could "edit" my data in
my tableview but as soon as I was done editing it never updated my
array so it my data never changed.


  Thanks for the reference, but the problem I'm seeing is that  
editing doesn't even begin on my tableview.  I double-click on a cell,  
and nothing whatsoever happens.


Ben Haller
Stick Software

___

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: Editing in a tableview without selecting

2009-11-01 Thread Graham Cox


On 02/11/2009, at 4:42 AM, Ben Haller wrote:

But where?  I've been hunting for a -setEditable:YES method  
somewhere that I need to call, but I haven't found it...



Hi Ben,

Have you tried -setEditable:YES on the textfield cell you're using for  
the table column? (Inherited from NSCell). I'm not sure what its  
default state is, documentation doesn't say.


--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: Does [NSNetService getInputStream:outputStream:] really return retain objects and where does it say that

2009-11-01 Thread Jens Alfke


On Nov 1, 2009, at 1:30 PM, Markus Spoettl wrote:

The documentation doesn't back this assertion, neither does the  
header comment in NSNetServices.h. According to the memory  
management rules the method should return autoreleased streams.


Yes; but that doesn't necessarily mean the streams will go away soon  
if you don't retain them. An NSStream object is usually scheduled on a  
runloop, which keeps a reference to it as long as its open, so I  
believe it will stay around even if not explicitly retained by the app.


Sure enough the author of the example project believes what he says  
because the project doesn't retain the streams anywhere.


Does it release the streams? That would be the true test. My belief is  
that it can get away without retaining them, as long as it never  
accesses them again after they close; but if it explicitly releases  
them, it would crash.


That said, I think it's safer to keep your own references to the  
stream objects by retaining and releasing them.


—Jens

___

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


Commandline Tool Help - NSDistantObject and NSConnection

2009-11-01 Thread aaron smith
hey Folks, quick question.

I'm building an app that I'm providing a command line tool for. I have it
hooked up and working. However the strange thing is that it works the first
time it's run, but then just throws exceptions.

I'm using a proxy object, which is exposed through NSConnection, and through
NSDistantObject it exposes one method to open a document at a path.

The application is using the document architecture, and I subclass
NSDocumentController. The cliproxy is setup in the document controller code
because it's initialized only once.

here's some code:

The commandline tool code:
http://pastebin.com/m6c1bb952

Here's the proxy code
h: http://pastebin.com/me651e88
m: http://pastebin.com/m57e4ab4e

The (simplified) doc controller:
http://pastebin.com/m6adf5d96

So what's strange is that it works fine on the first time I run the command
line tool; it opens the app, and opens a document as expected. But if the
cocoa application is already running - i'm seeing different behavior.

here's a quick sequence::

*first run*
$ ./build/Debug/gity
2009-11-01 16:01:33.895 gity[10625:903] proxy: 
2009-11-01 16:01:33.898 gity[10625:903] proxy: 
2009-11-01 16:01:33.899 gity[10625:903] doc: 

*second run (app is running)*
$ ./build/Debug/gity
2009-11-01 16:01:54.777 gity[10807:903] proxy: 
2009-11-01 16:01:54.780 gity[10807:903] doc: 
2009-11-01 16:01:54.784 gity[10807:903] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '[NOTE: this exception
originated in the server.]
*** -[NSDistantObject methodSignatureForSelector:]: remote object does not
recognize selector: 'isEqual:''
*** Call stack at first throw:
(
0   CoreFoundation  0x7fff854245a4
__exceptionPreprocess + 180
1   libobjc.A.dylib 0x7fff80d31313
objc_exception_throw + 45
2   Foundation  0x7fff83b21277 -[NSConnection
sendInvocation:internal:] + 4304
3   CoreFoundation  0x7fff853f737c ___forwarding___
+ 860
4   CoreFoundation  0x7fff853f3458
_CF_forwarding_prep_0 + 232
5   gity0x00011740 main + 471
6   gity0x0001134c start + 52
7   ??? 0x0001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Abort trap

*third run (app is running, but no windows are open)*
$ ./build/Debug/gity
2009-11-01 16:02:24.232 gity[10904:903] proxy: 
2009-11-01 16:02:24.235 gity[10904:903] doc: 
2009-11-01 16:02:24.315 gity[10904:903] *** Terminating app due to uncaught
exception 'NSObjectInaccessibleException', reason: '[NOTE: this exception
originated in the server.]
NSDistantObject (0x101e2e030) is invalid (no connection)'
*** Call stack at first throw:
(
0   CoreFoundation  0x7fff854245a4
__exceptionPreprocess + 180
1   libobjc.A.dylib 0x7fff80d31313
objc_exception_throw + 45
2   Foundation  0x7fff83b21277 -[NSConnection
sendInvocation:internal:] + 4304
3   CoreFoundation  0x7fff853f737c ___forwarding___
+ 860
4   CoreFoundation  0x7fff853f3458
_CF_forwarding_prep_0 + 232
5   gity0x00011740 main + 471
6   gity0x0001134c start + 52
7   ??? 0x0001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Abort trap


So there are a couple things that I'm unsure of here. One of the errors is
complaining that the distant object doesn't respond to isEqual. and another
error is saying that the object is inaccessible, but the NSLog's above it
clearly log out an object..

any help is appreciated.
___

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: Does [NSNetService getInputStream:outputStream:] really return retain objects and where does it say that

2009-11-01 Thread Markus Spoettl

On Nov 2, 2009, at 12:51 AM, Jens Alfke wrote:
Yes; but that doesn't necessarily mean the streams will go away soon  
if you don't retain them. An NSStream object is usually scheduled on  
a runloop, which keeps a reference to it as long as its open, so I  
believe it will stay around even if not explicitly retained by the  
app.


True. I did one additional test in that I delayed opening the streams  
by 5 seconds (using performSelector:withObject:afterDelay:), giving  
the run loop enough time to release them if they were in fact auto- 
released (I know there's no guarantee they would actually be release  
in that period of time). The app doesn't crash and keeps working which  
indicates they are retained.


Sure enough the author of the example project believes what he says  
because the project doesn't retain the streams anywhere.


Does it release the streams? That would be the true test. My belief  
is that it can get away without retaining them, as long as it never  
accesses them again after they close; but if it explicitly releases  
them, it would crash.


Yes, the example releases the streams. They're removed from the run  
loop first, the author apparently forgot to close them though (not  
sure if that can have an effect on the retain count).


It appears that Apple already knows about this (see radar in comment),  
they just forgot to document it. How else would someone who writes  
example projects for the SDK know this specific function has this very  
special behavior - not that I know anything about who writes such  
examples.


Regards
Markus
--
__
Markus Spoettl



smime.p7s
Description: S/MIME cryptographic signature
___

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: Editing in a tableview without selecting

2009-11-01 Thread Ben Haller

On 1-Nov-09, at 6:01 PM, Graham Cox wrote:


On 02/11/2009, at 4:42 AM, Ben Haller wrote:

But where?  I've been hunting for a -setEditable:YES method  
somewhere that I need to call, but I haven't found it...



Hi Ben,

Have you tried -setEditable:YES on the textfield cell you're using  
for the table column? (Inherited from NSCell). I'm not sure what its  
default state is, documentation doesn't say.


  Just tried it; makes no difference.

  I think I will have to construct a test case to see if I can  
reproduce this in a simple, isolated way.  If that test case  
reproduces the problem, then I will post it somewhere and follow up on  
the list...


Ben Haller
Stick Software


___

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


Update an NSMenu / NSMenuItem while it's being displayed on key down?

2009-11-01 Thread aaron smith
Hey all, quick question.

What's the best way to go about updating an NSMenu that's currently being
shown. For example, I have a button that triggers an NSMenu popup call and I
want to detect the option key press and update some of the items in the
menu.

anyone done this?

thanks
___

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: Update an NSMenu / NSMenuItem while it's being displayed on key down?

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 7:31 PM, aaron smith
 wrote:
> What's the best way to go about updating an NSMenu that's currently being
> shown. For example, I have a button that triggers an NSMenu popup call and I
> want to detect the option key press and update some of the items in the
> menu.

For this specific case, use menu alternates.

In general, NSEvent has the information you want in the form of a
modifiers-changed event.

--Kyle Sluder
___

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: Editing in a tableview without selecting

2009-11-01 Thread Graham Cox


On 02/11/2009, at 1:04 PM, Ben Haller wrote:

I think I will have to construct a test case to see if I can  
reproduce this in a simple, isolated way.  If that test case  
reproduces the problem, then I will post it somewhere and follow up  
on the list...



Well, setting up a table view in IB, which takes but a few minutes,  
works correctly.


The question you need to answer is a) what's different in your case  
and b) why not just use IB?


--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: Editing in a tableview without selecting

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 9:42 AM, Ben Haller  wrote:
> - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
> forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

You might want to double-check that you didn't typo this in your data
source's @implementation.

--Kyle Sluder
___

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


Create an NSCharacterSet constant

2009-11-01 Thread John Joyce

Hi All,

Is it possible to create an NSCharacterSet constant?
Attempting to do so with the methods for creating an NSCharacterSet  
naturally fails to compile with "initializer element is not constant"

I would ideally like to be able to do this.
Is it best just to declare a global constant string, then initialize  
an NSCharacterSet during app initialization? It certainly seems that  
is the only real option.

Am I missing something?
If I am correct in what I am seeing, would there not be a valid use  
case for this as an extension of NSCharacterSet?


(BTW, thanks GCC for the less than clear error message which should  
say "you cannot run functions or methods in a global initializer" or  
something better.)

___

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: Create an NSCharacterSet constant

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 9:19 PM, John Joyce
 wrote:
> Is it possible to create an NSCharacterSet constant?

No.  By definition, constants are assigned values at compile time.
Objects other than strings can only be created at runtime.  There is
no way around this fact.

> Is it best just to declare a global constant string, then initialize an
> NSCharacterSet during app initialization? It certainly seems that is the
> only real option.

Answers will vary.  You could use a static global variable which is
assigned in +initialize, or you could use a static variable in a
category on NSCharacterSet, or a number of other things.  Basically
what you really want is a singleton, not a constant.

I'm partial to the following construct:

+ (Foo *)sharedFoo {
  static Foo *sharedFoo;
  dispatch_once_t once;
  dispatch_once(&once, ^{ sharedFoo = [[foo alloc] init]; }
  return sharedfoo;
}

--Kyle Sluder
___

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: Create an NSCharacterSet constant

2009-11-01 Thread Graham Cox


On 02/11/2009, at 4:19 PM, John Joyce wrote:


Is it possible to create an NSCharacterSet constant?
Attempting to do so with the methods for creating an NSCharacterSet  
naturally fails to compile with "initializer element is not constant"

I would ideally like to be able to do this.
Is it best just to declare a global constant string, then initialize  
an NSCharacterSet during app initialization? It certainly seems that  
is the only real option.

Am I missing something?
If I am correct in what I am seeing, would there not be a valid use  
case for this as an extension of NSCharacterSet?



You can't create any non-scalar constant (except nil) using a static  
initializer.


However, what you want to do is super-easy, and yes, it's a case for  
an extension to NSCharacterSet. Just add a class method as a category:


@interface NSCharacterSet (MyCharacterSetConstant)

+ (NSCharacterSet*) theConstantCharacterSet;

@end


@implementation NSCharacterSet (MyCharacterSetConstant)

+ (NSCharacterSet*) theConstantCharacterSet
{
static NSCharacterSet* s_tccs = nil;

if( s_tccs == nil )
s_tccs = [[self characterSetWithCharactersInString:@"..."]  
retain];


return s_tccs;
}



@end


--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: Create an NSCharacterSet constant

2009-11-01 Thread Matt Neuburg
On Sun, 1 Nov 2009 21:29:25 -0800, Kyle Sluder  said:
>I'm partial to the following construct:
>
>+ (Foo *)sharedFoo {
>  static Foo *sharedFoo;
>  dispatch_once_t once;
>  dispatch_once(&once, ^{ sharedFoo = [[foo alloc] init]; }
>  return sharedfoo;
>}

Why (I'm really asking, not arguing; I don't know anything about GCD) is
this better than the traditional:

+ (Foo*) sharedFoo {
   static Foo* sharedFoo = nil;
   if (nil == sharedFoo) sharedFoo = [[Foo alloc] init];
   return sharedFoo;
}

m.

-- 
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



___

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: Create an NSCharacterSet constant

2009-11-01 Thread John Joyce


On Nov 1, 2009, at 11:32 PM, Graham Cox wrote:



On 02/11/2009, at 4:19 PM, John Joyce wrote:


Is it possible to create an NSCharacterSet constant?
Attempting to do so with the methods for creating an NSCharacterSet  
naturally fails to compile with "initializer element is not constant"

I would ideally like to be able to do this.
Is it best just to declare a global constant string, then  
initialize an NSCharacterSet during app initialization? It  
certainly seems that is the only real option.

Am I missing something?
If I am correct in what I am seeing, would there not be a valid use  
case for this as an extension of NSCharacterSet?



You can't create any non-scalar constant (except nil) using a static  
initializer.


However, what you want to do is super-easy, and yes, it's a case for  
an extension to NSCharacterSet. Just add a class method as a category:


@interface NSCharacterSet (MyCharacterSetConstant)

+ (NSCharacterSet*) theConstantCharacterSet;

@end


@implementation NSCharacterSet (MyCharacterSetConstant)

+ (NSCharacterSet*) theConstantCharacterSet
{
   static NSCharacterSet* s_tccs = nil;

   if( s_tccs == nil )
   s_tccs = [[self characterSetWithCharactersInString:@"..."]  
retain];


   return s_tccs;
}



@end


--Graham



Wow, you all responded wonderfully and super fast!
I had accidentally sent it to the list hours ago from the wrong email,  
so it was naturally rejected, then I just now sent this.
Thanks to everyone, when I get a block of time I'll dive into each  
approach and see how they all feel.

Anyway, I digress...
 Category, yeah, that's totally one way I thought about, but I was  
thinking more of an enhancement request in Radar. I figured the nature  
of it inheriting from NSObject implies there are some kind of  
optimizations under the hood (otherwise we'd just use NSString and  
NSScanner right?).
 Seems like a useful one considering the  
characterSetWithCharactersInString: method. Even if it were some sort  
of singleton class. Particularly useful in input validation routines  
(things like highly structured serial numbers and other identifiers,  
etc...)
If there is consensus from multiple people on an enhancement request  
and the functionality and justification for it, I'll be happy to file  
it.

___

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: Create an NSCharacterSet constant

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 9:49 PM, Matt Neuburg  wrote:
> Why (I'm really asking, not arguing; I don't know anything about GCD) is
> this better than the traditional:

It avoids a race condition if +sharedFoo is called simultaneously from
different threads, and it's wicked fast (Cmd-DoubleClick dispatch_once
to see why).  It's also got "once" in the name, and is roughly the
same shape as the traditional construction, so switching to it entails
minimal mental burden.

--Kyle Sluder
___

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: Create an NSCharacterSet constant

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 9:50 PM, John Joyce
 wrote:
>  Category, yeah, that's totally one way I thought about, but I was thinking
> more of an enhancement request in Radar. I figured the nature of it
> inheriting from NSObject implies there are some kind of optimizations under
> the hood (otherwise we'd just use NSString and NSScanner right?).

An NSCharacterSet embodies the concept of "a set of characters."  An
NSString and NSScanner pair embodies the concept of "how I'm gonna
find some characters in a string."  The first is a value type, the
second an implementation detail.  NSCharacterSets are also useful for
other things than just finding them in a string or other stream of
data.

>  Seems like a useful one considering the characterSetWithCharactersInString:
> method. Even if it were some sort of singleton class. Particularly useful in
> input validation routines (things like highly structured serial numbers and
> other identifiers, etc...)

I'm confused about what enhancement could be made that would not be
highly specific to your application.

--Kyle Sluder
___

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: Create an NSCharacterSet constant

2009-11-01 Thread Graham Cox


On 02/11/2009, at 4:50 PM, John Joyce wrote:

Category, yeah, that's totally one way I thought about, but I was  
thinking more of an enhancement request in Radar. I figured the  
nature of it inheriting from NSObject implies there are some kind of  
optimizations under the hood (otherwise we'd just use NSString and  
NSScanner right?).
Seems like a useful one considering the  
characterSetWithCharactersInString: method. Even if it were some  
sort of singleton class. Particularly useful in input validation  
routines (things like highly structured serial numbers and other  
identifiers, etc...)
If there is consensus from multiple people on an enhancement request  
and the functionality and justification for it, I'll be happy to  
file it.



What is your proposed character set going to contain? Is it of ultra- 
widespread utility?


Otherwise, this is what categories are for - to add enhancements  
yourself in a few moments instead of waiting (possibly years) for  
Apple to do it for you. I don't really see that there is a case here  
for a radar enhancement request, but it would depend on what you have  
in mind.


As for optimisations, I don't quite follow your argument -  
NSCharacterSet is not equivalent to NScanner + NSString, though it  
sometimes will get used with those classes. I expect the common built- 
in "constant" sets are there because they are of very widespread  
utility - e.g. stripping whitespace, but are probably not using much  
in the way of magic optimisations.


--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: Create an NSCharacterSet constant

2009-11-01 Thread John Joyce


On Nov 2, 2009, at 12:04 AM, Graham Cox wrote:



On 02/11/2009, at 4:50 PM, John Joyce wrote:

Category, yeah, that's totally one way I thought about, but I was  
thinking more of an enhancement request in Radar. I figured the  
nature of it inheriting from NSObject implies there are some kind  
of optimizations under the hood (otherwise we'd just use NSString  
and NSScanner right?).
Seems like a useful one considering the  
characterSetWithCharactersInString: method. Even if it were some  
sort of singleton class. Particularly useful in input validation  
routines (things like highly structured serial numbers and other  
identifiers, etc...)
If there is consensus from multiple people on an enhancement  
request and the functionality and justification for it, I'll be  
happy to file it.



What is your proposed character set going to contain? Is it of ultra- 
widespread utility?


Otherwise, this is what categories are for - to add enhancements  
yourself in a few moments instead of waiting (possibly years) for  
Apple to do it for you. I don't really see that there is a case here  
for a radar enhancement request, but it would depend on what you  
have in mind.


As for optimisations, I don't quite follow your argument -  
NSCharacterSet is not equivalent to NScanner + NSString, though it  
sometimes will get used with those classes. I expect the common  
built-in "constant" sets are there because they are of very  
widespread utility - e.g. stripping whitespace, but are probably not  
using much in the way of magic optimisations.


--Graham




Indeed this is the point of Categories.
___

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: Editing in a tableview without selecting

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 9:42 AM, Ben Haller
 wrote:\
>  The only unusual thing about this tableview is that I set it up in code
> instead of in IB, so I assume the root of the problem is in my programmatic
> setup code.  But where?  I've been hunting for a -setEditable:YES method
> somewhere that I need to call, but I haven't found it...

Oh!  You forgot to call -setEditable: on the table columns.  :)

--Kyle Sluder
___

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: Create an NSCharacterSet constant

2009-11-01 Thread John Joyce


On Nov 1, 2009, at 11:59 PM, Kyle Sluder wrote:


On Sun, Nov 1, 2009 at 9:50 PM, John Joyce
 wrote:
 Category, yeah, that's totally one way I thought about, but I was  
thinking

more of an enhancement request in Radar. I figured the nature of it
inheriting from NSObject implies there are some kind of  
optimizations under

the hood (otherwise we'd just use NSString and NSScanner right?).


An NSCharacterSet embodies the concept of "a set of characters."  An
NSString and NSScanner pair embodies the concept of "how I'm gonna
find some characters in a string."  The first is a value type, the
second an implementation detail.  NSCharacterSets are also useful for
other things than just finding them in a string or other stream of
data.

 Seems like a useful one considering the  
characterSetWithCharactersInString:
method. Even if it were some sort of singleton class. Particularly  
useful in
input validation routines (things like highly structured serial  
numbers and

other identifiers, etc...)


I'm confused about what enhancement could be made that would not be
highly specific to your application.

--Kyle Sluder

Not my application per se, but for more applications.
I see it as a useful thing to have predefined character sets that  
don't need to be managed.
It's still just as simple to create them, but it sure would be nifty  
to not have to and to manage them in a constants file.


At the very least, I will probably submit a radar on adding locale- 
specific standard sets.

The standard set is woefully Latin-centric.
Many languages do not use whitespace the same way (generally as word  
boundaries).

Many languages also do not have the concept of capitalization.

Japanese is one in which I happen to work.
There would be a multitude of sets that would make sense in Japanese  
for a multitude of super common purposes.


I know, some of this leads to things like tokenization.
Point being, if we look beyond English and Western Europe, and  
consider how much of programming is pushing text around, it certainly  
seems like a logical expansion that would be of benefit to a lot of  
people.

Maybe it's just me, not trying to hog the list.

If anybody has some good sets for consideration, I'll be happy to  
include them when I create that radar.
Beyond that, I'd be willing to produce and host open source sets for  
use, if anybody wants to contribute them (( send them off list )).
( anything locale-specific should ideally include localized  
documentation as well )

___

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: objectAtIndex

2009-11-01 Thread Nava Carmon

Thank you, that answers my question,

Nava

On Nov 1, 2009, at 10:24 PM, Sherm Pendley wrote:


On Sun, Nov 1, 2009 at 2:44 PM, Nava Carmon  wrote:


NSObject *anObject = [anArray objectAtIndex:i];

...

Should I release it?


No. You didn't create anObject with +alloc or a method beginning with
-copy, nor did you send it a -retain message. Therefore you do not own
it and must not release it.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net


___

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: Create an NSCharacterSet constant

2009-11-01 Thread Kyle Sluder
On Sun, Nov 1, 2009 at 11:03 PM, John Joyce
 wrote:
> I see it as a useful thing to have predefined character sets that don't need
> to be managed.

So you just want more things like +whitespaceCharacterSet?  That makes sense.

> At the very least, I will probably submit a radar on adding locale-specific
> standard sets.
> The standard set is woefully Latin-centric.

> Many languages do not use whitespace the same way (generally as word
> boundaries).

> [snip]

> I know, some of this leads to things like tokenization.

Well, in that specific instance, you should not be doing word
splitting yourself.  You should instead use CFStringTokenizer.

> Point being, if we look beyond English and Western Europe, and consider how
> much of programming is pushing text around, it certainly seems like a
> logical expansion that would be of benefit to a lot of people.
> Maybe it's just me, not trying to hog the list.

At some point you have to decide that it isn't worth adding more API.
I certainly would not want NSCharacterSet to expose the power set of
all Unicode characters.

--Kyle Sluder
___

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