Re: NSPredicateEditor Continuous updating failes

2010-01-21 Thread Jim Turner
On Thu, Jan 21, 2010 at 6:00 AM, Florian Soenens florian.soen...@nss.be wrote:
 Hi LIst,

 i set up an NSPredicateEditor and got it all working fine except that it
 only executes when i hit enter or tab out of the NSTextField.
 Is there a way to let it execute everytime something changes in the
 textfield?

 I tried checking the continuous button in IB but that is impossible, it
 always unchecks itself. I also tried setting continuous programatically but
 to no avail...

 Anyone has any suggestions?

 Kind regards,
 Florian.

Add an observer for notifications of
NSControlTextDidChangeNotification. When the predicate editor updates
a text field, it'll send this notification with itself as the object
value.

-- 
Jim
http://nukethemfromorbit.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


NSServices error parameter ignored?

2010-01-18 Thread Jim Turner
I've created and am successfully calling a service in my application.
But when an error is encountered and I set an error string, it doesn't
seem to go anywhere. The docs say its supposed to be logged to the
console but I see nothing. Is this a bug or am I missing something? My
code:

-(void) myCoolService:(NSPasteboard *)pboard userData:(NSString *)data
error:(NSString **)error
{
if( pboard contains cool things )
{
doing cool things
}
else
{
if( error )
*error = [NSString stringWithString:@This error never shows];
}
}

Thanks

-- 
Jim
http://nukethemfromorbit.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: NSServices error parameter ignored?

2010-01-18 Thread Jim Turner
On Mon, Jan 18, 2010 at 11:38 AM, Greg Parker gpar...@apple.com wrote:
 On Jan 18, 2010, at 8:52 AM, Jim Turner wrote:
 I've created and am successfully calling a service in my application.
 But when an error is encountered and I set an error string, it doesn't
 seem to go anywhere. The docs say its supposed to be logged to the
 console but I see nothing. Is this a bug or am I missing something?

 Looks like a bug. I think there's a miscommunication between AppKit and CF 
 that drops the error after your service is called. You should file a bug 
 report.


 --
 Greg Parker     gpar...@apple.com     Runtime Wrangler


Thanks for the reply, Greg. I've filed a bug rdar://problem/7551989

-- 
Jim
http://nukethemfromorbit.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: A password strength checker

2010-01-12 Thread Jim Turner
Code is available at:
http://code.google.com/p/nukethemfromorbit/source/browse/#svn/trunk/PasswordStrength

It's just the method for determining the strength, any UI
accouterments is an exercise left up to the reader... although I'll
probably make my stuff available once I have it cleaned up. If anyone
has suggestions for improvement of the algorithm, please let me know.

Jim

