Actions.js 37 KB

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