Re: Add bindings for custom menu items' isHidden to (an attribute of) a custom object?
On Sep 8, 2014, at 1:12 AM, Daryle Walker dary...@mac.com wrote: Yesterday, I had a thread (b6bbfa38-4761-4d25-bdfa-d6e5d71c1...@mac.com “Bindings to enable a menu item based on an array's element count”) on this list on how to add a Binding to a menu item’s Hidden flag based on the length of a custom object’s array-based property. I got the code working. There is a menu item for each day that has WebHistoryItem instances. (Each menu item has a submenu with items for each web-history entry.) The custom object is pointed to one of those menu items’ submenu and creates two arrays of menu items, one has copies of the first few menu items of the source menu, the other copies of the remaining trailing menu items. With KVO signaling, the first array’s items are directly dumped in the top-level menu and the second array’s items are dumped into a submenu of the menu item following the direct items. The Binding from the previous thread hid that menu item when the corresponding array was empty. Now whenever the custom object has at least one non-empty array, I want to hide the menu item that contains the source submenu, so I don’t have two copies visible. Right now, I handle hiding and un-hiding manually: - (void)prepareTodayHistoryMenu { NSMenu * const browseMenu = self.earlierToday.menu; NSMenuItem * const beyondEarlierTodayMenuItem = [browseMenu itemAtIndex:(1 + [browseMenu indexOfItem:self.earlierToday])]; self.todayHistoryHandler.sourceMenu = (beyondEarlierTodayMenuItem.isSeparatorItem || ![[NSCalendar autoupdatingCurrentCalendar] isDateInToday:beyondEarlierTodayMenuItem.representedObject]) ? nil : beyondEarlierTodayMenuItem.submenu; [beyondEarlierTodayMenuItem setHidden:!!self.todayHistoryHandler.sourceMenu]; } I grouped the source-menu assignment and the hiding of the original menu item together. - (void)notifyOnNewDay:(NSNotification *)notification { NSMenu * constbrowseMenu = self.earlierToday.menu; NSInteger const beyondEarlierTodayIndex = [browseMenu indexOfItem:self.earlierToday] + 1; [[browseMenu itemAtIndex:beyondEarlierTodayIndex] setHidden:NO]; // If the today menu item shifts, we'll lose track of this and therefore can't restore it. [self prepareTodayHistoryMenu]; } This makes sure to disconnect the menu item’s submenu from being the source menu, since it no longer belongs to Today. I assume that the latest per-day menu item has the source submenu. If there are no per-day items, then the following separator item gets a no-op set-visible action. Note that the affected menu item isn’t tracked, so I have to make it (which may be a no-op on the following separator item) re-visible before the prepare action sets its source menu to NIL. (A menu item and submenu for the new Today get created as-needed in the following method.) [SNIP big example] I was thinking that if I used Bindings for one menu item, could I add Bindings between the new menu items and some attribute of the custom object, so the menu items hide themselves when being mirrored. (At most one will be hidden.) I added a NSValueTransformer to my custom object. @interface MyOverflowMenuController : NSObject //! Starts as nil; when set, this instance stores copies of the menu’s //! items and tracks the menu for item insertions, removals, and renames. @property (nonatomic) NSMenu *sourceMenu; //! Starts as zero; if the menu has more menu items that this value, //! the copies of the menu's latter items are stored in the overflow //! array instead of the direct array. @property (nonatomic, assign) NSUInteger maxDirectCount; //! Starts as empty; updated to mirror the source menu's menu-items. //! Keeps at most 'maxDirectCount' items. KVO-compliant. @property (nonatomic, readonly) NSArray *directMenuItems; //! Starts as empty; updated to mirror the source menu's menu-items. //! Keeps the overflow from 'directMenuItems'. KVO-compliant. @property (nonatomic, readonly) NSArray * overflowMenuItems; //! Transforms a NSMenu to a NSNumber with a BOOL value that's YES //! when the given menu is self.sourceMenu. @property (nonatomic, readonly) NSValueTransformer * isSourceMenuTransformer; @end That last property is of a custom NSValueTransformer subclass. (Is not using a new .h/.m file pair for the subclass OK?) The subclass holds a pointer to the source menu, and gets updated when the outer class changes that property in the setter. The custom object should out-live the per-day history menu items. So how would connect each menu item’s Hidden attribute to the custom object and the value transformer? Am I using the right kind of transformer? The source-menu attribute should be KVO-compliant since I use the automatic getter and a custom setter (that mutate the two arrays). I tried: static inline NSMenuItem *
Re: Add bindings for custom menu items' isHidden to (an attribute of) a custom object?
On Sep 8, 2014, at 3:10 AM, Daryle Walker dary...@mac.com wrote: On Sep 8, 2014, at 1:12 AM, Daryle Walker dary...@mac.com wrote: [SNIP] @interface MyOverflowMenuController : NSObject //! Starts as nil; when set, this instance stores copies of the menu’s //! items and tracks the menu for item insertions, removals, and renames. @property (nonatomic) NSMenu *sourceMenu; //! Starts as zero; if the menu has more menu items that this value, //! the copies of the menu's latter items are stored in the overflow //! array instead of the direct array. @property (nonatomic, assign) NSUInteger maxDirectCount; //! Starts as empty; updated to mirror the source menu's menu-items. //! Keeps at most 'maxDirectCount' items. KVO-compliant. @property (nonatomic, readonly) NSArray *directMenuItems; //! Starts as empty; updated to mirror the source menu's menu-items. //! Keeps the overflow from 'directMenuItems'. KVO-compliant. @property (nonatomic, readonly) NSArray * overflowMenuItems; //! Transforms a NSMenu to a NSNumber with a BOOL value that's YES //! when the given menu is self.sourceMenu. @property (nonatomic, readonly) NSValueTransformer * isSourceMenuTransformer; @end That last property is of a custom NSValueTransformer subclass. (Is not using a new .h/.m file pair for the subclass OK?) The subclass holds a pointer to the source menu, and gets updated when the outer class changes that property in the setter. The custom object should out-live the per-day history menu items. So how would connect each menu item’s Hidden attribute to the custom object and the value transformer? Am I using the right kind of transformer? The source-menu attribute should be KVO-compliant since I use the automatic getter and a custom setter (that mutate the two arrays). I tried: static inline NSMenuItem * CreateMenuItemForDay(NSCalendarDate *day, NSDateFormatter *format) { NSString * const dayTitle = [format stringFromDate:day]; NSMenu * const daySubmenu = [[NSMenu alloc] initWithTitle:dayTitle]; NSMenuItem * const dayItem = [[NSMenuItem alloc] initWithTitle:dayTitle action:NULL keyEquivalent:@]; dayItem.representedObject = day; dayItem.submenu = daySubmenu; // Attach a binding to let the menu item auto-hide when used as the Today menu item. MyAppDelegate * const appDelegate = [NSApp delegate]; [dayItem bind:NSHiddenBinding toObject:appDelegate.myOverflowMenuController.sourceMenu withKeyPath:@sourceMenu options:@{NSValueTransformerBindingOption: appDelegate.myOverflowMenuController.isSourceMenuTransformer}]; return dayItem; } (Good thing I already #imported my application delegate header to get access to the load-URL-from-menu-item action.) I crashed with: 2014-09-08 02:43:31.216 MyApp[28296:303] Controller cannot be nil 2014-09-08 02:43:31.279 MyApp[28296:303] ( 0 CoreFoundation 0x7fff8557625c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x7fff8d741e75 objc_exception_throw + 43 2 CoreFoundation 0x7fff8557610c +[NSException raise:format:] + 204 3 AppKit 0x7fff8cc37499 -[NSBinder addBinding:toController:withKeyPath:valueTransformer:options:] + 337 4 AppKit 0x7fff8cc41c38 -[NSEditableBinder addBinding:toController:withKeyPath:valueTransformer:options:] + 51 5 AppKit 0x7fff8cc32efb -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 639 6 Prairie 0x00016246 CreateMenuItemForDay + 678 7 Prairie 0x00015a44 -[MyHistoryMenus notifyOnHistoryLoad:] + 708 8 CoreFoundation 0x7fff85544e0c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 (Trimming out the reset of the stack.) The “sourceMenu” starts off as NIL and gets set by -prepareTodayHistoryMenu, which gets called when the array of WebHistory per-day menu items (and sub-menus) gets updated. … In the definition, instead of ‘@“sourceMenu”’, I used a constant. Looking at that in this e-mail, I realized I specified that property twice. I changed the second argument to “appDelegate.myOverflowMenuController” and it doesn’t crash. Now, none of the per-day web-history menus show up, not just the one for Today. (The one page I visited today does show up directly in the History, proving that the just-today web-history menu item mirroring system still works. All of the per-day menu items return YES through the custom value-transformer, or I screwed up the binding. @interface MyCustomTargettingTransformer : NSValueTransformer //! Starts as nil; the menu instance to be compared. @property (nonatomic) NSMenu * targetMenu; @end
Re: My services in my own app
On 03 Sep 2014, at 01:20, dangerwillrobinsondan...@gmail.com wrote: Sent from my iPhone On 2014/09/03, at 3:45, Georg Seifert georg.seif...@gmx.de wrote: Here are some more information. I created a small test app following the example on apples documentation. The service works fine if invoked from other apps but if you select it from within the same app with text selected in a text view, the app menu will stay highlighted for 30s and after that it will give an error dialog: The “reverse String” service could not be used because the application did not respond to a request for services. Try reopening “(null),” or contact the vendor for an updated version. This is the backtrace (if I press pause in the debugger during that 30s): #00x7fff8d805a1a in mach_msg_trap () #10x7fff8d804d18 in mach_msg () #20x7fff8d434f15 in __CFRunLoopServiceMachPort () #30x7fff8d434539 in __CFRunLoopRun () #40x7fff8d433e75 in CFRunLoopRunSpecific () #50x7fff8872ea0d in RunCurrentEventLoopInMode () #60x7fff8872e7b7 in ReceiveNextEventCommon () #70x7fff8872e5bc in _BlockUntilNextEventMatchingListInModeWithFilter () #80x7fff8ddbe24e in _DPSNextEvent () #90x7fff8ddbd89b in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] () #100x7fff8e55f85d in _checkForUserCancelledEventUpToDate () #110x7fff8e560d92 in +[NSServicesMenuHandler _performServiceFromEntry:withPasteboard:withRequestor:withCarbonFocus:withSendTypes:withReturnTypes:canReleasePasteboardImmediately:] () #120x7fff8e56150d in +[NSServicesMenuHandler _performServiceFromEntry:withPasteboard:withRequestor:] () #130x7fff8dfdc260 in -[NSApplication sendAction:to:from:] () #140x7fff8dff71c8 in -[NSMenuItem _corePerformAction] () #150x7fff8dff6f04 in -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] () #160x7fff8e04640d in -[NSMenu _internalPerformActionForItemAtIndex:] () #170x7fff8e046289 in -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] () #180x7fff8dfecff6 in NSSLMMenuEventHandler () #190x7fff887081d4 in DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) () Here is the app: https://dl.dropboxusercontent.com/u/3563666/ServiceTest.zip (app and sources). First activate the Service reverse String in System Preferences. Open a new document, type something, select it and run the filter. I think is happens if both, the NSSendTypes and NSReturnTypes are set. Services that only have one seem to work fine. If anyone can help me with this? Best Georg It's a bit more work, but if you supplied the service via a helper app embedded in your app bundle, does that make it work? I didn't see anything in the docs about how to set it up. Can you just set the post name to the helper apps name? who would be responsible for first starting the app? Are there any examples on how to set it up? Thanks Georg ___ 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
NSUserDefaultsController in a NIB when not using standardUserDefaults
This feels like there should be an easy answer... We are no longer using standardUserDefaults since we want to someday offer a widget for our app that will require accessing our app's preferences..so we're using NSUserDefaults with a custom suiteName. *The question is*: in the NIBs for our Preference panes, we had various UI elements bound to NSUserDefaultsController. The normal NSUserDefaultsController in IB is set to only use standardUserDefaults. Is there any way to have it use our userdefaults instead? I did come up with one way - but I don't I love it. I made a subclass of NSUserDefaultsController and in the initWithCoder method, I tell it to use our defaults...of course, I have to first call super or else I'll get a compiler warning (which feels like a waste and causes me to re-assign self)...so here's what I have now: - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder: coder]; self = (MyUserDefaultsController *)[[NSUserDefaultsController alloc] initWithDefaults: myUserDefaults initialValues:nil]; return self; } Is there a better way? ___ 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: NSUserDefaultsController in a NIB when not using standardUserDefaults
Stupid question, but what happens if you don't assign the first self to the result of the call, but just call [super initWithCoder: coder]? Do you need the result of that call, since you immediately override it? Sent from my iPad On Sep 8, 2014, at 2:09 PM, Alex Kac a...@webis.net wrote: This feels like there should be an easy answer... We are no longer using standardUserDefaults since we want to someday offer a widget for our app that will require accessing our app's preferences..so we're using NSUserDefaults with a custom suiteName. *The question is*: in the NIBs for our Preference panes, we had various UI elements bound to NSUserDefaultsController. The normal NSUserDefaultsController in IB is set to only use standardUserDefaults. Is there any way to have it use our userdefaults instead? I did come up with one way - but I don't I love it. I made a subclass of NSUserDefaultsController and in the initWithCoder method, I tell it to use our defaults...of course, I have to first call super or else I'll get a compiler warning (which feels like a waste and causes me to re-assign self)...so here's what I have now: - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder: coder] self = (MyUserDefaultsController *)[[NSUserDefaultsController alloc] initWithDefaults: myUserDefaults initialValues:nil]; return self; } Is there a better way? ___ 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/zav%40mac.com This email sent to z...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSUserDefaultsController in a NIB when not using standardUserDefaults
Hi Alex. Xcode will also complain if you don’t call super. You must call super and assign it to self…but then it seems that you are free to re-assign self - which I kinda get - the parent class might be doing important stuff in super…maybe there’s a more primitive init method I can override. Ideally though, we don’t even do this. Ideally, there is a better way to handle a custom suite for bindings with a NIB. On Sep 8, 2014, at 1:15 PM, Alex Zavatone z...@mac.com wrote: Stupid question, but what happens if you don't assign the first self to the result of the call, but just call [super initWithCoder: coder]? Do you need the result of that call, since you immediately override it? Sent from my iPad On Sep 8, 2014, at 2:09 PM, Alex Kac a...@webis.net wrote: This feels like there should be an easy answer... We are no longer using standardUserDefaults since we want to someday offer a widget for our app that will require accessing our app's preferences..so we're using NSUserDefaults with a custom suiteName. *The question is*: in the NIBs for our Preference panes, we had various UI elements bound to NSUserDefaultsController. The normal NSUserDefaultsController in IB is set to only use standardUserDefaults. Is there any way to have it use our userdefaults instead? I did come up with one way - but I don't I love it. I made a subclass of NSUserDefaultsController and in the initWithCoder method, I tell it to use our defaults...of course, I have to first call super or else I'll get a compiler warning (which feels like a waste and causes me to re-assign self)...so here's what I have now: - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder: coder] self = (MyUserDefaultsController *)[[NSUserDefaultsController alloc] initWithDefaults: myUserDefaults initialValues:nil]; return self; } Is there a better way? ___ 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/zav%40mac.com This email sent to z...@mac.com Alex Kac - President and Founder Web Information Solutions, Inc. My wife and I do a lot of things together including Halo 3 and firearm training. She's awesome. ___ 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: Add bindings for custom menu items' isHidden to (an attribute of) a custom object?
Daryle, allow me to admit that I have not read much of your posts. I’m just going to give some general advice. Cocoa Bindings can be problematic, but the problems are worth it when they solve the otherwise-difficult problem of magically keeping a data model and view in sync. In the case of NSMenu and NSMenuItem, however, there is no difficult problem because the menu is only visible when the user clicks on it, and at that time the delegate method -menuNeedsUpdate: is invoked, in which you can update the menu to reflect the current state of the model. In the other direction, the only time that the menu can change the model is when a menu item is clicked, and at that time you get an action message sent to a target. It looks like you’ve written a lot of code there. You should ask yourself what you are trying to do with Cocoa Bindings that you could not do by setting a delegate, implementing -menuNeedsUpdate:, and defining targets and actions. Cocoa Bindings of menus are probably more problematic than are Cocoa Bindings of normal view-based controls, because menus work differently. Also, menu bindings may be more buggy since they are rarely used and thus rarely tested. ___ 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: Add bindings for custom menu items' isHidden to (an attribute of) a custom object?
On Sep 8, 2014, at 4:21 AM, Daryle Walker dary...@mac.com wrote: The test value and the target menu were always the same. Four runs of double NULL then four more with Today’s sub-menu (Sep. 8). So the transformer always returns YES and every per-day history menu item (and sub-menu) is hidden. How do I get “dayItem.submenu” to be the operand for the transformer? Did I mess up the binding? Or the transformer’s very design? Where did those 4 NULL runs come from? … Oh, for that last question, it’s because the “sourceMenu” property starts as NIL and I don’t change it until I create the per-day menus. It would have to be that way since I set the property to the sub-menu of the newest day (unless it’s before Today). I can’t change the operand, so I had to change the operation: @interface MyObjectIdentityTransformer : NSValueTransformer //! Starts as nil; the instance to be compared. @property (nonatomic) id compared; @end @implementation MyObjectIdentityTransformer + (Class)transformedValueClass { return [NSNumber class]; } + (BOOL)allowsReverseTransformation { return NO; } - (id)transformedValue:(id)value { return [NSNumber numberWithBool:(self.compared == value)]; } @end static inline NSMenuItem * CreateMenuItemForDay(NSCalendarDate *day, NSDateFormatter *format) { NSString * const dayTitle = [format stringFromDate:day]; NSMenu * const daySubmenu = [[NSMenu alloc] initWithTitle:dayTitle]; NSMenuItem * const dayItem = [[NSMenuItem alloc] initWithTitle:dayTitle action:NULL keyEquivalent:@]; dayItem.representedObject = day; dayItem.submenu = daySubmenu; // Attach a binding to let the menu item auto-hide when used as the Today menu item. MyAppDelegate * const appDelegate = [NSApp delegate]; MyObjectIdentityTransformer * const transformer = [[MyObjectIdentityTransformer alloc] init]; transformer.compared = dayItem.submenu; [dayItem bind:NSHiddenBinding toObject:appDelegate.myOverflowMenuController withKeyPath:MyKeyPathSourceMenu options:@{NSValueTransformerBindingOption: transformer}]; return dayItem; } Each point of a binding is described by two aspects: an object and a (not necessarily direct) attribute of the object. In the -bind:toObject:withKeyPath:options: method, the bound point is the receiver and first argument and the source point is the second and third arguments. When using a value transformer in forward mode, the operand is always the source point. So when I had the transformer as an attribute of the source point, both the operand and the stored menu were always the same: the current Today menu. Now I have the transformer associated with the per-day menu item (i.e. the bound point), so I compare its sub-menu with the current Today menu (the operand). I was going to change the menu item’s representedObject to store the transformer, but then I realized that since the value transformer is part of a NSDictionary, the dictionary will do a retain and so I can make the transformer a loosely-associated object. — Daryle Walker Mac, Internet, and Video Game Junkie darylew AT mac DOT 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: NSUserDefaultsController in a NIB when not using standardUserDefaults
On 2014 Sep 08, at 11:09, Alex Kac a...@webis.net wrote: Is there a better way? How about redirecting standardUserDefaults, by sending it -addSuiteNamed: and -removedSuiteNamed: during launching? ___ 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: NSOutlineView
Ken, Thanks for trying to help me out. I tried to follow your advice, but I must not have completely understood it. I changed the relevant method to this: func outlineView( _outlineView: NSOutlineView!, objectValueForTableColumn tableColumn: NSTableColumn!, byItem item: AnyObject! ) - AnyObject! { let node = getDocumentNodeFrom( item ) return node } And in the particular NSTextFieldCell, I made sure “Bind to Table Cell View” was checked, and I set the model key path to objectValue.title. I’d love to attach a screenshot of what I’ve done in Xcode, but I haven’t been able to make a JPEG small enough to get past the mailing list’s 25K limit. In case it matters, here’s part of the declaration of DocumentNode: import Foundation class DocumentNode : NSObject { var title: String var content: NSAttributedString var children: [DocumentNode] When I run my program, the outline view still shows disclosure triangles but no titles for the text view cells. -- Charles Jenkins On Saturday, September 6, 2014 at 13:42, Ken Thomases wrote: Depending on your model, you may actually find it's better to have your data source return a compound model object and then bind the text field to just a specific property of that model object. So, your data source method could return the node and the text field could bind to objectValue.title. This approach allows you to add another view (say, an image view) and bind it to a different property of the object that's represented by the row. It also allows the text field to be editable and directly modify the model object by setting its title property (if that's something you want to allow). Regards, 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSOutlineView
On Sep 8, 2014, at 16:00 , Charles Jenkins cejw...@gmail.com wrote: I changed the relevant method to this: func outlineView( _outlineView: NSOutlineView!, objectValueForTableColumn tableColumn: NSTableColumn!, byItem item: AnyObject! ) - AnyObject! { let node = getDocumentNodeFrom( item ) return node } Well, this isn’t the prototype of the data source function. Is the above a typo, or have you misread the declaration’s “_ outlineView” parameter as “_outlineView”? ___ 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: NSOutlineView
Hi, On Sep 8, 2014, at 6:00 PM, Charles Jenkins cejw...@gmail.com wrote: I changed the relevant method to this: func outlineView( _outlineView: NSOutlineView!, objectValueForTableColumn tableColumn: NSTableColumn!, byItem item: AnyObject! ) - AnyObject! { let node = getDocumentNodeFrom( item ) return node } And in the particular NSTextFieldCell, I made sure “Bind to Table Cell View” was checked, and I set the model key path to objectValue.title. Try binding the Value binding of the NSTextField itself, not its cell. The model key path looks right. class DocumentNode : NSObject { var title: String var content: NSAttributedString var children: [DocumentNode] I haven't been following Swift closely enough to know: is String completely interchangeable with NSString? The text field's binding is going to expect to receive an Objective-C object. It should either be an NSString or an object on which it can call -description and get an NSString. Regards, 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSUserDefaultsController in a NIB when not using standardUserDefaults
Thanks. I’ll let you know when I can try it out later tonight. On Sep 8, 2014, at 3:40 PM, Jerry Krinock je...@ieee.org wrote: On 2014 Sep 08, at 11:09, Alex Kac a...@webis.net wrote: Is there a better way? How about redirecting standardUserDefaults, by sending it -addSuiteNamed: and -removedSuiteNamed: during launching? ___ ___ 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: Responder Chain Confusion
If you’re targeting 10.7 or later, you can use supplementalTargetForAction:sender: to add a responder chain side branch without modifying the actual chain. On Sep 7, 2014, at 9:24 AM, dangerwillrobinsondan...@gmail.com wrote: Hi all I just spent a bit of time poking around the responder chain and nil targeted actions. I built a view controller and a view hierarchy with controls that should be configurable. When instantiating the view controller the interface allows configuring the action SEL of the controls. Reuse is the goal of course. I know 10.10 changes things greatly for view controllers. But on 10.9 that's not there. Anyway, I need to insert the view controller into the responder chain between its top level view and that view's superview. That wasn't too bad. Implement the missing reference to the vc in a view subclass and give the vc a callback when the view is in place. But what I found while tinkering is that for non-document based apps from a vanilla project template there was no next responder for the window or the NSApplication instance. I had a method in the app delegate that I was trying to reach via nil targeted action. It couldn't get there. So I set the window nextResponder to the app and the app to the app delegate. I also made the app delegate an NSResponder subclass. It feels like overkill. Am I missing something simple? Is there something better to do here? ___ 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://urldefense.proofpoint.com/v1/url?u=https://lists.apple.com/mailman/options/cocoa-dev/lrucker%2540vmware.comk=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0Ar=yJFJhaNnTZDfFSSz1U9TSNMmxGyib3KjZGuKfIhHLxA%3D%0Am=wiIBUDZXVD2hKTb8s%2FSqrN8y%2BGT%2F9xvGyxQqKN02Rl0%3D%0As=fa9bb34dae5116f40a8559ca004269945ea4578e20e1200c47cf4ace158b7e8b This email sent to lruc...@vmware.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: Add bindings for custom menu items' isHidden to (an attribute of) a custom object?
On Sep 8, 2014, at 3:55 PM, Jerry Krinock je...@ieee.org wrote: Daryle, allow me to admit that I have not read much of your posts. I’m just going to give some general advice. Cocoa Bindings can be problematic, but the problems are worth it when they solve the otherwise-difficult problem of magically keeping a data model and view in sync. In the case of NSMenu and NSMenuItem, however, there is no difficult problem because the menu is only visible when the user clicks on it, and at that time the delegate method -menuNeedsUpdate: is invoked, in which you can update the menu to reflect the current state of the model. In the other direction, the only time that the menu can change the model is when a menu item is clicked, and at that time you get an action message sent to a target. It looks like you’ve written a lot of code there. You should ask yourself what you are trying to do with Cocoa Bindings that you could not do by setting a delegate, implementing -menuNeedsUpdate:, and defining targets and actions. Cocoa Bindings of menus are probably more problematic than are Cocoa Bindings of normal view-based controls, because menus work differently. Also, menu bindings may be more buggy since they are rarely used and thus rarely tested. The code takes up big space in e-mail, but it’s very little in the project. I have a controller object with notifications on the global WebHistory store. When it changes (load/add/remove/remove-all/save), the array of per-day menu items, each with a sub-menu of per-WebHistoryItem menu items, is changed to mirror the store. My application delegate has a KVO watch on that controller’s array, and changes the collection of per-day menu items put on the History menu accordingly. I have a second controller object with two arrays of menu items that possibly mirror a sub-menu of a given day-based menu item, using notifications to track changes on the sub-menu. My application delegate has KVO watches on those arrays too, accordingly changing the collection of per-WebHistoryItem menu items put either directly on the History menu and/or the sub-menu of the “Earlier Today” menu item. The method that syncs the controller for the day menu item representing Today hides the original menu item. Unhiding the menu item when Today changes but the item isn’t deleted is done in the (currently) five different spots in the code where the day list can change, customized at each spot. Using Bindings puts the visibility synchronization code in the best spot, the potentially affected menu items themselves. The KVO method came to mind first since I didn’t know about menu delegates until later. I guess with the delegate method, I save all the changes with the controllers then apply them all at once at presentation time when -menuNeedsUpdate: (or -numberOfItemsInMenu: and -menu: updateItem: atIndex: shouldCancel:) is called. With KVO, menu presentation is standard, since all the applicable items are already in place, reactively done when the WebHistory store changed. — Daryle Walker Mac, Internet, and Video Game Junkie darylew AT mac DOT 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: Responder Chain Confusion
Intriguing. I will check that out for the future. I know there are at least a couple of chains. I just wish I knew more about the ups and downs of creating new chains. Without duplication and abuse, it's such a powerful pattern with Objective-C. Sent from my iPhone On 2014/09/09, at 8:55, Lee Ann Rucker lruc...@vmware.com wrote: If you’re targeting 10.7 or later, you can use supplementalTargetForAction:sender: to add a responder chain side branch without modifying the actual chain. On Sep 7, 2014, at 9:24 AM, dangerwillrobinsondan...@gmail.com wrote: Hi all I just spent a bit of time poking around the responder chain and nil targeted actions. I built a view controller and a view hierarchy with controls that should be configurable. When instantiating the view controller the interface allows configuring the action SEL of the controls. Reuse is the goal of course. I know 10.10 changes things greatly for view controllers. But on 10.9 that's not there. Anyway, I need to insert the view controller into the responder chain between its top level view and that view's superview. That wasn't too bad. Implement the missing reference to the vc in a view subclass and give the vc a callback when the view is in place. But what I found while tinkering is that for non-document based apps from a vanilla project template there was no next responder for the window or the NSApplication instance. I had a method in the app delegate that I was trying to reach via nil targeted action. It couldn't get there. So I set the window nextResponder to the app and the app to the app delegate. I also made the app delegate an NSResponder subclass. It feels like overkill. Am I missing something simple? Is there something better to do here? ___ 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://urldefense.proofpoint.com/v1/url?u=https://lists.apple.com/mailman/options/cocoa-dev/lrucker%2540vmware.comk=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0Ar=yJFJhaNnTZDfFSSz1U9TSNMmxGyib3KjZGuKfIhHLxA%3D%0Am=wiIBUDZXVD2hKTb8s%2FSqrN8y%2BGT%2F9xvGyxQqKN02Rl0%3D%0As=fa9bb34dae5116f40a8559ca004269945ea4578e20e1200c47cf4ace158b7e8b This email sent to lruc...@vmware.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: Add bindings for custom menu items' isHidden to (an attribute of) a custom object?
On 2014 Sep 08, at 18:42, Daryle Walker dary...@mac.com wrote: Using Bindings puts the visibility synchronization code in the best spot, the potentially affected menu items themselves. I see what you mean. The KVO method came to mind first since I didn’t know about menu delegates until later. I guess with the delegate method, I save all the changes with the controllers then apply them all at once at presentation time when -menuNeedsUpdate: (or -numberOfItemsInMenu: and -menu: updateItem: atIndex: shouldCancel:) is called. Again, I haven’t read your code in detail, but my high-level guess is that maybe you could create, or maybe you already have, a “MenuManager” object that could be interposed between your menu and the data model. It would contain all of the arrays or whatever. On the model side, you could expose bindings (in code) to these five whatever things that can change the data. On the view side, it would be the menu delegate. With KVO, menu presentation is standard, since all the applicable items are already in place, reactively done when the WebHistory store changed. Hey, if you can get Cocoa Bindings working directly on menus, more power to you! I’m just sayin’ that the one time I tried that, I concluded it was all pain and no gain, and quite lonely. ___ 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
NSUserDefaults not sticking
Hi, I write some data to my .plist using standard NSUserDefaults but recently I have been getting user feedback (less than 5% of users) that after every launch of the app the data needs to be entered again. I’m in the process of doing some debugging but can anyone think of a reason why this might happen? Thanks in advance for the input, rc ___ 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