Handle OSX Dock Drag N Drop - cocoa

I looked high and low for information on how to handle drag n drop to the dock in OSX. The drag n drop documentation (http://developer.apple.com/documentation/Cocoa/Conceptual/DragandDrop/DragandDrop.html#//apple_ref/doc/uid/10000069) I found all deal with dragging from view to view. If anyone can point me to some code samples, that would be excellent.
I'm writing my app using the PyObjC bride, but Cocoa examples would be equally welcome :-)

Well, looks like I asked too soon. Here is a great tutorial that shows how one does it:
http://recurser.com/articles/2007/04/13/cocoa-drag-to-dock-to-open/
Basically, just set your controller to be the delegate of NSApplication and implement the openFile method.

Here's a similar question from a couple weeks ago. My answer covered dragging files, which is what you're talking about; the other answer covers dragging data, such as images and bits of text (not image files or text files, but bare data).

http://lethain.com/entry/2008/aug/06/cocoa-drag-and-drop-text-into-the-dock-icon/ covers dragging and dropping text into a dock icon with pyobjc. You can adapt this into other files reasonably easily.

Here is a newer article for Xcode 4
http://fredandrandall.com/blog/2011/09/12/how-to-open-any-file-you-drag-onto-your-apps-dock-icon

Here is an example project "DockDrop".

Related

Looking for a spreadsheet-like control for Cocoa

I'm looking for a grid view / table view / spreadsheet-type control for Cocoa and can't seem to find anything that's in any reasonable state.
I've tried using NSTableView but it's not really meant to be a single cell control.
NSCollectionView doesn't seem to be right either.
Any ideas?
While Matt Ball's spreadsheet view (https://github.com/mattball/mbtablegrid/, mentioned above) is several years old, it does still compile on El Capitan. It must be easier as a starting point than working from scratch. There are several forks of the repository, most notable this one that does seem to be actively developed:
https://github.com/pixelspark/mbtablegrid
It seems like it would be better for those interested to pool contributions than create something new!
We now have NSGridView, which is most likely what any future person reading this will want to use.

Menu items in main menu bar show up with different font sizes.. what gives?

I just noticed the strangest thing when updating one of my Mac applications.
The menu bar of the application when run has different font sizes (!?). Some items are in the normal system text size (13 point?) and others are a few points smaller (11 points?). What gives?
I didn't even know that you could do this.. never mind understanding how this just came about of its own volition..
I immediately zeroed in on the likely culprit XCode 4, but compiling the same project with 3.2.5 shows the same problem.
I'm rather flummoxed by this.. has anybody come across this weird phenomenon?
Best regards,
Frank
I`m used to iOS but you may have a similar issue. The UILabels have an "autoshrink" property, which reduces the font size if the text is too long, to avoid truncating it. You can turn this property off in the Interface Builder. Hope this helps!

Drop down window to edit Cocoa pop-up menu items

I'm relatively new to Cocoa and I would like to implement the ability to add or delete items from a pop-up menu in the same way that the OS X System Preferences/Network Location pop-up works. Selecting the 'Edit Locations...' option rolls down a window that provides the ability to add to, or delete from the existing Location list. My interest in doing things this way is as much about conforming to the relevant Human Interface Guidelines as having a way to dynamically change the menu content. (I have no real problem with the 'background' coding side of things, it's the user interface that's my primary issue at this stage.)
Is this a standard IB View?
On the surface, I can't see anything appropriate, but maybe that's just my inexperience. I'm assuming that, because this is not an uncommon sort of requirement, the task should be pretty straightforward and that Apple, or someone, would even have a relevant code sample to show how to define such a window.
Can anyone point me in the right direction?
Sorry for the late answer. I found this tutorial: http://cocoadevcentral.com/articles/000014.php

Equivalent of .Net Data Repeater in Cocoa

I'm a total noob to Xcode and Interface builder. I'm on version 3.2.3 and OSX 10.6.4.
What I'd like to know, and haven't been able to find out, is how to display a list of n items. Using .Net, I'd probably use a Data Repeater control and then use that to repeatedly populate the controls I'd like to display.
Is there an equivalent or am I going about things in the wrong way? I don't see anything in the IB controls library that is quite what I'm looking for.
Any help is much appreciated, even a direction to a relevant tutorial or something.
Regards,
Iain
I guess you are looking for NSTableView with it's DataSource (ArrayController or equivalent) and it's delegate (for defining N items)?
The most common view for displaying lists is NSTableView. There are many, many tutorials on the web... Just google 'nstableview tutorial' and take your pick. :-)

Is there a simple way to combine a text and icon in an NSCell in Cocoa?

I'm trying to create a very simple selection list widget based on NSOutlineView. However, I'm having a hard time figuring out how to display an icon and a label right next to it, which is really the expected behavior in all the mainstream implementations of that kind of widget out there (iTunes, mail, Finder,...).
So far I am just binding two separate cells, but then when I'm expanding the tree, the icon cell grows larger and a gap appears between the icon and its accompanying label. I know I can probably overcome this problem by extending NSCell and provide a custom class, but as what I'm trying to achieve is really the standard thing, I can't be resigned to accept that there isn't a simpler solution.
Candide
Sadly, there isn't a 'text and icon' cell that you can just use, fresh out of the box as you would like. However, when I was working on a project, I found that Apple released some sample code that implements this, since it is such a common idiom.
This can be found here, specifically ImageAndTextCell.h/m
It can help teach you about UI customization by reading through this example, but scratching that, just dropping the ImageAndTextCell straight into your project should do just fine.
You need to create ImageAndTextcell to combine text and icon..
you can create ImageAndTextcell like this Sample Project

Resources