Actions.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Constructs the actions object for the given UI.
  6. */
  7. function Actions(editorUi)
  8. {
  9. this.editorUi = editorUi;
  10. this.actions = new Object();
  11. this.init();
  12. };
  13. /**
  14. * Adds the default actions.
  15. */
  16. Actions.prototype.init = function()
  17. {
  18. var ui = this.editorUi;
  19. var editor = ui.editor;
  20. var graph = editor.graph;
  21. var isGraphEnabled = function()
  22. {
  23. return Action.prototype.isEnabled.apply(this, arguments) && graph.isEnabled();
  24. };
  25. // File actions
  26. this.addAction('new...', function() { window.open(ui.getUrl()); });
  27. this.addAction('open...', function()
  28. {
  29. window.openNew = true;
  30. window.openKey = 'open';
  31. ui.openFile();
  32. });
  33. this.addAction('import...', function()
  34. {
  35. window.openNew = false;
  36. window.openKey = 'import';
  37. // Closes dialog after open
  38. window.openFile = new OpenFile(mxUtils.bind(this, function()
  39. {
  40. ui.hideDialog();
  41. }));
  42. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  43. {
  44. try
  45. {
  46. var doc = mxUtils.parseXml(xml);
  47. var model = new mxGraphModel();
  48. var codec = new mxCodec(doc);
  49. codec.decode(doc.documentElement, model);
  50. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  51. editor.graph.setSelectionCells(editor.graph.importCells(children));
  52. }
  53. catch (e)
  54. {
  55. mxUtils.alert(mxResources.get('invalidOrMissingFile') + ': ' + e.message);
  56. }
  57. }));
  58. // Removes openFile if dialog is closed
  59. ui.showDialog(new OpenDialog(this).container, 320, 220, true, true, function()
  60. {
  61. window.openFile = null;
  62. });
  63. }).isEnabled = isGraphEnabled;
  64. this.addAction('save', function() { ui.saveFile(false); }, null, null, 'Ctrl+S').isEnabled = isGraphEnabled;
  65. this.addAction('saveAs...', function() { ui.saveFile(true); }, null, null, 'Ctrl+Shift+S').isEnabled = isGraphEnabled;
  66. this.addAction('export...', function() { ui.showDialog(new ExportDialog(ui).container, 300, 230, true, true); });
  67. this.addAction('editDiagram...', function()
  68. {
  69. var dlg = new EditDiagramDialog(ui);
  70. ui.showDialog(dlg.container, 620, 420, true, true);
  71. dlg.init();
  72. });
  73. this.addAction('pageSetup...', function() { ui.showDialog(new PageSetupDialog(ui).container, 320, 220, true, true); }).isEnabled = isGraphEnabled;
  74. this.addAction('print...', function() { ui.showDialog(new PrintDialog(ui).container, 300, 180, true, true); }, null, 'sprite-print', 'Ctrl+P');
  75. this.addAction('preview', function() { mxUtils.show(graph, null, 10, 10); });
  76. // Edit actions
  77. this.addAction('undo', function() { ui.undo(); }, null, 'sprite-undo', 'Ctrl+Z');
  78. this.addAction('redo', function() { ui.redo(); }, null, 'sprite-redo', (!mxClient.IS_WIN) ? 'Ctrl+Shift+Z' : 'Ctrl+Y');
  79. this.addAction('cut', function() { mxClipboard.cut(graph); }, null, 'sprite-cut', 'Ctrl+X');
  80. this.addAction('copy', function() { mxClipboard.copy(graph); }, null, 'sprite-copy', 'Ctrl+C');
  81. this.addAction('paste', function()
  82. {
  83. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  84. {
  85. mxClipboard.paste(graph);
  86. }
  87. }, false, 'sprite-paste', 'Ctrl+V');
  88. this.addAction('pasteHere', function(evt)
  89. {
  90. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  91. {
  92. graph.getModel().beginUpdate();
  93. try
  94. {
  95. var cells = mxClipboard.paste(graph);
  96. if (cells != null)
  97. {
  98. var bb = graph.getBoundingBoxFromGeometry(cells);
  99. if (bb != null)
  100. {
  101. var t = graph.view.translate;
  102. var s = graph.view.scale;
  103. var dx = t.x;
  104. var dy = t.y;
  105. var x = Math.round(graph.snap(graph.popupMenuHandler.triggerX / s - dx));
  106. var y = Math.round(graph.snap(graph.popupMenuHandler.triggerY / s - dy));
  107. graph.cellsMoved(cells, x - bb.x, y - bb.y);
  108. }
  109. }
  110. }
  111. finally
  112. {
  113. graph.getModel().endUpdate();
  114. }
  115. }
  116. });
  117. function deleteCells(includeEdges)
  118. {
  119. // Cancels interactive operations
  120. graph.escape();
  121. var cells = graph.getDeletableCells(graph.getSelectionCells());
  122. if (cells != null && cells.length > 0)
  123. {
  124. var parents = graph.model.getParents(cells);
  125. graph.removeCells(cells, includeEdges);
  126. // Selects parents for easier editing of groups
  127. if (parents != null)
  128. {
  129. var select = [];
  130. for (var i = 0; i < parents.length; i++)
  131. {
  132. if (graph.model.contains(parents[i]) &&
  133. (graph.model.isVertex(parents[i]) ||
  134. graph.model.isEdge(parents[i])))
  135. {
  136. select.push(parents[i]);
  137. }
  138. }
  139. graph.setSelectionCells(select);
  140. }
  141. }
  142. };
  143. this.addAction('delete', function(evt)
  144. {
  145. deleteCells(evt != null && mxEvent.isShiftDown(evt));
  146. }, null, null, 'Delete');
  147. this.addAction('deleteAll', function()
  148. {
  149. deleteCells(true);
  150. }, null, null, 'Ctrl+Delete');
  151. this.addAction('duplicate', function()
  152. {
  153. graph.setSelectionCells(graph.duplicateCells());
  154. }, null, null, 'Ctrl+D');
  155. this.put('turn', new Action(mxResources.get('turn') + ' / ' + mxResources.get('reverse'), function()
  156. {
  157. graph.turnShapes(graph.getSelectionCells());
  158. }, null, null, 'Ctrl+R'));
  159. this.addAction('selectVertices', function() { graph.selectVertices(); }, null, null, 'Ctrl+Shift+I');
  160. this.addAction('selectEdges', function() { graph.selectEdges(); }, null, null, 'Ctrl+Shift+E');
  161. this.addAction('selectAll', function() { graph.selectAll(null, true); }, null, null, 'Ctrl+A');
  162. this.addAction('selectNone', function() { graph.clearSelection(); }, null, null, 'Ctrl+Shift+A');
  163. this.addAction('lockUnlock', function()
  164. {
  165. if (!graph.isSelectionEmpty())
  166. {
  167. graph.getModel().beginUpdate();
  168. try
  169. {
  170. var defaultValue = graph.isCellMovable(graph.getSelectionCell()) ? 1 : 0;
  171. graph.toggleCellStyles(mxConstants.STYLE_MOVABLE, defaultValue);
  172. graph.toggleCellStyles(mxConstants.STYLE_RESIZABLE, defaultValue);
  173. graph.toggleCellStyles(mxConstants.STYLE_ROTATABLE, defaultValue);
  174. graph.toggleCellStyles(mxConstants.STYLE_DELETABLE, defaultValue);
  175. graph.toggleCellStyles(mxConstants.STYLE_EDITABLE, defaultValue);
  176. graph.toggleCellStyles('connectable', defaultValue);
  177. }
  178. finally
  179. {
  180. graph.getModel().endUpdate();
  181. }
  182. }
  183. }, null, null, 'Ctrl+L');
  184. // Navigation actions
  185. this.addAction('home', function() { graph.home(); }, null, null, 'Home');
  186. this.addAction('exitGroup', function() { graph.exitGroup(); }, null, null, 'Ctrl+Shift+Page Up');
  187. this.addAction('enterGroup', function() { graph.enterGroup(); }, null, null, 'Ctrl+Shift+Page Down');
  188. this.addAction('expand', function() { graph.foldCells(false); }, null, null, 'Ctrl+Page Down');
  189. this.addAction('collapse', function() { graph.foldCells(true); }, null, null, 'Ctrl+Page Up');
  190. // Arrange actions
  191. this.addAction('toFront', function() { graph.orderCells(false); }, null, null, 'Ctrl+Shift+F');
  192. this.addAction('toBack', function() { graph.orderCells(true); }, null, null, 'Ctrl+Shift+B');
  193. this.addAction('group', function()
  194. {
  195. if (graph.getSelectionCount() == 1)
  196. {
  197. graph.setCellStyles('container', '1');
  198. }
  199. else
  200. {
  201. graph.setSelectionCell(graph.groupCells(null, 0));
  202. }
  203. }, null, null, 'Ctrl+G');
  204. this.addAction('ungroup', function()
  205. {
  206. if (graph.getSelectionCount() == 1 && graph.getModel().getChildCount(graph.getSelectionCell()) == 0)
  207. {
  208. graph.setCellStyles('container', '0');
  209. }
  210. else
  211. {
  212. graph.setSelectionCells(graph.ungroupCells());
  213. }
  214. }, null, null, 'Ctrl+Shift+U');
  215. this.addAction('removeFromGroup', function() { graph.removeCellsFromParent(); });
  216. // Adds action
  217. this.addAction('edit', function()
  218. {
  219. if (graph.isEnabled())
  220. {
  221. graph.startEditingAtCell();
  222. }
  223. }, null, null, 'F2/Enter');
  224. this.addAction('editData...', function()
  225. {
  226. var cell = graph.getSelectionCell() || graph.getModel().getRoot();
  227. if (cell != null)
  228. {
  229. var dlg = new EditDataDialog(ui, cell);
  230. ui.showDialog(dlg.container, 320, 320, true, false);
  231. dlg.init();
  232. }
  233. }, null, null, 'Ctrl+M');
  234. this.addAction('editTooltip...', function()
  235. {
  236. var graph = ui.editor.graph;
  237. if (graph.isEnabled() && !graph.isSelectionEmpty())
  238. {
  239. var cell = graph.getSelectionCell();
  240. var tooltip = '';
  241. if (mxUtils.isNode(cell.value))
  242. {
  243. var tmp = cell.value.getAttribute('tooltip');
  244. if (tmp != null)
  245. {
  246. tooltip = tmp;
  247. }
  248. }
  249. var dlg = new TextareaDialog(ui, mxResources.get('editTooltip') + ':', tooltip, function(newValue)
  250. {
  251. graph.setTooltipForCell(cell, newValue);
  252. });
  253. ui.showDialog(dlg.container, 320, 200, true, true);
  254. dlg.init();
  255. }
  256. });
  257. this.addAction('openLink', function()
  258. {
  259. var link = graph.getLinkForCell(graph.getSelectionCell());
  260. if (link != null)
  261. {
  262. window.open(link);
  263. }
  264. });
  265. this.addAction('editLink...', function()
  266. {
  267. var graph = ui.editor.graph;
  268. if (graph.isEnabled() && !graph.isSelectionEmpty())
  269. {
  270. var cell = graph.getSelectionCell();
  271. var value = graph.getLinkForCell(cell) || '';
  272. ui.showLinkDialog(value, mxResources.get('apply'), function(link)
  273. {
  274. link = mxUtils.trim(link);
  275. graph.setLinkForCell(cell, (link.length > 0) ? link : null);
  276. });
  277. }
  278. });
  279. this.addAction('insertLink...', function()
  280. {
  281. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  282. {
  283. var dlg = new LinkDialog(ui, '', mxResources.get('insert'), function(link, docs)
  284. {
  285. link = mxUtils.trim(link);
  286. if (link.length > 0)
  287. {
  288. var title = link.substring(link.lastIndexOf('/') + 1);
  289. var icon = null;
  290. if (docs != null && docs.length > 0)
  291. {
  292. icon = docs[0].iconUrl;
  293. title = docs[0].name || docs[0].type;
  294. title = title.charAt(0).toUpperCase() + title.substring(1);
  295. if (title.length > 30)
  296. {
  297. title = title.substring(0, 30) + '...';
  298. }
  299. }
  300. var pt = graph.getFreeInsertPoint();
  301. var linkCell = new mxCell(title, new mxGeometry(pt.x, pt.y, 100, 40),
  302. 'fontColor=#0000EE;fontStyle=4;rounded=1;overflow=hidden;' + ((icon != null) ?
  303. 'shape=label;imageWidth=16;imageHeight=16;spacingLeft=26;align=left;image=' + icon :
  304. 'spacing=10;'));
  305. linkCell.vertex = true;
  306. graph.setLinkForCell(linkCell, link);
  307. graph.cellSizeUpdated(linkCell, true);
  308. graph.setSelectionCell(graph.addCell(linkCell));
  309. graph.scrollCellToVisible(graph.getSelectionCell());
  310. }
  311. });
  312. ui.showDialog(dlg.container, 420, 90, true, true);
  313. dlg.init();
  314. }
  315. }).isEnabled = isGraphEnabled;
  316. this.addAction('link...', mxUtils.bind(this, function()
  317. {
  318. var graph = ui.editor.graph;
  319. if (graph.isEnabled())
  320. {
  321. if (graph.cellEditor.isContentEditing())
  322. {
  323. var link = graph.getParentByName(graph.getSelectedElement(), 'A', graph.cellEditor.textarea);
  324. var oldValue = '';
  325. if (link != null)
  326. {
  327. oldValue = link.getAttribute('href') || '';
  328. }
  329. var selState = graph.cellEditor.saveSelection();
  330. ui.showLinkDialog(oldValue, mxResources.get('apply'), mxUtils.bind(this, function(value)
  331. {
  332. graph.cellEditor.restoreSelection(selState);
  333. if (value != null)
  334. {
  335. graph.insertLink(value);
  336. }
  337. }));
  338. }
  339. else if (graph.isSelectionEmpty())
  340. {
  341. this.get('insertLink').funct();
  342. }
  343. else
  344. {
  345. this.get('editLink').funct();
  346. }
  347. }
  348. })).isEnabled = isGraphEnabled;
  349. this.addAction('autosize', function()
  350. {
  351. var cells = graph.getSelectionCells();
  352. if (cells != null)
  353. {
  354. graph.getModel().beginUpdate();
  355. try
  356. {
  357. for (var i = 0; i < cells.length; i++)
  358. {
  359. var cell = cells[i];
  360. if (graph.getModel().getChildCount(cell))
  361. {
  362. graph.updateGroupBounds([cell], 20);
  363. }
  364. else
  365. {
  366. var state = graph.view.getState(cell);
  367. var geo = graph.getCellGeometry(cell);
  368. if (graph.getModel().isVertex(cell) && state != null && state.text != null &&
  369. geo != null && graph.isWrapping(cell))
  370. {
  371. geo = geo.clone();
  372. geo.height = state.text.boundingBox.height / graph.view.scale;
  373. graph.getModel().setGeometry(cell, geo);
  374. }
  375. else
  376. {
  377. graph.updateCellSize(cell);
  378. }
  379. }
  380. }
  381. }
  382. finally
  383. {
  384. graph.getModel().endUpdate();
  385. }
  386. }
  387. }, null, null, 'Ctrl+Shift+Y');
  388. this.addAction('formattedText', function()
  389. {
  390. var state = graph.getView().getState(graph.getSelectionCell());
  391. if (state != null)
  392. {
  393. var value = '1';
  394. graph.stopEditing();
  395. graph.getModel().beginUpdate();
  396. try
  397. {
  398. if (state.style['html'] == '1')
  399. {
  400. value = null;
  401. var label = graph.convertValueToString(state.cell);
  402. if (mxUtils.getValue(state.style, 'nl2Br', '1') != '0')
  403. {
  404. // Removes newlines from HTML and converts breaks to newlines
  405. // to match the HTML output in plain text
  406. label = label.replace(/\n/g, '').replace(/<br\s*.?>/g, '\n');
  407. }
  408. // Removes HTML tags
  409. var temp = document.createElement('div');
  410. temp.innerHTML = label;
  411. label = mxUtils.extractTextWithWhitespace(temp.childNodes);
  412. graph.cellLabelChanged(state.cell, label);
  413. }
  414. else
  415. {
  416. // Converts HTML tags to text
  417. var label = mxUtils.htmlEntities(graph.convertValueToString(state.cell), false);
  418. if (mxUtils.getValue(state.style, 'nl2Br', '1') != '0')
  419. {
  420. // Converts newlines in plain text to breaks in HTML
  421. // to match the plain text output
  422. label = label.replace(/\n/g, '<br/>');
  423. }
  424. graph.cellLabelChanged(state.cell, graph.sanitizeHtml(label));
  425. }
  426. graph.setCellStyles('html', value);
  427. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['html'],
  428. 'values', [(value != null) ? value : '0'], 'cells',
  429. graph.getSelectionCells()));
  430. }
  431. finally
  432. {
  433. graph.getModel().endUpdate();
  434. }
  435. }
  436. });
  437. this.addAction('wordWrap', function()
  438. {
  439. var state = graph.getView().getState(graph.getSelectionCell());
  440. var value = 'wrap';
  441. graph.stopEditing();
  442. if (state != null && state.style[mxConstants.STYLE_WHITE_SPACE] == 'wrap')
  443. {
  444. value = null;
  445. }
  446. graph.setCellStyles(mxConstants.STYLE_WHITE_SPACE, value);
  447. });
  448. this.addAction('rotation', function()
  449. {
  450. var value = '0';
  451. var state = graph.getView().getState(graph.getSelectionCell());
  452. if (state != null)
  453. {
  454. value = state.style[mxConstants.STYLE_ROTATION] || value;
  455. }
  456. var dlg = new FilenameDialog(ui, value, mxResources.get('apply'), function(newValue)
  457. {
  458. if (newValue != null && newValue.length > 0)
  459. {
  460. graph.setCellStyles(mxConstants.STYLE_ROTATION, newValue);
  461. }
  462. }, mxResources.get('enterValue') + ' (' + mxResources.get('rotation') + ' 0-360)');
  463. ui.showDialog(dlg.container, 300, 80, true, true);
  464. dlg.init();
  465. });
  466. // View actions
  467. this.addAction('resetView', function()
  468. {
  469. graph.zoomTo(1);
  470. ui.resetScrollbars();
  471. }, null, null, 'Ctrl+H');
  472. this.addAction('zoomIn', function(evt) { graph.zoomIn(); }, null, null, 'Ctrl + (Numpad) / Alt+Mousewheel');
  473. this.addAction('zoomOut', function(evt) { graph.zoomOut(); }, null, null, 'Ctrl - (Numpad) / Alt+Mousewheel');
  474. this.addAction('fitWindow', function() { graph.fit(); }, null, null, 'Ctrl+Shift+H');
  475. this.addAction('fitPage', mxUtils.bind(this, function()
  476. {
  477. if (!graph.pageVisible)
  478. {
  479. this.get('pageView').funct();
  480. }
  481. var fmt = graph.pageFormat;
  482. var ps = graph.pageScale;
  483. var cw = graph.container.clientWidth - 10;
  484. var ch = graph.container.clientHeight - 10;
  485. var scale = Math.floor(20 * Math.min(cw / fmt.width / ps, ch / fmt.height / ps)) / 20;
  486. graph.zoomTo(scale);
  487. if (mxUtils.hasScrollbars(graph.container))
  488. {
  489. var pad = graph.getPagePadding();
  490. graph.container.scrollTop = pad.y * graph.view.scale;
  491. graph.container.scrollLeft = Math.min(pad.x * graph.view.scale, (graph.container.scrollWidth - graph.container.clientWidth) / 2);
  492. }
  493. }), null, null, 'Ctrl+J');
  494. this.addAction('fitTwoPages', mxUtils.bind(this, function()
  495. {
  496. if (!graph.pageVisible)
  497. {
  498. this.get('pageView').funct();
  499. }
  500. var fmt = graph.pageFormat;
  501. var ps = graph.pageScale;
  502. var cw = graph.container.clientWidth - 10;
  503. var ch = graph.container.clientHeight - 10;
  504. var scale = Math.floor(20 * Math.min(cw / (2 * fmt.width) / ps, ch / fmt.height / ps)) / 20;
  505. graph.zoomTo(scale);
  506. if (mxUtils.hasScrollbars(graph.container))
  507. {
  508. var pad = graph.getPagePadding();
  509. graph.container.scrollTop = Math.min(pad.y, (graph.container.scrollHeight - graph.container.clientHeight) / 2);
  510. graph.container.scrollLeft = Math.min(pad.x, (graph.container.scrollWidth - graph.container.clientWidth) / 2);
  511. }
  512. }), null, null, 'Ctrl+Shift+J');
  513. this.addAction('fitPageWidth', mxUtils.bind(this, function()
  514. {
  515. if (!graph.pageVisible)
  516. {
  517. this.get('pageView').funct();
  518. }
  519. var fmt = graph.pageFormat;
  520. var ps = graph.pageScale;
  521. var cw = graph.container.clientWidth - 10;
  522. var scale = Math.floor(20 * cw / fmt.width / ps) / 20;
  523. graph.zoomTo(scale);
  524. if (mxUtils.hasScrollbars(graph.container))
  525. {
  526. var pad = graph.getPagePadding();
  527. graph.container.scrollLeft = Math.min(pad.x * graph.view.scale,
  528. (graph.container.scrollWidth - graph.container.clientWidth) / 2);
  529. }
  530. }));
  531. this.put('customZoom', new Action(mxResources.get('custom') + '...', mxUtils.bind(this, function()
  532. {
  533. var dlg = new FilenameDialog(this.editorUi, parseInt(graph.getView().getScale() * 100), mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  534. {
  535. var val = parseInt(newValue);
  536. if (!isNaN(val) && val > 0)
  537. {
  538. graph.zoomTo(val / 100);
  539. }
  540. }), mxResources.get('zoom') + ' (%)');
  541. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  542. dlg.init();
  543. }), null, null, 'Ctrl+0'));
  544. this.addAction('pageScale...', mxUtils.bind(this, function()
  545. {
  546. var dlg = new FilenameDialog(this.editorUi, parseInt(graph.pageScale * 100), mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  547. {
  548. var val = parseInt(newValue);
  549. if (!isNaN(val) && val > 0)
  550. {
  551. ui.setPageScale(val / 100);
  552. }
  553. }), mxResources.get('pageScale') + ' (%)');
  554. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  555. dlg.init();
  556. }));
  557. // Option actions
  558. var action = null;
  559. action = this.addAction('grid', function()
  560. {
  561. graph.setGridEnabled(!graph.isGridEnabled());
  562. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  563. }, null, null, 'Ctrl+Shift+G');
  564. action.setToggleAction(true);
  565. action.setSelectedCallback(function() { return graph.isGridEnabled(); });
  566. action.setEnabled(false);
  567. action = this.addAction('guides', function()
  568. {
  569. graph.graphHandler.guidesEnabled = !graph.graphHandler.guidesEnabled;
  570. ui.fireEvent(new mxEventObject('guidesEnabledChanged'));
  571. });
  572. action.setToggleAction(true);
  573. action.setSelectedCallback(function() { return graph.graphHandler.guidesEnabled; });
  574. action.setEnabled(false);
  575. action = this.addAction('tooltips', function()
  576. {
  577. graph.tooltipHandler.setEnabled(!graph.tooltipHandler.isEnabled());
  578. });
  579. action.setToggleAction(true);
  580. action.setSelectedCallback(function() { return graph.tooltipHandler.isEnabled(); });
  581. action = this.addAction('collapseExpand', function()
  582. {
  583. ui.setFoldingEnabled(!graph.foldingEnabled);
  584. });
  585. action.setToggleAction(true);
  586. action.setSelectedCallback(function() { return graph.foldingEnabled; });
  587. action.isEnabled = isGraphEnabled;
  588. action = this.addAction('scrollbars', function()
  589. {
  590. ui.setScrollbars(!ui.hasScrollbars());
  591. });
  592. action.setToggleAction(true);
  593. action.setSelectedCallback(function() { return graph.scrollbars; });
  594. action = this.addAction('pageView', mxUtils.bind(this, function()
  595. {
  596. ui.setPageVisible(!graph.pageVisible);
  597. }));
  598. action.setToggleAction(true);
  599. action.setSelectedCallback(function() { return graph.pageVisible; });
  600. this.put('pageBackgroundColor', new Action(mxResources.get('backgroundColor') + '...', function()
  601. {
  602. ui.pickColor(graph.background || 'none', function(color)
  603. {
  604. ui.setBackgroundColor(color);
  605. });
  606. }));
  607. action = this.addAction('connectionArrows', function()
  608. {
  609. graph.connectionArrowsEnabled = !graph.connectionArrowsEnabled;
  610. ui.fireEvent(new mxEventObject('connectionArrowsChanged'));
  611. }, null, null, 'Ctrl+Q');
  612. action.setToggleAction(true);
  613. action.setSelectedCallback(function() { return graph.connectionArrowsEnabled; });
  614. action = this.addAction('connectionPoints', function()
  615. {
  616. graph.setConnectable(!graph.connectionHandler.isEnabled());
  617. ui.fireEvent(new mxEventObject('connectionPointsChanged'));
  618. }, null, null, 'Ctrl+Shift+Q');
  619. action.setToggleAction(true);
  620. action.setSelectedCallback(function() { return graph.connectionHandler.isEnabled(); });
  621. action = this.addAction('copyConnect', function()
  622. {
  623. graph.connectionHandler.setCreateTarget(!graph.connectionHandler.isCreateTarget());
  624. ui.fireEvent(new mxEventObject('copyConnectChanged'));
  625. });
  626. action.setToggleAction(true);
  627. action.setSelectedCallback(function() { return graph.connectionHandler.isCreateTarget(); });
  628. action.isEnabled = isGraphEnabled;
  629. action = this.addAction('autosave', function()
  630. {
  631. ui.editor.setAutosave(!ui.editor.autosave);
  632. });
  633. action.setToggleAction(true);
  634. action.setSelectedCallback(function() { return ui.editor.autosave; });
  635. action.isEnabled = isGraphEnabled;
  636. action.visible = false;
  637. // Help actions
  638. this.addAction('help', function()
  639. {
  640. var ext = '';
  641. if (mxResources.isLanguageSupported(mxClient.language))
  642. {
  643. ext = '_' + mxClient.language;
  644. }
  645. window.open(RESOURCES_PATH + '/help' + ext + '.html');
  646. });
  647. this.put('about', new Action(mxResources.get('about') + ' Graph Editor...', function()
  648. {
  649. ui.showDialog(new AboutDialog(ui).container, 320, 280, true, true);
  650. }, null, null, 'F1'));
  651. // Font style actions
  652. var toggleFontStyle = mxUtils.bind(this, function(key, style, fn, shortcut)
  653. {
  654. return this.addAction(key, function()
  655. {
  656. if (fn != null && graph.cellEditor.isContentEditing())
  657. {
  658. fn();
  659. }
  660. else
  661. {
  662. graph.stopEditing(false);
  663. graph.toggleCellStyleFlags(mxConstants.STYLE_FONTSTYLE, style);
  664. }
  665. }, null, null, shortcut);
  666. });
  667. toggleFontStyle('bold', mxConstants.FONT_BOLD, function() { document.execCommand('bold', false, null); }, 'Ctrl+B');
  668. toggleFontStyle('italic', mxConstants.FONT_ITALIC, function() { document.execCommand('italic', false, null); }, 'Ctrl+I');
  669. toggleFontStyle('underline', mxConstants.FONT_UNDERLINE, function() { document.execCommand('underline', false, null); }, 'Ctrl+U');
  670. // Color actions
  671. this.addAction('fontColor...', function() { ui.menus.pickColor(mxConstants.STYLE_FONTCOLOR, 'forecolor', '000000'); });
  672. this.addAction('strokeColor...', function() { ui.menus.pickColor(mxConstants.STYLE_STROKECOLOR); });
  673. this.addAction('fillColor...', function() { ui.menus.pickColor(mxConstants.STYLE_FILLCOLOR); });
  674. this.addAction('gradientColor...', function() { ui.menus.pickColor(mxConstants.STYLE_GRADIENTCOLOR); });
  675. this.addAction('backgroundColor...', function() { ui.menus.pickColor(mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, 'backcolor'); });
  676. this.addAction('borderColor...', function() { ui.menus.pickColor(mxConstants.STYLE_LABEL_BORDERCOLOR); });
  677. // Format actions
  678. this.addAction('vertical', function() { ui.menus.toggleStyle(mxConstants.STYLE_HORIZONTAL, true); });
  679. this.addAction('shadow', function() { ui.menus.toggleStyle(mxConstants.STYLE_SHADOW); });
  680. this.addAction('solid', function()
  681. {
  682. graph.getModel().beginUpdate();
  683. try
  684. {
  685. graph.setCellStyles(mxConstants.STYLE_DASHED, null);
  686. graph.setCellStyles(mxConstants.STYLE_DASH_PATTERN, null);
  687. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN],
  688. 'values', [null, null], 'cells', graph.getSelectionCells()));
  689. }
  690. finally
  691. {
  692. graph.getModel().endUpdate();
  693. }
  694. });
  695. this.addAction('dashed', function()
  696. {
  697. graph.getModel().beginUpdate();
  698. try
  699. {
  700. graph.setCellStyles(mxConstants.STYLE_DASHED, '1');
  701. graph.setCellStyles(mxConstants.STYLE_DASH_PATTERN, null);
  702. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN],
  703. 'values', ['1', null], 'cells', graph.getSelectionCells()));
  704. }
  705. finally
  706. {
  707. graph.getModel().endUpdate();
  708. }
  709. });
  710. this.addAction('dotted', function()
  711. {
  712. graph.getModel().beginUpdate();
  713. try
  714. {
  715. graph.setCellStyles(mxConstants.STYLE_DASHED, '1');
  716. graph.setCellStyles(mxConstants.STYLE_DASH_PATTERN, '1 4');
  717. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN],
  718. 'values', ['1', '1 4'], 'cells', graph.getSelectionCells()));
  719. }
  720. finally
  721. {
  722. graph.getModel().endUpdate();
  723. }
  724. });
  725. this.addAction('sharp', function()
  726. {
  727. graph.getModel().beginUpdate();
  728. try
  729. {
  730. graph.setCellStyles(mxConstants.STYLE_ROUNDED, '0');
  731. graph.setCellStyles(mxConstants.STYLE_CURVED, '0');
  732. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  733. 'values', ['0', '0'], 'cells', graph.getSelectionCells()));
  734. }
  735. finally
  736. {
  737. graph.getModel().endUpdate();
  738. }
  739. });
  740. this.addAction('rounded', function()
  741. {
  742. graph.getModel().beginUpdate();
  743. try
  744. {
  745. graph.setCellStyles(mxConstants.STYLE_ROUNDED, '1');
  746. graph.setCellStyles(mxConstants.STYLE_CURVED, '0');
  747. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  748. 'values', ['1', '0'], 'cells', graph.getSelectionCells()));
  749. }
  750. finally
  751. {
  752. graph.getModel().endUpdate();
  753. }
  754. });
  755. this.addAction('toggleRounded', function()
  756. {
  757. if (!graph.isSelectionEmpty() && graph.isEnabled())
  758. {
  759. graph.getModel().beginUpdate();
  760. try
  761. {
  762. var cells = graph.getSelectionCells();
  763. var state = graph.view.getState(cells[0]);
  764. var style = (state != null) ? state.style : graph.getCellStyle(cells[0]);
  765. var value = (mxUtils.getValue(style, mxConstants.STYLE_ROUNDED, '0') == '1') ? '0' : '1';
  766. graph.setCellStyles(mxConstants.STYLE_ROUNDED, value);
  767. graph.setCellStyles(mxConstants.STYLE_CURVED, null);
  768. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  769. 'values', [value, '0'], 'cells', graph.getSelectionCells()));
  770. }
  771. finally
  772. {
  773. graph.getModel().endUpdate();
  774. }
  775. }
  776. });
  777. this.addAction('curved', function()
  778. {
  779. graph.getModel().beginUpdate();
  780. try
  781. {
  782. graph.setCellStyles(mxConstants.STYLE_ROUNDED, '0');
  783. graph.setCellStyles(mxConstants.STYLE_CURVED, '1');
  784. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  785. 'values', ['0', '1'], 'cells', graph.getSelectionCells()));
  786. }
  787. finally
  788. {
  789. graph.getModel().endUpdate();
  790. }
  791. });
  792. this.addAction('collapsible', function()
  793. {
  794. var state = graph.view.getState(graph.getSelectionCell());
  795. var value = '1';
  796. if (state != null && graph.getFoldingImage(state) != null)
  797. {
  798. value = '0';
  799. }
  800. graph.setCellStyles('collapsible', value);
  801. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['collapsible'],
  802. 'values', [value], 'cells', graph.getSelectionCells()));
  803. });
  804. this.addAction('editStyle...', mxUtils.bind(this, function()
  805. {
  806. var cells = graph.getSelectionCells();
  807. if (cells != null && cells.length > 0)
  808. {
  809. var model = graph.getModel();
  810. var dlg = new TextareaDialog(this.editorUi, mxResources.get('editStyle') + ':',
  811. model.getStyle(cells[0]) || '', function(newValue)
  812. {
  813. if (newValue != null)
  814. {
  815. graph.setCellStyle(mxUtils.trim(newValue), cells);
  816. }
  817. }, null, null, 400, 220);
  818. this.editorUi.showDialog(dlg.container, 420, 300, true, true);
  819. dlg.init();
  820. }
  821. }), null, null, 'Ctrl+E');
  822. this.addAction('setAsDefaultStyle', function()
  823. {
  824. if (graph.isEnabled() && !graph.isSelectionEmpty())
  825. {
  826. ui.setDefaultStyle(graph.getSelectionCell());
  827. }
  828. }, null, null, 'Ctrl+Shift+D');
  829. this.addAction('clearDefaultStyle', function()
  830. {
  831. if (graph.isEnabled())
  832. {
  833. ui.clearDefaultStyle();
  834. }
  835. }, null, null, 'Ctrl+Shift+R');
  836. this.addAction('addWaypoint', function()
  837. {
  838. var cell = graph.getSelectionCell();
  839. if (cell != null && graph.getModel().isEdge(cell))
  840. {
  841. var handler = editor.graph.selectionCellsHandler.getHandler(cell);
  842. if (handler instanceof mxEdgeHandler)
  843. {
  844. var t = graph.view.translate;
  845. var s = graph.view.scale;
  846. var dx = t.x;
  847. var dy = t.y;
  848. var parent = graph.getModel().getParent(cell);
  849. var pgeo = graph.getCellGeometry(parent);
  850. while (graph.getModel().isVertex(parent) && pgeo != null)
  851. {
  852. dx += pgeo.x;
  853. dy += pgeo.y;
  854. parent = graph.getModel().getParent(parent);
  855. pgeo = graph.getCellGeometry(parent);
  856. }
  857. var x = Math.round(graph.snap(graph.popupMenuHandler.triggerX / s - dx));
  858. var y = Math.round(graph.snap(graph.popupMenuHandler.triggerY / s - dy));
  859. handler.addPointAt(handler.state, x, y);
  860. }
  861. }
  862. });
  863. this.addAction('removeWaypoint', function()
  864. {
  865. // TODO: Action should run with "this" set to action
  866. var rmWaypointAction = ui.actions.get('removeWaypoint');
  867. if (rmWaypointAction.handler != null)
  868. {
  869. // NOTE: Popupevent handled and action updated in Menus.createPopupMenu
  870. rmWaypointAction.handler.removePoint(rmWaypointAction.handler.state, rmWaypointAction.index);
  871. }
  872. });
  873. this.addAction('clearWaypoints', function()
  874. {
  875. var cells = graph.getSelectionCells();
  876. if (cells != null)
  877. {
  878. cells = graph.addAllEdges(cells);
  879. graph.getModel().beginUpdate();
  880. try
  881. {
  882. for (var i = 0; i < cells.length; i++)
  883. {
  884. var cell = cells[i];
  885. if (graph.getModel().isEdge(cell))
  886. {
  887. var geo = graph.getCellGeometry(cell);
  888. if (geo != null)
  889. {
  890. geo = geo.clone();
  891. geo.points = null;
  892. graph.getModel().setGeometry(cell, geo);
  893. }
  894. }
  895. }
  896. }
  897. finally
  898. {
  899. graph.getModel().endUpdate();
  900. }
  901. }
  902. }, null, null, 'Alt+Shift+C');
  903. action = this.addAction('subscript', mxUtils.bind(this, function()
  904. {
  905. if (graph.cellEditor.isContentEditing())
  906. {
  907. document.execCommand('subscript', false, null);
  908. }
  909. }), null, null, 'Ctrl+,');
  910. action = this.addAction('superscript', mxUtils.bind(this, function()
  911. {
  912. if (graph.cellEditor.isContentEditing())
  913. {
  914. document.execCommand('superscript', false, null);
  915. }
  916. }), null, null, 'Ctrl+.');
  917. this.addAction('image...', function()
  918. {
  919. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  920. {
  921. var title = mxResources.get('image') + ' (' + mxResources.get('url') + '):';
  922. var state = graph.getView().getState(graph.getSelectionCell());
  923. var value = '';
  924. if (state != null)
  925. {
  926. value = state.style[mxConstants.STYLE_IMAGE] || value;
  927. }
  928. var selectionState = graph.cellEditor.saveSelection();
  929. ui.showImageDialog(title, value, function(newValue, w, h)
  930. {
  931. // Inserts image into HTML text
  932. if (graph.cellEditor.isContentEditing())
  933. {
  934. graph.cellEditor.restoreSelection(selectionState);
  935. graph.insertImage(newValue, w, h);
  936. }
  937. else
  938. {
  939. var cells = graph.getSelectionCells();
  940. if (newValue != null)
  941. {
  942. var select = null;
  943. graph.getModel().beginUpdate();
  944. try
  945. {
  946. // Inserts new cell if no cell is selected
  947. if (cells.length == 0)
  948. {
  949. var pt = graph.getFreeInsertPoint();
  950. cells = [graph.insertVertex(graph.getDefaultParent(), null, '', pt.x, pt.y, w, h,
  951. 'shape=image;imageAspect=0;aspect=fixed;verticalLabelPosition=bottom;verticalAlign=top;')];
  952. select = cells;
  953. }
  954. graph.setCellStyles(mxConstants.STYLE_IMAGE, newValue, cells);
  955. // Sets shape only if not already shape with image (label or image)
  956. var state = graph.view.getState(cells[0]);
  957. var style = (state != null) ? state.style : graph.getCellStyle(cells[0]);
  958. if (style[mxConstants.STYLE_SHAPE] != 'image' && style[mxConstants.STYLE_SHAPE] != 'label')
  959. {
  960. graph.setCellStyles(mxConstants.STYLE_SHAPE, 'image', cells);
  961. }
  962. if (graph.getSelectionCount() == 1)
  963. {
  964. if (w != null && h != null)
  965. {
  966. var cell = cells[0];
  967. var geo = graph.getModel().getGeometry(cell);
  968. if (geo != null)
  969. {
  970. geo = geo.clone();
  971. geo.width = w;
  972. geo.height = h;
  973. graph.getModel().setGeometry(cell, geo);
  974. }
  975. }
  976. }
  977. }
  978. finally
  979. {
  980. graph.getModel().endUpdate();
  981. }
  982. if (select != null)
  983. {
  984. graph.setSelectionCells(select);
  985. graph.scrollCellToVisible(select[0]);
  986. }
  987. }
  988. }
  989. }, graph.cellEditor.isContentEditing(), !graph.cellEditor.isContentEditing());
  990. }
  991. }).isEnabled = isGraphEnabled;
  992. this.addAction('insertImage...', function()
  993. {
  994. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  995. {
  996. graph.clearSelection();
  997. ui.actions.get('image').funct();
  998. }
  999. }).isEnabled = isGraphEnabled;
  1000. action = this.addAction('layers', mxUtils.bind(this, function()
  1001. {
  1002. if (this.layersWindow == null)
  1003. {
  1004. // LATER: Check outline window for initial placement
  1005. this.layersWindow = new LayersWindow(ui, document.body.offsetWidth - 280, 120, 220, 180);
  1006. this.layersWindow.window.addListener('show', function()
  1007. {
  1008. ui.fireEvent(new mxEventObject('layers'));
  1009. });
  1010. this.layersWindow.window.addListener('hide', function()
  1011. {
  1012. ui.fireEvent(new mxEventObject('layers'));
  1013. });
  1014. this.layersWindow.window.setVisible(true);
  1015. ui.fireEvent(new mxEventObject('layers'));
  1016. }
  1017. else
  1018. {
  1019. this.layersWindow.window.setVisible(!this.layersWindow.window.isVisible());
  1020. }
  1021. //ui.fireEvent(new mxEventObject('layers'));
  1022. }), null, null, 'Ctrl+Shift+L');
  1023. action.setToggleAction(true);
  1024. action.setSelectedCallback(mxUtils.bind(this, function() { return this.layersWindow != null && this.layersWindow.window.isVisible(); }));
  1025. action = this.addAction('formatPanel', mxUtils.bind(this, function()
  1026. {
  1027. ui.toggleFormatPanel();
  1028. }), null, null, 'Ctrl+Shift+P');
  1029. action.setToggleAction(true);
  1030. action.setSelectedCallback(mxUtils.bind(this, function() { return ui.formatWidth > 0; }));
  1031. action = this.addAction('outline', mxUtils.bind(this, function()
  1032. {
  1033. if (this.outlineWindow == null)
  1034. {
  1035. // LATER: Check layers window for initial placement
  1036. this.outlineWindow = new OutlineWindow(ui, document.body.offsetWidth - 260, 100, 180, 180);
  1037. this.outlineWindow.window.addListener('show', function()
  1038. {
  1039. ui.fireEvent(new mxEventObject('outline'));
  1040. });
  1041. this.outlineWindow.window.addListener('hide', function()
  1042. {
  1043. ui.fireEvent(new mxEventObject('outline'));
  1044. });
  1045. this.outlineWindow.window.setVisible(true);
  1046. ui.fireEvent(new mxEventObject('outline'));
  1047. }
  1048. else
  1049. {
  1050. this.outlineWindow.window.setVisible(!this.outlineWindow.window.isVisible());
  1051. }
  1052. ui.fireEvent(new mxEventObject('outline'));
  1053. }), null, null, 'Ctrl+Shift+O');
  1054. action.setToggleAction(true);
  1055. action.setSelectedCallback(mxUtils.bind(this, function() { return this.outlineWindow != null && this.outlineWindow.window.isVisible(); }));
  1056. };
  1057. /**
  1058. * Registers the given action under the given name.
  1059. */
  1060. Actions.prototype.addAction = function(key, funct, enabled, iconCls, shortcut)
  1061. {
  1062. var title;
  1063. if (key.substring(key.length - 3) == '...')
  1064. {
  1065. key = key.substring(0, key.length - 3);
  1066. title = mxResources.get(key) + '...';
  1067. }
  1068. else
  1069. {
  1070. title = mxResources.get(key);
  1071. }
  1072. return this.put(key, new Action(title, funct, enabled, iconCls, shortcut));
  1073. };
  1074. /**
  1075. * Registers the given action under the given name.
  1076. */
  1077. Actions.prototype.put = function(name, action)
  1078. {
  1079. this.actions[name] = action;
  1080. return action;
  1081. };
  1082. /**
  1083. * Returns the action for the given name or null if no such action exists.
  1084. */
  1085. Actions.prototype.get = function(name)
  1086. {
  1087. return this.actions[name];
  1088. };
  1089. /**
  1090. * Constructs a new action for the given parameters.
  1091. */
  1092. function Action(label, funct, enabled, iconCls, shortcut)
  1093. {
  1094. mxEventSource.call(this);
  1095. this.label = label;
  1096. this.funct = funct;
  1097. this.enabled = (enabled != null) ? enabled : true;
  1098. this.iconCls = iconCls;
  1099. this.shortcut = shortcut;
  1100. this.visible = true;
  1101. };
  1102. // Action inherits from mxEventSource
  1103. mxUtils.extend(Action, mxEventSource);
  1104. /**
  1105. * Sets the enabled state of the action and fires a stateChanged event.
  1106. */
  1107. Action.prototype.setEnabled = function(value)
  1108. {
  1109. if (this.enabled != value)
  1110. {
  1111. this.enabled = value;
  1112. this.fireEvent(new mxEventObject('stateChanged'));
  1113. }
  1114. };
  1115. /**
  1116. * Sets the enabled state of the action and fires a stateChanged event.
  1117. */
  1118. Action.prototype.isEnabled = function()
  1119. {
  1120. return this.enabled;
  1121. };
  1122. /**
  1123. * Sets the enabled state of the action and fires a stateChanged event.
  1124. */
  1125. Action.prototype.setToggleAction = function(value)
  1126. {
  1127. this.toggleAction = value;
  1128. };
  1129. /**
  1130. * Sets the enabled state of the action and fires a stateChanged event.
  1131. */
  1132. Action.prototype.setSelectedCallback = function(funct)
  1133. {
  1134. this.selectedCallback = funct;
  1135. };
  1136. /**
  1137. * Sets the enabled state of the action and fires a stateChanged event.
  1138. */
  1139. Action.prototype.isSelected = function()
  1140. {
  1141. return this.selectedCallback();
  1142. };