Menus.js 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575
  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. if (!editorUi.isOffline())
  56. {
  57. var img = new Image();
  58. img.src = IMAGE_PATH + '/help.png';
  59. }
  60. editorUi.actions.addAction('new...', function()
  61. {
  62. var compact = editorUi.isOffline();
  63. var dlg = new NewDialog(editorUi, compact);
  64. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
  65. {
  66. if (cancel && editorUi.getCurrentFile() == null)
  67. {
  68. editorUi.showSplash();
  69. }
  70. });
  71. dlg.init();
  72. });
  73. // Export PDF action for chrome OS (same as print with different dialog title)
  74. editorUi.actions.addAction('exportPdf', function()
  75. {
  76. editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 360,
  77. (editorUi.pages != null && editorUi.pages.length > 1) ?
  78. 420 : 360, true, true);
  79. });
  80. editorUi.actions.addAction('open...', function()
  81. {
  82. editorUi.pickFile();
  83. });
  84. editorUi.actions.addAction('close', function()
  85. {
  86. editorUi.fileLoaded(null);
  87. });
  88. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  89. {
  90. var cells = graph.getSelectionCells();
  91. if (graph.getSelectionCount() == 1)
  92. {
  93. var cell = graph.getSelectionCell();
  94. var state = graph.view.getState(cell);
  95. if (state != null && state.shape != null && state.shape.stencil != null)
  96. {
  97. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  98. editorUi.showDialog(dlg.container, 640, 480, true, false);
  99. dlg.init();
  100. }
  101. }
  102. }));
  103. editorUi.actions.addAction('revisionHistory...', function()
  104. {
  105. var file = editorUi.getCurrentFile();
  106. if (file == null || (file.constructor != DriveFile && file.constructor != DropboxFile) ||
  107. (editorUi.drive == null && file.constructor == DriveFile) ||
  108. (editorUi.dropbox == null && file.constructor == DropboxFile))
  109. {
  110. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  111. }
  112. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  113. {
  114. if (file.constructor == DropboxFile)
  115. {
  116. // Limit is maximum number of entries to return
  117. var promise = editorUi.dropbox.client.filesListRevisions({path: file.stat.path_lower, limit: 100});
  118. promise.then(mxUtils.bind(this, function(response)
  119. {
  120. editorUi.spinner.stop();
  121. try
  122. {
  123. var revs = [];
  124. for (var i = response.entries.length - 1; i >= 0; i--)
  125. {
  126. (function(stat)
  127. {
  128. revs.push({modifiedDate: stat.client_modified, fileSize: stat.size, getXml: function(success, error)
  129. {
  130. editorUi.dropbox.readFile({path: file.stat.path_lower, rev: stat.rev}, success, error);
  131. }, getUrl: function()
  132. {
  133. return editorUi.getUrl(window.location.pathname + '?rev=' + stat.rev + '&chrome=0&edit=_blank') + window.location.hash;
  134. }});
  135. })(response.entries[i]);
  136. }
  137. var dlg = new RevisionDialog(editorUi, revs);
  138. editorUi.showDialog(dlg.container, 640, 480, true, true);
  139. dlg.init();
  140. }
  141. catch (e)
  142. {
  143. editorUi.handleError(e);
  144. }
  145. }));
  146. // Workaround for IE8/9 support with catch function
  147. promise['catch'](function(err)
  148. {
  149. editorUi.spinner.stop();
  150. editorUi.handleError(err);
  151. });
  152. }
  153. // Google Drive File
  154. else
  155. {
  156. editorUi.drive.executeRequest(gapi.client.drive.revisions.list({'fileId': file.getId()}), function(resp)
  157. {
  158. editorUi.spinner.stop();
  159. for (var i = 0; i < resp.items.length; i++)
  160. {
  161. (function(item)
  162. {
  163. item.getXml = function(success, error)
  164. {
  165. // Workaround for vanished head revision is to use current head revision from descriptor
  166. editorUi.drive.executeRequest(gapi.client.drive.revisions.get({'fileId': file.getId(),
  167. 'revisionId': (resp.items[resp.items.length - 1] === item) ?
  168. file.desc.headRevisionId : item.id}), function(resp)
  169. {
  170. editorUi.drive.getXmlFile(resp, null, function(file2)
  171. {
  172. success(file2.getData());
  173. }, function(resp)
  174. {
  175. error(resp);
  176. });
  177. }, function(resp)
  178. {
  179. error(resp);
  180. });
  181. };
  182. item.getUrl = function()
  183. {
  184. return editorUi.getUrl(window.location.pathname + '?rev=' + item.id + '&chrome=0&edit=_blank') + window.location.hash;
  185. };
  186. })(resp.items[i]);
  187. }
  188. var dlg = new RevisionDialog(editorUi, resp.items);
  189. editorUi.showDialog(dlg.container, 640, 480, true, true);
  190. dlg.init();
  191. }, function(resp)
  192. {
  193. editorUi.spinner.stop();
  194. editorUi.handleError(resp);
  195. });
  196. }
  197. }
  198. });
  199. editorUi.actions.addAction('createRevision', function()
  200. {
  201. editorUi.actions.get('save').funct();
  202. }, null, null, 'Ctrl+S');
  203. editorUi.actions.addAction('upload...', function()
  204. {
  205. var file = editorUi.getCurrentFile();
  206. if (file != null)
  207. {
  208. // Data is pulled from global variable after tab loads
  209. // LATER: Change to use message passing to deal with potential cross-domain
  210. window.drawdata = editorUi.getFileData();
  211. var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  212. window.open(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
  213. ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
  214. 'title=' + encodeURIComponent(filename));
  215. }
  216. });
  217. if (typeof(MathJax) !== 'undefined')
  218. {
  219. var action = editorUi.actions.addAction('mathematicalTypesetting', function()
  220. {
  221. editorUi.setMathEnabled(!editorUi.isMathEnabled());
  222. });
  223. action.setToggleAction(true);
  224. action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
  225. action.isEnabled = isGraphEnabled;
  226. }
  227. if (isLocalStorage)
  228. {
  229. var action = editorUi.actions.addAction('showStartScreen', function()
  230. {
  231. mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
  232. mxSettings.save();
  233. });
  234. action.setToggleAction(true);
  235. action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
  236. }
  237. var autosaveAction = editorUi.actions.addAction('autosave', function()
  238. {
  239. editorUi.editor.setAutosave(!editorUi.editor.autosave);
  240. });
  241. autosaveAction.setToggleAction(true);
  242. autosaveAction.setSelectedCallback(function()
  243. {
  244. return autosaveAction.isEnabled() && editorUi.editor.autosave;
  245. });
  246. editorUi.actions.addAction('editGeometry...', function()
  247. {
  248. var cells = graph.getSelectionCells();
  249. var vertices = [];
  250. for (var i = 0; i < cells.length; i++)
  251. {
  252. if (graph.getModel().isVertex(cells[i]))
  253. {
  254. vertices.push(cells[i]);
  255. }
  256. }
  257. if (vertices.length > 0)
  258. {
  259. var dlg = new EditGeometryDialog(editorUi, vertices);
  260. editorUi.showDialog(dlg.container, 180, 180, true, true);
  261. dlg.init();
  262. }
  263. }, null, null, 'Ctrl+Shift+M');
  264. var copiedStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'fontStyle',
  265. 'align', 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
  266. 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
  267. 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight', 'endFill', 'endArrow',
  268. 'endSize', 'startStill', 'startArrow', 'startSize', 'arcSize'];
  269. editorUi.actions.addAction('copyStyle', function()
  270. {
  271. var state = graph.view.getState(graph.getSelectionCell());
  272. if (graph.isEnabled() && state != null)
  273. {
  274. editorUi.copiedStyle = mxUtils.clone(state.style);
  275. // Handles special case for value "none"
  276. var cellStyle = graph.getModel().getStyle(state.cell);
  277. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  278. for (var j = 0; j < tokens.length; j++)
  279. {
  280. var tmp = tokens[j];
  281. var pos = tmp.indexOf('=');
  282. if (pos >= 0)
  283. {
  284. var key = tmp.substring(0, pos);
  285. var value = tmp.substring(pos + 1);
  286. if (editorUi.copiedStyle[key] == null && value == 'none')
  287. {
  288. editorUi.copiedStyle[key] = 'none';
  289. }
  290. }
  291. }
  292. }
  293. }, null, null, 'Ctrl+Shift+C');
  294. editorUi.actions.addAction('pasteStyle', function()
  295. {
  296. if (graph.isEnabled() && !graph.isSelectionEmpty() && editorUi.copiedStyle != null)
  297. {
  298. graph.getModel().beginUpdate();
  299. try
  300. {
  301. var cells = graph.getSelectionCells();
  302. for (var i = 0; i < cells.length; i++)
  303. {
  304. var state = graph.view.getState(cells[i]);
  305. for (var j = 0; j < copiedStyles.length; j++)
  306. {
  307. var key = copiedStyles[j];
  308. var value = editorUi.copiedStyle[key];
  309. if (state.style[key] != value)
  310. {
  311. graph.setCellStyles(key, value, [cells[i]]);
  312. }
  313. }
  314. }
  315. }
  316. finally
  317. {
  318. graph.getModel().endUpdate();
  319. }
  320. }
  321. }, null, null, 'Ctrl+Shift+V');
  322. editorUi.actions.put('pageBackgroundImage', new Action(mxResources.get('backgroundImage') + '...', function()
  323. {
  324. if (!editorUi.isOffline())
  325. {
  326. var apply = function(image)
  327. {
  328. editorUi.setBackgroundImage(image);
  329. };
  330. var dlg = new BackgroundImageDialog(editorUi, apply);
  331. editorUi.showDialog(dlg.container, 320, 170, true, true);
  332. dlg.init();
  333. }
  334. }));
  335. action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
  336. {
  337. graph.setShadowVisible(!graph.shadowVisible);
  338. }));
  339. action.setToggleAction(true);
  340. action.setSelectedCallback(function() { return graph.shadowVisible; });
  341. editorUi.actions.put('about', new Action(mxResources.get('aboutDrawio') + '...', function()
  342. {
  343. editorUi.showDialog(new AboutDialog(editorUi).container, 220, 300, true, true);
  344. }, null, null, 'F1'));
  345. editorUi.actions.addAction('userManual...', function()
  346. {
  347. window.open('https://support.draw.io/display/DO/Draw.io+Online+User+Manual');
  348. });
  349. editorUi.actions.addAction('support...', function()
  350. {
  351. window.open('https://support.draw.io/display/DO/draw.io+Online+Support');
  352. });
  353. editorUi.actions.addAction('exportOptionsDisabled...', function()
  354. {
  355. editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
  356. mxResources.get('exportOptionsDisabled'));
  357. });
  358. editorUi.actions.addAction('keyboardShortcuts...', function()
  359. {
  360. if (mxClient.IS_CHROMEAPP)
  361. {
  362. window.open('https://www.draw.io/shortcuts.svg');
  363. }
  364. else if (mxClient.IS_SVG)
  365. {
  366. window.open('shortcuts.svg');
  367. }
  368. else
  369. {
  370. window.open('https://www.draw.io/?lightbox=1#Uhttps%3A%2F%2Fwww.draw.io%2Fshortcuts.svg');
  371. }
  372. });
  373. editorUi.actions.addAction('feedback...', function()
  374. {
  375. var dlg = new FeedbackDialog(editorUi);
  376. editorUi.showDialog(dlg.container, 610, 360, true, true);
  377. dlg.init();
  378. });
  379. editorUi.actions.addAction('quickStart...', function()
  380. {
  381. window.open('https://youtu.be/Z0D96ZikMkc');
  382. });
  383. action = editorUi.actions.addAction('tags...', mxUtils.bind(this, function()
  384. {
  385. if (this.tagsWindow == null)
  386. {
  387. this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 380, 230, 280, 120);
  388. this.tagsWindow.window.addListener('show', function()
  389. {
  390. editorUi.fireEvent(new mxEventObject('tags'));
  391. });
  392. this.tagsWindow.window.addListener('hide', function()
  393. {
  394. editorUi.fireEvent(new mxEventObject('tags'));
  395. });
  396. this.tagsWindow.window.setVisible(true);
  397. editorUi.fireEvent(new mxEventObject('tags'));
  398. }
  399. else
  400. {
  401. this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
  402. }
  403. }));
  404. action.setToggleAction(true);
  405. action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
  406. action = editorUi.actions.addAction('find...', mxUtils.bind(this, function()
  407. {
  408. if (this.findWindow == null)
  409. {
  410. this.findWindow = new FindWindow(editorUi, document.body.offsetWidth - 300, 110, 204, 140);
  411. this.findWindow.window.addListener('show', function()
  412. {
  413. editorUi.fireEvent(new mxEventObject('find'));
  414. });
  415. this.findWindow.window.addListener('hide', function()
  416. {
  417. editorUi.fireEvent(new mxEventObject('find'));
  418. });
  419. this.findWindow.window.setVisible(true);
  420. editorUi.fireEvent(new mxEventObject('find'));
  421. }
  422. else
  423. {
  424. this.findWindow.window.setVisible(!this.findWindow.window.isVisible());
  425. }
  426. }));
  427. action.setToggleAction(true);
  428. action.setSelectedCallback(mxUtils.bind(this, function() { return this.findWindow != null && this.findWindow.window.isVisible(); }));
  429. editorUi.actions.put('exportVsdx', new Action(mxResources.get('formatVsdx') + ' (beta)...', function()
  430. {
  431. var delayed = mxUtils.bind(this, function()
  432. {
  433. // Checks for signature method
  434. if (typeof(VsdxExport) !== 'undefined')
  435. {
  436. try
  437. {
  438. new VsdxExport(editorUi).exportCurrentDiagrams();
  439. }
  440. catch (e)
  441. {
  442. // ignore
  443. }
  444. }
  445. });
  446. if (typeof(VsdxExport) === 'undefined' && !this.loadingVsdx && !editorUi.isOffline())
  447. {
  448. this.loadingVsdx = true;
  449. // Dependencies included in Devel.js
  450. mxscript('/js/vsdx.min.js', delayed);
  451. }
  452. else
  453. {
  454. // Must be async for cell selection
  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 in file menu only if localStorage is available for
  959. // storing the plugins.
  960. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  961. {
  962. var action = editorUi.actions.addAction('scratchpad', function()
  963. {
  964. editorUi.toggleScratchpad();
  965. });
  966. action.setToggleAction(true);
  967. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  968. editorUi.actions.addAction('plugins...', function()
  969. {
  970. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 156, true, false);
  971. });
  972. }
  973. var action = editorUi.actions.addAction('search', function()
  974. {
  975. var visible = editorUi.sidebar.isEntryVisible('search');
  976. editorUi.sidebar.showPalette('search', !visible);
  977. if (isLocalStorage)
  978. {
  979. mxSettings.settings.search = !visible;
  980. mxSettings.save();
  981. }
  982. });
  983. action.setToggleAction(true);
  984. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  985. if (urlParams['embed'] == '1')
  986. {
  987. editorUi.actions.get('save').funct = function(exit)
  988. {
  989. if (graph.isEditing())
  990. {
  991. graph.stopEditing();
  992. }
  993. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  994. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  995. if (urlParams['proto'] == 'json')
  996. {
  997. var msg = editorUi.createLoadMessage('save');
  998. msg.xml = data;
  999. if (exit)
  1000. {
  1001. msg.exit = true;
  1002. }
  1003. data = JSON.stringify(msg);
  1004. }
  1005. var parent = window.opener || window.parent;
  1006. parent.postMessage(data, '*');
  1007. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  1008. {
  1009. editorUi.editor.modified = false;
  1010. editorUi.editor.setStatus('');
  1011. }
  1012. };
  1013. editorUi.actions.addAction('saveAndExit', function()
  1014. {
  1015. editorUi.actions.get('save').funct(true);
  1016. });
  1017. editorUi.actions.addAction('exit', function()
  1018. {
  1019. var fn = function()
  1020. {
  1021. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  1022. modified: editorUi.editor.modified}) : '';
  1023. var parent = window.opener || window.parent;
  1024. parent.postMessage(msg, '*');
  1025. }
  1026. if (!editorUi.editor.modified)
  1027. {
  1028. fn();
  1029. }
  1030. else
  1031. {
  1032. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  1033. mxResources.get('cancel'), mxResources.get('discardChanges'));
  1034. }
  1035. });
  1036. }
  1037. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  1038. {
  1039. if (editorUi.isExportToCanvas())
  1040. {
  1041. menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
  1042. {
  1043. // TODO: Enable include option if CRC is fixed
  1044. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  1045. 'https://support.draw.io/display/DO/Exporting+Files',
  1046. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1047. addShadow, editable, embedImages, border, cropImage, currentPage)
  1048. {
  1049. var val = parseInt(scale);
  1050. if (!isNaN(val) && val > 0)
  1051. {
  1052. this.editorUi.exportImage(val / 100, transparentBackground, ignoreSelection,
  1053. addShadow, editable, border, !cropImage, currentPage);
  1054. }
  1055. }), true, false, 'png');
  1056. }), parent);
  1057. if (editorUi.jpgSupported)
  1058. {
  1059. menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
  1060. {
  1061. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  1062. 'https://support.draw.io/display/DO/Exporting+Files',
  1063. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1064. addShadow, editable, embedImages, border, cropImage, currentPage)
  1065. {
  1066. var val = parseInt(scale);
  1067. if (!isNaN(val) && val > 0)
  1068. {
  1069. this.editorUi.exportImage(val / 100, false, ignoreSelection,
  1070. addShadow, false, border, !cropImage, false, 'jpeg');
  1071. }
  1072. }), true, false, 'jpeg');
  1073. }), parent);
  1074. }
  1075. }
  1076. // Disabled for standalone mode in iOS because new tab cannot be closed
  1077. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1078. {
  1079. menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
  1080. {
  1081. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  1082. {
  1083. this.editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection);
  1084. }));
  1085. }), parent);
  1086. menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
  1087. {
  1088. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  1089. {
  1090. this.editorUi.downloadFile('jpeg', null, null, ignoreSelection);
  1091. }), true);
  1092. }), parent);
  1093. }
  1094. menu.addItem(mxResources.get('formatSvg') + '...', null, mxUtils.bind(this, function()
  1095. {
  1096. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  1097. 'https://support.draw.io/display/DO/Exporting+Files',
  1098. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1099. addShadow, editable, embedImages, border, cropImage, currentPage)
  1100. {
  1101. var val = parseInt(scale);
  1102. if (!isNaN(val) && val > 0)
  1103. {
  1104. this.editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection,
  1105. addShadow, editable, embedImages, border, !cropImage, currentPage);
  1106. }
  1107. }), true, null, 'svg');
  1108. }), parent);
  1109. menu.addSeparator(parent);
  1110. // Redirects export to PDF to print in Chrome App
  1111. if (editorUi.isOffline() || editorUi.printPdfExport)
  1112. {
  1113. menu.addItem(mxResources.get('formatPdf') + '...', null, this.editorUi.actions.get('exportPdf').funct, parent);
  1114. }
  1115. // Disabled for standalone mode in iOS because new tab cannot be closed
  1116. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1117. {
  1118. menu.addItem(mxResources.get('formatPdf') + '...', null, mxUtils.bind(this, function()
  1119. {
  1120. var div = document.createElement('div');
  1121. div.style.whiteSpace = 'nowrap';
  1122. var hd = document.createElement('h3');
  1123. mxUtils.write(hd, mxResources.get('formatPdf'));
  1124. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  1125. div.appendChild(hd);
  1126. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  1127. false, graph.isSelectionEmpty());
  1128. var crop = editorUi.addCheckbox(div, mxResources.get('crop'),
  1129. !graph.pageVisible || !editorUi.pdfPageExport,
  1130. !editorUi.pdfPageExport);
  1131. crop.style.marginBottom = '16px';
  1132. // Crop is only enabled if selection only is selected
  1133. if (!editorUi.pdfPageExport)
  1134. {
  1135. mxEvent.addListener(selection, 'change', function()
  1136. {
  1137. if (selection.checked)
  1138. {
  1139. crop.removeAttribute('disabled');
  1140. }
  1141. else
  1142. {
  1143. crop.setAttribute('disabled', 'disabled');
  1144. }
  1145. });
  1146. }
  1147. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  1148. {
  1149. this.editorUi.downloadFile('pdf', null, null, !selection.checked, null, !crop.checked);
  1150. }), null, mxResources.get('export'));
  1151. this.editorUi.showDialog(dlg.container, 300, 146, true, true);
  1152. }), parent);
  1153. }
  1154. menu.addItem(mxResources.get('formatHtmlEmbedded') + '...', null, mxUtils.bind(this, function()
  1155. {
  1156. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1157. {
  1158. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1159. {
  1160. editorUi.spinner.stop();
  1161. editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
  1162. initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  1163. {
  1164. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  1165. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  1166. {
  1167. var basename = editorUi.getBaseFilename();
  1168. var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
  1169. '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
  1170. '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
  1171. editorUi.saveData(basename + '.html', 'html', result, 'text/html');
  1172. }));
  1173. });
  1174. });
  1175. }
  1176. //this.editorUi.downloadFile('html');
  1177. }), parent);
  1178. // LATER: Fix namespace prefix (NS1, NS2..) in XML
  1179. // serializer for VSDX export in IE11 and earlier
  1180. if (!mxClient.IS_IE11 && !mxClient.IS_IE && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
  1181. {
  1182. this.addMenuItems(menu, ['exportVsdx'], parent);
  1183. }
  1184. menu.addSeparator(parent);
  1185. menu.addItem(mxResources.get('formatXml') + '...', null, mxUtils.bind(this, function()
  1186. {
  1187. var div = document.createElement('div');
  1188. div.style.whiteSpace = 'nowrap';
  1189. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  1190. var hd = document.createElement('h3');
  1191. mxUtils.write(hd, mxResources.get('formatXml'));
  1192. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  1193. div.appendChild(hd);
  1194. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  1195. false, graph.isSelectionEmpty());
  1196. var pages = editorUi.addCheckbox(div, mxResources.get((noPages) ? 'compressed' : 'allPages'), true);
  1197. pages.style.marginBottom = '16px';
  1198. mxEvent.addListener(selection, 'change', function()
  1199. {
  1200. if (selection.checked)
  1201. {
  1202. pages.setAttribute('disabled', 'disabled');
  1203. }
  1204. else
  1205. {
  1206. pages.removeAttribute('disabled');
  1207. }
  1208. });
  1209. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  1210. {
  1211. editorUi.downloadFile('xml', (noPages) ? !pages.checked : null, null,
  1212. !selection.checked, (!noPages) ? !pages.checked : null);
  1213. }), null, mxResources.get('export'));
  1214. this.editorUi.showDialog(dlg.container, 300, 146, true, true);
  1215. }), parent);
  1216. // Disables menu item for all external hosted integrations
  1217. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp ||/.*\.draw\.io$/.test(window.location.hostname))
  1218. {
  1219. menu.addItem(mxResources.get('url') + '...', null, mxUtils.bind(this, function()
  1220. {
  1221. editorUi.showPublishLinkDialog(mxResources.get('url'), true, null, null,
  1222. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  1223. {
  1224. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  1225. linkColor, allPages, lightbox, editLink, layers, null, true));
  1226. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1227. dlg.init();
  1228. });
  1229. }), parent);
  1230. }
  1231. if (!editorUi.isOffline())
  1232. {
  1233. menu.addSeparator(parent);
  1234. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  1235. }
  1236. })));
  1237. this.editorUi.actions.addAction('chatWindowTitle...', mxUtils.bind(this.editorUi, this.editorUi.toggleChat));
  1238. this.put('importFrom', new Menu(function(menu, parent)
  1239. {
  1240. function importFile(device)
  1241. {
  1242. if (device && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  1243. {
  1244. var input = document.createElement('input');
  1245. input.setAttribute('type', 'file');
  1246. mxEvent.addListener(input, 'change', function()
  1247. {
  1248. if (input.files != null)
  1249. {
  1250. // Using null for position will disable crop of input file
  1251. editorUi.importFiles(input.files, null, null, editorUi.maxImageSize);
  1252. }
  1253. });
  1254. input.click();
  1255. }
  1256. else
  1257. {
  1258. window.openNew = false;
  1259. window.openKey = 'import';
  1260. var prevValue = Editor.useLocalStorage;
  1261. Editor.useLocalStorage = !device;
  1262. // Closes dialog after open
  1263. window.openFile = new OpenFile(function(cancel)
  1264. {
  1265. editorUi.hideDialog(cancel);
  1266. });
  1267. window.openFile.setConsumer(function(xml, filename)
  1268. {
  1269. graph.setSelectionCells(editorUi.importXml(xml));
  1270. });
  1271. // Removes openFile if dialog is closed
  1272. editorUi.showDialog(new OpenDialog(editorUi).container, 360, 220, true, true, function()
  1273. {
  1274. window.openFile = null;
  1275. });
  1276. // Extends dialog close to show splash screen
  1277. var dlg = editorUi.dialog;
  1278. var dlgClose = dlg.close;
  1279. editorUi.dialog.close = function(cancel)
  1280. {
  1281. Editor.useLocalStorage = prevValue;
  1282. dlgClose.apply(dlg, arguments);
  1283. if (cancel && editorUi.getCurrentFile() == null && urlParams['embed'] != '1')
  1284. {
  1285. editorUi.showSplash();
  1286. }
  1287. };
  1288. }
  1289. };
  1290. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  1291. {
  1292. // Gets insert location
  1293. var view = graph.view;
  1294. var bds = graph.getGraphBounds();
  1295. var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
  1296. var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
  1297. if (data.substring(0, 11) == 'data:image/')
  1298. {
  1299. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  1300. {
  1301. var resizeImages = true;
  1302. var doInsert = mxUtils.bind(this, function()
  1303. {
  1304. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  1305. {
  1306. var s = (resizeImages) ? Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2)) : 1;
  1307. editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  1308. {
  1309. editorUi.spinner.stop();
  1310. graph.setSelectionCells(cells);
  1311. graph.scrollCellToVisible(graph.getSelectionCell());
  1312. });
  1313. }), resizeImages);
  1314. });
  1315. if (data.length > editorUi.resampleThreshold)
  1316. {
  1317. editorUi.confirmImageResize(function(doResize)
  1318. {
  1319. resizeImages = doResize;
  1320. doInsert();
  1321. });
  1322. }
  1323. else
  1324. {
  1325. doInsert();
  1326. }
  1327. }), mxUtils.bind(this, function()
  1328. {
  1329. editorUi.handleError({message: mxResources.get('cannotOpenFile')});
  1330. }));
  1331. }
  1332. else
  1333. {
  1334. editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
  1335. {
  1336. editorUi.spinner.stop();
  1337. graph.setSelectionCells(cells);
  1338. graph.scrollCellToVisible(graph.getSelectionCell());
  1339. });
  1340. }
  1341. });
  1342. var getMimeType = mxUtils.bind(this, function(filename)
  1343. {
  1344. var mime = 'text/xml';
  1345. if (/\.png$/i.test(filename))
  1346. {
  1347. mime = 'image/png';
  1348. }
  1349. else if (/\.jpe?g$/i.test(filename))
  1350. {
  1351. mime = 'image/jpg';
  1352. }
  1353. else if (/\.gif$/i.test(filename))
  1354. {
  1355. mime = 'image/gif';
  1356. }
  1357. return mime;
  1358. });
  1359. function pickFileFromService(service)
  1360. {
  1361. // Drive requires special arguments for libraries and bypassing realtime
  1362. service.pickFile(function(id)
  1363. {
  1364. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1365. {
  1366. // NOTE The third argument in getFile says denyConvert to match
  1367. // the existing signature in the original DriveClient which has
  1368. // as slightly different semantic, but works the same way.
  1369. service.getFile(id, function(file)
  1370. {
  1371. var mime = getMimeType(file.getTitle());
  1372. // Imports SVG as images
  1373. if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
  1374. {
  1375. file.setData(editorUi.createSvgDataUri(file.getData()));
  1376. mime = 'image/svg+xml';
  1377. }
  1378. doImportFile(file.getData(), mime, file.getTitle());
  1379. },
  1380. function(resp)
  1381. {
  1382. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1383. }, service == editorUi.drive);
  1384. }
  1385. }, true);
  1386. };
  1387. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1388. {
  1389. if (editorUi.drive != null)
  1390. {
  1391. // Requires special arguments for libraries and realtime
  1392. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1393. {
  1394. pickFileFromService(editorUi.drive);
  1395. }, parent);
  1396. }
  1397. else if (googleEnabled)
  1398. {
  1399. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1400. {
  1401. // do nothing
  1402. }, parent, null, false);
  1403. }
  1404. }
  1405. if (editorUi.gitHub != null)
  1406. {
  1407. menu.addItem(mxResources.get('github') + '...', null, function()
  1408. {
  1409. pickFileFromService(editorUi.gitHub);
  1410. }, parent);
  1411. }
  1412. if (editorUi.dropbox != null)
  1413. {
  1414. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1415. {
  1416. pickFileFromService(editorUi.dropbox);
  1417. }, parent);
  1418. }
  1419. else if (dropboxEnabled)
  1420. {
  1421. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1422. {
  1423. // do nothing
  1424. }, parent, null, false);
  1425. }
  1426. if (editorUi.oneDrive != null)
  1427. {
  1428. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1429. {
  1430. pickFileFromService(editorUi.oneDrive);
  1431. }, parent);
  1432. }
  1433. else if (oneDriveEnabled)
  1434. {
  1435. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1436. {
  1437. // do nothing
  1438. }, parent, null, false);
  1439. }
  1440. menu.addSeparator(parent);
  1441. if (isLocalStorage && urlParams['browser'] != '0')
  1442. {
  1443. menu.addItem(mxResources.get('browser') + '...', null, function()
  1444. {
  1445. importFile(false);
  1446. }, parent);
  1447. }
  1448. if (!mxClient.IS_IOS)
  1449. {
  1450. menu.addItem(mxResources.get('device') + '...', null, function()
  1451. {
  1452. importFile(true);
  1453. }, parent);
  1454. }
  1455. if (!editorUi.isOffline())
  1456. {
  1457. menu.addSeparator(parent);
  1458. menu.addItem(mxResources.get('url') + '...', null, function()
  1459. {
  1460. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1461. {
  1462. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1463. {
  1464. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1465. // Uses proxy to avoid CORS issues
  1466. editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1467. {
  1468. doImportFile(data, mime, fileUrl);
  1469. },
  1470. function ()
  1471. {
  1472. editorUi.spinner.stop();
  1473. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1474. }, mime == 'image/png');
  1475. }
  1476. }, mxResources.get('url'));
  1477. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1478. dlg.init();
  1479. }, parent);
  1480. }
  1481. menu.addItem(mxResources.get('csv') + '...', null, function()
  1482. {
  1483. editorUi.showImportCsvDialog();
  1484. }, parent);
  1485. })).isEnabled = isGraphEnabled;
  1486. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1487. {
  1488. var item = menu.addItem(mxResources.get('kennedy'), null, function()
  1489. {
  1490. mxSettings.setUi('');
  1491. mxSettings.save();
  1492. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1493. }, parent);
  1494. if (uiTheme != 'atlas')
  1495. {
  1496. menu.addCheckmark(item, Editor.checkmarkImage);
  1497. }
  1498. item = menu.addItem(mxResources.get('atlas'), null, function()
  1499. {
  1500. mxSettings.setUi('atlas');
  1501. mxSettings.save();
  1502. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1503. }, parent);
  1504. if (uiTheme == 'atlas')
  1505. {
  1506. menu.addCheckmark(item, Editor.checkmarkImage);
  1507. }
  1508. })));
  1509. this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  1510. {
  1511. var file = this.editorUi.getCurrentFile();
  1512. if (file != null)
  1513. {
  1514. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  1515. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  1516. {
  1517. if (title != null && title.length > 0 && file != null && this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  1518. {
  1519. // Delete old file, save new file in dropbox if autosize is enabled
  1520. file.rename(title, mxUtils.bind(this, function(resp)
  1521. {
  1522. this.editorUi.spinner.stop();
  1523. }),
  1524. mxUtils.bind(this, function(resp)
  1525. {
  1526. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  1527. }));
  1528. }
  1529. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  1530. mxResources.get('diagramName') : null, function(name)
  1531. {
  1532. if (name != null && name.length > 0)
  1533. {
  1534. return true;
  1535. }
  1536. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  1537. return false;
  1538. });
  1539. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1540. dlg.init();
  1541. }
  1542. })).isEnabled = isGraphEnabled;
  1543. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  1544. {
  1545. var file = editorUi.getCurrentFile();
  1546. if (file != null)
  1547. {
  1548. var title = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  1549. // Handles extension
  1550. var extension = '';
  1551. var dot = title.lastIndexOf('.');
  1552. if (dot >= 0)
  1553. {
  1554. extension = title.substring(dot);
  1555. title = title.substring(0, dot);
  1556. }
  1557. title = mxResources.get('copyOf', [title]) + extension;
  1558. if (file.constructor == DriveFile)
  1559. {
  1560. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  1561. {
  1562. // Mode is "download" if Create button is pressed, means use Google Drive
  1563. if (mode == 'download')
  1564. {
  1565. mode = App.MODE_GOOGLE;
  1566. }
  1567. if (newTitle != null && newTitle.length > 0)
  1568. {
  1569. if (mode == App.MODE_GOOGLE)
  1570. {
  1571. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  1572. {
  1573. // Makes sure the latest XML is in the file
  1574. file.save(false, mxUtils.bind(this, function()
  1575. {
  1576. // Saveas does not update the file descriptor in Google Drive
  1577. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  1578. {
  1579. editorUi.spinner.stop();
  1580. var url = editorUi.getUrl();
  1581. window.openWindow(url + '#G' + resp.id, null, mxUtils.bind(this, function()
  1582. {
  1583. window.location.hash = 'G' + resp.id;
  1584. }));
  1585. }), mxUtils.bind(this, function(resp)
  1586. {
  1587. editorUi.handleError(resp);
  1588. }));
  1589. }), mxUtils.bind(this, function(resp)
  1590. {
  1591. editorUi.handleError(resp);
  1592. }));
  1593. }
  1594. }
  1595. else
  1596. {
  1597. this.editorUi.createFile(newTitle, this.editorUi.getFileData(true), null, mode);
  1598. }
  1599. }
  1600. }), mxUtils.bind(this, function()
  1601. {
  1602. editorUi.hideDialog();
  1603. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  1604. null, null, null, true);
  1605. editorUi.showDialog(dlg.container, 420, 380, true, true);
  1606. dlg.init();
  1607. }
  1608. else
  1609. {
  1610. // Creates a copy with no predefined storage
  1611. editorUi.editor.editAsNew(editorUi.getEditBlankXml(), title);
  1612. }
  1613. }
  1614. }));
  1615. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  1616. {
  1617. var file = editorUi.getCurrentFile();
  1618. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  1619. {
  1620. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  1621. {
  1622. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  1623. {
  1624. file.move(folderId, mxUtils.bind(this, function(resp)
  1625. {
  1626. editorUi.spinner.stop();
  1627. }), mxUtils.bind(this, function(resp)
  1628. {
  1629. editorUi.handleError(resp);
  1630. }));
  1631. }
  1632. }));
  1633. }
  1634. }));
  1635. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  1636. {
  1637. this.addMenuItems(menu, ['publishLink'], parent);
  1638. })));
  1639. editorUi.actions.put('offline', new Action(mxResources.get('offline') + '...', function()
  1640. {
  1641. window.open('http://www.draw.io/app')
  1642. }));
  1643. editorUi.actions.put('chromeApp', new Action(mxResources.get('chromeApp') + '...', function()
  1644. {
  1645. window.open('https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla')
  1646. }));
  1647. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  1648. {
  1649. var file = this.editorUi.getCurrentFile();
  1650. if (file != null)
  1651. {
  1652. this.editorUi.drive.showPermissions(file.getId());
  1653. }
  1654. }));
  1655. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  1656. {
  1657. if (urlParams['test'] == '1')
  1658. {
  1659. this.addMenuItems(menu, ['liveImage', '-'], parent);
  1660. }
  1661. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  1662. if (!navigator.standalone && !editorUi.isOffline())
  1663. {
  1664. this.addMenuItems(menu, ['embedIframe'], parent);
  1665. }
  1666. if (!editorUi.isOffline())
  1667. {
  1668. this.addMenuItems(menu, ['-', 'googleSites', 'googleDocs'], parent);
  1669. }
  1670. })));
  1671. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree', '-', 'organic', 'circle', '-', 'fromText'];
  1672. var addInsertItem = function(menu, parent, title, method)
  1673. {
  1674. menu.addItem(title, null, mxUtils.bind(this, function()
  1675. {
  1676. if (method == 'fromText')
  1677. {
  1678. var dlg = new ParseDialog(editorUi, title);
  1679. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1680. editorUi.dialog.container.style.overflow = 'auto';
  1681. dlg.init();
  1682. }
  1683. else
  1684. {
  1685. var dlg = new CreateGraphDialog(editorUi, title, method);
  1686. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1687. // Executed after dialog is added to dom
  1688. dlg.init();
  1689. }
  1690. }), parent);
  1691. };
  1692. editorUi.actions.addAction('insertText', function()
  1693. {
  1694. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1695. {
  1696. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1697. var cell = new mxCell('Text', new mxGeometry(pt.x, pt.y, 40, 20),
  1698. 'text;html=1;resizable=0;autosize=1;align=left;verticalAlign=top;spacingTop=-4;points=[];');
  1699. cell.vertex = true;
  1700. graph.startEditingAtCell(graph.addCell(cell));
  1701. }
  1702. }, null, null, 'Ctrl+Shift+X').isEnabled = isGraphEnabled;
  1703. editorUi.actions.addAction('insertRectangle', function()
  1704. {
  1705. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1706. {
  1707. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1708. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 120, 60), 'whiteSpace=wrap;html=1;');
  1709. cell.vertex = true;
  1710. graph.setSelectionCell(graph.addCell(cell));
  1711. graph.scrollCellToVisible(graph.getSelectionCell());
  1712. }
  1713. }, null, null, 'Ctrl+K').isEnabled = isGraphEnabled;
  1714. editorUi.actions.addAction('insertEllipse', function()
  1715. {
  1716. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1717. {
  1718. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1719. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 80, 80), 'ellipse;whiteSpace=wrap;html=1;');
  1720. cell.vertex = true;
  1721. graph.setSelectionCell(graph.addCell(cell));
  1722. graph.scrollCellToVisible(graph.getSelectionCell());
  1723. }
  1724. }, null, null, 'Ctrl+Shift+K').isEnabled = isGraphEnabled;
  1725. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  1726. {
  1727. this.addMenuItems(menu, ['insertText', 'insertRectangle', 'insertEllipse', '-', 'insertLink', 'insertImage'], parent);
  1728. menu.addSeparator(parent);
  1729. for (var i = 0; i < methods.length; i++)
  1730. {
  1731. if (methods[i] == '-')
  1732. {
  1733. menu.addSeparator(parent);
  1734. }
  1735. else
  1736. {
  1737. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  1738. }
  1739. }
  1740. })));
  1741. this.put('openRecent', new Menu(function(menu, parent)
  1742. {
  1743. var recent = editorUi.getRecent();
  1744. if (recent != null)
  1745. {
  1746. for (var i = 0; i < recent.length; i++)
  1747. {
  1748. (function(entry)
  1749. {
  1750. var modeKey = entry.mode;
  1751. // Google and oneDrive use different keys
  1752. if (modeKey == App.MODE_GOOGLE)
  1753. {
  1754. modeKey = 'googleDrive';
  1755. }
  1756. else if (modeKey == App.MODE_ONEDRIVE)
  1757. {
  1758. modeKey = 'oneDrive';
  1759. }
  1760. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  1761. {
  1762. editorUi.loadFile(entry.id);
  1763. }, parent);
  1764. })(recent[i]);
  1765. }
  1766. menu.addSeparator(parent);
  1767. }
  1768. menu.addItem(mxResources.get('reset'), null, function()
  1769. {
  1770. editorUi.resetRecent();
  1771. }, parent);
  1772. }));
  1773. this.put('openFrom', new Menu(function(menu, parent)
  1774. {
  1775. if (editorUi.drive != null)
  1776. {
  1777. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1778. {
  1779. editorUi.pickFile(App.MODE_GOOGLE);
  1780. }, parent);
  1781. }
  1782. else if (googleEnabled)
  1783. {
  1784. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1785. {
  1786. // do nothing
  1787. }, parent, null, false);
  1788. }
  1789. if (editorUi.gitHub != null)
  1790. {
  1791. menu.addItem(mxResources.get('github') + '...', null, function()
  1792. {
  1793. editorUi.pickFile(App.MODE_GITHUB);
  1794. }, parent);
  1795. }
  1796. if (editorUi.dropbox != null)
  1797. {
  1798. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1799. {
  1800. editorUi.pickFile(App.MODE_DROPBOX);
  1801. }, parent);
  1802. }
  1803. else if (dropboxEnabled)
  1804. {
  1805. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1806. {
  1807. // do nothing
  1808. }, parent, null, false);
  1809. }
  1810. if (editorUi.oneDrive != null)
  1811. {
  1812. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1813. {
  1814. editorUi.pickFile(App.MODE_ONEDRIVE);
  1815. }, parent);
  1816. }
  1817. else if (oneDriveEnabled)
  1818. {
  1819. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1820. {
  1821. // do nothing
  1822. }, parent, null, false);
  1823. }
  1824. menu.addSeparator(parent);
  1825. if (isLocalStorage && urlParams['browser'] != '0')
  1826. {
  1827. menu.addItem(mxResources.get('browser') + '...', null, function()
  1828. {
  1829. editorUi.pickFile(App.MODE_BROWSER);
  1830. }, parent);
  1831. }
  1832. if (!mxClient.IS_IOS)
  1833. {
  1834. menu.addItem(mxResources.get('device') + '...', null, function()
  1835. {
  1836. editorUi.pickFile(App.MODE_DEVICE);
  1837. }, parent);
  1838. }
  1839. if (!editorUi.isOffline())
  1840. {
  1841. menu.addSeparator(parent);
  1842. menu.addItem(mxResources.get('url') + '...', null, function()
  1843. {
  1844. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1845. {
  1846. if (fileUrl != null && fileUrl.length > 0)
  1847. {
  1848. if (editorUi.getCurrentFile() == null)
  1849. {
  1850. window.location.hash = '#U' + encodeURIComponent(fileUrl);
  1851. }
  1852. else
  1853. {
  1854. window.openWindow(((mxClient.IS_CHROMEAPP) ?
  1855. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  1856. window.location.search + '#U' + encodeURIComponent(fileUrl));
  1857. }
  1858. }
  1859. }, mxResources.get('url'));
  1860. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1861. dlg.init();
  1862. }, parent);
  1863. }
  1864. }));
  1865. this.put('newLibrary', new Menu(function(menu, parent)
  1866. {
  1867. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1868. {
  1869. if (editorUi.drive != null)
  1870. {
  1871. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1872. {
  1873. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  1874. }, parent);
  1875. }
  1876. else if (googleEnabled)
  1877. {
  1878. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1879. {
  1880. // do nothing
  1881. }, parent, null, false);
  1882. }
  1883. }
  1884. if (editorUi.gitHub != null)
  1885. {
  1886. menu.addItem(mxResources.get('github') + '...', null, function()
  1887. {
  1888. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
  1889. }, parent);
  1890. }
  1891. if (editorUi.dropbox != null)
  1892. {
  1893. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1894. {
  1895. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  1896. }, parent);
  1897. }
  1898. else if (dropboxEnabled)
  1899. {
  1900. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1901. {
  1902. // do nothing
  1903. }, parent, null, false);
  1904. }
  1905. if (editorUi.oneDrive != null)
  1906. {
  1907. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1908. {
  1909. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  1910. }, parent);
  1911. }
  1912. else if (oneDriveEnabled)
  1913. {
  1914. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1915. {
  1916. // do nothing
  1917. }, parent, null, false);
  1918. }
  1919. menu.addSeparator(parent);
  1920. if (isLocalStorage && urlParams['browser'] != '0')
  1921. {
  1922. menu.addItem(mxResources.get('browser') + '...', null, function()
  1923. {
  1924. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  1925. }, parent);
  1926. }
  1927. if (!mxClient.IS_IOS)
  1928. {
  1929. menu.addItem(mxResources.get('device') + '...', null, function()
  1930. {
  1931. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  1932. }, parent);
  1933. }
  1934. }));
  1935. this.put('openLibraryFrom', new Menu(function(menu, parent)
  1936. {
  1937. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1938. {
  1939. if (editorUi.drive != null)
  1940. {
  1941. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1942. {
  1943. editorUi.pickLibrary(App.MODE_GOOGLE);
  1944. }, parent);
  1945. }
  1946. else if (googleEnabled)
  1947. {
  1948. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1949. {
  1950. // do nothing
  1951. }, parent, null, false);
  1952. }
  1953. }
  1954. if (editorUi.gitHub != null)
  1955. {
  1956. menu.addItem(mxResources.get('github') + '...', null, function()
  1957. {
  1958. editorUi.pickLibrary(App.MODE_GITHUB);
  1959. }, parent);
  1960. }
  1961. if (editorUi.dropbox != null)
  1962. {
  1963. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1964. {
  1965. editorUi.pickLibrary(App.MODE_DROPBOX);
  1966. }, parent);
  1967. }
  1968. else if (dropboxEnabled)
  1969. {
  1970. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1971. {
  1972. // do nothing
  1973. }, parent, null, false);
  1974. }
  1975. if (editorUi.oneDrive != null)
  1976. {
  1977. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1978. {
  1979. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  1980. }, parent);
  1981. }
  1982. else if (oneDriveEnabled)
  1983. {
  1984. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1985. {
  1986. // do nothing
  1987. }, parent, null, false);
  1988. }
  1989. menu.addSeparator(parent);
  1990. if (isLocalStorage && urlParams['browser'] != '0')
  1991. {
  1992. menu.addItem(mxResources.get('browser') + '...', null, function()
  1993. {
  1994. editorUi.pickLibrary(App.MODE_BROWSER);
  1995. }, parent);
  1996. }
  1997. if (!mxClient.IS_IOS)
  1998. {
  1999. menu.addItem(mxResources.get('device') + '...', null, function()
  2000. {
  2001. editorUi.pickLibrary(App.MODE_DEVICE);
  2002. }, parent);
  2003. }
  2004. if (!editorUi.isOffline())
  2005. {
  2006. menu.addSeparator(parent);
  2007. menu.addItem(mxResources.get('url') + '...', null, function()
  2008. {
  2009. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  2010. {
  2011. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2012. {
  2013. var realUrl = fileUrl;
  2014. if (!editorUi.isCorsEnabledForUrl(fileUrl))
  2015. {
  2016. realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
  2017. }
  2018. // Uses proxy to avoid CORS issues
  2019. mxUtils.get(realUrl, function(req)
  2020. {
  2021. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2022. {
  2023. editorUi.spinner.stop();
  2024. try
  2025. {
  2026. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  2027. }
  2028. catch (e)
  2029. {
  2030. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  2031. }
  2032. }
  2033. else
  2034. {
  2035. editorUi.spinner.stop();
  2036. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2037. }
  2038. }, function()
  2039. {
  2040. editorUi.spinner.stop();
  2041. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2042. });
  2043. }
  2044. }, mxResources.get('url'));
  2045. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2046. dlg.init();
  2047. }, parent);
  2048. }
  2049. }));
  2050. // Overrides edit menu to add find
  2051. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  2052. {
  2053. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-',
  2054. 'find', '-',
  2055. 'editData', 'editTooltip', 'editStyle', '-', 'edit', '-', 'editLink', 'openLink', '-',
  2056. 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
  2057. })));
  2058. // Overrides view menu to add search and scratchpad
  2059. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  2060. {
  2061. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  2062. concat(['outline', 'layers', '-']));
  2063. this.addMenuItems(menu, ['-', 'search'], parent);
  2064. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  2065. {
  2066. var item = this.addMenuItem(menu, 'scratchpad', parent);
  2067. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  2068. {
  2069. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000042367');
  2070. }
  2071. }
  2072. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
  2073. 'scrollbars', 'tooltips', '-',
  2074. 'grid', 'guides'], parent);
  2075. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  2076. {
  2077. this.addMenuItem(menu, 'shadowVisible', parent);
  2078. }
  2079. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  2080. 'resetView', 'zoomIn', 'zoomOut'], parent);
  2081. })));
  2082. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  2083. {
  2084. if (urlParams['embed'] != '1')
  2085. {
  2086. this.addSubmenu('theme', menu, parent);
  2087. menu.addSeparator(parent);
  2088. }
  2089. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  2090. if (typeof(MathJax) !== 'undefined')
  2091. {
  2092. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  2093. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  2094. }
  2095. this.addMenuItems(menu, ['autosave', '-', 'createShape', 'editDiagram'], parent);
  2096. menu.addSeparator(parent);
  2097. if (urlParams['embed'] != '1' && isLocalStorage)
  2098. {
  2099. this.addMenuItems(menu, ['showStartScreen'], parent);
  2100. }
  2101. if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
  2102. {
  2103. this.addMenuItems(menu, ['plugins', '-'], parent);
  2104. var item = this.addMenuItem(menu, 'tags', parent);
  2105. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  2106. {
  2107. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000046966');
  2108. }
  2109. this.addMenuItems(menu, ['-', 'offline'], parent);
  2110. }
  2111. else
  2112. {
  2113. menu.addSeparator(parent);
  2114. this.addMenuItem(menu, 'tags', parent);
  2115. menu.addSeparator(parent);
  2116. }
  2117. if (!editorUi.isOffline() && !navigator.standalone && urlParams['embed'] != '1')
  2118. {
  2119. this.addMenuItems(menu, ['chromeApp'], parent);
  2120. }
  2121. })));
  2122. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  2123. {
  2124. if (urlParams['embed'] == '1')
  2125. {
  2126. this.addSubmenu('importFrom', menu, parent);
  2127. this.addSubmenu('exportAs', menu, parent);
  2128. this.addSubmenu('embed', menu, parent);
  2129. if (urlParams['libraries'] == '1')
  2130. {
  2131. this.addMenuItems(menu, ['-'], parent);
  2132. this.addSubmenu('newLibrary', menu, parent);
  2133. this.addSubmenu('openLibraryFrom', menu, parent);
  2134. }
  2135. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'save'], parent);
  2136. if (urlParams['saveAndExit'] == '1')
  2137. {
  2138. this.addMenuItems(menu, ['saveAndExit'], parent);
  2139. }
  2140. this.addMenuItems(menu, ['exit'], parent);
  2141. }
  2142. else
  2143. {
  2144. var file = this.editorUi.getCurrentFile();
  2145. if (file != null && file.constructor == DriveFile)
  2146. {
  2147. if (file.isRestricted())
  2148. {
  2149. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  2150. }
  2151. if (file.realtime == null)
  2152. {
  2153. this.addMenuItems(menu, ['save', 'share', '-'], parent);
  2154. }
  2155. else
  2156. {
  2157. if (!file.isAutosave())
  2158. {
  2159. this.addMenuItems(menu, ['save'], parent);
  2160. }
  2161. this.addMenuItems(menu, ['share', 'chatWindowTitle', '-'], parent);
  2162. }
  2163. }
  2164. else
  2165. {
  2166. this.addMenuItems(menu, ['new'], parent);
  2167. }
  2168. this.addSubmenu('openFrom', menu, parent);
  2169. if (isLocalStorage)
  2170. {
  2171. this.addSubmenu('openRecent', menu, parent);
  2172. }
  2173. if (file != null && file.constructor == DriveFile)
  2174. {
  2175. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  2176. }
  2177. else
  2178. {
  2179. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-', 'rename'], parent);
  2180. if (editorUi.isOfflineApp())
  2181. {
  2182. if (!editorUi.isOffline())
  2183. {
  2184. this.addMenuItems(menu, ['upload'], parent);
  2185. }
  2186. }
  2187. else
  2188. {
  2189. this.addMenuItems(menu, ['makeCopy'], parent);
  2190. if (file != null && file.constructor == OneDriveFile)
  2191. {
  2192. this.addMenuItems(menu, ['moveToFolder'], parent);
  2193. }
  2194. }
  2195. }
  2196. menu.addSeparator(parent);
  2197. this.addSubmenu('importFrom', menu, parent);
  2198. this.addSubmenu('exportAs', menu, parent);
  2199. menu.addSeparator(parent);
  2200. this.addSubmenu('embed', menu, parent);
  2201. this.addSubmenu('publish', menu, parent);
  2202. menu.addSeparator(parent);
  2203. this.addSubmenu('newLibrary', menu, parent);
  2204. this.addSubmenu('openLibraryFrom', menu, parent);
  2205. if (file != null && (file.constructor == DriveFile || file.constructor == DropboxFile))
  2206. {
  2207. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  2208. }
  2209. if (file != null && file.constructor == DriveFile)
  2210. {
  2211. this.addMenuItems(menu, ['createRevision'], parent);
  2212. }
  2213. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  2214. // Cannot use print in standalone mode on iOS as we cannot open new windows
  2215. if (!mxClient.IS_IOS || !navigator.standalone)
  2216. {
  2217. this.addMenuItems(menu, ['print'], parent);
  2218. }
  2219. this.addMenuItems(menu, ['-', 'close']);
  2220. }
  2221. })));
  2222. };
  2223. /**
  2224. * Replaces help menu label with icon on small screen
  2225. */
  2226. var menuCreated = Menus.prototype.menuCreated;
  2227. Menus.prototype.menuCreated = function(menu, elt)
  2228. {
  2229. if (screen.width <= 480 && menu == this.get('help'))
  2230. {
  2231. elt.style.paddingRight = '0px';
  2232. elt.style.paddingLeft = '0px';
  2233. elt.innerHTML = '';
  2234. var icon = document.createElement('img');
  2235. icon.setAttribute('border', '0');
  2236. icon.setAttribute('valign', 'bottom');
  2237. icon.setAttribute('src', Editor.helpImage);
  2238. elt.appendChild(icon);
  2239. }
  2240. menuCreated.apply(this, arguments);
  2241. };
  2242. })();