when I transform objective-c code into monomac(c#) code ,I meet with a problem that how to Calling ObjC from JavaScript ,in obj-c the code as follows:
+ (NSString*)webScriptNameForSelector:(SEL)sel
{
if (sel == @selector(dataDidChange)) return @"dataDidChange";
if (sel == @selector(instanceReady)) return @"instanceReady";
if (sel == @selector(openColorPanel)) return @"openColorPanel";
if (sel == @selector(openFontPanel)) return @"openFontPanel";
return nil;
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)sel
{
if (sel == @selector(dataDidChange)) return NO;
if (sel == @selector(instanceReady)) return NO;
if(sel == @selector(openColorPanel)) return NO;
if(sel == @selector(openFontPanel)) return NO;
return YES;
}
- (void) openColorPanel {
[[NSColorPanel sharedColorPanel] orderFront:self];
// No need to do anything else. Selected text color is changed auto-magically. See: http://stackoverflow.com/questions/12543320/ckeditor-and-nscolorpanel-a-mystery
}
- (void) openFontPanel {
[[NSFontPanel sharedFontPanel] orderFront:self];
// No need to do anything else. Selected font is changed auto-magically. See: http://stackoverflow.com/questions/12543320/ckeditor-and-nscolorpanel-a-mystery
}
in the Objective-c code ,the application can work normally,however,when I translate these codes into monomac like downside,it can't work,I debug in the IDE,find that when application execute,it never enter into these methods,so I doubt that the monomac code don't associate with Javascript code successfully.
static string webScriptNameForSelector(MonoMac.ObjCRuntime.Selector sel)
{
Console.WriteLine("@@@@@@");
if (sel == new MonoMac.ObjCRuntime.Selector("dataDidChange"))
{
return "dataDidChange";
}
if (sel == new MonoMac.ObjCRuntime.Selector ("instanceReady"))
{
return "instanceReady";
}
if (sel == new MonoMac.ObjCRuntime.Selector ("openColorPanel"))
{
return "openColorPanel";
}
if (sel == new MonoMac.ObjCRuntime.Selector ("openFontPanel"))
{
return "openFontPanel";
}
if (sel == new MonoMac.ObjCRuntime.Selector ("Test"))
{
return "Test";
}
return "openFontPanel";
}
static bool isSelectorExcludedFromWebScript(MonoMac.ObjCRuntime.Selector sel)
{
Console.WriteLine("@@@@@@");
if (sel == new MonoMac.ObjCRuntime.Selector("dataDidChange"))
{
return false;
}
if (sel == new MonoMac.ObjCRuntime.Selector ("instanceReady"))
{
return false;
}
if (sel == new MonoMac.ObjCRuntime.Selector ("openColorPanel"))
{
return true;
}
if (sel == new MonoMac.ObjCRuntime.Selector ("openFontPanel"))
{
return false;
}
if (sel == new MonoMac.ObjCRuntime.Selector ("Test"))
{
return false;
}
return true;
}
the two method haven't been Invoked in this environment ,never does the code as follows:
[Export("openColorPanel")]
public void openColorPanel()
{
Console.WriteLine ("aaa");
NSColorPanel.SharedColorPanel.OrderFront (this);
}
[Export("openFontPanel")]
public void openFontPanel()
{
Console.WriteLine ("000");
NSFontPanel.SharedFontPanel.OrderFront (this);
}
The downside is the JS code:
//
// plugin.js
// CKEditor4Cocoa
//
// Created by Hermes Pique on 9/20/12.
// Copyright (c) 2012 Robot Media. All rights reserved.
//
CKEDITOR.plugins.add('osxbuttons', {
init: function(editor) {
editor.addCommand('openColorPanel', {
exec: function(editor) {
Cocoa.openColorPanel();
}
});
editor.ui.addButton('OSXTextColor', {
label: 'Text Color',
command: 'openColorPanel',
className: 'cke_button_osxTextColor'
});
editor.addCommand('openFontPanel', {
exec: function(editor) {
Cocoa.openFontPanel();
}
});
editor.ui.addButton('OSXFont', {
label: 'Font',
command: 'openFontPanel',
className: 'cke_button_osxFont'
});
}
});