Actions.js 37 KB

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