Fix missing method error

This commit is contained in:
Paulo Gustavo Veiga 2022-02-03 22:19:18 -08:00
parent 8dbd6a92b7
commit c58f434509
3 changed files with 95 additions and 76 deletions

View File

@ -354,6 +354,20 @@ class Designer extends Events {
} }
} }
shrinkSelectedBranch() {
const nodes = this.getModel().filterSelectedTopics();
if (nodes.length <= 0 || nodes.length !== 1) {
// If there are more than one node selected,
$notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED_COLLAPSE'));
return;
}
// Execute event ...
const topic = nodes[0];
if (topic.getType() !== 'CentralTopic') {
this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken());
}
}
copyToClipboard(): void { copyToClipboard(): void {
let topics = this.getModel().filterSelectedTopics(); let topics = this.getModel().filterSelectedTopics();
if (topics.length <= 0) { if (topics.length <= 0) {

View File

@ -18,15 +18,19 @@
import $ from 'jquery'; import $ from 'jquery';
import { $assert } from '@wisemapping/core-js'; import { $assert } from '@wisemapping/core-js';
import Keyboard from './Keyboard'; import Keyboard from './Keyboard';
import { Designer } from '..';
import Topic from './Topic';
class DesignerKeyboard extends Keyboard { class DesignerKeyboard extends Keyboard {
constructor(designer) { static _instance: any;
super(designer);
constructor(designer: Designer) {
super();
$assert(designer, 'designer can not be null'); $assert(designer, 'designer can not be null');
this._registerEvents(designer); this._registerEvents(designer);
} }
_registerEvents(designer) { private _registerEvents(designer: Designer) {
// Try with the keyboard .. // Try with the keyboard ..
const model = designer.getModel(); const model = designer.getModel();
this.addShortcut( this.addShortcut(
@ -250,8 +254,9 @@ class DesignerKeyboard extends Keyboard {
keyCode = event.keyCode; keyCode = event.keyCode;
} }
const specialKey = $.hotkeys.specialKeys[keyCode]; const jq: any = $;
if (['enter', 'capslock'].indexOf(specialKey) === -1 && !$.hotkeys.shiftNums[keyCode]) { const specialKey = jq.hotkeys.specialKeys[keyCode];
if (['enter', 'capslock'].indexOf(specialKey) === -1 && !jq.hotkeys.shiftNums[keyCode]) {
const nodes = designer.getModel().filterSelectedTopics(); const nodes = designer.getModel().filterSelectedTopics();
if (nodes.length > 0) { if (nodes.length > 0) {
// If a modifier is press, the key selected must be ignored. // If a modifier is press, the key selected must be ignored.
@ -266,7 +271,7 @@ class DesignerKeyboard extends Keyboard {
}); });
} }
_goToBrother(designer, node, direction) { private _goToBrother(designer: Designer, node: Topic, direction) {
const parent = node.getParent(); const parent = node.getParent();
if (parent) { if (parent) {
const brothers = parent.getChildren(); const brothers = parent.getChildren();
@ -305,7 +310,7 @@ class DesignerKeyboard extends Keyboard {
} }
} }
_goToSideChild(designer, node, side) { private _goToSideChild(designer: Designer, node: Topic, side: 'LEFT' | 'RIGHT') {
const children = node.getChildren(); const children = node.getChildren();
if (children.length > 0) { if (children.length > 0) {
let target = children[0]; let target = children[0];
@ -331,14 +336,14 @@ class DesignerKeyboard extends Keyboard {
} }
} }
_goToParent(designer, node) { private _goToParent(designer: Designer, node: Topic) {
const parent = node.getParent(); const parent = node.getParent();
if (parent) { if (parent) {
this._goToNode(designer, parent); this._goToNode(designer, parent);
} }
} }
_goToChild(designer, node) { private _goToChild(designer, node) {
const children = node.getChildren(); const children = node.getChildren();
if (children.length > 0) { if (children.length > 0) {
let target = children[0]; let target = children[0];
@ -354,16 +359,19 @@ class DesignerKeyboard extends Keyboard {
} }
} }
_goToNode(designer, node) { private _goToNode(designer: Designer, node: Topic) {
// First deselect all the nodes ... // First deselect all the nodes ...
designer.deselectAll(); designer.deselectAll();
// Give focus to the selected node.... // Give focus to the selected node....
node.setOnFocus(true); node.setOnFocus(true);
} }
}
DesignerKeyboard.specialKeys = { static register = function register(designer: Designer) {
this._instance = new DesignerKeyboard(designer);
};
static specialKeys = {
8: 'backspace', 8: 'backspace',
9: 'tab', 9: 'tab',
10: 'return', 10: 'return',
@ -421,12 +429,9 @@ DesignerKeyboard.specialKeys = {
224: 'meta', 224: 'meta',
}; };
DesignerKeyboard.register = function register(designer) { static getInstance() {
this._instance = new DesignerKeyboard(designer);
};
DesignerKeyboard.getInstance = function getInstance() {
return this._instance; return this._instance;
}; }
}
export default DesignerKeyboard; export default DesignerKeyboard;