Re: [BUG?] LSUIElement=YES and NSWorkspaceDidTerminateApplicationNotification

2013-07-31 Thread Peter Ammon

On Jul 31, 2013, at 9:28 AM, Jerry Krinock je...@ieee.org wrote:

 
 On 2013 Jul 31, at 06:32, Stephane Sudre dev.iceb...@gmail.com wrote:
 
 Is it a known bug that the NSWorkspaceDidTerminateApplicationNotification 
 notification is not
 sent for applications whose LSUIElement key is set to YES?
 
 The *behavior* is known, at least by me, and is as you say, Stephane.  The 
 question is: Does Apple consider it to be a bug?
 
 The documentation of NSWorkspaceDidTerminateApplicationNotification states 
 that it is posted when an application finishes executing.  Is an 
 application running with LSUIElement considered to be an application?  
 Unfortunately, NSWorkspace documentation throws out the word application 
 like that in quite a few places without a precise definition.
 
 This is likely one of those cases where it would be safe to assume that Apple 
 will not change (fix) the behavior, because to do so might break apps 
 expecting the old behavior.
 
 Have you filed a bug on this and has there been any response?  If not, I'll 
 file one because I too use this notification and would at least like the 
 behavior to be properly documented.

Yes, NSWorkspace does not post DidTerminate notifications (and a few others) 
for background and UIElement apps. This is one of those historical quirks that 
must be maintained for bug compatibility.

The more modern -[NSWorkspace runningApplications] method gives you a list of 
all applications, including background and UIElement. You can use KVO to 
observe this property, and be notified when apps are launched or terminated.

Hope that helps!




___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Restoring unsaved docs does wrong thing

2013-04-15 Thread Peter Ammon
Hi Steve,

On Apr 12, 2013, at 1:10 PM, Steve Mills smi...@makemusic.com wrote:

 If I have an unsaved doc open in my app (I mean one that has never been saved 
 to disk), and I kill the app, upon relaunch, the OS attempts to restore that 
 document, but it does so incorrectly. First of all, the data was never saved 
 by the new Cocoa autosaving mechanism (we have our own and must use it for 
 now). Second, it creates a new untitled doc by calling our document 
 controller's openUntitledDocumentAndDisplay method. Why would it do that? A 
 new untitled doc with nothing in it has *nothing* to do with what might've 
 been an untitled doc with user changes in it.

If the app unexpectedly crashed or was killed, the system will make a 
best-effort to restore state. If the document was never saved, the best it can 
do is recreate an Untitled document.

 Also, what should I be overriding and returning in my document subclass to 
 ensure that the OS autosaving never happens and prevent it from trying to 
 create new docs on launch like this?

You can mark a window as not restorable in the xib, or by calling [window 
setRestorable:NO]

Hope that helps,
-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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSLayoutConstraints - 2

2013-02-12 Thread Peter Ammon
Ho Koko,

Set the Deployment Target in the xib to 10.5, and you'll get the warning. The 
target is in the File inspector (leftmost tab in the right pane).

On Feb 11, 2013, at 10:46 AM, koko k...@highrolls.net wrote:

 Furthermore, where is the warning that I am building with the 10.8 SDK, 
 deploying 10.5 and that Layout Manager is not available … It is not like I am 
 using an API in my code … this is all IB determined.
 
 Hmmm … -koko
 
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/pammon%40apple.com
 
 This email sent to pam...@apple.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: split views, best practices for 10.8?

2012-12-13 Thread Peter Ammon

On Dec 12, 2012, at 4:20 PM, Chuck Soper chu...@veladg.com wrote:

 Your message helps a lot. Yesterday, I finally got it working. I had been
 trying to load a custom view with constraints from a nib file into the
 cell of an NSTableView which was inside an NSSplitView. By isolating the
 constraints in my custom view, I discovered the errors I was making. That
 is, I first got my custom view working in the contentView of the window,
 then moved it within the NSSplitView, then moved it within an NSTableView
 (in the NSSplitView).
 
 I have what I need for now, but I wanted to let you know that I discovered
 with my implementation that I must call
 setTranslatesAutoresizingMaskIntoConstraints:NO for my programmatically
 created subviews or I get lots of constraint exceptions. I also override
 + (BOOL)requiresConstraintBasedLayout to return YES. For my
 NSTableCellView subclass I do not call
 setTranslatesAutoresizingMaskIntoConstraints: or override
 requiresConstraintBasedLayout. My custom view is a subview of my
 NSTableCellView subclass.

That sounds exactly right.

 
 
 One more question below...
 
 
 On 12/11/12 11:08 AM, Peter Ammon pam...@apple.com wrote:
 On Dec 8, 2012, at 4:19 PM, Chuck Soper chu...@veladg.com wrote:
 
 Hi Peter,
 
 On 11/27/12 6:33 PM, Chuck Soper chu...@veladg.com wrote:
 On 11/27/12 2:11 PM, Peter Ammon pam...@apple.com wrote:
 
 Hi Chuck,
 
 Autolayout works well with NSSplitView in 10.8.
 
 Perfect. Thanks for that confirmation.
 
 Does that mean that in 10.8 (and not 10.7) that it's fine to call
 setTranslatesAutoresizingMaskIntoConstraints:NO for subviews of
 NSSplitView?
 
 For controls that have traditionally positioned their subviews, like
 NSTableView, NSSplitView, NSTabView, you can think of them as owning the
 translatesAutoresizingMaskIntoConstraints properties of its subviews, and
 it will set it appropriately depending on whether the view uses
 autolayout or not.
 
 When you say controls that have traditionally positioned their subviews,
 like NSTableView is 'their subviews' referring to NSTableCellView but NOT
 a programmatically created subview within NSTableCellView? For my case,
 this was true.

Right, that's what I mean.

 
 I did read the Adopting Auto Layout section in the Cocoa Auto Layout
 Guide but I think that I need to re-read the section. The info in the
 Adopting Auto Layout section seems critical to developers writing new
 10.8 applications, and the title and the fact that it's the last section
 of the guide suggests that the info is only applicable to adopting Auto
 Layout for existing apps.
 

Thanks, that's good feedback.
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: split views, best practices for 10.8?

2012-12-11 Thread Peter Ammon

On Dec 8, 2012, at 4:19 PM, Chuck Soper chu...@veladg.com wrote:

 Hi Peter,
 
 On 11/27/12 6:33 PM, Chuck Soper chu...@veladg.com wrote:
 On 11/27/12 2:11 PM, Peter Ammon pam...@apple.com wrote:
 
 Hi Chuck,
 
 Autolayout works well with NSSplitView in 10.8.
 
 Perfect. Thanks for that confirmation.
 
 Does that mean that in 10.8 (and not 10.7) that it's fine to call
 setTranslatesAutoresizingMaskIntoConstraints:NO for subviews of
 NSSplitView?

For controls that have traditionally positioned their subviews, like 
NSTableView, NSSplitView, NSTabView, you can think of them as owning the 
translatesAutoresizingMaskIntoConstraints properties of its subviews, and it 
will set it appropriately depending on whether the view uses autolayout or not.

In 10.8, NSSplitView will set it to NO for its subviews if it is in the modern 
autolayout mode, because it positions its subviews using autolayout. If you set 
it to NO yourself, it's harmless in 10.8 but will cause problems in 10.7. 
Leaving it alone is fine.

 And, that NSSplitView won't add constraints that conflict with my subviews?

It adds constraints that make sense for a split view. For example, in a two 
pane split view, NSSplitView adds constraints that align the first view's left 
edge is to the split view's left edge, the last view's right edge to the split 
view's right edge, and that make a gap in between the views. So if you tried to 
add constraints that would force one of the views outside of the split view, or 
that would change the order, then you'll get conflicts. This is a good thing, 
because the most likely reason you would add a constraint like that is by 
mistake.

However, you can and should add constraints that complement and enhance 
NSSplitView's layout. For example, you could add a minimum or maximum width 
constraint on one of its subviews; then when the user drags a split or resizes 
the window, it won't  make that view too big or too small. You can also align a 
button outside the split view to one of the views inside it. Plus/minus buttons 
often work this way.

And don't overlook the power of adjusting priorities. If you wanted to prevent 
a split view from clipping a text field, say, you could just raise the text 
field's content compression resistance priority to above that of the split 
view's holding priority. You can do that directly in IB.

By the way, if you're interested in what the constraints are, you can just log 
them out: NSLog(@%@, [splitView constraints]). Though of course these 
constraints are considered internal implementation details, so you should not 
depend on their existence, order, etc.

 
 The Cocoa Auto Layout Guide says not to call
 setTranslatesAutoresizingMaskIntoConstraints:NO for subviews of
 NSSplitView, but I think that's for 10.7 and the statement is no longer
 true for 10.8. Is that correct?

It's harmless to call in 10.8, because as I said above NSSplitView will call it.

 
 
 I had been attempting to use constraints in a subview of NSTableCellView
 (and call setTranslatesAutoresizingMaskIntoConstraints:NO). I was getting
 lots of Unable to simultaneously satisfy constraints exceptions.
 NSTableView was adding NSAutoresizingMaskLayoutConstraint instances that
 were conflicting with my subviews. After I read the Adopting Auto Layout
 section in Cocoa Auto Layout Guide this makes sense. The reason I had
 not read the Adopting Auto Layout section was because I was writing a
 new app for 10.8 and thought the section was specifically for adopting
 existing code for auto layout.


Ah. As you discovered, NSTableView positions its subviews using setFrame:, so 
it's best to not adjust translatesAutoresizingMaskIntoConstraints on subviews 
of NSTableView.

Hope that helps!
-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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: split views, best practices for 10.8?

2012-11-27 Thread Peter Ammon
Hi Chuck,

Autolayout works well with NSSplitView in 10.8.

On Nov 27, 2012, at 10:27 AM, Chuck Soper chu...@veladg.com wrote:

 Hi, I'm writing a Mac app for 10.8 (with Xcode 4.5.2) and I need to
 implement a layout similar to iPhoto. I think that the way to do use an
 NSSplitView with the right view containing another NSSplitView like this:
  [ sourceView | [ contentView | infoView ] ]
 
 
 I considered relying entirely on auto layout and avoiding NSSplitView, but
 it seems like too much work and that NSSplitView provides good
 functionality. Some auto layout sample code shows how to implement a split
 view without using NSSplitView. One WWDC 2012 auto layout session shows
 how to use auto layout to enhance NSSplitView. At the moment, I think that
 using NSSplitView with auto layout is the way to go.
 
 I need to include the follow features:
 1. Constrain the sourceView and infoView to a min/max widths.
 I have this working using auto layout constraints. I haven't yet looked
 into constraining the split position using NSSplitView instance methods.

