Bounce the Downloads stack dock icon using C++ (without using ObjectiveC) - cocoa

Firefox doesn't currently bounce the Downloads box in the dock when a download is finished, like Safari, Chrome and Camino do.
If Firefox was written in Objective C, you could very easily add the one line of Objective C code required to do this. However, it's not. Is there a way to call this Cocoa function from C++ so that it can be added to Firefox for the benefit of all Mac users?

What I'd recommend, and I had to do this for a project I was working on, you could have a few files of obj-c++ that provide both a C/C++ api and internally use obj-c code to trigger the doc flashing.
Essentially you create a standard C/C++ header file. In the code side you make the file a .m or .mm file.
This would then let you write the obj-c one liner in questions directly into a C/C++ function, and since the header file is in plain C/C++ it won't be a compiler error for the non .mm files in the project.
This of course assumes that compiling with a compiler (like GCC) that speaks both languages.
A simple and (tested) example of this approach would be:
TriggerBounce.h
void TriggerBounce(char * filepath);
TriggerBounce.m
#import <Cocoa/Cocoa.h>
void TriggerBounce(char * filepath) {
NSString *pathToFile = [NSString stringWithCString:filepath encoding:NSUTF8StringEncoding];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:#"com.apple.DownloadFileFinished" object:pathToFile];
}

You can use the Carbon API's CFNotificationCenterPostNotification.
Carbon is pure C.
Documentation and code samples here.

Related

Can't find AppDelegate.m in xcode

I'm currently trying to implement Facebook SDK into my Unity App but I can't find the AppDelegate.m that I must modify in order to implement the SDK.
I tried searching everywhere in my Xcode folder but it seems nowhere to be found.
I search on google too but as I really don't understand anything to Xcode (except from building my Unity Project), I don't understand the answers too...
Thanks, and have a nice day !
The file name “AppDelegate.m” is a generic reference to “the file that contains the definition of your application delegate class”. Your app is not required to name the file “AppDelegate.m” however, so you’ll need to find yours.
Somewhere in your app there is a class that implements the UIApplicationDelegate protocol. You should search for “UIApplicationDelegate” using Xcode’s search function. That should put you on the right track to finding the class. Whichever file that class is in is the file you need to refer to when other documentation says AppDelegate.m
Update:
I forgot that in objective-c you don't declare adoption of a protocol. Here is a different way to find your app delegate.
Find your main.m file (this file is required, so you'll definitely have one). It will contain code like this:
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegateClassName class]));
}
}
The interesting piece is [YourAppDelegateClassName class], since this represents the class of your application delegate. Do a search for the first word in the square brackets, in this case it is YourAppDelegateClassName.
You can find it by searching UIApplicationDelegate in xcode search, then you will find the implemenation of this protocol in some file named as something.h.that's the file which you needed.
In Xcode 13.3.1 the file would be the (AppName)App file. This file defines the entry point for the app. This file is where you would define the app delegate class.

Adding multiple Cib / Xib files in Cappuccino

Currently I'm working on a product that uses the Cappuccino Framework and the Objective-J language.
I created my project using this command after installing Cappuccino: capp gen -t NibApplication Myapp
The Problem I'm facing is that I want to keep my code and GUI clean.
By doing so I wanted to split the GUI up in separate Xib / Cib (compiled version Cappuccino can read) and separate controllers, like I do with iOS and Mac apps.
I couldn't find on the internet or on the docs how to do so.
Also, all the examples (including the NibApplication template) contains only 1 xib file.
In short what I'm after is to load a controller, based on a XIB file which holds the window. All the outlets are connected to the controller I loaded.
Is there anyone who knows how to do it?
Thanks in advance and have a nice day!
The typical way to do this is to use a CPWindowController or a CPViewController for each xib you want to load. Here's what it might look like:
var myViewController = [[CPViewController alloc] initWithCibName:"mynib" bundle:[CPBundle mainBundle]];
This would load Resources/mynib.cib from your main bundle. Normally you'd also subclass CPViewController so as to give yourself a convenient spot for your control code.
Fixed it myself! I used this tutorial: http://vimeo.com/8948460
But instead of using atlas I used XCode. Just follow the steps but with XCode and you'll be fine if you want the above to happen.

Need help understanding Xcode *.pch files

