开发插件总结下来的资料,原始资料来源于SDK,加入了自己的理解。
Listener Plug-in
它是一个自动化插件开发的例子,同时也是一个实用工具。在使用photoshop时,它记录下来用户的操作,以c代码的方式输出Listener.log,所以可以拷贝这些代码到插件源码中使用。如选择菜单、选择文档、移动图层,但是也有一些操作不能用动作表示。
安装Listener Plug-In:使用Debug版本的Listener.8li进行插件安装,启动photoshop,查看菜单File》Automate》Listener,如果存在说明安装成功了。
在photoshop工作期间,Listener plug-in记录用户层面的事件。较近的事件在Listener.log中靠前。
PlayeventNotify函数:在photoshop启动时,PlayeventNotify函数总是重现,表示的代码没有什么用处。
一个例子:
PlayeventPaste函数:它表示Edit->Paste菜单或Ctrl+V组合按键,粘贴剪切板的数据到当前图层。代码如下:
SPErr PlayeventPaste()
{
PIActionDescriptor result = NULL;
DescriptorTypeID runtimeID = 0;
DescriptorTypeID runtimeTypeID = 0;
SPErr error = kSPNoError;
error = sPSActionControl->Play(&result, eventPaste, NULL, plugInDialogSilent);
if(error) goto returnError;
returnError:
if(result != NULL) sPSActionDescriptor->Free(result);
return error;
}
Play函数执行目标事件有4个参数:结果descriptor的地址,事件名字,事件descriptor和对话框模式。粘贴没有事件参数,eventDescriptor就为NULL。对话框模式有3种,plugInDialogDontDisplay,plugInDialogDisplay,plugInDialogSilent。最经常用的就是plugInDialogSilent,它表示不显示对话框,没有用户交互。plugInDialogDisplay显示每一步的对话框。plugInDialogDontDisplay模式只在遇到错误数据时显示一个对话框。