Adding min/max constraints is the right way to do this. The NSSplitView 
delegate methods will kick you out of autolayout mode.

 
 2. Give the contentView priority (allow it to resize and hold the other
 views) when resizing the window.
 I have this working by increasing the Holding Priority of the Left View of
 the NSSplitView. (I haven't implemented the nested split view yet.)

Sounds good.

 
 
 3. Programmatically show/hide the sourceView and infoView with smooth
 animation. The Reminders app does this very well. I can't figure out how
 to do this. I think that adding and removing constraints in the action
 method to show/hide the sourceView is the correct approach, but I don't
 have that working yet. I noticed that setting the sourceView (the left
 view of an NSSplitView) to zero width using auto layout constraints does
 not cause isSubviewCollapsed:sourceView to return true. I don't know the
 recommended way to programmatically show/hide one view of an NSSplitView.
 Or, if avoiding NSSplitView and using auto layout is a possible solution.

If you want to animate a split view without changing the window size, try this:

- Add a constraint to the view that sets its width equal to its current width
- Call [[constraint animator] setConstant:0];
- Remove the constraint once the animation is done

You could also try using setPosition:ofDividerAtIndex:.

If you want to animate a split view while also changing the window size, adjust 
the holding priority so that the pane that you want to grow has the lowest 
priority, and just resize the window.

 
 
 One more issue:
 My NSWindowController nib file has Use Auto Layout checked. When I
 attempt to add an NSSplitView to the right view of another NSSplitView,
 Xcode/IB adds many suggested constraints that dramatically changes the
 existing behavior of my first NSSplitView, so much so that I don't know
 how to restore or fix it. Has anyone else had problems with this? I see
 two possible solutions:
 a. Turn off Use Auto Layout in the nib file and add this class method to
 the contentView of the window:
  + (BOOL)requiresConstraintBasedLayout { return YES; }
 This prevents IB from messing with my constraints.
 b. Add the nested NSSplitView to its own nib file and programmatically add
 it as a subview to the right view of the other NSSplitView.

Are you sure you need a nested split view at all? A single split view can have 
multiple panes.

Hope that helps!
-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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: initial value of an NSPopupButton shows with delay

2012-08-16 Thread Peter Ammon
Hi Koen,

Is your window set to be visible at launch (i.e. in IB)? Try making it not 
visible at launch, and then ordering it onscreen after the nib is loaded. That 
should allow all the awakeFromNib methods to run before the window appears.

Hope that helps,
-Peter

On Aug 16, 2012, at 3:53 PM, Koen van der Drift koenvanderdr...@gmail.com 
wrote:

 I have an NSPopupButton that is bound to an NSArrayController in IB as 
 follows:
 
 Content - ac.arrangedObjects
 ContentValue - ac.arrangedObjects.name
 SelectedObject - File's Owner.self.currentObject
 
 The ac is bound to entities that are in my CD store (which are created when 
 the app starts up for the first time, following the code example for the 
 Type entity in the Grokking Recipes app from Zarra's Core Data book). I am 
 using the SelectedObject binding so that when the popup is changed, I 
 immediately get the selectedobject from the ac. This works like a charm.
 
 Now when the view first appears, I'd like to set the NSPopupButton to a 
 default value, so I added this to awakeFromNib of my NSViewController to get 
 the entity with the name defaultName:
 
NSManagedObjectContext  *moc = [[NSApp delegate] managedObjectContext];
NSArray *results = [moc fetchObjectsForEntityName: @MyObject 
 withPredicateString: @name == %@, @defaultName];
 
 (that last line is based on this article: 
 http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html)
 
 then I set the currentObject to that entity:
self.currentObject = [results lastObject];
 
 It works, I get the entity with defaultName as the initial value in the 
 popup, but for a split second, I first see something else, as if there is 
 some delay before the popup is set to the correct item.
 
 Is this delay because I do a fetch in my CD store?   If so is there a faster 
 way to do this, to prevent the delay?
 
 - Koen.



___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Window cascading

2012-05-08 Thread Peter Ammon

On May 8, 2012, at 2:01 AM, ecir hana ecir.h...@gmail.com wrote:

 Why's that? Do I have to remember the returned NSPoint and pass it to
 next cascadeTopLeftFromPoint:?

Yes; the usual pattern is:

static NSPoint cascadeLoc = {0, 0};
cascadeLoc = [window cascadeTopLeftFromPoint:cascadeLoc];

The first time this is called (with 0, 0) the window won't be moved, so the 
window's initial position in the nib should be something reasonable (or call 
-center on it before cascade). 

Hope that helps,
-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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: addsubview

2012-04-24 Thread Peter Ammon
Hi koko,

This could be anything from the view is added to the wrong subview to the 
view has a frame that moves it outside of its' parents bounds to the view is 
visible but does not draw anything.

Two powerful tools that will help you with debugging:

- Run with NSShowAllViews set to YES
- Use the _subtreeDescription method to get a list of all your views and where 
they are.

A web search will show you how to do either of those if you're not sure.

Hope that helps.


On Apr 20, 2012, at 9:49 AM, koko k...@highrolls.net wrote:

 I have searched high and low and can find no reason for a subview to not 
 display.  Is this a trivial problem not worthy of list comment or is it truly 
 a difficult problem that cannot be dealt with as easily as more mundane 
 topics found here?
 
 Can you hear my cry for help ... this makes no sense ... 
 
 Oh well, I guess I'll have to rewind and try another approach.  
 
 Ah, ain't Cocoa a great, modern (85?) environment.
 
 -koko
 
 
 
 
 
 
 
 On Apr 20, 2012, at 9:23 AM, koko wrote:
 
 Here is the code that creates and adds the subview The method 
 -makeAndWrapViews is in the custom class of the NSTabViewItem view.
 
 I do get -viewDidMoveToSuperview when addSubview is called.
 
 When the tab is clicked I do get viewdidMoveToWindow
 
 But I never see thev iew!
 
 - (void)makeAndWrapViews
 {
   NSRect frame = [self frame];
   frame.size.width = 288;
   frame.size.height = 259;
 
   m_text = [[NSPDText alloc] initWithFrame:frame];
 
 BOOL text = [NSBundle loadNibNamed:@NSPDText owner:m_text];
 
 if (text) 
   {
   [self addSubview:m_text];
   }
 }
 
 
 
 
 
 On Apr 20, 2012, at 7:56 AM, koko wrote:
 
 Good questions.
 
 As an experiment, in the same method in which I create and add the subview 
 which is not displaying I create an NSButton using the same frame as for 
 the subview.  I add the NSButton and it displays.
 
 So, I am sure the NSTabviewItem view is correct.
 
 As to the subview, I added a delegate method for when the tab is clicked.  
 Breaking there and dumping the subviews I see my subview in the view 
 hierarchy.
 
 This seems such a trivial task that I am quite puzzled.
 
 -koko
 
 
 On Apr 19, 2012, at 9:27 PM, Keary Suska wrote:
 
 On Apr 19, 2012, at 5:34 PM, koko wrote:
 
 I get the view for an NSTabViewItem.
 
 To this view I add a subview.
 
 How do you (in code) identify the correct NSTabViewItem, retrieve the view 
 and add the subview? What is the frame of the subview?
 
 In the debugger displaying the subviews of view I see the subview.
 
 How do you know it is the correct/same subview?
 
 When  the NSTabViewItem displays  the subview is not being shown.  The 
 view does display.
 
 The subview is not set hidden in IB.
 
 Why would I not see the subview?
 
 
 
 Keary Suska
 Esoteritech, Inc.
 Demystifying technology for your home or business
 
 
 
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/koko%40highrolls.net
 
 This email sent to k...@highrolls.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:
 https://lists.apple.com/mailman/options/cocoa-dev/koko%40highrolls.net
 
 This email sent to k...@highrolls.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:
 https://lists.apple.com/mailman/options/cocoa-dev/pammon%40apple.com
 
 This email sent to pam...@apple.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: How to get max size of view according to constraints?

2012-03-20 Thread Peter Ammon
Hello Charles,

It sounds like you have the idea that constraints establish a minimum and 
maximum size on a window (or view), and the window is free to take on any size 
within that range.  When you resize a window, it evaluates the constraints at 
the proposed size. If would make the constraints invalid then it limits the 
size.

This isn't quite right. In fact, a window has the size it has because it is 
constrained to be exactly that size. If there is wiggle room we would say the 
constraints are ambiguous because they do not fully specify the size. That's 
considered a programming error.

As the user resizes a window by dragging it, AppKit modifies those constraints. 
These constraints have the priority NSLayoutPriorityWindowSizeStayPut. If there 
are other constraints with higher priority, they take precedence, and will 
limit the window size. There is no explicit max size calculation: the max 
size falls out of the constraints.

So to answer your question, in most cases it is a bad idea to try to figure out 
the maximum size of a view. It is also a bad idea to call setFrame:, because 
that will be immediately undone the next time -layout runs. Instead, you should 
create width and height constraints for the view, set them, call 
-layoutIfNeeded, and then inspect the resulting size. If you want to allow 
certain other constraints to limit the size, then set a priority for your 
constraint that is lower than that of those other constraints.

By the way, fittingSize does not correspond to the view's minimum size, for the 
same reason.

Hope that helps,
-Peter

On Mar 19, 2012, at 9:20 PM, Charles Srstka cocoa...@charlessoft.com wrote:

 As everyone knows, if you have a view with a bunch of subviews and you’ve got 
 NSLayoutConstraints set up for everything, in many cases you might end up 
 with a minimum or maximum size for the view beyond which the constraints are 
 impossible to satisfy, and if you try to resize the view outside these bounds 
 either in IB or in the actual program (if the view is the content view of a 
 resizable window, for example), the resizing will simply stop at those 
 boundaries.
 
 What I am having trouble figuring out is how to resize such a view in code in 
 such a way that it will respect the constraints. If I try just setting a 
 frame using -setFrame: with a rect which has an illegal size, NSView is all 
 too happy to do that, and then I get an exception and a flood of console 
 warnings about how I just broke my constraints. Now, getting the view’s 
 minimum size by calling -fittingSize and adjusting my frame accordingly is 
 easy enough, but some views can have a maximum size imposed by constraints as 
 well, and I’m having trouble finding a way to find out what it is in code.
 
 I know that this has to be possible, since Interface Builder and NSWindow are 
 both able to gracefully handle cases where one tries to set a frame size 
 outside the boundaries of what the constraints allow, but I haven’t been able 
 to find any -maximumSize or -adjustedSizeForSize: type methods, or any way to 
 figure this out short of wrapping -setFrame: in an exception handler. I’m 
 sure it’s gotta be something fairly obvious, and I’ll probably be embarrassed 
 by the answer, but at the moment I’m a bit stuck.
 
 Anyone know how to do this?
 
 Thanks,
 Charles


___

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

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

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

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

Re: How to get max size of view according to constraints?

2012-03-20 Thread Peter Ammon

On Mar 20, 2012, at 10:01 AM, Charles Srstka wrote:

 On Mar 20, 2012, at 8:16 AM, Richard Somers wrote:
 
 On Mar 19, 2012, at 10:20 PM, Charles Srstka wrote:
 
 As everyone knows, if you have a view with a bunch of subviews and you’ve 
 got NSLayoutConstraints set up for everything, in many cases you might end 
 up with a minimum or maximum size for the view beyond which the constraints 
 are impossible to satisfy, and if you try to resize the view outside these 
 bounds either in IB or in the actual program (if the view is the content 
 view of a resizable window, for example), the resizing will simply stop at 
 those boundaries.
 
 I have worked with constraints in another system and one of the things I 
 learned is that a collection of constraints must be exercised or driven 
 from one extreme to the other in order to have confidence that they are 
 correct. If you have a min or max size condition for the view beyond which 
 the constraints are impossible to satisfy, but this in not what you want, 
 then you need to change the constraints so that you get what you want under 
 all conditions. The constraint engine is mathematically correct and does not 
 lie. So if there is a problem, it is in how you are specifying and arranging 
 the constraints or in the number of constraints you have.
 
 Right, but the problem is that I want to make a view that can be given 
 arbitrary subviews at runtime, and I don’t necessarily know what its subviews 
 and their constraints will be at compile time. What I want is a way to 
 determine the range of sizes that this view can have, at runtime. I can find 
 the minimum size via -fittingSize, but I can’t figure out how to get the 
 maximum size.
 
 Specifically, what I’m trying to do is to make a constraints-aware 
 NSScrollView. You can put whatever views you want in it, and it resizes its 
 document view as appropriate as you resize the NSScrollView (say, by resizing 
 the window it’s in). The idea is, it should attempt to resize the document 
 view to match the size of the scroll view. If the user tries to resize the 
 view smaller than what the constraints will allow, then the scroll bars 
 appear. That part is working, but if the user tries to make the scroll view 
 too big, then everything blows up when my code attempts to stretch the 
 document view out.
 
 What I’m trying to find is the upper limit on the width and height according 
 to the current set of constraints at runtime, when I don’t necessarily know 
 what the subviews or their constraints are.

Here's how I'd recommend approaching the scroll view example via constraints.

1. Establish a required constraint that says your document view's top equals 
the scroll view's top.
2. Establish another constraint that says the height of the document view 
equals the height of the scroll view. Give this constraint a priority lower 
than required. What its priority should be depends on how tightly you want the 
document view to fill the scroll view, i.e. which other constraints it should 
be allowed to break.

By choosing a priority lower than Required, it will not break required 
constraints amongst the subviews, and so it will not cause exceptions.  You 
should be able to do all this without ever calling setFrame: or fittingSize.

Hope this helps. Feel free to ask more questions. Auto layout is very powerful, 
but requires a different way of thinking than the old setFrame: approach.

-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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: No indentation when displaying an icon in an NSMenuItem

2012-03-08 Thread Peter Ammon
The checkmark is the on-state image. Try calling [menuItem setState:NSOnState];

Hope this helps,
-Peter

On Mar 6, 2012, at 5:21 PM, Prime Coderama prime.coder...@gmail.com wrote:

 I am trying to add an icon to only one NSMenuItem item but it is indenting 
 the icon and text by 1 level.
 
 I tried to set the setIndentationLevel to 0 but that doesn't work.
 
 An example of what I am trying to achieve can be seen in the Wireless status 
 bar menu where the tickbox is displayed against the current WiFi your 
 connected to e.g. http://cl.ly/2T362b2I0f1G1O3b3G3z
 
 Any tips are 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:
 https://lists.apple.com/mailman/options/cocoa-dev/pammon%40apple.com
 
 This email sent to pam...@apple.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Is NSRuleEditor worth the learning curve?

2012-01-31 Thread Peter Ammon

On Jan 28, 2012, at 4:23 PM, Erik Stainsby erik.stain...@roaringsky.ca wrote:

 Hello list folks,
 
 I'm struggling with the abstraction and sketchy documentation that surround 
 NSRuleEditor. I feel a need to know that the effort is worthwhile, versus 
 cobbling together something in a table or outline view instead.
 
 The domain I am working in really fits well within the structured rule editor 
 model. I have many lists of finite scope which have an inherent hierarchy and 
 each choice made implies filters for the remaining options.
 
 But I am really confused by the highly flexible model of the rule editor. The 
 toughest part right now is that I am unable to see how the NSRuleEditor 
 instance populates a given row, based on having received either a 
 stringValue, a menuItem or a control/view.  Where in all of this have I the 
 opportunity to establish the layout and orientation of the various widgets 
 for a given row?  
 
 One example I have found (NibBasedSpotlightSearcher.xcodeproj - circa 2006) 
 presents a window in the nib which holds clusters of related controls in a 
 single view. I'm doing the gasping guppy trying to see where in the code 
 those individual controls are addressed, loaded and applied. 
 
 Has anyone got a nakedly simple example of a minimalist use of the 
 NSRuleEditor they could point me to? 


Hi Erik,

Have you considered using the simpler NSPredicateEditor instead? It's worth 
taking a look even if your data model is not directly an NSPredicate, as long 
as you can map to and form NSPredicate.

See the NSPredicateEditorRowTemplate header. NSPredicateEditor populates a row 
based on calling -templateViews and inserting your views into the row.

-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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSSegmentedControl in select any mode not working with textured appearance?

2010-12-10 Thread Peter Ammon

On Dec 9, 2010, at 8:45 AM, Jesper Papmehl-Dufay wrote:

 Hi!
 
 I'm having a bit of trouble with the segmented control.
 I'm trying to use it as a group of check buttons (I set the Mode to Select 
 Any in Interface Builder).
 This works fine as long as I don't set the Style to Textured Rounded or 
 Textured Square in IB. If I do, the control stops drawing the buttons in the 
 selected state; it behaves as if the Mode was set to Select None. (The 
 buttons look pressed while the mouse button is down over them, but when the 
 mouse button is released, the button goes back to not looking selected.)
 This is reproducible for me in a newly created nib file using the Simulate 
 Interface command in IB, so I don't think it's anything I'm doing wrong in my 
 code.
 
 Does anyone know how to get the Select Any mode (tracking mode 
 NSSegmentSwitchTrackingSelectAny) working with the textured appearance 
 (either the NSSegmentStyleTexturedRounded or the NSSegmentStyleTexturedSquare 
 segment style)?
 
 TIA


Hi Jesper,

This control style does not show its selection in the bezel, but instead 
through the blue glow effect applied to template images.  To see the 
selection, you set images that are marked as template through setTemplate:YES.  
They will draw blue when their segment is selected.

Hope this helps,
-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 arch...@mail-archive.com


Re: Set NSSegmentedControl ToolTip

2010-09-27 Thread Peter Ammon

On Sep 27, 2010, at 12:35 PM, k...@highrolls.net wrote:

 Is it possible to set a tool tip for a segment of a segmented control 
 programatically?
 
 That is what would be the receiver of -setToolTip?
 
 Or, how does one get the view for a segment?

Yes, see -[NSSegmentedCell setToolTip:forSegment:].  The contained 
NSSegmentedCell has a more comprehensive API than NSSegmentedControl.

-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 arch...@mail-archive.com


Re: Menus to distinguish Numpad vs normal digit keys

2010-09-27 Thread Peter Ammon

On Sep 27, 2010, at 11:35 AM, Russ wrote:

 I have different menu keys set up in my app for control-4 and 
 control-number-pad-4, but it seems that Cocoa is not distinguishing between 
 the 
 two. (There are several key equivalents in the number-pad area that are used 
 for 
 variants on directional motions, ie left, right, up, down, etc, whereas the 
 usual digit accelerators are used for more usual tasks, so I need to keep the 
 two separate). 
 
 
 The NSMenu setKeyEquivalent routine takes Unicode key codes, right? I'd like 
 to 
 be able to instead specify the key using an Apple key code, ie AK_KP_0..9, 
 which 
 has separate codes for each flavor. 
 
 
 Any suggestions on what/how to override to get the correct functionality?
 
 Thanks


Do you mean that you want to have menu items handle control-4 for the top row, 
but not for the numpad?  If so, the simplest approach is to override either 
-[NSApplication performKeyEquivalent:] or -[NSMenu performKeyEquivalent:] on 
the main menu.  Within your override, inspect the event's virtual key code 
(-keyCode), and return NO for the numpad.

If you mean that you want to have one menu item handle control-4 for the top 
row and a different menu item for the numpad, you'll have to take a more 
complicated route:

- Set the key equivalent like you currently do
- Implement the delegate method -menuHasKeyEquivalent:forEvent:target:action:
- Within that method, check the virtual key code of the NSEvent (that is, the 
-keyCode method)

That should allow you to distinguish between the two events.

A secondary issue that you'll run into is that NSMenu will prevent both items 
from sharing what it thinks is the same key equivalent.  You can work around 
this by giving each item the same action. 

Hope that helps,
-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 arch...@mail-archive.com


Re: App locking up in NSView call

2010-09-27 Thread Peter Ammon

On Sep 27, 2010, at 1:38 PM, Mike Silva wrote:

 We have a simple application with multiple NSView subclasses (like Buttons, 
 TextFields, etc.) that are being updated every couple seconds with status 
 information.  After a couple days of running continuously the application 
 will lock on this stack trace:
 
 Thread 1 (process 145):
 #0  0x96185782 in __semwait_signal ()
 #1  0x9618543e in _pthread_cond_wait ()
 #2  0x961870d8 in pthread_cond_wait$UNIX2003 ()
 #3  0x931d267d in CAViewEndDraw ()
 #4  0x9226c686 in -[NSView 
 _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()
 #5  0x921ccf26 in -[NSView displayIfNeeded] ()
 #6  0x92180bbd in -[NSNextStepFrame displayIfNeeded] ()
 #7  0x92196292 in -[NSWindow displayIfNeeded] ()
 #8  0x921c7764 in _handleWindowNeedsDisplay ()
 #9  0x97439b02 in __CFRunLoopDoObservers ()
 #10 0x973f665d in __CFRunLoopRun ()
 #11 0x973f5d34 in CFRunLoopRunSpecific ()
 #12 0x973f5b61 in CFRunLoopRunInMode ()
 #13 0x96f7efec in RunCurrentEventLoopInMode ()
 #14 0x96f7eda3 in ReceiveNextEventCommon ()
 #15 0x96f7ec28 in BlockUntilNextEventMatchingListInMode ()
 #16 0x9219dc95 in _DPSNextEvent ()
 #17 0x9219d50a in -[NSApplication 
 nextEventMatchingMask:untilDate:inMode:dequeue:] ()
 #18 0x9215f69b in -[NSApplication run] ()
 #19 0x92157735 in NSApplicationMain ()
 #20 0x2aca in start ()
 
 This is running on a 10.6.1 OS X machine.  I searched the archives and 
 googled but there's very little about this.  
 
 Any pointers, hints, or workarounds?

There was an OS bug that can produce that hang.  It was fixed with a software 
update in 10.6.3.

-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 arch...@mail-archive.com


Re: Using NSPredicateEditor with core data

2010-08-13 Thread Peter Ammon

On Aug 13, 2010, at 8:45 AM, Gustavo Pizano wrote:

 Hello all once again.
 
 I have been searching but I hadn't  found something useful, so please before 
 if you know a place I can look at let me know.
 
 I have these 3 Entities 
 
 ExpenditureGroup:
   name
   icon.
 ---
 toExpenditures. -
 
 
 Expenditure
   creationDate
   location
   total
 
 toExpenditureGroup -
 toExpenditureDetails -
 
 
 ExpenditureDetail
   detailDescrb
   subTotal
 --
 toExpenditure -
 
 also I have an arrayController that fetches all the ExpenditureGroup Entities 
 called _expenditureGorupArrayController.
 
 in my predicate editor I added the NSPredicateEditorRowTemplates with key 
 paths for  toExpenditures.location, toExpenditures.creationDate,  
 toExpenditures.total, toExpenditures.toExpenditrueDetails.detailDescrb and 
 finally toExpenditures.toExpenditureDetails.subTotal.
 
 I dunno if those last 2 are ok.. my guess NO.
 
 anyway, when I set the predicate, Im setting into the 
 _expenditureGroupArrayController setFilterPredicate, and pass the predicate I 
 just created, but nothing seems to work.

Hi Gustavo,

It looks like you want your predicate to cross a to-many relation.  Is that 
right?  If so, you need to create a predicate that has an 
NSComparisonPredicateModifier that knows how to cross to-many relations (that 
is, either NSAllPredicateModifier or NSAnyPredicateModifier).

If you're using NSPredicateEditor to create the predicate, then the RowTemplate 
has to know to create a predicate with the right modifier.  Unfortunately you 
cannot yet set that up in IB, but you can do it programmatically, by passing 
the right NSComparisonPredicateModifier to one of the initWith... methods on 
NSPredicateEditorRowTemplate (see its header).

You can also subclass NSPredicateEditorRowTemplate and override 
-predicateWithSubpredicates: to create an NSPredicate with the proper modifier.

Hope that helps, let me know if that's not clear,
-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 arch...@mail-archive.com


Re: Using NSPredicateEditor with core data

2010-08-13 Thread Peter Ammon
You can get the left and right expressions, etc. by calling through to super:

NSComparisonPredicate *superPredicate = [super 
predicateWithSubpredicates:subpredicates];
NSExpression *lhs = [superPredicate leftExpression], *rhs = [superPredicate 
rightExpression];
...

You would return a new predicate constructed from from the pieces of super's 
predicate, except substitute in your own modifier.

-Peter

