Is there a way, in OSX SDK, to represent a file in UI, by presenting its icon ?
In other words, is it possible to access the icon for a specific file, to show it in a NSImageView for example ?
PS: I'm using MonoMac, but Objective-C code will certainly help me too :)
Thanks in advance
You can use NSWorkspace's iconForFile:
e.g.:
[[NSWorkspace sharedWorkspace] iconForFile:#"/Applications/Launchpad.app"];
If you need icons for a certain file type, you can use iconForFileType:
I used this category
https://github.com/incbee/NSImage-QuickLook very helpful.
Related
i am searching from over 2 hours without finding an answer!
i am a noob in xcode and cocoa programming.. basically my xib file contains a tab view, and in one of the tabs i placed a webview. i also added the web framework.
my app is a document based application. and i am not able to declare an iboutlet for the webview in order to make it load a URL.
how am i supposed to declare the iboutlet in a document based application? and evne more in what file am i supposed to do it?
please keep the answer as simple as possible since i am veeery green in this and coming from Windows it takes some time understand the mac environment.
tahnk you!
Igor
Probelm solved!
first i fogto to implement the webkit framework, then i added the implementation to the app delegate instead of the document. thus when opening a document it did not load the page!
thanks for your help anyway jemmons!
I think : you have to import WebKit:
import < WebKit/WebKit.h>
That's just a guess, though, since you haven't posted enough code to say for sure.
Does anyone know where the icons in the Finder sidebar are located? I'd like to use that small resolution optimized Applications icon in my app, but I can't find the original anywhere.
If you want to use the icon in your source code you can get the NSImage by calling:
[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode(kToolbarApplicationsFolderIcon)]
You can change to kToolbar{theIcon} for getting any other icon that appears on the toolbar.
Found it.
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/SidebarApplicationsFolder.icns
I have a window with some content that could be previewed, mailed,...
I decided that the best way to do this is to put appropriate application icons in toolbar, namely from Mail, Preview,...
Trick is, how to do that? Is thee any way too access other's application package and have access to its icon? Or is there any other elegant way?
Code:
// Get icon
NSImage *theIcon = [[NSWorkspace sharedWorkspace] iconForFile:#"/Applications/Mail.app"];
// Display icon (irrelevant in your case)
[theIcon setSize:NSMakeSize(128, 128)];
[theImageView setImage:theIcon];
There is also one other way of doing it, especially if you are building toolbar in IB:
right-click application icon
copy it
open Preview
select New from Clipboard
You will get complete set of application icons in any size. You can export them and put them in Image Well in IB
I'm working on embedding a WebView in Cocoa. I have the basic view up and running, but the problem I'm facing is when I type using either the keyboard or the on-screen keyboard, I get a beep from my Mac and none of the characters are actually shown in the Web view's text field.
I've been going through the web view's reference guide from Apple, but couldn't find anything related to this.
Any help is much appreciated!
Thanks,
Teja.
Omz's comment solved the issue for me. I changed my NSWindow styleMask to a style that can become a key window:
window.styleMask = NSTitledWindowMask
I want to develop a plugin with Safari. Now I wan to make a demo for add a button into it's MainWindow or menu into it's MenuBar. I have seen to Document WebKitPluginProgTopic and the sample:/Developer/Examples/Webkit/WebKitMoviePlugIn . But they didn't tell the full process of make a plugin with safari and how to add some menu or button in the safari window . Someone can give me some advice or simple code to resolve this problem, Thank you very much!
The plug-in architecture isn't thought for enhancing the browser but to support special media formats like flash or quicktime. The problem is that the plugin is only loaded when the corresponding media type is found.
Agile Web Solutions have found a way to load the plug-in all sites in 1Password and insert code into Safari. They've documented it in their blog. For other means of injecting code have a look at this question: InputManager plug-ins in Snow Leopard.
I haven't got any experience in building menus programmatically, but it should work like this:
NSMenu *newMenu = [[[NSMenu alloc] initWithTitle:#"MyMenu"] autorelease];
NSMenu *mainMenu = [NSApp mainMenu];
[mainMenu addItem:newMenu];
Changing the windows isn't that easy. Your best guess is probably [NSApp orderedWindows], which exists only for scripting purposes, but should be usefull to your task.