Menus.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  1. /*
  2. * $Id: Menus.js,v 1.29 2014/02/11 13:56:10 gaudenz Exp $
  3. * Copyright (c) 2006-2014, JGraph Ltd
  4. */
  5. (function()
  6. {
  7. // Adds scrollbars for menus that exceed the page height
  8. var mxPopupMenuShowMenu = mxPopupMenu.prototype.showMenu;
  9. mxPopupMenu.prototype.showMenu = function()
  10. {
  11. mxPopupMenuShowMenu.apply(this, arguments);
  12. this.div.style.overflowY = 'auto';
  13. this.div.style.overflowX = 'hidden';
  14. var h0 = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
  15. this.div.style.maxHeight = (h0 - 10) + 'px';
  16. };
  17. Menus.prototype.addLinkToItem = function(item, href)
  18. {
  19. if (item != null)
  20. {
  21. var link = document.createElement('span');
  22. link.setAttribute('title', mxResources.get('help'));
  23. link.style.cssText = 'color:blue;text-decoration:underline;margin-left:12px;cursor:help;';
  24. var icon = document.createElement('img');
  25. icon.setAttribute('border', '0');
  26. icon.setAttribute('valign', 'bottom');
  27. icon.setAttribute('src', Editor.helpImage);
  28. link.appendChild(icon);
  29. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  30. {
  31. this.editorUi.menubar.hideMenu();
  32. window.open(href);
  33. mxEvent.consume(evt);
  34. }));
  35. item.firstChild.nextSibling.appendChild(link);
  36. }
  37. };
  38. var menusInit = Menus.prototype.init;
  39. Menus.prototype.init = function()
  40. {
  41. menusInit.apply(this, arguments);
  42. var editorUi = this.editorUi;
  43. var graph = editorUi.editor.graph;
  44. var isGraphEnabled = mxUtils.bind(graph, graph.isEnabled);
  45. var googleEnabled = ((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  46. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && mxClient.IS_SVG &&
  47. isLocalStorage && (document.documentMode == null || document.documentMode >= 10);
  48. var dropboxEnabled = ((urlParams['embed'] != '1' && urlParams['db'] != '0') || (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  49. mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
  50. var oneDriveEnabled = (window.location.hostname == 'www.draw.io' || window.location.hostname == 'test.draw.io' ||
  51. window.location.hostname == 'drive.draw.io' || window.location.hostname == 'legacy.draw.io') &&
  52. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  53. urlParams['od'] == '1')) && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  54. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10));
  55. if (!editorUi.isOffline())
  56. {
  57. var img = new Image();
  58. img.src = IMAGE_PATH + '/help.png';
  59. }
  60. editorUi.actions.addAction('new...', function()
  61. {
  62. var compact = editorUi.isOffline();
  63. var dlg = new NewDialog(editorUi, compact);
  64. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
  65. {
  66. if (cancel && editorUi.getCurrentFile() == null)
  67. {
  68. editorUi.showSplash();
  69. }
  70. });
  71. dlg.init();
  72. });
  73. editorUi.actions.get('print').funct = function()
  74. {
  75. editorUi.showDialog(new PrintDialog(editorUi).container, 320,
  76. (false && editorUi.pages != null && editorUi.pages.length > 1) ?
  77. 300 : 220, true, true);
  78. };
  79. editorUi.actions.addAction('open...', function()
  80. {
  81. editorUi.pickFile();
  82. });
  83. editorUi.actions.addAction('close', function()
  84. {
  85. editorUi.fileLoaded(null);
  86. });
  87. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  88. {
  89. var cells = graph.getSelectionCells();
  90. if (graph.getSelectionCount() == 1)
  91. {
  92. var cell = graph.getSelectionCell();
  93. var state = graph.view.getState(cell);
  94. if (state != null && state.shape != null && state.shape.stencil != null)
  95. {
  96. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  97. editorUi.showDialog(dlg.container, 640, 480, true, false);
  98. dlg.init();
  99. }
  100. }
  101. }));
  102. editorUi.actions.addAction('revisionHistory...', function()
  103. {
  104. var file = editorUi.getCurrentFile();
  105. if (file == null || (file.constructor != DriveFile && file.constructor != DropboxFile) ||
  106. (editorUi.drive == null && file.constructor == DriveFile) ||
  107. (editorUi.dropbox == null && file.constructor == DropboxFile))
  108. {
  109. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  110. }
  111. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  112. {
  113. if (file.constructor == DropboxFile)
  114. {
  115. // Limit is maximum number of entries to return
  116. editorUi.dropbox.client.revisions(file.stat.path, {limit: 100}, function(err, stats)
  117. {
  118. editorUi.spinner.stop();
  119. if (err == null)
  120. {
  121. var revs = [];
  122. for (var i = stats.length - 1; i >= 0; i--)
  123. {
  124. (function(stat)
  125. {
  126. revs.push({modifiedDate: stat.clientModifiedAt, fileSize: stat.size, getXml: function(success, error)
  127. {
  128. editorUi.dropbox.client.readFile('/' + file.stat.path, {versionTag: stat.versionTag}, mxUtils.bind(this, function(err2, data)
  129. {
  130. if (err2 == null)
  131. {
  132. success(data);
  133. }
  134. else
  135. {
  136. error(err2);
  137. }
  138. }));
  139. }, getUrl: function()
  140. {
  141. return editorUi.getUrl(window.location.pathname + '?rev=' + stat.versionTag + '&chrome=0&edit=_blank') + window.location.hash;
  142. }});
  143. })(stats[i]);
  144. }
  145. var dlg = new RevisionDialog(editorUi, revs);
  146. editorUi.showDialog(dlg.container, 640, 480, true, true);
  147. dlg.init();
  148. }
  149. else
  150. {
  151. editorUi.handleError(err);
  152. }
  153. });
  154. }
  155. // Google Drive File
  156. else
  157. {
  158. editorUi.drive.executeRequest(gapi.client.drive.revisions.list({'fileId': file.getId()}), function(resp)
  159. {
  160. editorUi.spinner.stop();
  161. for (var i = 0; i < resp.items.length; i++)
  162. {
  163. (function(item)
  164. {
  165. item.getXml = function(success, error)
  166. {
  167. // Workaround for vanished head revision is to use current head revision from descriptor
  168. editorUi.drive.executeRequest(gapi.client.drive.revisions.get({'fileId': file.getId(),
  169. 'revisionId': (resp.items[resp.items.length - 1] === item) ?
  170. file.desc.headRevisionId : item.id}), function(resp)
  171. {
  172. editorUi.drive.getXmlFile(resp, null, function(file2)
  173. {
  174. success(file2.getData());
  175. }, function(resp)
  176. {
  177. error(resp);
  178. });
  179. }, function(resp)
  180. {
  181. error(resp);
  182. });
  183. };
  184. item.getUrl = function()
  185. {
  186. return editorUi.getUrl(window.location.pathname + '?rev=' + item.id + '&chrome=0&edit=_blank') + window.location.hash;
  187. };
  188. })(resp.items[i]);
  189. }
  190. var dlg = new RevisionDialog(editorUi, resp.items);
  191. editorUi.showDialog(dlg.container, 640, 480, true, true);
  192. dlg.init();
  193. }, function(resp)
  194. {
  195. editorUi.spinner.stop();
  196. editorUi.handleError(resp);
  197. });
  198. }
  199. }
  200. });
  201. editorUi.actions.addAction('createRevision', function()
  202. {
  203. editorUi.actions.get('save').funct();
  204. }, null, null, 'Ctrl+S');
  205. editorUi.actions.addAction('upload...', function()
  206. {
  207. var file = editorUi.getCurrentFile();
  208. if (file != null)
  209. {
  210. // Data is pulled from global variable after tab loads
  211. // LATER: Change to use message passing to deal with potential cross-domain
  212. window.drawdata = editorUi.getFileData();
  213. var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  214. window.open(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
  215. ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
  216. 'title=' + encodeURIComponent(filename));
  217. }
  218. });
  219. if (typeof(MathJax) !== 'undefined')
  220. {
  221. var action = editorUi.actions.addAction('mathematicalTypesetting', function()
  222. {
  223. editorUi.setMathEnabled(!editorUi.isMathEnabled());
  224. });
  225. action.setToggleAction(true);
  226. action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
  227. action.isEnabled = isGraphEnabled;
  228. }
  229. if (isLocalStorage)
  230. {
  231. var action = editorUi.actions.addAction('showStartScreen', function()
  232. {
  233. mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
  234. mxSettings.save();
  235. });
  236. action.setToggleAction(true);
  237. action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
  238. }
  239. var autosaveAction = editorUi.actions.addAction('autosave', function()
  240. {
  241. editorUi.editor.setAutosave(!editorUi.editor.autosave);
  242. });
  243. autosaveAction.setToggleAction(true);
  244. autosaveAction.setSelectedCallback(function()
  245. {
  246. return autosaveAction.isEnabled() && editorUi.editor.autosave;
  247. });
  248. editorUi.actions.addAction('editGeometry...', function()
  249. {
  250. var cells = graph.getSelectionCells();
  251. var vertices = [];
  252. for (var i = 0; i < cells.length; i++)
  253. {
  254. if (graph.getModel().isVertex(cells[i]))
  255. {
  256. vertices.push(cells[i]);
  257. }
  258. }
  259. if (vertices.length > 0)
  260. {
  261. var dlg = new EditGeometryDialog(editorUi, vertices);
  262. editorUi.showDialog(dlg.container, 180, 180, true, true);
  263. dlg.init();
  264. }
  265. }, null, null, 'Ctrl+Shift+M');
  266. var copiedStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'fontStyle', 'align',
  267. 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
  268. 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
  269. 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight'];
  270. editorUi.actions.addAction('copyStyle', function()
  271. {
  272. var state = graph.view.getState(graph.getSelectionCell());
  273. if (graph.isEnabled() && state != null)
  274. {
  275. editorUi.copiedStyle = mxUtils.clone(state.style);
  276. // Handles special case for value "none"
  277. var cellStyle = graph.getModel().getStyle(state.cell);
  278. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  279. for (var j = 0; j < tokens.length; j++)
  280. {
  281. var tmp = tokens[j];
  282. var pos = tmp.indexOf('=');
  283. if (pos >= 0)
  284. {
  285. var key = tmp.substring(0, pos);
  286. var value = tmp.substring(pos + 1);
  287. if (editorUi.copiedStyle[key] == null && value == 'none')
  288. {
  289. editorUi.copiedStyle[key] = 'none';
  290. }
  291. }
  292. }
  293. editorUi.copiedEdgeStyle = null;
  294. }
  295. }, null, null, 'Ctrl+Shift+C');
  296. editorUi.actions.addAction('pasteStyle', function()
  297. {
  298. if (graph.isEnabled() && !graph.isSelectionEmpty() && editorUi.copiedStyle != null)
  299. {
  300. graph.getModel().beginUpdate();
  301. try
  302. {
  303. var cells = graph.getSelectionCells();
  304. for (var i = 0; i < cells.length; i++)
  305. {
  306. var state = graph.view.getState(cells[i]);
  307. for (var j = 0; j < copiedStyles.length; j++)
  308. {
  309. var key = copiedStyles[j];
  310. var value = editorUi.copiedStyle[key];
  311. if (state.style[key] != value)
  312. {
  313. graph.setCellStyles(key, value, [cells[i]]);
  314. }
  315. }
  316. }
  317. }
  318. finally
  319. {
  320. graph.getModel().endUpdate();
  321. }
  322. }
  323. }, null, null, 'Ctrl+Shift+V');
  324. editorUi.actions.put('pageBackgroundImage', new Action(mxResources.get('backgroundImage') + '...', function()
  325. {
  326. if (!editorUi.isOffline())
  327. {
  328. var apply = function(image)
  329. {
  330. editorUi.setBackgroundImage(image);
  331. };
  332. var dlg = new BackgroundImageDialog(editorUi, apply);
  333. editorUi.showDialog(dlg.container, 320, 170, true, true);
  334. dlg.init();
  335. }
  336. }));
  337. action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
  338. {
  339. graph.setShadowVisible(!graph.shadowVisible);
  340. }));
  341. action.setToggleAction(true);
  342. action.setSelectedCallback(function() { return graph.shadowVisible; });
  343. editorUi.actions.put('about', new Action(mxResources.get('aboutDrawio') + '...', function()
  344. {
  345. editorUi.showDialog(new AboutDialog(editorUi).container, 220, 300, true, true);
  346. }, null, null, 'F1'));
  347. editorUi.actions.addAction('userManual...', function()
  348. {
  349. window.open('https://support.draw.io/display/DO/Draw.io+Online+User+Manual');
  350. });
  351. editorUi.actions.addAction('support...', function()
  352. {
  353. window.open('https://support.draw.io/display/DO/draw.io+Online+Support');
  354. });
  355. editorUi.actions.addAction('exportOptionsDisabled...', function()
  356. {
  357. editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
  358. mxResources.get('exportOptionsDisabled'));
  359. });
  360. editorUi.actions.addAction('keyboardShortcuts...', function()
  361. {
  362. if (mxClient.IS_CHROMEAPP)
  363. {
  364. window.open('https://www.draw.io/shortcuts.svg');
  365. }
  366. else if (mxClient.IS_SVG)
  367. {
  368. window.open('shortcuts.svg');
  369. }
  370. else
  371. {
  372. window.open('https://www.draw.io/?chrome=0&url=https%3A%2F%2Fwww.draw.io%2Fshortcuts.svg');
  373. }
  374. });
  375. editorUi.actions.addAction('feedback...', function()
  376. {
  377. var dlg = new FeedbackDialog(editorUi);
  378. editorUi.showDialog(dlg.container, 610, 360, true, true);
  379. dlg.init();
  380. });
  381. editorUi.actions.addAction('quickStart...', function()
  382. {
  383. window.open('https://www.youtube.com/watch?v=8OaMWa4R1SE&t=1');
  384. });
  385. // Adds language menu to options only if localStorage is available for
  386. // storing the choice. We do not want to use cookies for older browsers.
  387. // Note that the URL param lang=XX is available for setting the language
  388. // in older browsers. URL param has precedence over the saved setting.
  389. if (mxClient.IS_CHROMEAPP || (isLocalStorage && urlParams['offline'] != '1'))
  390. {
  391. this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
  392. {
  393. var addLangItem = mxUtils.bind(this, function (id)
  394. {
  395. var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
  396. var item = null;
  397. if (lang != '')
  398. {
  399. item = menu.addItem(lang, null, mxUtils.bind(this, function()
  400. {
  401. mxSettings.setLanguage(id);
  402. mxSettings.save();
  403. // Shows dialog in new language
  404. mxClient.language = id;
  405. mxResources.loadDefaultBundle = false;
  406. mxResources.add(RESOURCE_BASE);
  407. editorUi.alert(mxResources.get('restartForChangeRequired'));
  408. }), parent);
  409. if (id == mxLanguage || (id == '' && mxLanguage == null))
  410. {
  411. menu.addCheckmark(item, Editor.checkmarkImage);
  412. }
  413. }
  414. return item;
  415. });
  416. var item = addLangItem('');
  417. menu.addSeparator(parent);
  418. // LATER: Sort menu by language name
  419. for(var langId in mxLanguageMap)
  420. {
  421. addLangItem(langId);
  422. }
  423. })));
  424. // Extends the menubar with the language menu
  425. if (uiTheme != 'atlas')
  426. {
  427. var menusCreateMenuBar = Menus.prototype.createMenubar;
  428. Menus.prototype.createMenubar = function(container)
  429. {
  430. var menubar = menusCreateMenuBar.apply(this, arguments);
  431. if (menubar != null)
  432. {
  433. var langMenu = this.get('language');
  434. if (langMenu != null)
  435. {
  436. var elt = menubar.addMenu('', langMenu.funct);
  437. elt.setAttribute('title', mxResources.get('language'));
  438. elt.style.width = '16px';
  439. elt.style.paddingTop = '2px';
  440. elt.style.paddingLeft = '4px';
  441. elt.innerHTML = '<div class="geIcon geSprite geSprite-globe"/>';
  442. elt.style.zIndex = '1';
  443. elt.style.position = 'absolute';
  444. elt.style.top = '2px';
  445. elt.style.right = '17px';
  446. elt.style.display = 'block';
  447. if (!mxClient.IS_VML)
  448. {
  449. mxUtils.setOpacity(elt, 60);
  450. }
  451. document.body.appendChild(elt);
  452. }
  453. }
  454. return menubar;
  455. };
  456. }
  457. }
  458. this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
  459. {
  460. if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
  461. {
  462. this.addMenuItems(menu, ['about']);
  463. }
  464. else
  465. {
  466. // No translation for menu item since help is english only
  467. var item = menu.addItem('Search', null, null, parent, null, null, false);
  468. var form = document.createElement('div');
  469. form.style.display = 'inline';
  470. form.innerHTML = ':<form style="display:inline;margin-left:8px;" id="rw_search_form"' +
  471. 'target="_blank" method="get" action="https://support.draw.io/dosearchsite.action">' +
  472. '<input id="rw_search_query" type="text" name="queryString" size="25"></form>';
  473. item.firstChild.nextSibling.appendChild(form);
  474. item.style.backgroundColor = 'whiteSmoke';
  475. item.style.cursor = 'default';
  476. var realForm = form.getElementsByTagName('form')[0]
  477. var input = form.getElementsByTagName('input')[0];
  478. if (input != null && realForm != null)
  479. {
  480. mxEvent.addListener(realForm, 'submit', function()
  481. {
  482. // Logs search terms for improving search results
  483. if (editorUi.enableLogging)
  484. {
  485. var img = new Image();
  486. img.src = 'log?severity=CONFIG&msg=helpsearch:' + encodeURIComponent(input.value) + '&v=' + encodeURIComponent(EditorUi.VERSION);
  487. }
  488. // Workaround for blocked submit on iOS/IE11
  489. window.setTimeout(function()
  490. {
  491. editorUi.menubar.hideMenu();
  492. }, 0);
  493. });
  494. mxEvent.addGestureListeners(item, function(evt)
  495. {
  496. if (document.activeElement != input)
  497. {
  498. input.focus();
  499. }
  500. mxEvent.consume(evt);
  501. }, function(evt)
  502. {
  503. mxEvent.consume(evt);
  504. }, function(evt)
  505. {
  506. mxEvent.consume(evt);
  507. });
  508. // Sets initial focus on input element
  509. window.setTimeout(function()
  510. {
  511. input.focus();
  512. }, 0);
  513. }
  514. this.addMenuItems(menu, ['-', 'quickStart', 'userManual', 'keyboardShortcuts', '-']);
  515. if (!mxClient.IS_CHROMEAPP)
  516. {
  517. this.addMenuItems(menu, ['feedback']);
  518. }
  519. this.addMenuItems(menu, ['support', '-', 'about']);
  520. }
  521. if (urlParams['test'] == '1')
  522. {
  523. // For showing the bounding box
  524. mxResources.parse('showBoundingBox=Show bounding box');
  525. this.editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  526. {
  527. var b = graph.getGraphBounds();
  528. var tr = graph.view.translate;
  529. var s = graph.view.scale;
  530. graph.insertVertex(parent, null, '', b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s, 'fillColor=none;strokeColor=red;');
  531. }));
  532. this.addMenuItems(menu, ['-', 'showBoundingBox'], parent);
  533. // For testing local XML export
  534. mxResources.parse('testXmlImageExport=XML Image Export');
  535. this.editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  536. {
  537. var bg = '#ffffff';
  538. var scale = 1;
  539. var b = 1;
  540. var imgExport = new mxImageExport();
  541. var bounds = graph.getGraphBounds();
  542. var vs = graph.view.scale;
  543. // New image export
  544. var xmlDoc = mxUtils.createXmlDocument();
  545. var root = xmlDoc.createElement('output');
  546. xmlDoc.appendChild(root);
  547. // Renders graph. Offset will be multiplied with state's scale when painting state.
  548. var xmlCanvas = new mxXmlCanvas2D(root);
  549. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  550. xmlCanvas.scale(scale / vs);
  551. var stateCounter = 0;
  552. var canvasSave = xmlCanvas.save;
  553. xmlCanvas.save = function()
  554. {
  555. stateCounter++;
  556. canvasSave.apply(this, arguments);
  557. };
  558. var canvasRestore = xmlCanvas.restore;
  559. xmlCanvas.restore = function()
  560. {
  561. stateCounter--;
  562. canvasRestore.apply(this, arguments);
  563. };
  564. var exportDrawShape = imgExport.drawShape;
  565. imgExport.drawShape = function(state)
  566. {
  567. mxLog.debug('entering shape', state, stateCounter);
  568. exportDrawShape.apply(this, arguments);
  569. mxLog.debug('leaving shape', state, stateCounter);
  570. };
  571. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  572. // Puts request data together
  573. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  574. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  575. mxLog.show();
  576. mxLog.debug(mxUtils.getXml(root));
  577. mxLog.debug('stateCounter', stateCounter);
  578. }));
  579. this.addMenuItems(menu, ['testXmlImageExport'], parent);
  580. mxResources.parse('animation=Animation');
  581. this.editorUi.actions.addAction('animation', mxUtils.bind(this, function()
  582. {
  583. if (this.animationWindow == null)
  584. {
  585. // LATER: Check outline window for initial placement
  586. this.animationWindow = new AnimationWindow(this.editorUi, (document.body.offsetWidth - 480) / 2,
  587. 120, 640, 480);
  588. this.animationWindow.window.setVisible(true);
  589. }
  590. else
  591. {
  592. this.animationWindow.window.setVisible(!this.animationWindow.window.isVisible());
  593. }
  594. }));
  595. this.addMenuItems(menu, ['animation'], parent);
  596. mxResources.parse('testShowRtModel=Show RT model');
  597. mxResources.parse('testDebugRtModel=Debug RT model');
  598. mxResources.parse('testDownloadRtModel=Download RT model');
  599. this.editorUi.actions.addAction('testShowRtModel', mxUtils.bind(this, function()
  600. {
  601. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  602. {
  603. console.log('bytesUsed', this.editorUi.getCurrentFile().realtime.rtModel.bytesUsed);
  604. console.log('root', this.editorUi.getCurrentFile().realtime.dumpRoot());
  605. this.editorUi.getCurrentFile().realtime.check();
  606. }
  607. }));
  608. this.editorUi.actions.addAction('testDebugRtModel', mxUtils.bind(this, function()
  609. {
  610. gapi.drive.realtime.debug();
  611. }));
  612. this.editorUi.actions.addAction('testDownloadRtModel', mxUtils.bind(this, function()
  613. {
  614. var file = this.editorUi.getCurrentFile();
  615. if (file != null && file.realtime != null &&
  616. editorUi.spinner.spin(document.body, mxResources.get('export')))
  617. {
  618. // LATER: Download full model dump with history
  619. var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
  620. file.getHash().substring(1) + '/realtime', null, 'GET');
  621. // Adds auth token
  622. req.setRequestHeaders = function(request)
  623. {
  624. mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
  625. var token = gapi.auth.getToken().access_token;
  626. request.setRequestHeader('authorization', 'Bearer ' + token);
  627. };
  628. req.send(function(req)
  629. {
  630. editorUi.spinner.stop();
  631. if (req.getStatus() == 200)
  632. {
  633. editorUi.saveLocalFile(req.getText(), 'realtime.txt', 'text/plain');
  634. }
  635. });
  636. }
  637. }));
  638. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  639. {
  640. this.addMenuItems(menu, ['-', 'testShowRtModel', 'testDebugRtModel', 'testDownloadRtModel'], parent);
  641. }
  642. mxResources.parse('testShowConsole=Show Console');
  643. this.editorUi.actions.addAction('testShowConsole', function()
  644. {
  645. if (!mxLog.isVisible())
  646. {
  647. mxLog.show();
  648. }
  649. else
  650. {
  651. mxLog.window.fit();
  652. }
  653. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  654. });
  655. this.addMenuItems(menu, ['-', 'testShowConsole']);
  656. }
  657. })));
  658. editorUi.actions.addAction('shapes...', function()
  659. {
  660. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  661. {
  662. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  663. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  664. }
  665. else
  666. {
  667. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  668. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  669. }
  670. });
  671. editorUi.actions.addAction('createShape...', function()
  672. {
  673. var file = editorUi.getCurrentFile();
  674. if (urlParams['embed'] == '1' || (file != null && file.isEditable()))
  675. {
  676. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  677. cell.vertex = true;
  678. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  679. editorUi.showDialog(dlg.container, 640, 480, true, false);
  680. dlg.init();
  681. }
  682. });
  683. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  684. {
  685. var dlg = new EmbedHtmlDialog(editorUi);
  686. editorUi.showDialog(dlg.container, 550, 400, true, true);
  687. dlg.init();
  688. }));
  689. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  690. {
  691. var dlg = new EmbedSvgDialog(editorUi);
  692. editorUi.showDialog(dlg.container, 550, 400, true, true);
  693. dlg.init();
  694. }));
  695. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  696. {
  697. var dlg = new IframeDialog(editorUi);
  698. editorUi.showDialog(dlg.container, 420, 210, true, true);
  699. dlg.init();
  700. }));
  701. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  702. {
  703. var dlg = new IframeDialog(editorUi, false, true);
  704. editorUi.showDialog(dlg.container, 420, 210, true, true);
  705. dlg.init();
  706. }));
  707. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  708. {
  709. var dlg = new EmbedSvgDialog(editorUi, true);
  710. editorUi.showDialog(dlg.container, 550, 400, true, true);
  711. dlg.init();
  712. }));
  713. editorUi.actions.put('liveImage', new Action('Live image...', function()
  714. {
  715. var dlg = new IframeDialog(editorUi, true);
  716. editorUi.showDialog(dlg.container, 420, 180, true, true);
  717. dlg.init();
  718. }));
  719. editorUi.actions.addAction('googleDocs...', function()
  720. {
  721. window.open('http://docsaddon.draw.io');
  722. });
  723. editorUi.actions.addAction('googleSites...', function()
  724. {
  725. var dlg = new GoogleSitesDialog(editorUi);
  726. editorUi.showDialog(dlg.container, 420, 256, true, true);
  727. dlg.init();
  728. });
  729. // Adds plugins menu item in file menu only if localStorage is available for
  730. // storing the plugins.
  731. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  732. {
  733. var action = editorUi.actions.addAction('scratchpad', function()
  734. {
  735. editorUi.toggleScratchpad();
  736. });
  737. action.setToggleAction(true);
  738. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  739. editorUi.actions.addAction('plugins...', function()
  740. {
  741. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 156, true, false);
  742. });
  743. }
  744. var action = editorUi.actions.addAction('search', function()
  745. {
  746. var visible = editorUi.sidebar.isEntryVisible('search');
  747. editorUi.sidebar.showPalette('search', !visible);
  748. if (isLocalStorage)
  749. {
  750. mxSettings.settings.search = !visible;
  751. mxSettings.save();
  752. }
  753. });
  754. action.setToggleAction(true);
  755. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  756. if (urlParams['embed'] == '1')
  757. {
  758. editorUi.actions.get('save').funct = function(exit)
  759. {
  760. if (graph.isEditing())
  761. {
  762. graph.stopEditing();
  763. }
  764. var data = mxUtils.getXml(editorUi.editor.getGraphXml());
  765. if (urlParams['proto'] == 'json')
  766. {
  767. var msg = editorUi.createLoadMessage('save');
  768. msg.xml = data;
  769. if (exit)
  770. {
  771. msg.exit = true;
  772. }
  773. data = JSON.stringify(msg);
  774. }
  775. var parent = window.opener || window.parent;
  776. parent.postMessage(data, '*');
  777. if (urlParams['modified'] != '0')
  778. {
  779. editorUi.editor.modified = false;
  780. }
  781. };
  782. editorUi.actions.addAction('saveAndExit', function()
  783. {
  784. editorUi.actions.get('save').funct(true);
  785. });
  786. editorUi.actions.addAction('exit', function()
  787. {
  788. var fn = function()
  789. {
  790. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  791. modified: editorUi.editor.modified}) : '';
  792. var parent = window.opener || window.parent;
  793. parent.postMessage(msg, '*');
  794. }
  795. if (!editorUi.editor.modified)
  796. {
  797. fn();
  798. }
  799. else
  800. {
  801. editorUi.confirm(mxResources.get('allChangesLost'), fn);
  802. }
  803. });
  804. }
  805. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  806. {
  807. if (editorUi.isExportToCanvas())
  808. {
  809. menu.addItem(mxResources.get('image') + '...', null, mxUtils.bind(this, function()
  810. {
  811. editorUi.showExportDialog(false, mxResources.get('export'),
  812. 'https://support.draw.io/display/DO/Exporting+Files',
  813. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable)
  814. {
  815. var val = parseInt(scale);
  816. if (!isNaN(val) && val > 0)
  817. {
  818. this.editorUi.exportImage(val / 100, transparentBackground, ignoreSelection, addShadow, editable);
  819. }
  820. }));
  821. }), parent);
  822. }
  823. // Disabled for standalone mode in iOS because new tab cannot be closed
  824. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  825. {
  826. menu.addItem(mxResources.get('image') + '...', null, mxUtils.bind(this, function()
  827. {
  828. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  829. {
  830. this.editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection);
  831. }));
  832. }), parent);
  833. }
  834. menu.addItem(mxResources.get('formatSvg') + '...', null, mxUtils.bind(this, function()
  835. {
  836. editorUi.showExportDialog(true, mxResources.get('export'),
  837. 'https://support.draw.io/display/DO/Exporting+Files',
  838. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable, embedImages)
  839. {
  840. var val = parseInt(scale);
  841. if (!isNaN(val) && val > 0)
  842. {
  843. this.editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection, addShadow, editable, embedImages);
  844. }
  845. }));
  846. }), parent);
  847. menu.addSeparator(parent);
  848. menu.addItem(mxResources.get('formatHtmlEmbedded') + '...', null, mxUtils.bind(this, function()
  849. {
  850. this.editorUi.downloadFile('html');
  851. }), parent);
  852. // Redirects export to PDF to print in Chrome App
  853. if (mxClient.IS_CHROMEAPP)
  854. {
  855. menu.addItem(mxResources.get('formatPdf') + '...', null, this.editorUi.actions.get('print').funct, parent);
  856. }
  857. // Disabled for standalone mode in iOS because new tab cannot be closed
  858. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  859. {
  860. menu.addItem(mxResources.get('formatPdf') + '...', null, mxUtils.bind(this, function()
  861. {
  862. var content = document.createElement('div');
  863. content.style.padding = '6px';
  864. var cb2 = document.createElement('input');
  865. cb2.style.marginRight = '8px';
  866. cb2.setAttribute('type', 'checkbox');
  867. if (graph.isSelectionEmpty())
  868. {
  869. cb2.setAttribute('disabled', 'disabled');
  870. }
  871. content.appendChild(cb2);
  872. mxUtils.write(content, mxResources.get('selectionOnly'));
  873. mxUtils.br(content);
  874. var cb = document.createElement('input');
  875. cb.setAttribute('type', 'checkbox');
  876. cb.style.marginTop = '16px';
  877. cb.style.marginRight = '8px';
  878. if (!graph.pageVisible)
  879. {
  880. cb.setAttribute('checked', 'checked');
  881. cb.defaultChecked = true;
  882. }
  883. content.appendChild(cb);
  884. mxUtils.write(content, mxResources.get('crop'));
  885. var dlg = new CustomDialog(editorUi, content, mxUtils.bind(this, function()
  886. {
  887. var prev = graph.pageVisible;
  888. graph.pageVisible = !cb.checked;
  889. this.editorUi.downloadFile('pdf', null, null, !cb2.checked);
  890. graph.pageVisible = prev;
  891. }), null, mxResources.get('export'));
  892. this.editorUi.showDialog(dlg.container, 300, 120, true, true);
  893. }), parent);
  894. }
  895. menu.addSeparator(parent);
  896. menu.addItem(mxResources.get('formatXml') + '...', null, mxUtils.bind(this, function()
  897. {
  898. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  899. var content = document.createElement('div');
  900. content.style.padding = '6px';
  901. var cb2 = document.createElement('input');
  902. cb2.style.marginRight = '8px';
  903. cb2.setAttribute('type', 'checkbox');
  904. if (graph.isSelectionEmpty())
  905. {
  906. cb2.setAttribute('disabled', 'disabled');
  907. }
  908. content.appendChild(cb2);
  909. mxUtils.write(content, mxResources.get('selectionOnly'));
  910. var cb = document.createElement('input');
  911. cb.setAttribute('type', 'checkbox');
  912. cb.setAttribute('checked', 'checked');
  913. cb.defaultChecked = true;
  914. cb.style.marginRight = '8px';
  915. cb.style.marginTop = '16px';
  916. if (noPages)
  917. {
  918. mxUtils.br(content);
  919. content.appendChild(cb);
  920. mxUtils.write(content, mxResources.get('compressed'));
  921. }
  922. var dlg = new CustomDialog(editorUi, content, mxUtils.bind(this, function()
  923. {
  924. editorUi.downloadFile('xml', !cb.checked, null, !cb2.checked);
  925. }), null, mxResources.get('export'));
  926. editorUi.showDialog(dlg.container, 300, (noPages) ? 120 : 80, true, true);
  927. }), parent);
  928. if (!editorUi.isOffline())
  929. {
  930. menu.addSeparator(parent);
  931. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  932. }
  933. })));
  934. this.editorUi.actions.addAction('chatWindowTitle...', mxUtils.bind(this.editorUi, this.editorUi.toggleChat));
  935. this.put('importFrom', new Menu(function(menu, parent)
  936. {
  937. function importFile(device)
  938. {
  939. if (device && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  940. {
  941. var input = document.createElement('input');
  942. input.setAttribute('type', 'file');
  943. mxEvent.addListener(input, 'change', function()
  944. {
  945. if (input.files != null)
  946. {
  947. // Using null for position will disable crop of input file
  948. editorUi.importFiles(input.files, null, null, editorUi.maxImageSize);
  949. }
  950. });
  951. input.click();
  952. }
  953. else
  954. {
  955. window.openNew = false;
  956. window.openKey = 'import';
  957. var prevValue = Editor.useLocalStorage;
  958. Editor.useLocalStorage = !device;
  959. // Closes dialog after open
  960. window.openFile = new OpenFile(function(cancel)
  961. {
  962. editorUi.hideDialog(cancel);
  963. });
  964. window.openFile.setConsumer(function(xml, filename)
  965. {
  966. graph.setSelectionCells(editorUi.importXml(xml));
  967. });
  968. // Removes openFile if dialog is closed
  969. editorUi.showDialog(new OpenDialog(editorUi).container, 360, 220, true, true, function()
  970. {
  971. window.openFile = null;
  972. });
  973. // Extends dialog close to show splash screen
  974. var dlg = editorUi.dialog;
  975. var dlgClose = dlg.close;
  976. editorUi.dialog.close = function(cancel)
  977. {
  978. Editor.useLocalStorage = prevValue;
  979. dlgClose.apply(dlg, arguments);
  980. if (cancel && editorUi.getCurrentFile() == null && urlParams['embed'] != '1')
  981. {
  982. editorUi.showSplash();
  983. }
  984. };
  985. }
  986. };
  987. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  988. {
  989. if (mime == 'image/png')
  990. {
  991. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  992. {
  993. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  994. {
  995. var s = Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2));
  996. editorUi.importFile(data, mime, 0, 0, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  997. {
  998. editorUi.spinner.stop();
  999. graph.setSelectionCells(cells);
  1000. });
  1001. }), true);
  1002. }));
  1003. }
  1004. else
  1005. {
  1006. editorUi.importFile(data, mime, 0, 0, 0, 0, filename, function(cells)
  1007. {
  1008. editorUi.spinner.stop();
  1009. graph.setSelectionCells(cells);
  1010. });
  1011. }
  1012. });
  1013. function pickFileFromService(service)
  1014. {
  1015. // Drive requires special arguments for libraries and bypassing realtime
  1016. service.pickFile(function(id)
  1017. {
  1018. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1019. {
  1020. if (service == editorUi.dropbox)
  1021. {
  1022. var mime = (/(\.png)$/i.test(id)) ? 'image/png' : 'text/xml';
  1023. editorUi.loadUrl(id, function(data)
  1024. {
  1025. doImportFile(data, mime, id);
  1026. },
  1027. function(resp)
  1028. {
  1029. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1030. }, mime == 'image/png');
  1031. }
  1032. else
  1033. {
  1034. // NOTE The third argument in getFile says denyConvert to match
  1035. // the existing signature in the original DriveClient which has
  1036. // as slightly different semantic, but works the same way.
  1037. service.getFile(id, function(file)
  1038. {
  1039. var mime = (/(\.png)$/i.test(file.getTitle())) ? 'image/png' : 'text/xml';
  1040. doImportFile(file.getData(), mime, file.getTitle());
  1041. },
  1042. function(resp)
  1043. {
  1044. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1045. }, true);
  1046. }
  1047. }
  1048. }, true);
  1049. };
  1050. if (editorUi.drive != null)
  1051. {
  1052. // Requires special arguments for libraries and realtime
  1053. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1054. {
  1055. pickFileFromService(editorUi.drive);
  1056. }, parent);
  1057. }
  1058. else if (googleEnabled)
  1059. {
  1060. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1061. {
  1062. // do nothing
  1063. }, parent, null, false);
  1064. }
  1065. if (editorUi.dropbox != null)
  1066. {
  1067. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1068. {
  1069. pickFileFromService(editorUi.dropbox);
  1070. }, parent);
  1071. }
  1072. else if (dropboxEnabled)
  1073. {
  1074. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1075. {
  1076. // do nothing
  1077. }, parent, null, false);
  1078. }
  1079. if (editorUi.oneDrive != null)
  1080. {
  1081. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1082. {
  1083. pickFileFromService(editorUi.oneDrive);
  1084. }, parent);
  1085. }
  1086. else if (oneDriveEnabled)
  1087. {
  1088. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1089. {
  1090. // do nothing
  1091. }, parent, null, false);
  1092. }
  1093. menu.addSeparator(parent);
  1094. if (isLocalStorage && urlParams['browser'] != '0')
  1095. {
  1096. menu.addItem(mxResources.get('browser') + '...', null, function()
  1097. {
  1098. importFile(false);
  1099. }, parent);
  1100. }
  1101. if (!mxClient.IS_IOS)
  1102. {
  1103. menu.addItem(mxResources.get('device') + '...', null, function()
  1104. {
  1105. importFile(true);
  1106. }, parent);
  1107. }
  1108. if (!editorUi.isOffline())
  1109. {
  1110. menu.addSeparator(parent);
  1111. menu.addItem(mxResources.get('url') + '...', null, function()
  1112. {
  1113. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1114. {
  1115. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1116. {
  1117. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1118. // Uses proxy to avoid CORS issues
  1119. editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1120. {
  1121. doImportFile(data, mime, fileUrl);
  1122. },
  1123. function ()
  1124. {
  1125. editorUi.spinner.stop();
  1126. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1127. }, mime == 'image/png');
  1128. }
  1129. }, mxResources.get('url'));
  1130. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1131. dlg.init();
  1132. }, parent);
  1133. }
  1134. })).isEnabled = isGraphEnabled;
  1135. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1136. {
  1137. var item = menu.addItem(mxResources.get('kennedy'), null, function()
  1138. {
  1139. mxSettings.setUi('');
  1140. mxSettings.save();
  1141. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1142. }, parent);
  1143. if (uiTheme != 'atlas')
  1144. {
  1145. menu.addCheckmark(item, Editor.checkmarkImage);
  1146. }
  1147. item = menu.addItem(mxResources.get('atlas'), null, function()
  1148. {
  1149. mxSettings.setUi('atlas');
  1150. mxSettings.save();
  1151. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1152. }, parent);
  1153. if (uiTheme == 'atlas')
  1154. {
  1155. menu.addCheckmark(item, Editor.checkmarkImage);
  1156. }
  1157. })));
  1158. this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  1159. {
  1160. var file = this.editorUi.getCurrentFile();
  1161. if (file != null)
  1162. {
  1163. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  1164. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  1165. {
  1166. if (title != null && title.length > 0 && file != null && this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  1167. {
  1168. // Delete old file, save new file in dropbox if autosize is enabled
  1169. file.rename(title, mxUtils.bind(this, function(resp)
  1170. {
  1171. this.editorUi.spinner.stop();
  1172. }),
  1173. mxUtils.bind(this, function(resp)
  1174. {
  1175. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  1176. }));
  1177. }
  1178. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  1179. mxResources.get('diagramName') : null, function(name)
  1180. {
  1181. if (name != null && name.length > 0)
  1182. {
  1183. return true;
  1184. }
  1185. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  1186. return false;
  1187. });
  1188. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1189. dlg.init();
  1190. }
  1191. })).isEnabled = isGraphEnabled;
  1192. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  1193. {
  1194. var file = editorUi.getCurrentFile();
  1195. if (file != null)
  1196. {
  1197. var title = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  1198. // Handles extension
  1199. var extension = '';
  1200. var dot = title.lastIndexOf('.');
  1201. if (dot >= 0)
  1202. {
  1203. extension = title.substring(dot);
  1204. title = title.substring(0, dot);
  1205. }
  1206. title = mxResources.get('copyOf', [title]) + extension;
  1207. if (file.constructor == DriveFile)
  1208. {
  1209. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  1210. {
  1211. // Mode is "download" if Create button is pressed, means use Google Drive
  1212. if (mode == 'download')
  1213. {
  1214. mode = App.MODE_GOOGLE;
  1215. }
  1216. if (newTitle != null && newTitle.length > 0)
  1217. {
  1218. if (mode == App.MODE_GOOGLE)
  1219. {
  1220. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  1221. {
  1222. // Makes sure the latest XML is in the file
  1223. file.save(false, mxUtils.bind(this, function()
  1224. {
  1225. // Saveas does not update the file descriptor in Google Drive
  1226. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  1227. {
  1228. editorUi.spinner.stop();
  1229. var url = editorUi.getUrl();
  1230. window.openWindow(url + '#G' + resp.id, null, mxUtils.bind(this, function()
  1231. {
  1232. window.location.hash = 'G' + resp.id;
  1233. }));
  1234. }), mxUtils.bind(this, function(resp)
  1235. {
  1236. editorUi.handleError(resp);
  1237. }));
  1238. }), mxUtils.bind(this, function(resp)
  1239. {
  1240. editorUi.handleError(resp);
  1241. }));
  1242. }
  1243. }
  1244. else
  1245. {
  1246. this.editorUi.createFile(newTitle, this.editorUi.getFileData(true), null, mode);
  1247. }
  1248. }
  1249. }), mxUtils.bind(this, function()
  1250. {
  1251. editorUi.hideDialog();
  1252. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  1253. null, null, null, true);
  1254. editorUi.showDialog(dlg.container, 420, 380, true, true);
  1255. dlg.init();
  1256. }
  1257. else
  1258. {
  1259. // Creates a copy with no predefined storage
  1260. editorUi.editor.editAsNew(editorUi.getEditBlankXml(), title);
  1261. }
  1262. }
  1263. }));
  1264. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  1265. {
  1266. var file = editorUi.getCurrentFile();
  1267. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  1268. {
  1269. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  1270. {
  1271. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  1272. {
  1273. file.move(folderId, mxUtils.bind(this, function(resp)
  1274. {
  1275. editorUi.spinner.stop();
  1276. }), mxUtils.bind(this, function(resp)
  1277. {
  1278. editorUi.handleError(resp);
  1279. }));
  1280. }
  1281. }));
  1282. }
  1283. }));
  1284. editorUi.actions.addAction('imgur...', mxUtils.bind(this, function()
  1285. {
  1286. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToImgur), function(imgurId)
  1287. {
  1288. window.open('https://imgur.com/' + imgurId);
  1289. });
  1290. }));
  1291. editorUi.actions.addAction('facebook...', mxUtils.bind(this, function()
  1292. {
  1293. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToImgur), function(imgurId)
  1294. {
  1295. window.open('https://www.facebook.com/sharer.php?p[url]=' + encodeURIComponent('https://imgur.com/' + imgurId) +
  1296. '&p[images][0]=' + encodeURIComponent(imgurId + '.png'));
  1297. });
  1298. }));
  1299. editorUi.actions.addAction('twitter...', mxUtils.bind(this, function()
  1300. {
  1301. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToImgur), function(imgurId)
  1302. {
  1303. window.open('https://twitter.com/intent/tweet?text=' +
  1304. encodeURIComponent('Check out the diagram I made with draw.io') +
  1305. '&via=drawio&hashtags=madewithdrawio&url=' +
  1306. encodeURIComponent('https://imgur.com/' + imgurId));
  1307. });
  1308. }));
  1309. editorUi.actions.addAction('github...', mxUtils.bind(this, function()
  1310. {
  1311. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToGithub));
  1312. }));
  1313. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  1314. {
  1315. // Disable publish in IE9- due to CORS problem when getting image from server
  1316. // which requires cross-domain XHR but XDomainRequest has no custom headers
  1317. // to set content type to form-encoded-data which is needed for the export.
  1318. if (document.documentMode == null || document.documentMode >= 10)
  1319. {
  1320. if (typeof XMLHttpRequest !== 'undefined')
  1321. {
  1322. this.addMenuItems(menu, ['github'], parent);
  1323. }
  1324. this.addMenuItems(menu, ['twitter'], parent);
  1325. this.addMenuItems(menu, ['facebook'], parent);
  1326. this.addMenuItems(menu, ['imgur'], parent);
  1327. }
  1328. if (!navigator.standalone && !editorUi.isOffline())
  1329. {
  1330. this.addMenuItems(menu, ['publishLink'], parent);
  1331. }
  1332. })));
  1333. editorUi.actions.put('offline', new Action(mxResources.get('offline') + '...', function()
  1334. {
  1335. window.open('http://www.draw.io/app')
  1336. }));
  1337. editorUi.actions.put('chromeApp', new Action(mxResources.get('chromeApp') + '...', function()
  1338. {
  1339. window.open('https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla')
  1340. }));
  1341. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  1342. {
  1343. var file = this.editorUi.getCurrentFile();
  1344. if (file != null)
  1345. {
  1346. this.editorUi.drive.showPermissions(file.getId());
  1347. }
  1348. }));
  1349. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  1350. {
  1351. if (urlParams['test'] == '1')
  1352. {
  1353. this.addMenuItems(menu, ['liveImage', '-'], parent);
  1354. }
  1355. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  1356. if (!navigator.standalone && !editorUi.isOffline())
  1357. {
  1358. this.addMenuItems(menu, ['embedIframe'], parent);
  1359. }
  1360. if (!editorUi.isOffline())
  1361. {
  1362. this.addMenuItems(menu, ['-', 'googleSites', 'googleDocs'], parent);
  1363. }
  1364. })));
  1365. // Overrides arrange menu to add insert submenu
  1366. this.put('arrange', new Menu(mxUtils.bind(this, function(menu, parent)
  1367. {
  1368. this.addMenuItems(menu, ['toFront', 'toBack', '-'], parent);
  1369. this.addSubmenu('direction', menu, parent);
  1370. this.addMenuItems(menu, ['turn', '-'], parent);
  1371. this.addSubmenu('align', menu, parent);
  1372. this.addSubmenu('distribute', menu, parent);
  1373. menu.addSeparator(parent);
  1374. this.addSubmenu('navigation', menu, parent);
  1375. this.addSubmenu('insert', menu, parent);
  1376. this.addSubmenu('layout', menu, parent);
  1377. this.addMenuItems(menu, ['-', 'group', 'ungroup', 'removeFromGroup', '-', 'editGeometry', 'clearWaypoints', 'autosize'], parent);
  1378. })));
  1379. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree', '-', 'organic', 'circle', '-', 'fromText'];
  1380. var addInsertItem = function(menu, parent, title, method)
  1381. {
  1382. menu.addItem(title, null, mxUtils.bind(this, function()
  1383. {
  1384. if (method == 'fromText')
  1385. {
  1386. var dlg = new ParseDialog(editorUi, title);
  1387. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1388. editorUi.dialog.container.style.overflow = 'auto';
  1389. dlg.init();
  1390. }
  1391. else
  1392. {
  1393. var dlg = new CreateGraphDialog(editorUi, title, method);
  1394. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1395. // Executed after dialog is added to dom
  1396. dlg.init();
  1397. }
  1398. }), parent);
  1399. };
  1400. editorUi.actions.addAction('insertText', function()
  1401. {
  1402. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1403. {
  1404. var pt = graph.getInsertPoint();
  1405. var cell = new mxCell('Text', new mxGeometry(pt.x, pt.y, 40, 20),
  1406. 'text;html=1;resizable=0;autosize=1;align=left;verticalAlign=top;spacingTop=-4;points=[];');
  1407. cell.vertex = true;
  1408. graph.startEditingAtCell(graph.addCell(cell));
  1409. }
  1410. }, null, null, 'Ctrl+Shift+X').isEnabled = isGraphEnabled;
  1411. editorUi.actions.addAction('insertRectangle', function()
  1412. {
  1413. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1414. {
  1415. var pt = graph.getInsertPoint();
  1416. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 120, 60), 'whiteSpace=wrap;html=1;');
  1417. cell.vertex = true;
  1418. graph.setSelectionCell(graph.addCell(cell));
  1419. }
  1420. }, null, null, 'Ctrl+K').isEnabled = isGraphEnabled;
  1421. editorUi.actions.addAction('insertEllipse', function()
  1422. {
  1423. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1424. {
  1425. var pt = graph.getInsertPoint();
  1426. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 80, 80), 'ellipse;whiteSpace=wrap;html=1;');
  1427. cell.vertex = true;
  1428. graph.setSelectionCell(graph.addCell(cell));
  1429. }
  1430. }, null, null, 'Ctrl+Shift+K').isEnabled = isGraphEnabled;
  1431. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  1432. {
  1433. this.addMenuItems(menu, ['insertText', 'insertRectangle', 'insertEllipse', '-', 'insertLink', 'insertImage'], parent);
  1434. menu.addSeparator(parent);
  1435. for (var i = 0; i < methods.length; i++)
  1436. {
  1437. if (methods[i] == '-')
  1438. {
  1439. menu.addSeparator(parent);
  1440. }
  1441. else
  1442. {
  1443. addInsertItem(menu, parent, mxResources.get(methods[i]), methods[i]);
  1444. }
  1445. }
  1446. })));
  1447. this.put('openRecent', new Menu(function(menu, parent)
  1448. {
  1449. var recent = editorUi.getRecent();
  1450. var count = 0;
  1451. if (recent != null)
  1452. {
  1453. for (var i = 0; i < recent.length; i++)
  1454. {
  1455. (function(entry)
  1456. {
  1457. count++;
  1458. var modeKey = entry.mode;
  1459. // Google and oneDrive use different keys
  1460. if (modeKey == App.MODE_GOOGLE)
  1461. {
  1462. modeKey = 'googleDrive';
  1463. }
  1464. else if (modeKey == App.MODE_ONEDRIVE)
  1465. {
  1466. modeKey = 'oneDrive';
  1467. }
  1468. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  1469. {
  1470. editorUi.loadFile(entry.id);
  1471. }, parent);
  1472. })(recent[i]);
  1473. }
  1474. menu.addSeparator(parent);
  1475. }
  1476. menu.addItem(mxResources.get('reset'), null, function()
  1477. {
  1478. editorUi.resetRecent();
  1479. }, parent);
  1480. }));
  1481. this.put('openFrom', new Menu(function(menu, parent)
  1482. {
  1483. if (editorUi.drive != null)
  1484. {
  1485. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1486. {
  1487. editorUi.pickFile(App.MODE_GOOGLE);
  1488. }, parent);
  1489. }
  1490. else if (googleEnabled)
  1491. {
  1492. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1493. {
  1494. // do nothing
  1495. }, parent, null, false);
  1496. }
  1497. if (editorUi.dropbox != null)
  1498. {
  1499. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1500. {
  1501. editorUi.pickFile(App.MODE_DROPBOX);
  1502. }, parent);
  1503. }
  1504. else if (dropboxEnabled)
  1505. {
  1506. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1507. {
  1508. // do nothing
  1509. }, parent, null, false);
  1510. }
  1511. if (editorUi.oneDrive != null)
  1512. {
  1513. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1514. {
  1515. editorUi.pickFile(App.MODE_ONEDRIVE);
  1516. }, parent);
  1517. }
  1518. else if (oneDriveEnabled)
  1519. {
  1520. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1521. {
  1522. // do nothing
  1523. }, parent, null, false);
  1524. }
  1525. menu.addSeparator(parent);
  1526. if (isLocalStorage && urlParams['browser'] != '0')
  1527. {
  1528. menu.addItem(mxResources.get('browser') + '...', null, function()
  1529. {
  1530. editorUi.pickFile(App.MODE_BROWSER);
  1531. }, parent);
  1532. }
  1533. if (!mxClient.IS_IOS)
  1534. {
  1535. menu.addItem(mxResources.get('device') + '...', null, function()
  1536. {
  1537. editorUi.pickFile(App.MODE_DEVICE);
  1538. }, parent);
  1539. }
  1540. if (!editorUi.isOffline())
  1541. {
  1542. menu.addSeparator(parent);
  1543. menu.addItem(mxResources.get('url') + '...', null, function()
  1544. {
  1545. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1546. {
  1547. if (fileUrl != null && fileUrl.length > 0)
  1548. {
  1549. var url = editorUi.getUrl(window.location.pathname + '?url=' + encodeURIComponent(fileUrl));
  1550. if (editorUi.getCurrentFile() == null)
  1551. {
  1552. window.location.href = url;
  1553. }
  1554. else
  1555. {
  1556. window.openWindow(url);
  1557. }
  1558. }
  1559. }, mxResources.get('url'));
  1560. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1561. dlg.init();
  1562. }, parent);
  1563. }
  1564. }));
  1565. this.put('newLibrary', new Menu(function(menu, parent)
  1566. {
  1567. if (editorUi.drive != null)
  1568. {
  1569. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1570. {
  1571. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  1572. }, parent);
  1573. }
  1574. else if (googleEnabled)
  1575. {
  1576. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1577. {
  1578. // do nothing
  1579. }, parent, null, false);
  1580. }
  1581. if (editorUi.dropbox != null)
  1582. {
  1583. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1584. {
  1585. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  1586. }, parent);
  1587. }
  1588. else if (dropboxEnabled)
  1589. {
  1590. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1591. {
  1592. // do nothing
  1593. }, parent, null, false);
  1594. }
  1595. if (editorUi.oneDrive != null)
  1596. {
  1597. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1598. {
  1599. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  1600. }, parent);
  1601. }
  1602. else if (oneDriveEnabled)
  1603. {
  1604. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1605. {
  1606. // do nothing
  1607. }, parent, null, false);
  1608. }
  1609. menu.addSeparator(parent);
  1610. if (isLocalStorage && urlParams['browser'] != '0')
  1611. {
  1612. menu.addItem(mxResources.get('browser') + '...', null, function()
  1613. {
  1614. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  1615. }, parent);
  1616. }
  1617. if (!mxClient.IS_IOS)
  1618. {
  1619. menu.addItem(mxResources.get('device') + '...', null, function()
  1620. {
  1621. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  1622. }, parent);
  1623. }
  1624. }));
  1625. this.put('openLibraryFrom', new Menu(function(menu, parent)
  1626. {
  1627. if (editorUi.drive != null)
  1628. {
  1629. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1630. {
  1631. editorUi.pickLibrary(App.MODE_GOOGLE);
  1632. }, parent);
  1633. }
  1634. else if (googleEnabled)
  1635. {
  1636. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1637. {
  1638. // do nothing
  1639. }, parent, null, false);
  1640. }
  1641. if (editorUi.dropbox != null)
  1642. {
  1643. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1644. {
  1645. editorUi.pickLibrary(App.MODE_DROPBOX);
  1646. }, parent);
  1647. }
  1648. else if (dropboxEnabled)
  1649. {
  1650. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1651. {
  1652. // do nothing
  1653. }, parent, null, false);
  1654. }
  1655. if (editorUi.oneDrive != null)
  1656. {
  1657. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1658. {
  1659. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  1660. }, parent);
  1661. }
  1662. else if (oneDriveEnabled)
  1663. {
  1664. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1665. {
  1666. // do nothing
  1667. }, parent, null, false);
  1668. }
  1669. menu.addSeparator(parent);
  1670. if (isLocalStorage && urlParams['browser'] != '0')
  1671. {
  1672. menu.addItem(mxResources.get('browser') + '...', null, function()
  1673. {
  1674. editorUi.pickLibrary(App.MODE_BROWSER);
  1675. }, parent);
  1676. }
  1677. if (!mxClient.IS_IOS)
  1678. {
  1679. menu.addItem(mxResources.get('device') + '...', null, function()
  1680. {
  1681. editorUi.pickLibrary(App.MODE_DEVICE);
  1682. }, parent);
  1683. }
  1684. if (!editorUi.isOffline())
  1685. {
  1686. menu.addSeparator(parent);
  1687. menu.addItem(mxResources.get('url') + '...', null, function()
  1688. {
  1689. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1690. {
  1691. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1692. {
  1693. // Uses proxy to avoid CORS issues
  1694. mxUtils.get(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(req)
  1695. {
  1696. if (req.getStatus() == 200)
  1697. {
  1698. editorUi.spinner.stop();
  1699. try
  1700. {
  1701. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  1702. }
  1703. catch (e)
  1704. {
  1705. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  1706. }
  1707. }
  1708. else
  1709. {
  1710. editorUi.spinner.stop();
  1711. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1712. }
  1713. }, function()
  1714. {
  1715. editorUi.spinner.stop();
  1716. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1717. });
  1718. }
  1719. }, mxResources.get('url'));
  1720. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1721. dlg.init();
  1722. }, parent);
  1723. }
  1724. }));
  1725. // Overrides view menu to add search and scratchpad
  1726. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  1727. {
  1728. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  1729. concat(['outline', 'layers', '-']));
  1730. this.addMenuItems(menu, ['-', 'search'], parent);
  1731. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  1732. {
  1733. var item = this.addMenuItem(menu, 'scratchpad', parent);
  1734. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  1735. {
  1736. this.addLinkToItem(item, 'https://support.draw.io/questions/10420280');
  1737. }
  1738. }
  1739. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
  1740. 'scrollbars', 'tooltips', '-',
  1741. 'grid', 'guides'], parent);
  1742. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  1743. {
  1744. this.addMenuItem(menu, 'shadowVisible', parent);
  1745. }
  1746. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  1747. 'resetView', 'zoomIn', 'zoomOut'], parent);
  1748. })));
  1749. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  1750. {
  1751. if (urlParams['embed'] != '1')
  1752. {
  1753. this.addSubmenu('theme', menu, parent);
  1754. menu.addSeparator(parent);
  1755. }
  1756. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  1757. if (typeof(MathJax) !== 'undefined')
  1758. {
  1759. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  1760. this.addLinkToItem(item, 'https://desk.draw.io/solution/articles/16000032875-how-to-use-mathematical-typesetting-');
  1761. }
  1762. this.addMenuItems(menu, ['autosave', '-', 'createShape', 'editDiagram'], parent);
  1763. menu.addSeparator(parent);
  1764. if (urlParams['embed'] != '1' && isLocalStorage)
  1765. {
  1766. this.addMenuItems(menu, ['showStartScreen'], parent);
  1767. }
  1768. if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
  1769. {
  1770. this.addMenuItems(menu, ['plugins', '-', 'offline'], parent);
  1771. }
  1772. else
  1773. {
  1774. menu.addSeparator(parent);
  1775. }
  1776. if (!editorUi.isOffline() && !navigator.standalone && urlParams['embed'] != '1')
  1777. {
  1778. this.addMenuItems(menu, ['chromeApp'], parent);
  1779. }
  1780. })));
  1781. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  1782. {
  1783. if (urlParams['embed'] == '1')
  1784. {
  1785. this.addSubmenu('importFrom', menu, parent);
  1786. this.addSubmenu('exportAs', menu, parent);
  1787. this.addSubmenu('embed', menu, parent);
  1788. if (urlParams['libraries'] == '1')
  1789. {
  1790. this.addMenuItems(menu, ['-'], parent);
  1791. this.addSubmenu('newLibrary', menu, parent);
  1792. this.addSubmenu('openLibraryFrom', menu, parent);
  1793. }
  1794. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'save'], parent);
  1795. if (urlParams['saveAndExit'] == '1')
  1796. {
  1797. this.addMenuItems(menu, ['saveAndExit'], parent);
  1798. }
  1799. this.addMenuItems(menu, ['exit'], parent);
  1800. }
  1801. else
  1802. {
  1803. var file = this.editorUi.getCurrentFile();
  1804. if (file != null && file.constructor == DriveFile)
  1805. {
  1806. if (file.isRestricted())
  1807. {
  1808. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  1809. }
  1810. if (file.realtime == null)
  1811. {
  1812. this.addMenuItems(menu, ['save', 'share', '-'], parent);
  1813. }
  1814. else
  1815. {
  1816. if (!file.isAutosave())
  1817. {
  1818. this.addMenuItems(menu, ['save'], parent);
  1819. }
  1820. this.addMenuItems(menu, ['share', 'chatWindowTitle', '-'], parent);
  1821. }
  1822. }
  1823. else
  1824. {
  1825. this.addMenuItems(menu, ['new'], parent);
  1826. }
  1827. this.addSubmenu('openFrom', menu, parent);
  1828. if (isLocalStorage)
  1829. {
  1830. this.addSubmenu('openRecent', menu, parent);
  1831. }
  1832. if (file != null && file.constructor == DriveFile)
  1833. {
  1834. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  1835. }
  1836. else
  1837. {
  1838. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-', 'rename'], parent);
  1839. if (editorUi.isOfflineApp())
  1840. {
  1841. if (!editorUi.isOffline())
  1842. {
  1843. this.addMenuItems(menu, ['upload'], parent);
  1844. }
  1845. }
  1846. else
  1847. {
  1848. this.addMenuItems(menu, ['makeCopy'], parent);
  1849. if (file != null && file.constructor == OneDriveFile)
  1850. {
  1851. this.addMenuItems(menu, ['moveToFolder'], parent);
  1852. }
  1853. }
  1854. }
  1855. menu.addSeparator(parent);
  1856. this.addSubmenu('importFrom', menu, parent);
  1857. this.addSubmenu('exportAs', menu, parent);
  1858. menu.addSeparator(parent);
  1859. this.addSubmenu('embed', menu, parent);
  1860. this.addSubmenu('publish', menu, parent);
  1861. menu.addSeparator(parent);
  1862. this.addSubmenu('newLibrary', menu, parent);
  1863. this.addSubmenu('openLibraryFrom', menu, parent);
  1864. if (file != null && (file.constructor == DriveFile || file.constructor == DropboxFile))
  1865. {
  1866. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  1867. }
  1868. if (file != null && file.constructor == DriveFile)
  1869. {
  1870. this.addMenuItems(menu, ['createRevision'], parent);
  1871. }
  1872. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  1873. // Cannot use print in standalone mode on iOS as we cannot open new windows
  1874. if (!mxClient.IS_IOS || !navigator.standalone)
  1875. {
  1876. this.addMenuItems(menu, ['print'], parent);
  1877. }
  1878. this.addMenuItems(menu, ['-', 'close']);
  1879. }
  1880. })));
  1881. };
  1882. })();