On Aug 13, 2010, at 3:12 PM, Gustavo Pizano wrote:

 Peter hello, first of all thanks for the reply.
 
 So yes, I need to cross a to-many relationship. let me see if I got this 
 straight because my mind was heading in that same direction you commented, 
 just I didn't know what to use or what was the name of the artifact, in this 
 case the NSComparasionPredicateModifier.
 
 So due the fact that I already have overwritten NSPredicateEditorRowTemplate 
 to enlarge the Floating-Decimal NSTextfield of the right expression, I would 
 take that approach first, overwriden the  predicateWithSubpredicates method 
 and doing the following:
 
 - (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates{
   NSPredicate * predicate = [NSComparasionPredicate 
 predicateWithLeftExpression:(NSExpression *)lhs 
 rightExpression:(NSExpression*)rhs modifier: NSAllPredicateModifier
   
 type:(NSPredicateOperatorType)type options:NSCaseInsensitivePredicateOption];
 }
 
 I don't know what lhs, rhs and type must be. should I pass [[self 
 leftExpresions] objectAtIndex:0] and also for the rightExpresion? or does it 
 comes from the subpredicates parameter?.
 
 sorry I got little confused there... :(
 
 Thx
 
 Gustavo
 
 
 On Aug 13, 2010, at 11:49 PM, Peter Ammon wrote:
 
 
 On Aug 13, 2010, at 8:45 AM, Gustavo Pizano wrote:
 
 Hello all once again.
 
 I have been searching but I hadn't  found something useful, so please 
 before if you know a place I can look at let me know.
 
 I have these 3 Entities 
 
 ExpenditureGroup:
 name
 icon.
 ---
 toExpenditures. -
 
 
 Expenditure
 creationDate
 location
 total
 
 toExpenditureGroup -
 toExpenditureDetails -
 
 
 ExpenditureDetail
 detailDescrb
 subTotal
 --
 toExpenditure -
 
 also I have an arrayController that fetches all the ExpenditureGroup 
 Entities called _expenditureGorupArrayController.
 
 in my predicate editor I added the NSPredicateEditorRowTemplates with key 
 paths for  toExpenditures.location, toExpenditures.creationDate,  
 toExpenditures.total, toExpenditures.toExpenditrueDetails.detailDescrb and 
 finally toExpenditures.toExpenditureDetails.subTotal.
 
 I dunno if those last 2 are ok.. my guess NO.
 
 anyway, when I set the predicate, Im setting into the 
 _expenditureGroupArrayController setFilterPredicate, and pass the predicate 
 I just created, but nothing seems to work.
 
 Hi Gustavo,
 
 It looks like you want your predicate to cross a to-many relation.  Is 
 that right?  If so, you need to create a predicate that has an 
 NSComparisonPredicateModifier that knows how to cross to-many relations 
 (that is, either NSAllPredicateModifier or NSAnyPredicateModifier).
 
 If you're using NSPredicateEditor to create the predicate, then the 
 RowTemplate has to know to create a predicate with the right modifier.  
 Unfortunately you cannot yet set that up in IB, but you can do it 
 programmatically, by passing the right NSComparisonPredicateModifier to one 
 of the initWith... methods on NSPredicateEditorRowTemplate (see its header).
 
 You can also subclass NSPredicateEditorRowTemplate and override 
 -predicateWithSubpredicates: to create an NSPredicate with the proper 
 modifier.
 
 Hope that helps, let me know if that's not clear,
 -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 arch...@mail-archive.com


Re: NStoolbarItem, custom view, setAction:

2010-08-09 Thread Peter Ammon

On Aug 9, 2010, at 5:37 PM, Tony Romano wrote:

[...]
 
 
 Looking at the documentation for NSToolbarItem setAction:, it has a little 
 note: For a custom view item, this method calls setAction: on the view if it 
 responds..   Which I infer to mean, that the basic Custom View should work.  
 What really interesting is NSToolbarItem is derived from NSObject(which is a 
 whole other discussion on this design), so the setAction and setTarget need 
 to get stored somewhere, there are no apparent private variables to store 
 these items. Looking at the toolbar item in the debugger, the object knows 
 that the view doesn't support set/get action because they set some bits on 
 creation and look at the bit setting instead of calling respondsToSelector 
 every time.
 
 Anyone have any ideas as to why I can't use a custom view derived from NSView?

You can set any custom view you want.  However, NSToolbarItem delegates its 
target/action entirely to its view, and has no storage for these properties.  
If your view does not implement -target or -action, then the toolbar item's 
target and action will both be NULL.

Hope this helps,
-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 arch...@mail-archive.com


Re: NSMenuDelegate menuDidClose called before NSMenuItem's action?

2010-06-25 Thread Peter Ammon

On Jun 25, 2010, at 2:58 PM, augusto callejas wrote:

 hi-
 
 i'm constructing an NSMenu with a delegate to handle menuDidClose.
 that menu has an NSMenuItem that had an action to handle when its selected.
 when i select the menu item from the menu, it calls menuDidClose, and then
 the action of the NSMenuItem.  i would expect the other order, but the 
 documentation
 doesn't state what order these messages are sent.  is there a way to specify 
 what
 order these messages are sent?
 
 thanks,
 augusto.___

Hi Augusto,

The menu always closes before the action is sent.  Imagine the user choosing 
File-Open:  if the action were sent before the menu was closed, the File menu 
would remain open until the Open panel is dismissed.

If you want to be notified after the action is sent, perhaps you want 
NSMenuDidSendActionNotification.

Hope this helps,
-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 arch...@mail-archive.com


Re: NSMenuDelegate menuDidClose called before NSMenuItem's action?

2010-06-25 Thread Peter Ammon
Unfortunately this isn't as easy as it should be.  Since the menu action can do 
anything, including trigger menu tracking again, it really does need to happen 
last.

I think your best option is to use performSelector:afterDelay: from within 
menuDidClose:.

Another possibility is to tie the lifetime of your resources to the menu items 
themselves (e.g. set them as the represented object of the menu item).  In 
SnowLeopard, we support the scenario of an NSMenuItem being removed from the 
menu after the item is selected by the user, but before the item's action 
fires.  This allows you to tear down the menu (for example, in 
NSMenuDidEndTrackingNotification): the NSMenuItem will be retained until its 
action fires.  However, this does not work in Leopard and earlier.

-Peter

On Jun 25, 2010, at 3:41 PM, augusto callejas wrote:

 peter-
 
 actually i wanted to be notified before the menu is closed,
 because i'm freeing some resources when the menu is closed,
 but i'm depending on those resources to be around when it
 comes time to execute the menu item's action.  perhaps
 i can't free those resources and need to take care of that
 somewhere else?
 
 thanks,
 augusto.
 
 On Jun 25, 2010, at 3:26 PM, Peter Ammon wrote:
 
 
 On Jun 25, 2010, at 2:58 PM, augusto callejas wrote:
 
 hi-
 
 i'm constructing an NSMenu with a delegate to handle menuDidClose.
 that menu has an NSMenuItem that had an action to handle when its selected.
 when i select the menu item from the menu, it calls menuDidClose, and then
 the action of the NSMenuItem.  i would expect the other order, but the 
 documentation
 doesn't state what order these messages are sent.  is there a way to 
 specify what
 order these messages are sent?
 
 thanks,
 augusto.___
 
 Hi Augusto,
 
 The menu always closes before the action is sent.  Imagine the user choosing 
 File-Open:  if the action were sent before the menu was closed, the File 
 menu would remain open until the Open panel is dismissed.
 
 If you want to be notified after the action is sent, perhaps you want 
 NSMenuDidSendActionNotification.
 
 Hope this helps,
 -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 arch...@mail-archive.com


Re: Initiating drag and drop from NSToolbarItem

2010-06-22 Thread Peter Ammon

On Jun 22, 2010, at 6:56 PM, Gideon King wrote:

 Hi, I have a toolbar item that I want to use for having an item that I drag 
 onto my main view. I can initiate the drag from my custom view, but the 
 window gets moved by the mouse down/dragged. I'm sure this will be trivial, 
 but can't think of how to do this...I've overridden mouseDown: and 
 mouseDragged: in my view, but the window still gets dragged.
 
 How do I stop the window being dragged?

Sounds like you want to override -mouseDownCanMoveWindow to return NO. 

Hope this helps,
-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 arch...@mail-archive.com


Re: Service without Icon or Window?

2010-06-15 Thread Peter Ammon

On Jun 15, 2010, at 2:56 PM, Lightning Duck wrote:

 I need to make an application  that runs a bit as a 'service' if you will.  
 Not in the sense of running from the Services menu but something the tuns 
 continually in the background with an Icon in the Dock or a Window of it's 
 own, that monitors when files are added or removed from a directory
 
 So basically I have two requirements
 
 Monitor the contents of a directory
 
 Run without visibility?
 
 Can anyone send me to some pointers for how to do either, or both, of these 
 tasks?

It sounds like you want a launchd agent.  launchd can launch your program when 
certain paths are modified, via the WatchPaths or QueueDirectories info plist 
keys.

The advantage of this approach is that your process does not have to run 
continuously in the background: it's launched on-demand, and can exit when it's 
finished.

-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 arch...@mail-archive.com


Re: Activating application raises windows meant to be invisible

2010-05-27 Thread Peter Ammon
If a window is ordered out, AppKit will not order it back in when the app is 
activated.  Is it possible that a different window is created, or that the 
window was not ordered out to begin with?

I'm confused when you say that an ordered-out window is the key window.  That 
should not be possible.

Is it possible that one of the windows is set to hide on deactivate?  The 
visibility of hideOnDeactivate windows is controlled by the window server.  A 
window that is hideOnDeactivate does not get ordered out when the app is 
deactivated: it is merely hidden.

Hope this helps,
-Peter

On May 27, 2010, at 5:44 AM, David Reitter wrote:

 How can I keep invisible windows invisible when my application is raised?
 
 My application can end up with only one NSWindow A that is invisible 
 ([NSWindow orderOut]).  This window is the key window.  The application may 
 also have other windows (B) that are iconified.
 
 I find that when switching back to the application, window A is always made 
 visible (provided I am on the same Space as the window).  How do I control 
 that?
 I would get my application to de-iconify B instead.
 
 Window A is raised even before my 
 applicationShouldHandleReopen:hasVisibleWindows: are 
 applicationDidBecomeActive: are sent.  I have also unsuccessfully tried to 
 implement [NSWindow orderFront] to override the behavior.
 
 How would I got about keeping the window hidden?
 
 Thanks for your help.___
 
 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/pammon%40apple.com
 
 This email sent to pam...@apple.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: Displaying NSPopUpButtonCells in NSTableView

2010-05-20 Thread Peter Ammon

On May 20, 2010, at 1:14 PM, James Maxwell wrote:

 I thought I'd change the topic on this, since the content really has changed.
 
 I have an table for setting up MIDI instruments with a name, port, and 
 channel. I've got the initial display of options for the table row displaying 
 correctly, and when I make changes to the name, port, and channel, the data 
 object is updated correctly. The only thing left is that the popups in 
 columns 2 and 3 are not holding the selected value. I understand that this is 
 probably because I'm reloading the menu in 
 tableView:objectValueForTableColumn:row, but I'm not sure how to get around 
 it. 
 
 Here's the code I've got so far. I'm not using an NSArrayController, because 
 that approach was driving me absolutely mental...
 I've copied all the code (except imports) to be thorough. Logging Edited 
 MIDIInstrument at the end shows that the instrument is set up correctly, 
 with the desire name, port, and channel. It's just that the popups always 
 display the 2nd item.

Hi James,

If you have a table view containing an NSPopUpButtonCell, the object value 
returned by your objectValueForTableColumn: method should be an NSNumber, which 
contains the index of the item that should be selected.  It looks like the 
attached code is returning the cell itself, which is strange, and I think 
that's causing the problem.

Hope this helps,
-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 arch...@mail-archive.com


Re: Process type

2010-04-30 Thread Peter Ammon

On Apr 30, 2010, at 1:18 PM, Matthew Mashyna wrote:

 I have an app that acts as a monitor for some other critical apps and one 
 thing the spec calls for is the need to look at other running apps and figure 
 out if they are running in 32 or 64 bit mode. The Activity monitor knows 
 this. How can I find a process's bit-ness? Sorry, not sure it if qualifies as 
  Cocoa question. If not can someone recommend a more appropriate list?
 
 Thanks,

On SnowLeopard, see the executableArchitecture property of the 
NSRunningApplication class.  On Leopard and earlier, you'll have to use the 
Process Manager or Darwin-level functionality.

-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 arch...@mail-archive.com


Re: Filling edges of NSView-customized NSMenu

2010-04-22 Thread Peter Ammon

On Apr 22, 2010, at 3:33 AM, Yuriy Shevyrov wrote:

 Hi all,
 
 
 
 Does exist any way to fill top and bottom edges of pop-up NSMenu in a 
 specified color? 
 
 
 
 I perform porting of one carbon application to cocoa, to be 64-bit 
 compatible. The problem is that the old application has dark-background 
 menus, and when I tried to do the same thing under cocoa I found that no way 
 exist to do so. I'm able to fill background of place where my NSView is drawn 
 but I can't customize drawing of top and bottom edges/corners and they remain 
 white. 
 
 

No, sorry, this isn't possible yet.

-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 arch...@mail-archive.com


Re: Carbon pasteboard/service events not firing in Cocoa app

2010-04-20 Thread Peter Ammon

On Apr 19, 2010, at 7:46 AM, Kevin Walzer wrote:

 I'm trying to port some Carbon code that provides basic services menu 
 integration to a Cocoa application. This code implements the basic Carbon 
 event handlers for this functionality, cf:
 
 const EventTypeSpec carbonServiceEvents[] = {
  { kEventClassService, kEventServiceGetTypes },
  { kEventClassService, kEventServiceCopy },
  { kEventClassService, kEventServicePaste },
  { kEventClassService, kEventServicePerform }
 };
 
 
 I understand that Cocoa has its own NSServices protocol/API, but these 
 particular events and the Pasteboard API are still supported and not 
 deprecated under Cocoa and 64-bit. The basic structure is here:
 
 http://developer.apple.com/carbon/pasteboards.html
 
 The code is mostly working: other applications can send clipboard data to my 
 app's service, and it will function as expected. However, inside my 
 application, the kEventServiceCopy event never fires. As a result, the 
 Services menu is completely grayed out.
 
 I'm not sure how to fix this. In my Carbon application, simply installing 
 these event handlers made the Services menu available. It's not clear to me 
 why the kEventServiceCopy event does not fire, but the kEventServiceGetTypes 
 event (necessary to determine if my app provides a service) and 
 kEventServicePerform (to perform the service) do fire.
 
 Any advice is appreciated.
 
 --Kevin


Hi Kevin,

These events only fire in an app with a Carbon menu bar.  If your menu bar is 
Cocoa (that is, you install it with -[NSApplication setMainMenu:]) then you 
will need to implement the Cocoa Services APIs.

-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 arch...@mail-archive.com


Re: MainMenu.nib won't load

2010-04-10 Thread Peter Ammon
Hi Ulf,

The first instance of NSDocumentController (or a subclass) becomes the shared 
instance.  It sounds like some code is instantiating an instance of 
NSDocumentController before your class, so the shared instance is of the base 
class instead of your subclass.  I don't know what would be causing that, but 
you might look in your code for direct messages to NSDocumentController, 
instead of your subclass.

Good luck tracking it down,
-Peter

On Apr 10, 2010, at 2:43 AM, Ulf Dunkel wrote:

 I am kind of stuck with a support question which I cannot explain myself. If 
 someone in this list can give me a hint, I would be more than happy. If this 
 list is the wrong place to ask for this issue, please excuse (and point me to 
 the right place, if possible).
 
 One of our customers cannot use our pure Cocoa app Barcody properly. He 
 complains that several menu items cannot be used. (And of course he is the 
 first and only one who complains about this.)
 
 Console.app tells us this (on his Mac OS X 10.6.3 machine):
 
 - snip -
 4/7/10 8:44:12 AM Barcody[83923]  Could not connect the action 
 showPreferences: to target of class NSDocumentController
 4/7/10 8:44:12 AM Barcody[83923]  Could not connect the action 
 showCreditsWindow: to target of class NSDocumentController
 4/7/10 8:44:12 AM Barcody[83923]  Could not connect the action gotoToReg: 
 to target of class NSDocumentController
 4/7/10 8:44:12 AM Barcody[83923]  Could not connect the action visitURL: 
 to target of class NSDocumentController
 4/7/10 8:44:12 AM Barcody[83923]  Could not connect the action 
 stopModalDialog: to target of class NSDocumentController
 - snap -
 
 So it looks like the MainMenu.nib won't load properly on his machine. 
 Although he is the only one who has this issue, I would be able to understand 
 WHY this can happen.
 
 Could we have done something wrong using the MainMenu.nib? Are there any 
 known issues with Snowy and NSDocumentController?
 
 If you want to check the Barcody Resources, just grab the multi-lingual app 
 from here:
 
 http://www.dsd.net/prod/mac/barcody.php?lan=enpmode=download
 
 (And yes, it happens whatever language and country he sets in his System 
 Prefs.)
 
 Clueless,
 Ulf Dunkel
 ___
 
 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/pammon%40apple.com
 
 This email sent to pam...@apple.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: Toolbar customizer crashes on Leopard when using menu delegate

2010-03-25 Thread Peter Ammon

On Mar 25, 2010, at 9:10 AM, Markus Spoettl wrote:

 Hi Peter,
 
 On Mar 24, 2010, at 11:13 PM, Peter Ammon wrote:
 Yes, this is a known problem on Leopard.  The issue is that when NSToolbar 
 shows the customization palette, well, a view can't be in the toolbar and 
 the customization palette simultaneously, so NSToolbar copies the popup 
 via NSKeyedArchiver.  Unfortunately, NSMenu's encodeWithCoder: method 
 encodes its delegate unconditionally, and if the delegate doesn't implement 
 NSCoding, you get an exception.
 
 In SnowLeopard, NSToolbar was revamped to render the views into images and 
 show the images - not the views - in the customization palette.  So 
 NSToolbar in SnowLeopard no longer copies views, which is why the problem 
 does not reproduce.
 
 I think the easiest workaround is to implement NSCoding on your NSMenu 
 delegate.  The delegate doesn't have to do a very good job encoding itself, 
 because the delegate will not actually be used in the customization palette. 
  In fact, you may be able to get away with implementing 
 replacementObjectForCoder: on your delegate to just return nil.
 
 
 Thanks a lot for the detailed explanation. Something else must be playing 
 into this because my delegate is an NSWindowController subclass which already 
 conforms to the NSCoding protocol. A second instance actually gets created 
 during the customizer setup, but it's dealloc'd before the crash happens.

Delegates aren't retained by the menu, so when NSToolbar copies the menu, it 
will create a new instance of your delegate which will then soon be deallocated 
because nothing retains it.  If the delegate isn't removed from the menu, then 
the menu will crash when it tries to talk to the delegate.  So another fix 
would be to remove your delegate from the menu in the -dealloc method.

-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 arch...@mail-archive.com


Re: Toolbar customizer crashes on Leopard when using menu delegate

2010-03-24 Thread Peter Ammon
Hi Markus,

Yes, this is a known problem on Leopard.  The issue is that when NSToolbar 
shows the customization palette, well, a view can't be in the toolbar and the 
customization palette simultaneously, so NSToolbar copies the popup via 
NSKeyedArchiver.  Unfortunately, NSMenu's encodeWithCoder: method encodes its 
delegate unconditionally, and if the delegate doesn't implement NSCoding, you 
get an exception.

In SnowLeopard, NSToolbar was revamped to render the views into images and show 
the images - not the views - in the customization palette.  So NSToolbar in 
SnowLeopard no longer copies views, which is why the problem does not 
reproduce.

I think the easiest workaround is to implement NSCoding on your NSMenu 
delegate.  The delegate doesn't have to do a very good job encoding itself, 
because the delegate will not actually be used in the customization palette.  
In fact, you may be able to get away with implementing 
replacementObjectForCoder: on your delegate to just return nil.

Hope that helps,
-Peter

On Mar 23, 2010, at 7:02 PM, Markus Spoettl wrote:

 Hello,
 
  I've been running into a strange crash for a toolbar customizer that happens 
 only on Leopard and works fine on Snow Leopard. 
 
 My toolbar contains an item hosting a NSPopUpButton which has a menu. That 
 menu contains regular items and a sub-menu which has its delegate assigned to 
 the File's Owner because it's dynamic and needs to be rebuilt each time it is 
 displayed. I have found out that the mere fact the delegate is set causes a 
 crash when the toolbar customizer is created (through Customize Toolbar…). 
 
 Ultimately the whole thing goes down badly inside AppKit (I'm pasting the 
 stack below if someone wants to take a look at it). In the process of digging 
 into this issue I also found that setting the delegate causes the entire nib 
 to be loaded again - probably to resolve the delegate, kind of recursive. 
 
 Well, I just thought this would be interesting for the list, since it's 
 working completely fine on Snow Leopard but not on Leopard (Deployment Target 
 of this project is 10.5). Unless of course this was foreseeable in which case 
 I'd like to hear about it.
 
 Regards
 Markus
 
 
 Thread 0 Crashed:
 0   libobjc.A.dylib   0x9173e699 objc_msgSend + 41
 1   com.apple.AppKit  0x947cb9fa -[NSMenu encodeWithCoder:] + 
 444
 2   com.apple.Foundation  0x9526138d _encodeObject + 621
 3   com.apple.AppKit  0x947cd08f -[NSMenuItem 
 encodeWithCoder:] + 1563
 4   com.apple.Foundation  0x9526138d _encodeObject + 621
 5   com.apple.Foundation  0x952d1bdd -[NSKeyedArchiver 
 _encodeArrayOfObjects:forKey:] + 541
 6   com.apple.Foundation  0x952815a7 -[NSArray(NSArray) 
 encodeWithCoder:] + 615
 7   com.apple.Foundation  0x9526138d _encodeObject + 621
 8   com.apple.AppKit  0x947cb916 -[NSMenu encodeWithCoder:] + 
 216
 9   com.apple.Foundation  0x9526138d _encodeObject + 621
 10  com.apple.AppKit  0x9481e547 -[NSPopUpButtonCell 
 encodeWithCoder:] + 269
 11  com.apple.Foundation  0x9526138d _encodeObject + 621
 12  com.apple.AppKit  0x94503809 -[NSControl 
 encodeWithCoder:] + 349
 13  com.apple.Foundation  0x9526138d _encodeObject + 621
 14  com.apple.Foundation  0x95260b08 +[NSKeyedArchiver 
 archivedDataWithRootObject:] + 184
 15  com.apple.AppKit  0x948f91b9 -[NSToolbarItem 
 _copyOfCustomView] + 47
 16  com.apple.AppKit  0x948f9278 -[NSToolbarItem 
 copyWithZone:] + 141
 17  com.apple.CoreFoundation  0x934e2f9a -[NSObject copy] + 42
 18  com.apple.AppKit  0x9449585a -[NSToolbar 
 _newItemFromItemIdentifier:requireImmediateLoad:willBeInsertedIntoToolbar:] + 
 306
 19  com.apple.AppKit  0x94495649 -[NSToolbar 
 _insertNewItemWithItemIdentifier:atIndex:notifyDelegate:notifyView:notifyFamilyAndUpdateDefaults:]
  + 86
 20  com.apple.AppKit  0x944ee904 -[NSToolbar 
 _appendNewItemWithItemIdentifier:notifyDelegate:notifyView:notifyFamilyAndUpdateDefaults:]
  + 104
 21  com.apple.AppKit  0x94497227 -[NSToolbar 
 _setCurrentItemsToItemIdentifiers:notifyDelegate:notifyView:notifyFamilyAndUpdateDefaults:]
  + 336
 22  com.apple.AppKit  0x948f18eb -[NSToolbar 
 _loadInitialItemIdentifiers:requireImmediateLoad:] + 138
 23  com.apple.AppKit  0x948f7e93 -[NSToolbarConfigPanel 
 _loadDefaultSetImageRep] + 861
 24  com.apple.AppKit  0x948f6d6b -[NSToolbarConfigPanel 
 _loadData] + 500
 25  com.apple.AppKit  0x948f674d -[NSToolbarConfigPanel 
 initForToolbar:withWidth:] + 269
 26  com.apple.AppKit  0x948f1e45 -[NSToolbar 
 _runCustomizationPanel] + 214
 27  com.apple.AppKit  0x943d7e8f -[NSApplication 
 sendAction:to:from:] + 112
 28  

Re: Key-Value Observing speed

2010-03-12 Thread Peter Ammon

On Mar 12, 2010, at 9:35 AM, Gwynne Raskind wrote:

 While profiling a project I'm working on, I found that while most of my time 
 was being spent in glFlush() (which is completely expected for an 
 OpenGL-based game), a non-trivial amount of time is being spent in dozens of 
 KVO internal methods and functions. Most especially, I noticed that KVO (or 
 possibly the KVC beneath it) makes heavy use of NSInvocation-based 
 forwarding, which is known to be the slowest possible code path for message 
 dispatch.
 
 KVO is central to my code's structure; I rely on it for everything to know 
 what everything else is doing without sprinkling manual notifications all 
 over the code. Is there any way to trick the runtime into taking some faster 
 code paths? It's really troublesome to see property setter methods taking up 
 almost as much total time as the audio converter thread in Instruments. Would 
 it help if my properties were sets of integers instead of structures 
 (specifically, NSPoint and NSRect are used quite a bit)? Would it be just 
 blindly insane to think that a NSRectObject would be faster somehow than a 
 plain NSRect because of the structure return trickery the runtime has to do?
 
 And if there's nothing I can do with Apple's KVO, is it even remotely 
 realistic to consider writing my own quickie version of KVO that takes faster 
 paths since I can tweak it for my uses?
 
 (Side note, Michael Ash's MAKVONotificationCenter has been a panacea for all 
 manner of minor issues I've had with the KVO implementation, kudos Mike!)
 
 Please, no one say I shouldn't be writing a game with Objective-C; KVO is the 
 only thing that's tripped me up speed-wise about it. (Well, that and the 
 audio threads doing a heck of a lot of sound processing, I keep wondering if 
 I can put my WAV files into some format that requires less CA conversion or 
 whether it's NSSound forcing that on me...)
 
 -- Gwynne

I think KVO only uses NSInvocation when setting or getting non-standard 
aggregate types.  So if your property is any primitive C type, any ObjC object, 
or an NSPoint, NSRect, NSRange, or NSSize, then it will not use NSInvocation.  
If it's a custom struct it will.  Does that seem plausible based on what your 
property types are?

If not, it would be helpful to post a backtrace for the call to +[NSInvocation 
invocationWithMethodSignature:], so we can figure out what's happening.

-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 arch...@mail-archive.com


Re: NSPredicateEditorRowTemplate and dynamic templateViews

2010-03-12 Thread Peter Ammon

On Mar 12, 2010, at 1:47 PM, Dave DeLong wrote:

 Hi everyone,
 
 I'm trying to build a custom predicate editor row template that lets me do 
 predicates like in the last 30 days or since {aDate}.  For the simple 
 date comparison, I'm returning an NSDatePicker as the third view in my 
 templateViews.
 
 My problem is that I only want to return the NSDatePicker if the operator is 
 =, !=, , =, , or =.  If the operator is in the last (a custom 
 operator), I want to return 4 template views: the first two being the 
 standard keypath + operator views, but the last two being an NSTextField 
 (with NSNumberFormatter attached) and an NSPopUpButton (with the units: days, 
 weeks, months, etc).
 
 I thought that I'd just be able to check which item was selected in the 
 operators popup and return the appropriate views based on the current 
 operator.
 
 Unfortunately, it seems like the predicateEditor invokes templateViews 
 *before* the operator actually changes.  In other words, if the operator is 
 =, and I switch it to =, then when templateViews is invoked, the operators 
 popup still says =, and won't say = until it's changed again.
 
 So my question is this:  how can I dynamically modify my row's templateViews 
 to accurately reflect the current operator?  I *could* post a notification 
 from the RowTemplate that the editor needs redrawing, and then have my 
 controller capture that notification and invoke reloadPredicate on my 
 predicate editor, but that seems like a really hackish work-around.
 
 Any recommendations?
 
 (for an example of what I'm describing, try creating a new smart playlist in 
 iTunes and fiddling around with the operators corresponding to the Date Added 
 attribute)
 
 Thanks!

What you want to do here is to create two separate templates.  One looks like 
this:

[Creation Date, Modification Date]  [=, !=, , =, , =]   
{NSDatePicker}

The other looks like this:

[Creation Date, Modification Date]  [in the last]   {NSTextField}   
[days, weeks, months]


The first template is responsible for predicates with the standard operators, 
and the second one is responsible for predicates with the custom operator.  At 
runtime, NSPredicateEditor will merge the templates together, and the second 
popup will show a union of all the operators of your date templates.

Hope that helps,
-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 arch...@mail-archive.com


Re: Can you obtain the NSRuleEditor localized display?

2010-03-10 Thread Peter Ammon

On Mar 10, 2010, at 11:30 AM, John C. Daub wrote:

 
 Can you obtain the localized display of an NSRuleEditor?
 
[...]

 I can't see any way to extract the actual displayed GUI (post-formatting),
 other than obtaining the criteria or displayValues myself, obtaining the
 formattingDictionary myself, and doing all the heavy lifting.
 
 Hoping I may be overlooking something or maybe there's a nice trick I could
 use. I need to run on 10.5, but if there's a 10.6-and-later-only solution
 that could be acceptable.

Sorry, there's no easy way to do this.

___

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: Overriding NSMenuItem's drawing

2010-02-17 Thread Peter Ammon

On Feb 17, 2010, at 8:30 AM, Tom Davie wrote:

 I need an NSMenuItem that rather than drawing an NSImage in it's cell draws
 *part* of an NSImage, is it possible to override NSMenuItem's drawing in any
 way to achieve this?  I don't see the relevant methods.

Can't you just make a different NSImage containing part of the original?  If 
you are worried about performance, you can make a custom NSImageRep that 
references the original image.

___

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: Showing a menu after a delay...?

2010-02-01 Thread Peter Ammon
Hi Eric,

Consider using a single-segment NSSegmentedControl.  If the NSSegmentedControl 
has both an action and a menu, then you will get the behavior you describe.  
Furthermore, it will use the system-standard menu delay, plus make the menu 
available to accessibility clients.

-Peter

On Feb 1, 2010, at 1:42 PM, Eric Gorr wrote:

 What I am trying to accomplish is displaying a menu (perhaps with 
 NSPopUpButtonCell's performClickWithFrame method) after a user clicks on a 
 sublass of NSButton and holds the left mouse button for = 1 second.
 
 Is anyone aware of any sample code doing this?
 
 I imagine I will need to customize the mouseDown method of NSButton with a 
 loop that checks to see if the mouse button is still down. However, I am 
 uncertain how to determine this. I have seen NSEvent's pressedMouseButtons 
 method, but it only became available with the 10.6 SDK and I need something 
 that works with 10.5.

___

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: Why does my menu have mutually exclusive states?

2010-01-15 Thread Peter Ammon

On Jan 15, 2010, at 11:41 AM, Eric Gorr wrote:

 I have some sample code at:
 
 http://ericgorr.net/cocoadev/UtilityMenu.zip
 
 According to the documentation in Application Menu and Pop-up List 
 Programming Topics for Cocoa, to get mutually exclusive states, one my 
 manage this oneself:
 
 
 
 You can use states to implement a group of mutually exclusive menu items, 
 much like a group of radio buttons. For example, a game could have three menu 
 items to show the level of play: Beginner, Intermediate, and Advanced. To 
 implement a such a group, create one action message that they all use. This 
 action message changes the appropriate setting, and then reflects that change 
 by unchecking the currently checked item and checking the newly selected item.
 In an action method that responds to all commands in the group use setState: 
 to uncheck the menu item that is currently marked:
 [curItem setState:NSOffState];
 Then mark the newly selected command:
 [sender setState:NSOnState];
 
 
 
 However, when my menu item is selected, I just turn it's state on and do 
 nothing else (for now).
 
 Why is the state of the previously selected items being set to off?

Hi Eric,

Your menu is in an NSPopUpButtonCell, and by default popups set the state of 
the selected item, and clear the state of other items.  You can disable this 
behavior by calling [cell setAltersStateOfSelectedItem:NO] on the popup button 
cell.

-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 arch...@mail-archive.com


Re: Displaying a non-contentual menu attachPopUpWithFrame

2010-01-13 Thread Peter Ammon
Hi Eric,

On SnowLeopard and later, use the NSMenu method popUpMenuPositioningItem: 
atLocation: inView:.

Before SnowLeopard, this is probably the easiest way:

NSPopUpButtonCell *cell = [[NSPopUpButtonCell alloc] initTextCell:@ 
pullsDown:NO];
[cell setMenu:menu];
[cell performClickWithFrame:NSMakeRect(menuLoc.x, menuLoc.y, 0, 0) 
inView:theView];
[cell release];

Hope this helps,

-Peter

On Jan 13, 2010, at 9:38 AM, Eric Gorr wrote:

 In the 'Application Menu and Pop-up List Programming Topics for Cocoa' 
 document it says:
 
 The preferred approach for programmatically displaying a non-contextual menu 
 is to create an NSPopUpButtonCell object, set its menu, and then call send a 
 attachPopUpWithFrame:inView: message to the pop-up button cell.
 
 I was wondering if anyone was aware of some sample code demonstrating this 
 technique.
 
 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/archive%40mail-archive.com

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


Re: set the label for the left hand expression / popup in an NSPredicateEditorRowTemplate?

2010-01-13 Thread Peter Ammon

On Jan 13, 2010, at 3:46 PM, Mike Chambers wrote:
 [...]
 I then add this to the NSPredicateEditor, and it works as expect.
 However, the left column in the editor for this row shows
 professions (the key value). I want it to show Profession. If I
 was using IB this would be very simple, as I could just rename it in
 the popup.
 
 How can I set the label for the left hand name in the editor?

You can simply change the title of the menu item in the NSPopUpButton.  You can 
access the first popup button with [[template templateViews] objectAtIndex:0].

-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 arch...@mail-archive.com


Re: __CFServiceControllerBeginPBSLoadForLocalizations timed out

2009-12-22 Thread Peter Ammon

On Dec 22, 2009, at 6:20 AM, Jerry Krinock wrote:

 The last few days, I've seen this message in the console when I launch an app 
 I'm working on:
 
 __CFServiceControllerBeginPBSLoadForLocalizations timed out while talking to 
 pbs
 
 The message also sometimes appears again a few minutes later.  It appears in 
 the regular Console Messages in Console.app, not just in Xcode.
 
 Searching list archives shows other such reports in the last couple months, 
 and a postulate that pbs means pasteboard server.  So, I retested some of 
 the inter-app drag/drop and copy/paste functions of the app but it all 
 appears to still be working.
 
 Google Chrome has the same problem:
 
 http://code.google.com/p/chromium/issues/detail?id=28161
 
 No resolution is given.  I just tested this in my 3-week old Google Chrome 
 and, yes, it still does it.
 
 I also found a few reports in support forums of other apps.  And this person 
 has got all of their Apple apps doing it…
 
 http://forums.applenova.com/showthread.php?t=33412
 
 So, apparently it's a bug in Snow Leopard.  No hits when searching for this 
 on developer.apple.com :(  Can anyone postulate a workaround or, more 
 importantly, is it possibly indicating that something that I missed in my 
 testing is not working?'

pbs is used for Services and isn't related to drag and drop or copy and paste.

Can you see if the pbs process is running?  If so, what does sample show it's 
doing?

If not, what happens if you run it directly: /System/Library/CoreServices/pbs ? 
 Does it crash or complete successfully?

Do you have any apps installed that attempt to modify Services (e.g. Service 
Scrubber)?___

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: NSRuleEditor: Criteria for new row

2009-12-22 Thread Peter Ammon

On Dec 22, 2009, at 10:57 AM, Houdah - ML Pierre Bernard wrote:

 When I hit the + button on a row in NSRuleEditor, a new row is created. How 
 can I take influence on the criteria used for that row.
 
 It seems NSRuleEditor defaults to selecting the first criterion sequentially 
 from the list of possible values. I would much rather have the new row match 
 the row where the + was clicked.
 
 Pierre

Sorry, this isn't possible right now.

___

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: __CFServiceControllerBeginPBSLoadForLocalizations timed out

2009-12-22 Thread Peter Ammon

On Dec 22, 2009, at 3:52 PM, Jerry Krinock wrote:

 
 On 2009 Dec 22, at 15:37, Peter Ammon wrote:
 
 Can you see if the pbs process is running?  If so, what does sample show 
 it's doing?
 
 Yes it is, and, not doing too much.  I took this sample while my app was 
 launching.  It looked the same if sampled at another time, except 2765 
 samples instead of 2747.
 
 Sampling process 22608 for 3 seconds with 1 millisecond of run time between 
 samples
 Sampling completed, processing symbols...
 Analysis of sampling pbs (pid 22608) every 1 millisecond
 Call graph:
2747 Thread_287412   DispatchQueue_1: com.apple.main-thread  (serial)
  2747 0x1cf5
2747 0x4b8d
  2747 0x3ea5
2747 0x532e
  2747 -[NSCondition wait]
2747 pthread_cond_wait$UNIX2003
  2747 _pthread_cond_wait
2747 __semwait_signal
2747 Thread_287432   DispatchQueue_2: com.apple.libdispatch-manager  
 (serial)
  2747 start_wqthread
2747 _pthread_wqthread
  2747 _dispatch_worker_thread2
2747 _dispatch_queue_invoke
  2747 _dispatch_mgr_invoke
2747 kevent
 
 Total number in stack (recursive counted multiple, when =5):

Thanks, this seems like a bug in pbs or in something underneath it.

You should be able to get the annoying log messages to stop by just running pbs 
directly: /System/Library/CoreServices/pbs .  It should exit within a second or 
so and the log messages should be gone.

Hope this helps,
-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 arch...@mail-archive.com


Re: Menu shortcuts without modifiers?

2009-12-21 Thread Peter Ammon


On Dec 21, 2009, at 7:29 AM, Uli Kusterer wrote:

 On 18.09.2009, at 23:07, Peter Ammon wrote:
 For key events without modifiers, like hitting the spacebar, the first 
 responder of the key window should get first crack via keyDown:.  So I'm not 
 sure why you're seeing the behavior you describe.  I wrote a quick test with 
 a focused text field in the key window and a main menu item with Space as 
 its key equivalent, and the text field won for spacebar.
 
 Hi Peter,
 
 just got back to this issue after having to drop it for some urgent work. A 
 short recap: It seems the winning works for the space bar in Cocoa windows, 
 but not for the arrow keys. In a Carbon window, neither of these keys get 
 passed to the edit field, the menu items get triggered immediately. I've 
 attached a short Cocoa test app with some Carbon and Cocoa windows, and two 
 menu items that exhibits the problem. Just type into any of the text fields 
 and then try to use the space or arrow key. You will get an NSAlert whenever 
 the menu items get the shortcut instead of the text field. 
 
 
[...]
 
 As an alternative, do you know if there is a way to find out what item 
 (Carbon or Cocoa, both) really has the focus right now? If I had an 
 NSView*/NSWindow*/NSResponder* or an HIViewRef/HIWindowRef, that I know has 
 the actual focus right now, I could probably remove the menu item shortcut 
 dynamically depending on what is focused.
 

Cocoa windows have the peculiar behavior that key down events without the 
command, control, or function key mask get sent to the window first, and then 
the menu.  Events with any of those flags set get sent to the main menu first.  
Pressing an arrow key generates an event with the function key mask set, but 
the spacebar does not set any of these mask bits, which explains the behavior 
you're seeing.  Carbon windows (including NSCarbonWindow) send all events to 
the main menu first, which is why the behavior is different between Cocoa and 
Carbon windows.

I think your suggestion of dynamically adding or removing the key equivalent is 
sound.  The best place to do this would be in either an implementation of 
menuNeedsUpdate: in the menu's delegate, or in validateMenuItem: in the target 
of the menu item.

To get Carbon's notion of the focus, you can do this:

HIViewRef focusedView = NULL;
HIViewGetFocus(GetUserFocusWindow(), focusedView, NULL);

To get Cocoa's notion, you would write:

NSResponder *fr = [[NSApp keyWindow] firstResponder]

The question of who really has the focus is a little complicated, because it 
depends on who is dispatching events.  If you have a Carbon window in a Cocoa 
app, HIViewGetFocus() will normally give you a NULL view if a Cocoa window is 
focused, so you might start by checking with Carbon, and then checking with 
Cocoa if the Carbon focus is not a text field.

Hope this helps,
-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 arch...@mail-archive.com


Re: NSRuleEditor rows binding

2009-12-04 Thread Peter Ammon

On Dec 4, 2009, at 1:08 PM, Carter R. Harrison wrote:

 Apple's documentation for NSRuleEditor indicates that it exposes a binding 
 named rows.  When I drag an NSRuleEditor onto my NSWindow in IB, I flip 
 over to the Bindings tab of the inspector and I don't see any bindings named 
 rows.  Anybody else manage to setup an NSRuleEditor with bindings?

The rows binding doesn't make much sense for NSPredicateEditor, so it's not 
available in IB.  It is better to use the value binding; the value is an 
NSPredicate.

-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 arch...@mail-archive.com


Re: NSToolbar problem in 10.6

2009-12-04 Thread Peter Ammon

On Dec 4, 2009, at 2:13 PM, John Mikros wrote:

 Hello all,
 
 I have a window with an NSToolbar attached.  The toolbar is created with 
 defaultItemIdentifiers being an empty NSArray, and then we add items via 
 insertItemWithItemIdentifier:atIndex:
 
 All the item identifiers that are added to the toolbar are in the array 
 returned by toolbarAllowedItemIdentifiers:
 
 However, the first toolbar item that I add does not show up in the toolbar.  
 The rest show up fine.  If you click the toolbar widget in the upper right of 
 the window to hide and then show the toolbar, then the missing item magically 
 appears in the toolbar.
 
 This does not happen in 10.5.8.  Is there a way to force the toolbar to 
 refresh, as if the user hid and re-showed the toolbar?

Hi John,

I wasn't able to reproduce this problem in a test app.  Can you please provide 
a sample that reproduces it?  I can then suggest a workaround.

You might try using setDisplayMode: to alternate between display modes, as a 
way of refreshing it.

-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 arch...@mail-archive.com


Re: Status Bar App menu won't work in 10.6, will in 10.5

2009-11-05 Thread Peter Ammon

On Nov 4, 2009, at 11:41 AM, Viraj Mody wrote:

 I have an application that sits in the status bar on the Mac. It has a menu
 that lets you look at the app version, change some settings and quit the
 app.
 
 I built it on Leopard and it works fine on Leopard. On Snow Leopard, I can
 see the app in the status bar and clicking on it shows the menu items. But
 clicking items in the menu doesn't do anything. The app isn't hung - it's
 doing stuff that it's expected to do. The UI thread isn't hung either - I
 can see the menu obviously, and and dialogs that the app causes to show on
 the UI thread (outside of the ones when the menu is clicked) show up fine.
 Compiling it on Snow Leopard targeted for 10.6 doesn't seem to change this
 behavior.
 
 So I know that the app is able to create dialogs, isn't hung and is
 functioning. I suspect this has something to do with the menu, and handling
 menu clicks either in my app or in Snow Leopard.
 
 Anyone else have suggestions on what this might be or where I should look?
 Any suggestions on where I can place a BP to trap whether the menu item
 click is actually happening?
 
 I've uploaded a simple repro 10.6 XCode project. I'll send a virtual beer
 your way if you can take a look and let me know if you see what's wrong.

Your status bar menu is also the main menu.  This isn't a supported 
configuration - you can't use a menu in more than one place at once.

-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 arch...@mail-archive.com


Re: NSWorkspaceDidMountNotification not firing on Snow Leopard

2009-10-08 Thread Peter Ammon


On Oct 8, 2009, at 1:05 AM, Kevin Bracey wrote:


Hi Guys and Gals,

I have some Leopard code that works fine, but on Snow it doesn't,  
hoping someone might have an idea how for fix it ;-)


I use an AppleScript to mount a afp
tell application iLike Installer

set holdMountPoint to stringForKey MountPoint

tell application Finder
mount volume holdMountPoint
end tell

end tell

This works great, the sharepoint mounts as expected on both OS X 5.8  
and OS X 6.1 :)


Now I have a Cocoa App listening for the share to mount with

[[[NSWorkspace sharedWorkspace] notificationCenter]  addObserver:self

selector:@selector(deviceDidMount:)

name:NSWorkspaceDidMountNotification

object:NULL];

shortly are the point mounts on Leopard the -( void )deviceDidMount: 
( NSNotification *)userInfo fires as expected and it goes about it's  
business,


but on Snow it never fires:(

anyone got any ideas as to what I could be doing wrong or another  
way to listen for an afp to mount?


Hi Kevin,

I wasn't able to reproduce this problem.   You might verify the  
following:


- The app is not hung at the point you expect to receive the  
notification
- The observer is retained, or if you are using GC, something is  
referencing it.  NSNotificationCenter does not root observers in  
either retain-release or GC.


It would also be interesting to know if the app receives the  
notification when you mount the volume manually with the Finder.


If none of that helps, and you can either distribute your app or  
produce a test case, please file a bug.  If I discover it's a problem  
in Workspace, I'll suggest a workaround.  Or if it's a problem in your  
app I'll share that information too of course :)


-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 arch...@mail-archive.com


Re: NSToolbarGroupItem not showing labels of subitems

2009-10-05 Thread Peter Ammon

Hi Brad,

The group item will use its own label, if it has been set.  Probably  
creating the toolbar in IB caused the item to acquire an empty label.   
Calling [groupItem setLabel:nil] should cause it to discard its own  
label and use its children.


Let me know if that doesn't work,
-Peter

On Oct 5, 2009, at 10:06 AM, Brad Gibbs wrote:


Hi,

I'm trying to create a toolbar with NSSegmentedControl as a custom  
view for an NSToolbarItemGroup in 10.6, but I can't get the labels  
for the subitems to appear.


I added an NSSegmentedControl to the toolbar item in IB and set  
images in the segmented control in IB.  I did not give the  
NSToolbarGroupItem a label.


I added the following code to my appDelegate (oProjectsGroup is an  
IBOutlet, which is bound to the NSToolbarGroupItem in IB):


- (void)applicationDidFinishLaunching:(NSNotification *) 
aNotification {

// Insert code here to initialize your application
	NSToolbarItem *item1 = [[[NSToolbarItem alloc]  
initWithItemIdentifier:@Item1] autorelease];
	NSToolbarItem *item2 = [[[NSToolbarItem alloc]  
initWithItemIdentifier:@Item2] autorelease];

[item1 setImage:[NSImage imageNamed:@Activities]];
[item2 setImage:[NSImage imageNamed:@Projects]];
[item1 setLabel:@Prev];
[item2 setLabel:@Next];

	[oProjectsGroup setSubitems:[NSArray arrayWithObjects:item1, item2,  
nil]];


for (id item in [oProjectsGroup subitems]) {
NSLog(@label is %@, [item label]);
}
}

The console displays the labels, so, apparently, the labels are  
being set, but they do not appear beneath their respective segments  
in the running app.


I've looked through the documentation and a list thread both of  
which seem to indicate that my code should be working


Any help would be appreciated.


Thanks.

Brad
___

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/pammon%40apple.com

This email sent to pam...@apple.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: Correct way to tell if a path is to a .bundle?

2009-09-25 Thread Peter Ammon


On Sep 24, 2009, at 8:09 PM, Jens Alfke wrote:



On Sep 24, 2009, at 6:41 PM, Rick Mann wrote:

I'm scanning a directory for plugins for my app. Given a path,  
what's the right way to tell if it's a path to a bundle?


-[NSWorkspace isFilePackageAtPath:].



Actually, bundles are often packages, and vice versa, but you can be  
either without the other.


A file package is a directory that is presented as a single file to  
the user, while a bundle is a directory with a particular layout.  For  
example, frameworks are bundles, but not packages.  If you navigate to  
a .framework file in Finder, you will see that it looks like a  
folder.  Likewise, you can take any directory and set the package bit,  
and it becomes a package.


The usual way is to just try loading the URL as a bundle, and see if  
you succeed.  You could also define a particular extension for your  
plugin type, and look for files of that extension, with the assistance  
of CFBundleCreateBundlesFromDirectory.


-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 arch...@mail-archive.com


Re: Menu shortcuts without modifiers?

2009-09-18 Thread Peter Ammon


On Sep 17, 2009, at 12:29 PM, Uli Kusterer wrote:


Hi,

I have an app that contains a QTMovieView. I've set things up so  
people can use the arrow keys to skip, fast forward, rewind, use  
space to play/pause etc., as they're used to from other movie- 
playing apps. Now, I'd like to add menu items that correspond to  
these actions for people who don't know the shortcuts. I'd also like  
to show the shortcuts in the menu items, so people know the  
shortcuts are there.


Trouble is: If I set e.g. the space key as a menu item's shortcut  
and a text field has keyboard focus, the space key goes to the menu,  
not to the text field.


I don't want to disable the menu item, as even if there's a text  
field with keyboard focus, the user may want to use the menu to  
pause etc. Is there a way to make any control get the shortcut  
*before* the menus? Is there a way to disable only the shortcut, but  
still have it displayed? Is there a way to fake the shortcut, so I  
can do the actual handling at a different level? (Carbon lets you  
set the menu shortcut glyph separately from the actual shortcut, for  
example).


Anyone have an idea for a solution?

Cheers,
-- Uli Kusterer
The Witnesses of TeachText are everywhere...
http://www.zathras.de



Hi Uli,

For key events without modifiers, like hitting the spacebar, the first  
responder of the key window should get first crack via keyDown:.  So  
I'm not sure why you're seeing the behavior you describe.  I wrote a  
quick test with a focused text field in the key window and a main menu  
item with Space as its key equivalent, and the text field won for  
spacebar.


Can you post the backtrace of the call to the action method of your  
menu item?  It's possible it's being invoked from some place other  
than -[NSApplication handleKeyEquivalent:].

___

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: no mouseDown on dismissing context menu

2009-09-17 Thread Peter Ammon


On Sep 17, 2009, at 11:03 AM, Georg Seifert wrote:


Hi,

If I show a context menu in my view and then click somewhere in the  
view, mouseDown for the view is not called. Subsequent mouseDragged  
are triggered.


The view returns YES in acceptsFirstMouse and acceptsFirstResponder.

What do I miss?

Georg___


Hi Georg,

This is by design.  A click that dismisses a menu should not also  
trigger whatever was clicked, because it would be easy to accidentally  
close a window or do something else undesirable.


The one (intentional) exception is dragging windows.

-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 arch...@mail-archive.com


Re: Menu item correct size

2009-09-17 Thread Peter Ammon


On Sep 17, 2009, at 7:17 AM, Felipe Monteiro de Carvalho wrote:


Hello,

I would like to make the text in a menu item bold, while maintaining
everything else exactly like in other menu items. Reading and
searching I managed to find the appropriate routines to do this, but I
seam to have found a big problem. NSFont menuFontOfSize with 0 as the
font size doesn't give the correct menu font size, it gives a 13 font
size which is smaller then the 14 size of all other menu items.

Is there any reliable way to get the right font size?


Hi Felipe,

The most reliable way is to ask the menu for its font, via the - 
[NSMenu font] method.


-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 arch...@mail-archive.com


Re: click on sub-menu's super-item dismisses menu?

2009-09-17 Thread Peter Ammon


On Sep 17, 2009, at 3:09 PM, David M. Cotter wrote:


say the user say clicks the file menu, the file menu opens
then say they hover over recent items and then clicks it (i don't  
know, out of habit or something)


in carbon, this click is ignored, rightfully it seems

in cocoa, it dismisses the menu.  is there a way i can tell the menu  
or menu item to NOT dismiss the menu?


Hi David,

I can't reproduce this behavior in SnowLeopard - the Open Recents menu  
item does not dismiss the menu when clicked.


To answer your question: a menu item with a submenu will ignore clicks  
if its action is @selector(submenuAction:) or NULL.  If the action is  
something else, then the menu item can be selected.

___

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: NSSegmentedControl with square edges

2009-09-11 Thread Peter Ammon


On Sep 11, 2009, at 8:10 AM, Arun wrote:


Hi All,

Does anybody know how to create an NSSegmentedControl with squared  
edges ?

If anyone has sample code please share..
I know if i use leopard SDK, by just changing a style in the IB we can
achieve this. But since my app needs to support on tiger, i need this.

Thanks
Arun KA


This style is not available on Tiger.  If you want to make it look the  
same on Tiger and later, you will have to make your own custom  
control.  It's easier to just live with the appearance on Tiger.


___

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

2009-09-10 Thread Peter Ammon


On Sep 10, 2009, at 10:30 AM, Nick Zitzmann wrote:

I have a service that can apply to multiple categories due to the  
pasteboard types it accepts. In Snow Leopard, for some reason, the  
service always shows up under the Pictures category even though it  
also accepts text. I want it to show up in the General category.


I'm aware of an apparently undocumented NSRequiredContext key called  
NSServiceCategory that manually sets the service category in the  
Keyboard preference pane, which is useful when the pane does not  
correctly categorize the service, which I'm guessing it does based  
on the name and pasteboard type. I know that you can use a UTI here  
to set the category, but what's the UTI for the general category?  
I tried searching for NSServiceCategory and found nothing, and  
searching for UTIs gives me results for a different meaning of UTI...


Nick Zitzmann
http://www.chronosnet.com/


Hi Nick,

You should try to pick a UTI that represents your Service accurately.   
If the UTI you pick does not conform to any category, then it will  
wind up in General.  But if later Apple adds a new category, and your  
Service's UTI conforms to the new category's UTI, your Service will  
show up in the new category.


If your Service really can't be categorized, just writing General is  
fine.


-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 arch...@mail-archive.com


Re: NSServiceCategory

2009-09-10 Thread Peter Ammon


On Sep 10, 2009, at 12:15 PM, Nick Zitzmann wrote:



On Sep 10, 2009, at 1:08 PM, Peter Ammon wrote:

You should try to pick a UTI that represents your Service  
accurately.  If the UTI you pick does not conform to any category,  
then it will wind up in General.  But if later Apple adds a new  
category, and your Service's UTI conforms to the new category's  
UTI, your Service will show up in the new category.


OK, but what if the service has a category but no real UTI? For  
example, there's a Searching category. What's the UTI for  
searching? I've looked at the list of system-declared UTIs and  
there's nothing with search in its name.


Yes, Searching unfortunately does not have an associated UTI - as you  
discovered you can specify the category name explicitly in that case.


I'd also better file a bug report about the lack of documentation  
for NSServiceCategory...


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: Application main menu title behavior change in 10.6

2009-09-04 Thread Peter Ammon


On Sep 4, 2009, at 11:31 AM, Jim Turner wrote:


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?


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

___

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

2009-09-03 Thread Peter Ammon

Hi Colin,

Adding the NSRequiredContext is the right way to make it appear by  
default.


Note that after adding it, you will have to run /System/Library/ 
CoreServices/pbs (or log out and back in) to make the Service appear.   
If you are unsure if the system is recognizing the context, run pbs  
with the -dump_pboard flag


/System/Library/CoreServices/pbs -dump_pboard

find your app's entry and make sure it shows the NSRequiredContext.   
Post again if that doesn't work.


-Peter

On Sep 3, 2009, at 12:48 AM, Colin Deasy wrote:



Ive tried it with the required context as well, no luck. I even  
tried building it with 10.6 SDK.



From: kyle.slu...@gmail.com
To: colde...@hotmail.com
Subject: Re: NSServices
Date: Wed, 2 Sep 2009 20:41:33 -0700
CC: cocoa-dev@lists.apple.com

Re-read the docs. Your plist needs to specify an array (possibly
empty) of valid contexts. Otherwise Snow Leopard assumes you haven't
updated your service for 10.6.

--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: detect left mouse button clicked in menu bar

2009-08-13 Thread Peter Ammon


On Aug 13, 2009, at 2:56 PM, David M. Cotter wrote:

i know i can detect when a particular menu is about to be shown, but  
what I want is to run a quick process before any menus from the menu  
bar are shown, and not run it again all the while the user is  
browsing the menus in the menu bar


how do i do this?   apparently there is no mouseDown event sent  
when it's in the menu bar. currently i have this very ugly code:


The NSMenuDidBeginTrackingNotification is posted at the point menu  
tracking begins, before any menu is shown.  That sounds like what you  
want.

___

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 Editor questions

2009-08-12 Thread Peter Ammon


On Aug 11, 2009, at 5:51 PM, Dave DeLong wrote:


Hey everyone,



Hi Dave!

I'm about to embark on understanding NSRule/PredicateEditors but  
before I get too deep into the code, I wanted to ask a couple  
questions.


I'm hoping to create an interface whereby the user can create an  
NSPredicate and then come back and edit it later.  From what I've  
understood from the documentation and PredicateEditorSample, it  
seems that the appropriate way to do this would be to construct an  
NSCompoundPredicate from the editor.  That way when the user goes to  
edit the predicate, I can easily break it up into its constituent  
parts by using the -subpredicates method of NSCompoundPredicate.  Is  
that correct?


You certainly can break it up if you want.  However, most tasks do not  
require you to do so.  For example, setting it as the filter predicate  
on an NSArrayController, evaluating it against some object, or  
persisting it to disk do not require you to break it up.




If that is correct, would I then have to determine with  
NSPredicateEditorRowTemplate I'd need to use by examining the  
subpredicate itself?


NSPredicateEditor does this work for you.  You can set an NSPredicate  
directly on an NSPredicateEditor via [editor  
setObjectValue:somePredicate], and it will figure out which templates  
to use, like so:


1) It calls matchForPredicate: on each template, and uses the template  
that returns the highest match.
2) It calls displayableSubpredicatesOfPredicate: on the winning  
template to determine what NSPredicates should become subrows.  The  
default implementation returns the subpredicates of a compound  
predicate, and nil for a simple predicate.


This process is recursive, so NSPredicateEditor does the work of  
picking apart compound predicates.  If you subclass  
NSPredicateEditorRowTemplate, you may want to override  
matchForPredicate: to identify which predicates your template handles,  
but you should not need to pick apart the predicate yourself.


Hope this helps,
-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 arch...@mail-archive.com


Re: Search Item in the Application menu missing in Other languages

2009-07-27 Thread Peter Ammon
Arun, my advice is the same.  To identify which menu (if any) should  
get the Search field, AppKit examines the actions of the items in that  
menu.  If a menu contains an item with the showHelp: action, then  
AppKit concludes that menu is the Help menu, and it will get the  
Search field.


-Peter

On Jul 27, 2009, at 9:54 AM, Arun wrote:


Hi  Peter,

selector(showHelp:) is the default action that gets called when we  
click on the Help - showHelp option.

Looks like you did not undersatnd the question correctly.
The Hep menu in english contains a Search menu item in English. If  
you change the Operating System language, Search menu item
disappears. Is there any way in which we can get the Search menu  
item under Help Menu in all the languages?


Thanks
Arun KA




On Sat, Jul 25, 2009 at 4:33 AM, Peter Ammon pam...@apple.com wrote:

On Jul 24, 2009, at 11:22 AM, Arun wrote:

Hi All,

I have a cocoa application which is localized in multiple languages.
My application uses default Menu's like File, Edit, View, etc.,
When the language is set to English in the System Preferences -
International - languages, Under the Help menu there is an item  
called

Search.
But if the language is changed to french, German or Japanese and  
application

is launched, the same Search item under Help menu is missing.
Is there anything that is missing or not configured in my  
application for

which my application is behaving like this?

Thanks
Arun

Hi Arun,

Leopard has some heuristics for determining which menu is the Help  
menu.  The simplest way to make sure it gets identified correctly in  
all languages is to include a menu item with the default Help  
action, which is @selector(showHelp:).


Hope this, well, helps,
-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 arch...@mail-archive.com


Re: Search Item in the Application menu missing in Other languages

2009-07-24 Thread Peter Ammon


On Jul 24, 2009, at 11:22 AM, Arun wrote:


Hi All,

I have a cocoa application which is localized in multiple languages.
My application uses default Menu's like File, Edit, View, etc.,
When the language is set to English in the System Preferences -
International - languages, Under the Help menu there is an item  
called

Search.
But if the language is changed to french, German or Japanese and  
application

is launched, the same Search item under Help menu is missing.
Is there anything that is missing or not configured in my  
application for

which my application is behaving like this?

Thanks
Arun


Hi Arun,

Leopard has some heuristics for determining which menu is the Help  
menu.  The simplest way to make sure it gets identified correctly in  
all languages is to include a menu item with the default Help action,  
which is @selector(showHelp:).


Hope this, well, helps,
-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 arch...@mail-archive.com


Re: NSPopupButton to display fonts in the fonts themselves

2009-07-09 Thread Peter Ammon


On Jul 8, 2009, at 6:15 PM, I. Savant wrote:


On Jul 8, 2009, at 9:06 PM, Peter Ammon wrote:

So for menus that may take a while to build, consider appending the  
items as they come in (like the Airport status item), or showing a  
Building... item until you're ready to add the complete set of  
items.



 What of menus that already have a selection well down the list? In  
this case, it sounds like my original idea of immediately building  
the list of font names on nibloading/creation/whenever first, then  
rendering the attributed titles in the background (and updating the  
popup on the main thread) might still be the better option.


 Or have I misunderstood?


If your menu has a selection, like a popup menu, then your idea is  
definitely the way to go.  However, getting the list of available  
fonts can take a noticeable amount of time, so you may find it too  
expensive to build the list up-front. 
___


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: NSPopupButton to display fonts in the fonts themselves

2009-07-09 Thread Peter Ammon


On Jul 8, 2009, at 8:02 PM, Graham Cox wrote:



On 09/07/2009, at 11:06 AM, Peter Ammon wrote:

- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex: 
(NSInteger)index shouldCancel:(BOOL)shouldCancel


is actually invoked on some sort of background thread/queue, so  
implementing these methods (the above + numberOfItemsInMenu:) in  
your menu delegate would allow you to update each item with the  
attributed title fairly simply and it wouldn't drag your main  
thread's performance down.


--Graham


What this method does is check at regular intervals for events that  
would cancel tracking.  If one is detected, it passes YES for  
shouldCancel.  So if your design is if the user clicks on the  
menu, sit and spin until it's built, then you could use this API  
to detect cancellation, to stop spinning.


However, sit and spin isn't a very good user experience, and  
Leopard allows you to append items to a menu in the menu bar while  
it is open. So for menus that may take a while to build, consider  
appending the items as they come in (like the Airport status item),  
or showing a Building... item until you're ready to add the  
complete set of items.



OK... this clarification has confused me a little though.

Can this delegate method be used as suggested or not? In other  
words, if I use it to change each item's plain title to a more  
complex attributed title, will that cause a performance problem?  
What I expect to see is that I pop open the menu and see plain  
titles, gradually being replaced one by one with the attributed  
titles but menu tracking proceeds normally.


No, the menu:updateItem:atIndex:shouldCancel: API does not support  
that.  Every item gets updated before the menu is shown.  It is  
entirely synchronous.


If you want to set the attributed titles while the menu is opened, you  
can do it by installing a timer from the delegate callbacks, like  
menuWillOpen:, or NSMenuWillBeginTrackingNotification.


But if my code inside this method takes significant time, will that  
make tracking sluggish? Also, if menu tracking ends, are the  
remainder of the items passed to this method or does it stop there?


Every item gets passed to the callback, until the items are exhausted  
or the callback returns NO.




If so, I. Savant's original plan would probably be better so that  
the titles can be processed in the background even if the menu isn't  
shown (though in that case it could be wasted work if the user  
*never* opens the menu).


menuWillOpen: is probably the best place to create a timer to start  
installing the attributed titles.  This will ensure that they only get  
installed if the menu is going to be displayed.


Hope this helps,
-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 arch...@mail-archive.com


Re: NSPopupButton to display fonts in the fonts themselves

2009-07-08 Thread Peter Ammon


On Jul 8, 2009, at 6:46 AM, Graham Cox wrote:



On 08/07/2009, at 11:33 PM, I. Savant wrote:


[NSMenuItem setAttributedTitle:];


... and if you want to get really fancy (ie modern), you could  
build the list with regular strings (just setTitle:) relatively,  
but use NSOperation/Queue to create / set the attributed titles  
with the actual fonts in the background, replacing the plain-text  
ones.


I suggest this because grabbing a list of font name strings is  
quicker than building an attributed string for each font. Do the  
quick thing first so it's available, but do the longer fancy thing  
in the background, updating while the UI is idling. Remember (99.9%  
of) all AppKit-related stuff should be done on the main thread.



A good idea, though I think the menu delegate can save you even this  
much effort. The docs are not explicit on this point, but a careful  
reading suggests that:


- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex: 
(NSInteger)index shouldCancel:(BOOL)shouldCancel


is actually invoked on some sort of background thread/queue, so  
implementing these methods (the above + numberOfItemsInMenu:) in  
your menu delegate would allow you to update each item with the  
attributed title fairly simply and it wouldn't drag your main  
thread's performance down.


--Graham


What this method does is check at regular intervals for events that  
would cancel tracking.  If one is detected, it passes YES for  
shouldCancel.  So if your design is if the user clicks on the menu,  
sit and spin until it's built, then you could use this API to detect  
cancellation, to stop spinning.


However, sit and spin isn't a very good user experience, and Leopard  
allows you to append items to a menu in the menu bar while it is  
open.  So for menus that may take a while to build, consider appending  
the items as they come in (like the Airport status item), or showing a  
Building... item until you're ready to add the complete set of items.


-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 arch...@mail-archive.com


Re: GC pros and cons

2009-06-25 Thread Peter Ammon

On Jun 24, 2009, at 8:11 PM, Kyle Sluder wrote:


On Wed, Jun 24, 2009 at 7:55 PM, Peter Ammonpam...@apple.com wrote:
Microsoft even says that all objects must be robust against being  
Dispose()d
multiple times, which smacks of sloppiness.  If your program  
disposes of an
object twice, then it is structured so that independent usages of  
the object
are not coordinated, and so it is likely that one part of your  
program uses

an object after it has been disposed by another part.


It's not really sloppiness.  Python behaves the same way with its
contexts; both Python contexts and Dispose() are intended to be used
on objects that hold on to finite resources.  Similarly to Dispose(),
you can't reopen a closed NSStream.

IOW, Dispose() isn't a memory management technique, it's a
limited-resource-management technique.

--Kyle Sluder



Are you saying that it's not sloppy to close a file twice, unlock a  
lock twice, etc.?


Python doesn't require that its contexts be robust against multiple  
calls to __exit__ (its answer to Dispose()).


___

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: GC pros and cons

2009-06-25 Thread Peter Ammon


On Jun 25, 2009, at 12:11 PM, Kyle Sluder wrote:


On Thu, Jun 25, 2009 at 11:39 AM, Peter Ammonpam...@apple.com wrote:
Are you saying that it's not sloppy to close a file twice, unlock a  
lock

twice, etc.?


It sounds to me like you were originally referring to language
implementation sloppiness, which has nothing to do with closing a file
twice, unlocking locks multiple times, etc. (client sloppiness).


Well, I can make my point with an analogy.

Anyone who has written C or C++ has committed a double free() at some  
point.  This usually indicates that parts of the program aren't  
coordinating properly.  We can apply ad-hoc fixes, but this is a  
common-enough error that it's worth coming up with a general  
solution.  Two possible solutions are:


1) Improve coordination techniques, such by adding garbage collection,  
reference counting, etc.
2) Require that malloc be robust against multiple free()s on the same  
pointer


