Actions.js 40 KB

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