Menus.js 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168
  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.createHelpLink = function(href)
  18. {
  19. var link = document.createElement('span');
  20. link.setAttribute('title', mxResources.get('help'));
  21. link.style.cssText = 'color:blue;text-decoration:underline;margin-left:8px;cursor:help;';
  22. var icon = document.createElement('img');
  23. mxUtils.setOpacity(icon, 50);
  24. icon.style.height = '16px';
  25. icon.style.width = '16px';
  26. icon.setAttribute('border', '0');
  27. icon.setAttribute('valign', 'bottom');
  28. icon.setAttribute('src', Editor.helpImage);
  29. link.appendChild(icon);
  30. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  31. {
  32. if (this.editorUi.menubar != null)
  33. {
  34. this.editorUi.menubar.hideMenu();
  35. }
  36. this.editorUi.openLink(href);
  37. mxEvent.consume(evt);
  38. }));
  39. return link;
  40. };
  41. Menus.prototype.addLinkToItem = function(item, href)
  42. {
  43. if (item != null)
  44. {
  45. item.firstChild.nextSibling.appendChild(this.createHelpLink(href));
  46. }
  47. };
  48. var menusInit = Menus.prototype.init;
  49. Menus.prototype.init = function()
  50. {
  51. menusInit.apply(this, arguments);
  52. var editorUi = this.editorUi;
  53. var graph = editorUi.editor.graph;
  54. var isGraphEnabled = mxUtils.bind(graph, graph.isEnabled);
  55. var googleEnabled = ((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  56. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && mxClient.IS_SVG &&
  57. isLocalStorage && (document.documentMode == null || document.documentMode >= 10);
  58. var dropboxEnabled = ((urlParams['embed'] != '1' && urlParams['db'] != '0') || (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  59. mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
  60. var oneDriveEnabled = (window.location.hostname == 'www.draw.io' || window.location.hostname == 'test.draw.io' ||
  61. window.location.hostname == 'drive.draw.io' || window.location.hostname == 'legacy.draw.io') &&
  62. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  63. urlParams['od'] == '1')) && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  64. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10));
  65. var trelloEnabled = ((urlParams['embed'] != '1' && urlParams['tr'] != '0') || (urlParams['embed'] == '1' && urlParams['tr'] == '1')) &&
  66. mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
  67. if (!mxClient.IS_SVG && !editorUi.isOffline())
  68. {
  69. var img = new Image();
  70. img.src = IMAGE_PATH + '/help.png';
  71. }
  72. editorUi.actions.addAction('new...', function()
  73. {
  74. var compact = editorUi.isOffline();
  75. var dlg = new NewDialog(editorUi, compact);
  76. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
  77. {
  78. if (cancel && editorUi.getCurrentFile() == null)
  79. {
  80. editorUi.showSplash();
  81. }
  82. });
  83. dlg.init();
  84. });
  85. editorUi.actions.put('exportSvg', new Action(mxResources.get('formatSvg') + '...', function()
  86. {
  87. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  88. 'https://support.draw.io/display/DO/Exporting+Files',
  89. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow,
  90. editable, embedImages, border, cropImage, currentPage, linkTarget)
  91. {
  92. var val = parseInt(scale);
  93. if (!isNaN(val) && val > 0)
  94. {
  95. editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection, addShadow,
  96. editable, embedImages, border, !cropImage, currentPage, linkTarget);
  97. }
  98. }), true, null, 'svg');
  99. }));
  100. editorUi.actions.put('insertTemplate', new Action(mxResources.get('template') + '...', function()
  101. {
  102. var dlg = new NewDialog(editorUi, null, false, function(xml)
  103. {
  104. editorUi.hideDialog();
  105. if (xml != null)
  106. {
  107. var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
  108. graph.setSelectionCells(editorUi.importXml(xml,
  109. Math.max(insertPoint.x, 20),
  110. Math.max(insertPoint.y, 20), true));
  111. graph.scrollCellToVisible(graph.getSelectionCell());
  112. }
  113. }, null, null, null, null, null, null, null, null, null, null,
  114. false, mxResources.get('insert'));
  115. editorUi.showDialog(dlg.container, 620, 440, true, true);
  116. })).isEnabled = isGraphEnabled;
  117. editorUi.actions.put('exportXml', new Action(mxResources.get('formatXml') + '...', function()
  118. {
  119. var div = document.createElement('div');
  120. div.style.whiteSpace = 'nowrap';
  121. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  122. var hd = document.createElement('h3');
  123. mxUtils.write(hd, mxResources.get('formatXml'));
  124. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  125. div.appendChild(hd);
  126. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  127. false, graph.isSelectionEmpty());
  128. var pages = editorUi.addCheckbox(div, mxResources.get((noPages) ? 'compressed' : 'allPages'), true);
  129. pages.style.marginBottom = '16px';
  130. mxEvent.addListener(selection, 'change', function()
  131. {
  132. if (selection.checked)
  133. {
  134. pages.setAttribute('disabled', 'disabled');
  135. }
  136. else
  137. {
  138. pages.removeAttribute('disabled');
  139. }
  140. });
  141. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  142. {
  143. editorUi.downloadFile('xml', (noPages) ? !pages.checked : null, null,
  144. !selection.checked, (!noPages) ? !pages.checked : null);
  145. }), null, mxResources.get('export'));
  146. editorUi.showDialog(dlg.container, 300, 146, true, true);
  147. }));
  148. editorUi.actions.put('exportUrl', new Action(mxResources.get('url') + '...', function()
  149. {
  150. editorUi.showPublishLinkDialog(mxResources.get('url'), true, null, null,
  151. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  152. {
  153. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  154. linkColor, allPages, lightbox, editLink, layers, null, true));
  155. editorUi.showDialog(dlg.container, 440, 240, true, true);
  156. dlg.init();
  157. });
  158. }));
  159. editorUi.actions.put('exportHtml', new Action(mxResources.get('formatHtmlEmbedded') + '...', function()
  160. {
  161. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  162. {
  163. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  164. {
  165. editorUi.spinner.stop();
  166. editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
  167. initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  168. {
  169. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  170. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  171. {
  172. var basename = editorUi.getBaseFilename(allPages);
  173. var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
  174. '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
  175. '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
  176. editorUi.saveData(basename + '.html', 'html', result, 'text/html');
  177. }));
  178. });
  179. });
  180. }
  181. }));
  182. editorUi.actions.put('exportPdf', new Action(mxResources.get('formatPdf') + '...', function()
  183. {
  184. if (editorUi.isOffline() || editorUi.printPdfExport)
  185. {
  186. // Export PDF action for chrome OS (same as print with different dialog title)
  187. editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 360,
  188. (editorUi.pages != null && editorUi.pages.length > 1) ?
  189. 420 : 360, true, true);
  190. }
  191. else
  192. {
  193. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  194. var div = document.createElement('div');
  195. div.style.whiteSpace = 'nowrap';
  196. var hd = document.createElement('h3');
  197. mxUtils.write(hd, mxResources.get('formatPdf'));
  198. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  199. div.appendChild(hd);
  200. var cropEnableFn = function()
  201. {
  202. if (allPages != this && this.checked)
  203. {
  204. crop.removeAttribute('disabled');
  205. }
  206. else
  207. {
  208. crop.setAttribute('disabled', 'disabled');
  209. crop.checked = false;
  210. }
  211. };
  212. var dlgH = 146;
  213. if (editorUi.pdfPageExport && !noPages)
  214. {
  215. var allPages = editorUi.addRadiobox(div, 'pages', mxResources.get('allPages'), true);
  216. var currentPage = editorUi.addRadiobox(div, 'pages', mxResources.get('currentPage', null, 'Current Page'), false);
  217. var selection = editorUi.addRadiobox(div, 'pages', mxResources.get('selectionOnly'), false, graph.isSelectionEmpty());
  218. var crop = editorUi.addCheckbox(div, mxResources.get('crop'), false, true);
  219. mxEvent.addListener(allPages, 'change', cropEnableFn);
  220. mxEvent.addListener(currentPage, 'change', cropEnableFn);
  221. mxEvent.addListener(selection, 'change', cropEnableFn);
  222. dlgH = 205;
  223. }
  224. else
  225. {
  226. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  227. false, graph.isSelectionEmpty());
  228. var crop = editorUi.addCheckbox(div, mxResources.get('crop'),
  229. !graph.pageVisible || !editorUi.pdfPageExport,
  230. !editorUi.pdfPageExport);
  231. // Crop is only enabled if selection only is selected
  232. if (!editorUi.pdfPageExport)
  233. {
  234. mxEvent.addListener(selection, 'change', cropEnableFn);
  235. }
  236. }
  237. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  238. {
  239. editorUi.downloadFile('pdf', null, null, !selection.checked, noPages? true : !allPages.checked, !crop.checked);
  240. }), null, mxResources.get('export'));
  241. editorUi.showDialog(dlg.container, 300, dlgH, true, true);
  242. }
  243. }));
  244. editorUi.actions.addAction('open...', function()
  245. {
  246. editorUi.pickFile();
  247. });
  248. editorUi.actions.addAction('close', function()
  249. {
  250. var currentFile = editorUi.getCurrentFile();
  251. function fn()
  252. {
  253. editorUi.fileLoaded(null);
  254. };
  255. if (currentFile != null && currentFile.isModified())
  256. {
  257. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  258. mxResources.get('cancel'), mxResources.get('discardChanges'));
  259. }
  260. else
  261. {
  262. fn();
  263. }
  264. });
  265. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  266. {
  267. var cells = graph.getSelectionCells();
  268. if (graph.getSelectionCount() == 1)
  269. {
  270. var cell = graph.getSelectionCell();
  271. var state = graph.view.getState(cell);
  272. if (state != null && state.shape != null && state.shape.stencil != null)
  273. {
  274. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  275. editorUi.showDialog(dlg.container, 640, 480, true, false);
  276. dlg.init();
  277. }
  278. }
  279. }));
  280. editorUi.actions.addAction('revisionHistory...', function()
  281. {
  282. if (!editorUi.isRevisionHistorySupported())
  283. {
  284. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  285. }
  286. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  287. {
  288. editorUi.getRevisions(mxUtils.bind(this, function(revs, restoreFn)
  289. {
  290. editorUi.spinner.stop();
  291. var dlg = new RevisionDialog(editorUi, revs, restoreFn);
  292. editorUi.showDialog(dlg.container, 640, 480, true, true);
  293. dlg.init();
  294. }), mxUtils.bind(this, function(err)
  295. {
  296. editorUi.handleError(err);
  297. }));
  298. }
  299. });
  300. editorUi.actions.addAction('createRevision', function()
  301. {
  302. editorUi.actions.get('save').funct();
  303. }, null, null, Editor.ctrlKey + '+S');
  304. var action = editorUi.actions.addAction('synchronize', function()
  305. {
  306. editorUi.synchronizeCurrentFile(DrawioFile.SYNC == 'none');
  307. }, null, null, 'Alt+Shift+S');
  308. // Changes the label if synchronization is disabled
  309. if (DrawioFile.SYNC == 'none')
  310. {
  311. action.label = mxResources.get('refresh');
  312. }
  313. editorUi.actions.addAction('upload...', function()
  314. {
  315. var file = editorUi.getCurrentFile();
  316. if (file != null)
  317. {
  318. // Data is pulled from global variable after tab loads
  319. // LATER: Change to use message passing to deal with potential cross-domain
  320. window.drawdata = editorUi.getFileData();
  321. var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  322. editorUi.openLink(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
  323. ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
  324. 'title=' + encodeURIComponent(filename), null, true);
  325. }
  326. });
  327. if (typeof(MathJax) !== 'undefined')
  328. {
  329. var action = editorUi.actions.addAction('mathematicalTypesetting', function()
  330. {
  331. var change = new ChangePageSetup(editorUi);
  332. change.ignoreColor = true;
  333. change.ignoreImage = true;
  334. change.mathEnabled = !editorUi.isMathEnabled();
  335. graph.model.execute(change);
  336. });
  337. action.setToggleAction(true);
  338. action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
  339. action.isEnabled = isGraphEnabled;
  340. }
  341. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  342. {
  343. var action = editorUi.actions.addAction('showStartScreen', function()
  344. {
  345. mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
  346. mxSettings.save();
  347. });
  348. action.setToggleAction(true);
  349. action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
  350. }
  351. var autosaveAction = editorUi.actions.addAction('autosave', function()
  352. {
  353. editorUi.editor.setAutosave(!editorUi.editor.autosave);
  354. });
  355. autosaveAction.setToggleAction(true);
  356. autosaveAction.setSelectedCallback(function()
  357. {
  358. return autosaveAction.isEnabled() && editorUi.editor.autosave;
  359. });
  360. editorUi.actions.addAction('editGeometry...', function()
  361. {
  362. var cells = graph.getSelectionCells();
  363. var vertices = [];
  364. for (var i = 0; i < cells.length; i++)
  365. {
  366. if (graph.getModel().isVertex(cells[i]))
  367. {
  368. vertices.push(cells[i]);
  369. }
  370. }
  371. if (vertices.length > 0)
  372. {
  373. var dlg = new EditGeometryDialog(editorUi, vertices);
  374. editorUi.showDialog(dlg.container, 200, 250, true, true);
  375. dlg.init();
  376. }
  377. }, null, null, Editor.ctrlKey + '+Shift+M');
  378. var copiedStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'fontStyle',
  379. 'align', 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
  380. 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
  381. 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight', 'endFill', 'endArrow',
  382. 'endSize', 'targetPerimeterSpacing', 'startFill', 'startArrow', 'startSize', 'sourcePerimeterSpacing',
  383. 'arcSize'];
  384. editorUi.actions.addAction('copyStyle', function()
  385. {
  386. var state = graph.view.getState(graph.getSelectionCell());
  387. if (graph.isEnabled() && state != null)
  388. {
  389. editorUi.copiedStyle = mxUtils.clone(state.style);
  390. // Handles special case for value "none"
  391. var cellStyle = graph.getModel().getStyle(state.cell);
  392. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  393. for (var j = 0; j < tokens.length; j++)
  394. {
  395. var tmp = tokens[j];
  396. var pos = tmp.indexOf('=');
  397. if (pos >= 0)
  398. {
  399. var key = tmp.substring(0, pos);
  400. var value = tmp.substring(pos + 1);
  401. if (editorUi.copiedStyle[key] == null && value == 'none')
  402. {
  403. editorUi.copiedStyle[key] = 'none';
  404. }
  405. }
  406. }
  407. }
  408. }, null, null, Editor.ctrlKey + '+Shift+C');
  409. editorUi.actions.addAction('pasteStyle', function()
  410. {
  411. if (graph.isEnabled() && !graph.isSelectionEmpty() && editorUi.copiedStyle != null)
  412. {
  413. graph.getModel().beginUpdate();
  414. try
  415. {
  416. var cells = graph.getSelectionCells();
  417. for (var i = 0; i < cells.length; i++)
  418. {
  419. var state = graph.view.getState(cells[i]);
  420. for (var j = 0; j < copiedStyles.length; j++)
  421. {
  422. var key = copiedStyles[j];
  423. var value = editorUi.copiedStyle[key];
  424. if (state.style[key] != value)
  425. {
  426. graph.setCellStyles(key, value, [cells[i]]);
  427. }
  428. }
  429. }
  430. }
  431. finally
  432. {
  433. graph.getModel().endUpdate();
  434. }
  435. }
  436. }, null, null, Editor.ctrlKey + '+Shift+V');
  437. editorUi.actions.put('pageBackgroundImage', new Action(mxResources.get('backgroundImage') + '...', function()
  438. {
  439. if (!editorUi.isOffline())
  440. {
  441. var apply = function(image)
  442. {
  443. editorUi.setBackgroundImage(image);
  444. };
  445. var dlg = new BackgroundImageDialog(editorUi, apply);
  446. editorUi.showDialog(dlg.container, 320, 170, true, true);
  447. dlg.init();
  448. }
  449. }));
  450. editorUi.actions.put('exportPng', new Action(mxResources.get('formatPng') + '...', function()
  451. {
  452. if (editorUi.isExportToCanvas())
  453. {
  454. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  455. 'https://support.draw.io/display/DO/Exporting+Files',
  456. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  457. addShadow, editable, embedImages, border, cropImage, currentPage)
  458. {
  459. var val = parseInt(scale);
  460. if (!isNaN(val) && val > 0)
  461. {
  462. editorUi.exportImage(val / 100, transparentBackground, ignoreSelection,
  463. addShadow, editable, border, !cropImage, currentPage);
  464. }
  465. }), true, true, 'png');
  466. }
  467. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  468. {
  469. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable, transparent)
  470. {
  471. editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection, null, null, transparent);
  472. }));
  473. }
  474. }));
  475. editorUi.actions.put('exportJpg', new Action(mxResources.get('formatJpg') + '...', function()
  476. {
  477. if (editorUi.isExportToCanvas())
  478. {
  479. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  480. 'https://support.draw.io/display/DO/Exporting+Files',
  481. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  482. addShadow, editable, embedImages, border, cropImage, currentPage)
  483. {
  484. var val = parseInt(scale);
  485. if (!isNaN(val) && val > 0)
  486. {
  487. editorUi.exportImage(val / 100, false, ignoreSelection,
  488. addShadow, false, border, !cropImage, false, 'jpeg');
  489. }
  490. }), true, false, 'jpeg');
  491. }
  492. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  493. {
  494. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  495. {
  496. editorUi.downloadFile('jpeg', null, null, ignoreSelection);
  497. }), true);
  498. }
  499. }));
  500. action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
  501. {
  502. graph.setShadowVisible(!graph.shadowVisible);
  503. }));
  504. action.setToggleAction(true);
  505. action.setSelectedCallback(function() { return graph.shadowVisible; });
  506. var showingAbout = false;
  507. editorUi.actions.put('about', new Action(mxResources.get('aboutDrawio') + '...', function()
  508. {
  509. if (!showingAbout)
  510. {
  511. editorUi.showDialog(new AboutDialog(editorUi).container, 220, 300, true, true, function()
  512. {
  513. showingAbout = false;
  514. });
  515. showingAbout = true;
  516. }
  517. }, null, null, 'F1'));
  518. editorUi.actions.addAction('userManual...', function()
  519. {
  520. editorUi.openLink('https://support.draw.io/display/DO/Draw.io+Online+User+Manual');
  521. });
  522. editorUi.actions.addAction('support...', function()
  523. {
  524. editorUi.openLink('https://about.draw.io/support/');
  525. });
  526. editorUi.actions.addAction('exportOptionsDisabled...', function()
  527. {
  528. editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
  529. mxResources.get('exportOptionsDisabled'));
  530. });
  531. editorUi.actions.addAction('keyboardShortcuts...', function()
  532. {
  533. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  534. {
  535. editorUi.openLink('https://www.draw.io/shortcuts.svg');
  536. }
  537. else if (mxClient.IS_SVG)
  538. {
  539. editorUi.openLink('shortcuts.svg');
  540. }
  541. else
  542. {
  543. editorUi.openLink('https://www.draw.io/?lightbox=1#Uhttps%3A%2F%2Fwww.draw.io%2Fshortcuts.svg');
  544. }
  545. });
  546. editorUi.actions.addAction('feedback...', function()
  547. {
  548. var dlg = new FeedbackDialog(editorUi);
  549. editorUi.showDialog(dlg.container, 610, 360, true, true);
  550. dlg.init();
  551. });
  552. editorUi.actions.addAction('quickStart...', function()
  553. {
  554. editorUi.openLink('https://www.youtube.com/watch?v=Z0D96ZikMkc');
  555. });
  556. action = editorUi.actions.addAction('tags...', mxUtils.bind(this, function()
  557. {
  558. if (this.tagsWindow == null)
  559. {
  560. this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 380, 230, 300, 120);
  561. this.tagsWindow.window.addListener('show', function()
  562. {
  563. editorUi.fireEvent(new mxEventObject('tags'));
  564. });
  565. this.tagsWindow.window.addListener('hide', function()
  566. {
  567. editorUi.fireEvent(new mxEventObject('tags'));
  568. });
  569. this.tagsWindow.window.setVisible(true);
  570. editorUi.fireEvent(new mxEventObject('tags'));
  571. }
  572. else
  573. {
  574. this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
  575. }
  576. }));
  577. action.setToggleAction(true);
  578. action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
  579. action = editorUi.actions.addAction('find...', mxUtils.bind(this, function()
  580. {
  581. if (this.findWindow == null)
  582. {
  583. this.findWindow = new FindWindow(editorUi, document.body.offsetWidth - 300, 110, 240, 140);
  584. this.findWindow.window.addListener('show', function()
  585. {
  586. editorUi.fireEvent(new mxEventObject('find'));
  587. });
  588. this.findWindow.window.addListener('hide', function()
  589. {
  590. editorUi.fireEvent(new mxEventObject('find'));
  591. });
  592. this.findWindow.window.setVisible(true);
  593. editorUi.fireEvent(new mxEventObject('find'));
  594. }
  595. else
  596. {
  597. this.findWindow.window.setVisible(!this.findWindow.window.isVisible());
  598. }
  599. }));
  600. action.setToggleAction(true);
  601. action.setSelectedCallback(mxUtils.bind(this, function() { return this.findWindow != null && this.findWindow.window.isVisible(); }));
  602. editorUi.actions.put('exportVsdx', new Action(mxResources.get('formatVsdx') + ' (beta)...', function()
  603. {
  604. editorUi.exportVisio();
  605. }));
  606. // Adds language menu to options only if localStorage is available for
  607. // storing the choice. We do not want to use cookies for older browsers.
  608. // Note that the URL param lang=XX is available for setting the language
  609. // in older browsers. URL param has precedence over the saved setting.
  610. if (mxClient.IS_CHROMEAPP || (isLocalStorage && urlParams['offline'] != '1'))
  611. {
  612. this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
  613. {
  614. var addLangItem = mxUtils.bind(this, function (id)
  615. {
  616. var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
  617. var item = null;
  618. if (lang != '')
  619. {
  620. item = menu.addItem(lang, null, mxUtils.bind(this, function()
  621. {
  622. mxSettings.setLanguage(id);
  623. mxSettings.save();
  624. // Shows dialog in new language
  625. mxClient.language = id;
  626. mxResources.loadDefaultBundle = false;
  627. mxResources.add(RESOURCE_BASE);
  628. editorUi.alert(mxResources.get('restartForChangeRequired'));
  629. }), parent);
  630. if (id == mxLanguage || (id == '' && mxLanguage == null))
  631. {
  632. menu.addCheckmark(item, Editor.checkmarkImage);
  633. }
  634. }
  635. return item;
  636. });
  637. var item = addLangItem('');
  638. menu.addSeparator(parent);
  639. // LATER: Sort menu by language name
  640. for(var langId in mxLanguageMap)
  641. {
  642. addLangItem(langId);
  643. }
  644. })));
  645. // Extends the menubar with the language menu
  646. var menusCreateMenuBar = Menus.prototype.createMenubar;
  647. Menus.prototype.createMenubar = function(container)
  648. {
  649. var menubar = menusCreateMenuBar.apply(this, arguments);
  650. if (menubar != null)
  651. {
  652. var langMenu = this.get('language');
  653. if (langMenu != null)
  654. {
  655. var elt = menubar.addMenu('', langMenu.funct);
  656. elt.setAttribute('title', mxResources.get('language'));
  657. elt.style.width = '16px';
  658. elt.style.paddingTop = '2px';
  659. elt.style.paddingLeft = '4px';
  660. elt.style.zIndex = '1';
  661. elt.style.position = 'absolute';
  662. elt.style.display = 'block';
  663. elt.style.cursor = 'pointer';
  664. elt.style.right = '17px';
  665. if (uiTheme == 'atlas')
  666. {
  667. elt.style.top = '6px';
  668. elt.style.right = '15px';
  669. }
  670. else if (uiTheme == 'min')
  671. {
  672. elt.style.top = '2px';
  673. }
  674. else
  675. {
  676. elt.style.top = '0px';
  677. }
  678. if (!mxClient.IS_VML)
  679. {
  680. var icon = document.createElement('div');
  681. icon.style.backgroundImage = 'url(' + Editor.globeImage + ')';
  682. icon.style.backgroundPosition = 'center center';
  683. icon.style.backgroundRepeat = 'no-repeat';
  684. icon.style.backgroundSize = '19px 19px';
  685. icon.style.position = 'absolute';
  686. icon.style.height = '19px';
  687. icon.style.width = '19px';
  688. icon.style.marginTop = '2px';
  689. icon.style.zIndex = '1';
  690. elt.appendChild(icon);
  691. mxUtils.setOpacity(elt, 40);
  692. if (uiTheme == 'atlas' || uiTheme == 'dark')
  693. {
  694. elt.style.opacity = '0.85';
  695. elt.style.filter = 'invert(100%)';
  696. }
  697. }
  698. else
  699. {
  700. elt.innerHTML = '<div class="geIcon geSprite geSprite-globe"/>';
  701. }
  702. document.body.appendChild(elt);
  703. }
  704. }
  705. return menubar;
  706. };
  707. }
  708. editorUi.customLayoutConfig = [{'layout': 'mxHierarchicalLayout',
  709. 'config':
  710. {'orientation': 'west',
  711. 'intraCellSpacing': 30,
  712. 'interRankCellSpacing': 100,
  713. 'interHierarchySpacing': 60,
  714. 'parallelEdgeSpacing': 10}}];
  715. // Adds action
  716. editorUi.actions.addAction('runLayout', function()
  717. {
  718. var graph = editorUi.editor.graph;
  719. var dlg = new TextareaDialog(editorUi, 'Run Layouts:',
  720. JSON.stringify(editorUi.customLayoutConfig, null, 2),
  721. function(newValue)
  722. {
  723. if (newValue.length > 0)
  724. {
  725. try
  726. {
  727. var json = JSON.parse(newValue);
  728. for (var i = 0; i < json.length; i++)
  729. {
  730. var layout = new window[json[i].layout](graph);
  731. if (json[i].config != null)
  732. {
  733. for (var key in json[i].config)
  734. {
  735. layout[key] = json[i].config[key];
  736. }
  737. }
  738. editorUi.executeLayout(function()
  739. {
  740. var selectionCells = graph.getSelectionCells();
  741. layout.execute(graph.getDefaultParent(), selectionCells.length == 0 ?
  742. null : selectionCells);
  743. }, i == json.length - 1);
  744. }
  745. editorUi.customLayoutConfig = json;
  746. }
  747. catch (e)
  748. {
  749. editorUi.handleError(e);
  750. console.error(e);
  751. }
  752. }
  753. });
  754. dlg.textarea.style.width = '600px';
  755. dlg.textarea.style.height = '380px';
  756. editorUi.showDialog(dlg.container, 620, 460, true, true);
  757. dlg.init();
  758. });
  759. var layoutMenu = this.get('layout');
  760. var layoutMenuFunct = layoutMenu.funct;
  761. layoutMenu.funct = function(menu, parent)
  762. {
  763. layoutMenuFunct.apply(this, arguments);
  764. menu.addSeparator(parent);
  765. editorUi.menus.addMenuItem(menu, 'runLayout', parent, null, null, mxResources.get('apply') + '...');
  766. };
  767. this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
  768. {
  769. if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
  770. {
  771. this.addMenuItems(menu, ['about'], parent);
  772. }
  773. else
  774. {
  775. // No translation for menu item since help is english only
  776. var item = menu.addItem('Search:', null, null, parent, null, null, false);
  777. item.style.backgroundColor = (uiTheme == 'dark') ? '#505759' : 'whiteSmoke';
  778. item.style.cursor = 'default';
  779. var input = document.createElement('input');
  780. input.setAttribute('type', 'text');
  781. input.setAttribute('size', '25');
  782. input.style.marginLeft = '8px';
  783. mxEvent.addListener(input, 'keydown', mxUtils.bind(this, function(e)
  784. {
  785. var term = mxUtils.trim(input.value);
  786. if (e.keyCode == 13 && term.length > 0)
  787. {
  788. this.editorUi.openLink('https://desk.draw.io/support/search/solutions?term=' +
  789. encodeURIComponent(term));
  790. input.value = '';
  791. EditorUi.logEvent({category: 'SEARCH-HELP', action: 'search', label: term});
  792. if (this.editorUi.menubar != null)
  793. {
  794. window.setTimeout(mxUtils.bind(this, function()
  795. {
  796. this.editorUi.menubar.hideMenu();
  797. }), 0);
  798. }
  799. }
  800. else if (e.keyCode == 27)
  801. {
  802. input.value = '';
  803. }
  804. }));
  805. item.firstChild.nextSibling.appendChild(input);
  806. mxEvent.addGestureListeners(input, function(evt)
  807. {
  808. if (document.activeElement != input)
  809. {
  810. input.focus();
  811. }
  812. mxEvent.consume(evt);
  813. }, function(evt)
  814. {
  815. mxEvent.consume(evt);
  816. }, function(evt)
  817. {
  818. mxEvent.consume(evt);
  819. });
  820. window.setTimeout(function()
  821. {
  822. input.focus();
  823. }, 0);
  824. this.addMenuItems(menu, ['-', 'quickStart', 'userManual', 'keyboardShortcuts', '-'], parent);
  825. if (!mxClient.IS_CHROMEAPP)
  826. {
  827. this.addMenuItems(menu, ['feedback'], parent);
  828. }
  829. this.addMenuItems(menu, ['support', '-'], parent);
  830. if (!EditorUi.isElectronApp && !navigator.standalone && urlParams['embed'] != '1')
  831. {
  832. this.addMenuItems(menu, ['downloadDesktop'], parent);
  833. }
  834. if (!navigator.standalone && urlParams['embed'] != '1')
  835. {
  836. this.addMenuItems(menu, ['useOffline'], parent);
  837. }
  838. this.addMenuItems(menu, ['-', 'about'], parent);
  839. }
  840. if (urlParams['test'] == '1')
  841. {
  842. menu.addSeparator(parent);
  843. this.addSubmenu('testDevelop', menu, parent);
  844. }
  845. if (urlParams['ruler'] == '1')
  846. {
  847. mxResources.parse('rulerInch=Ruler unit: Inches');
  848. editorUi.actions.addAction('rulerInch', mxUtils.bind(this, function()
  849. {
  850. editorUi.vRuler.setUnit(mxRuler.prototype.INCHES);
  851. editorUi.hRuler.setUnit(mxRuler.prototype.INCHES);
  852. editorUi.vRuler.drawRuler(true);
  853. editorUi.hRuler.drawRuler(true);
  854. }));
  855. mxResources.parse('rulerCM=Ruler unit: CMs');
  856. editorUi.actions.addAction('rulerCM', mxUtils.bind(this, function()
  857. {
  858. editorUi.vRuler.setUnit(mxRuler.prototype.CENTIMETER);
  859. editorUi.hRuler.setUnit(mxRuler.prototype.CENTIMETER);
  860. editorUi.vRuler.drawRuler(true);
  861. editorUi.hRuler.drawRuler(true);
  862. }));
  863. mxResources.parse('rulerPixel=Ruler unit: Pixels');
  864. editorUi.actions.addAction('rulerPixel', mxUtils.bind(this, function()
  865. {
  866. editorUi.vRuler.setUnit(mxRuler.prototype.PIXELS);
  867. editorUi.hRuler.setUnit(mxRuler.prototype.PIXELS);
  868. editorUi.vRuler.drawRuler(true);
  869. editorUi.hRuler.drawRuler(true);
  870. }));
  871. this.addMenuItems(menu, ['-', 'rulerInch', 'rulerCM', 'rulerPixel'], parent);
  872. }
  873. })));
  874. // Only visible in test mode
  875. if (urlParams['test'] == '1')
  876. {
  877. mxResources.parse('testDevelop=Develop');
  878. mxResources.parse('showBoundingBox=Show bounding box');
  879. mxResources.parse('createSidebarEntry=Create Sidebar Entry');
  880. mxResources.parse('testCheckFile=Check File');
  881. mxResources.parse('testDiff=Diff');
  882. mxResources.parse('testInspect=Inspect');
  883. mxResources.parse('testShowConsole=Show Console');
  884. mxResources.parse('testXmlImageExport=XML Image Export');
  885. mxResources.parse('testDownloadRtModel=Export RT model');
  886. mxResources.parse('testImportRtModel=Import RT model');
  887. editorUi.actions.addAction('createSidebarEntry', mxUtils.bind(this, function()
  888. {
  889. if (!graph.isSelectionEmpty())
  890. {
  891. editorUi.showTextDialog('Create Sidebar Entry', 'sb.createVertexTemplateFromData(\'' +
  892. Graph.compress(mxUtils.getXml(graph.encodeCells(graph.getSelectionCells()))) +
  893. '\', width, height, \'Title\');');
  894. }
  895. }));
  896. editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  897. {
  898. var b = graph.getGraphBounds();
  899. var tr = graph.view.translate;
  900. var s = graph.view.scale;
  901. graph.insertVertex(graph.getDefaultParent(), null, '',
  902. b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s,
  903. 'fillColor=none;strokeColor=red;');
  904. }));
  905. editorUi.actions.addAction('testCheckFile', mxUtils.bind(this, function()
  906. {
  907. var xml = (editorUi.pages != null && editorUi.getCurrentFile() != null) ?
  908. editorUi.getCurrentFile().getAnonymizedXmlForPages(editorUi.pages) : '';
  909. var dlg = new TextareaDialog(editorUi, 'Paste Data:', xml,
  910. function(newValue)
  911. {
  912. if (newValue.length > 0)
  913. {
  914. try
  915. {
  916. if (newValue.charAt(0) != '<')
  917. {
  918. newValue = Graph.decompress(newValue);
  919. mxLog.debug('See console for uncompressed XML');
  920. console.log('xml', newValue);
  921. }
  922. var doc = mxUtils.parseXml(newValue);
  923. var pages = editorUi.getPagesForNode(doc.documentElement, 'mxGraphModel');
  924. if (pages != null && pages.length > 0)
  925. {
  926. try
  927. {
  928. var checksum = editorUi.getHashValueForPages(pages);
  929. mxLog.debug('Checksum: ', checksum);
  930. }
  931. catch (e)
  932. {
  933. mxLog.debug('Error: ', e.message);
  934. }
  935. }
  936. else
  937. {
  938. mxLog.debug('No pages found for checksum');
  939. }
  940. // Checks for duplicates
  941. function checkModel(node)
  942. {
  943. var pageId = node.parentNode.id;
  944. var all = node.childNodes;
  945. var allIds = {};
  946. var childs = {};
  947. var root = null;
  948. var dups = {};
  949. for (var i = 0; i < all.length; i++)
  950. {
  951. var el = all[i];
  952. if (el.id != null && el.id.length > 0)
  953. {
  954. if (allIds[el.id] == null)
  955. {
  956. allIds[el.id] = el.id;
  957. var pid = el.getAttribute('parent');
  958. if (pid == null)
  959. {
  960. if (root != null)
  961. {
  962. mxLog.debug(pageId + ': Multiple roots: ' + el.id);
  963. }
  964. else
  965. {
  966. root = el.id;
  967. }
  968. }
  969. else
  970. {
  971. if (childs[pid] == null)
  972. {
  973. childs[pid] = [];
  974. }
  975. childs[pid].push(el.id);
  976. }
  977. }
  978. else
  979. {
  980. dups[el.id] = el.id;
  981. }
  982. }
  983. }
  984. if (Object.keys(dups).length > 0)
  985. {
  986. var log = pageId + ': ' + Object.keys(dups).length + ' Duplicates: ' + Object.keys(dups).join(', ');
  987. mxLog.debug(log + ' (see console)');
  988. }
  989. else
  990. {
  991. mxLog.debug(pageId + ': Checked');
  992. }
  993. // Checks tree for cycles
  994. var visited = {};
  995. function visit(id)
  996. {
  997. if (visited[id] == null)
  998. {
  999. visited[id] = true;
  1000. if (childs[id] != null)
  1001. {
  1002. while (childs[id].length > 0)
  1003. {
  1004. var temp = childs[id].pop();
  1005. visit(temp);
  1006. }
  1007. delete childs[id];
  1008. }
  1009. }
  1010. else
  1011. {
  1012. mxLog.debug(pageId + ': Visited: ' + id);
  1013. }
  1014. };
  1015. if (root == null)
  1016. {
  1017. mxLog.debug(pageId + ': No root');
  1018. }
  1019. else
  1020. {
  1021. visit(root);
  1022. if (Object.keys(visited).length != Object.keys(allIds).length)
  1023. {
  1024. mxLog.debug(pageId + ': Invalid tree: (see console)');
  1025. console.log(pageId + ': Invalid tree', childs);
  1026. }
  1027. }
  1028. };
  1029. var roots = doc.getElementsByTagName('root');
  1030. for (var i = 0; i < roots.length; i++)
  1031. {
  1032. checkModel(roots[i]);
  1033. }
  1034. mxLog.show();
  1035. }
  1036. catch (e)
  1037. {
  1038. editorUi.handleError(e);
  1039. console.error(e);
  1040. }
  1041. }
  1042. });
  1043. dlg.textarea.style.width = '600px';
  1044. dlg.textarea.style.height = '380px';
  1045. editorUi.showDialog(dlg.container, 620, 460, true, true);
  1046. dlg.init();
  1047. }));
  1048. editorUi.actions.addAction('testDiff', mxUtils.bind(this, function()
  1049. {
  1050. if (editorUi.pages != null)
  1051. {
  1052. var dlg = new TextareaDialog(editorUi, 'Paste Data:', '',
  1053. function(newValue)
  1054. {
  1055. if (newValue.length > 0)
  1056. {
  1057. try
  1058. {
  1059. console.log(JSON.stringify(editorUi.diffPages(editorUi.pages,
  1060. editorUi.getPagesForNode(mxUtils.parseXml(newValue).
  1061. documentElement)), null, 2));
  1062. }
  1063. catch (e)
  1064. {
  1065. editorUi.handleError(e);
  1066. console.error(e);
  1067. }
  1068. }
  1069. });
  1070. dlg.textarea.style.width = '600px';
  1071. dlg.textarea.style.height = '380px';
  1072. editorUi.showDialog(dlg.container, 620, 460, true, true);
  1073. dlg.init();
  1074. }
  1075. else
  1076. {
  1077. editorUi.alert('No pages');
  1078. }
  1079. }));
  1080. editorUi.actions.addAction('testInspect', mxUtils.bind(this, function()
  1081. {
  1082. console.log(editorUi, graph.getModel());
  1083. }));
  1084. editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  1085. {
  1086. var bg = '#ffffff';
  1087. var scale = 1;
  1088. var b = 1;
  1089. var imgExport = new mxImageExport();
  1090. var bounds = graph.getGraphBounds();
  1091. var vs = graph.view.scale;
  1092. // New image export
  1093. var xmlDoc = mxUtils.createXmlDocument();
  1094. var root = xmlDoc.createElement('output');
  1095. xmlDoc.appendChild(root);
  1096. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1097. var xmlCanvas = new mxXmlCanvas2D(root);
  1098. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  1099. xmlCanvas.scale(scale / vs);
  1100. var stateCounter = 0;
  1101. var canvasSave = xmlCanvas.save;
  1102. xmlCanvas.save = function()
  1103. {
  1104. stateCounter++;
  1105. canvasSave.apply(this, arguments);
  1106. };
  1107. var canvasRestore = xmlCanvas.restore;
  1108. xmlCanvas.restore = function()
  1109. {
  1110. stateCounter--;
  1111. canvasRestore.apply(this, arguments);
  1112. };
  1113. var exportDrawShape = imgExport.drawShape;
  1114. imgExport.drawShape = function(state)
  1115. {
  1116. mxLog.debug('entering shape', state, stateCounter);
  1117. exportDrawShape.apply(this, arguments);
  1118. mxLog.debug('leaving shape', state, stateCounter);
  1119. };
  1120. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1121. // Puts request data together
  1122. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  1123. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  1124. mxLog.show();
  1125. mxLog.debug(mxUtils.getXml(root));
  1126. mxLog.debug('stateCounter', stateCounter);
  1127. }));
  1128. editorUi.actions.addAction('testDownloadRtModel...', mxUtils.bind(this, function()
  1129. {
  1130. if (editorUi.drive == null)
  1131. {
  1132. editorUi.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  1133. }
  1134. else
  1135. {
  1136. editorUi.drive.execute(mxUtils.bind(this, function()
  1137. {
  1138. var fileId =prompt('File ID', '');
  1139. if (fileId != null && fileId.length > 0 &&
  1140. editorUi.spinner.spin(document.body, mxResources.get('export')))
  1141. {
  1142. // LATER: Download full model dump with history
  1143. var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
  1144. fileId + '/realtime?supportsTeamDrives=true', null, 'GET');
  1145. // Adds auth token
  1146. req.setRequestHeaders = function(request)
  1147. {
  1148. mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
  1149. var token = gapi.auth.getToken().access_token;
  1150. request.setRequestHeader('authorization', 'Bearer ' + token);
  1151. };
  1152. req.send(function(req)
  1153. {
  1154. editorUi.spinner.stop();
  1155. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  1156. {
  1157. editorUi.saveLocalFile(req.getText(), 'json-' + fileId +'.txt', 'text/plain');
  1158. }
  1159. else
  1160. {
  1161. editorUi.handleError({message: mxResources.get('fileNotFound')},
  1162. mxResources.get('errorLoadingFile'));
  1163. }
  1164. });
  1165. }
  1166. }));
  1167. }
  1168. }));
  1169. editorUi.actions.addAction('testShowConsole', function()
  1170. {
  1171. if (!mxLog.isVisible())
  1172. {
  1173. mxLog.show();
  1174. }
  1175. else
  1176. {
  1177. mxLog.window.fit();
  1178. }
  1179. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  1180. });
  1181. this.put('testDevelop', new Menu(mxUtils.bind(this, function(menu, parent)
  1182. {
  1183. this.addMenuItems(menu, ['createSidebarEntry', 'showBoundingBox', '-',
  1184. 'testCheckFile', 'testDiff', '-', 'testInspect', '-',
  1185. 'testXmlImageExport', '-', 'testDownloadRtModel'], parent);
  1186. menu.addItem(mxResources.get('testImportRtModel') + '...', null, function()
  1187. {
  1188. var input = document.createElement('input');
  1189. input.setAttribute('type', 'file');
  1190. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  1191. {
  1192. if (input.files != null)
  1193. {
  1194. var reader = new FileReader();
  1195. reader.onload = mxUtils.bind(this, function(e)
  1196. {
  1197. try
  1198. {
  1199. editorUi.openLocalFile(mxUtils.getXml(editorUi.drive.convertJsonToXml(
  1200. JSON.parse(e.target.result).data)), input.files[0].name, true);
  1201. }
  1202. catch (err)
  1203. {
  1204. editorUi.handleError(err, mxResources.get('errorLoadingFile'));
  1205. }
  1206. });
  1207. reader.readAsText(input.files[0]);
  1208. }
  1209. }));
  1210. input.click();
  1211. }, parent);
  1212. this.addMenuItems(menu, ['-', 'testShowConsole'], parent);
  1213. })));
  1214. }
  1215. editorUi.actions.addAction('shapes...', function()
  1216. {
  1217. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  1218. {
  1219. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  1220. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  1221. }
  1222. else
  1223. {
  1224. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  1225. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  1226. }
  1227. });
  1228. editorUi.actions.addAction('createShape...', function()
  1229. {
  1230. var file = editorUi.getCurrentFile();
  1231. if (graph.isEnabled())
  1232. {
  1233. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  1234. cell.vertex = true;
  1235. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  1236. editorUi.showDialog(dlg.container, 640, 480, true, false);
  1237. dlg.init();
  1238. }
  1239. });
  1240. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  1241. {
  1242. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1243. {
  1244. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1245. {
  1246. editorUi.spinner.stop();
  1247. editorUi.showHtmlDialog(mxResources.get('create'), 'https://desk.draw.io/support/solutions/articles/16000042542',
  1248. url, function(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  1249. {
  1250. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  1251. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  1252. {
  1253. var dlg = new EmbedDialog(editorUi, html + '\n' + scriptTag, null, null, function()
  1254. {
  1255. var wnd = window.open();
  1256. var doc = wnd.document;
  1257. if (doc != null)
  1258. {
  1259. if (document.compatMode === 'CSS1Compat')
  1260. {
  1261. doc.writeln('<!DOCTYPE html>');
  1262. }
  1263. doc.writeln('<html>');
  1264. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  1265. '</title><meta charset="utf-8"></head>');
  1266. doc.writeln('<body>');
  1267. doc.writeln(html);
  1268. var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
  1269. if (direct)
  1270. {
  1271. doc.writeln(scriptTag);
  1272. }
  1273. doc.writeln('</body>');
  1274. doc.writeln('</html>');
  1275. doc.close();
  1276. // Adds script tag after closing page and delay to fix timing issues
  1277. if (!direct)
  1278. {
  1279. var info = wnd.document.createElement('div');
  1280. info.marginLeft = '26px';
  1281. info.marginTop = '26px';
  1282. mxUtils.write(info, mxResources.get('updatingDocument'));
  1283. var img = wnd.document.createElement('img');
  1284. img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
  1285. '/' + IMAGE_PATH + '/spin.gif');
  1286. img.style.marginLeft = '6px';
  1287. info.appendChild(img);
  1288. wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
  1289. window.setTimeout(function()
  1290. {
  1291. var script = document.createElement('script');
  1292. script.type = 'text/javascript';
  1293. script.src = /<script.*?src="(.*?)"/.exec(scriptTag)[1];
  1294. doc.body.appendChild(script);
  1295. info.parentNode.removeChild(info);
  1296. }, 20);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  1302. }
  1303. });
  1304. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1305. dlg.init();
  1306. }));
  1307. });
  1308. });
  1309. }
  1310. }));
  1311. editorUi.actions.put('liveImage', new Action('Live image...', function()
  1312. {
  1313. var current = editorUi.getCurrentFile();
  1314. if (current != null && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1315. {
  1316. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1317. {
  1318. editorUi.spinner.stop();
  1319. if (url != null)
  1320. {
  1321. var dlg = new EmbedDialog(editorUi, '<img src="' + ((current.constructor != DriveFile) ?
  1322. url : 'https://drive.google.com/uc?id=' + current.getId()) + '"/>');
  1323. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1324. dlg.init();
  1325. }
  1326. else
  1327. {
  1328. editorUi.handleError({message: mxResources.get('invalidPublicUrl')});
  1329. }
  1330. });
  1331. }
  1332. }));
  1333. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  1334. {
  1335. editorUi.showEmbedImageDialog(function(fit, shadow, retina, lightbox, editLink, layers)
  1336. {
  1337. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1338. {
  1339. editorUi.createEmbedImage(fit, shadow, retina, lightbox, editLink, layers, function(result)
  1340. {
  1341. editorUi.spinner.stop();
  1342. var dlg = new EmbedDialog(editorUi, result);
  1343. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1344. dlg.init();
  1345. }, function(err)
  1346. {
  1347. editorUi.spinner.stop();
  1348. editorUi.handleError(err);
  1349. });
  1350. }
  1351. }, mxResources.get('image'), mxResources.get('retina'), editorUi.isExportToCanvas());
  1352. }));
  1353. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  1354. {
  1355. editorUi.showEmbedImageDialog(function(fit, shadow, image, lightbox, editLink, layers)
  1356. {
  1357. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1358. {
  1359. editorUi.createEmbedSvg(fit, shadow, image, lightbox, editLink, layers, function(result)
  1360. {
  1361. editorUi.spinner.stop();
  1362. var dlg = new EmbedDialog(editorUi, result);
  1363. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1364. dlg.init();
  1365. }, function(err)
  1366. {
  1367. editorUi.spinner.stop();
  1368. editorUi.handleError(err);
  1369. });
  1370. }
  1371. }, mxResources.get('formatSvg'), mxResources.get('image'),
  1372. true, 'https://desk.draw.io/support/solutions/articles/16000042548');
  1373. }));
  1374. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  1375. {
  1376. var bounds = graph.getGraphBounds();
  1377. editorUi.showPublishLinkDialog(mxResources.get('iframe'), null, '100%',
  1378. (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / graph.view.scale) + 2),
  1379. function(linkTarget, linkColor, allPages, lightbox, editLink, layers, width, height)
  1380. {
  1381. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1382. {
  1383. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1384. {
  1385. editorUi.spinner.stop();
  1386. var dlg = new EmbedDialog(editorUi, '<iframe frameborder="0" style="width:' + width +
  1387. ';height:' + height + ';" src="' + editorUi.createLink(linkTarget, linkColor,
  1388. allPages, lightbox, editLink, layers, url) + '"></iframe>');
  1389. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1390. dlg.init();
  1391. });
  1392. }
  1393. }, true);
  1394. }));
  1395. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  1396. {
  1397. editorUi.showPublishLinkDialog(null, null, null, null,
  1398. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  1399. {
  1400. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1401. {
  1402. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1403. {
  1404. editorUi.spinner.stop();
  1405. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  1406. linkColor, allPages, lightbox, editLink, layers, url));
  1407. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1408. dlg.init();
  1409. });
  1410. }
  1411. });
  1412. }));
  1413. editorUi.actions.addAction('googleDocs...', function()
  1414. {
  1415. editorUi.openLink('http://docsaddon.draw.io');
  1416. });
  1417. editorUi.actions.addAction('googleSlides...', function()
  1418. {
  1419. editorUi.openLink('https://slidesaddon.draw.io');
  1420. });
  1421. editorUi.actions.addAction('googleSites...', function()
  1422. {
  1423. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1424. {
  1425. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1426. {
  1427. editorUi.spinner.stop();
  1428. var dlg = new GoogleSitesDialog(editorUi, url);
  1429. editorUi.showDialog(dlg.container, 420, 256, true, true);
  1430. dlg.init();
  1431. });
  1432. }
  1433. });
  1434. // Adds plugins menu item only if localStorage is available for storing the plugins
  1435. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  1436. {
  1437. var action = editorUi.actions.addAction('scratchpad', function()
  1438. {
  1439. editorUi.toggleScratchpad();
  1440. });
  1441. action.setToggleAction(true);
  1442. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  1443. editorUi.actions.addAction('plugins...', function()
  1444. {
  1445. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 170, true, false);
  1446. });
  1447. }
  1448. var action = editorUi.actions.addAction('search', function()
  1449. {
  1450. var visible = editorUi.sidebar.isEntryVisible('search');
  1451. editorUi.sidebar.showPalette('search', !visible);
  1452. if (isLocalStorage)
  1453. {
  1454. mxSettings.settings.search = !visible;
  1455. mxSettings.save();
  1456. }
  1457. });
  1458. action.setToggleAction(true);
  1459. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  1460. if (urlParams['embed'] == '1')
  1461. {
  1462. editorUi.actions.get('save').funct = function(exit)
  1463. {
  1464. if (graph.isEditing())
  1465. {
  1466. graph.stopEditing();
  1467. }
  1468. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  1469. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  1470. if (urlParams['proto'] == 'json')
  1471. {
  1472. var msg = editorUi.createLoadMessage('save');
  1473. msg.xml = data;
  1474. if (exit)
  1475. {
  1476. msg.exit = true;
  1477. }
  1478. data = JSON.stringify(msg);
  1479. }
  1480. var parent = window.opener || window.parent;
  1481. parent.postMessage(data, '*');
  1482. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  1483. {
  1484. editorUi.editor.modified = false;
  1485. editorUi.editor.setStatus('');
  1486. }
  1487. //Add support to saving files if embedded mode is running with files
  1488. var file = editorUi.getCurrentFile();
  1489. if (file != null)
  1490. {
  1491. editorUi.saveFile();
  1492. }
  1493. };
  1494. editorUi.actions.addAction('saveAndExit', function()
  1495. {
  1496. editorUi.actions.get('save').funct(true);
  1497. });
  1498. editorUi.actions.addAction('exit', function()
  1499. {
  1500. var fn = function()
  1501. {
  1502. editorUi.editor.modified = false;
  1503. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  1504. modified: editorUi.editor.modified}) : '';
  1505. var parent = window.opener || window.parent;
  1506. parent.postMessage(msg, '*');
  1507. }
  1508. if (!editorUi.editor.modified)
  1509. {
  1510. fn();
  1511. }
  1512. else
  1513. {
  1514. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  1515. mxResources.get('cancel'), mxResources.get('discardChanges'));
  1516. }
  1517. });
  1518. }
  1519. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  1520. {
  1521. if (editorUi.isExportToCanvas())
  1522. {
  1523. this.addMenuItems(menu, ['exportPng'], parent);
  1524. if (editorUi.jpgSupported)
  1525. {
  1526. this.addMenuItems(menu, ['exportJpg'], parent);
  1527. }
  1528. }
  1529. // Disabled for standalone mode in iOS because new tab cannot be closed
  1530. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1531. {
  1532. this.addMenuItems(menu, ['exportPng', 'exportJpg'], parent);
  1533. }
  1534. this.addMenuItems(menu, ['exportSvg', '-'], parent);
  1535. // Redirects export to PDF to print in Chrome App
  1536. if (editorUi.isOffline() || editorUi.printPdfExport)
  1537. {
  1538. this.addMenuItems(menu, ['exportPdf'], parent);
  1539. }
  1540. // Disabled for standalone mode in iOS because new tab cannot be closed
  1541. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1542. {
  1543. this.addMenuItems(menu, ['exportPdf'], parent);
  1544. }
  1545. if (!mxClient.IS_IE && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
  1546. {
  1547. this.addMenuItems(menu, ['exportVsdx'], parent);
  1548. }
  1549. this.addMenuItems(menu, ['-', 'exportHtml', 'exportXml', 'exportUrl'], parent);
  1550. if (!editorUi.isOffline())
  1551. {
  1552. menu.addSeparator(parent);
  1553. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  1554. }
  1555. })));
  1556. this.put('importFrom', new Menu(mxUtils.bind(this, function(menu, parent)
  1557. {
  1558. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  1559. {
  1560. // Gets insert location
  1561. var view = graph.view;
  1562. var bds = graph.getGraphBounds();
  1563. var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
  1564. var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
  1565. if (data.substring(0, 11) == 'data:image/')
  1566. {
  1567. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  1568. {
  1569. var resizeImages = true;
  1570. var doInsert = mxUtils.bind(this, function()
  1571. {
  1572. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  1573. {
  1574. var s = (resizeImages) ? Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2)) : 1;
  1575. editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  1576. {
  1577. editorUi.spinner.stop();
  1578. graph.setSelectionCells(cells);
  1579. graph.scrollCellToVisible(graph.getSelectionCell());
  1580. });
  1581. }), resizeImages);
  1582. });
  1583. if (data.length > editorUi.resampleThreshold)
  1584. {
  1585. editorUi.confirmImageResize(function(doResize)
  1586. {
  1587. resizeImages = doResize;
  1588. doInsert();
  1589. });
  1590. }
  1591. else
  1592. {
  1593. doInsert();
  1594. }
  1595. }), mxUtils.bind(this, function()
  1596. {
  1597. editorUi.handleError({message: mxResources.get('cannotOpenFile')});
  1598. }));
  1599. }
  1600. else
  1601. {
  1602. editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
  1603. {
  1604. editorUi.spinner.stop();
  1605. graph.setSelectionCells(cells);
  1606. graph.scrollCellToVisible(graph.getSelectionCell());
  1607. });
  1608. }
  1609. });
  1610. var getMimeType = mxUtils.bind(this, function(filename)
  1611. {
  1612. var mime = 'text/xml';
  1613. if (/\.png$/i.test(filename))
  1614. {
  1615. mime = 'image/png';
  1616. }
  1617. else if (/\.jpe?g$/i.test(filename))
  1618. {
  1619. mime = 'image/jpg';
  1620. }
  1621. else if (/\.gif$/i.test(filename))
  1622. {
  1623. mime = 'image/gif';
  1624. }
  1625. return mime;
  1626. });
  1627. function pickFileFromService(service)
  1628. {
  1629. // Drive requires special arguments for libraries and bypassing realtime
  1630. service.pickFile(function(id)
  1631. {
  1632. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1633. {
  1634. // NOTE The third argument in getFile says denyConvert to match
  1635. // the existing signature in the original DriveClient which has
  1636. // as slightly different semantic, but works the same way.
  1637. service.getFile(id, function(file)
  1638. {
  1639. var mime = (file.getData().substring(0, 11) == 'data:image/') ? getMimeType(file.getTitle()) : 'text/xml';
  1640. // Imports SVG as images
  1641. if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
  1642. {
  1643. file.setData(editorUi.createSvgDataUri(file.getData()));
  1644. mime = 'image/svg+xml';
  1645. }
  1646. doImportFile(file.getData(), mime, file.getTitle());
  1647. },
  1648. function(resp)
  1649. {
  1650. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1651. }, service == editorUi.drive);
  1652. }
  1653. }, true);
  1654. };
  1655. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1656. {
  1657. if (editorUi.drive != null)
  1658. {
  1659. // Requires special arguments for libraries and realtime
  1660. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1661. {
  1662. pickFileFromService(editorUi.drive);
  1663. }, parent);
  1664. }
  1665. else if (googleEnabled && typeof window.DriveClient === 'function')
  1666. {
  1667. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1668. {
  1669. // do nothing
  1670. }, parent, null, false);
  1671. }
  1672. }
  1673. if (editorUi.oneDrive != null)
  1674. {
  1675. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1676. {
  1677. pickFileFromService(editorUi.oneDrive);
  1678. }, parent);
  1679. }
  1680. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  1681. {
  1682. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1683. {
  1684. // do nothing
  1685. }, parent, null, false);
  1686. }
  1687. if (editorUi.dropbox != null)
  1688. {
  1689. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1690. {
  1691. pickFileFromService(editorUi.dropbox);
  1692. }, parent);
  1693. }
  1694. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  1695. {
  1696. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1697. {
  1698. // do nothing
  1699. }, parent, null, false);
  1700. }
  1701. if (editorUi.gitHub != null)
  1702. {
  1703. menu.addItem(mxResources.get('github') + '...', null, function()
  1704. {
  1705. pickFileFromService(editorUi.gitHub);
  1706. }, parent);
  1707. }
  1708. if (editorUi.trello != null)
  1709. {
  1710. menu.addItem(mxResources.get('trello') + '...', null, function()
  1711. {
  1712. pickFileFromService(editorUi.trello);
  1713. }, parent);
  1714. }
  1715. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  1716. {
  1717. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  1718. {
  1719. // do nothing
  1720. }, parent, null, false);
  1721. }
  1722. menu.addSeparator(parent);
  1723. if (isLocalStorage && urlParams['browser'] != '0')
  1724. {
  1725. menu.addItem(mxResources.get('browser') + '...', null, function()
  1726. {
  1727. editorUi.importLocalFile(false);
  1728. }, parent);
  1729. }
  1730. menu.addItem(mxResources.get('device') + '...', null, function()
  1731. {
  1732. editorUi.importLocalFile(true);
  1733. }, parent);
  1734. if (!editorUi.isOffline())
  1735. {
  1736. menu.addSeparator(parent);
  1737. menu.addItem(mxResources.get('url') + '...', null, function()
  1738. {
  1739. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1740. {
  1741. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1742. {
  1743. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1744. // Uses proxy to avoid CORS issues
  1745. editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1746. {
  1747. doImportFile(data, mime, fileUrl);
  1748. },
  1749. function ()
  1750. {
  1751. editorUi.spinner.stop();
  1752. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1753. }, mime == 'image/png');
  1754. }
  1755. }, mxResources.get('url'));
  1756. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1757. dlg.init();
  1758. }, parent);
  1759. }
  1760. }))).isEnabled = isGraphEnabled;
  1761. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1762. {
  1763. var theme = mxSettings.getUi();
  1764. var item = menu.addItem(mxResources.get('automatic'), null, function()
  1765. {
  1766. mxSettings.setUi('');
  1767. mxSettings.save();
  1768. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1769. }, parent);
  1770. if (theme != 'kennedy' && theme != 'atlas' &&
  1771. theme != 'dark' && theme != 'min')
  1772. {
  1773. menu.addCheckmark(item, Editor.checkmarkImage);
  1774. }
  1775. menu.addSeparator(parent);
  1776. item = menu.addItem(mxResources.get('kennedy'), null, function()
  1777. {
  1778. mxSettings.setUi('kennedy');
  1779. mxSettings.save();
  1780. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1781. }, parent);
  1782. if (theme == 'kennedy')
  1783. {
  1784. menu.addCheckmark(item, Editor.checkmarkImage);
  1785. }
  1786. item = menu.addItem(mxResources.get('minimal'), null, function()
  1787. {
  1788. mxSettings.setUi('min');
  1789. mxSettings.save();
  1790. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1791. }, parent);
  1792. if (theme == 'min')
  1793. {
  1794. menu.addCheckmark(item, Editor.checkmarkImage);
  1795. }
  1796. item = menu.addItem(mxResources.get('atlas'), null, function()
  1797. {
  1798. mxSettings.setUi('atlas');
  1799. mxSettings.save();
  1800. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1801. }, parent);
  1802. if (theme == 'atlas')
  1803. {
  1804. menu.addCheckmark(item, Editor.checkmarkImage);
  1805. }
  1806. item = menu.addItem(mxResources.get('dark'), null, function()
  1807. {
  1808. mxSettings.setUi('dark');
  1809. mxSettings.save();
  1810. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1811. }, parent);
  1812. if (theme == 'dark')
  1813. {
  1814. menu.addCheckmark(item, Editor.checkmarkImage);
  1815. }
  1816. })));
  1817. var renameAction = this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  1818. {
  1819. var file = this.editorUi.getCurrentFile();
  1820. if (file != null)
  1821. {
  1822. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  1823. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  1824. {
  1825. if (title != null && title.length > 0 && file != null && title != file.getTitle() &&
  1826. this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  1827. {
  1828. // Delete old file, save new file in dropbox if autosize is enabled
  1829. file.rename(title, mxUtils.bind(this, function(resp)
  1830. {
  1831. this.editorUi.spinner.stop();
  1832. }),
  1833. mxUtils.bind(this, function(resp)
  1834. {
  1835. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  1836. }));
  1837. }
  1838. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  1839. mxResources.get('diagramName') : null, function(name)
  1840. {
  1841. if (name != null && name.length > 0)
  1842. {
  1843. return true;
  1844. }
  1845. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  1846. return false;
  1847. }, null, null, null, null, editorUi.editor.fileExtensions);
  1848. this.editorUi.showDialog(dlg.container, 340, 90, true, true);
  1849. dlg.init();
  1850. }
  1851. }));
  1852. renameAction.isEnabled = function()
  1853. {
  1854. return this.enabled && isGraphEnabled.apply(this, arguments);
  1855. }
  1856. renameAction.visible = urlParams['embed'] != '1';
  1857. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  1858. {
  1859. var file = editorUi.getCurrentFile();
  1860. if (file != null)
  1861. {
  1862. var title = editorUi.getCopyFilename(file);
  1863. if (file.constructor == DriveFile)
  1864. {
  1865. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  1866. {
  1867. // Mode is "download" if Create button is pressed, means use Google Drive
  1868. if (mode == 'download')
  1869. {
  1870. mode = App.MODE_GOOGLE;
  1871. }
  1872. if (newTitle != null && newTitle.length > 0)
  1873. {
  1874. if (mode == App.MODE_GOOGLE)
  1875. {
  1876. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  1877. {
  1878. // Saveas does not update the file descriptor in Google Drive
  1879. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  1880. {
  1881. // Replaces file descriptor in-place and saves
  1882. file.desc = resp;
  1883. // Makes sure the latest XML is in the file
  1884. file.save(false, mxUtils.bind(this, function()
  1885. {
  1886. editorUi.spinner.stop();
  1887. file.setModified(false);
  1888. file.addAllSavedStatus();
  1889. }), mxUtils.bind(this, function(resp)
  1890. {
  1891. editorUi.handleError(resp);
  1892. }));
  1893. }), mxUtils.bind(this, function(resp)
  1894. {
  1895. editorUi.handleError(resp);
  1896. }));
  1897. }
  1898. }
  1899. else
  1900. {
  1901. editorUi.createFile(newTitle, editorUi.getFileData(true), null, mode);
  1902. }
  1903. }
  1904. }), mxUtils.bind(this, function()
  1905. {
  1906. editorUi.hideDialog();
  1907. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  1908. null, null, null, true, null, null, null, null,
  1909. editorUi.editor.fileExtensions);
  1910. editorUi.showDialog(dlg.container, 420, 380, true, true);
  1911. dlg.init();
  1912. }
  1913. else
  1914. {
  1915. // Creates a copy with no predefined storage
  1916. editorUi.editor.editAsNew(this.editorUi.getFileData(true), title);
  1917. }
  1918. }
  1919. }));
  1920. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  1921. {
  1922. var file = editorUi.getCurrentFile();
  1923. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  1924. {
  1925. var isInRoot = false;
  1926. if (file.getMode() == App.MODE_GOOGLE && file.desc.parents != null)
  1927. {
  1928. for (var i = 0; i < file.desc.parents.length; i++)
  1929. {
  1930. if (file.desc.parents[i].isRoot)
  1931. {
  1932. isInRoot = true;
  1933. break;
  1934. }
  1935. }
  1936. }
  1937. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  1938. {
  1939. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  1940. {
  1941. file.move(folderId, mxUtils.bind(this, function(resp)
  1942. {
  1943. editorUi.spinner.stop();
  1944. }), mxUtils.bind(this, function(resp)
  1945. {
  1946. editorUi.handleError(resp);
  1947. }));
  1948. }
  1949. }), null, true, isInRoot);
  1950. }
  1951. }));
  1952. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  1953. {
  1954. this.addMenuItems(menu, ['publishLink'], parent);
  1955. })));
  1956. editorUi.actions.put('useOffline', new Action(mxResources.get('useOffline') + '...', function()
  1957. {
  1958. editorUi.openLink('https://app.draw.io/')
  1959. }));
  1960. editorUi.actions.put('downloadDesktop', new Action(mxResources.get('downloadDesktop') + '...', function()
  1961. {
  1962. editorUi.openLink('https://get.draw.io/')
  1963. }));
  1964. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  1965. {
  1966. try
  1967. {
  1968. var file = editorUi.getCurrentFile();
  1969. if (file != null)
  1970. {
  1971. editorUi.drive.showPermissions(file.getId());
  1972. }
  1973. }
  1974. catch (e)
  1975. {
  1976. editorUi.handleError(e);
  1977. }
  1978. }));
  1979. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  1980. {
  1981. var file = editorUi.getCurrentFile();
  1982. if (file != null && (file.getMode() == App.MODE_GOOGLE ||
  1983. file.getMode() == App.MODE_GITHUB) && /(\.png)$/i.test(file.getTitle()))
  1984. {
  1985. this.addMenuItems(menu, ['liveImage', '-'], parent);
  1986. }
  1987. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  1988. if (!navigator.standalone && !editorUi.isOffline())
  1989. {
  1990. this.addMenuItems(menu, ['embedIframe'], parent);
  1991. }
  1992. if (urlParams['embed'] != '1' && !editorUi.isOffline())
  1993. {
  1994. this.addMenuItems(menu, ['-', 'googleDocs', 'googleSlides'], parent);
  1995. }
  1996. })));
  1997. var addInsertItem = function(menu, parent, title, method)
  1998. {
  1999. if (method != 'plantUml' || (EditorUi.enablePlantUml && !editorUi.isOffline()))
  2000. {
  2001. menu.addItem(title, null, mxUtils.bind(this, function()
  2002. {
  2003. if (method == 'fromText' || method == 'formatSql' || method == 'plantUml')
  2004. {
  2005. var dlg = new ParseDialog(editorUi, title, method);
  2006. editorUi.showDialog(dlg.container, 620, 420, true, false);
  2007. editorUi.dialog.container.style.overflow = 'auto';
  2008. dlg.init();
  2009. }
  2010. else
  2011. {
  2012. var dlg = new CreateGraphDialog(editorUi, title, method);
  2013. editorUi.showDialog(dlg.container, 620, 420, true, false);
  2014. // Executed after dialog is added to dom
  2015. dlg.init();
  2016. }
  2017. }), parent, null, isGraphEnabled());
  2018. }
  2019. };
  2020. var insertVertex = function(value, w, h, style)
  2021. {
  2022. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  2023. var cell = new mxCell(value, new mxGeometry(pt.x, pt.y, w, h), style);
  2024. cell.vertex = true;
  2025. graph.getModel().beginUpdate();
  2026. try
  2027. {
  2028. cell = graph.addCell(cell);
  2029. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', [cell]));
  2030. }
  2031. finally
  2032. {
  2033. graph.getModel().endUpdate();
  2034. }
  2035. graph.scrollCellToVisible(cell);
  2036. graph.setSelectionCell(cell);
  2037. graph.container.focus();
  2038. if (graph.editAfterInsert)
  2039. {
  2040. graph.startEditing(cell);
  2041. }
  2042. return cell;
  2043. };
  2044. editorUi.actions.put('exportSvg', new Action(mxResources.get('formatSvg') + '...', function()
  2045. {
  2046. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  2047. 'https://support.draw.io/display/DO/Exporting+Files',
  2048. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow,
  2049. editable, embedImages, border, cropImage, currentPage, linkTarget)
  2050. {
  2051. var val = parseInt(scale);
  2052. if (!isNaN(val) && val > 0)
  2053. {
  2054. editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection, addShadow,
  2055. editable, embedImages, border, !cropImage, currentPage, linkTarget);
  2056. }
  2057. }), true, null, 'svg');
  2058. }));
  2059. editorUi.actions.put('insertText', new Action(mxResources.get('text'), function()
  2060. {
  2061. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2062. {
  2063. graph.startEditingAtCell(insertVertex('Text', 40, 20, 'text;html=1;resizable=0;autosize=1;' +
  2064. 'align=center;verticalAlign=middle;points=[];fillColor=none;strokeColor=none;rounded=0;'));
  2065. }
  2066. }), null, null, Editor.ctrlKey + '+Shift+X').isEnabled = isGraphEnabled;
  2067. editorUi.actions.put('insertRectangle', new Action(mxResources.get('rectangle'), function()
  2068. {
  2069. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2070. {
  2071. insertVertex('', 120, 60, 'whiteSpace=wrap;html=1;');
  2072. }
  2073. }), null, null, Editor.ctrlKey + '+K').isEnabled = isGraphEnabled;
  2074. editorUi.actions.put('insertEllipse', new Action(mxResources.get('ellipse'), function()
  2075. {
  2076. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2077. {
  2078. insertVertex('', 80, 80, 'ellipse;whiteSpace=wrap;html=1;');
  2079. }
  2080. }), null, null, Editor.ctrlKey + '+Shift+K').isEnabled = isGraphEnabled;
  2081. editorUi.actions.put('insertRhombus', new Action(mxResources.get('rhombus'), function()
  2082. {
  2083. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2084. {
  2085. insertVertex('', 80, 80, 'rhombus;whiteSpace=wrap;html=1;');
  2086. }
  2087. })).isEnabled = isGraphEnabled;
  2088. var addInsertMenuItems = mxUtils.bind(this, function(menu, parent, methods)
  2089. {
  2090. for (var i = 0; i < methods.length; i++)
  2091. {
  2092. if (methods[i] == '-')
  2093. {
  2094. menu.addSeparator(parent);
  2095. }
  2096. else
  2097. {
  2098. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  2099. }
  2100. }
  2101. });
  2102. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  2103. {
  2104. this.addMenuItems(menu, ['insertRectangle', 'insertEllipse', 'insertRhombus', '-',
  2105. 'insertText', 'insertLink', '-', 'insertImage'], parent);
  2106. if (editorUi.insertTemplateEnabled && !editorUi.isOffline())
  2107. {
  2108. this.addMenuItems(menu, ['insertTemplate', '-'], parent);
  2109. }
  2110. this.addSubmenu('insertLayout', menu, parent, mxResources.get('layout'));
  2111. menu.addSeparator(parent);
  2112. addInsertMenuItems(menu, parent, ['fromText', 'plantUml', '-', 'formatSql']);
  2113. menu.addItem(mxResources.get('csv') + '...', null, function()
  2114. {
  2115. editorUi.showImportCsvDialog();
  2116. }, parent, null, isGraphEnabled());
  2117. })));
  2118. this.put('insertLayout', new Menu(mxUtils.bind(this, function(menu, parent)
  2119. {
  2120. addInsertMenuItems(menu, parent, ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree',
  2121. 'verticalTree', 'radialTree', '-', 'organic', 'circle']);
  2122. })));
  2123. this.put('openRecent', new Menu(function(menu, parent)
  2124. {
  2125. var recent = editorUi.getRecent();
  2126. if (recent != null)
  2127. {
  2128. for (var i = 0; i < recent.length; i++)
  2129. {
  2130. (function(entry)
  2131. {
  2132. var modeKey = entry.mode;
  2133. // Google and oneDrive use different keys
  2134. if (modeKey == App.MODE_GOOGLE)
  2135. {
  2136. modeKey = 'googleDrive';
  2137. }
  2138. else if (modeKey == App.MODE_ONEDRIVE)
  2139. {
  2140. modeKey = 'oneDrive';
  2141. }
  2142. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  2143. {
  2144. editorUi.loadFile(entry.id);
  2145. }, parent);
  2146. })(recent[i]);
  2147. }
  2148. menu.addSeparator(parent);
  2149. }
  2150. menu.addItem(mxResources.get('reset'), null, function()
  2151. {
  2152. editorUi.resetRecent();
  2153. }, parent);
  2154. }));
  2155. this.put('openFrom', new Menu(function(menu, parent)
  2156. {
  2157. if (editorUi.drive != null)
  2158. {
  2159. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2160. {
  2161. editorUi.pickFile(App.MODE_GOOGLE);
  2162. }, parent);
  2163. }
  2164. else if (googleEnabled && typeof window.DriveClient === 'function')
  2165. {
  2166. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2167. {
  2168. // do nothing
  2169. }, parent, null, false);
  2170. }
  2171. if (editorUi.oneDrive != null)
  2172. {
  2173. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2174. {
  2175. editorUi.pickFile(App.MODE_ONEDRIVE);
  2176. }, parent);
  2177. }
  2178. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  2179. {
  2180. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2181. {
  2182. // do nothing
  2183. }, parent, null, false);
  2184. }
  2185. if (editorUi.dropbox != null)
  2186. {
  2187. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2188. {
  2189. editorUi.pickFile(App.MODE_DROPBOX);
  2190. }, parent);
  2191. }
  2192. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  2193. {
  2194. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2195. {
  2196. // do nothing
  2197. }, parent, null, false);
  2198. }
  2199. if (editorUi.gitHub != null)
  2200. {
  2201. menu.addItem(mxResources.get('github') + '...', null, function()
  2202. {
  2203. editorUi.pickFile(App.MODE_GITHUB);
  2204. }, parent);
  2205. }
  2206. if (editorUi.trello != null)
  2207. {
  2208. menu.addItem(mxResources.get('trello') + '...', null, function()
  2209. {
  2210. editorUi.pickFile(App.MODE_TRELLO);
  2211. }, parent);
  2212. }
  2213. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  2214. {
  2215. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2216. {
  2217. // do nothing
  2218. }, parent, null, false);
  2219. }
  2220. menu.addSeparator(parent);
  2221. if (isLocalStorage && urlParams['browser'] != '0')
  2222. {
  2223. menu.addItem(mxResources.get('browser') + '...', null, function()
  2224. {
  2225. editorUi.pickFile(App.MODE_BROWSER);
  2226. }, parent);
  2227. }
  2228. //if (!mxClient.IS_IOS)
  2229. {
  2230. menu.addItem(mxResources.get('device') + '...', null, function()
  2231. {
  2232. editorUi.pickFile(App.MODE_DEVICE);
  2233. }, parent);
  2234. }
  2235. if (!editorUi.isOffline())
  2236. {
  2237. menu.addSeparator(parent);
  2238. menu.addItem(mxResources.get('url') + '...', null, function()
  2239. {
  2240. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  2241. {
  2242. if (fileUrl != null && fileUrl.length > 0)
  2243. {
  2244. if (editorUi.getCurrentFile() == null)
  2245. {
  2246. window.location.hash = '#U' + encodeURIComponent(fileUrl);
  2247. }
  2248. else
  2249. {
  2250. window.openWindow(((mxClient.IS_CHROMEAPP) ?
  2251. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  2252. window.location.search + '#U' + encodeURIComponent(fileUrl));
  2253. }
  2254. }
  2255. }, mxResources.get('url'));
  2256. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2257. dlg.init();
  2258. }, parent);
  2259. }
  2260. }));
  2261. if (Editor.enableCustomLibraries)
  2262. {
  2263. this.put('newLibrary', new Menu(function(menu, parent)
  2264. {
  2265. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2266. {
  2267. if (editorUi.drive != null)
  2268. {
  2269. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2270. {
  2271. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  2272. }, parent);
  2273. }
  2274. else if (googleEnabled && typeof window.DriveClient === 'function')
  2275. {
  2276. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2277. {
  2278. // do nothing
  2279. }, parent, null, false);
  2280. }
  2281. }
  2282. if (editorUi.oneDrive != null)
  2283. {
  2284. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2285. {
  2286. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  2287. }, parent);
  2288. }
  2289. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  2290. {
  2291. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2292. {
  2293. // do nothing
  2294. }, parent, null, false);
  2295. }
  2296. if (editorUi.dropbox != null)
  2297. {
  2298. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2299. {
  2300. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  2301. }, parent);
  2302. }
  2303. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  2304. {
  2305. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2306. {
  2307. // do nothing
  2308. }, parent, null, false);
  2309. }
  2310. if (editorUi.gitHub != null)
  2311. {
  2312. menu.addItem(mxResources.get('github') + '...', null, function()
  2313. {
  2314. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
  2315. }, parent);
  2316. }
  2317. if (editorUi.trello != null)
  2318. {
  2319. menu.addItem(mxResources.get('trello') + '...', null, function()
  2320. {
  2321. editorUi.showLibraryDialog(null, null, null, null, App.MODE_TRELLO);
  2322. }, parent);
  2323. }
  2324. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  2325. {
  2326. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2327. {
  2328. // do nothing
  2329. }, parent, null, false);
  2330. }
  2331. menu.addSeparator(parent);
  2332. if (isLocalStorage && urlParams['browser'] != '0')
  2333. {
  2334. menu.addItem(mxResources.get('browser') + '...', null, function()
  2335. {
  2336. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  2337. }, parent);
  2338. }
  2339. //if (!mxClient.IS_IOS)
  2340. {
  2341. menu.addItem(mxResources.get('device') + '...', null, function()
  2342. {
  2343. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  2344. }, parent);
  2345. }
  2346. }));
  2347. this.put('openLibraryFrom', new Menu(function(menu, parent)
  2348. {
  2349. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2350. {
  2351. if (editorUi.drive != null)
  2352. {
  2353. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2354. {
  2355. editorUi.pickLibrary(App.MODE_GOOGLE);
  2356. }, parent);
  2357. }
  2358. else if (googleEnabled && typeof window.DriveClient === 'function')
  2359. {
  2360. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2361. {
  2362. // do nothing
  2363. }, parent, null, false);
  2364. }
  2365. }
  2366. if (editorUi.oneDrive != null)
  2367. {
  2368. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2369. {
  2370. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  2371. }, parent);
  2372. }
  2373. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  2374. {
  2375. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2376. {
  2377. // do nothing
  2378. }, parent, null, false);
  2379. }
  2380. if (editorUi.dropbox != null)
  2381. {
  2382. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2383. {
  2384. editorUi.pickLibrary(App.MODE_DROPBOX);
  2385. }, parent);
  2386. }
  2387. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  2388. {
  2389. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2390. {
  2391. // do nothing
  2392. }, parent, null, false);
  2393. }
  2394. if (editorUi.gitHub != null)
  2395. {
  2396. menu.addItem(mxResources.get('github') + '...', null, function()
  2397. {
  2398. editorUi.pickLibrary(App.MODE_GITHUB);
  2399. }, parent);
  2400. }
  2401. if (editorUi.trello != null)
  2402. {
  2403. menu.addItem(mxResources.get('trello') + '...', null, function()
  2404. {
  2405. editorUi.pickLibrary(App.MODE_TRELLO);
  2406. }, parent);
  2407. }
  2408. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  2409. {
  2410. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2411. {
  2412. // do nothing
  2413. }, parent, null, false);
  2414. }
  2415. menu.addSeparator(parent);
  2416. if (isLocalStorage && urlParams['browser'] != '0')
  2417. {
  2418. menu.addItem(mxResources.get('browser') + '...', null, function()
  2419. {
  2420. editorUi.pickLibrary(App.MODE_BROWSER);
  2421. }, parent);
  2422. }
  2423. //if (!mxClient.IS_IOS)
  2424. {
  2425. menu.addItem(mxResources.get('device') + '...', null, function()
  2426. {
  2427. editorUi.pickLibrary(App.MODE_DEVICE);
  2428. }, parent);
  2429. }
  2430. if (!editorUi.isOffline())
  2431. {
  2432. menu.addSeparator(parent);
  2433. menu.addItem(mxResources.get('url') + '...', null, function()
  2434. {
  2435. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  2436. {
  2437. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2438. {
  2439. var realUrl = fileUrl;
  2440. if (!editorUi.editor.isCorsEnabledForUrl(fileUrl))
  2441. {
  2442. realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
  2443. }
  2444. // Uses proxy to avoid CORS issues
  2445. mxUtils.get(realUrl, function(req)
  2446. {
  2447. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2448. {
  2449. editorUi.spinner.stop();
  2450. try
  2451. {
  2452. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  2453. }
  2454. catch (e)
  2455. {
  2456. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  2457. }
  2458. }
  2459. else
  2460. {
  2461. editorUi.spinner.stop();
  2462. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2463. }
  2464. }, function()
  2465. {
  2466. editorUi.spinner.stop();
  2467. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2468. });
  2469. }
  2470. }, mxResources.get('url'));
  2471. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2472. dlg.init();
  2473. }, parent);
  2474. }
  2475. if (urlParams['confLib'] == '1')
  2476. {
  2477. menu.addSeparator(parent);
  2478. menu.addItem(mxResources.get('confluenceCloud') + '...', null, function()
  2479. {
  2480. editorUi.showRemotelyStoredLibrary(mxResources.get('libraries'));
  2481. }, parent);
  2482. }
  2483. }));
  2484. }
  2485. // Overrides edit menu to add find and editGeometry
  2486. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  2487. {
  2488. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-',
  2489. 'find', '-', 'editData', 'editTooltip', '-', 'editStyle', 'editGeometry', '-',
  2490. 'edit', '-', 'editLink', 'openLink', '-',
  2491. 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
  2492. })));
  2493. var action = editorUi.actions.addAction('comments', mxUtils.bind(this, function()
  2494. {
  2495. if (this.commentsWindow == null)
  2496. {
  2497. // LATER: Check outline window for initial placement
  2498. this.commentsWindow = new CommentsWindow(editorUi, document.body.offsetWidth - 380, 120, 300, 350);
  2499. //TODO Are these events needed?
  2500. this.commentsWindow.window.addListener('show', function()
  2501. {
  2502. editorUi.fireEvent(new mxEventObject('comments'));
  2503. });
  2504. this.commentsWindow.window.addListener('hide', function()
  2505. {
  2506. editorUi.fireEvent(new mxEventObject('comments'));
  2507. });
  2508. this.commentsWindow.window.setVisible(true);
  2509. editorUi.fireEvent(new mxEventObject('comments'));
  2510. }
  2511. else
  2512. {
  2513. this.commentsWindow.window.setVisible(!this.commentsWindow.window.isVisible());
  2514. this.commentsWindow.refreshCommentsTime();
  2515. }
  2516. }));
  2517. action.setToggleAction(true);
  2518. action.setSelectedCallback(mxUtils.bind(this, function() { return this.commentsWindow != null && this.commentsWindow.window.isVisible(); }));
  2519. // Destroys comments window to force update or disable if not supported
  2520. editorUi.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  2521. {
  2522. if (this.commentsWindow != null)
  2523. {
  2524. this.commentsWindow.destroy();
  2525. this.commentsWindow = null;
  2526. }
  2527. }));
  2528. // Extends toolbar dropdown to add comments
  2529. var viewPanelsMenu = this.get('viewPanels');
  2530. var viewPanelsFunct = viewPanelsMenu.funct;
  2531. viewPanelsMenu.funct = function(menu, parent)
  2532. {
  2533. viewPanelsFunct.apply(this, arguments);
  2534. if (editorUi.commentsSupported())
  2535. {
  2536. editorUi.menus.addMenuItems(menu, ['comments'], parent);
  2537. }
  2538. };
  2539. // Overrides view menu to add search and scratchpad
  2540. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  2541. {
  2542. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  2543. concat(['outline', 'layers']).concat((editorUi.commentsSupported()) ?
  2544. ['comments', '-'] : ['-']));
  2545. this.addMenuItems(menu, ['-', 'search'], parent);
  2546. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  2547. {
  2548. var item = this.addMenuItem(menu, 'scratchpad', parent);
  2549. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2550. {
  2551. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000042367');
  2552. }
  2553. }
  2554. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
  2555. 'scrollbars', 'tooltips', '-',
  2556. 'grid', 'guides'], parent);
  2557. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  2558. {
  2559. this.addMenuItem(menu, 'shadowVisible', parent);
  2560. }
  2561. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  2562. 'resetView', 'zoomIn', 'zoomOut'], parent);
  2563. })));
  2564. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  2565. {
  2566. if (urlParams['embed'] != '1')
  2567. {
  2568. this.addSubmenu('theme', menu, parent);
  2569. menu.addSeparator(parent);
  2570. }
  2571. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  2572. if (typeof(MathJax) !== 'undefined')
  2573. {
  2574. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  2575. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2576. {
  2577. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  2578. }
  2579. }
  2580. if (urlParams['embed'] != '1')
  2581. {
  2582. this.addMenuItems(menu, ['autosave'], parent);
  2583. }
  2584. this.addMenuItems(menu, ['-', 'createShape', 'editDiagram'], parent);
  2585. menu.addSeparator(parent);
  2586. if (urlParams['embed'] != '1' && (isLocalStorage || mxClient.IS_CHROMEAPP))
  2587. {
  2588. this.addMenuItems(menu, ['showStartScreen'], parent);
  2589. }
  2590. if (!editorUi.isOfflineApp() && isLocalStorage)
  2591. {
  2592. this.addMenuItem(menu, 'plugins', parent);
  2593. }
  2594. menu.addSeparator(parent);
  2595. this.addMenuItem(menu, 'tags', parent);
  2596. // Adds trailing separator in case new plugin entries are added
  2597. menu.addSeparator(parent);
  2598. if (urlParams['newTempDlg'] == '1')
  2599. {
  2600. editorUi.actions.addAction('templates', function()
  2601. {
  2602. var tempDlg = new TemplatesDialog();
  2603. editorUi.showDialog(tempDlg.container, tempDlg.width, tempDlg.height, true, false, null, false, true);
  2604. tempDlg.init(editorUi, function(xml){console.log(xml)}, null,
  2605. null, null, "user", function(callback, username)
  2606. {
  2607. setTimeout(function(){
  2608. username? callback([
  2609. {url: '123', title: 'Test 1Test 1Test 1Test 1Test 1Test 1Test 11Test 1Test 11Test 1Test 1dgdsgdfg fdg dfgdfg dfg dfg'},
  2610. {url: '123', title: 'Test 2', imgUrl: 'https://www.google.com.eg/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
  2611. {url: '123', title: 'Test 3', changedBy: 'Ashraf Teleb', lastModifiedOn: 'Yesterday'},
  2612. {url: '123', title: 'Test 4'},
  2613. {url: '123', title: 'Test 5'},
  2614. {url: '123', title: 'Test 6'}
  2615. ]) : callback([
  2616. {url: '123', title: 'Test 4', imgUrl: 'https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg'},
  2617. {url: '123', title: 'Test 5'},
  2618. {url: '123', title: 'Test 6'},
  2619. {url: '123', title: 'Test 1Test 1Test 1Test 1Test 1Test 1Test 11Test 1Test 11Test 1Test 1dgdsgdfg fdg dfgdfg dfg dfg'},
  2620. {url: '123', title: 'Test 2', imgUrl: 'https://www.google.com.eg/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
  2621. {url: '123', title: 'Test 3', changedBy: 'Ashraf Teleb', lastModifiedOn: 'Yesterday'}
  2622. ]);
  2623. console.log(username);
  2624. }, 1000);
  2625. }, function(str, callback, username)
  2626. {
  2627. setTimeout(function(){
  2628. callback(username? [
  2629. {url: '123', title: str +'Test 1Test 1Test 1Test 1Test 1Test 1Test 1'},
  2630. {url: '123', title: str +'Test 2'},
  2631. {url: '123', title: str +'Test 3'},
  2632. {url: '123', title: str +'Test 4'},
  2633. {url: '123', title: str +'Test 5'},
  2634. {url: '123', title: str +'Test 6'}
  2635. ]: [
  2636. {url: '123', title: str +'Test 5'},
  2637. {url: '123', title: str +'Test 6'},
  2638. {url: '123', title: str +'Test 1Test 1Test 1Test 1Test 1Test 1Test 1'},
  2639. {url: '123', title: str +'Test 2'},
  2640. {url: '123', title: str +'Test 3'},
  2641. {url: '123', title: str +'Test 4'}
  2642. ]);
  2643. }, 2000);
  2644. }, null);
  2645. });
  2646. this.addMenuItem(menu, 'templates', parent);
  2647. }
  2648. })));
  2649. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  2650. {
  2651. if (urlParams['embed'] == '1')
  2652. {
  2653. this.addSubmenu('importFrom', menu, parent);
  2654. this.addSubmenu('exportAs', menu, parent);
  2655. this.addSubmenu('embed', menu, parent);
  2656. if (urlParams['libraries'] == '1')
  2657. {
  2658. this.addMenuItems(menu, ['-'], parent);
  2659. this.addSubmenu('newLibrary', menu, parent);
  2660. this.addSubmenu('openLibraryFrom', menu, parent);
  2661. }
  2662. if (editorUi.isRevisionHistorySupported())
  2663. {
  2664. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  2665. }
  2666. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'rename', 'save'], parent);
  2667. if (urlParams['saveAndExit'] == '1')
  2668. {
  2669. this.addMenuItems(menu, ['saveAndExit'], parent);
  2670. }
  2671. this.addMenuItems(menu, ['exit'], parent);
  2672. }
  2673. else
  2674. {
  2675. var file = this.editorUi.getCurrentFile();
  2676. if (file != null && file.constructor == DriveFile)
  2677. {
  2678. if (file.isRestricted())
  2679. {
  2680. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  2681. }
  2682. this.addMenuItems(menu, ['save', '-', 'share'], parent);
  2683. var item = this.addMenuItem(menu, 'synchronize', parent);
  2684. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2685. {
  2686. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000087947');
  2687. }
  2688. menu.addSeparator(parent);
  2689. }
  2690. else
  2691. {
  2692. this.addMenuItems(menu, ['new'], parent);
  2693. }
  2694. this.addSubmenu('openFrom', menu, parent);
  2695. if (isLocalStorage)
  2696. {
  2697. this.addSubmenu('openRecent', menu, parent);
  2698. }
  2699. if (file != null && file.constructor == DriveFile)
  2700. {
  2701. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  2702. }
  2703. else
  2704. {
  2705. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  2706. file != null && file.constructor != LocalFile)
  2707. {
  2708. menu.addSeparator(parent);
  2709. var item = this.addMenuItem(menu, 'synchronize', parent);
  2710. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2711. {
  2712. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000087947');
  2713. }
  2714. }
  2715. this.addMenuItems(menu, ['-', 'save', 'saveAs'], parent);
  2716. this.addMenuItems(menu, ['-', 'rename'], parent);
  2717. if (editorUi.isOfflineApp())
  2718. {
  2719. if (navigator.onLine && urlParams['stealth'] != '1')
  2720. {
  2721. this.addMenuItems(menu, ['upload'], parent);
  2722. }
  2723. }
  2724. else
  2725. {
  2726. this.addMenuItems(menu, ['makeCopy'], parent);
  2727. if (file != null && file.constructor == OneDriveFile)
  2728. {
  2729. this.addMenuItems(menu, ['moveToFolder'], parent);
  2730. }
  2731. }
  2732. }
  2733. menu.addSeparator(parent);
  2734. this.addSubmenu('importFrom', menu, parent);
  2735. this.addSubmenu('exportAs', menu, parent);
  2736. menu.addSeparator(parent);
  2737. this.addSubmenu('embed', menu, parent);
  2738. this.addSubmenu('publish', menu, parent);
  2739. menu.addSeparator(parent);
  2740. this.addSubmenu('newLibrary', menu, parent);
  2741. this.addSubmenu('openLibraryFrom', menu, parent);
  2742. if (editorUi.isRevisionHistorySupported())
  2743. {
  2744. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  2745. }
  2746. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  2747. // Cannot use print in standalone mode on iOS as we cannot open new windows
  2748. if (!mxClient.IS_IOS || !navigator.standalone)
  2749. {
  2750. this.addMenuItems(menu, ['print'], parent);
  2751. }
  2752. this.addMenuItems(menu, ['-', 'close']);
  2753. }
  2754. })));
  2755. };
  2756. })();