started updating editor code to new js syntax
parent
ff141aab15
commit
817308639a
|
@ -2,6 +2,10 @@
|
||||||
* Copyright (c) 2006-2015, JGraph Ltd
|
* Copyright (c) 2006-2015, JGraph Ltd
|
||||||
* Copyright (c) 2006-2015, Gaudenz Alder
|
* Copyright (c) 2006-2015, Gaudenz Alder
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import mxKeyHandler from "../handler/mxKeyHandler";
|
||||||
|
import mxEventObject from "../util/mxEventObject";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class: mxDefaultKeyHandler
|
* Class: mxDefaultKeyHandler
|
||||||
*
|
*
|
||||||
|
@ -16,7 +20,7 @@
|
||||||
* Bind the delete key to the delete action in an existing editor.
|
* Bind the delete key to the delete action in an existing editor.
|
||||||
*
|
*
|
||||||
* (code)
|
* (code)
|
||||||
* var keyHandler = new mxDefaultKeyHandler(editor);
|
* let keyHandler = new mxDefaultKeyHandler(editor);
|
||||||
* keyHandler.bindAction(46, 'delete');
|
* keyHandler.bindAction(46, 'delete');
|
||||||
* (end)
|
* (end)
|
||||||
*
|
*
|
||||||
|
@ -43,42 +47,40 @@
|
||||||
*
|
*
|
||||||
* editor - Reference to the enclosing <mxEditor>.
|
* editor - Reference to the enclosing <mxEditor>.
|
||||||
*/
|
*/
|
||||||
function mxDefaultKeyHandler(editor)
|
class mxDefaultKeyHandler {
|
||||||
{
|
/**
|
||||||
if (editor != null)
|
* Variable: editor
|
||||||
{
|
*
|
||||||
|
* Reference to the enclosing <mxEditor>.
|
||||||
|
*/
|
||||||
|
editor = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variable: handler
|
||||||
|
*
|
||||||
|
* Holds the <mxKeyHandler> for key event handling.
|
||||||
|
*/
|
||||||
|
handler = null;
|
||||||
|
|
||||||
|
constructor(editor) {
|
||||||
|
if (editor != null) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
this.handler = new mxKeyHandler(editor.graph);
|
this.handler = new mxKeyHandler(editor.graph);
|
||||||
|
|
||||||
// Extends the escape function of the internal key
|
// Extends the escape function of the internal key
|
||||||
// handle to hide the properties dialog and fire
|
// handle to hide the properties dialog and fire
|
||||||
// the escape event via the editor instance
|
// the escape event via the editor instance
|
||||||
var old = this.handler.escape;
|
let old = this.handler.escape;
|
||||||
|
|
||||||
this.handler.escape = function(evt)
|
this.handler.escape = (evt)=>{
|
||||||
{
|
|
||||||
old.apply(this, arguments);
|
old.apply(this, arguments);
|
||||||
editor.hideProperties();
|
editor.hideProperties();
|
||||||
editor.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
|
editor.fireEvent(new mxEventObject(mxEvent.ESCAPE, 'event', evt));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable: editor
|
|
||||||
*
|
|
||||||
* Reference to the enclosing <mxEditor>.
|
|
||||||
*/
|
|
||||||
mxDefaultKeyHandler.prototype.editor = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Variable: handler
|
|
||||||
*
|
|
||||||
* Holds the <mxKeyHandler> for key event handling.
|
|
||||||
*/
|
|
||||||
mxDefaultKeyHandler.prototype.handler = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function: bindAction
|
* Function: bindAction
|
||||||
*
|
*
|
||||||
* Binds the specified keycode to the given action in <editor>. The
|
* Binds the specified keycode to the given action in <editor>. The
|
||||||
|
@ -92,35 +94,31 @@ mxDefaultKeyHandler.prototype.handler = null;
|
||||||
* control - Optional boolean that specifies if control must be pressed.
|
* control - Optional boolean that specifies if control must be pressed.
|
||||||
* Default is false.
|
* Default is false.
|
||||||
*/
|
*/
|
||||||
mxDefaultKeyHandler.prototype.bindAction = function (code, action, control)
|
bindAction=(code, action, control)=>{
|
||||||
{
|
let keyHandler = mxUtils.bind(this, ()=>{
|
||||||
var keyHandler = mxUtils.bind(this, function()
|
|
||||||
{
|
|
||||||
this.editor.execute(action);
|
this.editor.execute(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (control) {
|
||||||
// Binds the function to control-down keycode
|
// Binds the function to control-down keycode
|
||||||
if (control)
|
|
||||||
{
|
|
||||||
this.handler.bindControlKey(code, keyHandler);
|
this.handler.bindControlKey(code, keyHandler);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Binds the function to the normal keycode
|
// Binds the function to the normal keycode
|
||||||
else
|
|
||||||
{
|
|
||||||
this.handler.bindKey(code, keyHandler);
|
this.handler.bindKey(code, keyHandler);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: destroy
|
* Function: destroy
|
||||||
*
|
*
|
||||||
* Destroys the <handler> associated with this object. This does normally
|
* Destroys the <handler> associated with this object. This does normally
|
||||||
* not need to be called, the <handler> is destroyed automatically when the
|
* not need to be called, the <handler> is destroyed automatically when the
|
||||||
* window unloads (in IE) by <mxEditor>.
|
* window unloads (in IE) by <mxEditor>.
|
||||||
*/
|
*/
|
||||||
mxDefaultKeyHandler.prototype.destroy = function ()
|
destroy=()=>{
|
||||||
{
|
|
||||||
this.handler.destroy();
|
this.handler.destroy();
|
||||||
this.handler = null;
|
this.handler = null;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mxDefaultKeyHandler;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* Copyright (c) 2006-2015, JGraph Ltd
|
* Copyright (c) 2006-2015, JGraph Ltd
|
||||||
* Copyright (c) 2006-2015, Gaudenz Alder
|
* Copyright (c) 2006-2015, Gaudenz Alder
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class: mxDefaultPopupMenu
|
* Class: mxDefaultPopupMenu
|
||||||
*
|
*
|
||||||
|
@ -30,28 +32,28 @@
|
||||||
*
|
*
|
||||||
* config - XML node that contains the configuration data.
|
* config - XML node that contains the configuration data.
|
||||||
*/
|
*/
|
||||||
function mxDefaultPopupMenu(config)
|
class mxDefaultPopupMenu {
|
||||||
{
|
/**
|
||||||
this.config = config;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Variable: imageBasePath
|
* Variable: imageBasePath
|
||||||
*
|
*
|
||||||
* Base path for all icon attributes in the config. Default is null.
|
* Base path for all icon attributes in the config. Default is null.
|
||||||
*/
|
*/
|
||||||
mxDefaultPopupMenu.prototype.imageBasePath = null;
|
imageBasePath = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable: config
|
* Variable: config
|
||||||
*
|
*
|
||||||
* XML node used as the description of new menu items. This node is
|
* XML node used as the description of new menu items. This node is
|
||||||
* used in <createMenu> to dynamically create the menu items if their
|
* used in <createMenu> to dynamically create the menu items if their
|
||||||
* respective conditions evaluate to true for the given arguments.
|
* respective conditions evaluate to true for the given arguments.
|
||||||
*/
|
*/
|
||||||
mxDefaultPopupMenu.prototype.config = null;
|
config = null;
|
||||||
|
|
||||||
/**
|
constructor(config) {
|
||||||
|
this.config = config;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
* Function: createMenu
|
* Function: createMenu
|
||||||
*
|
*
|
||||||
* This function is called from <mxEditor> to add items to the
|
* This function is called from <mxEditor> to add items to the
|
||||||
|
@ -151,18 +153,16 @@ mxDefaultPopupMenu.prototype.config = null;
|
||||||
* cell - Optional <mxCell> which is under the mousepointer.
|
* cell - Optional <mxCell> which is under the mousepointer.
|
||||||
* evt - Optional mouse event which triggered the menu.
|
* evt - Optional mouse event which triggered the menu.
|
||||||
*/
|
*/
|
||||||
mxDefaultPopupMenu.prototype.createMenu = function(editor, menu, cell, evt)
|
createMenu=(editor, menu, cell, evt)=>{
|
||||||
{
|
if (this.config != null) {
|
||||||
if (this.config != null)
|
let conditions = this.createConditions(editor, cell, evt);
|
||||||
{
|
let item = this.config.firstChild;
|
||||||
var conditions = this.createConditions(editor, cell, evt);
|
|
||||||
var item = this.config.firstChild;
|
|
||||||
|
|
||||||
this.addItems(editor, menu, cell, evt, conditions, item, null);
|
this.addItems(editor, menu, cell, evt, conditions, item, null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: addItems
|
* Function: addItems
|
||||||
*
|
*
|
||||||
* Recursively adds the given items and all of its children into the given menu.
|
* Recursively adds the given items and all of its children into the given menu.
|
||||||
|
@ -177,26 +177,22 @@ mxDefaultPopupMenu.prototype.createMenu = function(editor, menu, cell, evt)
|
||||||
* item - XML node that represents the current menu item.
|
* item - XML node that represents the current menu item.
|
||||||
* parent - DOM node that represents the parent menu item.
|
* parent - DOM node that represents the parent menu item.
|
||||||
*/
|
*/
|
||||||
mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, conditions, item, parent)
|
addItems=(editor, menu, cell, evt, conditions, item, parent)=>{
|
||||||
{
|
let addSeparator = false;
|
||||||
var addSeparator = false;
|
|
||||||
|
|
||||||
while (item != null)
|
while (item != null) {
|
||||||
{
|
if (item.nodeName === 'add') {
|
||||||
if (item.nodeName == 'add')
|
let condition = item.getAttribute('if');
|
||||||
{
|
|
||||||
var condition = item.getAttribute('if');
|
|
||||||
|
|
||||||
if (condition == null || conditions[condition])
|
if (condition == null || conditions[condition]) {
|
||||||
{
|
let as = item.getAttribute('as');
|
||||||
var as = item.getAttribute('as');
|
|
||||||
as = mxResources.get(as) || as;
|
as = mxResources.get(as) || as;
|
||||||
var funct = mxUtils.eval(mxUtils.getTextContent(item));
|
let funct = mxUtils.eval(mxUtils.getTextContent(item));
|
||||||
var action = item.getAttribute('action');
|
let action = item.getAttribute('action');
|
||||||
var icon = item.getAttribute('icon');
|
let icon = item.getAttribute('icon');
|
||||||
var iconCls = item.getAttribute('iconCls');
|
let iconCls = item.getAttribute('iconCls');
|
||||||
var enabledCond = item.getAttribute('enabled-if');
|
let enabledCond = item.getAttribute('enabled-if');
|
||||||
var enabled = enabledCond == null || conditions[enabledCond];
|
let enabled = enabledCond == null || conditions[enabledCond];
|
||||||
|
|
||||||
if (addSeparator)
|
if (addSeparator)
|
||||||
{
|
{
|
||||||
|
@ -209,20 +205,18 @@ mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, condit
|
||||||
icon = this.imageBasePath + icon;
|
icon = this.imageBasePath + icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
var row = this.addAction(menu, editor, as, icon, funct, action, cell, parent, iconCls, enabled);
|
let row = this.addAction(menu, editor, as, icon, funct, action, cell, parent, iconCls, enabled);
|
||||||
this.addItems(editor, menu, cell, evt, conditions, item.firstChild, row);
|
this.addItems(editor, menu, cell, evt, conditions, item.firstChild, row);
|
||||||
}
|
}
|
||||||
}
|
} else if (item.nodeName === 'separator') {
|
||||||
else if (item.nodeName == 'separator')
|
|
||||||
{
|
|
||||||
addSeparator = true;
|
addSeparator = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = item.nextSibling;
|
item = item.nextSibling;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: addAction
|
* Function: addAction
|
||||||
*
|
*
|
||||||
* Helper method to bind an action to a new menu item.
|
* Helper method to bind an action to a new menu item.
|
||||||
|
@ -243,64 +237,57 @@ mxDefaultPopupMenu.prototype.addItems = function(editor, menu, cell, evt, condit
|
||||||
* enabled - Optional boolean that specifies if the menu item is enabled.
|
* enabled - Optional boolean that specifies if the menu item is enabled.
|
||||||
* Default is true.
|
* Default is true.
|
||||||
*/
|
*/
|
||||||
mxDefaultPopupMenu.prototype.addAction = function(menu, editor, lab, icon, funct, action, cell, parent, iconCls, enabled)
|
addAction=(menu, editor, lab, icon, funct, action, cell, parent, iconCls, enabled)=>{
|
||||||
{
|
let clickHandler=(evt)=>{
|
||||||
var clickHandler = function(evt)
|
if (typeof(funct) == 'function') {
|
||||||
{
|
|
||||||
if (typeof(funct) == 'function')
|
|
||||||
{
|
|
||||||
funct.call(editor, editor, cell, evt);
|
funct.call(editor, editor, cell, evt);
|
||||||
}
|
}
|
||||||
|
if (action != null) {
|
||||||
if (action != null)
|
|
||||||
{
|
|
||||||
editor.execute(action, cell, evt);
|
editor.execute(action, cell, evt);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return menu.addItem(lab, icon, clickHandler, parent, iconCls, enabled);
|
return menu.addItem(lab, icon, clickHandler, parent, iconCls, enabled);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: createConditions
|
* Function: createConditions
|
||||||
*
|
*
|
||||||
* Evaluates the default conditions for the given context.
|
* Evaluates the default conditions for the given context.
|
||||||
*/
|
*/
|
||||||
mxDefaultPopupMenu.prototype.createConditions = function(editor, cell, evt)
|
createConditions=(editor, cell, evt)=>{
|
||||||
{
|
|
||||||
// Creates array with conditions
|
// Creates array with conditions
|
||||||
var model = editor.graph.getModel();
|
let model = editor.graph.getModel();
|
||||||
var childCount = model.getChildCount(cell);
|
let childCount = model.getChildCount(cell);
|
||||||
|
|
||||||
// Adds some frequently used conditions
|
// Adds some frequently used conditions
|
||||||
var conditions = [];
|
let conditions = [];
|
||||||
conditions['nocell'] = cell == null;
|
conditions['nocell'] = cell == null;
|
||||||
conditions['ncells'] = editor.graph.getSelectionCount() > 1;
|
conditions['ncells'] = editor.graph.getSelectionCount() > 1;
|
||||||
conditions['notRoot'] = model.getRoot() !=
|
conditions['notRoot'] = model.getRoot() != model.getParent(editor.graph.getDefaultParent());
|
||||||
model.getParent(editor.graph.getDefaultParent());
|
|
||||||
conditions['cell'] = cell != null;
|
conditions['cell'] = cell != null;
|
||||||
|
|
||||||
var isCell = cell != null && editor.graph.getSelectionCount() == 1;
|
let isCell = cell != null && editor.graph.getSelectionCount() === 1;
|
||||||
conditions['nonEmpty'] = isCell && childCount > 0;
|
conditions['nonEmpty'] = isCell && childCount > 0;
|
||||||
conditions['expandable'] = isCell && editor.graph.isCellFoldable(cell, false);
|
conditions['expandable'] = isCell && editor.graph.isCellFoldable(cell, false);
|
||||||
conditions['collapsable'] = isCell && editor.graph.isCellFoldable(cell, true);
|
conditions['collapsable'] = isCell && editor.graph.isCellFoldable(cell, true);
|
||||||
conditions['validRoot'] = isCell && editor.graph.isValidRoot(cell);
|
conditions['validRoot'] = isCell && editor.graph.isValidRoot(cell);
|
||||||
conditions['emptyValidRoot'] = conditions['validRoot'] && childCount == 0;
|
conditions['emptyValidRoot'] = conditions['validRoot'] && childCount === 0;
|
||||||
conditions['swimlane'] = isCell && editor.graph.isSwimlane(cell);
|
conditions['swimlane'] = isCell && editor.graph.isSwimlane(cell);
|
||||||
|
|
||||||
// Evaluates dynamic conditions from config file
|
// Evaluates dynamic conditions from config file
|
||||||
var condNodes = this.config.getElementsByTagName('condition');
|
let condNodes = this.config.getElementsByTagName('condition');
|
||||||
|
|
||||||
for (var i=0; i<condNodes.length; i++)
|
for (let i=0; i<condNodes.length; i++) {
|
||||||
{
|
let funct = mxUtils.eval(mxUtils.getTextContent(condNodes[i]));
|
||||||
var funct = mxUtils.eval(mxUtils.getTextContent(condNodes[i]));
|
let name = condNodes[i].getAttribute('name');
|
||||||
var name = condNodes[i].getAttribute('name');
|
|
||||||
|
|
||||||
if (name != null && typeof(funct) == 'function')
|
if (name != null && typeof(funct) == 'function') {
|
||||||
{
|
|
||||||
conditions[name] = funct(editor, cell, evt);
|
conditions[name] = funct(editor, cell, evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return conditions;
|
return conditions;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mxDefaultPopupMenu;
|
||||||
|
|
Loading…
Reference in New Issue