Custom NSTextView autocompletion menu - cocoa

How would one implement a custom auto-complete pop-up menu like Xcode has?
At the moment I can only put custom auto-completions using
- (NSArray *)textView:theTextView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(int *)index
I want a bit more flexibility than this.
Cheers!
MT

Xcode (and other apps) use a custom auto-completion view. You can bring up your view at the correct location using the text view's layout manager's method locationForGlyphAtIndex: (which return an NSPoint).

Related

Eclipse Scout Neon hide settings icon on table field

I would like to know how to hide settings wheel icon in header of table field.
Note: At the time of writing, Eclipse Scout Neon is not yet released.
From browsing the source code I did not see a convenient getConfigured... method to quickly hide that menu.
Fear not, you have two options to do so anyway.
The menu you wish to get rid of is the OrganizeColumnsMenu.
Override execInitTable on your table and hide the menu:
getMenuByClass(OrganizeColumnsMenu.class).setVisibleGranted(false);
Alternatively, override addHeaderMenus(OrderedCollection<IMenu> menus) and either remove the menu added by the default implementation, or not call the super implementation at all.

Unable to see custom classes in Interface Builder drop down

I'm using Xcode 6.1.1, and cannot select my custom class from the drop down. Because of this, I believe it is causing several other related issues (see below).
Symptoms:
When using the IB drop down to choose a custom class, none of the custom classes appear.
IB_DESIGNABLE and IBInspectable do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined as IB_DESIGNABLE.
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
Suspected to be related: WatchKit: unable to find interface controller class
How can I fix this?
Things that worked:
Try on another machine. (This leads me to believe the machine has some setting that is messing this up.)
Reinstall Xcode.
Moving the project to a new location (in this case a git repository), fixed it once.
Things I tried that didn't work (but have worked for others):
Restart Xcode
Restart machine (this worked once before, not this time)
Create a new storyboard.
Create a new subclass (not just rename it).
Create a new project via Apple's single view template.
Cleaning the project
Deleting derived data
Reindex the project
Remove localization on the storyboard file.
Things I tried that didn't work:
Naming the subclass according to Apple's conventions (e.g. instead of View use ABCTestView).
Import the .h of the class in the .h and .m of the view controller.
Try on another version of Xcode, which is already installed (beta 6.2).
Related discussions:
https://discussions.apple.com/thread/3054574?start=15&tstart=0
Storyboard uiviewcontroller, 'custom class' not showing in drop down
This wasn't your specific situation but I was in a similar "rip my hair out" moment. When creating custom controller classes and using the interface builder, you must make sure to click the yellow button at the top of the view you're working with (the view controller button). Otherwise the custom ViewController class won't show up in the custom class drop down menu within the identity inspector.
One thing that worked for me after inexplicably seeing the issue where the "Designables" row would not appear in the Custom Class section of the Identity Inspector:
Before (not functioning: Designables did not appear and Interface Builder did not render my class):
IB_DESIGNABLE
#class MyCustomClass;
#interface MyCustomView : UIView
After (functioning: Designables did appear and Interface Builder did render my class):
#class MyCustomClass;
IB_DESIGNABLE #interface MyCustomView : UIView
So it appears that Xcode is very sensitive to the order of things.
This is what worked for me:
I somehow lost the view reference, so all i did was to drag from a little circle "New Referencing Outlet" to the main view of the .xib, and BOOM!
Here are some possible solutions:
When using the IB drop down to choose a custom class, none of the custom classes appear.
Manually type the name of your custom class instead of trying to find it in the dropdown. Sometimes IB will autocomplete the name of the class as you type, especially if you follow Apple's conventions, i.e. YourView as a subclass of NSView.
IB_DESIGNABLE and IBInspectable do not work: When selecting the control in IB, the "Designable" status does not appear; none of the inspectable properties appear either. Debug selected views option is grayed out when selecting a view which is defined as IB_DESIGNABLE.
If the view does not begin as a Custom View either dragged from the Object library or created from Editor > Embed In > ..., for some reason changing the Custom Class in the Identity inspector doesn't make a difference. To fix this, right-click the .xib and choose Open As > Source Code. Search for the view you want to fix (giving your view a label that is easily identifiable in IB will make this easier). You will find an entry like this:
<view ... customClass="YourView">
...
</view>
Change view to customView so that the entry resembles:
<customView ... customClass="YourView">
...
</customView>
then right-click the .xib again and choose Open As > Interface Builder XIB Document and you should now see a Designables entry under Custom Class in the Identity inspector of IB and Debug Selected Views will be available under the Editor menu.
Ctrl-dragging items to create connections (IBOutlet and IBAction) from IB to source code occasionally doesn't allow you to "drop" the connection into the class's source code (as if there is a class mismatch). (Note: This assumes you manually typed in the class name in the Custom Class section.)
Doesn't sound like your exact problem, but on a dual-monitor/multi-monitor setup, if IB is on a different monitor from the source code window, go to Apple menu > System Preferences... > Mission Control and uncheck Displays have separate Spaces. This may have some visual side-effects (like window drop-shadows bleeding into other monitors) but it will fix the problem of ctrl-dragging onto a separate monitor.

