Menus.js 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  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. var trelloEnabled = ((urlParams['embed'] != '1' && urlParams['tr'] != '0') || (urlParams['embed'] == '1' && urlParams['tr'] == '1')) &&
  56. mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
  57. if (!editorUi.isOffline())
  58. {
  59. var img = new Image();
  60. img.src = IMAGE_PATH + '/help.png';
  61. }
  62. editorUi.actions.addAction('new...', function()
  63. {
  64. var compact = editorUi.isOffline();
  65. var dlg = new NewDialog(editorUi, compact);
  66. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
  67. {
  68. if (cancel && editorUi.getCurrentFile() == null)
  69. {
  70. editorUi.showSplash();
  71. }
  72. });
  73. dlg.init();
  74. });
  75. // Export PDF action for chrome OS (same as print with different dialog title)
  76. editorUi.actions.addAction('exportPdf', function()
  77. {
  78. editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 360,
  79. (editorUi.pages != null && editorUi.pages.length > 1) ?
  80. 420 : 360, true, true);
  81. });
  82. editorUi.actions.addAction('open...', function()
  83. {
  84. editorUi.pickFile();
  85. });
  86. editorUi.actions.addAction('close', function()
  87. {
  88. editorUi.fileLoaded(null);
  89. });
  90. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  91. {
  92. var cells = graph.getSelectionCells();
  93. if (graph.getSelectionCount() == 1)
  94. {
  95. var cell = graph.getSelectionCell();
  96. var state = graph.view.getState(cell);
  97. if (state != null && state.shape != null && state.shape.stencil != null)
  98. {
  99. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  100. editorUi.showDialog(dlg.container, 640, 480, true, false);
  101. dlg.init();
  102. }
  103. }
  104. }));
  105. editorUi.actions.addAction('revisionHistory...', function()
  106. {
  107. var file = editorUi.getCurrentFile();
  108. if (file == null || (file.constructor != DriveFile && file.constructor != DropboxFile) ||
  109. (editorUi.drive == null && file.constructor == DriveFile) ||
  110. (editorUi.dropbox == null && file.constructor == DropboxFile))
  111. {
  112. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  113. }
  114. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  115. {
  116. if (file.constructor == DropboxFile)
  117. {
  118. // Limit is maximum number of entries to return
  119. var promise = editorUi.dropbox.client.filesListRevisions({path: file.stat.path_lower, limit: 100});
  120. promise.then(mxUtils.bind(this, function(response)
  121. {
  122. editorUi.spinner.stop();
  123. try
  124. {
  125. var revs = [];
  126. for (var i = response.entries.length - 1; i >= 0; i--)
  127. {
  128. (function(stat)
  129. {
  130. revs.push({modifiedDate: stat.client_modified, fileSize: stat.size, getXml: function(success, error)
  131. {
  132. editorUi.dropbox.readFile({path: file.stat.path_lower, rev: stat.rev}, success, error);
  133. }, getUrl: function()
  134. {
  135. return editorUi.getUrl(window.location.pathname + '?rev=' + stat.rev + '&chrome=0&edit=_blank') + window.location.hash;
  136. }});
  137. })(response.entries[i]);
  138. }
  139. var dlg = new RevisionDialog(editorUi, revs);
  140. editorUi.showDialog(dlg.container, 640, 480, true, true);
  141. dlg.init();
  142. }
  143. catch (e)
  144. {
  145. editorUi.handleError(e);
  146. }
  147. }));
  148. // Workaround for IE8/9 support with catch function
  149. promise['catch'](function(err)
  150. {
  151. editorUi.spinner.stop();
  152. editorUi.handleError(err);
  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, Editor.ctrlKey + '+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, Editor.ctrlKey + '+Shift+M');
  266. var copiedStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'fontStyle',
  267. 'align', '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', 'arcSize'];
  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, Editor.ctrlKey + '+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, Editor.ctrlKey + '+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/?lightbox=1#Uhttps%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=Z0D96ZikMkc');
  384. });
  385. action = editorUi.actions.addAction('tags...', mxUtils.bind(this, function()
  386. {
  387. if (this.tagsWindow == null)
  388. {
  389. this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 380, 230, 280, 120);
  390. this.tagsWindow.window.addListener('show', function()
  391. {
  392. editorUi.fireEvent(new mxEventObject('tags'));
  393. });
  394. this.tagsWindow.window.addListener('hide', function()
  395. {
  396. editorUi.fireEvent(new mxEventObject('tags'));
  397. });
  398. this.tagsWindow.window.setVisible(true);
  399. editorUi.fireEvent(new mxEventObject('tags'));
  400. }
  401. else
  402. {
  403. this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
  404. }
  405. }));
  406. action.setToggleAction(true);
  407. action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
  408. action = editorUi.actions.addAction('find...', mxUtils.bind(this, function()
  409. {
  410. if (this.findWindow == null)
  411. {
  412. this.findWindow = new FindWindow(editorUi, document.body.offsetWidth - 300, 110, 204, 140);
  413. this.findWindow.window.addListener('show', function()
  414. {
  415. editorUi.fireEvent(new mxEventObject('find'));
  416. });
  417. this.findWindow.window.addListener('hide', function()
  418. {
  419. editorUi.fireEvent(new mxEventObject('find'));
  420. });
  421. this.findWindow.window.setVisible(true);
  422. editorUi.fireEvent(new mxEventObject('find'));
  423. }
  424. else
  425. {
  426. this.findWindow.window.setVisible(!this.findWindow.window.isVisible());
  427. }
  428. }));
  429. action.setToggleAction(true);
  430. action.setSelectedCallback(mxUtils.bind(this, function() { return this.findWindow != null && this.findWindow.window.isVisible(); }));
  431. editorUi.actions.put('exportVsdx', new Action(mxResources.get('formatVsdx') + ' (beta)...', function()
  432. {
  433. var delayed = mxUtils.bind(this, function()
  434. {
  435. // Checks for signature method
  436. if (typeof(VsdxExport) !== 'undefined')
  437. {
  438. try
  439. {
  440. new VsdxExport(editorUi).exportCurrentDiagrams();
  441. }
  442. catch (e)
  443. {
  444. // ignore
  445. }
  446. }
  447. });
  448. if (typeof(VsdxExport) === 'undefined' && !this.loadingVsdx && !editorUi.isOffline())
  449. {
  450. this.loadingVsdx = true;
  451. mxscript('js/vsdx.min.js', delayed);
  452. }
  453. else
  454. {
  455. window.setTimeout(delayed, 0);
  456. }
  457. }));
  458. // Adds language menu to options only if localStorage is available for
  459. // storing the choice. We do not want to use cookies for older browsers.
  460. // Note that the URL param lang=XX is available for setting the language
  461. // in older browsers. URL param has precedence over the saved setting.
  462. if (mxClient.IS_CHROMEAPP || (isLocalStorage && urlParams['offline'] != '1'))
  463. {
  464. this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
  465. {
  466. var addLangItem = mxUtils.bind(this, function (id)
  467. {
  468. var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
  469. var item = null;
  470. if (lang != '')
  471. {
  472. item = menu.addItem(lang, null, mxUtils.bind(this, function()
  473. {
  474. mxSettings.setLanguage(id);
  475. mxSettings.save();
  476. // Shows dialog in new language
  477. mxClient.language = id;
  478. mxResources.loadDefaultBundle = false;
  479. mxResources.add(RESOURCE_BASE);
  480. editorUi.alert(mxResources.get('restartForChangeRequired'));
  481. }), parent);
  482. if (id == mxLanguage || (id == '' && mxLanguage == null))
  483. {
  484. menu.addCheckmark(item, Editor.checkmarkImage);
  485. }
  486. }
  487. return item;
  488. });
  489. var item = addLangItem('');
  490. menu.addSeparator(parent);
  491. // LATER: Sort menu by language name
  492. for(var langId in mxLanguageMap)
  493. {
  494. addLangItem(langId);
  495. }
  496. })));
  497. // Extends the menubar with the language menu
  498. if (uiTheme != 'atlas')
  499. {
  500. var menusCreateMenuBar = Menus.prototype.createMenubar;
  501. Menus.prototype.createMenubar = function(container)
  502. {
  503. var menubar = menusCreateMenuBar.apply(this, arguments);
  504. if (menubar != null)
  505. {
  506. var langMenu = this.get('language');
  507. if (langMenu != null)
  508. {
  509. var elt = menubar.addMenu('', langMenu.funct);
  510. elt.setAttribute('title', mxResources.get('language'));
  511. elt.style.width = '16px';
  512. elt.style.paddingTop = '2px';
  513. elt.style.paddingLeft = '4px';
  514. elt.innerHTML = '<div class="geIcon geSprite geSprite-globe"/>';
  515. elt.style.zIndex = '1';
  516. elt.style.position = 'absolute';
  517. elt.style.top = '2px';
  518. elt.style.right = '17px';
  519. elt.style.display = 'block';
  520. if (!mxClient.IS_VML)
  521. {
  522. mxUtils.setOpacity(elt, 60);
  523. }
  524. document.body.appendChild(elt);
  525. }
  526. }
  527. return menubar;
  528. };
  529. }
  530. }
  531. this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
  532. {
  533. if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
  534. {
  535. this.addMenuItems(menu, ['about']);
  536. }
  537. else
  538. {
  539. // No translation for menu item since help is english only
  540. var item = menu.addItem('Search', null, null, parent, null, null, false);
  541. var form = document.createElement('div');
  542. form.style.display = 'inline';
  543. form.innerHTML = ':<form style="display:inline;margin-left:8px;"' +
  544. 'target="_blank" method="get" action="https://desk.draw.io/support/search/solutions">' +
  545. '<input type="text" name="term" size="25"></form>';
  546. item.firstChild.nextSibling.appendChild(form);
  547. item.style.backgroundColor = 'whiteSmoke';
  548. item.style.cursor = 'default';
  549. var realForm = form.getElementsByTagName('form')[0]
  550. var input = form.getElementsByTagName('input')[0];
  551. if (input != null && realForm != null)
  552. {
  553. mxEvent.addListener(realForm, 'submit', function()
  554. {
  555. // Logs search terms for improving search results
  556. if (EditorUi.enableLogging)
  557. {
  558. try
  559. {
  560. var img = new Image();
  561. var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
  562. img.src = logDomain + '/log?severity=CONFIG&msg=helpsearch:' + encodeURIComponent(input.value) + '&v=' + encodeURIComponent(EditorUi.VERSION);
  563. }
  564. catch (e)
  565. {
  566. // ignore
  567. }
  568. }
  569. // Workaround for blocked submit on iOS/IE11
  570. window.setTimeout(function()
  571. {
  572. editorUi.menubar.hideMenu();
  573. }, 0);
  574. });
  575. mxEvent.addGestureListeners(item, function(evt)
  576. {
  577. if (document.activeElement != input)
  578. {
  579. input.focus();
  580. }
  581. mxEvent.consume(evt);
  582. }, function(evt)
  583. {
  584. mxEvent.consume(evt);
  585. }, function(evt)
  586. {
  587. mxEvent.consume(evt);
  588. });
  589. // Sets initial focus on input element
  590. window.setTimeout(function()
  591. {
  592. input.focus();
  593. }, 0);
  594. }
  595. this.addMenuItems(menu, ['-', 'quickStart', 'userManual', 'keyboardShortcuts', '-']);
  596. if (!mxClient.IS_CHROMEAPP)
  597. {
  598. this.addMenuItems(menu, ['feedback']);
  599. }
  600. this.addMenuItems(menu, ['support', '-', 'about']);
  601. }
  602. if (urlParams['ruler'] == '1')
  603. {
  604. mxResources.parse('rulerInch=Ruler unit: Inches');
  605. this.editorUi.actions.addAction('rulerInch', mxUtils.bind(this, function()
  606. {
  607. this.editorUi.vRuler.setUnit(mxRuler.prototype.INCHES);
  608. this.editorUi.hRuler.setUnit(mxRuler.prototype.INCHES);
  609. this.editorUi.vRuler.drawRuler(true);
  610. this.editorUi.hRuler.drawRuler(true);
  611. }));
  612. mxResources.parse('rulerCM=Ruler unit: CMs');
  613. this.editorUi.actions.addAction('rulerCM', mxUtils.bind(this, function()
  614. {
  615. this.editorUi.vRuler.setUnit(mxRuler.prototype.CENTIMETER);
  616. this.editorUi.hRuler.setUnit(mxRuler.prototype.CENTIMETER);
  617. this.editorUi.vRuler.drawRuler(true);
  618. this.editorUi.hRuler.drawRuler(true);
  619. }));
  620. mxResources.parse('rulerPixel=Ruler unit: Pixels');
  621. this.editorUi.actions.addAction('rulerPixel', mxUtils.bind(this, function()
  622. {
  623. this.editorUi.vRuler.setUnit(mxRuler.prototype.PIXELS);
  624. this.editorUi.hRuler.setUnit(mxRuler.prototype.PIXELS);
  625. this.editorUi.vRuler.drawRuler(true);
  626. this.editorUi.hRuler.drawRuler(true);
  627. }));
  628. this.addMenuItems(menu, ['-', 'rulerInch', 'rulerCM', 'rulerPixel'], parent);
  629. }
  630. if (urlParams['test'] == '1')
  631. {
  632. // For showing the bounding box
  633. mxResources.parse('showBoundingBox=Show bounding box');
  634. this.editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  635. {
  636. var b = graph.getGraphBounds();
  637. var tr = graph.view.translate;
  638. var s = graph.view.scale;
  639. graph.insertVertex(parent, null, '', b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s, 'fillColor=none;strokeColor=red;');
  640. }));
  641. this.addMenuItems(menu, ['-', 'showBoundingBox'], parent);
  642. // For testing local XML export
  643. mxResources.parse('testXmlImageExport=XML Image Export');
  644. this.editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  645. {
  646. var bg = '#ffffff';
  647. var scale = 1;
  648. var b = 1;
  649. var imgExport = new mxImageExport();
  650. var bounds = graph.getGraphBounds();
  651. var vs = graph.view.scale;
  652. // New image export
  653. var xmlDoc = mxUtils.createXmlDocument();
  654. var root = xmlDoc.createElement('output');
  655. xmlDoc.appendChild(root);
  656. // Renders graph. Offset will be multiplied with state's scale when painting state.
  657. var xmlCanvas = new mxXmlCanvas2D(root);
  658. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  659. xmlCanvas.scale(scale / vs);
  660. var stateCounter = 0;
  661. var canvasSave = xmlCanvas.save;
  662. xmlCanvas.save = function()
  663. {
  664. stateCounter++;
  665. canvasSave.apply(this, arguments);
  666. };
  667. var canvasRestore = xmlCanvas.restore;
  668. xmlCanvas.restore = function()
  669. {
  670. stateCounter--;
  671. canvasRestore.apply(this, arguments);
  672. };
  673. var exportDrawShape = imgExport.drawShape;
  674. imgExport.drawShape = function(state)
  675. {
  676. mxLog.debug('entering shape', state, stateCounter);
  677. exportDrawShape.apply(this, arguments);
  678. mxLog.debug('leaving shape', state, stateCounter);
  679. };
  680. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  681. // Puts request data together
  682. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  683. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  684. mxLog.show();
  685. mxLog.debug(mxUtils.getXml(root));
  686. mxLog.debug('stateCounter', stateCounter);
  687. }));
  688. this.addMenuItems(menu, ['testXmlImageExport'], parent);
  689. mxResources.parse('testShowRtModel=Show RT model');
  690. mxResources.parse('testDebugRtModel=Debug RT model');
  691. mxResources.parse('testDownloadRtModel=Download RT model');
  692. this.editorUi.actions.addAction('testShowRtModel', mxUtils.bind(this, function()
  693. {
  694. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  695. {
  696. console.log('bytesUsed', this.editorUi.getCurrentFile().realtime.rtModel.bytesUsed);
  697. console.log('root', this.editorUi.getCurrentFile().realtime.dumpRoot());
  698. this.editorUi.getCurrentFile().realtime.check();
  699. }
  700. }));
  701. this.editorUi.actions.addAction('testDebugRtModel', mxUtils.bind(this, function()
  702. {
  703. gapi.drive.realtime.debug();
  704. }));
  705. this.editorUi.actions.addAction('testDownloadRtModel', mxUtils.bind(this, function()
  706. {
  707. var file = this.editorUi.getCurrentFile();
  708. if (file != null && file.realtime != null &&
  709. editorUi.spinner.spin(document.body, mxResources.get('export')))
  710. {
  711. // LATER: Download full model dump with history
  712. var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
  713. file.getHash().substring(1) + '/realtime', null, 'GET');
  714. // Adds auth token
  715. req.setRequestHeaders = function(request)
  716. {
  717. mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
  718. var token = gapi.auth.getToken().access_token;
  719. request.setRequestHeader('authorization', 'Bearer ' + token);
  720. };
  721. req.send(function(req)
  722. {
  723. editorUi.spinner.stop();
  724. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  725. {
  726. editorUi.saveLocalFile(req.getText(), 'realtime.txt', 'text/plain');
  727. }
  728. });
  729. }
  730. }));
  731. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  732. {
  733. this.addMenuItems(menu, ['-', 'testShowRtModel', 'testDebugRtModel', 'testDownloadRtModel'], parent);
  734. }
  735. mxResources.parse('testShowConsole=Show Console');
  736. this.editorUi.actions.addAction('testShowConsole', function()
  737. {
  738. if (!mxLog.isVisible())
  739. {
  740. mxLog.show();
  741. }
  742. else
  743. {
  744. mxLog.window.fit();
  745. }
  746. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  747. });
  748. this.addMenuItems(menu, ['-', 'testShowConsole']);
  749. }
  750. })));
  751. editorUi.actions.addAction('shapes...', function()
  752. {
  753. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  754. {
  755. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  756. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  757. }
  758. else
  759. {
  760. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  761. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  762. }
  763. });
  764. editorUi.actions.addAction('createShape...', function()
  765. {
  766. var file = editorUi.getCurrentFile();
  767. if (urlParams['embed'] == '1' || (file != null && file.isEditable()))
  768. {
  769. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  770. cell.vertex = true;
  771. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  772. editorUi.showDialog(dlg.container, 640, 480, true, false);
  773. dlg.init();
  774. }
  775. });
  776. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  777. {
  778. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  779. {
  780. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  781. {
  782. editorUi.spinner.stop();
  783. editorUi.showHtmlDialog(mxResources.get('create'), 'https://desk.draw.io/support/solutions/articles/16000042542',
  784. url, function(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  785. {
  786. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  787. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  788. {
  789. var dlg = new EmbedDialog(editorUi, html + '\n' + scriptTag, null, null, function()
  790. {
  791. var wnd = window.open();
  792. var doc = wnd.document;
  793. if (document.compatMode === 'CSS1Compat')
  794. {
  795. doc.writeln('<!DOCTYPE html>');
  796. }
  797. doc.writeln('<html>');
  798. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  799. '</title><meta charset="utf-8"></head>');
  800. doc.writeln('<body>');
  801. doc.writeln(html);
  802. var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
  803. if (direct)
  804. {
  805. doc.writeln(scriptTag);
  806. }
  807. doc.writeln('</body>');
  808. doc.writeln('</html>');
  809. doc.close();
  810. // Adds script tag after closing page and delay to fix timing issues
  811. if (!direct)
  812. {
  813. var info = wnd.document.createElement('div');
  814. info.marginLeft = '26px';
  815. info.marginTop = '26px';
  816. mxUtils.write(info, mxResources.get('updatingDocument'));
  817. var img = wnd.document.createElement('img');
  818. img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
  819. '/' + IMAGE_PATH + '/spin.gif');
  820. img.style.marginLeft = '6px';
  821. info.appendChild(img);
  822. wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
  823. window.setTimeout(function()
  824. {
  825. var script = document.createElement('script');
  826. script.type = 'text/javascript';
  827. script.src = /<script.*?src="(.*?)"/.exec(scriptTag)[1];
  828. doc.body.appendChild(script);
  829. info.parentNode.removeChild(info);
  830. }, 20);
  831. }
  832. });
  833. editorUi.showDialog(dlg.container, 440, 240, true, true);
  834. dlg.init();
  835. }));
  836. });
  837. });
  838. }
  839. }));
  840. editorUi.actions.put('liveImage', new Action('Live image...', function()
  841. {
  842. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  843. {
  844. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  845. {
  846. editorUi.spinner.stop();
  847. if (url != null)
  848. {
  849. var encUrl = encodeURIComponent(url);
  850. var dlg = new EmbedDialog(editorUi, EXPORT_URL + '?format=png&url=' + encUrl, 0);
  851. editorUi.showDialog(dlg.container, 440, 240, true, true);
  852. dlg.init();
  853. }
  854. else
  855. {
  856. editorUi.handleError({message: mxResources.get('invalidPublicUrl')});
  857. }
  858. });
  859. }
  860. }));
  861. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  862. {
  863. editorUi.showEmbedImageDialog(function(fit, shadow, retina, lightbox, editLink, layers)
  864. {
  865. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  866. {
  867. editorUi.createEmbedImage(fit, shadow, retina, lightbox, editLink, layers, function(result)
  868. {
  869. editorUi.spinner.stop();
  870. var dlg = new EmbedDialog(editorUi, result);
  871. editorUi.showDialog(dlg.container, 440, 240, true, true);
  872. dlg.init();
  873. }, function(err)
  874. {
  875. editorUi.spinner.stop();
  876. editorUi.handleError(err);
  877. });
  878. }
  879. }, mxResources.get('image'), mxResources.get('retina'), editorUi.isExportToCanvas());
  880. }));
  881. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  882. {
  883. editorUi.showEmbedImageDialog(function(fit, shadow, image, lightbox, editLink, layers)
  884. {
  885. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  886. {
  887. editorUi.createEmbedSvg(fit, shadow, image, lightbox, editLink, layers, function(result)
  888. {
  889. editorUi.spinner.stop();
  890. var dlg = new EmbedDialog(editorUi, result);
  891. editorUi.showDialog(dlg.container, 440, 240, true, true);
  892. dlg.init();
  893. }, function(err)
  894. {
  895. editorUi.spinner.stop();
  896. editorUi.handleError(err);
  897. });
  898. }
  899. }, mxResources.get('formatSvg'), mxResources.get('image'),
  900. true, 'https://desk.draw.io/support/solutions/articles/16000042548');
  901. }));
  902. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  903. {
  904. var bounds = graph.getGraphBounds();
  905. editorUi.showPublishLinkDialog(mxResources.get('iframe'), null, '100%',
  906. (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / graph.view.scale) + 2),
  907. function(linkTarget, linkColor, allPages, lightbox, editLink, layers, width, height)
  908. {
  909. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  910. {
  911. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  912. {
  913. editorUi.spinner.stop();
  914. var dlg = new EmbedDialog(editorUi, '<iframe frameborder="0" style="width:' + width +
  915. ';height:' + height + ';" src="' + editorUi.createLink(linkTarget, linkColor,
  916. allPages, lightbox, editLink, layers, url) + '"></iframe>');
  917. editorUi.showDialog(dlg.container, 440, 240, true, true);
  918. dlg.init();
  919. });
  920. }
  921. }, true);
  922. }));
  923. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  924. {
  925. editorUi.showPublishLinkDialog(null, null, null, null,
  926. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  927. {
  928. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  929. {
  930. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  931. {
  932. editorUi.spinner.stop();
  933. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  934. linkColor, allPages, lightbox, editLink, layers, url));
  935. editorUi.showDialog(dlg.container, 440, 240, true, true);
  936. dlg.init();
  937. });
  938. }
  939. });
  940. }));
  941. editorUi.actions.addAction('googleDocs...', function()
  942. {
  943. window.open('http://docsaddon.draw.io');
  944. });
  945. editorUi.actions.addAction('googleSites...', function()
  946. {
  947. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  948. {
  949. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  950. {
  951. editorUi.spinner.stop();
  952. var dlg = new GoogleSitesDialog(editorUi, url);
  953. editorUi.showDialog(dlg.container, 420, 256, true, true);
  954. dlg.init();
  955. });
  956. }
  957. });
  958. // Adds plugins menu item only if localStorage is available for storing the plugins
  959. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  960. {
  961. var action = editorUi.actions.addAction('scratchpad', function()
  962. {
  963. editorUi.toggleScratchpad();
  964. });
  965. action.setToggleAction(true);
  966. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  967. editorUi.actions.addAction('plugins...', function()
  968. {
  969. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 156, true, false);
  970. });
  971. }
  972. var action = editorUi.actions.addAction('search', function()
  973. {
  974. var visible = editorUi.sidebar.isEntryVisible('search');
  975. editorUi.sidebar.showPalette('search', !visible);
  976. if (isLocalStorage)
  977. {
  978. mxSettings.settings.search = !visible;
  979. mxSettings.save();
  980. }
  981. });
  982. action.setToggleAction(true);
  983. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  984. if (urlParams['embed'] == '1')
  985. {
  986. editorUi.actions.get('save').funct = function(exit)
  987. {
  988. if (graph.isEditing())
  989. {
  990. graph.stopEditing();
  991. }
  992. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  993. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  994. if (urlParams['proto'] == 'json')
  995. {
  996. var msg = editorUi.createLoadMessage('save');
  997. msg.xml = data;
  998. if (exit)
  999. {
  1000. msg.exit = true;
  1001. }
  1002. data = JSON.stringify(msg);
  1003. }
  1004. var parent = window.opener || window.parent;
  1005. parent.postMessage(data, '*');
  1006. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  1007. {
  1008. editorUi.editor.modified = false;
  1009. editorUi.editor.setStatus('');
  1010. }
  1011. };
  1012. editorUi.actions.addAction('saveAndExit', function()
  1013. {
  1014. editorUi.actions.get('save').funct(true);
  1015. });
  1016. editorUi.actions.addAction('exit', function()
  1017. {
  1018. var fn = function()
  1019. {
  1020. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  1021. modified: editorUi.editor.modified}) : '';
  1022. var parent = window.opener || window.parent;
  1023. parent.postMessage(msg, '*');
  1024. }
  1025. if (!editorUi.editor.modified)
  1026. {
  1027. fn();
  1028. }
  1029. else
  1030. {
  1031. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  1032. mxResources.get('cancel'), mxResources.get('discardChanges'));
  1033. }
  1034. });
  1035. }
  1036. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  1037. {
  1038. if (editorUi.isExportToCanvas())
  1039. {
  1040. menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
  1041. {
  1042. // TODO: Enable include option if CRC is fixed
  1043. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  1044. 'https://support.draw.io/display/DO/Exporting+Files',
  1045. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1046. addShadow, editable, embedImages, border, cropImage, currentPage)
  1047. {
  1048. var val = parseInt(scale);
  1049. if (!isNaN(val) && val > 0)
  1050. {
  1051. this.editorUi.exportImage(val / 100, transparentBackground, ignoreSelection,
  1052. addShadow, editable, border, !cropImage, currentPage);
  1053. }
  1054. }), true, false, 'png');
  1055. }), parent);
  1056. if (editorUi.jpgSupported)
  1057. {
  1058. menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
  1059. {
  1060. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  1061. 'https://support.draw.io/display/DO/Exporting+Files',
  1062. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1063. addShadow, editable, embedImages, border, cropImage, currentPage)
  1064. {
  1065. var val = parseInt(scale);
  1066. if (!isNaN(val) && val > 0)
  1067. {
  1068. this.editorUi.exportImage(val / 100, false, ignoreSelection,
  1069. addShadow, false, border, !cropImage, false, 'jpeg');
  1070. }
  1071. }), true, false, 'jpeg');
  1072. }), parent);
  1073. }
  1074. }
  1075. // Disabled for standalone mode in iOS because new tab cannot be closed
  1076. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1077. {
  1078. menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
  1079. {
  1080. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  1081. {
  1082. this.editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection);
  1083. }));
  1084. }), parent);
  1085. menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
  1086. {
  1087. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  1088. {
  1089. this.editorUi.downloadFile('jpeg', null, null, ignoreSelection);
  1090. }), true);
  1091. }), parent);
  1092. }
  1093. menu.addItem(mxResources.get('formatSvg') + '...', null, mxUtils.bind(this, function()
  1094. {
  1095. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  1096. 'https://support.draw.io/display/DO/Exporting+Files',
  1097. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1098. addShadow, editable, embedImages, border, cropImage, currentPage)
  1099. {
  1100. var val = parseInt(scale);
  1101. if (!isNaN(val) && val > 0)
  1102. {
  1103. this.editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection,
  1104. addShadow, editable, embedImages, border, !cropImage, currentPage);
  1105. }
  1106. }), true, null, 'svg');
  1107. }), parent);
  1108. menu.addSeparator(parent);
  1109. // Redirects export to PDF to print in Chrome App
  1110. if (editorUi.isOffline() || editorUi.printPdfExport)
  1111. {
  1112. menu.addItem(mxResources.get('formatPdf') + '...', null, this.editorUi.actions.get('exportPdf').funct, parent);
  1113. }
  1114. // Disabled for standalone mode in iOS because new tab cannot be closed
  1115. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1116. {
  1117. menu.addItem(mxResources.get('formatPdf') + '...', null, mxUtils.bind(this, function()
  1118. {
  1119. var div = document.createElement('div');
  1120. div.style.whiteSpace = 'nowrap';
  1121. var hd = document.createElement('h3');
  1122. mxUtils.write(hd, mxResources.get('formatPdf'));
  1123. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  1124. div.appendChild(hd);
  1125. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  1126. false, graph.isSelectionEmpty());
  1127. var crop = editorUi.addCheckbox(div, mxResources.get('crop'),
  1128. !graph.pageVisible || !editorUi.pdfPageExport,
  1129. !editorUi.pdfPageExport);
  1130. crop.style.marginBottom = '16px';
  1131. // Crop is only enabled if selection only is selected
  1132. if (!editorUi.pdfPageExport)
  1133. {
  1134. mxEvent.addListener(selection, 'change', function()
  1135. {
  1136. if (selection.checked)
  1137. {
  1138. crop.removeAttribute('disabled');
  1139. }
  1140. else
  1141. {
  1142. crop.setAttribute('disabled', 'disabled');
  1143. }
  1144. });
  1145. }
  1146. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  1147. {
  1148. this.editorUi.downloadFile('pdf', null, null, !selection.checked, null, !crop.checked);
  1149. }), null, mxResources.get('export'));
  1150. this.editorUi.showDialog(dlg.container, 300, 146, true, true);
  1151. }), parent);
  1152. }
  1153. menu.addItem(mxResources.get('formatHtmlEmbedded') + '...', null, mxUtils.bind(this, function()
  1154. {
  1155. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1156. {
  1157. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1158. {
  1159. editorUi.spinner.stop();
  1160. editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
  1161. initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  1162. {
  1163. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  1164. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  1165. {
  1166. var basename = editorUi.getBaseFilename();
  1167. var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
  1168. '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
  1169. '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
  1170. editorUi.saveData(basename + '.html', 'html', result, 'text/html');
  1171. }));
  1172. });
  1173. });
  1174. }
  1175. //this.editorUi.downloadFile('html');
  1176. }), parent);
  1177. // LATER: Fix namespace prefix (NS1, NS2..) in XML
  1178. // serializer for VSDX export in IE11 and earlier
  1179. if (!mxClient.IS_IE11 && !mxClient.IS_IE && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
  1180. {
  1181. this.addMenuItems(menu, ['exportVsdx'], parent);
  1182. }
  1183. menu.addSeparator(parent);
  1184. menu.addItem(mxResources.get('formatXml') + '...', null, mxUtils.bind(this, function()
  1185. {
  1186. var div = document.createElement('div');
  1187. div.style.whiteSpace = 'nowrap';
  1188. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  1189. var hd = document.createElement('h3');
  1190. mxUtils.write(hd, mxResources.get('formatXml'));
  1191. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  1192. div.appendChild(hd);
  1193. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  1194. false, graph.isSelectionEmpty());
  1195. var pages = editorUi.addCheckbox(div, mxResources.get((noPages) ? 'compressed' : 'allPages'), true);
  1196. pages.style.marginBottom = '16px';
  1197. mxEvent.addListener(selection, 'change', function()
  1198. {
  1199. if (selection.checked)
  1200. {
  1201. pages.setAttribute('disabled', 'disabled');
  1202. }
  1203. else
  1204. {
  1205. pages.removeAttribute('disabled');
  1206. }
  1207. });
  1208. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  1209. {
  1210. editorUi.downloadFile('xml', (noPages) ? !pages.checked : null, null,
  1211. !selection.checked, (!noPages) ? !pages.checked : null);
  1212. }), null, mxResources.get('export'));
  1213. this.editorUi.showDialog(dlg.container, 300, 146, true, true);
  1214. }), parent);
  1215. // Disables menu item for all external hosted integrations
  1216. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp ||/.*\.draw\.io$/.test(window.location.hostname))
  1217. {
  1218. menu.addItem(mxResources.get('url') + '...', null, mxUtils.bind(this, function()
  1219. {
  1220. editorUi.showPublishLinkDialog(mxResources.get('url'), true, null, null,
  1221. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  1222. {
  1223. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  1224. linkColor, allPages, lightbox, editLink, layers, null, true));
  1225. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1226. dlg.init();
  1227. });
  1228. }), parent);
  1229. }
  1230. if (!editorUi.isOffline())
  1231. {
  1232. menu.addSeparator(parent);
  1233. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  1234. }
  1235. })));
  1236. this.editorUi.actions.addAction('chatWindowTitle...', mxUtils.bind(this.editorUi, this.editorUi.toggleChat));
  1237. this.put('importFrom', new Menu(function(menu, parent)
  1238. {
  1239. function importFile(device)
  1240. {
  1241. if (device && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  1242. {
  1243. var input = document.createElement('input');
  1244. input.setAttribute('type', 'file');
  1245. mxEvent.addListener(input, 'change', function()
  1246. {
  1247. if (input.files != null)
  1248. {
  1249. // Using null for position will disable crop of input file
  1250. editorUi.importFiles(input.files, null, null, editorUi.maxImageSize);
  1251. }
  1252. });
  1253. input.click();
  1254. }
  1255. else
  1256. {
  1257. window.openNew = false;
  1258. window.openKey = 'import';
  1259. var prevValue = Editor.useLocalStorage;
  1260. Editor.useLocalStorage = !device;
  1261. // Closes dialog after open
  1262. window.openFile = new OpenFile(function(cancel)
  1263. {
  1264. editorUi.hideDialog(cancel);
  1265. });
  1266. window.openFile.setConsumer(function(xml, filename)
  1267. {
  1268. graph.setSelectionCells(editorUi.importXml(xml));
  1269. });
  1270. // Removes openFile if dialog is closed
  1271. editorUi.showDialog(new OpenDialog(editorUi).container, 360, 220, true, true, function()
  1272. {
  1273. window.openFile = null;
  1274. });
  1275. // Extends dialog close to show splash screen
  1276. var dlg = editorUi.dialog;
  1277. var dlgClose = dlg.close;
  1278. editorUi.dialog.close = function(cancel)
  1279. {
  1280. Editor.useLocalStorage = prevValue;
  1281. dlgClose.apply(dlg, arguments);
  1282. if (cancel && editorUi.getCurrentFile() == null && urlParams['embed'] != '1')
  1283. {
  1284. editorUi.showSplash();
  1285. }
  1286. };
  1287. }
  1288. };
  1289. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  1290. {
  1291. // Gets insert location
  1292. var view = graph.view;
  1293. var bds = graph.getGraphBounds();
  1294. var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
  1295. var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
  1296. if (data.substring(0, 11) == 'data:image/')
  1297. {
  1298. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  1299. {
  1300. var resizeImages = true;
  1301. var doInsert = mxUtils.bind(this, function()
  1302. {
  1303. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  1304. {
  1305. var s = (resizeImages) ? Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2)) : 1;
  1306. editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  1307. {
  1308. editorUi.spinner.stop();
  1309. graph.setSelectionCells(cells);
  1310. graph.scrollCellToVisible(graph.getSelectionCell());
  1311. });
  1312. }), resizeImages);
  1313. });
  1314. if (data.length > editorUi.resampleThreshold)
  1315. {
  1316. editorUi.confirmImageResize(function(doResize)
  1317. {
  1318. resizeImages = doResize;
  1319. doInsert();
  1320. });
  1321. }
  1322. else
  1323. {
  1324. doInsert();
  1325. }
  1326. }), mxUtils.bind(this, function()
  1327. {
  1328. editorUi.handleError({message: mxResources.get('cannotOpenFile')});
  1329. }));
  1330. }
  1331. else
  1332. {
  1333. editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
  1334. {
  1335. editorUi.spinner.stop();
  1336. graph.setSelectionCells(cells);
  1337. graph.scrollCellToVisible(graph.getSelectionCell());
  1338. });
  1339. }
  1340. });
  1341. var getMimeType = mxUtils.bind(this, function(filename)
  1342. {
  1343. var mime = 'text/xml';
  1344. if (/\.png$/i.test(filename))
  1345. {
  1346. mime = 'image/png';
  1347. }
  1348. else if (/\.jpe?g$/i.test(filename))
  1349. {
  1350. mime = 'image/jpg';
  1351. }
  1352. else if (/\.gif$/i.test(filename))
  1353. {
  1354. mime = 'image/gif';
  1355. }
  1356. return mime;
  1357. });
  1358. function pickFileFromService(service)
  1359. {
  1360. // Drive requires special arguments for libraries and bypassing realtime
  1361. service.pickFile(function(id)
  1362. {
  1363. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1364. {
  1365. // NOTE The third argument in getFile says denyConvert to match
  1366. // the existing signature in the original DriveClient which has
  1367. // as slightly different semantic, but works the same way.
  1368. service.getFile(id, function(file)
  1369. {
  1370. var mime = getMimeType(file.getTitle());
  1371. // Imports SVG as images
  1372. if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
  1373. {
  1374. file.setData(editorUi.createSvgDataUri(file.getData()));
  1375. mime = 'image/svg+xml';
  1376. }
  1377. doImportFile(file.getData(), mime, file.getTitle());
  1378. },
  1379. function(resp)
  1380. {
  1381. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1382. }, service == editorUi.drive);
  1383. }
  1384. }, true);
  1385. };
  1386. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1387. {
  1388. if (editorUi.drive != null)
  1389. {
  1390. // Requires special arguments for libraries and realtime
  1391. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1392. {
  1393. pickFileFromService(editorUi.drive);
  1394. }, parent);
  1395. }
  1396. else if (googleEnabled)
  1397. {
  1398. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1399. {
  1400. // do nothing
  1401. }, parent, null, false);
  1402. }
  1403. }
  1404. if (editorUi.gitHub != null)
  1405. {
  1406. menu.addItem(mxResources.get('github') + '...', null, function()
  1407. {
  1408. pickFileFromService(editorUi.gitHub);
  1409. }, parent);
  1410. }
  1411. if (editorUi.dropbox != null)
  1412. {
  1413. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1414. {
  1415. pickFileFromService(editorUi.dropbox);
  1416. }, parent);
  1417. }
  1418. else if (dropboxEnabled)
  1419. {
  1420. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1421. {
  1422. // do nothing
  1423. }, parent, null, false);
  1424. }
  1425. if (editorUi.oneDrive != null)
  1426. {
  1427. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1428. {
  1429. pickFileFromService(editorUi.oneDrive);
  1430. }, parent);
  1431. }
  1432. else if (oneDriveEnabled)
  1433. {
  1434. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1435. {
  1436. // do nothing
  1437. }, parent, null, false);
  1438. }
  1439. if (editorUi.trello != null)
  1440. {
  1441. menu.addItem(mxResources.get('trello') + '...', null, function()
  1442. {
  1443. pickFileFromService(editorUi.trello);
  1444. }, parent);
  1445. }
  1446. else if (trelloEnabled)
  1447. {
  1448. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  1449. {
  1450. // do nothing
  1451. }, parent, null, false);
  1452. }
  1453. menu.addSeparator(parent);
  1454. if (isLocalStorage && urlParams['browser'] != '0')
  1455. {
  1456. menu.addItem(mxResources.get('browser') + '...', null, function()
  1457. {
  1458. importFile(false);
  1459. }, parent);
  1460. }
  1461. if (!mxClient.IS_IOS)
  1462. {
  1463. menu.addItem(mxResources.get('device') + '...', null, function()
  1464. {
  1465. importFile(true);
  1466. }, parent);
  1467. }
  1468. if (!editorUi.isOffline())
  1469. {
  1470. menu.addSeparator(parent);
  1471. menu.addItem(mxResources.get('url') + '...', null, function()
  1472. {
  1473. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1474. {
  1475. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1476. {
  1477. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1478. // Uses proxy to avoid CORS issues
  1479. editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1480. {
  1481. doImportFile(data, mime, fileUrl);
  1482. },
  1483. function ()
  1484. {
  1485. editorUi.spinner.stop();
  1486. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1487. }, mime == 'image/png');
  1488. }
  1489. }, mxResources.get('url'));
  1490. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1491. dlg.init();
  1492. }, parent);
  1493. }
  1494. menu.addItem(mxResources.get('csv') + '...', null, function()
  1495. {
  1496. editorUi.showImportCsvDialog();
  1497. }, parent);
  1498. })).isEnabled = isGraphEnabled;
  1499. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1500. {
  1501. var item = menu.addItem(mxResources.get('kennedy'), null, function()
  1502. {
  1503. mxSettings.setUi('');
  1504. mxSettings.save();
  1505. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1506. }, parent);
  1507. if (uiTheme != 'atlas')
  1508. {
  1509. menu.addCheckmark(item, Editor.checkmarkImage);
  1510. }
  1511. item = menu.addItem(mxResources.get('atlas'), null, function()
  1512. {
  1513. mxSettings.setUi('atlas');
  1514. mxSettings.save();
  1515. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1516. }, parent);
  1517. if (uiTheme == 'atlas')
  1518. {
  1519. menu.addCheckmark(item, Editor.checkmarkImage);
  1520. }
  1521. })));
  1522. this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  1523. {
  1524. var file = this.editorUi.getCurrentFile();
  1525. if (file != null)
  1526. {
  1527. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  1528. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  1529. {
  1530. if (title != null && title.length > 0 && file != null && this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  1531. {
  1532. // Delete old file, save new file in dropbox if autosize is enabled
  1533. file.rename(title, mxUtils.bind(this, function(resp)
  1534. {
  1535. this.editorUi.spinner.stop();
  1536. }),
  1537. mxUtils.bind(this, function(resp)
  1538. {
  1539. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  1540. }));
  1541. }
  1542. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  1543. mxResources.get('diagramName') : null, function(name)
  1544. {
  1545. if (name != null && name.length > 0)
  1546. {
  1547. return true;
  1548. }
  1549. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  1550. return false;
  1551. });
  1552. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1553. dlg.init();
  1554. }
  1555. })).isEnabled = isGraphEnabled;
  1556. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  1557. {
  1558. var file = editorUi.getCurrentFile();
  1559. if (file != null)
  1560. {
  1561. var title = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  1562. // Handles extension
  1563. var extension = '';
  1564. var dot = title.lastIndexOf('.');
  1565. if (dot >= 0)
  1566. {
  1567. extension = title.substring(dot);
  1568. title = title.substring(0, dot);
  1569. }
  1570. title = mxResources.get('copyOf', [title]) + extension;
  1571. if (file.constructor == DriveFile)
  1572. {
  1573. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  1574. {
  1575. // Mode is "download" if Create button is pressed, means use Google Drive
  1576. if (mode == 'download')
  1577. {
  1578. mode = App.MODE_GOOGLE;
  1579. }
  1580. if (newTitle != null && newTitle.length > 0)
  1581. {
  1582. if (mode == App.MODE_GOOGLE)
  1583. {
  1584. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  1585. {
  1586. // Makes sure the latest XML is in the file
  1587. file.save(false, mxUtils.bind(this, function()
  1588. {
  1589. // Saveas does not update the file descriptor in Google Drive
  1590. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  1591. {
  1592. editorUi.spinner.stop();
  1593. var url = editorUi.getUrl();
  1594. window.openWindow(url + '#G' + resp.id, null, mxUtils.bind(this, function()
  1595. {
  1596. window.location.hash = 'G' + resp.id;
  1597. }));
  1598. }), mxUtils.bind(this, function(resp)
  1599. {
  1600. editorUi.handleError(resp);
  1601. }));
  1602. }), mxUtils.bind(this, function(resp)
  1603. {
  1604. editorUi.handleError(resp);
  1605. }));
  1606. }
  1607. }
  1608. else
  1609. {
  1610. this.editorUi.createFile(newTitle, this.editorUi.getFileData(true), null, mode);
  1611. }
  1612. }
  1613. }), mxUtils.bind(this, function()
  1614. {
  1615. editorUi.hideDialog();
  1616. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  1617. null, null, null, true);
  1618. editorUi.showDialog(dlg.container, 420, 380, true, true);
  1619. dlg.init();
  1620. }
  1621. else
  1622. {
  1623. // Creates a copy with no predefined storage
  1624. editorUi.editor.editAsNew(editorUi.getEditBlankXml(), title);
  1625. }
  1626. }
  1627. }));
  1628. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  1629. {
  1630. var file = editorUi.getCurrentFile();
  1631. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  1632. {
  1633. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  1634. {
  1635. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  1636. {
  1637. file.move(folderId, mxUtils.bind(this, function(resp)
  1638. {
  1639. editorUi.spinner.stop();
  1640. }), mxUtils.bind(this, function(resp)
  1641. {
  1642. editorUi.handleError(resp);
  1643. }));
  1644. }
  1645. }));
  1646. }
  1647. }));
  1648. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  1649. {
  1650. this.addMenuItems(menu, ['publishLink'], parent);
  1651. })));
  1652. editorUi.actions.put('offline', new Action(mxResources.get('offline') + '...', function()
  1653. {
  1654. window.open('https://www.draw.io/app')
  1655. }));
  1656. editorUi.actions.put('download', new Action(mxResources.get('download') + '...', function()
  1657. {
  1658. window.open('https://download.draw.io')
  1659. }));
  1660. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  1661. {
  1662. var file = this.editorUi.getCurrentFile();
  1663. if (file != null)
  1664. {
  1665. this.editorUi.drive.showPermissions(file.getId());
  1666. }
  1667. }));
  1668. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  1669. {
  1670. if (urlParams['test'] == '1')
  1671. {
  1672. this.addMenuItems(menu, ['liveImage', '-'], parent);
  1673. }
  1674. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  1675. if (!navigator.standalone && !editorUi.isOffline())
  1676. {
  1677. this.addMenuItems(menu, ['embedIframe'], parent);
  1678. }
  1679. if (!editorUi.isOffline())
  1680. {
  1681. this.addMenuItems(menu, ['-', 'googleSites', 'googleDocs'], parent);
  1682. }
  1683. })));
  1684. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree', '-', 'organic', 'circle', '-', 'fromText'];
  1685. var addInsertItem = function(menu, parent, title, method)
  1686. {
  1687. menu.addItem(title, null, mxUtils.bind(this, function()
  1688. {
  1689. if (method == 'fromText')
  1690. {
  1691. var dlg = new ParseDialog(editorUi, title);
  1692. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1693. editorUi.dialog.container.style.overflow = 'auto';
  1694. dlg.init();
  1695. }
  1696. else
  1697. {
  1698. var dlg = new CreateGraphDialog(editorUi, title, method);
  1699. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1700. // Executed after dialog is added to dom
  1701. dlg.init();
  1702. }
  1703. }), parent);
  1704. };
  1705. editorUi.actions.addAction('insertText', function()
  1706. {
  1707. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1708. {
  1709. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1710. var cell = new mxCell('Text', new mxGeometry(pt.x, pt.y, 40, 20),
  1711. 'text;html=1;resizable=0;autosize=1;align=left;verticalAlign=top;spacingTop=-4;points=[];');
  1712. cell.vertex = true;
  1713. graph.startEditingAtCell(graph.addCell(cell));
  1714. }
  1715. }, null, null, Editor.ctrlKey + '+Shift+X').isEnabled = isGraphEnabled;
  1716. editorUi.actions.addAction('insertRectangle', function()
  1717. {
  1718. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1719. {
  1720. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1721. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 120, 60), 'whiteSpace=wrap;html=1;');
  1722. cell.vertex = true;
  1723. graph.setSelectionCell(graph.addCell(cell));
  1724. graph.scrollCellToVisible(graph.getSelectionCell());
  1725. }
  1726. }, null, null, Editor.ctrlKey + '+K').isEnabled = isGraphEnabled;
  1727. editorUi.actions.addAction('insertEllipse', function()
  1728. {
  1729. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1730. {
  1731. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1732. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 80, 80), 'ellipse;whiteSpace=wrap;html=1;');
  1733. cell.vertex = true;
  1734. graph.setSelectionCell(graph.addCell(cell));
  1735. graph.scrollCellToVisible(graph.getSelectionCell());
  1736. }
  1737. }, null, null, Editor.ctrlKey + '+Shift+K').isEnabled = isGraphEnabled;
  1738. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  1739. {
  1740. this.addMenuItems(menu, ['insertText', 'insertRectangle', 'insertEllipse', '-', 'insertLink', 'insertImage'], parent);
  1741. menu.addSeparator(parent);
  1742. for (var i = 0; i < methods.length; i++)
  1743. {
  1744. if (methods[i] == '-')
  1745. {
  1746. menu.addSeparator(parent);
  1747. }
  1748. else
  1749. {
  1750. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  1751. }
  1752. }
  1753. })));
  1754. this.put('openRecent', new Menu(function(menu, parent)
  1755. {
  1756. var recent = editorUi.getRecent();
  1757. if (recent != null)
  1758. {
  1759. for (var i = 0; i < recent.length; i++)
  1760. {
  1761. (function(entry)
  1762. {
  1763. var modeKey = entry.mode;
  1764. // Google and oneDrive use different keys
  1765. if (modeKey == App.MODE_GOOGLE)
  1766. {
  1767. modeKey = 'googleDrive';
  1768. }
  1769. else if (modeKey == App.MODE_ONEDRIVE)
  1770. {
  1771. modeKey = 'oneDrive';
  1772. }
  1773. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  1774. {
  1775. editorUi.loadFile(entry.id);
  1776. }, parent);
  1777. })(recent[i]);
  1778. }
  1779. menu.addSeparator(parent);
  1780. }
  1781. menu.addItem(mxResources.get('reset'), null, function()
  1782. {
  1783. editorUi.resetRecent();
  1784. }, parent);
  1785. }));
  1786. this.put('openFrom', new Menu(function(menu, parent)
  1787. {
  1788. if (editorUi.drive != null)
  1789. {
  1790. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1791. {
  1792. editorUi.pickFile(App.MODE_GOOGLE);
  1793. }, parent);
  1794. }
  1795. else if (googleEnabled)
  1796. {
  1797. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1798. {
  1799. // do nothing
  1800. }, parent, null, false);
  1801. }
  1802. if (editorUi.gitHub != null)
  1803. {
  1804. menu.addItem(mxResources.get('github') + '...', null, function()
  1805. {
  1806. editorUi.pickFile(App.MODE_GITHUB);
  1807. }, parent);
  1808. }
  1809. if (editorUi.dropbox != null)
  1810. {
  1811. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1812. {
  1813. editorUi.pickFile(App.MODE_DROPBOX);
  1814. }, parent);
  1815. }
  1816. else if (dropboxEnabled)
  1817. {
  1818. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1819. {
  1820. // do nothing
  1821. }, parent, null, false);
  1822. }
  1823. if (editorUi.oneDrive != null)
  1824. {
  1825. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1826. {
  1827. editorUi.pickFile(App.MODE_ONEDRIVE);
  1828. }, parent);
  1829. }
  1830. else if (oneDriveEnabled)
  1831. {
  1832. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1833. {
  1834. // do nothing
  1835. }, parent, null, false);
  1836. }
  1837. if (editorUi.trello != null)
  1838. {
  1839. menu.addItem(mxResources.get('trello') + '...', null, function()
  1840. {
  1841. editorUi.pickFile(App.MODE_TRELLO);
  1842. }, parent);
  1843. }
  1844. else if (trelloEnabled)
  1845. {
  1846. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  1847. {
  1848. // do nothing
  1849. }, parent, null, false);
  1850. }
  1851. menu.addSeparator(parent);
  1852. if (isLocalStorage && urlParams['browser'] != '0')
  1853. {
  1854. menu.addItem(mxResources.get('browser') + '...', null, function()
  1855. {
  1856. editorUi.pickFile(App.MODE_BROWSER);
  1857. }, parent);
  1858. }
  1859. if (!mxClient.IS_IOS)
  1860. {
  1861. menu.addItem(mxResources.get('device') + '...', null, function()
  1862. {
  1863. editorUi.pickFile(App.MODE_DEVICE);
  1864. }, parent);
  1865. }
  1866. if (!editorUi.isOffline())
  1867. {
  1868. menu.addSeparator(parent);
  1869. menu.addItem(mxResources.get('url') + '...', null, function()
  1870. {
  1871. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1872. {
  1873. if (fileUrl != null && fileUrl.length > 0)
  1874. {
  1875. if (editorUi.getCurrentFile() == null)
  1876. {
  1877. window.location.hash = '#U' + encodeURIComponent(fileUrl);
  1878. }
  1879. else
  1880. {
  1881. window.openWindow(((mxClient.IS_CHROMEAPP) ?
  1882. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  1883. window.location.search + '#U' + encodeURIComponent(fileUrl));
  1884. }
  1885. }
  1886. }, mxResources.get('url'));
  1887. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1888. dlg.init();
  1889. }, parent);
  1890. }
  1891. }));
  1892. this.put('newLibrary', new Menu(function(menu, parent)
  1893. {
  1894. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1895. {
  1896. if (editorUi.drive != null)
  1897. {
  1898. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1899. {
  1900. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  1901. }, parent);
  1902. }
  1903. else if (googleEnabled)
  1904. {
  1905. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1906. {
  1907. // do nothing
  1908. }, parent, null, false);
  1909. }
  1910. }
  1911. if (editorUi.gitHub != null)
  1912. {
  1913. menu.addItem(mxResources.get('github') + '...', null, function()
  1914. {
  1915. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
  1916. }, parent);
  1917. }
  1918. if (editorUi.dropbox != null)
  1919. {
  1920. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1921. {
  1922. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  1923. }, parent);
  1924. }
  1925. else if (dropboxEnabled)
  1926. {
  1927. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1928. {
  1929. // do nothing
  1930. }, parent, null, false);
  1931. }
  1932. if (editorUi.oneDrive != null)
  1933. {
  1934. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1935. {
  1936. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  1937. }, parent);
  1938. }
  1939. else if (oneDriveEnabled)
  1940. {
  1941. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1942. {
  1943. // do nothing
  1944. }, parent, null, false);
  1945. }
  1946. if (editorUi.trello != null)
  1947. {
  1948. menu.addItem(mxResources.get('trello') + '...', null, function()
  1949. {
  1950. editorUi.showLibraryDialog(null, null, null, null, App.MODE_TRELLO);
  1951. }, parent);
  1952. }
  1953. else if (trelloEnabled)
  1954. {
  1955. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  1956. {
  1957. // do nothing
  1958. }, parent, null, false);
  1959. }
  1960. menu.addSeparator(parent);
  1961. if (isLocalStorage && urlParams['browser'] != '0')
  1962. {
  1963. menu.addItem(mxResources.get('browser') + '...', null, function()
  1964. {
  1965. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  1966. }, parent);
  1967. }
  1968. if (!mxClient.IS_IOS)
  1969. {
  1970. menu.addItem(mxResources.get('device') + '...', null, function()
  1971. {
  1972. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  1973. }, parent);
  1974. }
  1975. }));
  1976. this.put('openLibraryFrom', new Menu(function(menu, parent)
  1977. {
  1978. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1979. {
  1980. if (editorUi.drive != null)
  1981. {
  1982. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1983. {
  1984. editorUi.pickLibrary(App.MODE_GOOGLE);
  1985. }, parent);
  1986. }
  1987. else if (googleEnabled)
  1988. {
  1989. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1990. {
  1991. // do nothing
  1992. }, parent, null, false);
  1993. }
  1994. }
  1995. if (editorUi.gitHub != null)
  1996. {
  1997. menu.addItem(mxResources.get('github') + '...', null, function()
  1998. {
  1999. editorUi.pickLibrary(App.MODE_GITHUB);
  2000. }, parent);
  2001. }
  2002. if (editorUi.dropbox != null)
  2003. {
  2004. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2005. {
  2006. editorUi.pickLibrary(App.MODE_DROPBOX);
  2007. }, parent);
  2008. }
  2009. else if (dropboxEnabled)
  2010. {
  2011. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2012. {
  2013. // do nothing
  2014. }, parent, null, false);
  2015. }
  2016. if (editorUi.oneDrive != null)
  2017. {
  2018. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2019. {
  2020. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  2021. }, parent);
  2022. }
  2023. else if (oneDriveEnabled)
  2024. {
  2025. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2026. {
  2027. // do nothing
  2028. }, parent, null, false);
  2029. }
  2030. if (editorUi.trello != null)
  2031. {
  2032. menu.addItem(mxResources.get('trello') + '...', null, function()
  2033. {
  2034. editorUi.pickLibrary(App.MODE_TRELLO);
  2035. }, parent);
  2036. }
  2037. else if (trelloEnabled)
  2038. {
  2039. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2040. {
  2041. // do nothing
  2042. }, parent, null, false);
  2043. }
  2044. menu.addSeparator(parent);
  2045. if (isLocalStorage && urlParams['browser'] != '0')
  2046. {
  2047. menu.addItem(mxResources.get('browser') + '...', null, function()
  2048. {
  2049. editorUi.pickLibrary(App.MODE_BROWSER);
  2050. }, parent);
  2051. }
  2052. if (!mxClient.IS_IOS)
  2053. {
  2054. menu.addItem(mxResources.get('device') + '...', null, function()
  2055. {
  2056. editorUi.pickLibrary(App.MODE_DEVICE);
  2057. }, parent);
  2058. }
  2059. if (!editorUi.isOffline())
  2060. {
  2061. menu.addSeparator(parent);
  2062. menu.addItem(mxResources.get('url') + '...', null, function()
  2063. {
  2064. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  2065. {
  2066. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2067. {
  2068. var realUrl = fileUrl;
  2069. if (!editorUi.isCorsEnabledForUrl(fileUrl))
  2070. {
  2071. realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
  2072. }
  2073. // Uses proxy to avoid CORS issues
  2074. mxUtils.get(realUrl, function(req)
  2075. {
  2076. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2077. {
  2078. editorUi.spinner.stop();
  2079. try
  2080. {
  2081. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  2082. }
  2083. catch (e)
  2084. {
  2085. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  2086. }
  2087. }
  2088. else
  2089. {
  2090. editorUi.spinner.stop();
  2091. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2092. }
  2093. }, function()
  2094. {
  2095. editorUi.spinner.stop();
  2096. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2097. });
  2098. }
  2099. }, mxResources.get('url'));
  2100. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2101. dlg.init();
  2102. }, parent);
  2103. }
  2104. }));
  2105. // Overrides edit menu to add find
  2106. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  2107. {
  2108. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-',
  2109. 'find', '-',
  2110. 'editData', 'editTooltip', 'editStyle', '-', 'edit', '-', 'editLink', 'openLink', '-',
  2111. 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
  2112. })));
  2113. // Overrides view menu to add search and scratchpad
  2114. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  2115. {
  2116. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  2117. concat(['outline', 'layers', '-']));
  2118. this.addMenuItems(menu, ['-', 'search'], parent);
  2119. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  2120. {
  2121. var item = this.addMenuItem(menu, 'scratchpad', parent);
  2122. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  2123. {
  2124. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000042367');
  2125. }
  2126. }
  2127. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
  2128. 'scrollbars', 'tooltips', '-',
  2129. 'grid', 'guides'], parent);
  2130. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  2131. {
  2132. this.addMenuItem(menu, 'shadowVisible', parent);
  2133. }
  2134. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  2135. 'resetView', 'zoomIn', 'zoomOut'], parent);
  2136. })));
  2137. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  2138. {
  2139. if (urlParams['embed'] != '1')
  2140. {
  2141. this.addSubmenu('theme', menu, parent);
  2142. menu.addSeparator(parent);
  2143. }
  2144. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  2145. if (typeof(MathJax) !== 'undefined')
  2146. {
  2147. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  2148. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  2149. }
  2150. if (urlParams['embed'] != '1')
  2151. {
  2152. this.addMenuItems(menu, ['autosave'], parent);
  2153. }
  2154. this.addMenuItems(menu, ['-', 'createShape', 'editDiagram'], parent);
  2155. menu.addSeparator(parent);
  2156. if (urlParams['embed'] != '1' && isLocalStorage)
  2157. {
  2158. this.addMenuItems(menu, ['showStartScreen'], parent);
  2159. }
  2160. if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
  2161. {
  2162. var item = this.addMenuItem(menu, 'plugins', parent);
  2163. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  2164. {
  2165. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000056430');
  2166. }
  2167. }
  2168. menu.addSeparator(parent);
  2169. var item = this.addMenuItem(menu, 'tags', parent);
  2170. if (!editorUi.isOffline())
  2171. {
  2172. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000046966');
  2173. }
  2174. menu.addSeparator(parent);
  2175. if (!editorUi.isOffline() && !navigator.standalone && urlParams['embed'] != '1')
  2176. {
  2177. this.addMenuItems(menu, ['download'], parent);
  2178. }
  2179. if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
  2180. {
  2181. this.addMenuItems(menu, ['offline'], parent);
  2182. }
  2183. })));
  2184. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  2185. {
  2186. if (urlParams['embed'] == '1')
  2187. {
  2188. this.addSubmenu('importFrom', menu, parent);
  2189. this.addSubmenu('exportAs', menu, parent);
  2190. this.addSubmenu('embed', menu, parent);
  2191. if (urlParams['libraries'] == '1')
  2192. {
  2193. this.addMenuItems(menu, ['-'], parent);
  2194. this.addSubmenu('newLibrary', menu, parent);
  2195. this.addSubmenu('openLibraryFrom', menu, parent);
  2196. }
  2197. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'save'], parent);
  2198. if (urlParams['saveAndExit'] == '1')
  2199. {
  2200. this.addMenuItems(menu, ['saveAndExit'], parent);
  2201. }
  2202. this.addMenuItems(menu, ['exit'], parent);
  2203. }
  2204. else
  2205. {
  2206. var file = this.editorUi.getCurrentFile();
  2207. if (file != null && file.constructor == DriveFile)
  2208. {
  2209. if (file.isRestricted())
  2210. {
  2211. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  2212. }
  2213. if (file.realtime == null)
  2214. {
  2215. this.addMenuItems(menu, ['save', 'share', '-'], parent);
  2216. }
  2217. else
  2218. {
  2219. if (!file.isAutosave())
  2220. {
  2221. this.addMenuItems(menu, ['save'], parent);
  2222. }
  2223. this.addMenuItems(menu, ['share', 'chatWindowTitle', '-'], parent);
  2224. }
  2225. }
  2226. else
  2227. {
  2228. this.addMenuItems(menu, ['new'], parent);
  2229. }
  2230. this.addSubmenu('openFrom', menu, parent);
  2231. if (isLocalStorage)
  2232. {
  2233. this.addSubmenu('openRecent', menu, parent);
  2234. }
  2235. if (file != null && file.constructor == DriveFile)
  2236. {
  2237. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  2238. }
  2239. else
  2240. {
  2241. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-', 'rename'], parent);
  2242. if (editorUi.isOfflineApp())
  2243. {
  2244. if (!editorUi.isOffline())
  2245. {
  2246. this.addMenuItems(menu, ['upload'], parent);
  2247. }
  2248. }
  2249. else
  2250. {
  2251. this.addMenuItems(menu, ['makeCopy'], parent);
  2252. if (file != null && file.constructor == OneDriveFile)
  2253. {
  2254. this.addMenuItems(menu, ['moveToFolder'], parent);
  2255. }
  2256. }
  2257. }
  2258. menu.addSeparator(parent);
  2259. this.addSubmenu('importFrom', menu, parent);
  2260. this.addSubmenu('exportAs', menu, parent);
  2261. menu.addSeparator(parent);
  2262. this.addSubmenu('embed', menu, parent);
  2263. this.addSubmenu('publish', menu, parent);
  2264. menu.addSeparator(parent);
  2265. this.addSubmenu('newLibrary', menu, parent);
  2266. this.addSubmenu('openLibraryFrom', menu, parent);
  2267. if (file != null && (file.constructor == DriveFile || file.constructor == DropboxFile))
  2268. {
  2269. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  2270. }
  2271. if (file != null && file.constructor == DriveFile)
  2272. {
  2273. this.addMenuItems(menu, ['createRevision'], parent);
  2274. }
  2275. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  2276. // Cannot use print in standalone mode on iOS as we cannot open new windows
  2277. if (!mxClient.IS_IOS || !navigator.standalone)
  2278. {
  2279. this.addMenuItems(menu, ['print'], parent);
  2280. }
  2281. this.addMenuItems(menu, ['-', 'close']);
  2282. }
  2283. })));
  2284. };
  2285. /**
  2286. * Replaces help menu label with icon on small screen
  2287. */
  2288. var menuCreated = Menus.prototype.menuCreated;
  2289. Menus.prototype.menuCreated = function(menu, elt)
  2290. {
  2291. if (screen.width <= 480 && menu == this.get('help'))
  2292. {
  2293. elt.style.paddingRight = '0px';
  2294. elt.style.paddingLeft = '0px';
  2295. elt.innerHTML = '';
  2296. var icon = document.createElement('img');
  2297. icon.setAttribute('border', '0');
  2298. icon.setAttribute('valign', 'bottom');
  2299. icon.setAttribute('src', Editor.helpImage);
  2300. elt.appendChild(icon);
  2301. }
  2302. menuCreated.apply(this, arguments);
  2303. };
  2304. })();