The second solution is a lot easier to implement.  But it's really  
just papering over the problem, because double free()s are found with  
other bugs, such as deference-after-free or race conditions.


So when I see that Dispose() is required to be robust against multiple  
calls on the same object, it makes me think they encountered the same  
problem as double free(), but chose the second solution.  Client  
sloppiness thus informed the framework design.


In any case, it's been my experience that GC makes memory management  
much easier, but precious resource management somewhat harder.  It's  
harder because GC forces more of a divorce between the management of  
memory and precious resources, and the precious resource management  
techniques are about on the level with C circa 1989.


I mean, C# has the using statement, which works well as long as your  
precious resource's lifetime is tied to some scope.  And we have the  
explicit Dispose() call, which works well as long as you have some  
external way to coordinate between multiple clients of the object.   
There's an obvious analogy to stack allocation and free(), respectively.


-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 arch...@mail-archive.com


Re: GC pros and cons

2009-06-25 Thread Peter Ammon


On Jun 25, 2009, at 1:16 PM, Peter Duniho wrote:


On Jun 25, 2009, at 12:11 PM, Kyle Sluder wrote:


[...] .NET users often call Dispose()
explicitly, because it is useful in situations other than inside  
using

blocks.


Though, to be clear (lest the tendency to want to put down the other  
be allowed to go too far)...


