Actions.js 38 KB

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