Menus.js 77 KB

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