Re: Best guess at expressing a string as a variable
On 23 Jan 2013, at 01:32, Keary Suska cocoa-...@esoteritech.com wrote: On Jan 22, 2013, at 6:18 PM, Jens Alfke wrote: On Jan 22, 2013, at 3:28 PM, jonat...@mugginsoft.com wrote: Is + (id)letterCharacterSet the best choice here? The API docs say Informally, this set is the set of all characters used as letters of alphabets and ideographs.” Which very strongly implies it is not just ASCII, but covers all Unicode alphabets. Some languages, like Java and Go, can handle non-ASCII letters in identifiers, but most can’t. I would stick with a character set consisting of only upper and lowercase ASCII letters, digits and the underscore. And you’d probably want to force the first character to be a lowercase letter since some languages assign special meaning to identifiers that start with a capital letter or with an underscore. I was thinking that by language the OP meant linguistic rather than programming. Yes I mean linguistic language rather than programming. For the latter it is a bit easier to find the lowest common denominator, which is probably strictly ascii alpha and numbers, beginning with lowercase alpha and probably even a character limit of around 12. That would automatically exclude the identifier pattern example provided as most languages do not permit dashes in identifier names (that I know of). After a bit more experimenting it is clear that restricting the variable's character set is sensible. I think I will have to introduce an intermediate NSTextView that filters and displays the natural language input. The user can then modify the variable name if necessary before it gets utilised further. So the approach may be: 1. decompose the input with decomposedStringWithCanonicalMapping 2. build a NSMutableCharacterSet that asserts +alphanumericCharacterSet. The docs for +alphanumericCharacterSet A character set containing the characters in the categories Letters, Marks, and Numbers. So I think this means that I will have to also exclude + nonBaseCharacterSet. The actual content of an NSCharacterSet is only accessible via -bitmapRepresentation which makes previewing the content slightly involved. Additionally, for higher-level interpreted languages the app would need to understand identifier prefixes such as $, @ and % (and maybe ). The output from this is processed through a Mustache template that takes care of all the variable name decoration ($, @, - and the like). The template will also enforce case (upper, lower, Pascal etc) and white space handling (remove, -, _ etc) Thanks for the suggestions. Jonathan ___ 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: Best guess at expressing a string as a variable
On 23 janv. 2013, at 02:18, jonat...@mugginsoft.com jonat...@mugginsoft.com wrote: My current thinking is, regardless of the language, is to exclude all characters that are not members of NSCharacterSet + (id)letterCharacterSet. Is + (id)letterCharacterSet the best choice here? I don't know. Does it include characters in すごくやる気がある ? That is the question. I don't know what range of character ranges + letterCharacterSet includes. A better question might be what is the intended use of + letterCharacterSet. Is it locale dependent? That's a fair question. As Jens Alfke pointed out yesterday, the doc states: Return value: A character set containing the characters in the categories Letters and Marks. Discussion : Informally, this set is the set of all characters used as letters of alphabets and ideographs. So, it should not depend on the locale. It is however a huge set ! And I guess that you may not want most of it (all chinese ideograms for instance) Hmm. Maybe not. I want to keep the generated variable name legible. I think I will have to introduce an intermediate NSTextView that filters and displays the natural language input. The user can then modify the variable name if necessary before it gets utilised further. Maybe you could drop the extra textfields and the processing by requesting the variable name to use an english alphanumeric character set ? Otherwise, how would you deal with this input for a variable name: 名前 ? [ If I am a japanese user, I would expect your software to call the variable namae ]. IMHO the whole unicode character set is too large. Most language won't accept the largest part of the set. Jean --- Jean Suisse Institut de Chimie Moléculaire de l’Université de Bourgogne (ICMUB) — UMR 6302 ___ 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: Best guess at expressing a string as a variable
On 23 Jan 2013, at 11:40, Jean Suisse jean.li...@gmail.com wrote: On 23 janv. 2013, at 02:18, jonat...@mugginsoft.com jonat...@mugginsoft.com wrote: My current thinking is, regardless of the language, is to exclude all characters that are not members of NSCharacterSet + (id)letterCharacterSet. Is + (id)letterCharacterSet the best choice here? I don't know. Does it include characters in すごくやる気がある ? That is the question. I don't know what range of character ranges + letterCharacterSet includes. A better question might be what is the intended use of + letterCharacterSet. Is it locale dependent? That's a fair question. As Jens Alfke pointed out yesterday, the doc states: Return value: A character set containing the characters in the categories Letters and Marks. Discussion : Informally, this set is the set of all characters used as letters of alphabets and ideographs. So, it should not depend on the locale. It is however a huge set ! And I guess that you may not want most of it (all chinese ideograms for instance) My naive thought was that I could use this admittedly huge character set. Bad idea. Hmm. Maybe not. I want to keep the generated variable name legible. I think I will have to introduce an intermediate NSTextView that filters and displays the natural language input. The user can then modify the variable name if necessary before it gets utilised further. Maybe you could drop the extra textfields and the processing by requesting the variable name to use an english alphanumeric character set ? Otherwise, how would you deal with this input for a variable name: 名前 ? [ If I am a japanese user, I would expect your software to call the variable namae ]. I think that if the user enters the like of 名前 as a parameter title I will filter its decomposed version using the alphanumeric character set. This will give an empty string which I will then default to something sensible. Basically an alphanumeric approach will be, by definition, very tough on non alphabetic input. A Japanese speaker using the app to generate scripts will know how to program, hence entering some alpha numerics should be trivial. A Japanese speaker using the app just to execute the script will see the 名前 parameter title only. Thanks for the suggestions. Jonathan ___ 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: Best guess at expressing a string as a variable
On Jan 23, 2013, at 2:18 AM, jonat...@mugginsoft.com wrote: Hmm. Maybe not. I want to keep the generated variable name legible. You need to nail down the languages you want to deploy to, and then find out what their criteria for identifiers are. Then you can decide to either generate identical lowest-common-denominator-names for all of them (which is [a-zA-Z_]([a-zA-Z_0-9]*) in the case of C, i.e. it may not start with a number either), or adjust what characters to permit based on the target programming language. Apart from character set, you may also have to be aware of length limits etc. Early C compilers, for instance, only used the first 8 characters of an identifier. So ExceptionalHouse and ExceptionalCow both ended up as the same identifier, Exceptio. I'm hard pressed to think of a language with such a limit today, but I don't know what languages your targeting. Maybe one has such a limit. If you have a case where you can't express a character in a particular character set, you have several options: 1) Transcribe it to an equivalent character set. E.g. U-Umlaut (ü) is usually written as ue. However, you will then have to deal with collisions. E.g. what if one user enters the word Frauen, but another makes up a new word Fraün. The latter would transcribe to the former, and you might get unexpected side effects. You might have to generate a look-up-table, and if you find a collision like that, make the name unique again, e.g. by naming one frauen and the other frauen2. IIRC there are official transcriptions for many languages, e.g. Romanji for Japanese characters. 2) Fail and tell the user what the valid characters are, and only let them enter valid characters. 3) Transcribe in some other way, e.g. by base64-encoding, or using a hex-representation of the given byte sequence, or whatever. This way you could keep ASCII sentences valid, but modify everything else. But even then you could have collisions. E.g. if you replace spaces with underscores, what if there's a second version with the underscore? Is + (id)letterCharacterSet the best choice here? According to the docs (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCharacterSet_Class/Reference/Reference.html): An NSCharacterSet object represents a set of Unicode-compliant characters. The +letterCharacterSet documentation says Returns a character set containing the characters in the categories Letters and Marks. So a Google later, here http://www.fileformat.info/info/unicode/category/index.htm the categories mentioning Letters include greek characters, accented characters, hiragana and cyrillic characters among others (most of which are invalid as C identifier names). Oddly, marks seem to include some kind of punctuation. I couldn't find a section that is obviously only letters and marks or two separate letters and marks sections. Anyway, I think building your own custom character set from a string including the characters you *know* are valid identifiers in your target programming language(s) is probably the route of least surprise. Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://hammer-language.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 avoid warning?
On Jan 22, 2013, at 8:12 PM, Jens Alfke j...@mooseyard.com wrote: @interface SomeFictionalClassName - (id) initWithManager: (Foo*)manager; @end That feels a bit dirty to me. I'd recommend using a protocol instead. As long as the compiler has seen the method *somewhere*, it will consider it having been declared. So @protocol AvoidCompilerWarning - (id) initWithManager: (Foo*)manager; @end is, for the purposes of this particular discussion, equivalent to Jens's fictional class interface, but doesn't imply that such a class might exist to a (human) reader. Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://www.zathras.de ___ 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 avoid warning?
On Jan 22, 2013, at 8:28 PM, Andy Lee ag...@mac.com wrote: To be extra fail-safe, you might want to perform a cast to be sure the right initWithManager: gets called: if ([myClass conformsToProtocol:@protocol(MyProtocol)]) myObj = [(id MyProtocol)[myClass alloc] initWithManager:self]; else myObj = [[myClass alloc] init]; This only works for classes that actually declare themselves to be in conformance with this protocol, though. Even if a class implements all the methods in a protocol, conformsToProtocol: will return NO if it doesn't have the protocol name on the @interface (or on the @implementation line). IMO the nicest way to do this (if you can't make all your classes conform to the protocol by declaring them as @interface Foo : NSObject UKCanInitWithManagerProtocol, which would definitely be the cleanest approach), would be: @protocol UKCanInitWithManagerProtocol -(id) initWithManager: (Foo*)inManager; @end ... if( [myClass respondsToSelector: @selector(initWithManager:)] ) myObj = [(idUKCanInitWithManagerProtocol)[myClass alloc] initWithManager: self]; else myObj = [[myClass alloc] init]; Though I would recommend choosing a different name. E.g. -initWithBarManager: if the manager class is called UKBarManager. Manager alone is too generic a word, and someone might have declared it in ObjC++ and taking a C++ object and then you're screwed. Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://www.zathras.de ___ 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: Best guess at expressing a string as a variable
On 23 Jan 2013, at 13:07, Uli Kusterer witness.of.teacht...@gmx.net wrote: On Jan 23, 2013, at 2:18 AM, jonat...@mugginsoft.com wrote: Hmm. Maybe not. I want to keep the generated variable name legible. You need to nail down the languages you want to deploy to, and then find out what their criteria for identifiers are. Then you can decide to either generate identical lowest-common-denominator-names for all of them (which is [a-zA-Z_]([a-zA-Z_0-9]*) in the case of C, i.e. it may not start with a number either), or adjust what characters to permit based on the target programming language. This is known http://www.mugginsoft.com/kosmictask/help/languages. The app uses a plugin-architecture so more may appear. Apart from character set, you may also have to be aware of length limits etc. Early C compilers, for instance, only used the first 8 characters of an identifier. So ExceptionalHouse and ExceptionalCow both ended up as the same identifier, Exceptio. I'm hard pressed to think of a language with such a limit today, but I don't know what languages your targeting. Maybe one has such a limit. The plugin defines the language properties so length constraints can be included. Som experimentation will determine the limits. If you have a case where you can't express a character in a particular character set, you have several options: 1) Transcribe it to an equivalent character set. E.g. U-Umlaut (ü) is usually written as ue. However, you will then have to deal with collisions. E.g. what if one user enters the word Frauen, but another makes up a new word Fraün. The latter would transcribe to the former, and you might get unexpected side effects. You might have to generate a look-up-table, and if you find a collision like that, make the name unique again, e.g. by naming one frauen and the other frauen2. IIRC there are official transcriptions for many languages, e.g. Romanji for Japanese characters. 2) Fail and tell the user what the valid characters are, and only let them enter valid characters. 3) Transcribe in some other way, e.g. by base64-encoding, or using a hex-representation of the given byte sequence, or whatever. This way you could keep ASCII sentences valid, but modify everything else. But even then you could have collisions. E.g. if you replace spaces with underscores, what if there's a second version with the underscore? I was intending to decompose U-Umlaut (ü) to u + Umlaut and then discard the umlaut if possible. Or perhaps an API exists to decompose the likes of U-Umlaut (ü) to ue. I already have collision detection code that appends integers for uniqueness. Is + (id)letterCharacterSet the best choice here? According to the docs (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCharacterSet_Class/Reference/Reference.html): An NSCharacterSet object represents a set of Unicode-compliant characters. The +letterCharacterSet documentation says Returns a character set containing the characters in the categories Letters and Marks. So a Google later, here http://www.fileformat.info/info/unicode/category/index.htm Thanks for the link. I didn't know that the categories were specified by unicode. I had assumed they were arbitrarily defined by Apple. the categories mentioning Letters include greek characters, accented characters, hiragana and cyrillic characters among others (most of which are invalid as C identifier names). Oddly, marks seem to include some kind of punctuation. I couldn't find a section that is obviously only letters and marks or two separate letters and marks sections. I see that. Anyhow, I can have a look at the likes of +nonBaseCharacterSet and see how they correlate exactly with the Unicode categories. Anyway, I think building your own custom character set from a string including the characters you *know* are valid identifiers in your target programming language(s) is probably the route of least surprise. Agree. I want to get a sensible wide base and restrict it on a per language basis. Thanks for such a detailed reply. Jonathan ___ 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 avoid warning?
On Jan 23, 2013, at 8:22 AM, Uli Kusterer witness.of.teacht...@gmx.net wrote: @protocol UKCanInitWithManagerProtocol -(id) initWithManager: (Foo*)inManager; @end ... if( [myClass respondsToSelector: @selector(initWithManager:)] ) myObj = [(idUKCanInitWithManagerProtocol)[myClass alloc] initWithManager: self]; else myObj = [[myClass alloc] init]; Well, the extra-super-defensive approach would be to not only check respondsToSelector:, but to check that the method signature of the object's implementation matches what's declared in the protocol. :) But yeah, you can't rely on conformsToProtocol: if you don't have the luxury of making the relevant classes conform to the protocol. --Andy ___ 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: Best guess at expressing a string as a variable
On 23 Jan 2013, at 5:40 AM, Jean Suisse jean.li...@gmail.com wrote: Hmm. Maybe not. I want to keep the generated variable name legible. I think I will have to introduce an intermediate NSTextView that filters and displays the natural language input. The user can then modify the variable name if necessary before it gets utilised further. Maybe you could drop the extra textfields and the processing by requesting the variable name to use an english alphanumeric character set ? Otherwise, how would you deal with this input for a variable name: 名前 ? [ If I am a japanese user, I would expect your software to call the variable namae ]. IMHO the whole unicode character set is too large. Most language won't accept the largest part of the set. Would CFStringTransform() be of comfort in this situation? There is the problem that ideographs get mapped from Mandarin. Good choice in terms of (potential) user base; for now a poor choice for a technical user base. Oops, the function also takes ICU transliteration transforms (though I'd be impressed if it took all of them). The fully reversible transforms yield Latin with diacritics, but there seems to be an option to smash them. — F -- Fritz Anderson Xcode 4 Unleashed: 4.5 supplement for free! http://www.informit.com/store/xcode-4-unleashed-9780672333279 ___ 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
NSComboBox, binding, multiple selection, multiple values == trouble
Hello, in my app, I can edit a selection of model objects in a window which that consists of NSTextFields and NSComboBoxes to edit model properties, all via binding to an NSArrayController's selection proxy. When I'm editing a multi-selection that has property values are different for individual model objects in the selection, I get an undesired behavior from NSComboBox: When I tab over an NSComboBox which displays the multiple-values placeholder, upon exiting the combo box, the corresponding property for all selected objects is nil'd. (BAD) When I do the same (tabbing over) with an NSTextField, the values of the individual objects' properties are unchanged. (GOOD). Since I have no control over how NSComboBox implements its bindings and I therefore can't fix the handling of multi-valued selections, I fixed this by subclassing NSComboBox and implementing -objectValue by returning the NSMultipleValuesMarker object as I see fit. - (id)objectValue { id result = [super objectValue]; if (returnMultiValuesMarkerForEmptyObjectValue) { if ([result isEqualTo:@]) { result = NSMultipleValuesMarker; } } return result; } The private returnMultiValuesMarkerForEmptyObjectValue ivar is set to YES externally by my editor controller which knows that a multiple selection is being edited. This works reasonably well but I wonder how others have fixed this problem. I feel returning NSMultipleValuesMarker is a hack which works only because NSComboBox thinks it's a legitimate return value (or doesn't care). The fact that I can't clear properties for multiple selections is a side effect I can live with. Any better fixes for this? Regards Markus -- __ Markus Spoettl ___ 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: Using NSSavePanel to export to UTTypeFolder without a file extension.
Following up on my own question, NSSavePanel can be made to “work” under PowerBox with a UTI that has no file extension, but it does get upset with itself and fail an assertion when it elects to automatically turn on the hide extension checkbox in response to the user changing the file type. The exception is appended below. The default assertion handler just logs it and everything seems to work, though I do worry that we're not getting a proper reply to the request. Updated source here: https://www.dropbox.com/s/qjgnpee644c5eo3/NSSavePanel-kUTTypeFolder.zip I'll be filing a radar if bugreporter comes back up. Highlighted changes since I last posted: - I had neglected to set a code signing identity, so the example wasn't actually sandboxed before. - added the com.apple.security.files.user-selected.read-write entitlement - declared exportable formats as NSExportableTypes using real UTIs rather than the old school NSExportableAs wherein I was using CFBundleTypeMIMETypes completely wrong anyway. Here is the assertion that fails. Should you wish to download and build the project the steps to reproduce the assertion are as follows: - in Finder preferences, turn off Show all filename extensions - build and run the project - File - Export…, - switch the File Format. The hide extension checkbox will turn on. Turn it off. - repeat the previous step as necessary. This seems to be a race condition and may take many tries. 2013-01-23 11:21:35.728 NSSavePanel-kUTTypeFolder[26816:303] *** Assertion failure in -[NSRemoteSavePanel connection:didReceiveRequest:], /SourceCache/RemoteViewServices/RemoteViewServices-80.5/NSRemoteSavePanel.m:1713 2013-01-23 11:21:35.730 NSSavePanel-kUTTypeFolder[26816:303] caught exception { name = NSInternalInconsistencyException; reason = window allowed unexpectedly; } during request {requestType: 15, connections: 0, ports: 0, arguments: { NSRemotePanelRequestKVOStateDidChangeNewStateKey = 1; NSRemotePanelRequestKVOStateDidChangePathKey = isExtensionHidden; }} with call stack ( 0 CoreFoundation 0x7fff8a9e30a6 __exceptionPreprocess + 198 1 libobjc.A.dylib 0x7fff8baca3f0 objc_exception_throw + 43 2 CoreFoundation 0x7fff8a9e2ee8 +[NSException raise:format:arguments:] + 104 3 Foundation 0x7fff86ae96a2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189 4 RemoteViewServices 0x7fff85bf3dc1 -[NSRemoteSavePanel connection:didReceiveRequest:] + 131 5 RemoteViewServices 0x7fff85bec73f __block_global_4 + 68 6 CoreFoundation 0x7fff8a9a0272 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 18 7 CoreFoundation 0x7fff8a960a4f __CFRunLoopDoBlocks + 255 8 CoreFoundation 0x7fff8a985220 __CFRunLoopRun + 1904 9 CoreFoundation 0x7fff8a9846b2 CFRunLoopRunSpecific + 290 10 AppKit 0x7fff860fb14b -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 150 11 AppKit 0x7fff85de846f -[NSMenu _internalPerformActionForItemAtIndex:] + 36 12 AppKit 0x7fff85de82f7 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 135 13 AppKit 0x7fff860f4245 NSSLMMenuEventHandler + 342 14 HIToolbox 0x7fff8904af0a _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1206 15 HIToolbox 0x7fff8904a3d9 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 410 16 HIToolbox 0x7fff890601bd SendEventToEventTarget + 40 17 HIToolbox 0x7fff89096e89 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 443 18 HIToolbox 0x7fff8903bc11 SendMenuCommandWithContextAndModifiers + 59 19 HIToolbox 0x7fff8903bbc3 SendMenuItemSelectedEvent + 254 20 HIToolbox 0x7fff8903ba4f _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94 21 HIToolbox 0x7fff891b2009 _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1673 22 HIToolbox 0x7fff891b1924 _HandlePopUpMenuSelection7 + 629 23 AppKit 0x7fff8617761b _NSSLMPopUpCarbonMenu3 + 3916 24 AppKit 0x7fff864d8d2a
Re: NSComboBox, binding, multiple selection, multiple values == trouble
On Jan 23, 2013, at 09:28 , Markus Spoettl ms_li...@shiftoption.com wrote: in my app, I can edit a selection of model objects in a window which that consists of NSTextFields and NSComboBoxes to edit model properties, all via binding to an NSArrayController's selection proxy. When I'm editing a multi-selection that has property values are different for individual model objects in the selection, I get an undesired behavior from NSComboBox: When I tab over an NSComboBox which displays the multiple-values placeholder, upon exiting the combo box, the corresponding property for all selected objects is nil'd. (BAD) Does the Allows Editing Multiple Values Selection binding option, if unchecked, prevent the problem? ___ 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: NSComboBox, binding, multiple selection, multiple values == trouble
On 1/23/13 9:51 PM, Quincey Morris wrote: When I'm editing a multi-selection that has property values are different for individual model objects in the selection, I get an undesired behavior from NSComboBox: When I tab over an NSComboBox which displays the multiple-values placeholder, upon exiting the combo box, the corresponding property for all selected objects is nil'd. (BAD) Does the Allows Editing Multiple Values Selection binding option, if unchecked, prevent the problem? No. Allows Editing Multiple Values Selection ON or OFF doesn't change the behavior (clearing multi-value content on exit). Conditionally Sets Editable ON makes it non-editable for multi-value content if Allows Editing Multiple Values Selection is OFF, which is not what I want. Regards Markus -- __ Markus Spoettl ___ 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: NSComboBox, binding, multiple selection, multiple values == trouble
On Jan 23, 2013, at 10:28 AM, Markus Spoettl wrote: in my app, I can edit a selection of model objects in a window which that consists of NSTextFields and NSComboBoxes to edit model properties, all via binding to an NSArrayController's selection proxy. When I'm editing a multi-selection that has property values are different for individual model objects in the selection, I get an undesired behavior from NSComboBox: When I tab over an NSComboBox which displays the multiple-values placeholder, upon exiting the combo box, the corresponding property for all selected objects is nil'd. (BAD) When I do the same (tabbing over) with an NSTextField, the values of the individual objects' properties are unchanged. (GOOD). I had a similar issue and I don't think it has anything to do with the binding. It seems to be that NSCombobox always sets the value as displayed when the field is exited regardless of whether the contents have been edited or not. So, if the contents are nil, it will set the value(s) to nil on exit. This may be an acceptable outcome when editing a single value, so it is probably overlooked. In my case it was unnecessarily dirtying the document edited state. My solution was to scrap comboboxes and instead use regular NSTextFields with autocompletion support provided by a formatter. It proved to be actually better in my situation--more intuitive to the user. Of course, these were fields whose possible contents are already known by the user, such as a name prefix (Mr Ms etc) Since I have no control over how NSComboBox implements its bindings and I therefore can't fix the handling of multi-valued selections, I fixed this by subclassing NSComboBox and implementing -objectValue by returning the NSMultipleValuesMarker object as I see fit. - (id)objectValue { id result = [super objectValue]; if (returnMultiValuesMarkerForEmptyObjectValue) { if ([result isEqualTo:@]) { result = NSMultipleValuesMarker; } } return result; } The private returnMultiValuesMarkerForEmptyObjectValue ivar is set to YES externally by my editor controller which knows that a multiple selection is being edited. This works reasonably well but I wonder how others have fixed this problem. I feel returning NSMultipleValuesMarker is a hack which works only because NSComboBox thinks it's a legitimate return value (or doesn't care). The fact that I can't clear properties for multiple selections is a side effect I can live with. This actually works? I wouldn't think so--I would expect that all of the field values get set to the string value of NSMultipleValuesMarker, which is really what the code looks like it should be doing. If there are indeed some internals that are ignoring the marker, they are undocumented (AFAIK) and shouldn't be relied upon. Any better fixes for this? If you are really dedicated to using NSCombobox, I would avoid bindings and instead handle it manually, using target-action. This way, when your controller receives the action you can check for a multiple selection and ignore it if so. HTH, 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSComboBox, binding, multiple selection, multiple values == trouble
On 1/23/13 10:25 PM, Keary Suska wrote: This works reasonably well but I wonder how others have fixed this problem. I feel returning NSMultipleValuesMarker is a hack which works only because NSComboBox thinks it's a legitimate return value (or doesn't care). The fact that I can't clear properties for multiple selections is a side effect I can live with. This actually works? I wouldn't think so--I would expect that all of the field values get set to the string value of NSMultipleValuesMarker, which is really what the code looks like it should be doing. If there are indeed some internals that are ignoring the marker, they are undocumented (AFAIK) and shouldn't be relied upon. Yes, it works. My theory is that the NSArrayController, which is actually updating the model via its selection proxy, does the right thing when it gets a NSMultipleValuesMarker back as object value. Any better fixes for this? If you are really dedicated to using NSCombobox, I would avoid bindings and instead handle it manually, using target-action. This way, when your controller receives the action you can check for a multiple selection and ignore it if so. Yes, that may be an option, though not a very convenient one. Getting rid of NSComboBox altogether may be more attractive. Regards Markus -- __ Markus Spoettl ___ 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
New iTunes UI
In the album view if you select and begin to drag a view slides out from the right with drop destinations. The question: Is this sliding view an animated split view or some other form of view animation? -koko Sent from my iPad ___ 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: New iTunes UI
On 24/01/2013, at 3:40 AM, Koko k...@highrolls.net wrote: The question: Is this sliding view an animated split view or some other form of view animation? It definitely doesn't look like a split view, since it appears on top of the underlying view, not alongside. It's probably just another view. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Coordinate conversions in CALayer
On 23/01/2013, at 5:41 PM, Graham Cox graham@bigpond.com wrote: To create a transform that supposedly will transform from the superlayer TO the layer, and I then invert it to go back the other way. It works in the simple case, but a rotation transform upsets things. I've tried pretty much every combination of ordering different things in constructing the transform but this is the best result I get. Still wrong though. Funny, every time I think I have transforms figured out something turns up to show me I don't. Boiling down my problem to its bare essentials, why are these two bits of code not equivalent? CGPoint anch = layer.anchorPoint; CGRect br = layer.bounds; CGPoint pos = layer.position; CGContextTranslateCTM( ctx, pos.x, pos.y ); CGContextConcatCTM( ctx, layer.transform ); CGContextTranslateCTM(ctx, -(br.origin.x + anch.x * br.size.width), -(br.origin.y + anch.y * br.size.height)); The above works correctly, but below, which I thought should do the same, does not, if the layer.transform property is not the identity matrix: CGPoint anch = layer.anchorPoint; CGRect br = layer.bounds; CGPoint pos = layer.position; CGAffineTransform tfm = CGAffineTransformMakeTranslation( pos.x, pos.y ); tfm = CGAffineTransformConcat( tfm, layer.transform ); tfm = CGAffineTransformTranslate( tfm, -(br.origin.x + anch.x * br.size.width), -(br.origin.y + anch.y * br.size.height)); CGContextConcatCTM( ctx, tfm ); In the second case I've tried every combination of ordering the different statements that build the transform, and the sign of the translations, but nothing I have tried makes the second code work identically to the first. I'm missing something obvious but I'm not grokking it. I need the second case to work because it is needed in other situations where I have no context - e.g. just performing transformation calculations between a layer and its superlayer. Please someone help, this is driving me bats. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Coordinate conversions in CALayer
On Jan 23, 2013, at 17:01 , Graham Cox graham@bigpond.com wrote: The above works correctly, but below, which I thought should do the same, does not, if the layer.transform property is not the identity matrix: CGPoint anch = layer.anchorPoint; CGRect br = layer.bounds; CGPoint pos = layer.position; CGAffineTransform tfm = CGAffineTransformMakeTranslation( pos.x, pos.y ); tfm = CGAffineTransformConcat( tfm, layer.transform ); tfm = CGAffineTransformTranslate( tfm, -(br.origin.x + anch.x * br.size.width), -(br.origin.y + anch.y * br.size.height)); CGContextConcatCTM( ctx, tfm ); In the second case I've tried every combination of ordering the different statements that build the transform, and the sign of the translations, but nothing I have tried makes the second code work identically to the first. I'm missing something obvious but I'm not grokking it. I need the second case to work because it is needed in other situations where I have no context - e.g. just performing transformation calculations between a layer and its superlayer. Please someone help, this is driving me bats. This sort of thing drives me nuts too. You have to simplify the problem. 1. In the scenario where bounds.origin is (0,0) and the anchor point is (0,0) -- which should be be a very ordinary scenario to set up, even if you have to abuse your app to make it so -- the third transformation has no effect. If -- another ordinary scenario (I'd hope) -- the layer transform is the identity, the second transformation has no effect. So start with those scenarios in effect. Can you make it work with *just* the first translation doing something? That will incidentally settle the sign question once and for all. 2. Once you have that working, start using a non-identity layer transform, preferably something very easy like a 90 degree rotation, or a 50% scale, or a reflection about a vertical axis. If you don't get the right answer, it *should* be obvious why not. Then try it with a 30 degree rotation to check you didn't just solve it for a special case. (If you're depending on seeing what draws to find out if you got it right, try something like a 95% or a 105% scale. One or other of those would likely still draw something you can recognize, and tell you whether the error is a mis-translation or a mis-scale, and in which direction.) 3. After you get that far, I can't imagine it would be difficult to get the last transformation right. Even so, do it in 2 parts, first with a non-zero bounds origin, then second with a different anchor point. As to why the methodology isn't precisely parallel in the 2 cases, I dunno, but I suspect it's because in one case you're drawing untransformed geometry into a transformed drawing space; in the other case, you're drawing transformed geometry into an untransformed drawing space. Those two things might be as equivalent as you expect. But you've probably thought this all through already ... ___ 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
NSAttributedString boundingRectWithSize vs. paragraph margins
The docs on boundingRectWithSize:options:context: say: Typically, the renderer preserves the width constraint and adjusts the height constraint as needed. Yes, that's what I was hoping for. But in fact I'm getting a much narrower width than what I supplied. I suspect that the problem here has to do with differing expectations as to what bounding rect means, and as to what my paragraph margins mean. Here's some more complete code: NSString* sentence = @This is a test. ; NSString* s = @; for (int i = 0; i 20; i++) s = [s stringByAppendingString:sentence]; NSMutableParagraphStyle* mps = [NSMutableParagraphStyle new]; mps.headIndent = 20; mps.firstLineHeadIndent = 20; mps.tailIndent = -20; NSAttributedString* as = [[NSAttributedString alloc] initWithString:s attributes:@{ NSParagraphStyleAttributeName:mps }]; CGRect r = [as boundingRectWithSize:CGSizeMake(100,1) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; NSLog(@%@, NSStringFromCGRect(r)); The resulting width is 51.8. So it looks as if that's the width *after* the margins (20 and 20) have squeezed the text inward. What we're getting, it seems, is the minimum bounding rect containing any text. But that's not what I want to know; I want to know the height of this text as drawn within the width I supplied (100) using the paragraph margins I supplied. Is there some other way to find that out? Or is this a bug with regard to how margins are interpreted? m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.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
can update the UI from sheetDidEnd:…. ?
Hi, I was updating a few textfields from my sheetDidEnd:…. method. Just wondering if that was causing the crash (UI related error in main thread). Thanks, Nick ___ 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: Issue with Core Data Mapping Model
Yes, the hashes do change when I add the model mapping. I ended up writing an NSEntityMigrationPolicy for a parent object that copies these child entities. In addition, I also opened up a DTS incident with Apple. The gentleman from Apple observed that I had an interesting difference between model versions: * In the prior version, I had an entity that was optional and had a minimum and maximum count set to 1. * In the newer version, the minimum count was not set. It is odd that the minimum and maximum values even exist, since the relationship in question is not a to-many relationship. I honestly don't know if I set these values or if Xcode did that for me. At any rate, setting the minimum count back to 1 seemed to make the mapping model recognized by Core Data. I hope this helps you. John On Jan 22, 2013, at 12:12 PM, Sean McBride s...@rogue-research.com wrote: On Thu, 17 Jan 2013 21:45:51 -0500, John Brayton said: I am building a mapping model between two versions of my Core Data model, and I am encountering a strange issue: * If I define six of the seven entity mappings I need in the mapping model, migrating the data works as expected. * When I add the seventh entity mapping, the migration fails with this error: Persistent store migration failed, missing mapping model. * If I delete that seventh entity mapping, the migration works again. * I am trying to do the migration by calling addPersistentStoreWithType: … on the NSPersistentStoreCoordinator. * Reading in both the source and destination models with NSManagedObjectModel initWithContentsOfURL:... works as expected. * Reading in the NSMappingModel with initWithContentsOfURL:… works as expected. * With the seventh entity mapping added, reading in the mapping model with [NSMappingModel mappingModelFromBundles:@[bundle] forSourceModel:source destinationModel:dest] returns null. This sounds a lot like something I am seeing. Do you see hash mismatches like described here: http://stackoverflow.com/questions/10894383/core-data-mapping-model-version-hashes-not-matching-to-source-model-version-hash I've spent hours on it, and as best as I can tell Xcode is generating invalid xcmappingmodel files. Just the other day I've used a DTS incident on this, but have not heard back yet. I'll follow up in this thread when I do. Cheers, -- Sean McBride, B. Eng s...@rogue-research.com Rogue Researchwww.rogue-research.com Mac Software Developer Montréal, Québec, Canada On Jan 22, 2013, at 12:12 PM, Sean McBride s...@rogue-research.com wrote: On Thu, 17 Jan 2013 21:45:51 -0500, John Brayton said: I am building a mapping model between two versions of my Core Data model, and I am encountering a strange issue: * If I define six of the seven entity mappings I need in the mapping model, migrating the data works as expected. * When I add the seventh entity mapping, the migration fails with this error: Persistent store migration failed, missing mapping model. * If I delete that seventh entity mapping, the migration works again. * I am trying to do the migration by calling addPersistentStoreWithType: … on the NSPersistentStoreCoordinator. * Reading in both the source and destination models with NSManagedObjectModel initWithContentsOfURL:... works as expected. * Reading in the NSMappingModel with initWithContentsOfURL:… works as expected. * With the seventh entity mapping added, reading in the mapping model with [NSMappingModel mappingModelFromBundles:@[bundle] forSourceModel:source destinationModel:dest] returns null. This sounds a lot like something I am seeing. Do you see hash mismatches like described here: http://stackoverflow.com/questions/10894383/core-data-mapping-model-version-hashes-not-matching-to-source-model-version-hash I've spent hours on it, and as best as I can tell Xcode is generating invalid xcmappingmodel files. Just the other day I've used a DTS incident on this, but have not heard back yet. I'll follow up in this thread when I do. Cheers, -- Sean McBride, B. Eng s...@rogue-research.com Rogue Researchwww.rogue-research.com Mac Software Developer Montréal, Québec, Canada ___ 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: NSAttributedString boundingRectWithSize vs. paragraph margins
On Jan 23, 2013, at 7:29 PM, Matt Neuburg wrote: The docs on boundingRectWithSize:options:context: say: Typically, the renderer preserves the width constraint and adjusts the height constraint as needed. Yes, that's what I was hoping for. But in fact I'm getting a much narrower width than what I supplied. I suspect that the problem here has to do with differing expectations as to what bounding rect means, and as to what my paragraph margins mean. Here's some more complete code: NSString* sentence = @This is a test. ; NSString* s = @; for (int i = 0; i 20; i++) s = [s stringByAppendingString:sentence]; NSMutableParagraphStyle* mps = [NSMutableParagraphStyle new]; mps.headIndent = 20; mps.firstLineHeadIndent = 20; mps.tailIndent = -20; NSAttributedString* as = [[NSAttributedString alloc] initWithString:s attributes:@{ NSParagraphStyleAttributeName:mps }]; CGRect r = [as boundingRectWithSize:CGSizeMake(100,1) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; NSLog(@%@, NSStringFromCGRect(r)); The resulting width is 51.8. So it looks as if that's the width *after* the margins (20 and 20) have squeezed the text inward. What we're getting, it seems, is the minimum bounding rect containing any text. But that's not what I want to know; I want to know the height of this text as drawn within the width I supplied (100) using the paragraph margins I supplied. Is there some other way to find that out? Or is this a bug with regard to how margins are interpreted? m. What height value are you getting that you believe is incorrect? If the value is unchanged (1000), it could mean that the layout manager is constructing an NSTextContainer with your desired size (100,1) and fitting text within it. My experience has been that NSLayoutManager will not shrink containers, but will grow them. If you set the height to a small value, do you get a different and more expected value? I didn't know about this method--I had to construct an NSTextView as laid out in the Text System User Interface Layer Programming Guide under Setting Up the Text View, set the attributed string, then call -[NSLayoutManager getGlyphs:range:] or similar to force rendering. I believe this approach will do exactly what you want if all else fails... HTH, 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: can update the UI from sheetDidEnd:…. ?
On Jan 23, 2013, at 9:30 PM, Nick Rogers roger...@mac.com wrote: I was updating a few textfields from my sheetDidEnd:…. method. Just wondering if that was causing the crash (UI related error in main thread). What happens if you *don't* update the text fields in your sheetDidEnd method? Does it still crash? Can you show us the code for the sheetDidEnd method just in case there's a clue there? Are you passing a contextInfo pointer to the sheetDidEnd message? If it's an object reference, maybe you need to retain it (and then autorelease it in sheetDidEnd), assuming you're not using ARC. Are you using ARC? Are you remembering to call orderOut: as mentioned in the Sheet Programming Guide (unlikely to cause a crash, but worth checking)? https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/sheets/Tasks/UsingCustomSheets.html#//apple_ref/doc/uid/20001290-BABFIBIA Are the text fields in question *on* the sheet? If so, maybe you're trying to modify them after they've been dealloc'ed due to the sheet being dismissed. Does the stack trace show any of your code, or is it all Apple stuff? Are there any meaningful error messages being logged? Are you actually crashing or just throwing an exception? What if you add a breakpoint exception? --Andy ___ 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: NSAttributedString boundingRectWithSize vs. paragraph margins
I should have been explicit that this is iOS. Sorry. It may be that the height is right despite the narrowed width, but since the narrowed width is unexpected, it would be nice to be assured of this. m. - Sent from my iPad, but I am not a dork. Really. On Jan 23, 2013, at 7:18 PM, Keary Suska cocoa-...@esoteritech.com wrote: On Jan 23, 2013, at 7:29 PM, Matt Neuburg wrote: The docs on boundingRectWithSize:options:context: say: Typically, the renderer preserves the width constraint and adjusts the height constraint as needed. Yes, that's what I was hoping for. But in fact I'm getting a much narrower width than what I supplied. I suspect that the problem here has to do with differing expectations as to what bounding rect means, and as to what my paragraph margins mean. Here's some more complete code: NSString* sentence = @This is a test. ; NSString* s = @; for (int i = 0; i 20; i++) s = [s stringByAppendingString:sentence]; NSMutableParagraphStyle* mps = [NSMutableParagraphStyle new]; mps.headIndent = 20; mps.firstLineHeadIndent = 20; mps.tailIndent = -20; NSAttributedString* as = [[NSAttributedString alloc] initWithString:s attributes:@{ NSParagraphStyleAttributeName:mps }]; CGRect r = [as boundingRectWithSize:CGSizeMake(100,1) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; NSLog(@%@, NSStringFromCGRect(r)); The resulting width is 51.8. So it looks as if that's the width *after* the margins (20 and 20) have squeezed the text inward. What we're getting, it seems, is the minimum bounding rect containing any text. But that's not what I want to know; I want to know the height of this text as drawn within the width I supplied (100) using the paragraph margins I supplied. Is there some other way to find that out? Or is this a bug with regard to how margins are interpreted? m. What height value are you getting that you believe is incorrect? If the value is unchanged (1000), it could mean that the layout manager is constructing an NSTextContainer with your desired size (100,1) and fitting text within it. My experience has been that NSLayoutManager will not shrink containers, but will grow them. If you set the height to a small value, do you get a different and more expected value? I didn't know about this method--I had to construct an NSTextView as laid out in the Text System User Interface Layer Programming Guide under Setting Up the Text View, set the attributed string, then call -[NSLayoutManager getGlyphs:range:] or similar to force rendering. I believe this approach will do exactly what you want if all else fails... HTH, 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: can update the UI from sheetDidEnd:…. ?
On 24/01/2013, at 1:30 PM, Nick Rogers roger...@mac.com wrote: Hi, I was updating a few textfields from my sheetDidEnd:…. method. Just wondering if that was causing the crash (UI related error in main thread). If written correctly, the sheetDidEnd method is free to access stuff still in the sheet. In fact, it often has to to ensure any last minute entries in fields are committed - I usually start my sheetDidEnd methods with [sheet makeFirstResponder:sheet] to force a focused text field to push its content to its action method. sheetDidEnd methods also often call their delegates, and the delegate must be able to assume it can access anything (public) in the sheet. So whatever your problem is, it's not that. Show your code. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: can update the UI from sheetDidEnd:…. ?
Hi, Thanks for the replies. Sorry I didn't provide enough info in the beginning. Here it is. On 24-Jan-2013, at 9:55 AM, Graham Cox graham@bigpond.com wrote: On 24/01/2013, at 1:30 PM, Nick Rogers roger...@mac.com wrote: Hi, I was updating a few textfields from my sheetDidEnd:…. method. Just wondering if that was causing the crash (UI related error in main thread). If written correctly, the sheetDidEnd method is free to access stuff still in the sheet. In fact, it often has to to ensure any last minute entries in fields are committed - I usually start my sheetDidEnd methods with [sheet makeFirstResponder:sheet] to force a focused text field to push its content to its action method. sheetDidEnd methods also often call their delegates, and the delegate must be able to assume it can access anything (public) in the sheet. So whatever your problem is, it's not that. Show your code. The text fields to update are on the main window. On 24-Jan-2013, at 9:03 AM, Andy Lee ag...@mac.com wrote: On Jan 23, 2013, at 9:30 PM, Nick Rogers roger...@mac.com wrote: I was updating a few textfields from my sheetDidEnd:…. method. Just wondering if that was causing the crash (UI related error in main thread). What happens if you *don't* update the text fields in your sheetDidEnd method? Does it still crash? The crash doesn't happen always, so no way to tell if not updating the text fields from sheetDidEnd:.. has taken care of it. Can you show us the code for the sheetDidEnd method just in case there's a clue there? The code is simple. just updating the text fields on the main window, using setStringValue:@some string. Now I am doing this using performSelectorOnMainThread:. Are you passing a contextInfo pointer to the sheetDidEnd message? If it's an object reference, maybe you need to retain it (and then autorelease it in sheetDidEnd), assuming you're not using ARC. No context info. its NULL. Are you using ARC? The code is not ARC or GC. Are you remembering to call orderOut: as mentioned in the Sheet Programming Guide (unlikely to cause a crash, but worth checking)? I am calling orderOut:self but not from sheetDidEnd:… but from other method which ends the sheet. method is like: [NSApp endSheet:sheetWindow]; [sheetWindow orderOut:self]; Is it okay to do so as between these two statements the sheetDidEnd:… will execute? So, will the execution of second statement happen only after sheet ends. https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/sheets/Tasks/UsingCustomSheets.html#//apple_ref/doc/uid/20001290-BABFIBIA Are the text fields in question *on* the sheet? If so, maybe you're trying to modify them after they've been dealloc'ed due to the sheet being dismissed. The text fields are on the main window. Does the stack trace show any of your code, or is it all Apple stuff? The stack trace shows internal UI problem. selector is retain. Now I am not sure if the sheet is problem, it could be something else too. But knowing the answer will help rule out the sheet part of the code. Are there any meaningful error messages being logged? The crash actually show _updateTrackingAreas being called repeatedly and the crash happened just after sheet ends so I just wanted to know the best practices regarding sheet. I am going to post another one with crash report and details of hover button where I am using updateTrackingAreas. The crash happened many seconds after the last hover button was pushed. And after a sheet ended, so started this thread to make sheets clear. Are you actually crashing or just throwing an exception? What if you add a breakpoint exception? Crash happened only once and is not reproducible. Wishes, Nick ___ 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
Multithreading crash in -[NSConditionLock unlockWithCondition:]
I received a crash report from a user indicating EXC_BAD_ACCESS in -[NSConditionLock unlockWithCondition:]. Since the 'condition' parameter is an integer, I think the only explanation is that the receiver must have been deallocced. That didn't seem possible at the time when -unlockWithCondition: was invoked, but the lock was released (and deallocced) on another thread, which was blocked waiting for this lock to be unlocked. After inserting an extra -retain and testing it for a time myself I found that, on rare occasions, the retain count was one less than expected. My theory is that, on these rare occasions, the thread running -unlockWithCondition: would run enough to unblock the other thread, and, oddly but legally, the system would then pause this thread before this method had returned, and run the other thread, which would dealloc the lock. Then, upon resuming the first thread, the remaining code in -unlockWithCondition: would send some message to its deallocced self, causing EXC_BAD_ACCESS. I suppose that if this old project had been built with ARC I never would have had this bug? ___ 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: can update the UI from sheetDidEnd:…. ?
Hi, Sorry if I caused any confusion. But I don't know if _updateTrackingAreas would or would not be called by the system for its own UI display mechanism even if I don't use it in code. Best, Nick ___ 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: can update the UI from sheetDidEnd:…. ?
On 24/01/2013, at 4:48 PM, Nick Rogers roger...@mac.com wrote: The text fields to update are on the main window. The code is simple. just updating the text fields on the main window, using setStringValue:@some string. Now I am doing this using performSelectorOnMainThread:. Okaaayyy. This is indicative of a poor design, sorry to say. You haven't separated the concerns in one part of your app from another. It's not necessarily pertinent to your crash, but bad design often covers up those sorts of issues, making debugging hard and difficult to spot when you read through the code. A sheet should have its own controller and this controller should have sole and limited responsibility for the controls and elements within the sheet ONLY. It is up to you to design the methods that the sheet presents to its clients (e.g. the document that brings the sheet up) and any protocols necessary such that this principle is maintained. That way you have separated the internal design of the sheet from the internal design of its client, and neither needs to know about the other, except where they communicate through their public interface which constitutes the sole contract between them. Basically, if your sheet is touching text fields that belong to another object, you've cut corners too far and need to revise that. I bet if/when you do the crashing bug will reveal itself as obvious. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSAttributedString boundingRectWithSize vs. paragraph margins
On Jan 23, 2013, at 8:17 PM, Matt Neuburg m...@tidbits.com wrote: It may be that the height is right despite the narrowed width, but since the narrowed width is unexpected, it would be nice to be assured of this. m. Why is the narrowed width unexpected? You told the text system to use 20pt margins on each side of a 100pt text container. If you're not sure that the value is correct, fill the rect with a color and then draw the text atop it. That'll quickly tell you whether they match up. --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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Multithreading crash in -[NSConditionLock unlockWithCondition:]
On Jan 23, 2013, at 22:38 , Jerry Krinock je...@ieee.org wrote: My theory is that, on these rare occasions, the thread running -unlockWithCondition: would run enough to unblock the other thread, and, oddly but legally, the system would then pause this thread before this method had returned, and run the other thread, which would dealloc the lock. Then, upon resuming the first thread, the remaining code in -unlockWithCondition: would send some message to its deallocced self, causing EXC_BAD_ACCESS. I dunno about this theory in particular, but it's worth noting that pretty most manual retain/release code was technically flawed, in that it generally relied on an assumption that an object pointer in a local variable would not get deallocated until at least the method containing the variable returned. The most usual failure of this assumption came when it was actually being kept alive by an autorelease, and something drained the pool prematurely. Normally, though the assumption was safe enough. This may be an example when the assumption isn't safe. I suppose that if this old project had been built with ARC I never would have had this bug? It depends. What's the source code line that invokes 'unlockWithCondition:'? If it's sending that message to a local variable, then the ARC version is safe, since the local variable keeps the object alive until it (the variable) goes out of scope. If it's sending that message to an ivar, then the ARC version is unsafe, if another thread might nil the ivar while the method is executing, as you speculate might be happening. ARC won't save you here (unless you invoke 'unlockWithCondition:' via a local variable, of course). From a different perspective, though, this isn't a memory management issue, but rather a thread safety issue. You have your lock protecting some shared resource or other, but your lock is itself a shared resource, and nothing is protecting *it*. That's the real bug. ___ 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
Hover button and tracking area questions
Hi, I have just a tab view on my main window and I switch tabs based on user input. First tab has three hover buttons and on clicking one of them, it takes to another tab which two hover buttons. After clicking one of the two hover buttons, I switch tab and show a table view and then show and end a sheet. On clicking another button there I bring another sheet with radio buttons and on clicking a radio button, it just crashed, many seconds after the last hover button was clicked. The crash report says something about _updateTrackingAreas, so I have detailed about the situation above. Part of code is reproduced below. @interface HoverButton : NSButton { NSTrackingArea *trackingArea; BOOL hovering; } // Implementation - (void)ensureTrackingArea { if (trackingArea == nil) { trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] options: (NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow | NSTrackingInVisibleRect) owner:self userInfo:nil]; } } - (void)updateTrackingAreas { if (trackingArea) { [trackingArea release]; trackingArea = nil; } [self ensureTrackingArea]; [self addTrackingArea:trackingArea]; [super updateTrackingAreas]; } - (void)mouseExited:(NSEvent *)theEvent { // shows one image over the button } - (void)mouseEntered:(NSEvent *)theEvent { // shows another image over the button } Part of the crash report stack trace: Application Specific Information: objc_msgSend() selector name: retain objc[347]: garbage collection is OFF Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libobjc.A.dylib 0x7fff97c31350 objc_msgSend_vtable13 + 16 1 com.apple.CoreFoundation0x7fff96525b87 +[__NSArrayI __new::] + 167 2 com.apple.CoreFoundation0x7fff96525a75 -[__NSPlaceholderArray initWithObjects:count:] + 245 3 com.apple.CoreFoundation0x7fff965287c0 -[NSArray initWithArray:range:copyItems:] + 816 4 com.apple.CoreFoundation0x7fff96528482 -[NSArray initWithArray:copyItems:] + 66 5 com.apple.CoreFoundation0x7fff9654caf6 -[__NSArrayM copyWithZone:] + 54 6 com.apple.CoreFoundation0x7fff96524d54 -[NSObject copy] + 20 7 com.apple.AppKit0x7fff942a7ad2 -[NSView(NSInternal) _updateTrackingAreas] + 1295 8 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 9 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 10 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 11 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 12 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 13 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 14 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 15 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 16 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 17 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 18 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 19 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 20 com.apple.CoreFoundation0x7fff96574cee __NSArrayEnumerate + 718 21 com.apple.AppKit0x7fff942a7aeb -[NSView(NSInternal) _updateTrackingAreas] + 1320 22 com.apple.AppKit0x7fff942a7444 __-[NSWindow _postInvalidCursorRects]_block_invoke_1 + 1107 23 com.apple.CoreFoundation0x7fff9653c8e7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 24 com.apple.CoreFoundation0x7fff9653c846 __CFRunLoopDoObservers + 374 25 com.apple.CoreFoundation0x7fff96511af9 __CFRunLoopRun + 825 26 com.apple.CoreFoundation0x7fff96511486 CFRunLoopRunSpecific + 230 27 com.apple.HIToolbox 0x7fff959702bf RunCurrentEventLoopInMode + 277 28 com.apple.HIToolbox 0x7fff959774bf ReceiveNextEventCommon + 181 29 com.apple.HIToolbox 0x7fff959773fa BlockUntilNextEventMatchingListInMode + 62 30 com.apple.AppKit0x7fff941e1779 _DPSNextEvent + 659 31 com.apple.AppKit0x7fff941e107d
Re: Hover button and tracking area questions
On Wed, Jan 23, 2013, at 11:14 PM, Nick Rogers wrote: - (void)updateTrackingAreas { if (trackingArea) { [trackingArea release]; trackingArea = nil; } I was just working with tracking areas today, and I've come to the conclusion that this pattern is wrong. There's no need to release and reinstall your tracking areas every time you get -updateTrackingAreas, and in fact doing so will cause you to miss -mouseExited: events in the event that you're getting -updateTrackingAreas because the view that owns the tracking area has moved. Regardless, you've failed to implement the pattern properly. You're never removing the tracking areas before installing new ones. It should be pretty obvious why this is causing you to crash when messaging zombie objects. --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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com