> On Mar 28, 2017, at 1:45 PM, Daryle Walker <[email protected]> wrote:
> 
> It seems that I’ll be the first American in general & GitHub open-source 
> history to ever make a NSText​Find​Bar​Container subclass. The window 
> controller shows two views in a split view. The top half is a NSTableView 
> surrounded by a NSScrollView. The bottom half is a NSTextView surrounded by a 
> scroll view. Each one can handle NSTextFinder, but I’m considering them 
> halves of the same document (since they are). So I’m make a single find-bar 
> to cover both views. I’ve read about NSTitlebarAccessoryViewController and 
> wonder if I can use it to hold the Find controls.
> 
>> class MyWindowController: NSWindowController {
>>    //...
>>    dynamic var representedMessage: RawMessage?
>>    dynamic var isWritable: Bool = true
>> 
>>    // Outlets
>>    @IBOutlet weak var messageController: NSObjectController!
>>    @IBOutlet weak var headerController: NSArrayController!
>>    @IBOutlet weak var textFinder: NSTextFinder!
>>    @IBOutlet weak var accessoryView: NSVisualEffectView!
>> 
>>    // Pseudo-outlets
>>    var headerViewController: NSViewController!
>>    var bodyViewController: NSTabViewController!
>>    var addBodyViewController: NSViewController!
>>    var bodyTextViewController: NSViewController!
>> 
>>    var headerTableView: NSTableView!
>>    var bodyTextView: NSTextView!
>> 
>>    /// Table of which characters, combining the header and body as a single 
>> string, are where.
>>    dynamic var textRanges = [NSMakeRange(0, 0)]
>>    /// The accessory title-bar to contain the text-finding controls.
>>    let findBar = NSTitlebarAccessoryViewController()
>> 

This creates an empty class; you should subclass 
NSTitlebarAccessoryViewController and provide implementation stuff to get the 
view, or use initWithNibName and pass in your NIB that contains the view. Hence 
the log you mention later.

>>    //…

You left off what you are doing here; it might be relevant.

corbin

>> 
>>    override func windowDidLoad() {
>>        super.windowDidLoad()
>>        //...
>>        findBar.layoutAttribute = .bottom
>>    }
>>    //...
>> }
> 
> I added a NSTextFinder to my window controller’s top bar and added an outlet. 
> I’m using the window controller class as the NSTextFinderClient delegate:
> 
>> extension MyWindowController: NSTextFinderClient {
>> 
>>    /// Determine the right substring, from the text range map.
>>    func string(at characterIndex: Int, effectiveRange outRange: 
>> NSRangePointer, endsWithSearchBoundary outFlag: 
>> UnsafeMutablePointer<ObjCBool>) -> String {
>>        //...
>>    }
>> 
>>    /// Determine the length of the virtual string, from the text range map.
>>    func stringLength() -> Int {
>>        return NSMaxRange(self.textRanges.last!)
>>    }
>> 
>> }
> 
> and a NSTextFindBarContainer delegate:
> 
>> extension MyWindowController: NSTextFinderBarContainer {
>> 
>>    var findBarView: NSView? {
>>        get { return self.findBar.view }
>>        set { self.findBar.view = newValue ?? /*self.accessoryView*/ NSView() 
>> }
>>    }
>> 
>>    func contentView() -> NSView? {
>>        return self.window?.contentView
>>    }
>> 
>>    var isFindBarVisible: Bool {
>>        get {
>>            return self.findBar.parent != nil
>>        }
>> 
>>        @objc(setFindBarVisible:) set {
>>            if newValue && self.findBar.parent == nil {
>>                self.window?.addTitlebarAccessoryViewController(self.findBar)
>>            } else if !newValue && self.findBar.parent != nil {
>>                self.findBar.removeFromParentViewController()
>>            }
>>        }
>>    }
>> 
>>    func findBarViewDidChangeHeight() {
>>        // Do I need to do something here?
>>    }
>> 
>> }
> 
> I have no idea if what I’m doing here is even close to being right. (The 
> “accessoryView” property maps to a NSVisualEffectView that I made because I 
> thought “NSView()” was wrong at first. It made no difference.) When I try 
> running the app, creation of the first window is jammed by:
> 
>> 2017-03-28 15:33:27.659649 XNW[51906:6766586] -[NSNib 
>> _initWithNibNamed:bundle:options:] could not load the nibName: 
>> NSTitlebarAccessoryViewController in bundle (null).
>> 2017-03-28 15:33:27.677235 XNW[51906:6766586] -[NSNib 
>> _initWithNibNamed:bundle:options:] could not load the nibName: 
>> NSTitlebarAccessoryViewController in bundle (null).
> 
> Is anyone from Apple and/or has privately made a NSTextFindBarContainer class 
> capable of helping? As I said, there are no answers from WebSearch (i.e. 
> others will be helped by me). Is there Apple sample code that covers this?
> 
> — 
> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> 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/corbind%40apple.com
> 
> This email sent to [email protected]


_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to