Open rygler opened 6 years ago
@rygler Could you please describe your scenario in more details?
Thank you, Andrew
@andrewtelnov Sure.
Currently, a default element operation is to copy a given element to the Toolbox. However, there is no way to remove that element from the Toolbox (unless the Toolbox's copiedItemMaxCount
property is reached, and that copied element happens to be the one that is replaced).
I added a custom element operation to enable the user to remove the specified element from the Toolbox like so:
editor.onDefineElementMenuItems.add((editor, options) => {
options.items.splice(1, 0, { // Inserted in position after the add operation
text: 'Remove element from toolbox',
onClick: (obj) => {
const isItemRemoved = editor.toolbox.removeItem(obj.name)
if (!isItemRemoved) {
// Item was not in the toolbox. Either ignore or display error.
}
},
});
});
However, I do not want to always enable this operation. I would like to only enable it if the element is already copied into the Toolbox. I would like to be able to selectively show this custom remove operation depending on whether the item is in the Toolbox in a manner such as the following:
editor.onElementAllowOperations.add((editor, options) => {
if (indexOf(options.obj.name) < 0) { // assuming I have an implementation of indexOf
// Somehow set my custom remove operation to be disabled
// Maybe something like this: options['someIdentifier'].allowed = false;
}
});
What do you think?
@rygler This scenario has the right to exists. It is a valid one. Let us to think how we may implement it.
Thank you, Andrew
Are you requesting a feature, reporting a bug or ask a question?
Feature
What is the current behavior?
You can add custom operations on elements using
editor.onDefineElementMenuItems
and adding them tooptions.items
, as implemented in #140 .You can disable default operations using
onElementAllowOperations
and setting the appropriate operation inoptions
to false, as implemented in #249 . However, there is no way to override for custom operations.What is the expected behavior?
The ability to disable/enable custom operations on elements.
Perhaps this can be done by giving a unique key when adding custom operations in
onDefineElementMenuItems
and be given access to them throughoptions
inonElementAllowOperations
.Specify your