Actions.js 37 KB

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