On Mon, Jan 11, 2010 at 10:05 PM, Howard Siegel hsie...@gmail.com wrote:
 If you would, please post your code some place and let us know the URL to
 it.

 There is supposed to be an iPhone version coming out, but I suspect that
 it will be done using MonoDevelop (C#.NET for non-Windows platforms)
 rather than being written in ObjC/Cocoa.

 - h

 On Mon, Jan 11, 2010 at 08:12, Jim Turner jturner.li...@gmail.com wrote:

 Awesome find, Howard. I've needed a password strength algorithm in the
 past and never could find one.  Plus, the strength computed by the
 Password Assistant is questionable at best.  Given a password of
 '' (20 lowercase 'a'), the assistant scores it
 about a 20%. Add one more 'a' though and it jumps to 80%. I'm not sure
 how that one extra 'a'  is worth a 60% increase in strength. I'd be
 nice if their implementation was a bit more open for examination.

 The algorithm used by KeePass, however, scores both a 20-character 'a'
 and 21-character 'a' password as 10 (with 0 being no password or a
 worthless password). Seems more accurate.

 If anyone's interested in it, I wrote a Cocoa version of their
 implementation. I'd be happy to make it available.

 Jim

 On Thu, Jan 7, 2010 at 2:32 PM, Howard Siegel hsie...@gmail.com wrote:
  Have a look at the source code for KeePass Password Safe (
  http://keepass.info/).  It has a password generator and strength
  computation. Version 1.x is written in C++ for MS Windows (using MFC).
  Version 2.x is a rewrite in C# for .NET.
 
  It has been ported as KeyPassX for Mac OS X and Linux.
 
  - h
 
  On Thu, Jan 7, 2010 at 11:51, Martin Hewitson
  martin.hewit...@aei.mpg.dewrote:
 
  Dear list,
 
  Is anybody aware of a reasonable algorithm or some code that can be
  used to
  test/check the strength of a password? I'd like to give a kind of score
  or a
  color (red,yellow,green). I've looked at cracklib, but that doesn't
  give a
  score, really.
 
  Best wishes,
 
  Martin
 
  
  Martin Hewitson
  Albert-Einstein-Institut
  Max-Planck-Institut fuer
     Gravitationsphysik und Universitaet Hannover
  Callinstr. 38, 30167 Hannover, Germany
  Tel: +49-511-762-17121, Fax: +49-511-762-5861
  E-Mail: martin.hewit...@aei.mpg.de
  WWW: http://www.aei.mpg.de/~hewitson
  http://www.aei.mpg.de/%7Ehewitson
  
 
 
 
 
 
  ___
 
  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/hsiegel%40gmail.com
 
  This email sent to hsie...@gmail.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/jturner.lists%40gmail.com
 
  This email sent to jturner.li...@gmail.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: A password strength checker

2010-01-11 Thread Jim Turner
Awesome find, Howard. I've needed a password strength algorithm in the
past and never could find one.  Plus, the strength computed by the
Password Assistant is questionable at best.  Given a password of
'' (20 lowercase 'a'), the assistant scores it
about a 20%. Add one more 'a' though and it jumps to 80%. I'm not sure
how that one extra 'a'  is worth a 60% increase in strength. I'd be
nice if their implementation was a bit more open for examination.

The algorithm used by KeePass, however, scores both a 20-character 'a'
and 21-character 'a' password as 10 (with 0 being no password or a
worthless password). Seems more accurate.

If anyone's interested in it, I wrote a Cocoa version of their
implementation. I'd be happy to make it available.

Jim

On Thu, Jan 7, 2010 at 2:32 PM, Howard Siegel hsie...@gmail.com wrote:
 Have a look at the source code for KeePass Password Safe (
 http://keepass.info/).  It has a password generator and strength
 computation. Version 1.x is written in C++ for MS Windows (using MFC).
 Version 2.x is a rewrite in C# for .NET.

 It has been ported as KeyPassX for Mac OS X and Linux.

 - h

 On Thu, Jan 7, 2010 at 11:51, Martin Hewitson 
 martin.hewit...@aei.mpg.dewrote:

 Dear list,

 Is anybody aware of a reasonable algorithm or some code that can be used to
 test/check the strength of a password? I'd like to give a kind of score or a
 color (red,yellow,green). I've looked at cracklib, but that doesn't give a
 score, really.

 Best wishes,

 Martin

 
 Martin Hewitson
 Albert-Einstein-Institut
 Max-Planck-Institut fuer
    Gravitationsphysik und Universitaet Hannover
 Callinstr. 38, 30167 Hannover, Germany
 Tel: +49-511-762-17121, Fax: +49-511-762-5861
 E-Mail: martin.hewit...@aei.mpg.de
 WWW: http://www.aei.mpg.de/~hewitson http://www.aei.mpg.de/%7Ehewitson
 





 ___

 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/hsiegel%40gmail.com

 This email sent to hsie...@gmail.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/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.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: NSPredicate like NSLiteralSearch

2009-12-15 Thread Jim Turner
I believe you need the diacritic insensitive option:

'someProperty BEGINSWITH[d] ?'

Look up NSComparisonPredicate options in the documentation for more
discussion.  As for what the 'w' means, it's Spotlight specific.  The
Comparison is word based, and also detects transitions from lower-case
to upper-case.

http://developer.apple.com/Mac/library/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/QueryFormat.html

-- 
Jim
http://nukethemfromorbit.com



On Tue, Dec 15, 2009 at 1:30 AM, Gerriet M. Denkmann
gerr...@mdenkmann.de wrote:

 This works. i.e. returns {0,1}:
 NSRange r2 = [ @??? rangeOfString: @? options: NSAnchoredSearch | 
 NSLiteralSearch ];
 (without NSLiteralSearch it returns NSNotFound).

 but an NSPredicate with: someProperty BEGINSWITH ?  does NOT find ???.
 (the NSPredicate is to be used with -[NSArrayController setFilterPredicate:] 
 to query Core Data).

 So: is there some string_option equivalent to NSLiteralSearch?

 And a related question: where are the available string_options defined?
 The Predicate Programming Guide has:
 string_options ::= c | d | cd

 but also an example with w:
 ((* = FooBar*wcd)) || (kMDItemTextContent = FooBar*cd))

 10.6.2

 Kind regards,

 Gerriet.

 ___

 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/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.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: NSPredicateEditorRowTemplate and dynamic popups

2009-11-13 Thread Jim Turner
Try this:

Create an outlet to your row template. When you need to update the
popups, make a copy of that template. Make a copy of the rowTemplates
the predicate editor currently tracks and iterate over them replacing
the template in the list that is the same class as your custom
template.  Then set this new list of templates back onto the predicate
editor.

The net effect is that the predicate editor will rebuild all the
templates it's currently using which gives you a chance to update the
popups as needed.  I don't know what'll happen when the popup
transitions to/from the text field... there's little you can do with
that as its an optimization the predicate editor does when building
it's templates (if there's only one option, why offer a choice?)

cheap-n-dirty code sample

-(void) updateTemplates {
MyRowTemplate *_newTemplate = [[myRowTemplateOutlet copy] autorelease];
NSMutableArray *rowTemplates = [[[predicateEditor rowTemplates]
mutableCopy] autorelease];

NSInteger ctr;
for( ctr=0; ctr[rowTemplates count]; ctr++ ) {
if( [[rowTemplates objectAtIndex:ctr] 
isKindOfClass:[MyRowTemplate class]] ) {
[rowTemplates replaceObjectAtIndex:ctr 
withObject:_newTemplate];
break;
}
}
[predicateEditor setRowTemplates:rowTemplates];
}


-- 
Jim
http://nukethemfromorbit.com


On Fri, Nov 13, 2009 at 10:48 AM, Dave DeLong davedel...@me.com wrote:
 Hi everyone,

 I have an NSPredicateEditor, with some standard row templates.  I'd like to 
 add a custom row template with three views:  a popup button (indicating the 
 attributes this template references), a second popup button (with the 
 operators), and a third popup button that's populated with a list of possible 
 values.

 This is very similar to a regular row template, except that the list of 
 possible values is computed at runtime and can change periodically based on 
 system events.

 I've tried subclassing NSPredicateEditorRowTemplate, overriding 
 -templateViews, and returning my 3 popup buttons (all properly populated).  
 This works once, but after the row is created, I haven't been able to figure 
 out how to repopulate the popup button when the list of possible values 
 changes.  I've tried setting the popup button's menu's delegate to an object 
 that will repopulate it, but the delegate methods are never called.

 I've also seen that when there's only one possible value, my popup button is 
 replaced with a textfield.  I suppose that's OK, except that if the list of 
 possible values changes, I need that textfield to change to a popup button.

 How can I achieve my dynamic popup button in an NSPredicateEditorRowTemplate?

 Thanks!

 Dave DeLong
 ___

 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/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.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: NSCollectionView issues

2009-10-16 Thread Jim Turner
10.5's collection view is, safe to say, kind of a train wreck. I've
had to work around quite a few things.  Your problem is solvable by
asking the NSCollectionViewItem created for your new table element for
its view and to have that view scrollRectToVisible: for its bounds.

If you need to get the ViewItem for a specific index (available via
NSCollectionView's itemAtIndex: under 10.6), you'll need to go into
slightly undocumented land and look at the collection view's
_targetItems ivar. It contains the list of NSCollectionViewItems
currently displayed in the collection view.  Make sure you
conditionalize this for 10.6 as _targetItems isn't there anymore.

Hope that helps

-- 
Jim
http://nukethemfromorbit.com


On Fri, Oct 16, 2009 at 9:32 AM, Half Activist halfactiv...@gmail.com wrote:
 Hi,
        I'm using a NSCollectionView to display a stack of items (a table)
 but since what's display is far too complex to be laid out programmatically
 I went for the NSCollectionView. And it's been all problems from the
 beginning.
        First of all with setContent that never worked no matter what I
 did...it only works if I bind the content to an nsarraycontroller.

        Now, when I add a new item in this table i want to be able to
 scroll it to the displayed area of the view, but the frameForItemAtIndex:
 method only appeared in 10.6, so I decided to use the subviews and get the
 frame this way, and now what did I discover: Suppose I have N items and
 therefore N subviews in the NSCollectionView, after changing the array that
 now contains N + 1 items, the nscollectionview has after the update N + N +
 1 subviews!
 So, accessing subviews is not an option either.

 If anyone knows how to do fix these bugs, and how to disable the animation,
 i'd be really glad. I'm considering writing an homebrew nscollectionview.

 regards.
 ___

 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/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.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: Application main menu title behavior change in 10.6

2009-09-08 Thread Jim Turner
On Fri, Sep 4, 2009 at 9:03 PM, Peter Ammonpam...@apple.com wrote:

 Hi Jim,

 First let me thank you for checking the release notes.  However, that
 particular issue is unrelated, confusingly enough.

 Here's what's going on.  The first menu item in the main menu (or more
 precisely, its submenu) is magic, in that when it becomes the first item,
 its title is ignored and instead the application name is used.  This is why
 you do not have to update your MainMenu.nib every time you change your
 application name.  In Leopard, there was a bug that caused this to be
 applied inconsistently.  It sounds like your application was benefiting from
 this bug.

 You can change the title of the application menu, after you set the main
 menu, like so:

 NSApp mainMenu] itemAtIndex:0] submenu] setTitle:@New Title]

 Hope this helps,
 -Peter



