MagicSketch / XcodeTemplate-SketchPlugin

MIT License
106 stars 13 forks source link

No function named onOpenDocument in Sketch Panel UI Framework #5

Open eldos-dl opened 7 years ago

eldos-dl commented 7 years ago

In the default code generated by Sketch Panel UI Framework, there is no onOpenDocument function in Panel/Panel.js while we have default onStartup and onSelectionChanged functions.

    "handlers" : {
        "actions" : {
            "Startup" : "onStartup",
            "OpenDocument":"onOpenDocument",
            "SelectionChanged.finish" : "onSelectionChanged"
        }
    }
}
]
*/

var onStartup = function(context) {
  var testing_FrameworkPath = testing_FrameworkPath || COScript.currentCOScript().env().scriptURL.path().stringByDeletingLastPathComponent().stringByDeletingLastPathComponent();
  var testing_Log = testing_Log || log;
  (function() {
    var mocha = Mocha.sharedRuntime();
    var frameworkName = "testing";
    var directory = testing_FrameworkPath;
    if (mocha.valueForKey(frameworkName)) {
      testing_Log("😎 loadFramework: `" + frameworkName + "` already loaded.");
      return true;
    } else if ([mocha loadFrameworkWithName:frameworkName inDirectory:directory]) {
      testing_Log("✅ loadFramework: `" + frameworkName + "` success!");
      mocha.setValue_forKey_(true, frameworkName);
      return true;
    } else {
      testing_Log("❌ loadFramework: `" + frameworkName + "` failed!: " + directory + ". Please define testing_FrameworkPath if you're trying to @import in a custom plugin");
      return false;
    }
  })();
};

var onSelectionChanged = function(context) {
  testing.onSelectionChanged(context);
};