Menus.js 71 KB

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