123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- class DisabledCells {
- constructor() {
- this.disabledCells = new Set();
- }
- add(cell) {
- this.disabledCells.add(cell);
- }
- delete(cell) {
- this.disabledCells.delete(cell);
- }
- install(graph) {
- const self = this;
- // part #1: Intercepting mxGraph.fireMouseEvent
- const oldFireMouseEvent = graph.fireMouseEvent;
- graph.fireMouseEvent = function(evtName, me, sender) {
- if (me.state && self.disabledCells.has(me.state.cell.id)) {
- // clicked shape is disabled
- return;
- }
- oldFireMouseEvent.apply(this, arguments);
- }
- // part #2: Ignore double clicks on disabled cells
- const oldDblClick = graph.dblClick;
- graph.dblClick = function(evt, cell) {
- if (cell && self.disabledCells.has(cell.id)) {
- // clicked shape is disabled
- return;
- }
- oldDblClick.apply(this, arguments);
- }
- // part #3: Protect disabled cells from ever being selected
- const oldMxSelectionChange = mxSelectionChange; // override constructor :)
- mxSelectionChange = function(selectionModel, added, removed) {
- oldMxSelectionChange.apply(this, arguments);
- if (this.added) {
- this.added = this.added.filter(cell => !self.disabledCells.has(cell.id));
- }
- }
- mxSelectionChange.prototype = oldMxSelectionChange.prototype;
- }
- }
- module.exports = { DisabledCells };
|