I'm working on a 3rd party UIKit replacement for iOS. I have it building as a framework using a seriously helpful project from GitHub. (Not mine, but if you have interest, it's here.
I'm trying to use my library in other projects I'm writing. Like I said, it's basically a drop-in replacement for much of UIKit, so I decided to import the framework in my project's *.pch file instead of everywhere I might wish to use a button, action sheet, alert view, etc...
When I DON'T have an #import directive in a header file and declare a property of type MBMButton, the compiler gives me an error of "Unknown type name 'MBMButton'; did you mean 'UIButton'?" Oddly enough, the code will still run (even though this is an error, not a warning). Adding #class MBMButton or #import <MBMUIKit/MBMUIKit.h> resolves this compiler complaint.
When I DON'T have an #import directive in an implementation file (or its header) and call a method that exists in MBMUIButton but NOT in UIButton, I get a compiler error of "No visible #interface for 'UIButton' declares the selector...". As before, the code will actually run, since it's a valid call.
Now, I've done some digging, and I've changed my project's settings. Where I didn't have any value in the GCC_PREFIX_HEADER, I added the file name. Noting the Quick Help description by Apple, I tried both "ProjectName-Prefix.pch" and "./ProjectName-Prefix.pch". Neither seemed to resolve the problem. I eventually figured out that the Target-level settings override the Project-level settings, and that the Target-level settings already specified "ProjectName/ProjectName-Prefix.pch". So that was a dead end. (Nice to learn exactly what the relative path settings are, though!)
I'm OK with not using the *.pch file. It's only a convenience, and I can definitely use appropriate #class and #import directives. What's bugging me is not understanding the issue. How should one use the *.pch file?
The prefix header file is automatically included in every .m file in your project but not in any .h files.
Therefore, any references to classes will require the header to be included or a forward declaration:
#class MyClass;
However for #protocols you'll need the full header, a forward declaration won't work:
#protocol MyProtocol; //this won't work
#interface MyController : UIViewController <MyProtocol>
…
#end

Xcode: How to find the source code for standard or system libraries?

Xcode question here: If I'm programming in C++ or objective-C, and I #include or #import a library; e.g.
#include <iostream>
#import <Cocoa/Cocoa.h>
I'm often not sure where to look for these header files in the directory structure on my Mac. In other development environments, you can right click the included or imported filename and have the option to jump to source. Is there an equivalent feature in Xcode?
Also, for the standard C++ libraries and the Cocoa framework, is the source code for the implementation files available, or only the headers together with compiled link libraries?
For Apple frameworks, the headers are available. You can also option-double-click on a method or selector to get to either Apple documentation or to the relevant entry in the associated header file.
Holding option and double clicking on a function is a great way to see a document snippit, pictured below. You can hit the book button from there to see the whole documentation item.
But that doesn't have the source. To answer your question, what you might try is the button with the .h on it, pictured above the NSURLConnection.h box, It should pop you into the source for the file displayed in that title.

Is there a syntax highlighting editor component for Mac OS X

I am looking for a syntax highlighting component that I can include in a Mac OS X XCode project to allow editing of Ruby, C++, Lua, etc.
I need a component that is open source or has the source included.
My Google searches didn't turn up much in the way of Mac OS X frameworks or components at all, let alone the type I am looking for.
Thanks for any pointers!
UKSyntaxColoredTextDocument (Mac-specific) or Scintilla (cross-platform and in use in a variety of editors, including Komodo) might be what you're looking for.
Try to use scintilla. http://www.scintilla.org/
You could try using CodeMirror. I do this in my SQLite Professional app to highlight user editable queries. It's also fairly simple to setup:
In your project, add the CodeMirror contents as a Folder rather than a group.
Add the WebKit.Framework to your project.
Add a WebView to your nib/xib.
Add the following code:
// Load our webview from our local CodeMirror path
NSURL * url = [NSURL fileURLWithPath: [NSString stringWithFormat:#"%#/CodeMirror/Demo/preview.html", [[NSBundle mainBundle] resourcePath]]];
NSString * html = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding error:nil];
[webView.mainFrame loadHTMLString: html baseURL: url];
They also have lots of formats pre-defined, so it works quite well. The one issue I have found with this, is that the native Find dialog does not work when in the context of the WebView.

Resources