Indeed it does help, Peter. I now see why I was so confused with the
behavior I was encountering when I tried setTitle: initially.
setTitle: does its business only if the new title is different than
the current title. We are building a new main menu with the new
application's name already in place.

Doing the following sets the menu's title correctly when the title is
already set to New Title:

NSApp mainMenu] itemAtIndex:0] submenu] setTitle:@]
NSApp mainMenu] itemAtIndex:0] submenu] setTitle:@New Title]

Always appreciative of the help, Peter. Thanks!

-- 
Jim
___

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


Application main menu title behavior change in 10.6

2009-09-04 Thread Jim Turner
Hi all,

I have an application (QuicKeys) that allows the user to define menu
selection as an action. In our latest version and under Leopard, we
present UI that replaces the main menu bar of our app with the menu
bar of the target app (via setMainMenu:) so that we can correctly
retrieve which menu item the user selected. Works like a champ, even
under Snow Leopard, save for one problem.  Under 10.6, the application
name is always QuicKeys, not Finder or whatever the target
application name would be. This is causing confusion with our users as
while the menu is really the target app's menu, it has the wrong
application name.

Reading through the release notes for AppKit on 10.6, I found that
there's been a change to how the main menu bar displays the
application's name.  Specifically, under the NSApplication
application menu item title header, it states ... the application
menu always reflects the application name.  This appears to be what's
causing the issue and I'm curious if anyone knows of a work-around?

Thanks
Jim
___

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


NSFileManager's copyItemAtPath:toPath:error: syslogging every directory it finds?

2009-06-01 Thread Jim Turner
Hopefully this has a simple answer but it seems now that when I call
copyItemAtPath:toPath:error: to copy a folder to another location, I
get this in the console:

6/1/09 3:48:28 PM
/Users/jimt/Source/MyApp/trunk/build/Debug/MyApp.app/Contents/MacOS/MyApp[29625]
reading from /Users/jimt/Library/MyApp/MyFolder: Is a directory

I had to break on syslog() to see who was even causing this to happen.
 I'm not sure what's changed or if I've set some magic flag someplace
that's finding its way into the internals of
copyItemAtPath:toPath:error: but does anyone know why I'd be getting
that logged? Very confusing.

-- 
Jim
http://nukethemfromorbit.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: Renaming a file repositions icon in Finder

2009-05-11 Thread Jim Turner
On Fri, May 8, 2009 at 5:45 PM, Sean McBride s...@rogue-research.com wrote:
 On 5/8/09 2:52 PM, Jim Turner said:

It appears that renaming a file will cause the Finder to reposition
the icon for the file if it's currently displayed in a icon view
somewhere.  Is there any way to prevent that from happening?  It looks
very strange to have icons jump all over the place just because of a
rename.

Thinking that it might have been the method with which I was renaming
the file, I tried NSFileManager's moveItemAtPath:toPath:error:,
rename(), and FSRenameUnicode() and all three exhibit the same
problem.

 Many apps exibit this problem and it has driven me and others nuts for
 years.  Do file a(nother) bug.

 --
 
 Sean McBride, B. Eng                 s...@rogue-research.com
 Rogue Research                        www.rogue-research.com
 Mac Software Developer              Montréal, Québec, Canada




If anyone would like to me-too my me-too, it's rdar://problem/6874498

-- 
Jim
http://nukethemfromorbit.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


Renaming a file repositions icon in Finder

2009-05-08 Thread Jim Turner
It appears that renaming a file will cause the Finder to reposition
the icon for the file if it's currently displayed in a icon view
somewhere.  Is there any way to prevent that from happening?  It looks
very strange to have icons jump all over the place just because of a
rename.

Thinking that it might have been the method with which I was renaming
the file, I tried NSFileManager's moveItemAtPath:toPath:error:,
rename(), and FSRenameUnicode() and all three exhibit the same
problem.

-- 
Jim
http://nukethemfromorbit.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: filteredArrayUsingPredicate and points