The requirement in .NET that Dispose() be safe to call multiple  
times has very little to do with how _client_ code is expected to  
use it, and more to do with the GC system.  In particular, the order  
of finalizer execution is indeterminate, and the usual job of a  
finalizer is to call Dispose() on the object in which it's  
implemented, which in turn may call Dispose() on other objects  
referenced by that object.


Without a requirement that Dispose() be safe to call multiple times,  
the caller of Dispose() would have to always check to see whether  
the object has been disposed yet, because an object that is being  
disposed by some other object being finalized might already have  
been disposed by the first object's finalizer.


Certainly it would be unusual, and generally a sign of sloppy  
programming, for _client_ code to call Dispose() on an object more  
than once (or for the finalizer to be executed, for that matter).   
The rules are there to make the system more robust, not to encourage  
sloppy programming (though of course, unfortunately, the former does  
sometimes lead to the latter).


Thanks for that explanation!  That makes sense.  I'm happy that the  
idempotence of Dispose() has a sane justification.

___

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: GC pros and cons

2009-06-25 Thread Peter Ammon


On Jun 25, 2009, at 1:42 PM, Bill Bumgarner wrote:


On Jun 25, 2009, at 3:14 PM, Peter Ammon wrote:
In any case, it's been my experience that GC makes memory  
management much easier, but precious resource management somewhat  
harder.  It's harder because GC forces more of a divorce between  
the management of memory and precious resources, and the precious  
resource management techniques are about on the level with C circa  
1989.


