Menus.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197
  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. (editorUi.pages != null && editorUi.pages.length > 1) ?
  77. 400 : 340, 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', 'endFill', 'endArrow',
  270. 'endSize', 'startStill', 'startArrow', 'startSize'];
  271. editorUi.actions.addAction('copyStyle', function()
  272. {
  273. var state = graph.view.getState(graph.getSelectionCell());
  274. if (graph.isEnabled() && state != null)
  275. {
  276. editorUi.copiedStyle = mxUtils.clone(state.style);
  277. // Handles special case for value "none"
  278. var cellStyle = graph.getModel().getStyle(state.cell);
  279. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  280. for (var j = 0; j < tokens.length; j++)
  281. {
  282. var tmp = tokens[j];
  283. var pos = tmp.indexOf('=');
  284. if (pos >= 0)
  285. {
  286. var key = tmp.substring(0, pos);
  287. var value = tmp.substring(pos + 1);
  288. if (editorUi.copiedStyle[key] == null && value == 'none')
  289. {
  290. editorUi.copiedStyle[key] = 'none';
  291. }
  292. }
  293. }
  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. var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
  487. img.src = logDomain + '/log?severity=CONFIG&msg=helpsearch:' + encodeURIComponent(input.value) + '&v=' + encodeURIComponent(EditorUi.VERSION);
  488. }
  489. // Workaround for blocked submit on iOS/IE11
  490. window.setTimeout(function()
  491. {
  492. editorUi.menubar.hideMenu();
  493. }, 0);
  494. });
  495. mxEvent.addGestureListeners(item, function(evt)
  496. {
  497. if (document.activeElement != input)
  498. {
  499. input.focus();
  500. }
  501. mxEvent.consume(evt);
  502. }, function(evt)
  503. {
  504. mxEvent.consume(evt);
  505. }, function(evt)
  506. {
  507. mxEvent.consume(evt);
  508. });
  509. // Sets initial focus on input element
  510. window.setTimeout(function()
  511. {
  512. input.focus();
  513. }, 0);
  514. }
  515. this.addMenuItems(menu, ['-', 'quickStart', 'userManual', 'keyboardShortcuts', '-']);
  516. if (!mxClient.IS_CHROMEAPP)
  517. {
  518. this.addMenuItems(menu, ['feedback']);
  519. }
  520. this.addMenuItems(menu, ['support', '-', 'about']);
  521. }
  522. if (urlParams['test'] == '1')
  523. {
  524. // For showing the bounding box
  525. mxResources.parse('showBoundingBox=Show bounding box');
  526. this.editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  527. {
  528. var b = graph.getGraphBounds();
  529. var tr = graph.view.translate;
  530. var s = graph.view.scale;
  531. graph.insertVertex(parent, null, '', b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s, 'fillColor=none;strokeColor=red;');
  532. }));
  533. this.addMenuItems(menu, ['-', 'showBoundingBox'], parent);
  534. // For testing local XML export
  535. mxResources.parse('testXmlImageExport=XML Image Export');
  536. this.editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  537. {
  538. var bg = '#ffffff';
  539. var scale = 1;
  540. var b = 1;
  541. var imgExport = new mxImageExport();
  542. var bounds = graph.getGraphBounds();
  543. var vs = graph.view.scale;
  544. // New image export
  545. var xmlDoc = mxUtils.createXmlDocument();
  546. var root = xmlDoc.createElement('output');
  547. xmlDoc.appendChild(root);
  548. // Renders graph. Offset will be multiplied with state's scale when painting state.
  549. var xmlCanvas = new mxXmlCanvas2D(root);
  550. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  551. xmlCanvas.scale(scale / vs);
  552. var stateCounter = 0;
  553. var canvasSave = xmlCanvas.save;
  554. xmlCanvas.save = function()
  555. {
  556. stateCounter++;
  557. canvasSave.apply(this, arguments);
  558. };
  559. var canvasRestore = xmlCanvas.restore;
  560. xmlCanvas.restore = function()
  561. {
  562. stateCounter--;
  563. canvasRestore.apply(this, arguments);
  564. };
  565. var exportDrawShape = imgExport.drawShape;
  566. imgExport.drawShape = function(state)
  567. {
  568. mxLog.debug('entering shape', state, stateCounter);
  569. exportDrawShape.apply(this, arguments);
  570. mxLog.debug('leaving shape', state, stateCounter);
  571. };
  572. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  573. // Puts request data together
  574. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  575. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  576. mxLog.show();
  577. mxLog.debug(mxUtils.getXml(root));
  578. mxLog.debug('stateCounter', stateCounter);
  579. }));
  580. this.addMenuItems(menu, ['testXmlImageExport'], parent);
  581. mxResources.parse('animation=Animation');
  582. this.editorUi.actions.addAction('animation', mxUtils.bind(this, function()
  583. {
  584. if (this.animationWindow == null)
  585. {
  586. // LATER: Check outline window for initial placement
  587. this.animationWindow = new AnimationWindow(this.editorUi, (document.body.offsetWidth - 480) / 2,
  588. 120, 640, 480);
  589. this.animationWindow.window.setVisible(true);
  590. }
  591. else
  592. {
  593. this.animationWindow.window.setVisible(!this.animationWindow.window.isVisible());
  594. }
  595. }));
  596. this.addMenuItems(menu, ['animation'], parent);
  597. mxResources.parse('testShowRtModel=Show RT model');
  598. mxResources.parse('testDebugRtModel=Debug RT model');
  599. mxResources.parse('testDownloadRtModel=Download RT model');
  600. this.editorUi.actions.addAction('testShowRtModel', mxUtils.bind(this, function()
  601. {
  602. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  603. {
  604. console.log('bytesUsed', this.editorUi.getCurrentFile().realtime.rtModel.bytesUsed);
  605. console.log('root', this.editorUi.getCurrentFile().realtime.dumpRoot());
  606. this.editorUi.getCurrentFile().realtime.check();
  607. }
  608. }));
  609. this.editorUi.actions.addAction('testDebugRtModel', mxUtils.bind(this, function()
  610. {
  611. gapi.drive.realtime.debug();
  612. }));
  613. this.editorUi.actions.addAction('testDownloadRtModel', mxUtils.bind(this, function()
  614. {
  615. var file = this.editorUi.getCurrentFile();
  616. if (file != null && file.realtime != null &&
  617. editorUi.spinner.spin(document.body, mxResources.get('export')))
  618. {
  619. // LATER: Download full model dump with history
  620. var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
  621. file.getHash().substring(1) + '/realtime', null, 'GET');
  622. // Adds auth token
  623. req.setRequestHeaders = function(request)
  624. {
  625. mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
  626. var token = gapi.auth.getToken().access_token;
  627. request.setRequestHeader('authorization', 'Bearer ' + token);
  628. };
  629. req.send(function(req)
  630. {
  631. editorUi.spinner.stop();
  632. if (req.getStatus() == 200)
  633. {
  634. editorUi.saveLocalFile(req.getText(), 'realtime.txt', 'text/plain');
  635. }
  636. });
  637. }
  638. }));
  639. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  640. {
  641. this.addMenuItems(menu, ['-', 'testShowRtModel', 'testDebugRtModel', 'testDownloadRtModel'], parent);
  642. }
  643. mxResources.parse('testShowConsole=Show Console');
  644. this.editorUi.actions.addAction('testShowConsole', function()
  645. {
  646. if (!mxLog.isVisible())
  647. {
  648. mxLog.show();
  649. }
  650. else
  651. {
  652. mxLog.window.fit();
  653. }
  654. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  655. });
  656. this.addMenuItems(menu, ['-', 'testShowConsole']);
  657. }
  658. })));
  659. editorUi.actions.addAction('shapes...', function()
  660. {
  661. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  662. {
  663. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  664. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  665. }
  666. else
  667. {
  668. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  669. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  670. }
  671. });
  672. editorUi.actions.addAction('createShape...', function()
  673. {
  674. var file = editorUi.getCurrentFile();
  675. if (urlParams['embed'] == '1' || (file != null && file.isEditable()))
  676. {
  677. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  678. cell.vertex = true;
  679. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  680. editorUi.showDialog(dlg.container, 640, 480, true, false);
  681. dlg.init();
  682. }
  683. });
  684. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  685. {
  686. var dlg = new EmbedHtmlDialog(editorUi);
  687. editorUi.showDialog(dlg.container, 550, 400, true, true);
  688. dlg.init();
  689. }));
  690. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  691. {
  692. var dlg = new EmbedSvgDialog(editorUi);
  693. editorUi.showDialog(dlg.container, 550, 400, true, true);
  694. dlg.init();
  695. }));
  696. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  697. {
  698. var dlg = new IframeDialog(editorUi);
  699. editorUi.showDialog(dlg.container, 420, 220, true, true);
  700. dlg.init();
  701. }));
  702. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  703. {
  704. var dlg = new IframeDialog(editorUi, false, true);
  705. editorUi.showDialog(dlg.container, 420, 200, true, true);
  706. dlg.init();
  707. }));
  708. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  709. {
  710. var dlg = new EmbedSvgDialog(editorUi, true);
  711. editorUi.showDialog(dlg.container, 550, 400, true, true);
  712. dlg.init();
  713. }));
  714. editorUi.actions.put('liveImage', new Action('Live image...', function()
  715. {
  716. var dlg = new IframeDialog(editorUi, true);
  717. editorUi.showDialog(dlg.container, 420, 180, true, true);
  718. dlg.init();
  719. }));
  720. editorUi.actions.addAction('googleDocs...', function()
  721. {
  722. window.open('http://docsaddon.draw.io');
  723. });
  724. editorUi.actions.addAction('googleSites...', function()
  725. {
  726. var dlg = new GoogleSitesDialog(editorUi);
  727. editorUi.showDialog(dlg.container, 420, 256, true, true);
  728. dlg.init();
  729. });
  730. // Adds plugins menu item in file menu only if localStorage is available for
  731. // storing the plugins.
  732. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  733. {
  734. var action = editorUi.actions.addAction('scratchpad', function()
  735. {
  736. editorUi.toggleScratchpad();
  737. });
  738. action.setToggleAction(true);
  739. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  740. editorUi.actions.addAction('plugins...', function()
  741. {
  742. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 156, true, false);
  743. });
  744. }
  745. var action = editorUi.actions.addAction('search', function()
  746. {
  747. var visible = editorUi.sidebar.isEntryVisible('search');
  748. editorUi.sidebar.showPalette('search', !visible);
  749. if (isLocalStorage)
  750. {
  751. mxSettings.settings.search = !visible;
  752. mxSettings.save();
  753. }
  754. });
  755. action.setToggleAction(true);
  756. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  757. if (urlParams['embed'] == '1')
  758. {
  759. editorUi.actions.get('save').funct = function(exit)
  760. {
  761. if (graph.isEditing())
  762. {
  763. graph.stopEditing();
  764. }
  765. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  766. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  767. if (urlParams['proto'] == 'json')
  768. {
  769. var msg = editorUi.createLoadMessage('save');
  770. msg.xml = data;
  771. if (exit)
  772. {
  773. msg.exit = true;
  774. }
  775. data = JSON.stringify(msg);
  776. }
  777. var parent = window.opener || window.parent;
  778. parent.postMessage(data, '*');
  779. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  780. {
  781. editorUi.editor.modified = false;
  782. editorUi.editor.setStatus('');
  783. }
  784. };
  785. editorUi.actions.addAction('saveAndExit', function()
  786. {
  787. editorUi.actions.get('save').funct(true);
  788. });
  789. editorUi.actions.addAction('exit', function()
  790. {
  791. var fn = function()
  792. {
  793. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  794. modified: editorUi.editor.modified}) : '';
  795. var parent = window.opener || window.parent;
  796. parent.postMessage(msg, '*');
  797. }
  798. if (!editorUi.editor.modified)
  799. {
  800. fn();
  801. }
  802. else
  803. {
  804. editorUi.confirm(mxResources.get('allChangesLost'), fn);
  805. }
  806. });
  807. }
  808. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  809. {
  810. if (editorUi.isExportToCanvas())
  811. {
  812. menu.addItem(mxResources.get('image') + '...', null, mxUtils.bind(this, function()
  813. {
  814. editorUi.showExportDialog(false, mxResources.get('export'),
  815. 'https://support.draw.io/display/DO/Exporting+Files',
  816. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable)
  817. {
  818. var val = parseInt(scale);
  819. if (!isNaN(val) && val > 0)
  820. {
  821. this.editorUi.exportImage(val / 100, transparentBackground, ignoreSelection, addShadow, editable);
  822. }
  823. }));
  824. }), parent);
  825. }
  826. // Disabled for standalone mode in iOS because new tab cannot be closed
  827. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  828. {
  829. menu.addItem(mxResources.get('image') + '...', null, mxUtils.bind(this, function()
  830. {
  831. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  832. {
  833. this.editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection);
  834. }));
  835. }), parent);
  836. }
  837. menu.addItem(mxResources.get('formatSvg') + '...', null, mxUtils.bind(this, function()
  838. {
  839. editorUi.showExportDialog(true, mxResources.get('export'),
  840. 'https://support.draw.io/display/DO/Exporting+Files',
  841. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable, embedImages)
  842. {
  843. var val = parseInt(scale);
  844. if (!isNaN(val) && val > 0)
  845. {
  846. this.editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection, addShadow, editable, embedImages);
  847. }
  848. }));
  849. }), parent);
  850. menu.addSeparator(parent);
  851. menu.addItem(mxResources.get('formatHtmlEmbedded') + '...', null, mxUtils.bind(this, function()
  852. {
  853. this.editorUi.downloadFile('html');
  854. }), parent);
  855. // Redirects export to PDF to print in Chrome App
  856. if (mxClient.IS_CHROMEAPP)
  857. {
  858. menu.addItem(mxResources.get('formatPdf') + '...', null, this.editorUi.actions.get('print').funct, parent);
  859. }
  860. // Disabled for standalone mode in iOS because new tab cannot be closed
  861. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  862. {
  863. menu.addItem(mxResources.get('formatPdf') + '...', null, mxUtils.bind(this, function()
  864. {
  865. var content = document.createElement('div');
  866. content.style.padding = '6px';
  867. var cb2 = document.createElement('input');
  868. cb2.style.marginRight = '8px';
  869. cb2.setAttribute('type', 'checkbox');
  870. if (graph.isSelectionEmpty())
  871. {
  872. cb2.setAttribute('disabled', 'disabled');
  873. }
  874. content.appendChild(cb2);
  875. mxUtils.write(content, mxResources.get('selectionOnly'));
  876. mxUtils.br(content);
  877. var cb = document.createElement('input');
  878. cb.setAttribute('type', 'checkbox');
  879. cb.style.marginTop = '16px';
  880. cb.style.marginRight = '8px';
  881. if (!graph.pageVisible)
  882. {
  883. cb.setAttribute('checked', 'checked');
  884. cb.defaultChecked = true;
  885. }
  886. content.appendChild(cb);
  887. mxUtils.write(content, mxResources.get('crop'));
  888. var dlg = new CustomDialog(editorUi, content, mxUtils.bind(this, function()
  889. {
  890. var prev = graph.pageVisible;
  891. graph.pageVisible = !cb.checked;
  892. this.editorUi.downloadFile('pdf', null, null, !cb2.checked);
  893. graph.pageVisible = prev;
  894. }), null, mxResources.get('export'));
  895. this.editorUi.showDialog(dlg.container, 300, 120, true, true);
  896. }), parent);
  897. }
  898. menu.addSeparator(parent);
  899. menu.addItem(mxResources.get('formatXml') + '...', null, mxUtils.bind(this, function()
  900. {
  901. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  902. var content = document.createElement('div');
  903. content.style.padding = '6px';
  904. var cb2 = document.createElement('input');
  905. cb2.style.marginRight = '8px';
  906. cb2.setAttribute('type', 'checkbox');
  907. if (graph.isSelectionEmpty())
  908. {
  909. cb2.setAttribute('disabled', 'disabled');
  910. }
  911. content.appendChild(cb2);
  912. mxUtils.write(content, mxResources.get('selectionOnly'));
  913. var cb = document.createElement('input');
  914. cb.setAttribute('type', 'checkbox');
  915. cb.setAttribute('checked', 'checked');
  916. cb.defaultChecked = true;
  917. cb.style.marginRight = '8px';
  918. cb.style.marginTop = '16px';
  919. mxUtils.br(content);
  920. content.appendChild(cb);
  921. if (noPages)
  922. {
  923. mxUtils.write(content, mxResources.get('compressed'));
  924. }
  925. else
  926. {
  927. mxUtils.write(content, mxResources.get('allPages'));
  928. mxEvent.addListener(cb2, 'change', function()
  929. {
  930. if (cb2.checked)
  931. {
  932. cb.setAttribute('disabled', 'disabled');
  933. }
  934. else
  935. {
  936. cb.removeAttribute('disabled');
  937. }
  938. });
  939. }
  940. var dlg = new CustomDialog(editorUi, content, mxUtils.bind(this, function()
  941. {
  942. editorUi.downloadFile('xml', (noPages) ? !cb.checked : null, null, !cb2.checked,
  943. (!noPages) ? !cb.checked : null);
  944. }), null, mxResources.get('export'));
  945. editorUi.showDialog(dlg.container, 300, 120, true, true);
  946. }), parent);
  947. if (!editorUi.isOffline())
  948. {
  949. menu.addSeparator(parent);
  950. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  951. }
  952. })));
  953. this.editorUi.actions.addAction('chatWindowTitle...', mxUtils.bind(this.editorUi, this.editorUi.toggleChat));
  954. this.put('importFrom', new Menu(function(menu, parent)
  955. {
  956. function importFile(device)
  957. {
  958. if (device && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  959. {
  960. var input = document.createElement('input');
  961. input.setAttribute('type', 'file');
  962. mxEvent.addListener(input, 'change', function()
  963. {
  964. if (input.files != null)
  965. {
  966. // Using null for position will disable crop of input file
  967. editorUi.importFiles(input.files, null, null, editorUi.maxImageSize);
  968. }
  969. });
  970. input.click();
  971. }
  972. else
  973. {
  974. window.openNew = false;
  975. window.openKey = 'import';
  976. var prevValue = Editor.useLocalStorage;
  977. Editor.useLocalStorage = !device;
  978. // Closes dialog after open
  979. window.openFile = new OpenFile(function(cancel)
  980. {
  981. editorUi.hideDialog(cancel);
  982. });
  983. window.openFile.setConsumer(function(xml, filename)
  984. {
  985. graph.setSelectionCells(editorUi.importXml(xml));
  986. });
  987. // Removes openFile if dialog is closed
  988. editorUi.showDialog(new OpenDialog(editorUi).container, 360, 220, true, true, function()
  989. {
  990. window.openFile = null;
  991. });
  992. // Extends dialog close to show splash screen
  993. var dlg = editorUi.dialog;
  994. var dlgClose = dlg.close;
  995. editorUi.dialog.close = function(cancel)
  996. {
  997. Editor.useLocalStorage = prevValue;
  998. dlgClose.apply(dlg, arguments);
  999. if (cancel && editorUi.getCurrentFile() == null && urlParams['embed'] != '1')
  1000. {
  1001. editorUi.showSplash();
  1002. }
  1003. };
  1004. }
  1005. };
  1006. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  1007. {
  1008. if (mime == 'image/png')
  1009. {
  1010. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  1011. {
  1012. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  1013. {
  1014. var s = Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2));
  1015. editorUi.importFile(data, mime, 0, 0, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  1016. {
  1017. editorUi.spinner.stop();
  1018. graph.setSelectionCells(cells);
  1019. });
  1020. }), true);
  1021. }));
  1022. }
  1023. else
  1024. {
  1025. editorUi.importFile(data, mime, 0, 0, 0, 0, filename, function(cells)
  1026. {
  1027. editorUi.spinner.stop();
  1028. graph.setSelectionCells(cells);
  1029. });
  1030. }
  1031. });
  1032. function pickFileFromService(service)
  1033. {
  1034. // Drive requires special arguments for libraries and bypassing realtime
  1035. service.pickFile(function(id)
  1036. {
  1037. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1038. {
  1039. if (service == editorUi.dropbox)
  1040. {
  1041. var mime = (/(\.png)$/i.test(id)) ? 'image/png' : 'text/xml';
  1042. editorUi.loadUrl(id, function(data)
  1043. {
  1044. doImportFile(data, mime, id);
  1045. },
  1046. function(resp)
  1047. {
  1048. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1049. }, mime == 'image/png');
  1050. }
  1051. else
  1052. {
  1053. // NOTE The third argument in getFile says denyConvert to match
  1054. // the existing signature in the original DriveClient which has
  1055. // as slightly different semantic, but works the same way.
  1056. service.getFile(id, function(file)
  1057. {
  1058. var mime = (/(\.png)$/i.test(file.getTitle())) ? 'image/png' : 'text/xml';
  1059. doImportFile(file.getData(), mime, file.getTitle());
  1060. },
  1061. function(resp)
  1062. {
  1063. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1064. }, true);
  1065. }
  1066. }
  1067. }, true);
  1068. };
  1069. if (editorUi.drive != null)
  1070. {
  1071. // Requires special arguments for libraries and realtime
  1072. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1073. {
  1074. pickFileFromService(editorUi.drive);
  1075. }, parent);
  1076. }
  1077. else if (googleEnabled)
  1078. {
  1079. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1080. {
  1081. // do nothing
  1082. }, parent, null, false);
  1083. }
  1084. if (editorUi.dropbox != null)
  1085. {
  1086. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1087. {
  1088. pickFileFromService(editorUi.dropbox);
  1089. }, parent);
  1090. }
  1091. else if (dropboxEnabled)
  1092. {
  1093. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1094. {
  1095. // do nothing
  1096. }, parent, null, false);
  1097. }
  1098. if (editorUi.oneDrive != null)
  1099. {
  1100. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1101. {
  1102. pickFileFromService(editorUi.oneDrive);
  1103. }, parent);
  1104. }
  1105. else if (oneDriveEnabled)
  1106. {
  1107. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1108. {
  1109. // do nothing
  1110. }, parent, null, false);
  1111. }
  1112. menu.addSeparator(parent);
  1113. if (isLocalStorage && urlParams['browser'] != '0')
  1114. {
  1115. menu.addItem(mxResources.get('browser') + '...', null, function()
  1116. {
  1117. importFile(false);
  1118. }, parent);
  1119. }
  1120. if (!mxClient.IS_IOS)
  1121. {
  1122. menu.addItem(mxResources.get('device') + '...', null, function()
  1123. {
  1124. importFile(true);
  1125. }, parent);
  1126. }
  1127. if (!editorUi.isOffline())
  1128. {
  1129. menu.addSeparator(parent);
  1130. menu.addItem(mxResources.get('url') + '...', null, function()
  1131. {
  1132. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1133. {
  1134. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1135. {
  1136. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1137. // Uses proxy to avoid CORS issues
  1138. editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1139. {
  1140. doImportFile(data, mime, fileUrl);
  1141. },
  1142. function ()
  1143. {
  1144. editorUi.spinner.stop();
  1145. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1146. }, mime == 'image/png');
  1147. }
  1148. }, mxResources.get('url'));
  1149. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1150. dlg.init();
  1151. }, parent);
  1152. }
  1153. })).isEnabled = isGraphEnabled;
  1154. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1155. {
  1156. var item = menu.addItem(mxResources.get('kennedy'), null, function()
  1157. {
  1158. mxSettings.setUi('');
  1159. mxSettings.save();
  1160. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1161. }, parent);
  1162. if (uiTheme != 'atlas')
  1163. {
  1164. menu.addCheckmark(item, Editor.checkmarkImage);
  1165. }
  1166. item = menu.addItem(mxResources.get('atlas'), null, function()
  1167. {
  1168. mxSettings.setUi('atlas');
  1169. mxSettings.save();
  1170. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1171. }, parent);
  1172. if (uiTheme == 'atlas')
  1173. {
  1174. menu.addCheckmark(item, Editor.checkmarkImage);
  1175. }
  1176. })));
  1177. this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  1178. {
  1179. var file = this.editorUi.getCurrentFile();
  1180. if (file != null)
  1181. {
  1182. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  1183. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  1184. {
  1185. if (title != null && title.length > 0 && file != null && this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  1186. {
  1187. // Delete old file, save new file in dropbox if autosize is enabled
  1188. file.rename(title, mxUtils.bind(this, function(resp)
  1189. {
  1190. this.editorUi.spinner.stop();
  1191. }),
  1192. mxUtils.bind(this, function(resp)
  1193. {
  1194. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  1195. }));
  1196. }
  1197. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  1198. mxResources.get('diagramName') : null, function(name)
  1199. {
  1200. if (name != null && name.length > 0)
  1201. {
  1202. return true;
  1203. }
  1204. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  1205. return false;
  1206. });
  1207. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1208. dlg.init();
  1209. }
  1210. })).isEnabled = isGraphEnabled;
  1211. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  1212. {
  1213. var file = editorUi.getCurrentFile();
  1214. if (file != null)
  1215. {
  1216. var title = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  1217. // Handles extension
  1218. var extension = '';
  1219. var dot = title.lastIndexOf('.');
  1220. if (dot >= 0)
  1221. {
  1222. extension = title.substring(dot);
  1223. title = title.substring(0, dot);
  1224. }
  1225. title = mxResources.get('copyOf', [title]) + extension;
  1226. if (file.constructor == DriveFile)
  1227. {
  1228. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  1229. {
  1230. // Mode is "download" if Create button is pressed, means use Google Drive
  1231. if (mode == 'download')
  1232. {
  1233. mode = App.MODE_GOOGLE;
  1234. }
  1235. if (newTitle != null && newTitle.length > 0)
  1236. {
  1237. if (mode == App.MODE_GOOGLE)
  1238. {
  1239. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  1240. {
  1241. // Makes sure the latest XML is in the file
  1242. file.save(false, mxUtils.bind(this, function()
  1243. {
  1244. // Saveas does not update the file descriptor in Google Drive
  1245. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  1246. {
  1247. editorUi.spinner.stop();
  1248. var url = editorUi.getUrl();
  1249. window.openWindow(url + '#G' + resp.id, null, mxUtils.bind(this, function()
  1250. {
  1251. window.location.hash = 'G' + resp.id;
  1252. }));
  1253. }), mxUtils.bind(this, function(resp)
  1254. {
  1255. editorUi.handleError(resp);
  1256. }));
  1257. }), mxUtils.bind(this, function(resp)
  1258. {
  1259. editorUi.handleError(resp);
  1260. }));
  1261. }
  1262. }
  1263. else
  1264. {
  1265. this.editorUi.createFile(newTitle, this.editorUi.getFileData(true), null, mode);
  1266. }
  1267. }
  1268. }), mxUtils.bind(this, function()
  1269. {
  1270. editorUi.hideDialog();
  1271. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  1272. null, null, null, true);
  1273. editorUi.showDialog(dlg.container, 420, 380, true, true);
  1274. dlg.init();
  1275. }
  1276. else
  1277. {
  1278. // Creates a copy with no predefined storage
  1279. editorUi.editor.editAsNew(editorUi.getEditBlankXml(), title);
  1280. }
  1281. }
  1282. }));
  1283. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  1284. {
  1285. var file = editorUi.getCurrentFile();
  1286. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  1287. {
  1288. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  1289. {
  1290. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  1291. {
  1292. file.move(folderId, mxUtils.bind(this, function(resp)
  1293. {
  1294. editorUi.spinner.stop();
  1295. }), mxUtils.bind(this, function(resp)
  1296. {
  1297. editorUi.handleError(resp);
  1298. }));
  1299. }
  1300. }));
  1301. }
  1302. }));
  1303. editorUi.actions.addAction('imgur...', mxUtils.bind(this, function()
  1304. {
  1305. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToImgur), function(imgurId, editable)
  1306. {
  1307. window.open('https://imgur.com/' + imgurId);
  1308. }, mxResources.get('open'));
  1309. }));
  1310. editorUi.actions.addAction('facebook...', mxUtils.bind(this, function()
  1311. {
  1312. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToImgur), function(imgurId)
  1313. {
  1314. window.open('https://www.facebook.com/sharer.php?p[url]=' + encodeURIComponent('https://imgur.com/' + imgurId) +
  1315. '&p[images][0]=' + encodeURIComponent(imgurId + '.png'));
  1316. });
  1317. }));
  1318. editorUi.actions.addAction('twitter...', mxUtils.bind(this, function()
  1319. {
  1320. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToImgur), function(imgurId)
  1321. {
  1322. window.open('https://twitter.com/intent/tweet?text=' +
  1323. encodeURIComponent('Check out the diagram I made with draw.io') +
  1324. '&via=drawio&hashtags=madewithdrawio&url=' +
  1325. encodeURIComponent('https://imgur.com/' + imgurId));
  1326. });
  1327. }));
  1328. editorUi.actions.addAction('github...', mxUtils.bind(this, function()
  1329. {
  1330. editorUi.publishImage(mxUtils.bind(editorUi, editorUi.uploadToGithub));
  1331. }));
  1332. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  1333. {
  1334. // Disable publish in IE9- due to CORS problem when getting image from server
  1335. // which requires cross-domain XHR but XDomainRequest has no custom headers
  1336. // to set content type to form-encoded-data which is needed for the export.
  1337. if (document.documentMode == null || document.documentMode >= 10)
  1338. {
  1339. this.addMenuItems(menu, ['imgur'], parent);
  1340. this.addMenuItems(menu, ['twitter'], parent);
  1341. this.addMenuItems(menu, ['facebook'], parent);
  1342. if (typeof XMLHttpRequest !== 'undefined')
  1343. {
  1344. this.addMenuItems(menu, ['github'], parent);
  1345. }
  1346. }
  1347. if (!navigator.standalone && !editorUi.isOffline())
  1348. {
  1349. this.addMenuItems(menu, ['publishLink'], parent);
  1350. }
  1351. })));
  1352. editorUi.actions.put('offline', new Action(mxResources.get('offline') + '...', function()
  1353. {
  1354. window.open('http://www.draw.io/app')
  1355. }));
  1356. editorUi.actions.put('chromeApp', new Action(mxResources.get('chromeApp') + '...', function()
  1357. {
  1358. window.open('https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla')
  1359. }));
  1360. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  1361. {
  1362. var file = this.editorUi.getCurrentFile();
  1363. if (file != null)
  1364. {
  1365. this.editorUi.drive.showPermissions(file.getId());
  1366. }
  1367. }));
  1368. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  1369. {
  1370. if (urlParams['test'] == '1')
  1371. {
  1372. this.addMenuItems(menu, ['liveImage', '-'], parent);
  1373. }
  1374. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  1375. if (!navigator.standalone && !editorUi.isOffline())
  1376. {
  1377. this.addMenuItems(menu, ['embedIframe'], parent);
  1378. }
  1379. if (!editorUi.isOffline())
  1380. {
  1381. this.addMenuItems(menu, ['-', 'googleSites', 'googleDocs'], parent);
  1382. }
  1383. })));
  1384. // Overrides arrange menu to add insert submenu
  1385. this.put('arrange', new Menu(mxUtils.bind(this, function(menu, parent)
  1386. {
  1387. this.addMenuItems(menu, ['toFront', 'toBack', '-'], parent);
  1388. this.addSubmenu('direction', menu, parent);
  1389. this.addMenuItems(menu, ['turn', '-'], parent);
  1390. this.addSubmenu('align', menu, parent);
  1391. this.addSubmenu('distribute', menu, parent);
  1392. menu.addSeparator(parent);
  1393. this.addSubmenu('navigation', menu, parent);
  1394. this.addSubmenu('insert', menu, parent);
  1395. this.addSubmenu('layout', menu, parent);
  1396. this.addMenuItems(menu, ['-', 'group', 'ungroup', 'removeFromGroup', '-', 'editGeometry', 'clearWaypoints', 'autosize'], parent);
  1397. })));
  1398. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree', '-', 'organic', 'circle', '-', 'fromText'];
  1399. var addInsertItem = function(menu, parent, title, method)
  1400. {
  1401. menu.addItem(title, null, mxUtils.bind(this, function()
  1402. {
  1403. if (method == 'fromText')
  1404. {
  1405. var dlg = new ParseDialog(editorUi, title);
  1406. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1407. editorUi.dialog.container.style.overflow = 'auto';
  1408. dlg.init();
  1409. }
  1410. else
  1411. {
  1412. var dlg = new CreateGraphDialog(editorUi, title, method);
  1413. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1414. // Executed after dialog is added to dom
  1415. dlg.init();
  1416. }
  1417. }), parent);
  1418. };
  1419. editorUi.actions.addAction('insertText', function()
  1420. {
  1421. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1422. {
  1423. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1424. var cell = new mxCell('Text', new mxGeometry(pt.x, pt.y, 40, 20),
  1425. 'text;html=1;resizable=0;autosize=1;align=left;verticalAlign=top;spacingTop=-4;points=[];');
  1426. cell.vertex = true;
  1427. graph.startEditingAtCell(graph.addCell(cell));
  1428. }
  1429. }, null, null, 'Ctrl+Shift+X').isEnabled = isGraphEnabled;
  1430. editorUi.actions.addAction('insertRectangle', function()
  1431. {
  1432. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1433. {
  1434. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1435. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 120, 60), 'whiteSpace=wrap;html=1;');
  1436. cell.vertex = true;
  1437. graph.setSelectionCell(graph.addCell(cell));
  1438. graph.scrollCellToVisible(graph.getSelectionCell());
  1439. }
  1440. }, null, null, 'Ctrl+K').isEnabled = isGraphEnabled;
  1441. editorUi.actions.addAction('insertEllipse', function()
  1442. {
  1443. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1444. {
  1445. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1446. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 80, 80), 'ellipse;whiteSpace=wrap;html=1;');
  1447. cell.vertex = true;
  1448. graph.setSelectionCell(graph.addCell(cell));
  1449. graph.scrollCellToVisible(graph.getSelectionCell());
  1450. }
  1451. }, null, null, 'Ctrl+Shift+K').isEnabled = isGraphEnabled;
  1452. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  1453. {
  1454. this.addMenuItems(menu, ['insertText', 'insertRectangle', 'insertEllipse', '-', 'insertLink', 'insertImage'], parent);
  1455. menu.addSeparator(parent);
  1456. for (var i = 0; i < methods.length; i++)
  1457. {
  1458. if (methods[i] == '-')
  1459. {
  1460. menu.addSeparator(parent);
  1461. }
  1462. else
  1463. {
  1464. addInsertItem(menu, parent, mxResources.get(methods[i]), methods[i]);
  1465. }
  1466. }
  1467. })));
  1468. this.put('openRecent', new Menu(function(menu, parent)
  1469. {
  1470. var recent = editorUi.getRecent();
  1471. var count = 0;
  1472. if (recent != null)
  1473. {
  1474. for (var i = 0; i < recent.length; i++)
  1475. {
  1476. (function(entry)
  1477. {
  1478. count++;
  1479. var modeKey = entry.mode;
  1480. // Google and oneDrive use different keys
  1481. if (modeKey == App.MODE_GOOGLE)
  1482. {
  1483. modeKey = 'googleDrive';
  1484. }
  1485. else if (modeKey == App.MODE_ONEDRIVE)
  1486. {
  1487. modeKey = 'oneDrive';
  1488. }
  1489. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  1490. {
  1491. editorUi.loadFile(entry.id);
  1492. }, parent);
  1493. })(recent[i]);
  1494. }
  1495. menu.addSeparator(parent);
  1496. }
  1497. menu.addItem(mxResources.get('reset'), null, function()
  1498. {
  1499. editorUi.resetRecent();
  1500. }, parent);
  1501. }));
  1502. this.put('openFrom', new Menu(function(menu, parent)
  1503. {
  1504. if (editorUi.drive != null)
  1505. {
  1506. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1507. {
  1508. editorUi.pickFile(App.MODE_GOOGLE);
  1509. }, parent);
  1510. }
  1511. else if (googleEnabled)
  1512. {
  1513. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1514. {
  1515. // do nothing
  1516. }, parent, null, false);
  1517. }
  1518. if (editorUi.dropbox != null)
  1519. {
  1520. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1521. {
  1522. editorUi.pickFile(App.MODE_DROPBOX);
  1523. }, parent);
  1524. }
  1525. else if (dropboxEnabled)
  1526. {
  1527. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1528. {
  1529. // do nothing
  1530. }, parent, null, false);
  1531. }
  1532. if (editorUi.oneDrive != null)
  1533. {
  1534. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1535. {
  1536. editorUi.pickFile(App.MODE_ONEDRIVE);
  1537. }, parent);
  1538. }
  1539. else if (oneDriveEnabled)
  1540. {
  1541. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1542. {
  1543. // do nothing
  1544. }, parent, null, false);
  1545. }
  1546. menu.addSeparator(parent);
  1547. if (isLocalStorage && urlParams['browser'] != '0')
  1548. {
  1549. menu.addItem(mxResources.get('browser') + '...', null, function()
  1550. {
  1551. editorUi.pickFile(App.MODE_BROWSER);
  1552. }, parent);
  1553. }
  1554. if (!mxClient.IS_IOS)
  1555. {
  1556. menu.addItem(mxResources.get('device') + '...', null, function()
  1557. {
  1558. editorUi.pickFile(App.MODE_DEVICE);
  1559. }, parent);
  1560. }
  1561. if (!editorUi.isOffline())
  1562. {
  1563. menu.addSeparator(parent);
  1564. menu.addItem(mxResources.get('url') + '...', null, function()
  1565. {
  1566. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1567. {
  1568. if (fileUrl != null && fileUrl.length > 0)
  1569. {
  1570. var url = editorUi.getUrl(window.location.pathname + '?url=' + encodeURIComponent(fileUrl));
  1571. if (editorUi.getCurrentFile() == null)
  1572. {
  1573. window.location.href = url;
  1574. }
  1575. else
  1576. {
  1577. window.openWindow(url);
  1578. }
  1579. }
  1580. }, mxResources.get('url'));
  1581. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1582. dlg.init();
  1583. }, parent);
  1584. }
  1585. }));
  1586. this.put('newLibrary', new Menu(function(menu, parent)
  1587. {
  1588. if (editorUi.drive != null)
  1589. {
  1590. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1591. {
  1592. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  1593. }, parent);
  1594. }
  1595. else if (googleEnabled)
  1596. {
  1597. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1598. {
  1599. // do nothing
  1600. }, parent, null, false);
  1601. }
  1602. if (editorUi.dropbox != null)
  1603. {
  1604. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1605. {
  1606. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  1607. }, parent);
  1608. }
  1609. else if (dropboxEnabled)
  1610. {
  1611. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1612. {
  1613. // do nothing
  1614. }, parent, null, false);
  1615. }
  1616. if (editorUi.oneDrive != null)
  1617. {
  1618. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1619. {
  1620. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  1621. }, parent);
  1622. }
  1623. else if (oneDriveEnabled)
  1624. {
  1625. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1626. {
  1627. // do nothing
  1628. }, parent, null, false);
  1629. }
  1630. menu.addSeparator(parent);
  1631. if (isLocalStorage && urlParams['browser'] != '0')
  1632. {
  1633. menu.addItem(mxResources.get('browser') + '...', null, function()
  1634. {
  1635. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  1636. }, parent);
  1637. }
  1638. if (!mxClient.IS_IOS)
  1639. {
  1640. menu.addItem(mxResources.get('device') + '...', null, function()
  1641. {
  1642. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  1643. }, parent);
  1644. }
  1645. }));
  1646. this.put('openLibraryFrom', new Menu(function(menu, parent)
  1647. {
  1648. if (editorUi.drive != null)
  1649. {
  1650. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1651. {
  1652. editorUi.pickLibrary(App.MODE_GOOGLE);
  1653. }, parent);
  1654. }
  1655. else if (googleEnabled)
  1656. {
  1657. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1658. {
  1659. // do nothing
  1660. }, parent, null, false);
  1661. }
  1662. if (editorUi.dropbox != null)
  1663. {
  1664. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1665. {
  1666. editorUi.pickLibrary(App.MODE_DROPBOX);
  1667. }, parent);
  1668. }
  1669. else if (dropboxEnabled)
  1670. {
  1671. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1672. {
  1673. // do nothing
  1674. }, parent, null, false);
  1675. }
  1676. if (editorUi.oneDrive != null)
  1677. {
  1678. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1679. {
  1680. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  1681. }, parent);
  1682. }
  1683. else if (oneDriveEnabled)
  1684. {
  1685. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1686. {
  1687. // do nothing
  1688. }, parent, null, false);
  1689. }
  1690. menu.addSeparator(parent);
  1691. if (isLocalStorage && urlParams['browser'] != '0')
  1692. {
  1693. menu.addItem(mxResources.get('browser') + '...', null, function()
  1694. {
  1695. editorUi.pickLibrary(App.MODE_BROWSER);
  1696. }, parent);
  1697. }
  1698. if (!mxClient.IS_IOS)
  1699. {
  1700. menu.addItem(mxResources.get('device') + '...', null, function()
  1701. {
  1702. editorUi.pickLibrary(App.MODE_DEVICE);
  1703. }, parent);
  1704. }
  1705. if (!editorUi.isOffline())
  1706. {
  1707. menu.addSeparator(parent);
  1708. menu.addItem(mxResources.get('url') + '...', null, function()
  1709. {
  1710. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1711. {
  1712. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1713. {
  1714. // Uses proxy to avoid CORS issues
  1715. mxUtils.get(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(req)
  1716. {
  1717. if (req.getStatus() == 200)
  1718. {
  1719. editorUi.spinner.stop();
  1720. try
  1721. {
  1722. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  1723. }
  1724. catch (e)
  1725. {
  1726. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  1727. }
  1728. }
  1729. else
  1730. {
  1731. editorUi.spinner.stop();
  1732. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1733. }
  1734. }, function()
  1735. {
  1736. editorUi.spinner.stop();
  1737. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1738. });
  1739. }
  1740. }, mxResources.get('url'));
  1741. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1742. dlg.init();
  1743. }, parent);
  1744. }
  1745. }));
  1746. // Overrides view menu to add search and scratchpad
  1747. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  1748. {
  1749. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  1750. concat(['outline', 'layers', '-']));
  1751. this.addMenuItems(menu, ['-', 'search'], parent);
  1752. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  1753. {
  1754. var item = this.addMenuItem(menu, 'scratchpad', parent);
  1755. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  1756. {
  1757. this.addLinkToItem(item, 'https://support.draw.io/questions/10420280');
  1758. }
  1759. }
  1760. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
  1761. 'scrollbars', 'tooltips', '-',
  1762. 'grid', 'guides'], parent);
  1763. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  1764. {
  1765. this.addMenuItem(menu, 'shadowVisible', parent);
  1766. }
  1767. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  1768. 'resetView', 'zoomIn', 'zoomOut'], parent);
  1769. })));
  1770. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  1771. {
  1772. if (urlParams['embed'] != '1')
  1773. {
  1774. this.addSubmenu('theme', menu, parent);
  1775. menu.addSeparator(parent);
  1776. }
  1777. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  1778. if (typeof(MathJax) !== 'undefined')
  1779. {
  1780. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  1781. this.addLinkToItem(item, 'https://desk.draw.io/solution/articles/16000032875-how-to-use-mathematical-typesetting-');
  1782. }
  1783. this.addMenuItems(menu, ['autosave', '-', 'createShape', 'editDiagram'], parent);
  1784. menu.addSeparator(parent);
  1785. if (urlParams['embed'] != '1' && isLocalStorage)
  1786. {
  1787. this.addMenuItems(menu, ['showStartScreen'], parent);
  1788. }
  1789. if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
  1790. {
  1791. this.addMenuItems(menu, ['plugins', '-', 'offline'], parent);
  1792. }
  1793. else
  1794. {
  1795. menu.addSeparator(parent);
  1796. }
  1797. if (!editorUi.isOffline() && !navigator.standalone && urlParams['embed'] != '1')
  1798. {
  1799. this.addMenuItems(menu, ['chromeApp'], parent);
  1800. }
  1801. })));
  1802. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  1803. {
  1804. if (urlParams['embed'] == '1')
  1805. {
  1806. this.addSubmenu('importFrom', menu, parent);
  1807. this.addSubmenu('exportAs', menu, parent);
  1808. this.addSubmenu('embed', menu, parent);
  1809. if (urlParams['libraries'] == '1')
  1810. {
  1811. this.addMenuItems(menu, ['-'], parent);
  1812. this.addSubmenu('newLibrary', menu, parent);
  1813. this.addSubmenu('openLibraryFrom', menu, parent);
  1814. }
  1815. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'save'], parent);
  1816. if (urlParams['saveAndExit'] == '1')
  1817. {
  1818. this.addMenuItems(menu, ['saveAndExit'], parent);
  1819. }
  1820. this.addMenuItems(menu, ['exit'], parent);
  1821. }
  1822. else
  1823. {
  1824. var file = this.editorUi.getCurrentFile();
  1825. if (file != null && file.constructor == DriveFile)
  1826. {
  1827. if (file.isRestricted())
  1828. {
  1829. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  1830. }
  1831. if (file.realtime == null)
  1832. {
  1833. this.addMenuItems(menu, ['save', 'share', '-'], parent);
  1834. }
  1835. else
  1836. {
  1837. if (!file.isAutosave())
  1838. {
  1839. this.addMenuItems(menu, ['save'], parent);
  1840. }
  1841. this.addMenuItems(menu, ['share', 'chatWindowTitle', '-'], parent);
  1842. }
  1843. }
  1844. else
  1845. {
  1846. this.addMenuItems(menu, ['new'], parent);
  1847. }
  1848. this.addSubmenu('openFrom', menu, parent);
  1849. if (isLocalStorage)
  1850. {
  1851. this.addSubmenu('openRecent', menu, parent);
  1852. }
  1853. if (file != null && file.constructor == DriveFile)
  1854. {
  1855. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  1856. }
  1857. else
  1858. {
  1859. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-', 'rename'], parent);
  1860. if (editorUi.isOfflineApp())
  1861. {
  1862. if (!editorUi.isOffline())
  1863. {
  1864. this.addMenuItems(menu, ['upload'], parent);
  1865. }
  1866. }
  1867. else
  1868. {
  1869. this.addMenuItems(menu, ['makeCopy'], parent);
  1870. if (file != null && file.constructor == OneDriveFile)
  1871. {
  1872. this.addMenuItems(menu, ['moveToFolder'], parent);
  1873. }
  1874. }
  1875. }
  1876. menu.addSeparator(parent);
  1877. this.addSubmenu('importFrom', menu, parent);
  1878. this.addSubmenu('exportAs', menu, parent);
  1879. menu.addSeparator(parent);
  1880. this.addSubmenu('embed', menu, parent);
  1881. this.addSubmenu('publish', menu, parent);
  1882. menu.addSeparator(parent);
  1883. this.addSubmenu('newLibrary', menu, parent);
  1884. this.addSubmenu('openLibraryFrom', menu, parent);
  1885. if (file != null && (file.constructor == DriveFile || file.constructor == DropboxFile))
  1886. {
  1887. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  1888. }
  1889. if (file != null && file.constructor == DriveFile)
  1890. {
  1891. this.addMenuItems(menu, ['createRevision'], parent);
  1892. }
  1893. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  1894. // Cannot use print in standalone mode on iOS as we cannot open new windows
  1895. if (!mxClient.IS_IOS || !navigator.standalone)
  1896. {
  1897. this.addMenuItems(menu, ['print'], parent);
  1898. }
  1899. this.addMenuItems(menu, ['-', 'close']);
  1900. }
  1901. })));
  1902. };
  1903. })();