2009-04-15 Thread Jim Turner
On Wed, Apr 15, 2009 at 9:05 AM, Alexey Baev b...@belightsoft.com wrote:
 Hi.

 I have class MyDot. This class has function:
 - (BOOL) containsPoint: (NSPoint) pt;

 I have also NSArray, which contains several MyDot objects:
 NSArray* dots;

 I want to get new array
 NSArray* newDots
 which contains MyDot objects and
 for these dots containsPoint:(NSPoint)pt = YES.

 How can I do that?

 I would like to write something like that:

 NSPoint checkedPoint = NSMakePoint(100, 100);

 NSPredicate* predicate = [NSPredicate predicateWithFormat: @containsPoint
 %p == YES , checkedPoint]; //i don't know what to write here

 NSArray* newDots = [dots filteredArrayUsingPredicate: predicate];

 I would be glad if you helped me.

 --
 Alexey Baev

Alexey,

It's quite possible, although it takes a bit more that a simple
predicateWithFormat: can do.  You'll need to use NSExpression's
expressionForFunction:selectorName:arguments: along with a
NSComparisonPredicate.  Your MyDot class will also need a method
that's able to accept a NSValue object (containing a NSPoint) and
return an NSNumber.  Something like...

-(NSNumber *) containsThisPoint: (NSValue *) aPoint;

So to filter your array:

NSArray *myArrayOfObjects = ...
NSPoint tgtPoint = ...