Really, retain/release requires such a separation, too.  At least,  
it does for relatively complex, often concurrent, piles of code.




I totally agree, which is why I said more of a divorce.  Since  
retain/release is more deterministic than GC, it allows you to  
tolerate ordering dependencies  and tying resource lifetime to memory  
lifetime for longer.  But it ultimately breaks down as complexity  
increases, just as you say.


The switch to GC has forced me to redesign a number of classes.  But I  
usually find that the redesigned classes work better under retain/ 
release as well.


-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 arch...@mail-archive.com


Re: GC pros and cons

2009-06-24 Thread Peter Ammon


On Jun 24, 2009, at 6:02 PM, Stephen J. Butler wrote:

On Wed, Jun 24, 2009 at 7:40 PM, Jeff  
Laingjeff.la...@spatialinfo.com wrote:

http://www.simple-talk.com/dotnet/.net-framework/understanding-garbage-collection-in-.net/

(Yes, I do .NET as well as Cocoa)

No real surprises there, except for the closing paragraphs which  
can be paraphrased down to If you need memory to be collected  
efficiently, you should implement IDisposable and call Dispose()  
explicitly when you are done with your objects.  Which gives a net  
gain of zero, since you need to call Dispose() exactly where you  
used to call Release().  To make the automatic model (GC) work  
efficiently every time, you need to replicate the manual (retain/ 
release) model, all the while presumably telling yourself that  
this is so much better than what I had.


Well, no, that's not a good summary of the last couple paragraphs. IF
YOU HAVE A FINALIZER, then you should probably be using the
IDisposable interface. Objects with finalizer methods essentially need
two passes, since actions in the finalizer can cause objects that
would have been collected to end up in a root again. So you pass once
to finalize, and again to make sure the object is still collectable.

But the reason people need finalizers is usually because they're
holding open some external resource that needs special closing: a
connection to a server, a file, an OS handle, etc. That's where
IDisposable comes in. People can then use the using() construct, which
closes the external resource as soon as possible. But you write a
finalizer just in case programmers aren't careful and forget to use
using() or call Dispose() manually. The GC.SuppressFinalize() is just
a hint to tell the runtime you've handled the external resource and it
can collect in one pass.

None of this is anything like retain/release or reference counting.
And is easier, IMHO. Even when you screw up and forget to call
release, your object is still eventually collected and its external
resource closed.


You're right that IDisposable is nothing like release - it is more  
like dealloc.  An object that has had Dispose() called on it is no  
longer good for anything.


In Cocoa, it is unwise to call -dealloc on an object when you are done  
with it, because other objects may still need it.  Instead, you should  
allow the reference counting machinery to call dealloc for you at the  
right time.  But in .NET, it is common to call Dispose() on an object  
when you are done with it.  There is no machinery to determine if  
other objects may still need the about-to-be-disposed object.


Microsoft even says that all objects must be robust against being  
Dispose()d multiple times, which smacks of sloppiness.  If your  
program disposes of an object twice, then it is structured so that  
independent usages of the object are not coordinated, and so it is  
likely that one part of your program uses an object after it has been  
disposed by another part.


So the Dispose technique is (in my opinion) inferior to retain /  
release when it comes to management of external resources.


-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 arch...@mail-archive.com


Re: highlighting menu item in main menu bar

2009-06-01 Thread Peter Ammon

Hi Ken,

The menu item unhighlights after the menu item's action is finished.   
If user input should be blocked while the script is running, then you  
should register for the NSTaskDidTerminateNotification and then drive  
the main run loop forwards from within your menu item's action method,  
until you get the notification.


On the other hand, if the user can continue using your app as normal,  
you should not show the menu item highlighted, because the user might  
want to choose different menu items.


On Jun 1, 2009, at 9:34 AM, kvic...@pobox.com wrote:

my app has a scripts menu item (in the main menu bar). the items in  
this menu correspond to applescript files the user has placed in my  
application support folder. when the user selects one of these menu  
items, i execute the appropriate script. i execute the script in a  
(sub) task (NSTask). i do it this way because i discovered (the hard/ 
empirical way) that if an executing script, executes functionality  
in my app that calls -[NSScriptCommand suspendExecution], then the  
executing of that script will erroneously terminate early. using a  
sub task solves this problem.


in my app, when i launch this task, i register for the  
NSTaskDidTerminateNotification and in my notification routine, i  
display any errors returned.


this all works fine... except that as soon as i return from  
launching the sub task, the menu item (in the main menu bar) for the  
scripts menu un-highlights. i would like this to remain highlighted  
until my notification routine is called, in order to provide  
feedback to the user that his/her script is still executing.


is this possible? if so, could someone provide any code and/or  
documentation pointers?


thanx,
ken


___

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: NSToolbar: notification of change?

2009-06-01 Thread Peter Ammon


On Jun 1, 2009, at 3:53 PM, David Reitter wrote:

Having subclassed NSToolbar, I am now trying to get a notification  
of changes done by the user using the customization palette.
This works fine for the removal of items (toolbarDidRemoveItem:),  
but I can't see a way to get notified of added/moved items after the  
fact.
The only notification I can get is toolbarWillAddItem:, but that's  
obviously before the addition, which is not very helpful.


I have tried implementing insertItemWithItemIdentifier: and also  
setConfigurationFromDictionary:, but it seems that the palette  
doesn't go through these.


Short of regularly monitoring the tool bar for possible changes, I  
don't know what to do...


Thanks for your suggestions!

PS.: please cc me on replies.


