partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
247 stars 61 forks source link

created class is not called. #285

Closed keeper1030 closed 1 year ago

keeper1030 commented 1 year ago

I would like to make a button to add atomSymbol by referring to the demo code. #209 Even if the code is operated as it is, the controller class that I created will not be called properly. I think it is an error that is reflected in the React js, so I was wondering if I could get a solution or hint. If I write the toolbutton name "specifiedAtomN" incorrectly in the middle to cause an error and correct it again, it will work properly. The controller and action class are properly created in kekule, but they cannot be called.

I think the problem is that the Kekule.Editor.MolSpecifiedAtomIaController has not yet been created properly when performing the createComposerIaControllerActionClass.

  Kekule.Editor.MolSpecifiedAtomIaController = Class.create(
    Kekule.Editor.BaseEditorIaController,
    /** @lends Kekule.Editor.MolSpecifiedAtomIaController# */
    {
      /** @private */
      CLASS_NAME: "Kekule.Editor.MolSpecifiedAtomIaController",
      /** @private */
      initProperties: function () {
        console.log("Active");
        this.defineProp("specifiedAtomSymbol", { dataType: DataType.STRING });
      },
...
  Kekule.Editor.ActionComposerMolSpecifiedAtomController_N =
    Kekule.Editor.createComposerIaControllerActionClass(
      "Kekule.Editor.ActionComposerMolSpecifiedAtomController_N",
      "O",
      "Oxygen atom",
      "MolSpecifiedAtomIaController",
      "MolSpecifiedAtomIaController-N",
      { specifiedAtomSymbol: "N" },
    );
  Kekule.ActionManager.registerNamedActionClass(
    "specifiedAtomN",
    Kekule.Editor.ActionComposerMolSpecifiedAtomController_N,
    Kekule.Editor.BaseEditor,
  );
    composerRef.current
      .setChemToolButtons([
        "specifiedAtomN",
        "specifiedAtomC",
partridgejiang commented 1 year ago

Yes, it should be of that reason. You have to ensure the creation sequence of those routines.