mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-25 15:47:55 +01:00
Code clean up.
This commit is contained in:
parent
b84f0b6142
commit
4851da1f18
@ -24,9 +24,9 @@ import Topic from './Topic';
|
|||||||
export type EventCallback = (event?: Event) => void;
|
export type EventCallback = (event?: Event) => void;
|
||||||
class DesignerKeyboard extends Keyboard {
|
class DesignerKeyboard extends Keyboard {
|
||||||
// eslint-disable-next-line no-use-before-define
|
// eslint-disable-next-line no-use-before-define
|
||||||
static _instance: DesignerKeyboard;
|
private static _instance: DesignerKeyboard;
|
||||||
|
|
||||||
static _disabled: boolean;
|
private static _disabled: boolean;
|
||||||
|
|
||||||
constructor(designer: Designer) {
|
constructor(designer: Designer) {
|
||||||
super();
|
super();
|
||||||
@ -35,25 +35,21 @@ class DesignerKeyboard extends Keyboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addShortcut(shortcuts: string[] | string, callback: EventCallback): void {
|
addShortcut(shortcuts: string[] | string, callback: EventCallback): void {
|
||||||
super.addShortcut(shortcuts, (e: Event) => {
|
super.addShortcut(shortcuts, () => {
|
||||||
if (DesignerKeyboard.isDisabled()) {
|
if (DesignerKeyboard.isDisabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callback(e);
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _registerEvents(designer: Designer) {
|
private _registerEvents(designer: Designer) {
|
||||||
// Try with the keyboard ..
|
// Try with the keyboard ..
|
||||||
const model = designer.getModel();
|
const model = designer.getModel();
|
||||||
this.addShortcut('backspace', () => { designer.deleteSelectedEntities(); });
|
this.addShortcut(['backspace', 'del'], () => { designer.deleteSelectedEntities(); });
|
||||||
|
|
||||||
this.addShortcut('space', () => { designer.shrinkSelectedBranch(); });
|
this.addShortcut('space', () => { designer.shrinkSelectedBranch(); });
|
||||||
|
|
||||||
this.addShortcut('del', () => { designer.deleteSelectedEntities(); });
|
|
||||||
|
|
||||||
this.addShortcut('enter', () => { designer.createSiblingForSelectedNode(); });
|
|
||||||
|
|
||||||
this.addShortcut('f2', () => {
|
this.addShortcut('f2', () => {
|
||||||
const node = model.selectedTopic();
|
const node = model.selectedTopic();
|
||||||
if (node) {
|
if (node) {
|
||||||
@ -61,14 +57,14 @@ class DesignerKeyboard extends Keyboard {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addShortcut('insert', () => { designer.createChildForSelectedNode(); });
|
this.addShortcut(['insert', 'tab', 'meta+enter'], () => { designer.createChildForSelectedNode(); });
|
||||||
|
|
||||||
this.addShortcut('tab', () => { designer.createChildForSelectedNode(); });
|
this.addShortcut('enter', () => { designer.createSiblingForSelectedNode(); });
|
||||||
|
|
||||||
this.addShortcut('meta+enter', () => { designer.createChildForSelectedNode(); });
|
|
||||||
|
|
||||||
this.addShortcut(['ctrl+z', 'meta+z'], () => { designer.undo(); });
|
this.addShortcut(['ctrl+z', 'meta+z'], () => { designer.undo(); });
|
||||||
|
|
||||||
|
this.addShortcut(['ctrl+shift+z', 'meta+shift+z'], () => { designer.redo(); });
|
||||||
|
|
||||||
this.addShortcut(['ctrl+c', 'meta+c'], () => { designer.copyToClipboard(); });
|
this.addShortcut(['ctrl+c', 'meta+c'], () => { designer.copyToClipboard(); });
|
||||||
|
|
||||||
this.addShortcut(['ctrl+l', 'meta+l'], () => { designer.addLink(); });
|
this.addShortcut(['ctrl+l', 'meta+l'], () => { designer.addLink(); });
|
||||||
@ -77,8 +73,6 @@ class DesignerKeyboard extends Keyboard {
|
|||||||
|
|
||||||
this.addShortcut(['ctrl+v', 'meta+v'], () => { designer.pasteClipboard(); });
|
this.addShortcut(['ctrl+v', 'meta+v'], () => { designer.pasteClipboard(); });
|
||||||
|
|
||||||
this.addShortcut(['ctrl+shift+z', 'meta+shift+z'], () => { designer.redo(); });
|
|
||||||
|
|
||||||
this.addShortcut(['ctrl+a', 'meta+a'], () => { designer.selectAll(); });
|
this.addShortcut(['ctrl+a', 'meta+a'], () => { designer.selectAll(); });
|
||||||
|
|
||||||
this.addShortcut(['ctrl+b', 'meta+b'], () => { designer.changeFontWeight(); });
|
this.addShortcut(['ctrl+b', 'meta+b'], () => { designer.changeFontWeight(); });
|
||||||
@ -281,75 +275,17 @@ class DesignerKeyboard extends Keyboard {
|
|||||||
this._disabled = false;
|
this._disabled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static pause = function pause() {
|
static pause() {
|
||||||
this._disabled = true;
|
this._disabled = true;
|
||||||
};
|
}
|
||||||
|
|
||||||
static resume = function resume() {
|
static resume() {
|
||||||
this._disabled = false;
|
this._disabled = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
static isDisabled = function isDisabled() {
|
static isDisabled() {
|
||||||
return this._disabled;
|
return this._disabled;
|
||||||
};
|
}
|
||||||
|
|
||||||
static specialKeys = {
|
|
||||||
8: 'backspace',
|
|
||||||
9: 'tab',
|
|
||||||
10: 'return',
|
|
||||||
13: 'enter',
|
|
||||||
16: 'shift',
|
|
||||||
17: 'ctrl',
|
|
||||||
18: 'alt',
|
|
||||||
19: 'pause',
|
|
||||||
20: 'capslock',
|
|
||||||
27: 'esc',
|
|
||||||
32: 'space',
|
|
||||||
33: 'pageup',
|
|
||||||
34: 'pagedown',
|
|
||||||
35: 'end',
|
|
||||||
36: 'home',
|
|
||||||
37: 'left',
|
|
||||||
38: 'up',
|
|
||||||
39: 'right',
|
|
||||||
40: 'down',
|
|
||||||
45: 'insert',
|
|
||||||
46: 'del',
|
|
||||||
96: '0',
|
|
||||||
97: '1',
|
|
||||||
98: '2',
|
|
||||||
99: '3',
|
|
||||||
100: '4',
|
|
||||||
101: '5',
|
|
||||||
102: '6',
|
|
||||||
103: '7',
|
|
||||||
104: '8',
|
|
||||||
105: '9',
|
|
||||||
106: '*',
|
|
||||||
107: '+',
|
|
||||||
109: '-',
|
|
||||||
110: '.',
|
|
||||||
111: '/',
|
|
||||||
112: 'f1',
|
|
||||||
113: 'f2',
|
|
||||||
114: 'f3',
|
|
||||||
115: 'f4',
|
|
||||||
116: 'f5',
|
|
||||||
117: 'f6',
|
|
||||||
118: 'f7',
|
|
||||||
119: 'f8',
|
|
||||||
120: 'f9',
|
|
||||||
121: 'f10',
|
|
||||||
122: 'f11',
|
|
||||||
123: 'f12',
|
|
||||||
144: 'numlock',
|
|
||||||
145: 'scroll',
|
|
||||||
186: ';',
|
|
||||||
191: '/',
|
|
||||||
220: '\\',
|
|
||||||
222: "'",
|
|
||||||
224: 'meta',
|
|
||||||
};
|
|
||||||
|
|
||||||
static getInstance() {
|
static getInstance() {
|
||||||
return this._instance;
|
return this._instance;
|
||||||
|
@ -59,27 +59,15 @@ class DesignerModel extends Events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterSelectedTopics(): Topic[] {
|
filterSelectedTopics(): Topic[] {
|
||||||
const result: Topic[] = [];
|
return this._topics.filter((t) => t.isOnFocus());
|
||||||
for (let i = 0; i < this._topics.length; i++) {
|
|
||||||
if (this._topics[i].isOnFocus()) {
|
|
||||||
result.push(this._topics[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filterSelectedRelationships(): Relationship[] {
|
filterSelectedRelationships(): Relationship[] {
|
||||||
const result:Relationship[] = [];
|
return this._relationships.filter((r) => r.isOnFocus());
|
||||||
for (let i = 0; i < this._relationships.length; i++) {
|
|
||||||
if (this._relationships[i].isOnFocus()) {
|
|
||||||
result.push(this._relationships[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getEntities(): (Relationship | Topic)[] {
|
getEntities(): (Relationship | Topic)[] {
|
||||||
let result:(Relationship|Topic)[] = [];
|
let result: (Relationship | Topic)[] = [];
|
||||||
result = result.concat(this._topics);
|
result = result.concat(this._topics);
|
||||||
result = result.concat(this._relationships);
|
result = result.concat(this._relationships);
|
||||||
return result;
|
return result;
|
||||||
@ -133,15 +121,7 @@ class DesignerModel extends Events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findTopicById(id: number): Topic | undefined {
|
findTopicById(id: number): Topic | undefined {
|
||||||
let result: Topic | undefined;
|
return this._topics.find((t) => t.getId() === id);
|
||||||
for (let i = 0; i < this._topics.length; i++) {
|
|
||||||
const topic = this._topics[i];
|
|
||||||
if (topic.getId() === id) {
|
|
||||||
result = topic;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user