In addition to what Keary said, you can also set a timer to fire after  
toolbarWillAddItem:.  Not ideal, but better than nothing.

___

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: Rearrange items on NSToolbar

2009-05-29 Thread Peter Ammon


On May 29, 2009, at 1:41 AM, Nikhil Khandelwal wrote:


Hi,

Is it possible to rearrange items in customize toolbar ?
I want to change the order of NSToolbarItem in NSToolbar.

Thanks,
Nikhil


Hello Nikhil,

The order of the items in the toolbar is determined by the order of  
the item identifiers in toolbarDefaultItemIdentifiers, or the order  
that the user gives them by dragging.


-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 arch...@mail-archive.com


Re: Hiding process list app icon for GUI apps

2009-05-28 Thread Peter Ammon


On May 28, 2009, at 1:57 PM, Erg Consultant wrote:

Is there a way to hide a GUI app's icon in the process/switch list  
as can be done for faceless background apps?


I've tried several of the Info.plist settings but nothing seems to  
do this.


Thanks,

Erg


Hi Erg,

The LSUIElement key prevents the app from appearing in the Dock or  
Force Quit dialog, but still allows these apps to show windows.  Is  
that what you want?

___

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, NSPopupButton and bindings

2009-05-26 Thread Peter Ammon

Hi Martin,

Yes, that's right.

More generally, any changes to the popups after calling  
setRowTemplates: are likely to be futile.  This is because the real  
popup buttons displayed in an NSPredicateEditor are not the same popup  
buttons returned from your NSPredicateEditorRowTemplate's - 
templateViews method.  Instead, they are a conglomerate of all the  
popups at the same index in all the templates.  NSPredicateEditor does  
not notice when the template popups change, though this might be a  
nice thing to add at some point in the future.


Hope this helps,

-Peter



On May 25, 2009, at 7:57 AM, Martin Stanley wrote:


Peter,

Thanks for your response (I was hoping you would notice my post :-).

My interpretation of your response is as follows:
1- Cocoa bindings are not supported for popup views that are used in  
a NSPredicateRowtemplate, even if I am careful to make sure that the  
view is re-bound (via copyWithZone) when NSPredicateEditor creates  
its copies. This is true in spite of the fact that I managed to fill  
the popup via bindings upon initial creation.
2- One needs to observe the appropriate objects using KVO and then  
take the steps you outlined below in order to ensure that the popup  
has current values.


Can you please confirm my understanding?

Thanks,
Martin


On 22-May-09, at 10:55 PM, Peter Ammon wrote:



On May 22, 2009, at 9:37 AM, Martin Stanley wrote:

I've finally got the hang of NSPredicateEditor and custom  
NSPredicateEditorRowTemplates. (It sure took a while and many,  
many searches and head-scratchings). However, I am stuck on one  
thing and I suspect that the problem might lie in the  
NSPredicateEditor code itself; hence this post.


Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks  
(to-do items). I am using NSPredicateEditor to manage a set of  
user-defined Smart Groups. I want the user to be able to build a  
predicate based on a choice from a popup button. For example the  
(sub-)predicate might look like this:

 status == Not Started

Implementing this is straightforward enough, but I the wrinkle is  
that want the right hand side of the expression to come from a  
core data entity. So, no problem, when I create the NSPopUpButton  
(in my custom NSPredicateEditorRowTemplate class) I simply fill  
the menuitems from the appropriate array controller, which in turn  
gets its data from the Core Data entity. After much learning and  
experimenting, this now works. All is well.


So, then I realize that if (in another window) the user edits the  
Core Data entity in question, the changes are not reflected in the  
NSPredicateEditor popup. Okay, this seems like a candidate for  
cocoa bindings. Again, after much searching and experimentation I  
come up the following:


Hi Martin,

NSPredicateEditor does not support editing the popups like this.   
What you should do, when the available values in the popup need to  
change, is create a new NSPredicateEditorRowTemplate that reflects  
the change, and set it on the NSPredicateEditor in place of the old  
one, with setRowTemplates:


I think you may also need to save off the predicate editor's object  
value first, and then set it back on after calling setRowTemplates:.




___

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, NSPopupButton and bindings

2009-05-22 Thread Peter Ammon


On May 22, 2009, at 9:37 AM, Martin Stanley wrote:

I've finally got the hang of NSPredicateEditor and custom  
NSPredicateEditorRowTemplates. (It sure took a while and many, many  
searches and head-scratchings). However, I am stuck on one thing and  
I suspect that the problem might lie in the NSPredicateEditor code  
itself; hence this post.


Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks (to- 
do items). I am using NSPredicateEditor to manage a set of user- 
defined Smart Groups. I want the user to be able to build a  
predicate based on a choice from a popup button. For example the  
(sub-)predicate might look like this:

   status == Not Started

Implementing this is straightforward enough, but I the wrinkle is  
that want the right hand side of the expression to come from a core  
data entity. So, no problem, when I create the NSPopUpButton (in my  
custom NSPredicateEditorRowTemplate class) I simply fill the  
menuitems from the appropriate array controller, which in turn gets  
its data from the Core Data entity. After much learning and  
experimenting, this now works. All is well.


So, then I realize that if (in another window) the user edits the  
Core Data entity in question, the changes are not reflected in the  
NSPredicateEditor popup. Okay, this seems like a candidate for cocoa  
bindings. Again, after much searching and experimentation I come up  
the following:


Hi Martin,

NSPredicateEditor does not support editing the popups like this.  What  
you should do, when the available values in the popup need to change,  
is create a new NSPredicateEditorRowTemplate that reflects the change,  
and set it on the NSPredicateEditor in place of the old one, with  
setRowTemplates:


I think you may also need to save off the predicate editor's object  
value first, and then set it back on after calling setRowTemplates:.

___

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: NSToolBar : Unable to add a seperator item in the toolBar

2009-05-19 Thread Peter Ammon
This code is correct.   You may have customized the toolbar as a user,  
so that toolbarDefaultItemIdentifiers is not called.  In that case,  
you can throw away the preferences file for testing.  Otherwise,  
you'll have to explain what you mean by not working.


On May 19, 2009, at 10:26 AM, Arun wrote:


Hi,
I have an application in which i added 2 buttons and one search view  
in the
too bar. I need to insert a seperator in between search view and 2  
buttons.
I have tried the following in my code. and it is not working. Any  
idea?


- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
{
   return [NSArray arrayWithObjects:[NSString
stringWithString:serachIdentifier],
   NSToolbarSeparatorItemIdentifier,
   [NSString stringWithString:Button1ToolbarItemIdentifier],
   [NSString stringWithString:Button2ToolbarItemIdentifier],
nil];
}

- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
{
   return [NSArray arrayWithObjects:searchIdentifier,
   NSToolbarSeparatorItemIdentifier,
   Button1ItemIdentifier,
   Button2ItemIdentifier, nil];
}


Thanks
Arun KA


___

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: NSPopupButton with blurry image

2009-05-18 Thread Peter Ammon

Hi Gideon,

It sounds like the PDF image is being rasterized at the point you sent  
it on the menu item, and being cached into a NSCachedImageRep; for the  
subsequent menu items the cache is used.


If you can arrange for the image to be rasterized before the being set  
on the menu item, it would probably fix the problem.  The simplest way  
to rasterize the image is to draw it; or alternatively make a new  
image of the right size, lock focus onto it, draw your PDF into the  
new image, unlock focus, and set the new image on the menu item.


On May 18, 2009, at 10:26 AM, Gideon King wrote:

Hi, I have an NSPopupButton which I am populating programmatically.  
The button class is set to square because I need it to be bigger  
than the standard popup button. I am setting an image on each menu  
item (the images are produced as PDF images).


All the images appear correctly, but when I pop up the menu the  
first image is always blurry, and the remainder of the images are  
crisp. It's as if the first image has been stretched. As an  
experiment I put the second image as the same image as the first,  
and now it appeared stretched too, which appears to prove the point.


Is this a known issue? How should I ensure that my image is not  
stretched?


TIA
Gideon
___

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/pammon%40apple.com

This email sent to pam...@apple.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: Packages vs bundles vs folders etc

2009-05-11 Thread Peter Ammon


On May 10, 2009, at 10:43 PM, Chris Idou wrote:



 Would it be fair to say that if a path is a directory, and if the  
kMDItemContentType != public.folder then  
NSWorkspace.isFilePackageAtPath would

return YES?

No.  A non-package directory may not even conform to  
public.folder.  For example, volume mount points have the type ID  
public.volume, which does
conform; but frameworks have the type ID public.framework, which  
does not conform.


But isn't a framework a package, thus making my statement correct?  
If a framework is not a package, then what specifically makes a  
package a package that a framework doesn't fit?




Frameworks are not packages.  A package is a directory that is  
presented as a single file to the user, but frameworks are shown as  
folders and are browsable like other folders.


You can check the UTI hierarchy in the UTCoreTypes.h header (try open - 
h UTCoreTypes.h).


Perhaps I should state my question more explicitly. I'm trying to  
figure out what things should be copied atomically. When a directory  
is really a bundle (is a bundle == package?), then it must be  
considered as one unit. If it's just a folder, then the files  
therein have their own unique reasons for existing. But I'm  not  
sure which API exactly will give me the distinction I want to make.



If you copy two folders, Finder reports the total number of items  
contained within them; but if you copy two applications, Finder  
reports only two items.  Is that the sort of distinction you want to  
make?


If so, I think you're on the right track.  On Leopard, I would get the  
UTI of a file via -[NSWorkspace typeOfFile: error:], and then see if  
it conforms to kUTTypeFolder via -[NSWorkspace type:fileType  
conformsToType:(NSString *)kUTTypeFolder].  If it does NOT conform, it  
should be treated as a single item.


If you need Tiger compatibility, you can do the same thing, except you  
would use LaunchServices functions like LSCopyItemAttribute().


-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 arch...@mail-archive.com


Re: Packages vs bundles vs folders etc

2009-05-11 Thread Peter Ammon
Frameworks act like folders so that users can browse their header  
files in Finder.  As a developer, I think I would want that frameworks  
be treated atomically for synchronization purposes.


My understanding is that Finder decides that frameworks are user  
browsable because they're directories, but not packages.  Applications  
are not user browsable because they descend from com.apple.package.   
The bundle type says something about how the directory's contents are  
arranged; the package type says something about how it should be  
presented to the user.  You can have either, both, or neither.


Unfortunately I don't know the details of Spotlight or iDisk  
synchronization with respect to these types.


On May 11, 2009, at 5:11 AM, Chris Idou wrote:



I'm surprised that frameworks act like folders in Finder, yet don't  
conform to public.folder.


To be more explicit, I'm writing some code that synchronises two  
folders. If directory A contains file X and directory B contains  
file Y, then synchronising them depends on what kind of directory it  
is. If it is a package, then a resulting package containing files X  
and Y would be wrong, it could be a corrupt package. Folders should  
be synchronised and have both X and Y. But I'm not sure about  
frameworks being neither a folder nor a package. What would users  
expect?


Hmm, I see that bundle, package and folder are the three decendents  
of public.directory. framework conforms to bundle rather than  
package and appears in the finder like a folder. However  
applications descend from bundle and do NOT appear like folders.


Why does finder decide that frameworks appear like folders?

And which items does spotlight indexing delve into? Which items  
would iDisk synchronise atomically?


From: Peter Ammon pam...@apple.com
To: Chris Idou idou...@yahoo.com
Cc: cocoa-dev@lists.apple.com
Sent: Monday, 11 May, 2009 4:02:17 PM
Subject: Re: Packages vs bundles vs folders etc


On May 10, 2009, at 10:43 PM, Chris Idou wrote:



 Would it be fair to say that if a path is a directory, and if  
the kMDItemContentType != public.folder then  
NSWorkspace.isFilePackageAtPath would

return YES?

No.  A non-package directory may not even conform to  
public.folder.  For example, volume mount points have the type ID  
public.volume, which does
conform; but frameworks have the type ID public.framework, which  
does not conform.


But isn't a framework a package, thus making my statement correct?  
If a framework is not a package, then what specifically makes a  
package a package that a framework doesn't fit?




Frameworks are not packages.  A package is a directory that is  
presented as a single file to the user, but frameworks are shown as  
folders and are browsable like other folders.


You can check the UTI hierarchy in the UTCoreTypes.h header (try  
open -h UTCoreTypes.h).


Perhaps I should state my question more explicitly. I'm trying to  
figure out what things should be copied atomically. When a  
directory is really a bundle (is a bundle == package?), then it  
must be considered as one unit. If it's just a folder, then the  
files therein have their own unique reasons for existing. But I'm   
not sure which API exactly will give me the distinction I want to  
make.



If you copy two folders, Finder reports the total number of items  
contained within them; but if you copy two applications, Finder  
reports only two items.  Is that the sort of distinction you want to  
make?


If so, I think you're on the right track.  On Leopard, I would get  
the UTI of a file via -[NSWorkspace typeOfFile: error:], and then  
see if it conforms to kUTTypeFolder via -[NSWorkspace type:fileType  
conformsToType:(NSString *)kUTTypeFolder].  If it does NOT conform,  
it should be treated as a single item.


If you need Tiger compatibility, you can do the same thing, except  
you would use LaunchServices functions like LSCopyItemAttribute().


-Peter


Chat right from the comfort of your inbox. Show me how..


___

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: Attr Str drawing vs Layout Manager drawing

2009-05-10 Thread Peter Ammon


On May 10, 2009, at 2:24 PM, Seth Willits wrote:



If I create a text view, type in some text with different styles  
multiple lines etc, and grab the attributed string object, when I  
draw that attributed string using drawInRect: with the same bounds  
as the text view, there are small differences between the two. The  
line height seems to be one point different, and there's also an  
offset for all text, which seems to simply be {5, 0}. The text  
container inset is {0, 0} so I'm not sure what's causing the offset,  
nor do I know why the line height is different.


Does anyone know? I'd really like the two to line up.


Hi Seth,

You may be seeing differences in the typesetter behavior.  See the  
discussion of typesetter behaviors at http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Concepts/Typesetters.html 
 and the String Drawing and Typesetter Behavior topic at http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/Tasks/DrawingStrings.html


-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 arch...@mail-archive.com


Re: Packages vs bundles vs folders etc

2009-05-10 Thread Peter Ammon


On May 10, 2009, at 6:46 PM, Chris Idou wrote:




Would it be fair to say that if a path is a directory, and if the  
kMDItemContentType != public.folder then  
NSWorkspace.isFilePackageAtPath would return YES?


No.  A non-package directory may not even conform to public.folder.   
For example, volume mount points have the type ID public.volume, which  
does conform; but frameworks have the type ID public.framework, which  
does not conform.


And conversely if a path is not a directory or the  
kMDItemContentType == public.folder, then  
NSWorkspace.isFilePackageAtPath would return NO?


I'm pretty sure this is true.  All packages are directories, and no  
package type conforms to public.folder, or ever will.


-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 arch...@mail-archive.com


Re: Obvious NSSegmentedControl Bug?

2009-04-13 Thread Peter Ammon
This looks like a bug.  I appreciate your taking the time to check and  
hopefully to file it.


-Peter

On Apr 12, 2009, at 1:22 PM, Seth Willits wrote:



I need a sanity check before I file a bug report.



sc is a 3-segment NSSegmentedControl with either Select One or  
Select Any as its mode. Segment 1 (the middle one) is selected in  
IB. Triggered as an action:



NSLog(@Before:);
NSLog(@  %d, [sc selectedSegment]);
NSLog(@  %@, [sc isSelectedForSegment:0] ? @YES : @NO);
NSLog(@  %@, [sc isSelectedForSegment:1] ? @YES : @NO);
NSLog(@  %@, [sc isSelectedForSegment:2] ? @YES : @NO);

[sc setSelected:NO forSegment:[sc selectedSegment]];

NSLog(@After:);
NSLog(@  %d, [sc selectedSegment]);
NSLog(@  %@, [sc isSelectedForSegment:0] ? @YES : @NO);
NSLog(@  %@, [sc isSelectedForSegment:1] ? @YES : @NO);
NSLog(@  %@, [sc isSelectedForSegment:2] ? @YES : @NO);


Before:
 1
 NO
 YES
 NO

After:
 1
 NO
 NO
 NO


selectedSegment: [Returns t]he index of the currently selected  
segment, or -1 if no segment is selected.



No segment is selected so selectedSegment should clearly be -1, right?


___

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: how to load an NSMenu out of a nib?

2009-04-08 Thread Peter Ammon


On Apr 8, 2009, at 2:47 PM, Rua Haszard Morris wrote:


I'm baffled, this seems fundamental, I can't see how it's done!

I have a Menu in a nib file, which I need to use in a few places in  
code. So I want to do something like


NSMenu* myMenu = [NSMenu menuFromNib:@MyNibFile  
name:@MyUsefulMenu];


Is this possible - how can this be done?

I have looked at the NSMenu reference, how to unarchive Carbon menus  
(but there is no toll free mapping/other conversion between MenuRef  
and NSMenu?). It seems the only way to get this working is to have  
an class with an outlet specifically for receiving a reference to my  
menu - which seems indirect...


Hopefully this is a dumb question and there's an easy answer...


Making a class with an outlet, and passing an instance of that class  
as the nib's owner, is one way.


You can also use the NSNibTopLevelObjects key as described at the  
bottom of http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSNib_Class/Reference/Reference.html 
 .  You pass an NSMutableArray under this key, and after the nib is  
loaded, the array is populated with the top level objects in the nib.


-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 arch...@mail-archive.com


Re: NS - CG Rect Conversion and screen coordinates

2009-04-01 Thread Peter Ammon


On Mar 31, 2009, at 9:34 PM, Trygve Inda wrote:


Using these two calls:

NSRect nsRect = [screen frame];
CGRect cgRect = CGDisplayBounds (displayID);

I get for my two screens:

NSx=0y=0  w=2560h=1600  // screen A
CGx=0y=0  w=2560h=1600

NSx=-1920y=184w=1920h=1200  // screen B
CGx=-1920y=216w=1920h=1200


It seems CG origin is Top, Left with y growing down, while NS is  
origin

Bottom, Left, y growing up. So I convert CG to NS with:

// Convert CG coordinates from (TL, y down) to (BL, y up)

CGRectmainScreenRect = CGDisplayBounds (CGMainDisplayID ());

cgRect.origin.y = (cgRect.origin.y + cgRect.size.height -
mainScreenRect.size.height) * -1;

(216 + 1200 - 1600) * -1 = 184

Is there a system function that does this? NSRectFromCGRect does not  
do the

coordinate conversion.


No, there is no function to do this conversion.