NSExpression *functionExp = [NSExpression
expressionForFunction:[NSExpression expressionForEvaluatedObject]
selectorName:@containsThisPoint: arguments:[NSArray
arrayWithObject:[NSExpression expressionForConstantValue:[NSValue
valueWithPoint:tgtPoint;

NSPredicate *searchPredicate = [NSComparisonPredicate
predicateWithLeftExpression:functionExp rightExpression:[NSExpression
expressionForConstantValue:[NSNumber numberWithBool:YES]]
modifier:NSDirectPredicateModifier type:NSEqualToPredicateOperatorType
options:0];

NSArray *newArray = [myArrayOfObjects
filteredArrayUsingPredicate:searchPredicate];


-- 
Jim
http://nukethemfromorbit.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: Anyone using IKImageView/any alternatives ?

2009-02-05 Thread Jim Turner
I'm using IKImageView in an app and while it's far from being a
fully-featured control, it can do some things ok.  If all you need
to do is pan and zoom, IKImageView will work just fine.  It's when you
get into more advanced things like rotation and saving changes
where the implementation falls apart.

Stay in the shallow end of the pool and you'll be fine.  If you ever
plan on needing more than just pan and zoom, you'll be better off
looking somewhere else or just rolling your own from the start.

Jim

On Thu, Feb 5, 2009 at 4:13 AM, Christian Graus
christian.gr...@gmail.com wrote:
 I am googling for example of IKImageView, and all I am finding is posts like
 this one:
 http://espresso-served-here.com/category/scribbler/

 In short, lots of people are reporting that IKImageView plain does not work
 as advertised.  Does anyone have any positive experience with this control ?
 All I need to do is zoom and pan an image, does the NSImageView support
 that, or is there somewhere else I should be looking ?

 Thanks as always

 Christian
 ___

 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/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.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: NSPredicateEditorRowTemplate for NSDate

2009-01-19 Thread Jim Turner
The miracle is over.  The out-of-the-box templates in IB only provide
three-view templates (left expression, operator, right expression).
You'll need to subclass NSPredicateEditorRowTemplate and provide the
views and logic you want to use in your template.

I did a presentation for the local CocoaHeads a while back on
NSPredicateEditor and my sample code does show a basic Date is within
N days/weeks/months/years if you'd like a starting point.

Go to http://groups.google.com/group/des-moines-cocoaheads/files   and
look for NSPredicateEditor.zip (I'd direct link but the URL is a
monster).

-- 
Jim
http://nukethemfromorbit.com


On Mon, Jan 19, 2009 at 2:13 PM, Vitaly Ovchinnikov
vitaly.ovchinni...@gmail.com wrote:
 Hey, boys and girls?
 Am I the first, who use NSPredicateEditor?
 I just found that there is no default template for time values...

 Please somebody confirm that miracle is over and I need to code all
 this data/time stuff myself :(


 On Sun, Jan 18, 2009 at 7:22 PM, Vitaly Ovchinnikov
 vitaly.ovchinni...@gmail.com wrote:
 Hello list,

 When I add a row template that edits date to predicate editor, it
 allows to perform simple comparisons. Like less or greater or equal
 etc. Smart folders in Finder allow to add clauses like Date is within
 last X weeks. I can't find a simple way to do the same. It seems that
 the only way is to use custom view with that implements what I want,
 but want to make sure that it is correct before I start.

 Maybe I missed something? Or maybe some standard implementation
 already exists? I googled the Internet and this list - nothing.
 Any ideas?

 Thank you.

 ___

 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/jturner.lists%40gmail.com

 This email sent to jturner.li...@gmail.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


Accessing NSKeyedArchiver's archivedDataWithRootObject by name

2008-12-09 Thread Jim Turner
I have a situation where I'm archiving an array of objects via
NSKeyedArchiver's archivedDataWithRootObject: and later needing to set
a delegate on the NSKeyedUnarchiver that decodes it.  The
documentation is a bit unclear on how one starts the unarchive process
when a NSKeyedUnarchiver is created on an archive where you don't
know, for certain, the keys it contains.

So my question... is this legitimate?

NSKeyedUnarchiver *_keyedUnarchiver = [[[NSKeyedUnarchiver alloc]
initForReadingWithData:archivedData] autorelease];
[_keyedUnarchiver setDelegate:self];
NSMutableArray *archivedArray = [_keyedUnarchiver decodeObjectForKey:@root];
[_keyedUnarchiver finishDecoding];

It works, but I always question things when I hard-code a string for
something.  Will 'root' always be the key that represents the root
object?

If I could do something like [NSKeyedUnarchiver
unarchiveObjectWithData:delegate:], that would be better than perfect.

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


IKImageView and delegate callback/notification of image changes

2008-10-06 Thread Jim Turner
Hi list.

Attempting to use IKImageView to implement a really basic image editor
in my app and I've come across what appears to be a pretty odd
omission: IKImageView never tells you when the image has been edited
and needs saved.  While the object supports a delegate, there's no
documentation on whether it actually implements anything that would
tell me when something changed.

Has anyone come across a solution for knowing when the image has been edited?

Thanks

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: How to develop a Safari event listener

2008-09-29 Thread Jim Turner
Hi Bill

Unless things have changed recently, what you're looking for is called
Not Officially Supported by Safari.  As you discovered, there is no
interface that will allow a plugin to load arbitrarily unless it's
going to provide some sort of media handler for content on the page.

That being said, the WebKit plugin API *can* do what you want, but
it's a bit ugly at best and utilizes a loophole in how plugins can
externally define their MIME types to get the plugin to load.  If you
search Google for Safari and browser with plugins, you'll find some
guidance.

Finally, if you're completely open to all options, things like SIMBL
or Unsanity's Application Enhancer may be an option... but input
managers can get people's feathers ruffled.  Plus, there could be a
large discussion on whether input managers will be around much longer
at all (which I won't start here).  In short, use them at your own
risk.

-- 
Jim
http://nukethemfromorbit.com



On Sun, Sep 28, 2008 at 8:43 PM, Bill Morgan [EMAIL PROTECTED] wrote:
 Hi to all,


 I am trying to develop a small tool, it can be an appliction/bundle/plug-in
 ... The goal is, when Safari opens certain web page, like www.apple.com, the
 tool will be launched automatically, and it can get the page's url.  I know
 for firefox, people call this kind of tool as add-on, not sure what it's
 exactly called for Safari.


 I tried to do it with Web Kit plug-in. But as I learned, Web Kit plug-in
 only works when the web page has certain embed tag, like 'mov', that was
 defined in the MIME type that the plug-in registered for. But in my case, I
 want the tool to work for any web page Safari opened.


 Any one has any suggestion on how to do this?


 thank you all for your kind support!


 Bill
 ___

 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/jturner.lists%40gmail.com

 This email sent to [EMAIL PROTECTED]

___

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 [EMAIL PROTECTED]


Re: Core Data Form

2008-09-05 Thread Jim Turner
Jon,

First off, unless you're doing something special you don't need to
create custom classes for each entity.  If your managed object really
is just slinging strings, leave the class as NSManagedObject and
create a new entity with:

NSManagedObject *hostObj = [NSEntityDescription
insertNewObjectForEntityForName:@Host inManagedObjectContext:[[NSApp
delegate] managedObjectContext]];

then set the values on that object with:

[hostObj setValue: hostString forKey:@hostStringKey];
etc...

Second, your +(id)addHostFromPanel: method is a class method yet
you're asking for [self managedObjectContext], which is an instance
method.  Basically, you don't have a properly initialized managed
object at the time you asked for the context it's in.

If you're set on sticking with the class method, you could do
something like the following:

// Written in TextEdit, forgive the formatting
+(id)addHostFromPanel:(NSString *)hostPanel name:(NSString *)hostName
ipAddress:(NSString *)ipAddress group:(NSString *)group
inManagedObjectContext:(NSManangedObjectContext *)objContext
{
self = [super insertNewObjectForEntityForName:@Host
inManagedObjectContext:objContext];
if( self != nil )
{
[self setValue:hostName forKey:@hostNameKey];
etc...
}

return( self );
}


I'm not much of a CoreData ninja but I hope that helps.

Jim

On Thu, Sep 4, 2008 at 6:01 AM, Jon Buys [EMAIL PROTECTED] wrote:
 Hello,

 I have a problem with my app that is most likely very simple for someone
 with experience.  I have a core data based application that I would like to
 be able to add objects to via a sheet that drops down when the user clicks
 the + button (or presses Command-N).  On the sheet are two NSTextField and
 one NSPopUpButton, an add button and a cancel button.  From my AppController
 class I can get the values as strings that are entered into the sheet here:

 - (IBAction)endAddHostSheet:(id)sender
 {

NSString *hostString = [hostNameTextField stringValue];
if ([hostString length] == 0)
{
return;
}
NSLog(@the host name is %@, hostString);

NSString *ipAddressString = [ipAddressTextField stringValue];
if ([ipAddressString length] == 0)
{
return;
}
NSLog(@the ip address  is %@, ipAddressString);

NSString *selectedGroupString = [groupsPopUpButton
 titleOfSelectedItem];
NSLog(@the selected Group is %@, selectedGroupString);

// Do stuff to add to core data here...


[NSApp endSheet:addHostSheet];

//Goodbye, sheet
[addHostSheet orderOut:sender];
 }

 But my question is, how can I add these strings to core data?

 My core data setup is very simple.  I have three entities (one which I'm not
 yet using) named Host, Group, and ContactGroup. Host has attributes
 hostName, ipAddress, and a to-one relationship named group.  Group has an
 attribute groupName, and a to-many relationship named hosts.

 I've defined classes for the Entities, like this:

 #import Cocoa/Cocoa.h
 @class ContactGroup;
 @class Group;

 @interface Host : NSManagedObject {

 }

 @property (readwrite, retain) ContactGroup *contactGroup;
 @property (readwrite, retain) Group *group;
 @property (readwrite, copy) NSString *hostName, *ipAddress, *CPU, *RAM,
 *hardDrive;

 +(id)addHostFromPanel:(NSString *)newHostPanel withName:(NSString
 *)newHostName andIpAddress:(NSString *)newIpAddress inGroup:(NSString
 *)newGroup;


 @end


 I've was trying to add the hosts with the addHostFromPanel method defined
 above (with a + instead of a -), and implemented like this:

 +(id)addHostFromPanel:(NSString *)newHostPanel withName:(NSString
 *)newHostName andIpAddress:(NSString *)newIpAddress inGroup:(NSString
 *)newGroup
 {
// Debug stuff
NSLog(@host name passed over is  is %@, newHostName);
NSLog(@ip address  passed over is is %@, newIpAddress);
NSLog(@the group passed over  is %@, newGroup);

// Here we go!
Host *host = [NSEntityDescription
 insertNewObjectForEntityForName:@Host inManagedObjectContext:[self
 managedObjectContext]];
host.hostName = newHostName;
host.ipAddress = newIpAddress;
host.group = newGroup;

return host;
 }


 But, when I try to call this method from my AppController to add the strings
 to core data, I get an error (as well as a compile warning) that Host can't
 find it's managedObjectContext.

 I'm very new to Cocoa (obviously), and right now I'm very confused.  I'm
 sure I'm missing something very basic here, but I've been stuck on this for
 a couple of weeks now.

 Thanks in advance for any advice.

 Jon
 ___

 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 

NSPredicateEditorRowTemplates and preserving user input

2008-08-29 Thread Jim Turner
Hi List,

I noticed something today while building a new popup-popup-popup
template: when the user changes the comparator (a simple is/is not in
my case), the third popup resets itself to the default value instead
of maintaining the selection the user had already chosen.  The same is
true if the third view in my template is a text field.  If they enter
text, then change the value from contains to begins with, the text
they've entered is removed.

I understand that templates are copied like mad behind the scenes of
the editor and that popups are treated differently, but I'm not sure
how I go about fixing this.  I tried subclassing NSPopUpButton to see
what is passed for setObjectValue but the editor doesn't seem to like
a subclassed NSPopUpButton.  Instead, it ignores it and displays
nothing.  Very strange.

Any thoughts on where I should start looking?  Thanks

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplates and preserving user input

2008-08-29 Thread Jim Turner
Thanks for the reply Peter.

Just for the archives, my subclassed NSPopUpButton wasn't showing up
because, like you said, it was being treated differently and I was
initializing it with NSZeroRect.  Giving it a starting size and
sending it sizeToFit in templateViews got it on screen.

Jim

On Fri, Aug 29, 2008 at 4:17 PM, Peter Ammon [EMAIL PROTECTED] wrote:

 On Aug 29, 2008, at 8:51 AM, Jim Turner wrote:

 Hi List,

 I noticed something today while building a new popup-popup-popup
 template: when the user changes the comparator (a simple is/is not in
 my case), the third popup resets itself to the default value instead
 of maintaining the selection the user had already chosen.  The same is
 true if the third view in my template is a text field.  If they enter
 text, then change the value from contains to begins with, the text
 they've entered is removed.

 Hi Jim,

 This is a known issue and I don't think there's a workaround yet, sorry.



 I understand that templates are copied like mad behind the scenes of
 the editor and that popups are treated differently, but I'm not sure
 how I go about fixing this.  I tried subclassing NSPopUpButton to see
 what is passed for setObjectValue but the editor doesn't seem to like
 a subclassed NSPopUpButton.  Instead, it ignores it and displays
 nothing.  Very strange.

 If you subclass NSPopUpButton, NSPredicateEditor assumes it has special
 behavior and you want it to be treated like other views.  It's only
 instances of NSPopUpButton themselves that get the different treatment of
 being merged together to build the tree of options.

 -Peter


___

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 [EMAIL PROTECTED]


Re: NSPredicateEditor

2008-06-25 Thread Jim Turner
On Wed, Jun 25, 2008 at 1:08 AM, Chris [EMAIL PROTECTED] wrote:
 Let's say I create a NSPredicateEditor and it looks like this:

 
 [All] of the following are true:
 
 [Name] equals [ ]
 ---

 So the user enters say Fred and the predicate returned is Name == Fred.

 Later on, I reload that predicate into the NSPredicateEditor and it looks
 like this:

 
 [Name] equals [ Fred ]
 ---

 But now there is no option to change it to say:

 [Some] of the following are true:

 because that line isn't shown.

 How do I make that line reappear the next time?

By default, the NSPredicateEditor object in IB creates a compound
predicate.  Wrap your Name == Fred predicate in a compound predicate
before reloading it in the editor and the Any/All/None row should
return.

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate

2008-06-24 Thread Jim Turner
On Tue, Jun 24, 2008 at 2:02 AM, Chris [EMAIL PROTECTED] wrote:
 When the user clicks ok, then I call objectValue on the NSPredicateEditor
 and it calls predicateWithSubpredicates not on object C, but on object
 B, which is always going to be blank, because it is in fact object C
 which is the one displayed. Thus I can never retrieve values from the row.
 This phantom and unexplained object B that is created during NIB loading
 suddenly seems to be the one it cares about.

 I'm not sure where to go next. Has anyone got any advice?

Hi Chris,

I saw this very same behavior and was fortunate enough to get the
following explanation from Peter Ammon:

A single row may be composed of views from multiple templates.  When
it's time to construct a predicate for that row, we pick one template,
and if its views are not actually in the row, we call objectValue on
the view in the row, and then setObjectValue: on the corresponding
view in your template.

Due to a bug, this happens more often than it should :(

What this means for your NSTextField subclass is that it should do the
right thing for objectValue and setObjectValue:.  The object value of
your view should encapsulate all the state your template needs to
compute that portion of the predicate.

The short answer, for me at least, was to make sure my custom
NSTextField in my template handled objectValue/setObjectValue:
properly.  That way, when predicateWithSubpredicates: is called, the
internals of the editor can pass around the values needed to properly
compute the predicate.

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: NSPredicateEditorRowTemplate

2008-06-24 Thread Jim Turner
On Tue, Jun 24, 2008 at 8:46 AM, Chris [EMAIL PROTECTED] wrote:

 Hi!
 This is very interesting information. Wish it was in the doco!
 I have a custom view which wasn't responding to setObjectValue /
 objectValue.
 When I add those methods I find that on startup it does indeed copy the
 values from object C to object B. This means that when I retrieve the
 values later on, instead of returning blank like before, it now returns the
 old value instead of blank. However I need the new value! If it were to copy
 the values across AFTER the user made changes or prior to me calling
 objectValue, then it would work. I thought maybe [rulePredicateEditor
 reloadPredicate] sounded like it might do it perhaps, but that doesn't help
 either. Once the user hits ok, we are still left with bogus values from
 object B, albeit now old values instead of nil values.

How are you accessing your custom view's object value?  It almost
sounds like you're asking your original custom view for it's value
each time instead of the object currently being displayed.

When you create your template and insert your custom view, make sure
to keep a reference to that specific object so you can query it later
on.

@interface CustomPredicateEditorRowTemplate : NSPredicateEditorRowTemplate
{
CustomTextField *myTextField;
}
-(CustomTextField *) myTextField;
@end

@implementation CustomPredicateEditorRowTemplate
-(CustomTextField *) myTextField
{
if( !myTextField )
// init your view

return( myTextField );
}

- (NSArray *)templateViews
{
return( [[super templateViews] arrayByAddingObject:[self myTextField]] );
}

-(void) dealloc
{
[myTextField release];
[super dealloc];
}

- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{
id objectValue = [[self myTextField] objectValue];
// Do magical things with objectValue
}
@end


-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: NSPredicate for a ANY match based on two properties at once

2008-06-20 Thread Jim Turner
On Fri, Jun 20, 2008 at 10:56 AM, Jesse Grosjean
[EMAIL PROTECTED] wrote:
 I'm having a hard time figuring out how to construct a query. The objects
 involved are:

 Entry
- has many tags

 Tag
- name (string)
- value (string)

 I want to construct searches such as:

- find all entries that have a the tag named priority with the
 value 1.

 I can use [NSPredicate predicateWithFormat:@ANY tags.name = %@, tag.name]
 to find all entries that have a particular tag... but I don't know how to
 also figure in the value.

 I don't need this predicate to work with a database, these queries are all
 just being run in memory, with my own custom model objects (not using Core
 Data). If there is no way to do this in a format string, is there some way
 to do it by directly constructing a predicate object?

 Thanks,
 Jesse
 ___


Jesse,

I'm thinking NSCompoundPredicate is what you're looking for.  You
should be able to do something like this:

NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@ANY
tags.name = %@, tag.name];
NSPredicate *valuePredicate = [NSPredicate predicateWithFormat:@ANY
tags.value = %@, tag.value];

NSPredicate *combinedPredicate = [NSComparisonPredicate
andPredicateWithSubpredicates:[NSArray arrayWithObjects:tagPredicate,
valuePredicate,nil]];

If the simple predicateWithFormat: predicates don't work,
NSComparisonPredicates will definitely do what you need (I've never
tried creating a compound predicate with predicateWithFormat:
predicates)

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: NSPredicate for a ANY match based on two properties at once

2008-06-20 Thread Jim Turner
On Fri, Jun 20, 2008 at 2:06 PM, Jesse Grosjean
[EMAIL PROTECTED] wrote:
 I want to construct searches such as:

  - find all entries that have a the tag named priority with the
 value 1.

 NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@ANY
 tags.name = %@, tag.name];
 NSPredicate *valuePredicate = [NSPredicate predicateWithFormat:@ANY
 tags.value = %@, tag.value];

 NSPredicate *combinedPredicate = [NSComparisonPredicate
 andPredicateWithSubpredicates:[NSArray arrayWithObjects:tagPredicate,
 valuePredicate,nil]];

 Thanks, but I don't think this quite works. The problem is that the two ANY
 predicates aren't forced to match against the same tag. So if the potential
 matching entry has multiple tags this query will match if any of those tags
 match the tag name, and if any of the tags values match the tag name, but
 there's no constraint that a the same tag value pair matches both
 constraints.

 Jesse


You are correct, it doesn't work.  And in trying to figure this out,
I've come to realize that I've used predicates the hard way in some
of my code.  Try this instead:

NSPredicate *pred = [NSPredicate predicateWithFormat:@(SUBQUERY(
tags, $x, $x.name = %@ AND $x.value = %@)[EMAIL PROTECTED] != 0),
@aNameToMatch, @aValueToMatch];

Appears that this was a problem in 10.4 and fixed in 10.5.
NSExpression's documentation for
expressionForSubquery:usingIteratorVariable:predicate: has some
discussion about it.

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


NSSearchField in menu item weirdness

2008-05-13 Thread Jim Turner
I have a custom NSView that contains static text and a NSSearchField,
it's your run-of-the-mill attempt to provide live search in a menu, a
la the Apple help menu.

My issue is that while I can get the cursor into the search field, if
I type something other than standard text (arrow keys, home, end,
etc), the search field's action is fired and I receive the character
value of said key.  As you can surmise, this doesn't really return the
right results.  I would like the user to be able to use the down arrow
key to move out of the search field, so I implemented
controlView:textView:doCommandBySelector: for the search field's
delegate to catch moveDown:

This never gets called unless I actually click in the search field.
My custom NSView has this as it's implementation of
viewDidMoveToWindow to move the cursor into the field:

-(void) viewDidMoveToWindow
{
[[self window] makeFirstResponder:searchField];
}

It almost seems like this isn't really making the field the first
responder, at least not in the way that clicking on the field does.
Any thoughts on how to properly assign first responder status to a
text field in a view of a NSMenuItem?

And as a somewhat related question, can one programmatically change
the highlighted item in a menu?  There doesn't appear to be a
selectMenuItemAtIndex: method...

As always, thanks

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: KVO autonotifying complaining about custom setter return value

2008-03-05 Thread Jim Turner
Chris,

On Tue, Mar 4, 2008 at 9:47 PM, Chris Suter [EMAIL PROTECTED] wrote:


  On 05/03/2008, at 2:10 PM, Kyle Sluder wrote:

   On Tue, Mar 4, 2008 at 11:49 AM, Jim Turner
   [EMAIL PROTECTED] wrote:
   In attempting to use a custom setter for a object, I'm getting the
   following message in the console the first time that object is
   instantiated:
  
   KVO autonotifying only supports -setKey: methods that return void.
   Autonotifying will not be done for invocations of -[MyObject
   setValue:]
  
   [snip]
  
   -(void) setValueForBindings:(id)_value
   {
  [self willChangeValueForKey:@value];
  {
  BOOL didSetOK = [self setStringValue:(NSString
   *)_value];
  // Do something with didSetOK
  }
  [self didChangeValueForKey:@value];
   }
  
   Please re-read the second sentence of that error again.  You are
   manually invoking -willChangeValueForKey: and -didChangeValueForKey:
   and KVO is complaining I've already done that!.  Either stop doing
   that, or implement -automaticallyNotifiesObserversForKey: to return NO
   for the bindings key.

Actually, these were never getting called at all.  Read below.


  Implementing -automaticallyNotifiesObserversForKey: will solve the
  problem but just removing the calls to -willChangeValueForKey: and -
  didChangeValueForKey: won't.

  I suspect the real cause of the problem is that there's a setValue:
  method defined in the superclass that returns something.

Actually, there was a -(BOOL) setValue: method in the object itself
that was getting called, I simply didn't see it in there.  KVO/KVC was
finding it instead of my defined setter method, as it should have.

Having +automaticallyNotifiesObserversForKey: return NO for value
stopped the warning, but observation stopped as well, regardless if I
posted will/didChangeValueForKey because my custom setter still wasn't
getting called (the ivar was getting accessed directly)

When I implement +accessInstanceVariablesDirectly and have it return
NO, KVO then complains that my object is now no longer compliant even
though I have valid values for getter and setter defined in the
property declaration.  The object responds to my custom methods but is
missing the connection that the property should be using those as well
instead of the default.

I filed a bug (rdar://problems/5781977) as this doesn't appear to be
proper behavior.  I'd be happy to be told I'm wrong if you can point
out what I'm missing.


  If you're going to be using KVO/KVC on your objects, you should
  probably reconsider whether it's a good idea for your setter/getter
  methods to use non-default names. Obviously, you can change the name
  of your property if it clashes with methods in your superclass.

  - Chris



Thanks

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: KVO autonotifying complaining about custom setter return value

2008-03-05 Thread Jim Turner
On Wed, Mar 5, 2008 at 12:00 PM, mmalc crawford [EMAIL PROTECTED] wrote:

  On Mar 5, 2008, at 9:34 AM, Jim Turner wrote:

   I filed a bug (rdar://problems/5781977) as this doesn't appear to be
   proper behavior.  I'd be happy to be told I'm wrong if you can point
   out what I'm missing.

  I believe this behaves correctly.
  As stated in 
 http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_5.html#
   , Key-value coding and declared properties are orthogonal
  technologies.
  KVC doesn't know about any custom setter you may have defined for a
  property.

  mmalc



Hmm, it appears the developer documentation I have locally on my
machine is slightly out of date.  After reading that link (and the
updated description of setter= and getter=), I see now why what I'm
doing isn't working.  Properties and KVO/KVC aren't complimentary to
each other... although it'd be nice if they were.  I'll have to
re-work my object to get it to be properly compliant.

But, I still appear to have an issue with defining a custom
getter/setter.  Defining a property as

@property (setter=mySetMethod:,getter=myMethod) id valueTest;

and sending my object a valueTest message, I get the unrecognized
selector sent to instance warning.  Reading (and re-reading several
times) 
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_3.html#//apple_ref/doc/uid/TP30001163-CH17-SW17
it appears that I don't need to define anything other than the
@property but unless I also place

-(id) valueTest;
-(void) setValueTest:(id)_value;

in the interface, the object can't find a method signature.

This is a little more confusing that I originally thought. I
appreciate all the help, though.

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]


Re: KVO autonotifying complaining about custom setter return value

2008-03-05 Thread Jim Turner
On Wed, Mar 5, 2008 at 4:14 PM, mmalc crawford [EMAIL PROTECTED] wrote:

  On Mar 5, 2008, at 1:40 PM, Adam P Jenkins wrote:

   If you define a @property in the interface, then in the
   implementation you either need use @synthesize to have the compiler
   automatically generate a getter and setter, or use @dynamic to
   inform the compiler that you will provide the appropriately named
   getter and setter methods.
  
  There is no *need* to specify @dynamic.  In fact, doing so will
  conceal a bug (at least until runtime...) if you don't intend to
  create the appropriate methods at runtime (as do, for example, managed
  objects) but forget to provide an implementation.  If you don't
  specify @dynamic, then the compiler will warn you if you don't supply
  appropriate methods at compile time.


   If you need to define the accessors yourself because the auto-
   generated ones don't do what you want, then use @dynamic instead
   like this:
   @implementation Person
   @dynamic firstName;
  
   - (NSString*)firstName { ... }
   - (void)setFirstName:(NSString *)newName { ... }
   @end

  It's perfectly reasonable also to do either:


  @implementation Person


  - (NSString*)firstName { ... }
  - (void)setFirstName:(NSString *)newName { ... }
  @end


  or, for example:


  @implementation Person
  @synthesize firstName;


  - (void)setFirstName:(NSString *)newName { ... }
  @end


  In the latter case, the compiler will just synthesise -firstName.


  One further issue for the sake of raising it:

  @property (setter=mySetMethod:,getter=myMethod) id valueTest;
  

  Note that this implies that the accessor methods are atomic.  It's
  comparatively rare (unless you're using GC) that Cocoa developers
  implement atomic accessor methods, so you'd typically specify:

  @property (nonatomic, setter=mySetMethod:,getter=myMethod) id valueTest;


  mmalc


Ok first, mmalc, thank you for taking the time to point out exactly
what I needed to see to understand where I was going wrong.  My
problem stemmed from the misguided idea that properties were required
for KVC/KVO.  Chris' comment about using non-default names makes
much more sense now.

Second, for my situation, I ended up with an interface that looks like this:

@property (getter=getValueForBindings, setter=setValueForBindings:,
assign, nonatomic) id value;

And an implementation:

-(void) setValueForBindings:(id)_value
{
[self willChangeValueForKey:@value];
{
 BOOL didSetOK = [self setStringValue:(NSString *)_value];
   // Do something with didSetOK
}
[self didChangeValueForKey:@value];
}

-(id) getValueForBindings
{
return( value );
}

Then binding my interface to the key 'valueForBindings'.  Not the
prettiest, but it's required for my situation.

Thanks again to everyone for all the help.

-- 
Jim
http://nukethemfromorbit.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 [EMAIL PROTECTED]