如何实现基于Cocoa的Adobe Photoshop插件 [英] How to implement a Cocoa-based Adobe Photoshop plugin

查看:295
本文介绍了如何实现基于Cocoa的Adobe Photoshop插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cocoa曾在CS3上使用诀窍将Cocoa bundle放在主要的Carbon插件包里面,从Carbon加载它并发出一个NSApplicationLoad()。这是因为Photoshop CS3是Carbon-only,用于卸载插件包。

Cocoa used to work on CS3 with the trick of putting a Cocoa bundle inside the main Carbon plugin bundle, loading it from Carbon and issuing a NSApplicationLoad(). That's because Photoshop CS3 was Carbon-only and used to unload the plugin bundles.

Photoshop CS4使用Cocoa,并在主线程上有自己的NSAutorelease池。

Photoshop CS4 uses Cocoa and has its own NSAutorelease pool in place on the main thread.

在Photoshop CS4非常简单的基于窗口的xibs / nibs由NSWindowController加载开箱即用。

On Photoshop CS4 very simple window-based xibs/nibs loaded by a NSWindowController work out of the box.

但是只是添加一个绑定到窗口上的控件,你会得到有趣的崩溃,可选择当你关闭窗口,或第二次使用插件,或者甚至当关闭Photoshop本身。

But just add a binding to a control on the window and you'll get funny crashes, optionally when you close the window, or the second time you use the plugin, or even when closing Photoshop itself.

为什么在我使用一些高级Cocoa功能之前,一切似乎都很好?我被困住。

Why everything seem to work well until I use some advanced Cocoa features? I'm stuck.

编辑:我真的发现自己解决更广泛的问题如何使用Cocoa在Photoshop CS3 / CS4插件?

EDIT: I've really found myself the solution to the broader problem "How to use Cocoa in a Photoshop CS3/CS4 plugin?". See below.

推荐答案

您必须创建一个新的包含您的nib和您的Cocoa代码。将产品包添加到插件的复制捆绑资源阶段。然后,一个过滤插件的代码加载一个Cocoa窗口与一些控件将是:

You have to create a new Loadable Bundle target that contains your nibs and your Cocoa code. Add the bundle product to the Copy Bundle Resources phase of your plugin. Then the code for a filter plugin that loads a Cocoa window with some controls would be:

Boolean DoUI (void) {

    // Create the CF Cocoa bundle
    CFBundleRef pluginBundle;
    CFURLRef cocoaBundleURL;
    pluginBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.example.plugin"));
    cocoaBundleURL = CFBundleCopyResourceURL(pluginBundle, 
                                             CFSTR("Cocoa_bundle"), 
                                             CFSTR("bundle"), 
                                             NULL);
    CFBundleRef cocoaBundleRef;
    cocoaBundleRef = CFBundleCreate(kCFAllocatorDefault, cocoaBundleURL);
    CFRelease(cocoaBundleURL);

    // start Cocoa (for CS3)
    NSApplicationLoad(); 

    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

    // load the cocoa bundle by identifier
    NSBundle* cocoaBundle;
    cocoaBundle = [NSBundle bundleWithIdentifier:@"com.example.plugin.cocoa"];

    // load the window controller from the bundle
    Class testControllerClass;
    testControllerClass = [cocoaBundle classNamed:@"MyWindowController"];

    MyWindowController* winController = [[testControllerClass alloc] init];
    [NSApp runModalForWindow:[winController window]];
    [[winController window] performClose:nil];
    [winController release];

    // release the bundle
    CFRelease(cocoaBundleRef);

    [pool release];

    return 1;
}

这是基于Craig Hockenberry 束缚。我仍在测试它,但它应该工作在CS3和CS4。

This is based on the Craig Hockenberry bundle trick. I'm still testing it but it should work both on CS3 and CS4.

这篇关于如何实现基于Cocoa的Adobe Photoshop插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