On Oct 5, 2011, at 18:44, Donald Ness wrote: Thank you for the clarification. I understand that the quicklook plugin is not for the app -- it's a plugin for the quicklook viewer, or whatever finder uses to render previews and thumbnails. But yes, I totally misinterpreted the bundle loader setting. I thought it specified bundles that will be loaded there, not a bundle that does loading.
My NSDocument is what loads my model and sets up the document view correctly. I've already written a printView method for printing that does all the formatting work, and I just want to render that view in the quicklook graphics context.
I'm a little confused because I'm following an Apple example here:
It looks to me like the wrong thing to do. I have seen many examples of Apple's sample code that is too quick-and-easy, or downright buggy. Generally, I think you should think of Apple's sample as nothing more as an example-of concept associate to a single issue, not really as a final way of doing things. This looks to me like fragile (as I argued) and certainly overkill (as there's almost certainly a lot in the document class you don't need). The relevant code:
--
OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options)
{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // Create and read the document file SKTDrawDocument* document = [[SKTDrawDocument alloc] init];
if(![document readFromURL:(NSURL *)url ofType:(NSString *)contentTypeUTI]) { [document release]; [pool release]; return noErr; }
NSSize canvasSize = [document canvasSize]; // Preview will be drawn in a vectorized context CGContextRef cgContext = QLPreviewRequestCreateContext(preview, *(CGSize *)&canvasSize, false, NULL);
if(cgContext) { NSGraphicsContext* context = [NSGraphicsContext graphicsContextWithGraphicsPort:(void *)cgContext flipped:YES]; if(context) { [document drawDocumentInContext:context];
} QLPreviewRequestFlushContext(preview, cgContext); CFRelease(cgContext); } [pool release]; return noErr; }
--
My code is nearly identical. I need almost everything in the app project to render my NSDocument, so I wanted to avoid creating an additional project to house a library.
You have just two choices: either put the shared stuff in a separate (third) project, or share the shared sources in the two projects. The main point is that all the relevant shared code needs to end up in two different places, the app and the plugin, as those are run separately.
And my point is that for many reasons it is best to share as little as possible between the two projects. Otherwise any change in one project needs to propagate to the other, even if it is a change that would be completely irrelevant to the other, it would probably be a maintenance headache. To achieve that you have to think hard about how your code is set up, try to set it up as modular as possible.
So in your case I would separate the model code (including reading from a file), your view, perhaps some generic loading and data management code (perhaps in a separate controller class), and the generic printing code (which could be a method for the view class or the model class).
Of course I cannot be any more detailed here, as I know almost nothing about your context.
Christiaan
I don't really see a better way to do it, but I'm definitely open to a better suggestion. On Wed, Oct 5, 2011 at 10:25 AM, Christiaan Hofman <email@hidden> wrote:
On Oct 5, 2011, at 16:56, Donald Ness wrote:
I understand linking, but I wasn't clear on Bundle loading. After reading up on on it, an App is indeed a "Bundle" but not a "Loadable Bundle", so it can't be dynamically loaded which is what I was trying to do.
It's not just that. I think you still don't know what this is about. Especially, you don't understand how quicklook plugins work (hint: they're NOT plugins for the app), and also you don't understand what the "bundle loader" setting does (hint: it's about the executable that *loads* the bundle). The plugin cannot use something from the app, because the app is not running when the plugin is used (or when it is the plugin does not know about it).
What I need from my App code is the NSDocument, as well as the associated xib and other object and resource dependencies.
I'm thinking the best option is to recompile the sources in my app project in my plugin project.
Is there a better way? I want to do the simplest thing that just works.
First of all: is that REALLY what you want? (And if you say yes, than my second question is: is this REALLY REALLY what you need?) It sounds wrong. NSDocument is designed for an (document based) app. Not for anything else. So if you use it in another context, it may fail (you don't know what code Apple uses, neither do I, so you also don't know what further assumptions are made.)
So you should reconsider your design. Use only what you need in the plugin. You could separate the stuff that you need in both your app (i.e. in your document, so not the document class itself) and your plugin to separate source and resource files. Perhaps put that in a framework (or loadable bundle) that's included in both the plugin and the app.
Christiaan On Wed, Oct 5, 2011 at 4:45 AM, Christiaan Hofman <email@hidden> wrote:
On Oct 5, 2011, at 8:29, Donald Ness wrote:
> Hello,
>
> I'm having some trouble linking my document-based application with a QuickLook plugin.
>
> I can compile the plugin OK. And I can run it if I remove all references to my NSDocument (and just render a red square as the quicklook for example) -- I can see it render in the qlmanage tool.
>
> However, once I reference my NSDocument subclass, I receive this error:
>
> [ERROR] Can't load plug-in at /Users/donald/Development/MyApp/build/Debug/MyAppQuickLook.qlgenerator: The bundle “MyAppQuickLook” couldn’t be loaded.
>
> Which leads me to believe I have a linking error.
>
> Here's how I set up my project on Xcode 4:
>
> - Added a QuickLook plug-in target to my main project called MyAppQuickLook
> - Set MyApp as a target dependency for MyAppQuickLook
> - In build settings under Linking for MyAppQuickLook, I set "Bundle Loader" to: $(BUILT_PRODUCTS_DIR)/MyApp.app/Contents/MacOS/MyApp
>
> How do I investigate and fix this? The error message doesn't help much, and I'm stuck. Any help would be greatly appreciated.
>
> Thanks,
>
> Donald
Are you really saying that you want the *plugin* to link to the *app*? That makes no sense. You apparently don't understand what linking and loading means. So you should read up in the docs what that means. So in short: you cannot do this, it';s impossible and makes no sense.
Christiaan
_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden)
This email sent to email@hidden
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
|