Actions.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074
  1. /**
  2. * Copyright (c) 2006-2020, JGraph Ltd
  3. * Copyright (c) 2006-2020, draw.io AG
  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() { graph.openLink(ui.getUrl()); });
  27. this.addAction('open...', function()
  28. {
  29. window.openNew = true;
  30. window.openKey = 'open';
  31. ui.openFile();
  32. });
  33. this.put('smartFit', new Action(mxResources.get('fitWindow') + ' / ' + mxResources.get('resetView'), function()
  34. {
  35. graph.popupMenuHandler.hideMenu();
  36. var scale = graph.view.scale;
  37. var sx = graph.container.scrollLeft;
  38. var sy = graph.container.scrollTop;
  39. var tx = graph.view.translate.x;
  40. var ty = graph.view.translate.y;
  41. var thresh = 5;
  42. ui.actions.get('resetView').funct();
  43. // Toggle scale if nothing has changed
  44. if (Math.abs(scale - graph.view.scale) < 0.00001 &&
  45. Math.abs(sx - graph.container.scrollLeft) < thresh &&
  46. Math.abs(sy - graph.container.scrollTop) < thresh &&
  47. tx == graph.view.translate.x &&
  48. ty == graph.view.translate.y)
  49. {
  50. ui.actions.get('fitWindow').funct();
  51. }
  52. }, null, null, 'Enter'));
  53. this.addAction('keyPressEnter', function()
  54. {
  55. if (graph.isSelectionEmpty())
  56. {
  57. ui.actions.get('smartFit').funct();
  58. }
  59. else if (graph.isEnabled())
  60. {
  61. graph.startEditingAtCell();
  62. }
  63. });
  64. this.addAction('import...', function()
  65. {
  66. window.openNew = false;
  67. window.openKey = 'import';
  68. // Closes dialog after open
  69. window.openFile = new OpenFile(mxUtils.bind(this, function()
  70. {
  71. ui.hideDialog();
  72. }));
  73. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  74. {
  75. try
  76. {
  77. var doc = mxUtils.parseXml(xml);
  78. editor.graph.setSelectionCells(editor.graph.importGraphModel(doc.documentElement));
  79. }
  80. catch (e)
  81. {
  82. mxUtils.alert(mxResources.get('invalidOrMissingFile') + ': ' + e.message);
  83. }
  84. }));
  85. // Removes openFile if dialog is closed
  86. ui.showDialog(new OpenDialog(this).container, 320, 220, true, true, function()
  87. {
  88. window.openFile = null;
  89. });
  90. }).isEnabled = isGraphEnabled;
  91. this.addAction('save', function() { ui.saveFile(false); }, null, null, Editor.ctrlKey + '+S').isEnabled = isGraphEnabled;
  92. this.addAction('saveAs...', function() { ui.saveFile(true); }, null, null, Editor.ctrlKey + '+Shift+S');
  93. this.addAction('export...', function() { ui.showDialog(new ExportDialog(ui).container, 300, 340, true, true); });
  94. this.addAction('editDiagram...', function()
  95. {
  96. var dlg = new EditDiagramDialog(ui);
  97. ui.showDialog(dlg.container, 620, 420, true, false);
  98. dlg.init();
  99. }).isEnabled = isGraphEnabled;
  100. this.addAction('pageSetup...', function() { ui.showDialog(new PageSetupDialog(ui).container, 320, 240, true, true); }).isEnabled = isGraphEnabled;
  101. this.addAction('print...', function() { ui.showPrintDialog(); }, null, 'sprite-print', Editor.ctrlKey + '+P');
  102. this.addAction('preview', function() { mxUtils.show(graph, null, 10, 10); });
  103. // Edit actions
  104. this.addAction('undo', function() { ui.undo(); }, null, 'sprite-undo', Editor.ctrlKey + '+Z');
  105. this.addAction('redo', function() { ui.redo(); }, null, 'sprite-redo', (!mxClient.IS_WIN) ? Editor.ctrlKey + '+Shift+Z' : Editor.ctrlKey + '+Y');
  106. this.addAction('cut', function()
  107. {
  108. var cells = null;
  109. try
  110. {
  111. cells = ui.copyXml();
  112. if (cells != null)
  113. {
  114. graph.removeCells(cells, false);
  115. }
  116. }
  117. catch (e)
  118. {
  119. // ignore
  120. }
  121. try
  122. {
  123. if (cells == null)
  124. {
  125. mxClipboard.cut(graph);
  126. }
  127. }
  128. catch (e)
  129. {
  130. ui.handleError(e);
  131. }
  132. }, null, 'sprite-cut', Editor.ctrlKey + '+X');
  133. this.addAction('copy', function()
  134. {
  135. try
  136. {
  137. ui.copyXml();
  138. }
  139. catch (e)
  140. {
  141. // ignore
  142. }
  143. try
  144. {
  145. mxClipboard.copy(graph);
  146. }
  147. catch (e)
  148. {
  149. ui.handleError(e);
  150. }
  151. }, null, 'sprite-copy', Editor.ctrlKey + '+C');
  152. this.addAction('paste', function()
  153. {
  154. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  155. {
  156. var done = false;
  157. try
  158. {
  159. if (Editor.enableNativeCipboard)
  160. {
  161. ui.readGraphModelFromClipboard(function(xml)
  162. {
  163. if (xml != null)
  164. {
  165. graph.getModel().beginUpdate();
  166. try
  167. {
  168. ui.pasteXml(xml, true);
  169. }
  170. finally
  171. {
  172. graph.getModel().endUpdate();
  173. }
  174. }
  175. else
  176. {
  177. mxClipboard.paste(graph);
  178. }
  179. })
  180. done = true;
  181. }
  182. }
  183. catch (e)
  184. {
  185. // ignore
  186. }
  187. if (!done)
  188. {
  189. mxClipboard.paste(graph);
  190. }
  191. }
  192. }, false, 'sprite-paste', Editor.ctrlKey + '+V');
  193. this.addAction('pasteHere', function(evt)
  194. {
  195. function pasteCellsHere(cells)
  196. {
  197. if (cells != null)
  198. {
  199. var includeEdges = true;
  200. for (var i = 0; i < cells.length && includeEdges; i++)
  201. {
  202. includeEdges = includeEdges && graph.model.isEdge(cells[i]);
  203. }
  204. var t = graph.view.translate;
  205. var s = graph.view.scale;
  206. var dx = t.x;
  207. var dy = t.y;
  208. var bb = null;
  209. if (cells.length == 1 && includeEdges)
  210. {
  211. var geo = graph.getCellGeometry(cells[0]);
  212. if (geo != null)
  213. {
  214. bb = geo.getTerminalPoint(true);
  215. }
  216. }
  217. bb = (bb != null) ? bb : graph.getBoundingBoxFromGeometry(cells, includeEdges);
  218. if (bb != null)
  219. {
  220. var x = Math.round(graph.snap(graph.popupMenuHandler.triggerX / s - dx));
  221. var y = Math.round(graph.snap(graph.popupMenuHandler.triggerY / s - dy));
  222. graph.cellsMoved(cells, x - bb.x, y - bb.y);
  223. }
  224. }
  225. };
  226. function fallback()
  227. {
  228. graph.getModel().beginUpdate();
  229. try
  230. {
  231. pasteCellsHere(mxClipboard.paste(graph));
  232. }
  233. finally
  234. {
  235. graph.getModel().endUpdate();
  236. }
  237. };
  238. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  239. {
  240. var done = false;
  241. try
  242. {
  243. if (Editor.enableNativeCipboard)
  244. {
  245. ui.readGraphModelFromClipboard(function(xml)
  246. {
  247. if (xml != null)
  248. {
  249. graph.getModel().beginUpdate();
  250. try
  251. {
  252. pasteCellsHere(ui.pasteXml(xml, true));
  253. }
  254. finally
  255. {
  256. graph.getModel().endUpdate();
  257. }
  258. }
  259. else
  260. {
  261. fallback();
  262. }
  263. })
  264. done = true;
  265. }
  266. }
  267. catch (e)
  268. {
  269. // ignore
  270. }
  271. if (!done)
  272. {
  273. fallback();
  274. }
  275. }
  276. });
  277. this.addAction('swap', function()
  278. {
  279. var cells = graph.getSelectionCells();
  280. if (cells.length == 2)
  281. {
  282. graph.swapShapes(cells[0], cells[1]);
  283. }
  284. });
  285. this.addAction('copySize', function()
  286. {
  287. var cell = graph.getSelectionCell();
  288. if (graph.isEnabled() && cell != null && graph.getModel().isVertex(cell))
  289. {
  290. var geo = graph.getCellGeometry(cell);
  291. if (geo != null)
  292. {
  293. ui.copiedSize = new mxRectangle(geo.x, geo.y, geo.width, geo.height);
  294. }
  295. }
  296. }, null, null, 'Alt+Shift+F');
  297. this.addAction('pasteSize', function()
  298. {
  299. if (graph.isEnabled() && !graph.isSelectionEmpty() && ui.copiedSize != null)
  300. {
  301. graph.getModel().beginUpdate();
  302. try
  303. {
  304. var cells = graph.getResizableCells(graph.getSelectionCells());
  305. for (var i = 0; i < cells.length; i++)
  306. {
  307. if (graph.getModel().isVertex(cells[i]))
  308. {
  309. var geo = graph.getCellGeometry(cells[i]);
  310. if (geo != null)
  311. {
  312. geo = geo.clone();
  313. geo.width = ui.copiedSize.width;
  314. geo.height = ui.copiedSize.height;
  315. graph.getModel().setGeometry(cells[i], geo);
  316. }
  317. }
  318. }
  319. }
  320. finally
  321. {
  322. graph.getModel().endUpdate();
  323. }
  324. }
  325. }, null, null, 'Alt+Shift+V');
  326. this.addAction('copyData', function()
  327. {
  328. var cell = graph.getSelectionCell() || graph.getModel().getRoot();
  329. if (graph.isEnabled() && cell != null)
  330. {
  331. var value = cell.cloneValue();
  332. if (value != null && !isNaN(value.nodeType))
  333. {
  334. ui.copiedValue = value;
  335. }
  336. }
  337. }, null, null, 'Alt+Shift+B');
  338. this.addAction('copyAsText', function()
  339. {
  340. var cell = graph.getSelectionCell();
  341. if (graph.isEnabled() && cell != null)
  342. {
  343. try
  344. {
  345. if (graph.isHtmlLabel(cell))
  346. {
  347. ui.writeHtmlToClipboard(graph.getLabel(cell), mxUtils.bind(this, function(e)
  348. {
  349. ui.handleError(e);
  350. }));
  351. }
  352. else
  353. {
  354. ui.writeTextToClipboard(graph.getLabel(cell), mxUtils.bind(this, function(e)
  355. {
  356. ui.handleError(e);
  357. }));
  358. }
  359. }
  360. catch (e)
  361. {
  362. ui.handleError(e);
  363. }
  364. }
  365. });
  366. this.addAction('pasteData', function(evt, trigger)
  367. {
  368. // Context menu click uses trigger, toolbar menu click uses evt
  369. var evt = (trigger != null) ? trigger : evt;
  370. var model = graph.getModel();
  371. function applyValue(cell, value)
  372. {
  373. var old = model.getValue(cell);
  374. value = cell.cloneValue(value);
  375. value.removeAttribute('placeholders');
  376. // Carries over placeholders and label properties
  377. if (old != null && !isNaN(old.nodeType))
  378. {
  379. value.setAttribute('placeholders', old.getAttribute('placeholders'));
  380. }
  381. if (evt == null || !mxEvent.isShiftDown(evt))
  382. {
  383. value.setAttribute('label', graph.convertValueToString(cell));
  384. }
  385. model.setValue(cell, value);
  386. };
  387. if (graph.isEnabled() && !graph.isSelectionEmpty() && ui.copiedValue != null)
  388. {
  389. model.beginUpdate();
  390. try
  391. {
  392. var cells = graph.getEditableCells(graph.getSelectionCells());
  393. if (cells.length == 0)
  394. {
  395. applyValue(model.getRoot(), ui.copiedValue);
  396. }
  397. else
  398. {
  399. for (var i = 0; i < cells.length; i++)
  400. {
  401. applyValue(cells[i], ui.copiedValue);
  402. }
  403. }
  404. }
  405. finally
  406. {
  407. model.endUpdate();
  408. }
  409. }
  410. }, null, null, 'Alt+Shift+E');
  411. function deleteCells(includeEdges)
  412. {
  413. // Cancels interactive operations
  414. graph.escape();
  415. var select = graph.deleteCells(graph.getDeletableCells(graph.getSelectionCells()), includeEdges);
  416. if (select != null)
  417. {
  418. graph.setSelectionCells(select);
  419. }
  420. };
  421. function deleteLabels()
  422. {
  423. if (!graph.isSelectionEmpty())
  424. {
  425. graph.getModel().beginUpdate();
  426. try
  427. {
  428. var cells = graph.getSelectionCells();
  429. for (var i = 0; i < cells.length; i++)
  430. {
  431. graph.cellLabelChanged(cells[i], '');
  432. }
  433. }
  434. finally
  435. {
  436. graph.getModel().endUpdate();
  437. }
  438. }
  439. };
  440. this.addAction('delete', function(evt, trigger)
  441. {
  442. // Context menu click uses trigger, toolbar menu click uses evt
  443. var evt = (trigger != null) ? trigger : evt;
  444. if (evt != null && mxEvent.isShiftDown(evt))
  445. {
  446. deleteLabels();
  447. }
  448. else
  449. {
  450. deleteCells(evt != null && (mxEvent.isControlDown(evt) ||
  451. mxEvent.isMetaDown(evt) || mxEvent.isAltDown(evt)));
  452. }
  453. }, null, null, 'Delete');
  454. this.addAction('deleteAll', function()
  455. {
  456. deleteCells(true);
  457. });
  458. this.addAction('deleteLabels', function()
  459. {
  460. deleteLabels();
  461. }, null, null, Editor.ctrlKey + '+Delete');
  462. this.addAction('duplicate', function()
  463. {
  464. try
  465. {
  466. graph.setSelectionCells(graph.duplicateCells());
  467. graph.scrollCellToVisible(graph.getSelectionCell());
  468. }
  469. catch (e)
  470. {
  471. ui.handleError(e);
  472. }
  473. }, null, null, Editor.ctrlKey + '+D');
  474. this.put('mergeCells', new Action(mxResources.get('merge'), function()
  475. {
  476. var ss = ui.getSelectionState();
  477. if (ss.mergeCell != null)
  478. {
  479. graph.getModel().beginUpdate();
  480. try
  481. {
  482. graph.setCellStyles('rowspan', ss.rowspan, [ss.mergeCell]);
  483. graph.setCellStyles('colspan', ss.colspan, [ss.mergeCell]);
  484. }
  485. finally
  486. {
  487. graph.getModel().endUpdate();
  488. }
  489. }
  490. }));
  491. this.put('unmergeCells', new Action(mxResources.get('unmerge'), function()
  492. {
  493. var ss = ui.getSelectionState();
  494. if (ss.cells.length > 0)
  495. {
  496. graph.getModel().beginUpdate();
  497. try
  498. {
  499. graph.setCellStyles('rowspan', null, ss.cells);
  500. graph.setCellStyles('colspan', null, ss.cells);
  501. }
  502. finally
  503. {
  504. graph.getModel().endUpdate();
  505. }
  506. }
  507. }));
  508. this.put('turn', new Action(mxResources.get('turn') + ' / ' + mxResources.get('reverse'), function(evt, trigger)
  509. {
  510. // Context menu click uses trigger, toolbar menu click uses evt
  511. var evt = (trigger != null) ? trigger : evt;
  512. graph.turnShapes(graph.getResizableCells(graph.getSelectionCells()),
  513. (evt != null) ? mxEvent.isShiftDown(evt) : false);
  514. }, null, null, (mxClient.IS_SF) ? null : Editor.ctrlKey + '+R'));
  515. this.put('selectConnections', new Action(mxResources.get('selectEdges'), function(evt)
  516. {
  517. var cell = graph.getSelectionCell();
  518. if (graph.isEnabled() && cell != null)
  519. {
  520. graph.addSelectionCells(graph.getEdges(cell));
  521. }
  522. }));
  523. this.addAction('selectVertices', function() { graph.selectVertices(null, true); }, null, null, Editor.ctrlKey + '+Shift+I');
  524. this.addAction('selectEdges', function() { graph.selectEdges(); }, null, null, Editor.ctrlKey + '+Shift+E');
  525. this.addAction('selectAll', function() { graph.selectAll(null, true); }, null, null, Editor.ctrlKey + '+A');
  526. this.addAction('selectNone', function() { graph.clearSelection(); }, null, null, Editor.ctrlKey + '+Shift+A');
  527. this.addAction('lockUnlock', function()
  528. {
  529. if (!graph.isSelectionEmpty())
  530. {
  531. graph.getModel().beginUpdate();
  532. try
  533. {
  534. var cells = graph.getSelectionCells();
  535. var style = graph.getCurrentCellStyle(graph.getSelectionCell());
  536. var value = (mxUtils.getValue(style, mxConstants.STYLE_EDITABLE, 1)) == 1 ? 0 : 1;
  537. graph.setCellStyles(mxConstants.STYLE_MOVABLE, value, cells);
  538. graph.setCellStyles(mxConstants.STYLE_RESIZABLE, value, cells);
  539. graph.setCellStyles(mxConstants.STYLE_ROTATABLE, value, cells);
  540. graph.setCellStyles(mxConstants.STYLE_DELETABLE, value, cells);
  541. graph.setCellStyles(mxConstants.STYLE_EDITABLE, value, cells);
  542. graph.setCellStyles('locked', (value == 1) ? 0 : 1, cells);
  543. graph.setCellStyles('connectable', value, cells);
  544. }
  545. finally
  546. {
  547. graph.getModel().endUpdate();
  548. }
  549. }
  550. }, null, null, Editor.ctrlKey + '+L');
  551. this.addAction('explore', function()
  552. {
  553. if (graph.model.isVertex(graph.getSelectionCell()))
  554. {
  555. Graph.exploreFromCell(ui.editor.graph, ui.editor.graph.getSelectionCell());
  556. }
  557. });
  558. // Navigation actions
  559. this.addAction('home', function() { graph.home(); }, null, null, 'Shift+Home');
  560. this.addAction('exitGroup', function() { graph.exitGroup(); }, null, null, Editor.ctrlKey + '+Shift+Home');
  561. this.addAction('enterGroup', function() { graph.enterGroup(); }, null, null, Editor.ctrlKey + '+Shift+End');
  562. this.addAction('collapse', function() { graph.foldCells(true); }, null, null, Editor.ctrlKey + '+Home');
  563. this.addAction('expand', function() { graph.foldCells(false); }, null, null, Editor.ctrlKey + '+End');
  564. // Arrange actions
  565. this.addAction('toFront', function()
  566. {
  567. graph.orderCells(false);
  568. }, null, null, Editor.ctrlKey + '+Shift+F');
  569. this.addAction('toBack', function()
  570. {
  571. graph.orderCells(true);
  572. }, null, null, Editor.ctrlKey + '+Shift+B');
  573. this.addAction('bringForward', function(evt)
  574. {
  575. graph.orderCells(false, null, true);
  576. }, null, null, Editor.ctrlKey + '+Alt+Shift+F');
  577. this.addAction('sendBackward', function(evt)
  578. {
  579. graph.orderCells(true, null, true);
  580. }, null, null, Editor.ctrlKey + '+Alt+Shift+B');
  581. this.addAction('group', function()
  582. {
  583. if (graph.isEnabled())
  584. {
  585. var cells = mxUtils.sortCells(graph.getSelectionCells(), true);
  586. if (cells.length == 1 && !graph.isTable(cells[0]) && !graph.isTableRow(cells[0]))
  587. {
  588. graph.setCellStyles('container', '1');
  589. }
  590. else
  591. {
  592. cells = graph.getCellsForGroup(cells);
  593. if (cells.length > 1)
  594. {
  595. graph.setSelectionCell(graph.groupCells(null, 0, cells));
  596. }
  597. }
  598. }
  599. }, null, null, Editor.ctrlKey + '+G');
  600. this.addAction('ungroup', function()
  601. {
  602. if (graph.isEnabled())
  603. {
  604. var cells = graph.getEditableCells(graph.getSelectionCells());
  605. graph.model.beginUpdate();
  606. try
  607. {
  608. var temp = graph.ungroupCells();
  609. // Clears container flag for remaining cells
  610. if (cells != null)
  611. {
  612. for (var i = 0; i < cells.length; i++)
  613. {
  614. if (graph.model.contains(cells[i]))
  615. {
  616. if (graph.model.getChildCount(cells[i]) == 0 &&
  617. graph.model.isVertex(cells[i]))
  618. {
  619. graph.setCellStyles('container', '0', [cells[i]]);
  620. }
  621. temp.push(cells[i]);
  622. }
  623. }
  624. }
  625. }
  626. finally
  627. {
  628. graph.model.endUpdate();
  629. }
  630. if (temp.length > 0)
  631. {
  632. graph.setSelectionCells(temp);
  633. }
  634. }
  635. }, null, null, Editor.ctrlKey + '+Shift+U');
  636. this.addAction('removeFromGroup', function()
  637. {
  638. if (graph.isEnabled())
  639. {
  640. var cells = graph.getSelectionCells();
  641. // Removes table rows and cells
  642. if (cells != null)
  643. {
  644. var temp = [];
  645. for (var i = 0; i < cells.length; i++)
  646. {
  647. if (!graph.isTableRow(cells[i]) &&
  648. !graph.isTableCell(cells[i]))
  649. {
  650. temp.push(cells[i]);
  651. }
  652. }
  653. graph.removeCellsFromParent(temp);
  654. if (temp.length > 0)
  655. {
  656. graph.scrollCellToVisible(temp[0]);
  657. }
  658. }
  659. }
  660. });
  661. // Adds action
  662. this.addAction('edit', function()
  663. {
  664. if (graph.isEnabled())
  665. {
  666. graph.startEditingAtCell();
  667. }
  668. }, null, null, 'F2/Enter');
  669. this.addAction('editData...', function()
  670. {
  671. var cell = graph.getSelectionCell() || graph.getModel().getRoot();
  672. ui.showDataDialog(cell);
  673. }, null, null, Editor.ctrlKey + '+M');
  674. this.addAction('editTooltip...', function()
  675. {
  676. var cell = graph.getSelectionCell();
  677. if (graph.isEnabled() && cell != null && graph.isCellEditable(cell))
  678. {
  679. var tooltip = '';
  680. if (mxUtils.isNode(cell.value))
  681. {
  682. var tmp = null;
  683. if (Graph.translateDiagram && Graph.diagramLanguage != null &&
  684. cell.value.hasAttribute('tooltip_' + Graph.diagramLanguage))
  685. {
  686. tmp = cell.value.getAttribute('tooltip_' + Graph.diagramLanguage);
  687. }
  688. if (tmp == null)
  689. {
  690. tmp = cell.value.getAttribute('tooltip');
  691. }
  692. if (tmp != null)
  693. {
  694. tooltip = tmp;
  695. }
  696. }
  697. var dlg = new TextareaDialog(ui, mxResources.get('editTooltip') + ':', tooltip, function(newValue)
  698. {
  699. graph.setTooltipForCell(cell, newValue);
  700. });
  701. ui.showDialog(dlg.container, 320, 200, true, true);
  702. dlg.init();
  703. }
  704. }, null, null, 'Alt+Shift+T');
  705. this.addAction('openLink', function()
  706. {
  707. var link = graph.getLinkForCell(graph.getSelectionCell());
  708. if (link != null)
  709. {
  710. graph.openLink(link);
  711. }
  712. });
  713. this.addAction('editLink...', function()
  714. {
  715. var cell = graph.getSelectionCell();
  716. if (graph.isEnabled() && cell != null && graph.isCellEditable(cell))
  717. {
  718. var value = graph.getLinkForCell(cell, true) || '';
  719. ui.showLinkDialog(value, mxResources.get('ok'), function(link, docs, linkTarget)
  720. {
  721. graph.getModel().beginUpdate();
  722. try
  723. {
  724. graph.setLinkForCell(cell, (link.length > 0) ? link : null);
  725. graph.setAttributeForCell(cell, 'linkTarget', linkTarget);
  726. }
  727. finally
  728. {
  729. graph.getModel().endUpdate();
  730. }
  731. }, true, graph.getLinkTargetForCell(cell));
  732. }
  733. }, null, null, 'Alt+Shift+L');
  734. this.put('insertImage', new Action(mxResources.get('image') + '...', function()
  735. {
  736. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  737. {
  738. graph.clearSelection();
  739. ui.actions.get('image').funct();
  740. }
  741. })).isEnabled = isGraphEnabled;
  742. this.addAction('editImage...', function()
  743. {
  744. ui.actions.get('image').funct();
  745. });
  746. this.put('insertLink', new Action(mxResources.get('link') + '...', function()
  747. {
  748. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  749. {
  750. ui.showLinkDialog('', mxResources.get('ok'), function(link, docs, linkTarget)
  751. {
  752. link = mxUtils.trim(link);
  753. if (link.length > 0)
  754. {
  755. var icon = null;
  756. var title = graph.getLinkTitle(link);
  757. if (docs != null && docs.length > 0)
  758. {
  759. icon = docs[0].iconUrl;
  760. title = docs[0].name || docs[0].type;
  761. title = title.charAt(0).toUpperCase() + title.substring(1);
  762. if (title.length > 30)
  763. {
  764. title = title.substring(0, 30) + '...';
  765. }
  766. }
  767. var linkCell = new mxCell(title, new mxGeometry(0, 0, 100, 40),
  768. 'fontColor=#0000EE;fontStyle=4;rounded=1;overflow=hidden;' + ((icon != null) ?
  769. 'shape=label;imageWidth=16;imageHeight=16;spacingLeft=26;align=left;image=' + icon :
  770. 'spacing=10;'));
  771. linkCell.vertex = true;
  772. var pt = graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry([linkCell], true));
  773. linkCell.geometry.x = pt.x;
  774. linkCell.geometry.y = pt.y;
  775. graph.setAttributeForCell(linkCell, 'linkTarget', linkTarget);
  776. graph.setLinkForCell(linkCell, link);
  777. graph.cellSizeUpdated(linkCell, true);
  778. graph.getModel().beginUpdate();
  779. try
  780. {
  781. linkCell = graph.addCell(linkCell);
  782. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', [linkCell]));
  783. }
  784. finally
  785. {
  786. graph.getModel().endUpdate();
  787. }
  788. graph.setSelectionCell(linkCell);
  789. graph.scrollCellToVisible(graph.getSelectionCell());
  790. }
  791. }, true);
  792. }
  793. }, null, null, 'L')).isEnabled = isGraphEnabled;
  794. this.addAction('link...', mxUtils.bind(this, function()
  795. {
  796. if (graph.isEnabled())
  797. {
  798. if (graph.cellEditor.isContentEditing())
  799. {
  800. var elt = graph.getSelectedElement();
  801. var link = graph.getParentByName(elt, 'A', graph.cellEditor.textarea);
  802. var oldValue = '';
  803. // Workaround for FF returning the outermost selected element after double
  804. // click on a DOM hierarchy with a link inside (but not as topmost element)
  805. if (link == null && elt != null && elt.getElementsByTagName != null)
  806. {
  807. // Finds all links in the selected DOM and uses the link
  808. // where the selection text matches its text content
  809. var links = elt.getElementsByTagName('a');
  810. for (var i = 0; i < links.length && link == null; i++)
  811. {
  812. if (links[i].textContent == elt.textContent)
  813. {
  814. link = links[i];
  815. }
  816. }
  817. }
  818. if (link != null && link.nodeName == 'A')
  819. {
  820. oldValue = link.getAttribute('href') || '';
  821. graph.selectNode(link);
  822. }
  823. var selState = graph.cellEditor.saveSelection();
  824. ui.showLinkDialog(oldValue, mxResources.get('ok'), mxUtils.bind(this, function(value)
  825. {
  826. graph.cellEditor.restoreSelection(selState);
  827. if (value != null)
  828. {
  829. graph.insertLink(value);
  830. }
  831. }));
  832. }
  833. else if (graph.isSelectionEmpty())
  834. {
  835. this.get('insertLink').funct();
  836. }
  837. else
  838. {
  839. this.get('editLink').funct();
  840. }
  841. }
  842. })).isEnabled = isGraphEnabled;
  843. this.addAction('autosize', function()
  844. {
  845. var cells = graph.getSelectionCells();
  846. if (cells != null)
  847. {
  848. graph.getModel().beginUpdate();
  849. try
  850. {
  851. for (var i = 0; i < cells.length; i++)
  852. {
  853. var cell = cells[i];
  854. if (graph.getModel().isVertex(cell))
  855. {
  856. if (graph.getModel().getChildCount(cell) > 0)
  857. {
  858. graph.updateGroupBounds([cell], 0, true);
  859. }
  860. else
  861. {
  862. graph.updateCellSize(cell);
  863. }
  864. }
  865. }
  866. }
  867. finally
  868. {
  869. graph.getModel().endUpdate();
  870. }
  871. }
  872. }, null, null, Editor.ctrlKey + '+Shift+Y');
  873. this.addAction('snapToGrid', function()
  874. {
  875. graph.snapCellsToGrid(graph.getSelectionCells(), graph.gridSize);
  876. });
  877. this.addAction('formattedText', function()
  878. {
  879. graph.stopEditing();
  880. var style = graph.getCommonStyle(graph.getSelectionCells());
  881. var value = (mxUtils.getValue(style, 'html', '0') == '1') ? null : '1';
  882. graph.getModel().beginUpdate();
  883. try
  884. {
  885. var cells = graph.getEditableCells(graph.getSelectionCells());
  886. for (var i = 0; i < cells.length; i++)
  887. {
  888. state = graph.getView().getState(cells[i]);
  889. if (state != null)
  890. {
  891. var html = mxUtils.getValue(state.style, 'html', '0');
  892. if (html == '1' && value == null)
  893. {
  894. graph.removeTextStyleForCell(state.cell);
  895. graph.setCellStyles('html', value, [cells[i]]);
  896. }
  897. else if (html == '0' && value == '1')
  898. {
  899. // Converts HTML tags to text
  900. var label = mxUtils.htmlEntities(graph.convertValueToString(state.cell), false);
  901. if (mxUtils.getValue(state.style, 'nl2Br', '1') != '0')
  902. {
  903. // Converts newlines in plain text to breaks in HTML
  904. // to match the plain text output
  905. label = label.replace(/\n/g, '<br/>');
  906. }
  907. graph.cellLabelChanged(state.cell, Graph.sanitizeHtml(label));
  908. graph.setCellStyles('html', value, [cells[i]]);
  909. }
  910. }
  911. }
  912. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['html'],
  913. 'values', [(value != null) ? value : '0'], 'cells', cells));
  914. }
  915. finally
  916. {
  917. graph.getModel().endUpdate();
  918. }
  919. });
  920. this.addAction('wordWrap', function()
  921. {
  922. var state = graph.getView().getState(graph.getSelectionCell());
  923. var value = 'wrap';
  924. graph.stopEditing();
  925. if (state != null && state.style[mxConstants.STYLE_WHITE_SPACE] == 'wrap')
  926. {
  927. value = null;
  928. }
  929. graph.setCellStyles(mxConstants.STYLE_WHITE_SPACE, value);
  930. });
  931. this.addAction('rotation', function()
  932. {
  933. var value = '0';
  934. var state = graph.getView().getState(graph.getSelectionCell());
  935. if (state != null)
  936. {
  937. value = state.style[mxConstants.STYLE_ROTATION] || value;
  938. }
  939. var dlg = new FilenameDialog(ui, value, mxResources.get('apply'), function(newValue)
  940. {
  941. if (newValue != null && newValue.length > 0)
  942. {
  943. graph.setCellStyles(mxConstants.STYLE_ROTATION, newValue);
  944. }
  945. }, mxResources.get('enterValue') + ' (' + mxResources.get('rotation') + ' 0-360)');
  946. ui.showDialog(dlg.container, 375, 80, true, true);
  947. dlg.init();
  948. });
  949. // View actions
  950. this.addAction('resetView', function()
  951. {
  952. graph.zoomTo(1);
  953. ui.resetScrollbars();
  954. }, null, null, 'Enter/Home');
  955. this.addAction('zoomIn', function(evt)
  956. {
  957. if (graph.isFastZoomEnabled())
  958. {
  959. graph.lazyZoom(true, true, ui.buttonZoomDelay);
  960. }
  961. else
  962. {
  963. graph.zoomIn();
  964. }
  965. }, null, null, Editor.ctrlKey + ' + / Alt+Mousewheel');
  966. this.addAction('zoomOut', function(evt)
  967. {
  968. if (graph.isFastZoomEnabled())
  969. {
  970. graph.lazyZoom(false, true, ui.buttonZoomDelay);
  971. }
  972. else
  973. {
  974. graph.zoomOut();
  975. }
  976. }, null, null, Editor.ctrlKey + ' - / Alt+Mousewheel');
  977. this.addAction('fitWindow', function()
  978. {
  979. if (graph.pageVisible && graph.isSelectionEmpty())
  980. {
  981. graph.fitPages();
  982. }
  983. else
  984. {
  985. ui.fitDiagramToWindow();
  986. }
  987. }, null, null, Editor.ctrlKey + '+Shift+H');
  988. this.addAction('fitPage', mxUtils.bind(this, function()
  989. {
  990. if (graph.pageVisible)
  991. {
  992. graph.fitPages(1);
  993. }
  994. else
  995. {
  996. this.get('pageView').funct();
  997. }
  998. }), null, null, Editor.ctrlKey + '+J');
  999. this.addAction('fitTwoPages', mxUtils.bind(this, function()
  1000. {
  1001. if (graph.pageVisible)
  1002. {
  1003. graph.fitPages(2);
  1004. }
  1005. else
  1006. {
  1007. this.get('pageView').funct();
  1008. }
  1009. }), null, null, Editor.ctrlKey + '+Shift+J');
  1010. this.addAction('fitPageWidth', mxUtils.bind(this, function()
  1011. {
  1012. if (graph.pageVisible)
  1013. {
  1014. graph.fitPages(1, true);
  1015. }
  1016. else
  1017. {
  1018. this.get('pageView').funct();
  1019. }
  1020. }));
  1021. this.put('customZoom', new Action(mxResources.get('custom') + '...', mxUtils.bind(this, function()
  1022. {
  1023. var dlg = new FilenameDialog(this.editorUi, parseInt(graph.getView().getScale() * 100),
  1024. mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  1025. {
  1026. var val = parseInt(newValue);
  1027. if (!isNaN(val) && val > 0)
  1028. {
  1029. graph.zoomTo(val / 100);
  1030. }
  1031. }), mxResources.get('zoom') + ' (%)');
  1032. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1033. dlg.init();
  1034. }), null, null, Editor.ctrlKey + '+0'));
  1035. this.addAction('pageScale...', mxUtils.bind(this, function()
  1036. {
  1037. var dlg = new FilenameDialog(this.editorUi, parseInt(graph.pageScale * 100),
  1038. mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  1039. {
  1040. var val = parseInt(newValue);
  1041. if (!isNaN(val) && val > 0)
  1042. {
  1043. var change = new ChangePageSetup(ui, null, null, null, val / 100);
  1044. change.ignoreColor = true;
  1045. change.ignoreImage = true;
  1046. graph.model.execute(change);
  1047. }
  1048. }), mxResources.get('pageScale') + ' (%)');
  1049. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1050. dlg.init();
  1051. }));
  1052. // Option actions
  1053. var action = null;
  1054. action = this.addAction('grid', function()
  1055. {
  1056. graph.setGridEnabled(!graph.isGridEnabled());
  1057. graph.defaultGridEnabled = graph.isGridEnabled();
  1058. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  1059. }, null, null, Editor.ctrlKey + '+Shift+G');
  1060. action.setToggleAction(true);
  1061. action.setSelectedCallback(function() { return graph.isGridEnabled(); });
  1062. action.setEnabled(false);
  1063. action = this.addAction('guides', function()
  1064. {
  1065. graph.graphHandler.guidesEnabled = !graph.graphHandler.guidesEnabled;
  1066. ui.fireEvent(new mxEventObject('guidesEnabledChanged'));
  1067. });
  1068. action.setToggleAction(true);
  1069. action.setSelectedCallback(function() { return graph.graphHandler.guidesEnabled; });
  1070. action.setEnabled(false);
  1071. action = this.addAction('animations', function()
  1072. {
  1073. Editor.enableAnimations = !Editor.enableAnimations;
  1074. ui.fireEvent(new mxEventObject('enableAnimationsChanged'));
  1075. });
  1076. action.setToggleAction(true);
  1077. action.setSelectedCallback(function() { return Editor.enableAnimations; });
  1078. action = this.addAction('tooltips', function()
  1079. {
  1080. graph.tooltipHandler.setEnabled(!graph.tooltipHandler.isEnabled());
  1081. ui.fireEvent(new mxEventObject('tooltipsEnabledChanged'));
  1082. });
  1083. action.setToggleAction(true);
  1084. action.setSelectedCallback(function() { return graph.tooltipHandler.isEnabled(); });
  1085. action = this.addAction('collapseExpand', function()
  1086. {
  1087. var change = new ChangePageSetup(ui);
  1088. change.ignoreColor = true;
  1089. change.ignoreImage = true;
  1090. change.foldingEnabled = !graph.foldingEnabled;
  1091. graph.model.execute(change);
  1092. });
  1093. action.setToggleAction(true);
  1094. action.setSelectedCallback(function() { return graph.foldingEnabled; });
  1095. action.isEnabled = isGraphEnabled;
  1096. action = this.addAction('pageView', mxUtils.bind(this, function()
  1097. {
  1098. ui.setPageVisible(!graph.pageVisible);
  1099. }));
  1100. action.setToggleAction(true);
  1101. action.setSelectedCallback(function() { return graph.pageVisible; });
  1102. action = this.addAction('connectionArrows', function()
  1103. {
  1104. graph.connectionArrowsEnabled = !graph.connectionArrowsEnabled;
  1105. ui.fireEvent(new mxEventObject('connectionArrowsChanged'));
  1106. }, null, null, 'Alt+Shift+A');
  1107. action.setToggleAction(true);
  1108. action.setSelectedCallback(function() { return graph.connectionArrowsEnabled; });
  1109. action = this.addAction('connectionPoints', function()
  1110. {
  1111. graph.setConnectable(!graph.connectionHandler.isEnabled());
  1112. ui.fireEvent(new mxEventObject('connectionPointsChanged'));
  1113. }, null, null, 'Alt+Shift+O');
  1114. action.setToggleAction(true);
  1115. action.setSelectedCallback(function() { return graph.connectionHandler.isEnabled(); });
  1116. action = this.addAction('copyConnect', function()
  1117. {
  1118. graph.connectionHandler.setCreateTarget(!graph.connectionHandler.isCreateTarget());
  1119. ui.fireEvent(new mxEventObject('copyConnectChanged'));
  1120. });
  1121. action.setToggleAction(true);
  1122. action.setSelectedCallback(function() { return graph.connectionHandler.isCreateTarget(); });
  1123. action.isEnabled = isGraphEnabled;
  1124. action = this.addAction('autosave', function()
  1125. {
  1126. ui.editor.setAutosave(!ui.editor.autosave);
  1127. });
  1128. action.setToggleAction(true);
  1129. action.setSelectedCallback(function() { return ui.editor.autosave; });
  1130. action.isEnabled = isGraphEnabled;
  1131. action.visible = false;
  1132. // Help actions
  1133. this.addAction('help', function()
  1134. {
  1135. var ext = '';
  1136. if (mxResources.isLanguageSupported(mxClient.language))
  1137. {
  1138. ext = '_' + mxClient.language;
  1139. }
  1140. graph.openLink(RESOURCES_PATH + '/help' + ext + '.html');
  1141. });
  1142. var showingAbout = false;
  1143. this.put('about', new Action(mxResources.get('about') + ' Graph Editor...', function()
  1144. {
  1145. if (!showingAbout)
  1146. {
  1147. ui.showDialog(new AboutDialog(ui).container, 320, 280, true, true, function()
  1148. {
  1149. showingAbout = false;
  1150. });
  1151. showingAbout = true;
  1152. }
  1153. }));
  1154. // Font style actions
  1155. var toggleFontStyle = mxUtils.bind(this, function(key, style, fn, shortcut)
  1156. {
  1157. return this.addAction(key, function()
  1158. {
  1159. if (fn != null && graph.cellEditor.isContentEditing())
  1160. {
  1161. fn();
  1162. }
  1163. else
  1164. {
  1165. graph.stopEditing(false);
  1166. graph.getModel().beginUpdate();
  1167. try
  1168. {
  1169. var cells = graph.getEditableCells(graph.getSelectionCells());
  1170. graph.toggleCellStyleFlags(mxConstants.STYLE_FONTSTYLE, style, cells);
  1171. // Removes bold and italic tags and CSS styles inside labels
  1172. if ((style & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD)
  1173. {
  1174. graph.updateLabelElements(cells, function(elt)
  1175. {
  1176. elt.style.fontWeight = null;
  1177. if (elt.nodeName == 'B')
  1178. {
  1179. graph.replaceElement(elt);
  1180. }
  1181. });
  1182. }
  1183. else if ((style & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC)
  1184. {
  1185. graph.updateLabelElements(cells, function(elt)
  1186. {
  1187. elt.style.fontStyle = null;
  1188. if (elt.nodeName == 'I')
  1189. {
  1190. graph.replaceElement(elt);
  1191. }
  1192. });
  1193. }
  1194. else if ((style & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE)
  1195. {
  1196. graph.updateLabelElements(cells, function(elt)
  1197. {
  1198. elt.style.textDecoration = null;
  1199. if (elt.nodeName == 'U')
  1200. {
  1201. graph.replaceElement(elt);
  1202. }
  1203. });
  1204. }
  1205. for (var i = 0; i < cells.length; i++)
  1206. {
  1207. if (graph.model.getChildCount(cells[i]) == 0)
  1208. {
  1209. graph.autoSizeCell(cells[i], false);
  1210. }
  1211. }
  1212. }
  1213. finally
  1214. {
  1215. graph.getModel().endUpdate();
  1216. }
  1217. }
  1218. }, null, null, shortcut);
  1219. });
  1220. toggleFontStyle('bold', mxConstants.FONT_BOLD, function() { document.execCommand('bold', false, null); }, Editor.ctrlKey + '+B');
  1221. toggleFontStyle('italic', mxConstants.FONT_ITALIC, function() { document.execCommand('italic', false, null); }, Editor.ctrlKey + '+I');
  1222. toggleFontStyle('underline', mxConstants.FONT_UNDERLINE, function() { document.execCommand('underline', false, null); }, Editor.ctrlKey + '+U');
  1223. // Color actions
  1224. this.addAction('fontColor...', function()
  1225. {
  1226. ui.menus.pickColor(mxConstants.STYLE_FONTCOLOR,
  1227. 'forecolor', '000000', 'default',
  1228. graph.shapeForegroundColor);
  1229. });
  1230. this.addAction('strokeColor...', function()
  1231. {
  1232. ui.menus.pickColor(mxConstants.STYLE_STROKECOLOR, null,
  1233. null, 'default', graph.shapeForegroundColor);
  1234. });
  1235. this.addAction('fillColor...', function()
  1236. {
  1237. ui.menus.pickColor(mxConstants.STYLE_FILLCOLOR, null,
  1238. null, 'default', graph.shapeBackgroundColor);
  1239. });
  1240. this.addAction('gradientColor...', function()
  1241. {
  1242. ui.menus.pickColor(mxConstants.STYLE_GRADIENTCOLOR, null,
  1243. null, 'default', graph.shapeForegroundColor);
  1244. });
  1245. this.addAction('backgroundColor...', function()
  1246. {
  1247. ui.menus.pickColor(mxConstants.STYLE_LABEL_BACKGROUNDCOLOR,
  1248. 'backcolor', null, 'default', graph.shapeBackgroundColor);
  1249. });
  1250. this.addAction('borderColor...', function()
  1251. {
  1252. ui.menus.pickColor(mxConstants.STYLE_LABEL_BORDERCOLOR,
  1253. null, null, 'default', graph.shapeForegroundColor);
  1254. });
  1255. // Format actions
  1256. this.addAction('removeFormat', function()
  1257. {
  1258. if (graph.isEnabled() && !graph.isSelectionEmpty() && !graph.isEditing())
  1259. {
  1260. graph.getModel().beginUpdate();
  1261. try
  1262. {
  1263. var cells = graph.getSelectionCells();
  1264. for (var i = 0; i < cells.length; i++)
  1265. {
  1266. graph.removeTextStyleForCell(cells[i], true);
  1267. }
  1268. }
  1269. finally
  1270. {
  1271. graph.getModel().endUpdate();
  1272. }
  1273. }
  1274. });
  1275. this.addAction('vertical', function() { ui.menus.toggleStyle(mxConstants.STYLE_HORIZONTAL, true); });
  1276. this.addAction('shadow', function() { ui.menus.toggleStyle(mxConstants.STYLE_SHADOW); });
  1277. this.addAction('solid', function()
  1278. {
  1279. graph.getModel().beginUpdate();
  1280. try
  1281. {
  1282. graph.setCellStyles(mxConstants.STYLE_DASHED, null);
  1283. graph.setCellStyles(mxConstants.STYLE_DASH_PATTERN, null);
  1284. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN],
  1285. 'values', [null, null], 'cells', graph.getSelectionCells()));
  1286. }
  1287. finally
  1288. {
  1289. graph.getModel().endUpdate();
  1290. }
  1291. });
  1292. this.addAction('dashed', function()
  1293. {
  1294. graph.getModel().beginUpdate();
  1295. try
  1296. {
  1297. graph.setCellStyles(mxConstants.STYLE_DASHED, '1');
  1298. graph.setCellStyles(mxConstants.STYLE_DASH_PATTERN, null);
  1299. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN],
  1300. 'values', ['1', null], 'cells', graph.getSelectionCells()));
  1301. }
  1302. finally
  1303. {
  1304. graph.getModel().endUpdate();
  1305. }
  1306. });
  1307. this.addAction('dotted', function()
  1308. {
  1309. graph.getModel().beginUpdate();
  1310. try
  1311. {
  1312. graph.setCellStyles(mxConstants.STYLE_DASHED, '1');
  1313. graph.setCellStyles(mxConstants.STYLE_DASH_PATTERN, '1 4');
  1314. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN],
  1315. 'values', ['1', '1 4'], 'cells', graph.getSelectionCells()));
  1316. }
  1317. finally
  1318. {
  1319. graph.getModel().endUpdate();
  1320. }
  1321. });
  1322. this.addAction('sharp', function()
  1323. {
  1324. graph.getModel().beginUpdate();
  1325. try
  1326. {
  1327. graph.setCellStyles(mxConstants.STYLE_ROUNDED, '0');
  1328. graph.setCellStyles(mxConstants.STYLE_CURVED, '0');
  1329. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  1330. 'values', ['0', '0'], 'cells', graph.getSelectionCells()));
  1331. }
  1332. finally
  1333. {
  1334. graph.getModel().endUpdate();
  1335. }
  1336. });
  1337. this.addAction('rounded', function()
  1338. {
  1339. graph.getModel().beginUpdate();
  1340. try
  1341. {
  1342. graph.setCellStyles(mxConstants.STYLE_ROUNDED, '1');
  1343. graph.setCellStyles(mxConstants.STYLE_CURVED, '0');
  1344. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  1345. 'values', ['1', '0'], 'cells', graph.getSelectionCells()));
  1346. }
  1347. finally
  1348. {
  1349. graph.getModel().endUpdate();
  1350. }
  1351. });
  1352. this.addAction('toggleRounded', function()
  1353. {
  1354. if (!graph.isSelectionEmpty() && graph.isEnabled())
  1355. {
  1356. graph.getModel().beginUpdate();
  1357. try
  1358. {
  1359. var cells = graph.getSelectionCells();
  1360. var style = graph.getCurrentCellStyle(cells[0]);
  1361. var value = (mxUtils.getValue(style, mxConstants.STYLE_ROUNDED, '0') == '1') ? '0' : '1';
  1362. graph.setCellStyles(mxConstants.STYLE_ROUNDED, value);
  1363. graph.setCellStyles(mxConstants.STYLE_CURVED, null);
  1364. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  1365. 'values', [value, '0'], 'cells', graph.getSelectionCells()));
  1366. }
  1367. finally
  1368. {
  1369. graph.getModel().endUpdate();
  1370. }
  1371. }
  1372. });
  1373. this.addAction('curved', function()
  1374. {
  1375. graph.getModel().beginUpdate();
  1376. try
  1377. {
  1378. graph.setCellStyles(mxConstants.STYLE_ROUNDED, '0');
  1379. graph.setCellStyles(mxConstants.STYLE_CURVED, '1');
  1380. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED],
  1381. 'values', ['0', '1'], 'cells', graph.getSelectionCells()));
  1382. }
  1383. finally
  1384. {
  1385. graph.getModel().endUpdate();
  1386. }
  1387. });
  1388. this.addAction('collapsible', function()
  1389. {
  1390. var state = graph.view.getState(graph.getSelectionCell());
  1391. var value = '1';
  1392. if (state != null && graph.getFoldingImage(state) != null)
  1393. {
  1394. value = '0';
  1395. }
  1396. graph.setCellStyles('collapsible', value);
  1397. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['collapsible'],
  1398. 'values', [value], 'cells', graph.getSelectionCells()));
  1399. });
  1400. this.addAction('editStyle...', mxUtils.bind(this, function()
  1401. {
  1402. var cells = graph.getEditableCells(graph.getSelectionCells());
  1403. if (cells != null && cells.length > 0)
  1404. {
  1405. var model = graph.getModel();
  1406. var dlg = new TextareaDialog(this.editorUi, mxResources.get('editStyle') + ':',
  1407. model.getStyle(cells[0]) || '', function(newValue)
  1408. {
  1409. if (newValue != null)
  1410. {
  1411. graph.setCellStyle(mxUtils.trim(newValue), cells);
  1412. }
  1413. }, null, null, 400, 220);
  1414. this.editorUi.showDialog(dlg.container, 420, 300, true, true);
  1415. dlg.init();
  1416. }
  1417. }), null, null, Editor.ctrlKey + '+E');
  1418. this.addAction('setAsDefaultStyle', function()
  1419. {
  1420. if (graph.isEnabled() && !graph.isSelectionEmpty())
  1421. {
  1422. ui.setDefaultStyle(graph.getSelectionCell());
  1423. }
  1424. }, null, null, Editor.ctrlKey + '+Shift+D');
  1425. this.addAction('clearDefaultStyle', function()
  1426. {
  1427. if (graph.isEnabled())
  1428. {
  1429. ui.clearDefaultStyle();
  1430. }
  1431. }, null, null, Editor.ctrlKey + '+Shift+R');
  1432. this.addAction('addWaypoint', function()
  1433. {
  1434. var cell = graph.getSelectionCell();
  1435. if (cell != null && graph.getModel().isEdge(cell))
  1436. {
  1437. var handler = editor.graph.selectionCellsHandler.getHandler(cell);
  1438. if (handler instanceof mxEdgeHandler)
  1439. {
  1440. var t = graph.view.translate;
  1441. var s = graph.view.scale;
  1442. var dx = t.x;
  1443. var dy = t.y;
  1444. var parent = graph.getModel().getParent(cell);
  1445. var pgeo = graph.getCellGeometry(parent);
  1446. while (graph.getModel().isVertex(parent) && pgeo != null)
  1447. {
  1448. dx += pgeo.x;
  1449. dy += pgeo.y;
  1450. parent = graph.getModel().getParent(parent);
  1451. pgeo = graph.getCellGeometry(parent);
  1452. }
  1453. var x = Math.round(graph.snap(graph.popupMenuHandler.triggerX / s - dx));
  1454. var y = Math.round(graph.snap(graph.popupMenuHandler.triggerY / s - dy));
  1455. handler.addPointAt(handler.state, x, y);
  1456. }
  1457. }
  1458. });
  1459. this.addAction('removeWaypoint', function()
  1460. {
  1461. // TODO: Action should run with "this" set to action
  1462. var rmWaypointAction = ui.actions.get('removeWaypoint');
  1463. if (rmWaypointAction.handler != null)
  1464. {
  1465. // NOTE: Popupevent handled and action updated in Menus.createPopupMenu
  1466. rmWaypointAction.handler.removePoint(rmWaypointAction.handler.state, rmWaypointAction.index);
  1467. }
  1468. });
  1469. this.addAction('clearAnchors', function()
  1470. {
  1471. var cells = graph.getSelectionCells();
  1472. if (cells != null)
  1473. {
  1474. cells = graph.getEditableCells(graph.addAllEdges(cells));
  1475. graph.getModel().beginUpdate();
  1476. try
  1477. {
  1478. for (var i = 0; i < cells.length; i++)
  1479. {
  1480. var cell = cells[i];
  1481. if (graph.getModel().isEdge(cell))
  1482. {
  1483. graph.setCellStyles(mxConstants.STYLE_EXIT_X, null, [cell]);
  1484. graph.setCellStyles(mxConstants.STYLE_EXIT_Y, null, [cell]);
  1485. graph.setCellStyles(mxConstants.STYLE_ENTRY_X, null, [cell]);
  1486. graph.setCellStyles(mxConstants.STYLE_ENTRY_Y, null, [cell]);
  1487. }
  1488. }
  1489. }
  1490. finally
  1491. {
  1492. graph.getModel().endUpdate();
  1493. }
  1494. }
  1495. });
  1496. this.addAction('clearWaypoints', function()
  1497. {
  1498. var cells = graph.getSelectionCells();
  1499. if (cells != null)
  1500. {
  1501. cells = graph.getEditableCells(graph.addAllEdges(cells));
  1502. graph.getModel().beginUpdate();
  1503. try
  1504. {
  1505. for (var i = 0; i < cells.length; i++)
  1506. {
  1507. var cell = cells[i];
  1508. if (graph.getModel().isEdge(cell))
  1509. {
  1510. var geo = graph.getCellGeometry(cell);
  1511. if (geo != null)
  1512. {
  1513. geo = geo.clone();
  1514. geo.points = null;
  1515. geo.x = 0;
  1516. geo.y = 0;
  1517. geo.offset = null;
  1518. graph.getModel().setGeometry(cell, geo);
  1519. }
  1520. }
  1521. }
  1522. }
  1523. finally
  1524. {
  1525. graph.getModel().endUpdate();
  1526. }
  1527. }
  1528. }, null, null, 'Alt+Shift+R');
  1529. action = this.addAction('subscript', mxUtils.bind(this, function()
  1530. {
  1531. if (graph.cellEditor.isContentEditing())
  1532. {
  1533. document.execCommand('subscript', false, null);
  1534. }
  1535. }), null, null, Editor.ctrlKey + '+,');
  1536. action = this.addAction('superscript', mxUtils.bind(this, function()
  1537. {
  1538. if (graph.cellEditor.isContentEditing())
  1539. {
  1540. document.execCommand('superscript', false, null);
  1541. }
  1542. }), null, null, Editor.ctrlKey + '+.');
  1543. action = this.addAction('decreaseFontSize', mxUtils.bind(this, function()
  1544. {
  1545. if (!graph.isSelectionEmpty())
  1546. {
  1547. var style = graph.getCurrentCellStyle(graph.getSelectionCell());
  1548. var size = mxUtils.getValue(style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  1549. graph.setCellStyles(mxConstants.STYLE_FONTSIZE, Math.max(1, size - 1),
  1550. graph.getSelectionCells());
  1551. }
  1552. }), null, null, Editor.ctrlKey + '+Shift + (Numpad)');
  1553. action = this.addAction('increaseFontSize', mxUtils.bind(this, function()
  1554. {
  1555. if (!graph.isSelectionEmpty())
  1556. {
  1557. var style = graph.getCurrentCellStyle(graph.getSelectionCell());
  1558. var size = mxUtils.getValue(style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  1559. graph.setCellStyles(mxConstants.STYLE_FONTSIZE, Math.min(100, size + 1),
  1560. graph.getSelectionCells());
  1561. }
  1562. }), null, null, Editor.ctrlKey + '+Shift - (Numpad)');
  1563. function applyClipPath(cell, clipPath, width, height, graph)
  1564. {
  1565. graph.getModel().beginUpdate();
  1566. try
  1567. {
  1568. var geo = graph.getCellGeometry(cell);
  1569. if (geo != null && width && height) //Comparing the ratio mostly will fail since it's float
  1570. {
  1571. var scale = width / height;
  1572. geo = geo.clone();
  1573. if (scale > 1)
  1574. {
  1575. geo.height = geo.width / scale;
  1576. }
  1577. else
  1578. {
  1579. geo.width = geo.height * scale;
  1580. }
  1581. graph.getModel().setGeometry(cell, geo);
  1582. }
  1583. graph.setCellStyles(mxConstants.STYLE_CLIP_PATH, clipPath, [cell]); //Set/unset clipPath
  1584. graph.setCellStyles(mxConstants.STYLE_ASPECT, 'fixed', [cell]);
  1585. }
  1586. finally
  1587. {
  1588. graph.getModel().endUpdate();
  1589. }
  1590. };
  1591. this.addAction('image...', function()
  1592. {
  1593. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1594. {
  1595. var title = mxResources.get('image') + ' (' + mxResources.get('url') + '):';
  1596. var state = graph.getView().getState(graph.getSelectionCell());
  1597. var value = '', clipPath = null;
  1598. if (state != null)
  1599. {
  1600. value = state.style[mxConstants.STYLE_IMAGE] || value;
  1601. clipPath = state.style[mxConstants.STYLE_CLIP_PATH] || clipPath;
  1602. }
  1603. var selectionState = graph.cellEditor.saveSelection();
  1604. ui.showImageDialog(title, value, function(newValue, w, h, clipPath, cW, cH)
  1605. {
  1606. // Inserts image into HTML text
  1607. if (graph.cellEditor.isContentEditing())
  1608. {
  1609. graph.cellEditor.restoreSelection(selectionState);
  1610. graph.insertImage(newValue, w, h);
  1611. }
  1612. else
  1613. {
  1614. var cells = graph.getSelectionCells();
  1615. if (newValue != null && (newValue.length > 0 || cells.length > 0))
  1616. {
  1617. var select = null;
  1618. graph.getModel().beginUpdate();
  1619. try
  1620. {
  1621. // Inserts new cell if no cell is selected
  1622. if (cells.length == 0)
  1623. {
  1624. cells = [graph.insertVertex(graph.getDefaultParent(), null, '', 0, 0, w, h,
  1625. 'shape=image;imageAspect=0;aspect=fixed;verticalLabelPosition=bottom;verticalAlign=top;')];
  1626. var pt = graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry(cells, true));
  1627. cells[0].geometry.x = pt.x;
  1628. cells[0].geometry.y = pt.y;
  1629. if (clipPath != null)
  1630. {
  1631. applyClipPath(cells[0], clipPath, cW, cH, graph);
  1632. }
  1633. select = cells;
  1634. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', select));
  1635. }
  1636. graph.setCellStyles(mxConstants.STYLE_IMAGE, (newValue.length > 0) ? newValue : null, cells);
  1637. // Sets shape only if not already shape with image (label or image)
  1638. var style = graph.getCurrentCellStyle(cells[0]);
  1639. if (style[mxConstants.STYLE_SHAPE] != 'image' && style[mxConstants.STYLE_SHAPE] != 'label')
  1640. {
  1641. graph.setCellStyles(mxConstants.STYLE_SHAPE, 'image', cells);
  1642. }
  1643. else if (newValue.length == 0)
  1644. {
  1645. graph.setCellStyles(mxConstants.STYLE_SHAPE, null, cells);
  1646. }
  1647. if (clipPath == null)
  1648. {
  1649. graph.setCellStyles(mxConstants.STYLE_CLIP_PATH, null, cells); //Reset clip path
  1650. }
  1651. if (w != null && h != null)
  1652. {
  1653. for (var i = 0; i < cells.length; i++)
  1654. {
  1655. var cell = cells[i];
  1656. if (graph.getCurrentCellStyle(cell)['expand'] != '0')
  1657. {
  1658. var geo = graph.getModel().getGeometry(cell);
  1659. if (geo != null)
  1660. {
  1661. geo = geo.clone();
  1662. geo.width = w;
  1663. geo.height = h;
  1664. graph.getModel().setGeometry(cell, geo);
  1665. }
  1666. }
  1667. if (clipPath != null)
  1668. {
  1669. applyClipPath(cell, clipPath, cW, cH, graph);
  1670. }
  1671. }
  1672. }
  1673. }
  1674. finally
  1675. {
  1676. graph.getModel().endUpdate();
  1677. }
  1678. if (select != null)
  1679. {
  1680. graph.setSelectionCells(select);
  1681. graph.scrollCellToVisible(select[0]);
  1682. }
  1683. }
  1684. }
  1685. }, graph.cellEditor.isContentEditing(), !graph.cellEditor.isContentEditing(), true, clipPath);
  1686. }
  1687. }).isEnabled = isGraphEnabled;
  1688. this.addAction('crop...', function()
  1689. {
  1690. var cell = graph.getSelectionCell();
  1691. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()) && cell != null)
  1692. {
  1693. var style = graph.getCurrentCellStyle(cell);
  1694. var value = style[mxConstants.STYLE_IMAGE], shape = style[mxConstants.STYLE_SHAPE];
  1695. if (!value || shape != 'image')
  1696. {
  1697. return; //Can only process an existing image
  1698. }
  1699. var dlg = new CropImageDialog(ui, value, style[mxConstants.STYLE_CLIP_PATH], function(clipPath, width, height)
  1700. {
  1701. applyClipPath(cell, clipPath, width, height, graph);
  1702. });
  1703. ui.showDialog(dlg.container, 300, 390, true, true);
  1704. }
  1705. }).isEnabled = isGraphEnabled;
  1706. action = this.addAction('layers', mxUtils.bind(this, function()
  1707. {
  1708. if (this.layersWindow == null)
  1709. {
  1710. // LATER: Check outline window for initial placement
  1711. this.layersWindow = new LayersWindow(ui, document.body.offsetWidth - 280, 120, 212, 200);
  1712. this.layersWindow.window.addListener('show', mxUtils.bind(this, function()
  1713. {
  1714. ui.fireEvent(new mxEventObject('layers'));
  1715. }));
  1716. this.layersWindow.window.addListener('hide', function()
  1717. {
  1718. ui.fireEvent(new mxEventObject('layers'));
  1719. });
  1720. this.layersWindow.window.setVisible(true);
  1721. ui.fireEvent(new mxEventObject('layers'));
  1722. this.layersWindow.init();
  1723. }
  1724. else
  1725. {
  1726. this.layersWindow.window.setVisible(!this.layersWindow.window.isVisible());
  1727. }
  1728. }), null, null, Editor.ctrlKey + '+Shift+L');
  1729. action.setToggleAction(true);
  1730. action.setSelectedCallback(mxUtils.bind(this, function() { return this.layersWindow != null && this.layersWindow.window.isVisible(); }));
  1731. action = this.addAction('format', mxUtils.bind(this, function()
  1732. {
  1733. ui.toggleFormatPanel();
  1734. }), null, null, Editor.ctrlKey + '+Shift+P');
  1735. action.setToggleAction(true);
  1736. action.setSelectedCallback(mxUtils.bind(this, function() { return ui.isFormatPanelVisible(); }));
  1737. action = this.addAction('outline', mxUtils.bind(this, function()
  1738. {
  1739. if (this.outlineWindow == null)
  1740. {
  1741. // LATER: Check layers window for initial placement
  1742. this.outlineWindow = new OutlineWindow(ui, document.body.offsetWidth - 260, 100, 180, 180);
  1743. this.outlineWindow.window.addListener('show', mxUtils.bind(this, function()
  1744. {
  1745. ui.fireEvent(new mxEventObject('outline'));
  1746. }));
  1747. this.outlineWindow.window.addListener('hide', function()
  1748. {
  1749. ui.fireEvent(new mxEventObject('outline'));
  1750. });
  1751. this.outlineWindow.window.setVisible(true);
  1752. ui.fireEvent(new mxEventObject('outline'));
  1753. }
  1754. else
  1755. {
  1756. this.outlineWindow.window.setVisible(!this.outlineWindow.window.isVisible());
  1757. }
  1758. }), null, null, Editor.ctrlKey + '+Shift+O');
  1759. action.setToggleAction(true);
  1760. action.setSelectedCallback(mxUtils.bind(this, function() { return this.outlineWindow != null && this.outlineWindow.window.isVisible(); }));
  1761. this.addAction('editConnectionPoints...', function()
  1762. {
  1763. var cell = graph.getSelectionCell();
  1764. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()) &&
  1765. cell != null && cell.geometry != null)
  1766. {
  1767. var dlg = new ConnectionPointsDialog(ui, cell);
  1768. ui.showDialog(dlg.container, 350, 450, true, false, function()
  1769. {
  1770. dlg.destroy();
  1771. });
  1772. dlg.init();
  1773. }
  1774. }, null, null, 'Alt+Shift+Q').isEnabled = isGraphEnabled;
  1775. };
  1776. /**
  1777. * Registers the given action under the given name.
  1778. */
  1779. Actions.prototype.addAction = function(key, funct, enabled, iconCls, shortcut)
  1780. {
  1781. var title;
  1782. if (key.substring(key.length - 3) == '...')
  1783. {
  1784. key = key.substring(0, key.length - 3);
  1785. title = mxResources.get(key) + '...';
  1786. }
  1787. else
  1788. {
  1789. title = mxResources.get(key);
  1790. }
  1791. return this.put(key, new Action(title, funct, enabled, iconCls, shortcut));
  1792. };
  1793. /**
  1794. * Registers the given action under the given name.
  1795. */
  1796. Actions.prototype.put = function(name, action)
  1797. {
  1798. this.actions[name] = action;
  1799. return action;
  1800. };
  1801. /**
  1802. * Returns the action for the given name or null if no such action exists.
  1803. */
  1804. Actions.prototype.get = function(name)
  1805. {
  1806. return this.actions[name];
  1807. };
  1808. /**
  1809. * Constructs a new action for the given parameters.
  1810. */
  1811. function Action(label, funct, enabled, iconCls, shortcut)
  1812. {
  1813. mxEventSource.call(this);
  1814. this.label = label;
  1815. this.funct = this.createFunction(funct);
  1816. this.enabled = (enabled != null) ? enabled : true;
  1817. this.iconCls = iconCls;
  1818. this.shortcut = shortcut;
  1819. this.visible = true;
  1820. };
  1821. // Action inherits from mxEventSource
  1822. mxUtils.extend(Action, mxEventSource);
  1823. /**
  1824. * Sets the enabled state of the action and fires a stateChanged event.
  1825. */
  1826. Action.prototype.createFunction = function(funct)
  1827. {
  1828. return funct;
  1829. };
  1830. /**
  1831. * Sets the enabled state of the action and fires a stateChanged event.
  1832. */
  1833. Action.prototype.setEnabled = function(value)
  1834. {
  1835. if (this.enabled != value)
  1836. {
  1837. this.enabled = value;
  1838. this.fireEvent(new mxEventObject('stateChanged'));
  1839. }
  1840. };
  1841. /**
  1842. * Sets the enabled state of the action and fires a stateChanged event.
  1843. */
  1844. Action.prototype.isEnabled = function()
  1845. {
  1846. return this.enabled;
  1847. };
  1848. /**
  1849. * Sets the enabled state of the action and fires a stateChanged event.
  1850. */
  1851. Action.prototype.setToggleAction = function(value)
  1852. {
  1853. this.toggleAction = value;
  1854. };
  1855. /**
  1856. * Sets the enabled state of the action and fires a stateChanged event.
  1857. */
  1858. Action.prototype.setSelectedCallback = function(funct)
  1859. {
  1860. this.selectedCallback = funct;
  1861. };
  1862. /**
  1863. * Sets the enabled state of the action and fires a stateChanged event.
  1864. */
  1865. Action.prototype.isSelected = function()
  1866. {
  1867. return this.selectedCallback();
  1868. };