Note that your conversion has a subtle bug that will fail for multiple  
displays.  The CG coordinate system has its origin at the top of the  
zero screen, not the main screen (which changes with the user focus).   
The zero screen is the screen at index zero in the +screens array.


So if you define a function like this:

CGFloat zeroScreenHeight(void) {
   CGFloat result = 0;
   NSArray *screens = [NSScreen screens];
   if ([screens count]  0) result = NSHeight([[screens objectAtIndex: 
0] frame]);

   return result;
}

then you can do screen-coordinate conversions like this:

NSMakePoint(cgPoint.x, zeroScreenHeight() - cgPoint.y);
NSMakeRect(cgRect.origin.x,  zeroScreenHeight() - cgRect.origin.y -  
cgRect.size.height, cgRect.size.width, cgRect.size.height);


-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 arch...@mail-archive.com


Re: NS - CG Rect Conversion and screen coordinates

2009-04-01 Thread Peter Ammon
My mistake, I saw mainScreenRect and assumed it was the frame of what  
Cocoa calls the main screen.


-Peter

On Apr 1, 2009, at 2:52 PM, Jesper Storm Bache wrote:


Forgive me for being dense. Where is the subtle bug?
The code is using CGMainDisplayID (not [NSScreen mainScreen] which  
would be the display with the key window)


CGMainDisplayID is documented as:
===
The main display is the display with its screen location at (0,0) in  
global coordinates. In a system without display mirroring, the  
display with the menu bar is typically the main display.

===

I would expect that CGRectGetHeight(CGDisplayBounds (CGMainDisplayID  
())) == zeroScreenHeight()?



Jesper Storm Bache
Core Technologies
Adobe Systems Inc


On Apr 1, 2009, at 12:25 PM, Peter Ammon wrote:



On Mar 31, 2009, at 9:34 PM, Trygve Inda wrote:


Using these two calls:

NSRect nsRect = [screen frame];
CGRect cgRect = CGDisplayBounds (displayID);

I get for my two screens:

NSx=0y=0  w=2560h=1600  // screen A
CGx=0y=0  w=2560h=1600

NSx=-1920y=184w=1920h=1200  // screen B
CGx=-1920y=216w=1920h=1200


It seems CG origin is Top, Left with y growing down, while NS is
origin
Bottom, Left, y growing up. So I convert CG to NS with:

// Convert CG coordinates from (TL, y down) to (BL, y up)

CGRectmainScreenRect = CGDisplayBounds (CGMainDisplayID ());

cgRect.origin.y = (cgRect.origin.y + cgRect.size.height -
mainScreenRect.size.height) * -1;

(216 + 1200 - 1600) * -1 = 184

Is there a system function that does this? NSRectFromCGRect does not
do the
coordinate conversion.


No, there is no function to do this conversion.

Note that your conversion has a subtle bug that will fail for  
multiple

displays.  The CG coordinate system has its origin at the top of the
zero screen, not the main screen (which changes with the user focus).
The zero screen is the screen at index zero in the +screens array.

So if you define a function like this:

CGFloat zeroScreenHeight(void) {
  CGFloat result = 0;
  NSArray *screens = [NSScreen screens];
  if ([screens count]  0) result = NSHeight([[screens objectAtIndex:
0] frame]);
  return result;
}

then you can do screen-coordinate conversions like this:

NSMakePoint(cgPoint.x, zeroScreenHeight() - cgPoint.y);
NSMakeRect(cgRect.origin.x,  zeroScreenHeight() - cgRect.origin.y -
cgRect.size.height, cgRect.size.width, cgRect.size.height);

-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/jsbache%40adobe.com

This email sent to jsba...@adobe.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: custom toolbar item autoresizing?

2009-03-31 Thread Peter Ammon


On Mar 31, 2009, at 12:16 PM, John Mikros wrote:


Hello all,

I have a custom view in an NSToolbar.  I would like this item to  
expand as much as possible, similar to  
NSToolbarFlexibleSpaceItemIdentifier, or similar to the address bar  
in Safari.


I was hoping that setting the min and max size on the NSToolbarItem  
would cause this to happen, but it does not.


Is there some trick to this?

thanks
-john


Setting the minimum and maximum size should be enough.  See the search  
field in the SimpleToolbar example (/Developer/Examples/AppKit/ 
SimpleToolbar/) for sample code.


-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 arch...@mail-archive.com


Re: NSLog fixes output, but why?

2009-03-18 Thread Peter Ammon


On Mar 18, 2009, at 3:05 PM, James Maxwell wrote:


I've got a really frustrating, and really silly problem.

I have some fairly complex machine learning code I'm working on.  
I've noticed inconsistent output from a particular method. I'm doing  
some fairly nasty array and matrix stuff, which is all done in C,  
and I pass the arrays around wrapped in NSData objects. What's  
really strange is that, in this particular method, if I place an  
NSLog after calling and unwrapping a particular 2D matrix, then the  
output is as expected. If I remove the NSLog, the output is  
incorrect (or at least, unexpected). The system is pretty complex,  
and involves 4 different classes, so I won't post it here, and  
obviously I don't expect any magical help. But does anybody have any  
experience with something this flaky? Whereby literally adding a  
single NSLog (and thus obviously slowing things down a fair bit)  
makes the method run correctly?... It's just bizarre, to me.


Maybe somebody here has worked their way into a similar corner?  
Obviously I've done something stupid somewhere, but I don't really  
know how to go about finding it. It was weird enough to realize that  
the NSLog could make or break my output - tracking down the actual  
reason why is just baffling... Everything being done in these  
classes is basically procedural stuff, so it doesn't seem like  
timing should dramatically influence the output. But I am doing  
*lots* of iterations over this data. Does that suggest anything?


Any thoughts very much appreciated.

cheers,

J.


Hi James,

I once encountered a case that sounds similar.  I had a method that  
returned a BOOL (signed char).  I expected the return value to be  
false, but the calling method behaved as it had received true.  When I  
added a debugging printf() inside the callee, the caller bizarrely  
started getting back false.  A Heisenbug if there ever was one!


The problem turned out to be as follows: the caller did not have a  
declaration for the method it was calling.  This causes the compiler  
to assume that the callee returned an id (much like implicit int in  
C), so it looked at all four bytes of the return register.  But the  
callee returned just one byte, so it only bothered to set the least  
significant byte in the return register.  Thus the caller ended up  
comparing NULL to whatever garbage happened to be in the remainder  
three bytes of %eax.


printf() returns an int containing the number of characters written.   
Since I was writing fewer than 256 characters, the upper three bytes  
of %eax were all 0 - it cleared exactly the portion that needed  
clearing.  So it happened to work.  But without the printf(), nothing  
cleared those bytes and I'd often get nonzero when I expected zero.


So make sure that every caller of your method has a declaration of  
that method in scope.  If that's not it, hope you enjoyed the war story.


-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 arch...@mail-archive.com


Re: Performance problem with GC enabled

2009-03-13 Thread Peter Ammon


On Mar 13, 2009, at 4:47 PM, John Engelhart wrote:


On Thu, Mar 12, 2009 at 3:17 PM, Peter Ammon pam...@apple.com wrote:


Hi John,

Instead of storing each string individually into the heap, try  
batching up,

say, 1k or so into a stack allocated buffer.  Then use
objc_memmove_collectable() to move them in bulk into the heap at  
the point

your stack allocated buffer gets full, or your scan finishes.



I actually did give this a shot, or something close to it.  I tried
using just the stack (swapping NSAllocateCollectable() with alloca()),
but no joy- exactly the same times came out.  Good call though.



That wasn't quite my suggestion, and I would not expect that to result  
in any improvement.  If you store an object through an arbitrary  
pointer, the compiler will use a write barrier.  I doubt the compiler  
will figure out that because the memory came from alloca(), it is on  
the stack.


The goal is for the compiler to not use individual write barriers at  
all, and it won't for stack allocated buffers.  So my suggestion is to  
make a buffer that the compiler knows is on the stack:


id stackBuffer[1024];

Stores to that buffer will not go through write barriers.  When that  
buffer is full, use objc_memmove_collectable() to move it to the heap.


I wrote a quick test to try this and it resulted in a 10x speedup  
compared to individual write barriers.


-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 arch...@mail-archive.com


Re: Performance problem with GC enabled

2009-03-13 Thread Peter Ammon


On Mar 13, 2009, at 7:59 PM, John Engelhart wrote:


On Fri, Mar 13, 2009 at 8:26 PM, Peter Ammon pam...@apple.com wrote:



http://c-faq.com/malloc/alloca.html for a rough idea why)

The goal is for the compiler to not use individual write barriers  
at all,
and it won't for stack allocated buffers.  So my suggestion is to  
make a

buffer that the compiler knows is on the stack:

id stackBuffer[1024];

Stores to that buffer will not go through write barriers.  When  
that buffer

is full, use objc_memmove_collectable() to move it to the heap.

I wrote a quick test to try this and it resulted in a 10x speedup  
compared

to individual write barriers.


Ok, now I see where you're going.  I'll certainly give it a whirl, but
it's going to make swiss cheese out of the code with #ifdef
__OBJC_GC__ statements, unfortunately. (the code needs to work with or
without GC (w/o -fobjc-gc*), and with or without -std=(c|gnu)99 and
thus the use of alloca(), not VLAs).


I think you're saying that it's more convenient for you to work with a  
pointer than directly with an array.  If so, another way you can  
defeat write barriers is with a cast to void*:


void func(id *ptr) {
   ptr[0] = @foo; // --- write barrier
   ((void **)ptr)[0] = @bar; //  no write barrier
}

Of course, this is only safe if the pointer points at something not in  
the GC heap, e.g. on the stack or in malloc()ed memory.  If you store  
into the GC heap this way, your object is likely to be prematurely  
collected.




Thanks for the suggestion.   Hmmm, that does raise the obvious
question of Does objc_memmove_collectable() hold the GC lock the
entire time it's doing its thing?  If so, it'll probably make some
sense to find that sweet spot where you hit the point of diminishing
returns so you keep the lock for as short a time as possible.


I believe it does hold the lock the entire time in Leopard.

-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 arch...@mail-archive.com


Re: Performance problem with GC enabled

2009-03-12 Thread Peter Ammon


On Mar 12, 2009, at 6:04 AM, John Engelhart wrote:



This is (obviously) due to -fobjc-gc turning the storing of a __strong
pointer in to a call to objc_assign_strongCast().  Each and every call
to objc_assign_strongCast, in turn, grabs a gc lock before it does its
work.  Soo.. what was a simple, single movl instruction of the
returned pointer in to the matchedStrings array has now turned in to,
at a minimum, a function call and an expensive mutex lock acquisition,
a lock that is pretty heavily contested to boot, and that doesn't even
include any of the work done inside the function itself.



This kind of reduction in performance is just flat out unacceptable,
and I can't think of anything I can do to speed things up.  Any ideas?



Hi John,

Instead of storing each string individually into the heap, try  
batching up, say, 1k or so into a stack allocated buffer.  Then use  
objc_memmove_collectable() to move them in bulk into the heap at the  
point your stack allocated buffer gets full, or your scan finishes.


-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 arch...@mail-archive.com


Re: A question about NSPredicateEditor and NSPredicateEditorRowTemplate

2009-03-06 Thread Peter Ammon


On Mar 6, 2009, at 6:42 AM, David Hoerl wrote:


[following up to a Jan 08 thread]


 is it possible to modify the width of the NSTextField representing

a Number in a NSPredicateEditorRowTemplate ?


Yes, but not yet in Interface Builder.  To do so programatically,  
get the row template, get the text field as the last member of the  
row template's templateViews array, and set its frame to the size  
you want.


I hope that helps,
-Peter



Peter, I tried to do as you suggest - set the frames to what I want,  
but it has no effect. Any other suggestions?


David

PS: code

-applicationDidFinishLaunching
...
   int i = 0;
   NSArray *temps = [predicateEditor rowTemplates];
   for(NSPredicateEditorRowTemplate *temp in temps) {
   NSArray *views = [temp templateViews];
   int j = 0;
   int x = 0;
   for(NSControl *view in views) { // I know, view is not a good  
name for this :-)
   NSLog(@temp=%@ view=%@ frame: %@, temp, view,  
NSStringFromRect([view frame])); // verify all is connected

   if(i==0) continue; // don't touch first one
   NSRect r = [view frame];
   r.origin.x = 0; // just for testing impact...
   [view setFrame:r];
   NSLog(@ mod frame=%@, NSStringFromRect([view  
frame])); // yes, it took

   ++j;
   }
   ++i;
   }


David, the above code changes the frame origin, but not the frame  
width.  Changing the frame origin will have no effect (the origins are  
controlled by NSPredicateEditor).  But changing the width should have  
an effect.


-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 arch...@mail-archive.com


Re: Images In Dock Menu?

2009-02-13 Thread Peter Ammon


On Feb 13, 2009, at 3:27 PM, Chunk 1978 wrote:


i have a NSMenu that i use as both a right-click menu and the dock
menu.  The images i use for some of the menu items will appear in the
right-click menu, but they do not show up in the dock menu.

i've connected the the File's Owner dockMenu to the NSMenu in IB so to
add the menu to the app's dock menu.  i've searched for an answer in
the archives, but it seems that this has been a known issue since
2003?


The Dock menu is more limited than a general menu, because it has to  
be sent to the Dock process, where it's shown.  Images are not  
supported in it.


-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 arch...@mail-archive.com


Re: NSToolbarItems - deallocating view-based items

2009-02-10 Thread Peter Ammon


On Feb 9, 2009, at 7:13 PM, Steve Cronin wrote:


Folks;

I have a mix of view and image based toolbar items.
The views are all IBOutlets defined in IB.
Everything is working well - events are handled and items  
arevalidated, everything is dandy.


Except when the user customizes the toolbar.

The image based items can be added and removed 'till the cows come  
home

BUT the view based items   -  not so much...
They can be added and then they can be removed.
But once they are removed they cannot be re-added unless the  
application is quit and restarted.
Attempting to re-add a view-based toolbar item that has been removed  
causes a message like the following:
 -[NSSearchField retain]: message sent to deallocated instance  
0x19b83490 



Sooo what is the correct way to handle this?
I guess I'm puzzled by the IBOutlet aspect..


Hi Steve,

Make sure that your implementation of  
toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar: returns a  
toolbar item with a fresh view each time.  That should take care of  
this problem.


-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 arch...@mail-archive.com


Re: NSService - I need a headslap

2009-02-04 Thread Peter Ammon

Hi Steve,

What appears in the Services menu is entirely determined by the  
NSServices portion of your Info.plist.  If you post that to the list,  
we can look for any problems.


Your Service is launched on-demand when the user selects it from the  
menu.  Services may be background only, but do not have to be.


On Tiger and earlier, there is no way to avoid needing to log in and  
out.  On Leopard, you can use the function NSUpdateDynamicServices()  
to immediately scan for new Services.  If you're just testing, a quick  
way to scan for new Services is to run pbs directly:


/System/Library/CoreServices/pbs

However, pbs has no supported public interface and this will (has  
already) change, so don't include any reference to pbs in a script.   
NSUpdateDynamicServices() is the right way to programmatically refresh  
Services.


-Peter

On Feb 4, 2009, at 7:03 AM, Steve Cronin wrote:

Well, sheesh - that's embarrassing!   There is no 'self' until init  
- I know that!  Ugh.


However, that doesn't change my end result!

I never see anything on the Services menu nor anything from the  
NSLog statements shown below.
(Even when I double-click on the .service file;  after whcih I CAN  
see it in the process list in Activity monitor but still no log  
messages)
Logging out and back in doesn't make my service name appear on the  
Service menu...
This is on a 10.5.6 system using a Release build which has been  
placed in ~/Library/Services.


SO my basic questions still stand:
What event/conditions launches a .service which resides in ~/Library/ 
Services?

Should/must .service files be 'Background Only'?
Am I missing something basic in my setup here -
I have only a Info.plist and 1 .h (NSObject) and 2 . m files (main  
and MyService) and no .xib?
Other than the 'wrapper' settings are there other compiler settings  
required for this setup?
I have only 2 steps in my build process: 'Compile Source (2)' and  
'Link Binary w/ Lib (1)' [Cocoa]



___

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: NSToolbar and constrolling visible items

2009-02-02 Thread Peter Ammon


On Jan 31, 2009, at 8:07 AM, Ferhat Ayaz wrote:


Hello,

I have added - (BOOL)validateToolbarItem:(NSToolbarItem  
*)toolbarItem  to my code, which will control whether a toolbar item  
is enabled or not. However, I need a something similar to control  
whether a toolbar item is visible or not.


How can I do this?

Thank you,
Ferhat


You should probably just use multiple toolbars, and switch among them  
with setToolbar:.

___

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: Adding rows in NSPredicateEditor

2009-01-26 Thread Peter Ammon


On Jan 25, 2009, at 3:25 AM, Tom wrote:


Hi everyone,

I'm wondering if there is a way I can control which row template  
gets added when the user clicks the '+' button on an  
NSPredicateEditor. The template chosen seems to be random, but I  
want it to be a specific one for user convenience.


Kind regards,


Tom


Hi Tom,

Unfortunately there's no easy way to control this yet.  Please file an  
enhancement request.  Thanks!


Note that the current algorithm is not random: it picks the first  
unused rule in a breadth-first search.


-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 arch...@mail-archive.com


Re: A question about key equivalents for menu items

2009-01-26 Thread Peter Ammon


On Jan 26, 2009, at 2:57 PM, Slava Pestov wrote:


Hi all,

Is there a nice way to get a Unicode string from a keyboard shortcut,
that looks like the key equivalents in NSMenuItems, for rendering
elsewhere in a GUI?

Slava


Hey Slava,

No such function, unfortunately.  You can roll your own with the  
Unicode characters for the modifier keys (0x2303, 0x2325, 0x21E7,  
0x2318 for control, option, shift, and command), though there's still  
some special cased glyphs, like space.  This would be worth an  
enhancement request.


-Peter

PS: Keep up the good work on Factor, it's way cool!

___

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: Show In Menu Bar Option?

2009-01-21 Thread Peter Ammon


On Jan 21, 2009, at 10:34 AM, Chunk 1978 wrote:


what is the proper way to update the menu bar after switching the view
of the app's menu bar extension?  force quit the SystemUIServer?  or
actually just quit the SystemUIServer?  or is there a more common
method to updating the menu bar?


I think what you are asking is, you have an NSStatusItem and you call  
setView: on it.  In this case, the status item should redraw  
automatically with the new view.  You should not need to interact with  
SystemUIServer.


-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 arch...@mail-archive.com


  1   2   >