Enable Edit Menu for NSTableView

I'm new in cocoa but with some experience with Cococa-Touch. As I am developing a OSX Lion app that uses tables (NSTableView and NSOutlineView), I am having troubles trying to add copy-paste features to tables.
I have no problems with drag-n-drop features that I have coded in table view controllers. But I cannot make edit menu options (copy and paste) enable.
I did read apple documents, but I'm missing something. I can't make it work. Can you please guide me with the first steps to enable that edit menu options and attend them from table view's controller?
I have solved it, so I answer my own question.
I have subclassed NSTableView and NSOutlineView and, in the new class, included the methods: -validateUserInterfaceItem: , copy: and so on. I was erroneously expecting to receive actions in Table Delegates.

How to enable toolbaritems in NSToolbar?

I have created an application in which I have implemented a custom toolbar, and I have put a custom item in that toolbar. But I am unable to click on it; it shows
that it's disabled. How to solve this problem?
If toolbar buttons are disabled by default and you haven't implemented NSToolbarItemValidation, it's usually because you have forgotten to connect the buttons to IBActions, or you have but you haven't implemented the actions.
Implement the NSToolbarItemValidation protocol in your NSToolbar's delegate, and return NO for every NSToolbarItem that you want disabled (return YES to enable it).
i had similar issue, and got resolved by subclassing NSToolbarItem and override validate Method in it.
NSToolbarItem are disabled by default if you do not implement the corresponding action on the target. Be sure to have a corresponding method for the action on the target instance.
In the Storyboard, select the tool bar item.
In the Utilities panel in the right side select Attributes inspector.
Turn off the Autovalidates option for Behaviour.

Cocoa Interface Builder's 'Attributes Inspector' like window

I'm making a Cocoa application, and I would like a panel like the 'Attributes Inspector' in Interface Builder. So with big tabs on the top and collapsable/expandable groups. Does anyone know how I can do this?
This is an image of the Attributes Inspector:
Attributes Inspector http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeQuickTour/Art/hello_win_attributes.jpg
So I actually want to make a window like the one shown in the image above.
InspectorKit is FOSS on github.
There's no built-in Cocoa controls to do this. You're going to have to write some custom views which replicate the functionality.
There some good advice for creating custom controls in the answers to this question: Looking for info on custom drawing of interface components (Cocoa)
If you need additional help, I recommend you ask smaller, more specific questions explaining what you've tried and what hasn't worked.
I've written some custom classes to do this- it ended up being less work than I expected. I broke it down into two separate components which can be used independently- the first handles the icons at the top and performs the view switching and the second handles the expandable panes:
My code is available at github and is under the BSD 2-clause license.

Resources