/** * Copyright (c) 2006-2012, JGraph Ltd */ /** * Constructs a new graph editor */ Menus = function(editorUi) { this.editorUi = editorUi; this.menus = new Object(); this.init(); // Pre-fetches checkmark image if (!mxClient.IS_SVG) { new Image().src = this.checkmarkImage; } }; /** * Sets the default font family. */ Menus.prototype.defaultFont = 'Helvetica'; /** * Sets the default font size. */ Menus.prototype.defaultFontSize = '12'; /** * Sets the default font size. */ Menus.prototype.defaultMenuItems = ['file', 'edit', 'view', 'arrange', 'extras', 'help']; /** * Adds the label menu items to the given menu and parent. */ Menus.prototype.defaultFonts = ['Helvetica', 'Verdana', 'Times New Roman', 'Garamond', 'Comic Sans MS', 'Courier New', 'Georgia', 'Lucida Console', 'Tahoma']; /** * Adds the label menu items to the given menu and parent. */ Menus.prototype.autoPopup = true; /** * Adds the label menu items to the given menu and parent. */ Menus.prototype.init = function() { var ui = this.editorUi; var graph = ui.editor.graph; var isGraphEnabled = mxUtils.bind(graph, graph.isEnabled); this.customFonts = []; this.customFontSizes = []; this.put('fontFamily', new Menu(mxUtils.bind(this, function(menu, parent) { var addItem = mxUtils.bind(this, function(fontFamily) { var tr = this.styleChange(menu, fontFamily, [mxConstants.STYLE_FONTFAMILY], [fontFamily], null, parent, function() { document.execCommand('fontname', false, fontFamily); ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_FONTFAMILY], 'values', [fontFamily], 'cells', [graph.cellEditor.getEditingCell()])); }, function() { graph.updateLabelElements(graph.getSelectionCells(), function(elt) { elt.removeAttribute('face'); elt.style.fontFamily = null; if (elt.nodeName == 'PRE') { graph.replaceElement(elt, 'div'); } }); }); tr.firstChild.nextSibling.style.fontFamily = fontFamily; }); for (var i = 0; i < this.defaultFonts.length; i++) { addItem(this.defaultFonts[i]); } menu.addSeparator(parent); if (this.customFonts.length > 0) { for (var i = 0; i < this.customFonts.length; i++) { addItem(this.customFonts[i]); } menu.addSeparator(parent); menu.addItem(mxResources.get('reset'), null, mxUtils.bind(this, function() { this.customFonts = []; this.editorUi.fireEvent(new mxEventObject('customFontsChanged')); }), parent); menu.addSeparator(parent); } this.promptChange(menu, mxResources.get('custom') + '...', '', mxConstants.DEFAULT_FONTFAMILY, mxConstants.STYLE_FONTFAMILY, parent, true, mxUtils.bind(this, function(newValue) { if (mxUtils.indexOf(this.customFonts, newValue) < 0) { this.customFonts.push(newValue); this.editorUi.fireEvent(new mxEventObject('customFontsChanged')); } })); }))); this.put('formatBlock', new Menu(mxUtils.bind(this, function(menu, parent) { function addItem(label, tag) { return menu.addItem(label, null, mxUtils.bind(this, function() { // TODO: Check if visible if (graph.cellEditor.textarea != null) { graph.cellEditor.textarea.focus(); document.execCommand('formatBlock', false, '<' + tag + '>'); } }), parent); }; addItem(mxResources.get('normal'), 'p'); addItem('', 'h1').firstChild.nextSibling.innerHTML = '
' + mxResources.get('formatted') + ''; addItem('', 'blockquote').firstChild.nextSibling.innerHTML = '
' + mxResources.get('blockquote') + ''; }))); this.put('fontSize', new Menu(mxUtils.bind(this, function(menu, parent) { var sizes = [6, 8, 9, 10, 11, 12, 14, 18, 24, 36, 48, 72]; if (mxUtils.indexOf(sizes, this.defaultFontSize) < 0) { sizes.push(this.defaultFontSize); sizes.sort(function(a, b) { return a - b; }); } var setFontSize = mxUtils.bind(this, function(fontSize) { if (graph.cellEditor.textarea != null) { // Creates an element with arbitrary size 3 document.execCommand('fontSize', false, '3'); // Changes the css font size of the first font element inside the in-place editor with size 3 // hopefully the above element that we've just created. LATER: Check for new element using // previous result of getElementsByTagName (see other actions) var elts = graph.cellEditor.textarea.getElementsByTagName('font'); for (var i = 0; i < elts.length; i++) { if (elts[i].getAttribute('size') == '3') { elts[i].removeAttribute('size'); elts[i].style.fontSize = fontSize + 'px'; break; } } ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_FONTSIZE], 'values', [fontSize], 'cells', [graph.cellEditor.getEditingCell()])); } }); var addItem = mxUtils.bind(this, function(fontSize) { this.styleChange(menu, fontSize, [mxConstants.STYLE_FONTSIZE], [fontSize], null, parent, function() { setFontSize(fontSize); }); }); for (var i = 0; i < sizes.length; i++) { addItem(sizes[i]); } menu.addSeparator(parent); if (this.customFontSizes.length > 0) { var counter = 0; for (var i = 0; i < this.customFontSizes.length; i++) { if (mxUtils.indexOf(sizes, this.customFontSizes[i]) < 0) { addItem(this.customFontSizes[i]); counter++; } } if (counter > 0) { menu.addSeparator(parent); } menu.addItem(mxResources.get('reset'), null, mxUtils.bind(this, function() { this.customFontSizes = []; }), parent); menu.addSeparator(parent); } var selState = null; this.promptChange(menu, mxResources.get('custom') + '...', '(' + mxResources.get('points') + ')', this.defaultFontSize, mxConstants.STYLE_FONTSIZE, parent, true, mxUtils.bind(this, function(newValue) { if (selState != null && graph.cellEditor.textarea != null) { graph.cellEditor.textarea.focus(); graph.cellEditor.restoreSelection(selState); } if (newValue != null && newValue.length > 0) { this.customFontSizes.push(newValue); setFontSize(newValue); } }), null, function() { selState = graph.cellEditor.saveSelection(); return false; }); }))); this.put('direction', new Menu(mxUtils.bind(this, function(menu, parent) { menu.addItem(mxResources.get('flipH'), null, function() { graph.toggleCellStyles(mxConstants.STYLE_FLIPH, false); }, parent); menu.addItem(mxResources.get('flipV'), null, function() { graph.toggleCellStyles(mxConstants.STYLE_FLIPV, false); }, parent); this.addMenuItems(menu, ['-', 'rotation'], parent); }))); this.put('align', new Menu(mxUtils.bind(this, function(menu, parent) { var ss = this.editorUi.getSelectionState(); var enabled = ss.vertices.length > 1; menu.addItem(mxResources.get('leftAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_LEFT); }, parent, null, enabled); menu.addItem(mxResources.get('center'), null, function() { graph.alignCells(mxConstants.ALIGN_CENTER); }, parent, null, enabled); menu.addItem(mxResources.get('rightAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_RIGHT); }, parent, null, enabled); menu.addSeparator(parent); menu.addItem(mxResources.get('topAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_TOP); }, parent, null, enabled); menu.addItem(mxResources.get('middle'), null, function() { graph.alignCells(mxConstants.ALIGN_MIDDLE); }, parent, null, enabled); menu.addItem(mxResources.get('bottomAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_BOTTOM); }, parent, null, enabled); this.addMenuItems(menu, ['-', 'snapToGrid'], parent); }))); this.put('distribute', new Menu(mxUtils.bind(this, function(menu, parent) { menu.addItem(mxResources.get('horizontal'), null, function() { graph.distributeCells(true); }, parent); menu.addItem(mxResources.get('vertical'), null, function() { graph.distributeCells(false); }, parent); menu.addSeparator(parent); this.addSubmenu('distributeSpacing', menu, parent, mxResources.get('spacing')); }))); this.put('distributeSpacing', new Menu(mxUtils.bind(this, function(menu, parent) { menu.addItem(mxResources.get('horizontal'), null, function() { graph.distributeCells(true, null, true); }, parent); menu.addItem(mxResources.get('vertical'), null, function() { graph.distributeCells(false, null, true); }, parent); }))); this.put('line', new Menu(mxUtils.bind(this, function(menu, parent) { var state = graph.view.getState(graph.getSelectionCell()); if (state != null) { var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE); if (shape != 'arrow') { this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], [null, null, null], 'geIcon geSprite geSprite-straight', parent, true).setAttribute('title', mxResources.get('straight')); this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['orthogonalEdgeStyle', null, null], 'geIcon geSprite geSprite-orthogonal', parent, true).setAttribute('title', mxResources.get('orthogonal')); this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['elbowEdgeStyle', null, null, null], 'geIcon geSprite geSprite-horizontalelbow', parent, true).setAttribute('title', mxResources.get('simple')); this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['elbowEdgeStyle', 'vertical', null, null], 'geIcon geSprite geSprite-verticalelbow', parent, true).setAttribute('title', mxResources.get('simple')); this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['isometricEdgeStyle', null, null, null], 'geIcon geSprite geSprite-horizontalisometric', parent, true).setAttribute('title', mxResources.get('isometric')); this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['isometricEdgeStyle', 'vertical', null, null], 'geIcon geSprite geSprite-verticalisometric', parent, true).setAttribute('title', mxResources.get('isometric')); if (shape == 'connector') { this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['orthogonalEdgeStyle', '1', null], 'geIcon geSprite geSprite-curved', parent, true).setAttribute('title', mxResources.get('curved')); } this.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['entityRelationEdgeStyle', null, null], 'geIcon geSprite geSprite-entity', parent, true).setAttribute('title', mxResources.get('entityRelation')); } menu.addSeparator(parent); this.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], [null, null, null, null], 'geIcon geSprite geSprite-connection', parent, null, null, true).setAttribute('title', mxResources.get('line')); this.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], ['link', null, null, null], 'geIcon geSprite geSprite-linkedge', parent, null, null, true).setAttribute('title', mxResources.get('link')); this.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], ['flexArrow', null, null, null], 'geIcon geSprite geSprite-arrow', parent, null, null, true).setAttribute('title', mxResources.get('arrow')); this.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], ['arrow', null, null, null], 'geIcon geSprite geSprite-simplearrow', parent, null, null, true).setAttribute('title', mxResources.get('simpleArrow')); } }))); this.put('layout', new Menu(mxUtils.bind(this, function(menu, parent) { var promptSpacing = mxUtils.bind(this, function(defaultValue, fn) { this.editorUi.prompt(mxResources.get('spacing'), defaultValue, fn); }); var runTreeLayout = mxUtils.bind(this, function(layout) { this.editorUi.tryAndHandle(mxUtils.bind(this, function() { var tmp = graph.getSelectionCell(); var roots = null; if (tmp == null || graph.getModel().getChildCount(tmp) == 0) { if (graph.getModel().getEdgeCount(tmp) == 0) { roots = graph.findTreeRoots(graph.getDefaultParent()); } } else { roots = graph.findTreeRoots(tmp); } if (roots != null && roots.length > 0) { tmp = roots[0]; } if (tmp != null) { this.editorUi.executeLayout(function() { layout.execute(graph.getDefaultParent(), tmp); if (!graph.isSelectionEmpty()) { tmp = graph.getModel().getParent(tmp); if (graph.getModel().isVertex(tmp)) { graph.updateGroupBounds([tmp], graph.gridSize * 2, true); } } }, true); } })); }); menu.addItem(mxResources.get('horizontalFlow'), null, mxUtils.bind(this, function() { this.editorUi.tryAndHandle(mxUtils.bind(this, function() { var layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST); this.editorUi.executeLayout(function() { var selectionCells = graph.getSelectionCells(); layout.execute(graph.getDefaultParent(), selectionCells.length == 0 ? null : selectionCells); }, true); })); }), parent); menu.addItem(mxResources.get('verticalFlow'), null, mxUtils.bind(this, function() { this.editorUi.tryAndHandle(mxUtils.bind(this, function() { var layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH); this.editorUi.executeLayout(function() { var selectionCells = graph.getSelectionCells(); layout.execute(graph.getDefaultParent(), selectionCells.length == 0 ? null : selectionCells); }, true); })); }), parent); menu.addSeparator(parent); menu.addItem(mxResources.get('horizontalTree'), null, mxUtils.bind(this, function() { var layout = new mxCompactTreeLayout(graph, true); layout.edgeRouting = false; layout.levelDistance = 30; promptSpacing(layout.levelDistance, mxUtils.bind(this, function(spacing) { if (!isNaN(spacing)) { layout.levelDistance = spacing; runTreeLayout(layout); } })); }), parent); menu.addItem(mxResources.get('verticalTree'), null, mxUtils.bind(this, function() { var layout = new mxCompactTreeLayout(graph, false); layout.edgeRouting = false; layout.levelDistance = 30; promptSpacing(layout.levelDistance, mxUtils.bind(this, function(spacing) { if (!isNaN(spacing)) { layout.levelDistance = spacing; runTreeLayout(layout); } })); }), parent); menu.addItem(mxResources.get('radialTree'), null, mxUtils.bind(this, function() { var layout = new mxRadialTreeLayout(graph); layout.levelDistance = 80; layout.autoRadius = true; promptSpacing(layout.levelDistance, mxUtils.bind(this, function(spacing) { if (!isNaN(spacing)) { layout.levelDistance = spacing; runTreeLayout(layout); } })); }), parent); menu.addSeparator(parent); menu.addItem(mxResources.get('organic'), null, mxUtils.bind(this, function() { var layout = new mxFastOrganicLayout(graph); promptSpacing(layout.forceConstant, mxUtils.bind(this, function(newValue) { this.editorUi.tryAndHandle(mxUtils.bind(this, function() { layout.forceConstant = newValue; this.editorUi.executeLayout(function() { var tmp = graph.getSelectionCell(); if (tmp == null || graph.getModel().getChildCount(tmp) == 0) { tmp = graph.getDefaultParent(); } layout.execute(tmp); if (graph.getModel().isVertex(tmp)) { graph.updateGroupBounds([tmp], graph.gridSize * 2, true); } }, true); })); })); }), parent); menu.addItem(mxResources.get('circle'), null, mxUtils.bind(this, function() { this.editorUi.tryAndHandle(mxUtils.bind(this, function() { var layout = new mxCircleLayout(graph); this.editorUi.executeLayout(function() { var tmp = graph.getSelectionCell(); if (tmp == null || graph.getModel().getChildCount(tmp) == 0) { tmp = graph.getDefaultParent(); } layout.execute(tmp); if (graph.getModel().isVertex(tmp)) { graph.updateGroupBounds([tmp], graph.gridSize * 2, true); } }, true); })); }), parent); }))); this.put('navigation', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['home', '-', 'exitGroup', 'enterGroup', '-', 'expand', 'collapse', '-', 'collapsible'], parent); }))); this.put('arrange', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['toFront', 'toBack', 'bringForward', 'sendBackward', '-'], parent); this.addSubmenu('direction', menu, parent); this.addMenuItems(menu, ['turn', '-'], parent); this.addSubmenu('align', menu, parent); this.addSubmenu('distribute', menu, parent); menu.addSeparator(parent); this.addSubmenu('navigation', menu, parent); this.addSubmenu('insert', menu, parent); this.addSubmenu('layout', menu, parent); this.addMenuItems(menu, ['-', 'group', 'ungroup', 'removeFromGroup', '-', 'clearWaypoints', 'autosize'], parent); }))).isEnabled = isGraphEnabled; this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['insertLink', 'insertImage'], parent); }))); this.put('view', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ((this.editorUi.format != null) ? ['format'] : []). concat(['outline', 'layers', '-', 'pageView', 'pageScale', '-', 'tooltips', 'grid', 'guides', '-', 'connectionArrows', 'connectionPoints', '-', 'resetView', 'zoomIn', 'zoomOut'], parent)); }))); // Two special dropdowns that are only used in the toolbar this.put('viewPanels', new Menu(mxUtils.bind(this, function(menu, parent) { if (this.editorUi.format != null) { this.addMenuItems(menu, ['format'], parent); } this.addMenuItems(menu, ['outline', 'layers'], parent); }))); this.put('viewZoom', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['smartFit', '-'], parent); var scales = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4]; for (var i = 0; i < scales.length; i++) { (function(scale) { menu.addItem((scale * 100) + '%', null, function() { graph.zoomTo(scale); }, parent); })(scales[i]); } this.addMenuItems(menu, ['-', 'fitWindow', 'fitPageWidth', 'fitPage', 'fitTwoPages', '-', 'customZoom'], parent); }))); this.put('file', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['new', 'open', '-', 'save', 'saveAs', '-', 'import', 'export', '-', 'pageSetup', 'print'], parent); }))); this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-', 'editData', 'editTooltip', '-', 'editStyle', '-', 'edit', '-', 'editLink', 'openLink', '-', 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']); }))); this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-', 'editDiagram']); }))); this.put('help', new Menu(mxUtils.bind(this, function(menu, parent) { this.addMenuItems(menu, ['help', '-', 'about']); }))); }; /** * Adds the label menu items to the given menu and parent. */ Menus.prototype.put = function(name, menu) { this.menus[name] = menu; return menu; }; /** * Adds the label menu items to the given menu and parent. */ Menus.prototype.get = function(name) { return this.menus[name]; }; /** * Adds the given submenu. */ Menus.prototype.addSubmenu = function(name, menu, parent, label) { var entry = this.get(name); var submenu = null; if (entry != null) { var enabled = entry.isEnabled(); if (menu.showDisabled || enabled) { submenu = menu.addItem(label || mxResources.get(name), null, null, parent, null, enabled); this.addMenu(name, menu, submenu); } } return submenu; }; /** * Adds the label menu items to the given menu and parent. */ Menus.prototype.addMenu = function(name, popupMenu, parent) { var menu = this.get(name); if (menu != null && (popupMenu.showDisabled || menu.isEnabled())) { menu.execute(popupMenu, parent); } }; /** * Adds a menu item to insert a table cell. */ Menus.prototype.addInsertTableCellItem = function(menu, parent) { var graph = this.editorUi.editor.graph; var cell = graph.getSelectionCell(); var style = graph.getCurrentCellStyle(cell); if (graph.getSelectionCount() > 1) { if (graph.isTableCell(cell)) { cell = graph.model.getParent(cell); } if (graph.isTableRow(cell)) { cell = graph.model.getParent(cell); } } var isTable = graph.isTable(cell) || graph.isTableRow(cell) || graph.isTableCell(cell); var isStack = graph.isStack(cell) || graph.isStackChild(cell); var showCols = isTable; var showRows = isTable; if (isStack) { var style = (graph.isStack(cell)) ? style : graph.getCellStyle(graph.model.getParent(cell)); showRows = style['horizontalStack'] == '0'; showCols = !showRows; } if (parent != null || (!isTable && !isStack)) { this.addInsertTableItem(menu, mxUtils.bind(this, function(evt, rows, cols, title, container) { var table = (container || mxEvent.isControlDown(evt) || mxEvent.isMetaDown(evt)) ? graph.createCrossFunctionalSwimlane(rows, cols, null, null, (title || mxEvent.isShiftDown(evt)) ? 'Cross-Functional Flowchart' : null) : graph.createTable(rows, cols, null, null, (title || mxEvent.isShiftDown(evt)) ? 'Table' : null); var pt = (mxEvent.isAltDown(evt)) ? graph.getFreeInsertPoint() : graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry([table], true)); var select = null; graph.getModel().beginUpdate(); try { select = graph.importCells([table], pt.x, pt.y); graph.fireEvent(new mxEventObject('cellsInserted', 'cells', graph.model.getDescendants(select[0]))); } finally { graph.getModel().endUpdate(); } if (select != null && select.length > 0) { graph.scrollCellToVisible(select[0]); graph.setSelectionCells(select); } }), parent); } else { if (showCols) { var elt = menu.addItem(mxResources.get('insertColumnBefore'), null, mxUtils.bind(this, function() { try { if (isStack) { graph.insertLane(cell, true); } else { graph.insertTableColumn(cell, true); } } catch (e) { this.editorUi.handleError(e); } }), null, 'geIcon geSprite geSprite-insertcolumnbefore'); elt.setAttribute('title', mxResources.get('insertColumnBefore')); elt = menu.addItem(mxResources.get('insertColumnAfter'), null, mxUtils.bind(this, function() { try { if (isStack) { graph.insertLane(cell, false); } else { graph.insertTableColumn(cell, false); } } catch (e) { this.editorUi.handleError(e); } }), null, 'geIcon geSprite geSprite-insertcolumnafter'); elt.setAttribute('title', mxResources.get('insertColumnAfter')); elt = menu.addItem(mxResources.get('deleteColumn'), null, mxUtils.bind(this, function() { if (cell != null) { try { if (isStack) { graph.deleteLane(cell); } else { graph.deleteTableColumn(cell); } } catch (e) { this.editorUi.handleError(e); } } }), null, 'geIcon geSprite geSprite-deletecolumn'); elt.setAttribute('title', mxResources.get('deleteColumn')); } if (showRows) { elt = menu.addItem(mxResources.get('insertRowBefore'), null, mxUtils.bind(this, function() { try { if (isStack) { graph.insertLane(cell, true); } else { graph.insertTableRow(cell, true); } } catch (e) { this.editorUi.handleError(e); } }), null, 'geIcon geSprite geSprite-insertrowbefore'); elt.setAttribute('title', mxResources.get('insertRowBefore')); elt = menu.addItem(mxResources.get('insertRowAfter'), null, mxUtils.bind(this, function() { try { if (isStack) { graph.insertLane(cell, false); } else { graph.insertTableRow(cell, false); } } catch (e) { this.editorUi.handleError(e); } }), null, 'geIcon geSprite geSprite-insertrowafter'); elt.setAttribute('title', mxResources.get('insertRowAfter')); elt = menu.addItem(mxResources.get('deleteRow'), null, mxUtils.bind(this, function() { try { if (isStack) { graph.deleteLane(cell); } else { graph.deleteTableRow(cell); } } catch (e) { this.editorUi.handleError(e); } }), null, 'geIcon geSprite geSprite-deleterow'); elt.setAttribute('title', mxResources.get('deleteRow')); var ss = this.editorUi.getSelectionState(); if (ss.mergeCell != null) { this.addMenuItem(menu, 'mergeCells'); } else if (ss.style['colspan'] > 1 || ss.style['rowspan'] > 1) { this.addMenuItem(menu, 'unmergeCells'); } } } }; /** * Adds a menu item to insert a table. */ Menus.prototype.addInsertTableItem = function(menu, insertFn, parent, showOptions) { showOptions = (showOptions != null) ? showOptions : true; insertFn = (insertFn != null) ? insertFn : mxUtils.bind(this, function(evt, rows, cols) { var graph = this.editorUi.editor.graph; var td = graph.getParentByName(mxEvent.getSource(evt), 'TD'); if (td != null && graph.cellEditor.textarea != null) { // To find the new link, we create a list of all existing links first // LATER: Refactor for reuse with code for finding inserted image below var tmp = graph.cellEditor.textarea.getElementsByTagName('table'); var oldTables = []; for (var i = 0; i < tmp.length; i++) { oldTables.push(tmp[i]); } // Finding the new table will work with insertHTML, but IE does not support that graph.container.focus(); graph.pasteHtmlAtCaret(createTable(rows, cols)); // Moves cursor to first table cell var newTables = graph.cellEditor.textarea.getElementsByTagName('table'); if (newTables.length == oldTables.length + 1) { // Inverse order in favor of appended tables for (var i = newTables.length - 1; i >= 0; i--) { if (i == 0 || newTables[i] != oldTables[i - 1]) { graph.selectNode(newTables[i].rows[0].cells[0]); break; } } } } }); // KNOWN: Does not work in IE8 standards and quirks var graph = this.editorUi.editor.graph; var row2 = null; var td = null; function createTable(rows, cols) { var html = ['