Menus.js 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980
  1. /**
  2. * Copyright (c) 2006-2020, JGraph Ltd
  3. * Copyright (c) 2006-2020, draw.io AG
  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 == 'app.diagrams.net') &&
  62. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' && urlParams['od'] == '1')) &&
  63. !mxClient.IS_IOS && (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10));
  64. var trelloEnabled = ((urlParams['embed'] != '1' && urlParams['tr'] != '0') || (urlParams['embed'] == '1' && urlParams['tr'] == '1')) &&
  65. mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
  66. if (!mxClient.IS_SVG && !editorUi.isOffline())
  67. {
  68. var img = new Image();
  69. img.src = IMAGE_PATH + '/help.png';
  70. }
  71. editorUi.actions.addAction('new...', function()
  72. {
  73. var compact = editorUi.isOffline();
  74. var dlg = new NewDialog(editorUi, compact, !(editorUi.mode == App.MODE_DEVICE && 'chooseFileSystemEntries' in window));
  75. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
  76. {
  77. if (cancel && editorUi.getCurrentFile() == null)
  78. {
  79. editorUi.showSplash();
  80. }
  81. });
  82. dlg.init();
  83. });
  84. editorUi.actions.put('insertTemplate', new Action(mxResources.get('template') + '...', function()
  85. {
  86. var dlg = new NewDialog(editorUi, null, false, function(xml)
  87. {
  88. editorUi.hideDialog();
  89. if (xml != null)
  90. {
  91. var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
  92. graph.setSelectionCells(editorUi.importXml(xml,
  93. Math.max(insertPoint.x, 20),
  94. Math.max(insertPoint.y, 20), true));
  95. graph.scrollCellToVisible(graph.getSelectionCell());
  96. }
  97. }, null, null, null, null, null, null, null, null, null, null,
  98. false, mxResources.get('insert'));
  99. editorUi.showDialog(dlg.container, 620, 440, true, true);
  100. })).isEnabled = isGraphEnabled;
  101. var pointAction = editorUi.actions.addAction('points', function()
  102. {
  103. editorUi.editor.graph.view.setUnit(mxConstants.POINTS);
  104. });
  105. pointAction.setToggleAction(true);
  106. pointAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.POINTS; });
  107. var inchAction = editorUi.actions.addAction('inches', function()
  108. {
  109. editorUi.editor.graph.view.setUnit(mxConstants.INCHES);
  110. });
  111. inchAction.setToggleAction(true);
  112. inchAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.INCHES; });
  113. var mmAction = editorUi.actions.addAction('millimeters', function()
  114. {
  115. editorUi.editor.graph.view.setUnit(mxConstants.MILLIMETERS);
  116. });
  117. mmAction.setToggleAction(true);
  118. mmAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.MILLIMETERS; });
  119. this.put('units', new Menu(mxUtils.bind(this, function(menu, parent)
  120. {
  121. this.addMenuItems(menu, ['points', /*'inches',*/ 'millimeters'], parent);
  122. })));
  123. var rulerAction = editorUi.actions.addAction('ruler', function()
  124. {
  125. mxSettings.setRulerOn(!mxSettings.isRulerOn());
  126. mxSettings.save();
  127. if (editorUi.ruler != null)
  128. {
  129. editorUi.ruler.destroy();
  130. editorUi.ruler = null;
  131. editorUi.refresh();
  132. }
  133. else
  134. {
  135. editorUi.ruler = new mxDualRuler(editorUi, editorUi.editor.graph.view.unit);
  136. editorUi.refresh();
  137. }
  138. });
  139. rulerAction.setEnabled(editorUi.canvasSupported && document.documentMode != 9);
  140. rulerAction.setToggleAction(true);
  141. rulerAction.setSelectedCallback(function() { return editorUi.ruler != null; });
  142. editorUi.actions.addAction('properties...', function()
  143. {
  144. var dlg = new FilePropertiesDialog(editorUi);
  145. editorUi.showDialog(dlg.container, 320, 120, true, true);
  146. dlg.init();
  147. }).isEnabled = isGraphEnabled;
  148. if (window.mxFreehand)
  149. {
  150. editorUi.actions.put('insertFreehand', new Action(mxResources.get('freehand') + '...', function(evt)
  151. {
  152. if (graph.isEnabled())
  153. {
  154. if (this.freehandWindow == null)
  155. {
  156. this.freehandWindow = new FreehandWindow(editorUi, document.body.offsetWidth - 420, 102, 176, 104);
  157. }
  158. if (graph.freehand.isDrawing())
  159. {
  160. graph.freehand.stopDrawing();
  161. }
  162. else
  163. {
  164. graph.freehand.startDrawing();
  165. }
  166. this.freehandWindow.window.setVisible(graph.freehand.isDrawing());
  167. }
  168. })).isEnabled = function()
  169. {
  170. return isGraphEnabled() && mxClient.IS_SVG;
  171. };
  172. }
  173. editorUi.actions.put('exportXml', new Action(mxResources.get('formatXml') + '...', function()
  174. {
  175. var div = document.createElement('div');
  176. div.style.whiteSpace = 'nowrap';
  177. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  178. var hd = document.createElement('h3');
  179. mxUtils.write(hd, mxResources.get('formatXml'));
  180. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  181. div.appendChild(hd);
  182. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  183. false, graph.isSelectionEmpty());
  184. var compressed = editorUi.addCheckbox(div, mxResources.get('compressed'), true);
  185. var pages = editorUi.addCheckbox(div, mxResources.get('allPages'), !noPages, noPages);
  186. pages.style.marginBottom = '16px';
  187. mxEvent.addListener(selection, 'change', function()
  188. {
  189. if (selection.checked)
  190. {
  191. pages.setAttribute('disabled', 'disabled');
  192. }
  193. else
  194. {
  195. pages.removeAttribute('disabled');
  196. }
  197. });
  198. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  199. {
  200. editorUi.downloadFile('xml', !compressed.checked, null,
  201. !selection.checked, noPages || !pages.checked);
  202. }), null, mxResources.get('export'));
  203. editorUi.showDialog(dlg.container, 300, 180, true, true);
  204. }));
  205. editorUi.actions.put('exportUrl', new Action(mxResources.get('url') + '...', function()
  206. {
  207. editorUi.showPublishLinkDialog(mxResources.get('url'), true, null, null,
  208. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  209. {
  210. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  211. linkColor, allPages, lightbox, editLink, layers, null, true));
  212. editorUi.showDialog(dlg.container, 440, 240, true, true);
  213. dlg.init();
  214. });
  215. }));
  216. editorUi.actions.put('exportHtml', new Action(mxResources.get('formatHtmlEmbedded') + '...', function()
  217. {
  218. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  219. {
  220. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  221. {
  222. editorUi.spinner.stop();
  223. editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
  224. initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  225. {
  226. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  227. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  228. {
  229. var basename = editorUi.getBaseFilename(allPages);
  230. var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
  231. '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
  232. '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
  233. editorUi.saveData(basename + '.html', 'html', result, 'text/html');
  234. }));
  235. });
  236. });
  237. }
  238. }));
  239. editorUi.actions.put('exportPdf', new Action(mxResources.get('formatPdf') + '...', function()
  240. {
  241. if (!EditorUi.isElectronApp && (editorUi.isOffline() || editorUi.printPdfExport))
  242. {
  243. // Export PDF action for chrome OS (same as print with different dialog title)
  244. editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 360,
  245. (editorUi.pages != null && editorUi.pages.length > 1 && (editorUi.editor.editable ||
  246. urlParams['hide-pages'] != '1')) ?
  247. 450 : 370, true, true);
  248. }
  249. else
  250. {
  251. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  252. var div = document.createElement('div');
  253. div.style.whiteSpace = 'nowrap';
  254. var hd = document.createElement('h3');
  255. mxUtils.write(hd, mxResources.get('formatPdf'));
  256. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  257. div.appendChild(hd);
  258. var cropEnableFn = function()
  259. {
  260. if (allPages != this && this.checked)
  261. {
  262. crop.removeAttribute('disabled');
  263. crop.checked = !graph.pageVisible;
  264. }
  265. else
  266. {
  267. crop.setAttribute('disabled', 'disabled');
  268. crop.checked = false;
  269. }
  270. };
  271. var dlgH = 180;
  272. if (editorUi.pdfPageExport && !noPages)
  273. {
  274. var allPages = editorUi.addRadiobox(div, 'pages', mxResources.get('allPages'), true);
  275. var currentPage = editorUi.addRadiobox(div, 'pages', mxResources.get('currentPage'), false);
  276. var selection = editorUi.addRadiobox(div, 'pages', mxResources.get('selectionOnly'), false, graph.isSelectionEmpty());
  277. var crop = editorUi.addCheckbox(div, mxResources.get('crop'), false, true);
  278. var grid = editorUi.addCheckbox(div, mxResources.get('grid'), false, false);
  279. mxEvent.addListener(allPages, 'change', cropEnableFn);
  280. mxEvent.addListener(currentPage, 'change', cropEnableFn);
  281. mxEvent.addListener(selection, 'change', cropEnableFn);
  282. dlgH += 60;
  283. }
  284. else
  285. {
  286. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  287. false, graph.isSelectionEmpty());
  288. var crop = editorUi.addCheckbox(div, mxResources.get('crop'),
  289. !graph.pageVisible || !editorUi.pdfPageExport,
  290. !editorUi.pdfPageExport);
  291. var grid = editorUi.addCheckbox(div, mxResources.get('grid'), false, false);
  292. // Crop is only enabled if selection only is selected
  293. if (!editorUi.pdfPageExport)
  294. {
  295. mxEvent.addListener(selection, 'change', cropEnableFn);
  296. }
  297. }
  298. var isDrawioWeb = !mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  299. editorUi.getServiceName() == 'draw.io';
  300. var transparentBkg = null, include = null;
  301. if (isDrawioWeb)
  302. {
  303. include = editorUi.addCheckbox(div,
  304. mxResources.get('includeCopyOfMyDiagram'), true);
  305. transparentBkg = editorUi.addCheckbox(div,
  306. mxResources.get('transparentBackground'), false);
  307. dlgH += 60;
  308. }
  309. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  310. {
  311. editorUi.downloadFile('pdf', null, null, !selection.checked,
  312. noPages? true : !allPages.checked, !crop.checked, transparentBkg != null && transparentBkg.checked, null,
  313. null, grid.checked, include != null && include.checked);
  314. }), null, mxResources.get('export'));
  315. editorUi.showDialog(dlg.container, 300, dlgH, true, true);
  316. }
  317. }));
  318. editorUi.actions.addAction('open...', function()
  319. {
  320. editorUi.pickFile();
  321. });
  322. editorUi.actions.addAction('close', function()
  323. {
  324. var currentFile = editorUi.getCurrentFile();
  325. function fn()
  326. {
  327. if (currentFile != null)
  328. {
  329. currentFile.removeDraft();
  330. }
  331. editorUi.fileLoaded(null);
  332. };
  333. if (currentFile != null && currentFile.isModified())
  334. {
  335. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  336. mxResources.get('cancel'), mxResources.get('discardChanges'));
  337. }
  338. else
  339. {
  340. fn();
  341. }
  342. });
  343. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  344. {
  345. var cells = graph.getSelectionCells();
  346. if (graph.getSelectionCount() == 1)
  347. {
  348. var cell = graph.getSelectionCell();
  349. var state = graph.view.getState(cell);
  350. if (state != null && state.shape != null && state.shape.stencil != null)
  351. {
  352. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  353. editorUi.showDialog(dlg.container, 640, 480, true, false);
  354. dlg.init();
  355. }
  356. }
  357. }));
  358. editorUi.actions.addAction('revisionHistory...', function()
  359. {
  360. if (!editorUi.isRevisionHistorySupported())
  361. {
  362. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  363. }
  364. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  365. {
  366. editorUi.getRevisions(mxUtils.bind(this, function(revs, restoreFn)
  367. {
  368. editorUi.spinner.stop();
  369. var dlg = new RevisionDialog(editorUi, revs, restoreFn);
  370. editorUi.showDialog(dlg.container, 640, 480, true, true);
  371. dlg.init();
  372. }), mxUtils.bind(this, function(err)
  373. {
  374. editorUi.handleError(err);
  375. }));
  376. }
  377. });
  378. editorUi.actions.addAction('createRevision', function()
  379. {
  380. editorUi.actions.get('save').funct();
  381. }, null, null, Editor.ctrlKey + '+S');
  382. var action = editorUi.actions.addAction('synchronize', function()
  383. {
  384. editorUi.synchronizeCurrentFile(DrawioFile.SYNC == 'none');
  385. }, null, null, 'Alt+Shift+S');
  386. // Changes the label if synchronization is disabled
  387. if (DrawioFile.SYNC == 'none')
  388. {
  389. action.label = mxResources.get('refresh');
  390. }
  391. editorUi.actions.addAction('upload...', function()
  392. {
  393. var file = editorUi.getCurrentFile();
  394. if (file != null)
  395. {
  396. // Data is pulled from global variable after tab loads
  397. // LATER: Change to use message passing to deal with potential cross-domain
  398. window.drawdata = editorUi.getFileData();
  399. var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  400. editorUi.openLink(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
  401. ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
  402. 'title=' + encodeURIComponent(filename), null, true);
  403. }
  404. });
  405. if (typeof(MathJax) !== 'undefined')
  406. {
  407. var action = editorUi.actions.addAction('mathematicalTypesetting', function()
  408. {
  409. var change = new ChangePageSetup(editorUi);
  410. change.ignoreColor = true;
  411. change.ignoreImage = true;
  412. change.mathEnabled = !editorUi.isMathEnabled();
  413. graph.model.execute(change);
  414. });
  415. action.setToggleAction(true);
  416. action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
  417. action.isEnabled = isGraphEnabled;
  418. }
  419. if (isLocalStorage)
  420. {
  421. var action = editorUi.actions.addAction('showStartScreen', function()
  422. {
  423. mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
  424. mxSettings.save();
  425. });
  426. action.setToggleAction(true);
  427. action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
  428. }
  429. var autosaveAction = editorUi.actions.addAction('autosave', function()
  430. {
  431. editorUi.editor.setAutosave(!editorUi.editor.autosave);
  432. });
  433. autosaveAction.setToggleAction(true);
  434. autosaveAction.setSelectedCallback(function()
  435. {
  436. return autosaveAction.isEnabled() && editorUi.editor.autosave;
  437. });
  438. editorUi.actions.addAction('editGeometry...', function()
  439. {
  440. var cells = graph.getSelectionCells();
  441. var vertices = [];
  442. for (var i = 0; i < cells.length; i++)
  443. {
  444. if (graph.getModel().isVertex(cells[i]))
  445. {
  446. vertices.push(cells[i]);
  447. }
  448. }
  449. if (vertices.length > 0)
  450. {
  451. var dlg = new EditGeometryDialog(editorUi, vertices);
  452. editorUi.showDialog(dlg.container, 200, 270, true, true);
  453. dlg.init();
  454. }
  455. }, null, null, Editor.ctrlKey + '+Shift+M');
  456. var currentStyle = null;
  457. editorUi.actions.addAction('copyStyle', function()
  458. {
  459. if (graph.isEnabled() && !graph.isSelectionEmpty())
  460. {
  461. currentStyle = graph.copyStyle(graph.getSelectionCell())
  462. }
  463. }, null, null, Editor.ctrlKey + '+Shift+C');
  464. editorUi.actions.addAction('pasteStyle', function()
  465. {
  466. if (graph.isEnabled() && !graph.isSelectionEmpty() && currentStyle != null)
  467. {
  468. graph.pasteStyle(currentStyle, graph.getSelectionCells())
  469. }
  470. }, null, null, Editor.ctrlKey + '+Shift+V');
  471. editorUi.actions.put('pageBackgroundImage', new Action(mxResources.get('backgroundImage') + '...', function()
  472. {
  473. if (!editorUi.isOffline())
  474. {
  475. var apply = function(image)
  476. {
  477. editorUi.setBackgroundImage(image);
  478. };
  479. var dlg = new BackgroundImageDialog(editorUi, apply);
  480. editorUi.showDialog(dlg.container, 320, 170, true, true);
  481. dlg.init();
  482. }
  483. }));
  484. editorUi.actions.put('exportSvg', new Action(mxResources.get('formatSvg') + '...', function()
  485. {
  486. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  487. 'https://desk.draw.io/support/solutions/articles/16000067785',
  488. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow,
  489. editable, embedImages, border, cropImage, currentPage, linkTarget, grid, keepTheme)
  490. {
  491. var val = parseInt(scale);
  492. if (!isNaN(val) && val > 0)
  493. {
  494. editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection, addShadow,
  495. editable, embedImages, border, !cropImage, currentPage, linkTarget, keepTheme);
  496. }
  497. }), true, null, 'svg');
  498. }));
  499. editorUi.actions.put('exportPng', new Action(mxResources.get('formatPng') + '...', function()
  500. {
  501. if (editorUi.isExportToCanvas())
  502. {
  503. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  504. 'https://desk.draw.io/support/solutions/articles/16000067785',
  505. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow,
  506. editable, embedImages, border, cropImage, currentPage, dummy, grid, keepTheme)
  507. {
  508. var val = parseInt(scale);
  509. if (!isNaN(val) && val > 0)
  510. {
  511. editorUi.exportImage(val / 100, transparentBackground, ignoreSelection, addShadow,
  512. editable, border, !cropImage, currentPage, null, grid, null, keepTheme);
  513. }
  514. }), true, true, 'png');
  515. }
  516. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  517. {
  518. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable, transparent, scale, border)
  519. {
  520. editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection, null, null, transparent, scale, border);
  521. }), false, true);
  522. }
  523. }));
  524. editorUi.actions.put('exportJpg', new Action(mxResources.get('formatJpg') + '...', function()
  525. {
  526. if (editorUi.isExportToCanvas())
  527. {
  528. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  529. 'https://desk.draw.io/support/solutions/articles/16000067785',
  530. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow,
  531. editable, embedImages, border, cropImage, currentPage, dummy, grid, keepTheme)
  532. {
  533. var val = parseInt(scale);
  534. if (!isNaN(val) && val > 0)
  535. {
  536. editorUi.exportImage(val / 100, false, ignoreSelection, addShadow,
  537. false, border, !cropImage, false, 'jpeg', grid, null, keepTheme);
  538. }
  539. }), true, false, 'jpeg');
  540. }
  541. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  542. {
  543. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable, tranaparent, scale, border)
  544. {
  545. editorUi.downloadFile('jpeg', null, null, ignoreSelection, null, null, null, scale, border);
  546. }), true, true);
  547. }
  548. }));
  549. action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
  550. {
  551. graph.setShadowVisible(!graph.shadowVisible);
  552. }));
  553. action.setToggleAction(true);
  554. action.setSelectedCallback(function() { return graph.shadowVisible; });
  555. var showingAbout = false;
  556. editorUi.actions.put('about', new Action(mxResources.get('about') + ' ' + EditorUi.VERSION + '...', function()
  557. {
  558. if (editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  559. {
  560. editorUi.alert(editorUi.editor.appName + ' ' + EditorUi.VERSION);
  561. }
  562. else
  563. {
  564. editorUi.openLink('https://www.diagrams.net/');
  565. }
  566. }));
  567. editorUi.actions.addAction('support...', function()
  568. {
  569. editorUi.openLink('https://github.com/jgraph/drawio/wiki/Getting-Support');
  570. });
  571. editorUi.actions.addAction('exportOptionsDisabled...', function()
  572. {
  573. editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
  574. mxResources.get('exportOptionsDisabled'));
  575. });
  576. editorUi.actions.addAction('keyboardShortcuts...', function()
  577. {
  578. if (mxClient.IS_SVG && !mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  579. {
  580. editorUi.openLink('shortcuts.svg');
  581. }
  582. else
  583. {
  584. editorUi.openLink('https://viewer.diagrams.net/#Uhttps%3A%2F%2Fviewer.diagrams.net%2Fshortcuts.svg');
  585. }
  586. });
  587. editorUi.actions.addAction('feedback...', function()
  588. {
  589. var dlg = new FeedbackDialog(editorUi);
  590. editorUi.showDialog(dlg.container, 610, 360, true, false);
  591. dlg.init();
  592. });
  593. editorUi.actions.addAction('quickStart...', function()
  594. {
  595. editorUi.openLink('https://www.youtube.com/watch?v=Z0D96ZikMkc');
  596. });
  597. editorUi.actions.addAction('forkme', function()
  598. {
  599. editorUi.openLink('https://github.com/jgraph/drawio');
  600. }).label = 'Fork me on GitHub...';
  601. editorUi.actions.addAction('downloadDesktop...', function()
  602. {
  603. editorUi.openLink('https://get.diagrams.net/');
  604. });
  605. action = editorUi.actions.addAction('tags...', mxUtils.bind(this, function()
  606. {
  607. if (this.tagsWindow == null)
  608. {
  609. this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 380, 230, 300, 120);
  610. this.tagsWindow.window.addListener('show', function()
  611. {
  612. editorUi.fireEvent(new mxEventObject('tags'));
  613. });
  614. this.tagsWindow.window.addListener('hide', function()
  615. {
  616. editorUi.fireEvent(new mxEventObject('tags'));
  617. });
  618. this.tagsWindow.window.setVisible(true);
  619. editorUi.fireEvent(new mxEventObject('tags'));
  620. }
  621. else
  622. {
  623. this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
  624. }
  625. }));
  626. action.setToggleAction(true);
  627. action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
  628. action = editorUi.actions.addAction('find...', mxUtils.bind(this, function()
  629. {
  630. if (this.findWindow == null)
  631. {
  632. this.findWindow = new FindWindow(editorUi, document.body.offsetWidth - 300, 110, 240, 155);
  633. this.findWindow.window.addListener('show', function()
  634. {
  635. editorUi.fireEvent(new mxEventObject('find'));
  636. });
  637. this.findWindow.window.addListener('hide', function()
  638. {
  639. editorUi.fireEvent(new mxEventObject('find'));
  640. });
  641. this.findWindow.window.setVisible(true);
  642. editorUi.fireEvent(new mxEventObject('find'));
  643. }
  644. else
  645. {
  646. this.findWindow.window.setVisible(!this.findWindow.window.isVisible());
  647. }
  648. }));
  649. action.setToggleAction(true);
  650. action.setSelectedCallback(mxUtils.bind(this, function() { return this.findWindow != null && this.findWindow.window.isVisible(); }));
  651. editorUi.actions.put('exportVsdx', new Action(mxResources.get('formatVsdx') + ' (beta)...', function()
  652. {
  653. editorUi.exportVisio();
  654. }));
  655. if (isLocalStorage && localStorage != null && urlParams['embed'] != '1')
  656. {
  657. editorUi.actions.addAction('configuration...', function()
  658. {
  659. // Add help, link button
  660. var value = localStorage.getItem('.configuration');
  661. var dlg = new TextareaDialog(editorUi, mxResources.get('configuration') + ':',
  662. (value != null) ? JSON.stringify(JSON.parse(value), null, 2) : '', function(newValue)
  663. {
  664. if (newValue != null)
  665. {
  666. try
  667. {
  668. if (newValue.length > 0)
  669. {
  670. var obj = JSON.parse(newValue);
  671. localStorage.setItem('.configuration', JSON.stringify(obj));
  672. }
  673. else
  674. {
  675. localStorage.removeItem('.configuration');
  676. }
  677. editorUi.hideDialog();
  678. editorUi.alert(mxResources.get('restartForChangeRequired'));
  679. }
  680. catch (e)
  681. {
  682. editorUi.handleError(e);
  683. }
  684. }
  685. }, null, null, null, null, null, true, null, null,
  686. 'https://desk.draw.io/support/solutions/articles/16000058316',
  687. (EditorUi.isElectronApp) ? null : [[mxResources.get('reset'), function(evt, input)
  688. {
  689. editorUi.confirm(mxResources.get('areYouSure'), function()
  690. {
  691. try
  692. {
  693. localStorage.removeItem('.configuration');
  694. localStorage.removeItem('.drawio-config');
  695. localStorage.removeItem('.mode');
  696. editorUi.hideDialog();
  697. editorUi.alert(mxResources.get('restartForChangeRequired'));
  698. }
  699. catch (e)
  700. {
  701. editorUi.handleError(e);
  702. }
  703. });
  704. }], [mxResources.get('link'), function(evt, input)
  705. {
  706. if (input.value.length > 0)
  707. {
  708. try
  709. {
  710. var obj = JSON.parse(input.value);
  711. var url = window.location.protocol + '//' + window.location.host +
  712. '/' + editorUi.getSearch() + '#_CONFIG_' +
  713. Graph.compress(JSON.stringify(obj));
  714. var dlg = new EmbedDialog(editorUi, url);
  715. editorUi.showDialog(dlg.container, 440, 240, true);
  716. dlg.init();
  717. }
  718. catch (e)
  719. {
  720. editorUi.handleError(e);
  721. }
  722. }
  723. else
  724. {
  725. editorUi.handleError({message: mxResources.get('invalidInput')});
  726. }
  727. }]]);
  728. dlg.textarea.style.width = '600px';
  729. dlg.textarea.style.height = '380px';
  730. editorUi.showDialog(dlg.container, 620, 460, true, false);
  731. dlg.init();
  732. });
  733. }
  734. // Adds language menu to options only if localStorage is available for
  735. // storing the choice. We do not want to use cookies for older browsers.
  736. // Note that the URL param lang=XX is available for setting the language
  737. // in older browsers. URL param has precedence over the saved setting.
  738. if (mxClient.IS_CHROMEAPP || isLocalStorage)
  739. {
  740. this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
  741. {
  742. var addLangItem = mxUtils.bind(this, function (id)
  743. {
  744. var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
  745. var item = null;
  746. if (lang != '')
  747. {
  748. item = menu.addItem(lang, null, mxUtils.bind(this, function()
  749. {
  750. mxSettings.setLanguage(id);
  751. mxSettings.save();
  752. // Shows dialog in new language
  753. mxClient.language = id;
  754. mxResources.loadDefaultBundle = false;
  755. mxResources.add(RESOURCE_BASE);
  756. editorUi.alert(mxResources.get('restartForChangeRequired'));
  757. }), parent);
  758. if (id == mxLanguage || (id == '' && mxLanguage == null))
  759. {
  760. menu.addCheckmark(item, Editor.checkmarkImage);
  761. }
  762. }
  763. return item;
  764. });
  765. var item = addLangItem('');
  766. menu.addSeparator(parent);
  767. // LATER: Sort menu by language name
  768. for(var langId in mxLanguageMap)
  769. {
  770. addLangItem(langId);
  771. }
  772. })));
  773. // Extends the menubar with the language menu
  774. var menusCreateMenuBar = Menus.prototype.createMenubar;
  775. Menus.prototype.createMenubar = function(container)
  776. {
  777. var menubar = menusCreateMenuBar.apply(this, arguments);
  778. if (menubar != null)
  779. {
  780. var langMenu = this.get('language');
  781. if (langMenu != null)
  782. {
  783. var elt = menubar.addMenu('', langMenu.funct);
  784. elt.setAttribute('title', mxResources.get('language'));
  785. elt.style.width = '16px';
  786. elt.style.paddingTop = '2px';
  787. elt.style.paddingLeft = '4px';
  788. elt.style.zIndex = '1';
  789. elt.style.position = 'absolute';
  790. elt.style.display = 'block';
  791. elt.style.cursor = 'pointer';
  792. elt.style.right = '17px';
  793. if (uiTheme == 'atlas')
  794. {
  795. elt.style.top = '6px';
  796. elt.style.right = '15px';
  797. }
  798. else if (uiTheme == 'min')
  799. {
  800. elt.style.top = '2px';
  801. }
  802. else
  803. {
  804. elt.style.top = '0px';
  805. }
  806. if (!mxClient.IS_VML)
  807. {
  808. var icon = document.createElement('div');
  809. icon.style.backgroundImage = 'url(' + Editor.globeImage + ')';
  810. icon.style.backgroundPosition = 'center center';
  811. icon.style.backgroundRepeat = 'no-repeat';
  812. icon.style.backgroundSize = '19px 19px';
  813. icon.style.position = 'absolute';
  814. icon.style.height = '19px';
  815. icon.style.width = '19px';
  816. icon.style.marginTop = '2px';
  817. icon.style.zIndex = '1';
  818. elt.appendChild(icon);
  819. mxUtils.setOpacity(elt, 40);
  820. if (uiTheme == 'atlas' || uiTheme == 'dark')
  821. {
  822. elt.style.opacity = '0.85';
  823. elt.style.filter = 'invert(100%)';
  824. }
  825. }
  826. else
  827. {
  828. elt.innerHTML = '<div class="geIcon geSprite geSprite-globe"/>';
  829. }
  830. document.body.appendChild(elt);
  831. }
  832. }
  833. return menubar;
  834. };
  835. }
  836. editorUi.customLayoutConfig = [{'layout': 'mxHierarchicalLayout',
  837. 'config':
  838. {'orientation': 'west',
  839. 'intraCellSpacing': 30,
  840. 'interRankCellSpacing': 100,
  841. 'interHierarchySpacing': 60,
  842. 'parallelEdgeSpacing': 10}}];
  843. // Adds action
  844. editorUi.actions.addAction('runLayout', function()
  845. {
  846. var dlg = new TextareaDialog(editorUi, 'Run Layouts:',
  847. JSON.stringify(editorUi.customLayoutConfig, null, 2),
  848. function(newValue)
  849. {
  850. if (newValue.length > 0)
  851. {
  852. try
  853. {
  854. var layoutList = JSON.parse(newValue);
  855. editorUi.executeLayoutList(layoutList)
  856. editorUi.customLayoutConfig = layoutList;
  857. }
  858. catch (e)
  859. {
  860. editorUi.handleError(e);
  861. if (window.console != null)
  862. {
  863. console.error(e);
  864. }
  865. }
  866. }
  867. });
  868. dlg.textarea.style.width = '600px';
  869. dlg.textarea.style.height = '380px';
  870. editorUi.showDialog(dlg.container, 620, 460, true, true);
  871. dlg.init();
  872. });
  873. var layoutMenu = this.get('layout');
  874. var layoutMenuFunct = layoutMenu.funct;
  875. layoutMenu.funct = function(menu, parent)
  876. {
  877. layoutMenuFunct.apply(this, arguments);
  878. menu.addSeparator(parent);
  879. menu.addItem(mxResources.get('orgChart') + '...', null, function()
  880. {
  881. var branchOptimizer = null, parentChildSpacingVal = 20, siblingSpacingVal = 20, notExecuted = true;
  882. // Invoked when orgchart code was loaded
  883. var delayed = function()
  884. {
  885. editorUi.loadingOrgChart = false;
  886. editorUi.spinner.stop();
  887. if (typeof mxOrgChartLayout !== 'undefined' && branchOptimizer != null && notExecuted)
  888. {
  889. var graph = editorUi.editor.graph;
  890. var orgChartLayout = new mxOrgChartLayout(graph, branchOptimizer, parentChildSpacingVal, siblingSpacingVal);
  891. var cell = graph.getDefaultParent();
  892. if (graph.model.getChildCount(graph.getSelectionCell()) > 1)
  893. {
  894. cell = graph.getSelectionCell();
  895. }
  896. orgChartLayout.execute(cell);
  897. notExecuted = false;
  898. }
  899. };
  900. // Invoked from dialog
  901. function doLayout()
  902. {
  903. if (typeof mxOrgChartLayout === 'undefined' && !editorUi.loadingOrgChart && !editorUi.isOffline(true))
  904. {
  905. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  906. {
  907. editorUi.loadingOrgChart = true;
  908. if (urlParams['dev'] == '1')
  909. {
  910. mxscript('js/orgchart.min.js', delayed);
  911. }
  912. else
  913. {
  914. mxscript('js/extensions.min.js', delayed);
  915. }
  916. }
  917. }
  918. else
  919. {
  920. delayed();
  921. }
  922. };
  923. var div = document.createElement('div');
  924. var title = document.createElement('div');
  925. title.style.marginTop = '6px';
  926. title.style.display = 'inline-block';
  927. title.style.width = '140px';
  928. mxUtils.write(title, mxResources.get('orgChartType') + ': ');
  929. div.appendChild(title);
  930. var typeSelect = document.createElement('select');
  931. typeSelect.style.width = '200px';
  932. typeSelect.style.boxSizing = 'border-box';
  933. //Types are hardcoded here since the code is not loaded yet
  934. var typesArr = [mxResources.get('linear'),
  935. mxResources.get('hanger2'),
  936. mxResources.get('hanger4'),
  937. mxResources.get('fishbone1'),
  938. mxResources.get('fishbone2'),
  939. mxResources.get('1ColumnLeft'),
  940. mxResources.get('1ColumnRight'),
  941. mxResources.get('smart')
  942. ];
  943. for (var i = 0; i < typesArr.length; i++)
  944. {
  945. var option = document.createElement('option');
  946. mxUtils.write(option, typesArr[i]);
  947. option.value = i;
  948. if (i == 2)
  949. {
  950. option.setAttribute('selected', 'selected');
  951. }
  952. typeSelect.appendChild(option);
  953. }
  954. mxEvent.addListener(typeSelect, 'change', function()
  955. {
  956. branchOptimizer = typeSelect.value;
  957. });
  958. div.appendChild(typeSelect);
  959. title = document.createElement('div');
  960. title.style.marginTop = '6px';
  961. title.style.display = 'inline-block';
  962. title.style.width = '140px';
  963. mxUtils.write(title, mxResources.get('parentChildSpacing') + ': ');
  964. div.appendChild(title);
  965. var parentChildSpacing = document.createElement('input');
  966. parentChildSpacing.type = 'number';
  967. parentChildSpacing.value = parentChildSpacingVal;
  968. parentChildSpacing.style.width = '200px';
  969. parentChildSpacing.style.boxSizing = 'border-box';
  970. div.appendChild(parentChildSpacing);
  971. mxEvent.addListener(parentChildSpacing, 'change', function()
  972. {
  973. parentChildSpacingVal = parentChildSpacing.value;
  974. });
  975. title = document.createElement('div');
  976. title.style.marginTop = '6px';
  977. title.style.display = 'inline-block';
  978. title.style.width = '140px';
  979. mxUtils.write(title, mxResources.get('siblingSpacing') + ': ');
  980. div.appendChild(title);
  981. var siblingSpacing = document.createElement('input');
  982. siblingSpacing.type = 'number';
  983. siblingSpacing.value = siblingSpacingVal;
  984. siblingSpacing.style.width = '200px';
  985. siblingSpacing.style.boxSizing = 'border-box';
  986. div.appendChild(siblingSpacing);
  987. mxEvent.addListener(siblingSpacing, 'change', function()
  988. {
  989. siblingSpacingVal = siblingSpacing.value;
  990. });
  991. var dlg = new CustomDialog(editorUi, div, function()
  992. {
  993. if (branchOptimizer == null)
  994. {
  995. branchOptimizer = 2;
  996. }
  997. doLayout();
  998. });
  999. editorUi.showDialog(dlg.container, 355, 125, true, true);
  1000. }, parent, null, isGraphEnabled());
  1001. menu.addSeparator(parent);
  1002. editorUi.menus.addMenuItem(menu, 'runLayout', parent, null, null, mxResources.get('apply') + '...');
  1003. };
  1004. this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
  1005. {
  1006. if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
  1007. {
  1008. this.addMenuItems(menu, ['about'], parent);
  1009. }
  1010. else
  1011. {
  1012. // No translation for menu item since help is english only
  1013. var item = menu.addItem('Search:', null, null, parent, null, null, false);
  1014. item.style.backgroundColor = (uiTheme == 'dark') ? '#505759' : 'whiteSmoke';
  1015. item.style.cursor = 'default';
  1016. var input = document.createElement('input');
  1017. input.setAttribute('type', 'text');
  1018. input.setAttribute('size', '25');
  1019. input.style.marginLeft = '8px';
  1020. mxEvent.addListener(input, 'keydown', mxUtils.bind(this, function(e)
  1021. {
  1022. var term = mxUtils.trim(input.value);
  1023. if (e.keyCode == 13 && term.length > 0)
  1024. {
  1025. this.editorUi.openLink('https://desk.draw.io/support/search/solutions?term=' +
  1026. encodeURIComponent(term));
  1027. input.value = '';
  1028. EditorUi.logEvent({category: 'SEARCH-HELP', action: 'search', label: term});
  1029. if (this.editorUi.menubar != null)
  1030. {
  1031. window.setTimeout(mxUtils.bind(this, function()
  1032. {
  1033. this.editorUi.menubar.hideMenu();
  1034. }), 0);
  1035. }
  1036. }
  1037. else if (e.keyCode == 27)
  1038. {
  1039. input.value = '';
  1040. }
  1041. }));
  1042. item.firstChild.nextSibling.appendChild(input);
  1043. mxEvent.addGestureListeners(input, function(evt)
  1044. {
  1045. if (document.activeElement != input)
  1046. {
  1047. input.focus();
  1048. }
  1049. mxEvent.consume(evt);
  1050. }, function(evt)
  1051. {
  1052. mxEvent.consume(evt);
  1053. }, function(evt)
  1054. {
  1055. mxEvent.consume(evt);
  1056. });
  1057. window.setTimeout(function()
  1058. {
  1059. input.focus();
  1060. }, 0);
  1061. this.addMenuItems(menu, ['-', 'keyboardShortcuts', 'quickStart',
  1062. 'support', '-', 'forkme', 'downloadDesktop', '-', 'about'], parent);
  1063. }
  1064. if (urlParams['test'] == '1')
  1065. {
  1066. menu.addSeparator(parent);
  1067. this.addSubmenu('testDevelop', menu, parent);
  1068. }
  1069. })));
  1070. // Only visible in test mode
  1071. if (urlParams['test'] == '1')
  1072. {
  1073. mxResources.parse('testDevelop=Develop');
  1074. mxResources.parse('showBoundingBox=Show bounding box');
  1075. mxResources.parse('createSidebarEntry=Create Sidebar Entry');
  1076. mxResources.parse('testCheckFile=Check File');
  1077. mxResources.parse('testDiff=Diff');
  1078. mxResources.parse('testInspect=Inspect');
  1079. mxResources.parse('testShowConsole=Show Console');
  1080. mxResources.parse('testXmlImageExport=XML Image Export');
  1081. mxResources.parse('testDownloadRtModel=Export RT model');
  1082. mxResources.parse('testImportRtModel=Import RT model');
  1083. editorUi.actions.addAction('createSidebarEntry', mxUtils.bind(this, function()
  1084. {
  1085. if (!graph.isSelectionEmpty())
  1086. {
  1087. var cells = graph.cloneCells(graph.getSelectionCells());
  1088. var bbox = graph.getBoundingBoxFromGeometry(cells);
  1089. cells = graph.moveCells(cells, -bbox.x, -bbox.y);
  1090. editorUi.showTextDialog('Create Sidebar Entry', 'this.addDataEntry(\'tag1 tag2\', ' +
  1091. bbox.width + ', ' + bbox.height + ', \'The Title\', \'' +
  1092. Graph.compress(mxUtils.getXml(graph.encodeCells(cells))) + '\'),');
  1093. }
  1094. }));
  1095. editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  1096. {
  1097. var b = graph.getGraphBounds();
  1098. var tr = graph.view.translate;
  1099. var s = graph.view.scale;
  1100. graph.insertVertex(graph.getDefaultParent(), null, '',
  1101. b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s,
  1102. 'fillColor=none;strokeColor=red;');
  1103. }));
  1104. editorUi.actions.addAction('testCheckFile', mxUtils.bind(this, function()
  1105. {
  1106. var xml = (editorUi.pages != null && editorUi.getCurrentFile() != null) ?
  1107. editorUi.getCurrentFile().getAnonymizedXmlForPages(editorUi.pages) : '';
  1108. var dlg = new TextareaDialog(editorUi, 'Paste Data:', xml,
  1109. function(newValue)
  1110. {
  1111. if (newValue.length > 0)
  1112. {
  1113. try
  1114. {
  1115. if (newValue.charAt(0) != '<')
  1116. {
  1117. newValue = Graph.decompress(newValue);
  1118. mxLog.debug('See console for uncompressed XML');
  1119. console.log('xml', newValue);
  1120. }
  1121. var doc = mxUtils.parseXml(newValue);
  1122. var pages = editorUi.getPagesForNode(doc.documentElement, 'mxGraphModel');
  1123. if (pages != null && pages.length > 0)
  1124. {
  1125. try
  1126. {
  1127. var checksum = editorUi.getHashValueForPages(pages);
  1128. mxLog.debug('Checksum: ', checksum);
  1129. }
  1130. catch (e)
  1131. {
  1132. mxLog.debug('Error: ', e.message);
  1133. }
  1134. }
  1135. else
  1136. {
  1137. mxLog.debug('No pages found for checksum');
  1138. }
  1139. // Checks for duplicates
  1140. function checkModel(node)
  1141. {
  1142. var pageId = node.parentNode.id;
  1143. var all = node.childNodes;
  1144. var allIds = {};
  1145. var childs = {};
  1146. var root = null;
  1147. var dups = {};
  1148. for (var i = 0; i < all.length; i++)
  1149. {
  1150. var el = all[i];
  1151. if (el.id != null && el.id.length > 0)
  1152. {
  1153. if (allIds[el.id] == null)
  1154. {
  1155. allIds[el.id] = el.id;
  1156. var pid = el.getAttribute('parent');
  1157. if (pid == null)
  1158. {
  1159. if (root != null)
  1160. {
  1161. mxLog.debug(pageId + ': Multiple roots: ' + el.id);
  1162. }
  1163. else
  1164. {
  1165. root = el.id;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. if (childs[pid] == null)
  1171. {
  1172. childs[pid] = [];
  1173. }
  1174. childs[pid].push(el.id);
  1175. }
  1176. }
  1177. else
  1178. {
  1179. dups[el.id] = el.id;
  1180. }
  1181. }
  1182. }
  1183. if (Object.keys(dups).length > 0)
  1184. {
  1185. var log = pageId + ': ' + Object.keys(dups).length + ' Duplicates: ' + Object.keys(dups).join(', ');
  1186. mxLog.debug(log + ' (see console)');
  1187. }
  1188. else
  1189. {
  1190. mxLog.debug(pageId + ': Checked');
  1191. }
  1192. // Checks tree for cycles
  1193. var visited = {};
  1194. function visit(id)
  1195. {
  1196. if (visited[id] == null)
  1197. {
  1198. visited[id] = true;
  1199. if (childs[id] != null)
  1200. {
  1201. while (childs[id].length > 0)
  1202. {
  1203. var temp = childs[id].pop();
  1204. visit(temp);
  1205. }
  1206. delete childs[id];
  1207. }
  1208. }
  1209. else
  1210. {
  1211. mxLog.debug(pageId + ': Visited: ' + id);
  1212. }
  1213. };
  1214. if (root == null)
  1215. {
  1216. mxLog.debug(pageId + ': No root');
  1217. }
  1218. else
  1219. {
  1220. visit(root);
  1221. if (Object.keys(visited).length != Object.keys(allIds).length)
  1222. {
  1223. mxLog.debug(pageId + ': Invalid tree: (see console)');
  1224. console.log(pageId + ': Invalid tree', childs);
  1225. }
  1226. }
  1227. };
  1228. var roots = doc.getElementsByTagName('root');
  1229. for (var i = 0; i < roots.length; i++)
  1230. {
  1231. checkModel(roots[i]);
  1232. }
  1233. mxLog.show();
  1234. }
  1235. catch (e)
  1236. {
  1237. editorUi.handleError(e);
  1238. if (window.console != null)
  1239. {
  1240. console.error(e);
  1241. }
  1242. }
  1243. }
  1244. });
  1245. dlg.textarea.style.width = '600px';
  1246. dlg.textarea.style.height = '380px';
  1247. editorUi.showDialog(dlg.container, 620, 460, true, true);
  1248. dlg.init();
  1249. }));
  1250. editorUi.actions.addAction('testDiff', mxUtils.bind(this, function()
  1251. {
  1252. if (editorUi.pages != null)
  1253. {
  1254. var dlg = new TextareaDialog(editorUi, 'Paste Data:', '',
  1255. function(newValue)
  1256. {
  1257. if (newValue.length > 0)
  1258. {
  1259. try
  1260. {
  1261. console.log(JSON.stringify(editorUi.diffPages(editorUi.pages,
  1262. editorUi.getPagesForNode(mxUtils.parseXml(newValue).
  1263. documentElement)), null, 2));
  1264. }
  1265. catch (e)
  1266. {
  1267. editorUi.handleError(e);
  1268. if (window.console != null)
  1269. {
  1270. console.error(e);
  1271. }
  1272. }
  1273. }
  1274. });
  1275. dlg.textarea.style.width = '600px';
  1276. dlg.textarea.style.height = '380px';
  1277. editorUi.showDialog(dlg.container, 620, 460, true, true);
  1278. dlg.init();
  1279. }
  1280. else
  1281. {
  1282. editorUi.alert('No pages');
  1283. }
  1284. }));
  1285. editorUi.actions.addAction('testInspect', mxUtils.bind(this, function()
  1286. {
  1287. console.log(editorUi, graph.getModel());
  1288. }));
  1289. editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  1290. {
  1291. var bg = '#ffffff';
  1292. var scale = 1;
  1293. var b = 1;
  1294. var imgExport = new mxImageExport();
  1295. var bounds = graph.getGraphBounds();
  1296. var vs = graph.view.scale;
  1297. // New image export
  1298. var xmlDoc = mxUtils.createXmlDocument();
  1299. var root = xmlDoc.createElement('output');
  1300. xmlDoc.appendChild(root);
  1301. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1302. var xmlCanvas = new mxXmlCanvas2D(root);
  1303. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  1304. xmlCanvas.scale(scale / vs);
  1305. var stateCounter = 0;
  1306. var canvasSave = xmlCanvas.save;
  1307. xmlCanvas.save = function()
  1308. {
  1309. stateCounter++;
  1310. canvasSave.apply(this, arguments);
  1311. };
  1312. var canvasRestore = xmlCanvas.restore;
  1313. xmlCanvas.restore = function()
  1314. {
  1315. stateCounter--;
  1316. canvasRestore.apply(this, arguments);
  1317. };
  1318. var exportDrawShape = imgExport.drawShape;
  1319. imgExport.drawShape = function(state)
  1320. {
  1321. mxLog.debug('entering shape', state, stateCounter);
  1322. exportDrawShape.apply(this, arguments);
  1323. mxLog.debug('leaving shape', state, stateCounter);
  1324. };
  1325. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1326. // Puts request data together
  1327. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  1328. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  1329. mxLog.show();
  1330. mxLog.debug(mxUtils.getXml(root));
  1331. mxLog.debug('stateCounter', stateCounter);
  1332. }));
  1333. editorUi.actions.addAction('testDownloadRtModel...', mxUtils.bind(this, function()
  1334. {
  1335. if (editorUi.drive == null)
  1336. {
  1337. editorUi.handleError({message: mxResources.get('serviceUnavailableOrBlocked')});
  1338. }
  1339. else
  1340. {
  1341. editorUi.drive.execute(mxUtils.bind(this, function()
  1342. {
  1343. var fileId =prompt('File ID', '');
  1344. if (fileId != null && fileId.length > 0 &&
  1345. editorUi.spinner.spin(document.body, mxResources.get('export')))
  1346. {
  1347. // LATER: Download full model dump with history
  1348. var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
  1349. fileId + '/realtime?supportsAllDrives=true', null, 'GET');
  1350. // Adds auth token
  1351. req.setRequestHeaders = function(request)
  1352. {
  1353. mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
  1354. request.setRequestHeader('authorization', 'Bearer ' + editorUi.drive.token);
  1355. };
  1356. req.send(function(req)
  1357. {
  1358. editorUi.spinner.stop();
  1359. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  1360. {
  1361. editorUi.saveLocalFile(req.getText(), 'json-' + fileId +'.txt', 'text/plain');
  1362. }
  1363. else
  1364. {
  1365. editorUi.handleError({message: mxResources.get('fileNotFound')},
  1366. mxResources.get('errorLoadingFile'));
  1367. }
  1368. });
  1369. }
  1370. }));
  1371. }
  1372. }));
  1373. editorUi.actions.addAction('testShowConsole', function()
  1374. {
  1375. if (!mxLog.isVisible())
  1376. {
  1377. mxLog.show();
  1378. }
  1379. else
  1380. {
  1381. mxLog.window.fit();
  1382. }
  1383. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  1384. });
  1385. this.put('testDevelop', new Menu(mxUtils.bind(this, function(menu, parent)
  1386. {
  1387. this.addMenuItems(menu, ['createSidebarEntry', 'showBoundingBox', '-',
  1388. 'testCheckFile', 'testDiff', '-', 'testInspect', '-',
  1389. 'testXmlImageExport', '-', 'testDownloadRtModel'], parent);
  1390. menu.addItem(mxResources.get('testImportRtModel') + '...', null, function()
  1391. {
  1392. var input = document.createElement('input');
  1393. input.setAttribute('type', 'file');
  1394. mxEvent.addListener(input, 'change', mxUtils.bind(this, function()
  1395. {
  1396. if (input.files != null)
  1397. {
  1398. var reader = new FileReader();
  1399. reader.onload = mxUtils.bind(this, function(e)
  1400. {
  1401. try
  1402. {
  1403. editorUi.openLocalFile(mxUtils.getXml(editorUi.drive.convertJsonToXml(
  1404. JSON.parse(e.target.result).data)), input.files[0].name, true);
  1405. }
  1406. catch (err)
  1407. {
  1408. editorUi.handleError(err, mxResources.get('errorLoadingFile'));
  1409. }
  1410. });
  1411. reader.readAsText(input.files[0]);
  1412. }
  1413. }));
  1414. input.click();
  1415. }, parent);
  1416. this.addMenuItems(menu, ['-', 'testShowConsole'], parent);
  1417. })));
  1418. }
  1419. editorUi.actions.addAction('shapes...', function()
  1420. {
  1421. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  1422. {
  1423. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  1424. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  1425. }
  1426. else
  1427. {
  1428. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  1429. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  1430. }
  1431. });
  1432. editorUi.actions.put('createShape', new Action(mxResources.get('shape') + '...', function(evt)
  1433. {
  1434. if (graph.isEnabled())
  1435. {
  1436. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  1437. cell.vertex = true;
  1438. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  1439. editorUi.showDialog(dlg.container, 640, 480, true, false);
  1440. dlg.init();
  1441. }
  1442. })).isEnabled = isGraphEnabled;
  1443. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  1444. {
  1445. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1446. {
  1447. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1448. {
  1449. editorUi.spinner.stop();
  1450. editorUi.showHtmlDialog(mxResources.get('create'), 'https://desk.draw.io/support/solutions/articles/16000042542',
  1451. url, function(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  1452. {
  1453. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  1454. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  1455. {
  1456. var dlg = new EmbedDialog(editorUi, html + '\n' + scriptTag, null, null, function()
  1457. {
  1458. var wnd = window.open();
  1459. var doc = wnd.document;
  1460. if (doc != null)
  1461. {
  1462. if (document.compatMode === 'CSS1Compat')
  1463. {
  1464. doc.writeln('<!DOCTYPE html>');
  1465. }
  1466. doc.writeln('<html>');
  1467. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  1468. '</title><meta charset="utf-8"></head>');
  1469. doc.writeln('<body>');
  1470. doc.writeln(html);
  1471. var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
  1472. if (direct)
  1473. {
  1474. doc.writeln(scriptTag);
  1475. }
  1476. doc.writeln('</body>');
  1477. doc.writeln('</html>');
  1478. doc.close();
  1479. // Adds script tag after closing page and delay to fix timing issues
  1480. if (!direct)
  1481. {
  1482. var info = wnd.document.createElement('div');
  1483. info.marginLeft = '26px';
  1484. info.marginTop = '26px';
  1485. mxUtils.write(info, mxResources.get('updatingDocument'));
  1486. var img = wnd.document.createElement('img');
  1487. img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
  1488. '/' + IMAGE_PATH + '/spin.gif');
  1489. img.style.marginLeft = '6px';
  1490. info.appendChild(img);
  1491. wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
  1492. window.setTimeout(function()
  1493. {
  1494. var script = document.createElement('script');
  1495. script.type = 'text/javascript';
  1496. script.src = /<script.*?src="(.*?)"/.exec(scriptTag)[1];
  1497. doc.body.appendChild(script);
  1498. info.parentNode.removeChild(info);
  1499. }, 20);
  1500. }
  1501. }
  1502. else
  1503. {
  1504. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  1505. }
  1506. });
  1507. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1508. dlg.init();
  1509. }));
  1510. });
  1511. });
  1512. }
  1513. }));
  1514. editorUi.actions.put('liveImage', new Action('Live image...', function()
  1515. {
  1516. var current = editorUi.getCurrentFile();
  1517. if (current != null && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1518. {
  1519. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1520. {
  1521. editorUi.spinner.stop();
  1522. if (url != null)
  1523. {
  1524. var dlg = new EmbedDialog(editorUi, '<img src="' + ((current.constructor != DriveFile) ?
  1525. url : 'https://drive.google.com/uc?id=' + current.getId()) + '"/>');
  1526. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1527. dlg.init();
  1528. }
  1529. else
  1530. {
  1531. editorUi.handleError({message: mxResources.get('invalidPublicUrl')});
  1532. }
  1533. });
  1534. }
  1535. }));
  1536. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  1537. {
  1538. editorUi.showEmbedImageDialog(function(fit, shadow, retina, lightbox, editLink, layers)
  1539. {
  1540. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1541. {
  1542. editorUi.createEmbedImage(fit, shadow, retina, lightbox, editLink, layers, function(result)
  1543. {
  1544. editorUi.spinner.stop();
  1545. var dlg = new EmbedDialog(editorUi, result);
  1546. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1547. dlg.init();
  1548. }, function(err)
  1549. {
  1550. editorUi.spinner.stop();
  1551. editorUi.handleError(err);
  1552. });
  1553. }
  1554. }, mxResources.get('image'), mxResources.get('retina'), editorUi.isExportToCanvas());
  1555. }));
  1556. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  1557. {
  1558. editorUi.showEmbedImageDialog(function(fit, shadow, image, lightbox, editLink, layers)
  1559. {
  1560. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1561. {
  1562. editorUi.createEmbedSvg(fit, shadow, image, lightbox, editLink, layers, function(result)
  1563. {
  1564. editorUi.spinner.stop();
  1565. var dlg = new EmbedDialog(editorUi, result);
  1566. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1567. dlg.init();
  1568. }, function(err)
  1569. {
  1570. editorUi.spinner.stop();
  1571. editorUi.handleError(err);
  1572. });
  1573. }
  1574. }, mxResources.get('formatSvg'), mxResources.get('image'),
  1575. true, 'https://desk.draw.io/support/solutions/articles/16000042548');
  1576. }));
  1577. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  1578. {
  1579. var bounds = graph.getGraphBounds();
  1580. editorUi.showPublishLinkDialog(mxResources.get('iframe'), null, '100%',
  1581. (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / graph.view.scale) + 2),
  1582. function(linkTarget, linkColor, allPages, lightbox, editLink, layers, width, height)
  1583. {
  1584. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1585. {
  1586. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1587. {
  1588. editorUi.spinner.stop();
  1589. var dlg = new EmbedDialog(editorUi, '<iframe frameborder="0" style="width:' + width +
  1590. ';height:' + height + ';" src="' + editorUi.createLink(linkTarget, linkColor,
  1591. allPages, lightbox, editLink, layers, url) + '"></iframe>');
  1592. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1593. dlg.init();
  1594. });
  1595. }
  1596. }, true);
  1597. }));
  1598. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  1599. {
  1600. editorUi.showPublishLinkDialog(null, null, null, null,
  1601. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  1602. {
  1603. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1604. {
  1605. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1606. {
  1607. editorUi.spinner.stop();
  1608. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  1609. linkColor, allPages, lightbox, editLink, layers, url));
  1610. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1611. dlg.init();
  1612. });
  1613. }
  1614. });
  1615. }));
  1616. editorUi.actions.addAction('microsoftOffice...', function()
  1617. {
  1618. editorUi.openLink('https://office.draw.io');
  1619. });
  1620. editorUi.actions.addAction('googleDocs...', function()
  1621. {
  1622. editorUi.openLink('http://docsaddon.draw.io');
  1623. });
  1624. editorUi.actions.addAction('googleSlides...', function()
  1625. {
  1626. editorUi.openLink('https://slidesaddon.draw.io');
  1627. });
  1628. editorUi.actions.addAction('googleSheets...', function()
  1629. {
  1630. editorUi.openLink('https://sheetsaddon.draw.io');
  1631. });
  1632. editorUi.actions.addAction('googleSites...', function()
  1633. {
  1634. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1635. {
  1636. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1637. {
  1638. editorUi.spinner.stop();
  1639. var dlg = new GoogleSitesDialog(editorUi, url);
  1640. editorUi.showDialog(dlg.container, 420, 256, true, true);
  1641. dlg.init();
  1642. });
  1643. }
  1644. });
  1645. // Adds plugins menu item only if localStorage is available for storing the plugins
  1646. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  1647. {
  1648. var action = editorUi.actions.addAction('scratchpad', function()
  1649. {
  1650. editorUi.toggleScratchpad();
  1651. });
  1652. action.setToggleAction(true);
  1653. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  1654. editorUi.actions.addAction('plugins...', function()
  1655. {
  1656. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 170, true, false);
  1657. });
  1658. }
  1659. var action = editorUi.actions.addAction('search', function()
  1660. {
  1661. var visible = editorUi.sidebar.isEntryVisible('search');
  1662. editorUi.sidebar.showPalette('search', !visible);
  1663. if (isLocalStorage)
  1664. {
  1665. mxSettings.settings.search = !visible;
  1666. mxSettings.save();
  1667. }
  1668. });
  1669. action.setToggleAction(true);
  1670. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  1671. if (urlParams['embed'] == '1')
  1672. {
  1673. editorUi.actions.get('save').funct = function(exit)
  1674. {
  1675. if (graph.isEditing())
  1676. {
  1677. graph.stopEditing();
  1678. }
  1679. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  1680. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  1681. if (urlParams['proto'] == 'json')
  1682. {
  1683. var msg = editorUi.createLoadMessage('save');
  1684. msg.xml = data;
  1685. if (exit)
  1686. {
  1687. msg.exit = true;
  1688. }
  1689. data = JSON.stringify(msg);
  1690. }
  1691. var parent = window.opener || window.parent;
  1692. parent.postMessage(data, '*');
  1693. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  1694. {
  1695. editorUi.editor.modified = false;
  1696. editorUi.editor.setStatus('');
  1697. }
  1698. //Add support to saving files if embedded mode is running with files
  1699. var file = editorUi.getCurrentFile();
  1700. if (file != null && file.constructor != EmbedFile && (file.constructor != LocalFile || file.mode != null))
  1701. {
  1702. editorUi.saveFile();
  1703. }
  1704. };
  1705. var saveAndExitAction = editorUi.actions.addAction('saveAndExit', function()
  1706. {
  1707. editorUi.actions.get('save').funct(true);
  1708. });
  1709. saveAndExitAction.label = urlParams['publishClose'] == '1' ? mxResources.get('publish') : mxResources.get('saveAndExit');
  1710. editorUi.actions.addAction('exit', function()
  1711. {
  1712. var fn = function()
  1713. {
  1714. editorUi.editor.modified = false;
  1715. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  1716. modified: editorUi.editor.modified}) : '';
  1717. var parent = window.opener || window.parent;
  1718. parent.postMessage(msg, '*');
  1719. }
  1720. if (!editorUi.editor.modified)
  1721. {
  1722. fn();
  1723. }
  1724. else
  1725. {
  1726. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  1727. mxResources.get('cancel'), mxResources.get('discardChanges'));
  1728. }
  1729. });
  1730. }
  1731. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  1732. {
  1733. if (editorUi.isExportToCanvas())
  1734. {
  1735. this.addMenuItems(menu, ['exportPng'], parent);
  1736. if (editorUi.jpgSupported)
  1737. {
  1738. this.addMenuItems(menu, ['exportJpg'], parent);
  1739. }
  1740. }
  1741. // Disabled for standalone mode in iOS because new tab cannot be closed
  1742. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1743. {
  1744. this.addMenuItems(menu, ['exportPng', 'exportJpg'], parent);
  1745. }
  1746. this.addMenuItems(menu, ['exportSvg', '-'], parent);
  1747. // Redirects export to PDF to print in Chrome App
  1748. if (editorUi.isOffline() || editorUi.printPdfExport)
  1749. {
  1750. this.addMenuItems(menu, ['exportPdf'], parent);
  1751. }
  1752. // Disabled for standalone mode in iOS because new tab cannot be closed
  1753. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1754. {
  1755. this.addMenuItems(menu, ['exportPdf'], parent);
  1756. }
  1757. if (!mxClient.IS_IE && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
  1758. {
  1759. this.addMenuItems(menu, ['exportVsdx'], parent);
  1760. }
  1761. this.addMenuItems(menu, ['-', 'exportHtml', 'exportXml', 'exportUrl'], parent);
  1762. if (!editorUi.isOffline())
  1763. {
  1764. menu.addSeparator(parent);
  1765. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  1766. }
  1767. })));
  1768. this.put('importFrom', new Menu(mxUtils.bind(this, function(menu, parent)
  1769. {
  1770. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  1771. {
  1772. // Gets insert location
  1773. var view = graph.view;
  1774. var bds = graph.getGraphBounds();
  1775. var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
  1776. var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
  1777. if (data.substring(0, 11) == 'data:image/')
  1778. {
  1779. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  1780. {
  1781. var resizeImages = true;
  1782. var doInsert = mxUtils.bind(this, function()
  1783. {
  1784. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  1785. {
  1786. var s = (resizeImages) ? Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2)) : 1;
  1787. editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  1788. {
  1789. editorUi.spinner.stop();
  1790. graph.setSelectionCells(cells);
  1791. graph.scrollCellToVisible(graph.getSelectionCell());
  1792. });
  1793. }), resizeImages);
  1794. });
  1795. if (data.length > editorUi.resampleThreshold)
  1796. {
  1797. editorUi.confirmImageResize(function(doResize)
  1798. {
  1799. resizeImages = doResize;
  1800. doInsert();
  1801. });
  1802. }
  1803. else
  1804. {
  1805. doInsert();
  1806. }
  1807. }), mxUtils.bind(this, function()
  1808. {
  1809. editorUi.handleError({message: mxResources.get('cannotOpenFile')});
  1810. }));
  1811. }
  1812. else
  1813. {
  1814. editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
  1815. {
  1816. editorUi.spinner.stop();
  1817. graph.setSelectionCells(cells);
  1818. graph.scrollCellToVisible(graph.getSelectionCell());
  1819. });
  1820. }
  1821. });
  1822. var getMimeType = mxUtils.bind(this, function(filename)
  1823. {
  1824. var mime = 'text/xml';
  1825. if (/\.png$/i.test(filename))
  1826. {
  1827. mime = 'image/png';
  1828. }
  1829. else if (/\.jpe?g$/i.test(filename))
  1830. {
  1831. mime = 'image/jpg';
  1832. }
  1833. else if (/\.gif$/i.test(filename))
  1834. {
  1835. mime = 'image/gif';
  1836. }
  1837. else if (/\.pdf$/i.test(filename))
  1838. {
  1839. mime = 'application/pdf';
  1840. }
  1841. return mime;
  1842. });
  1843. function pickFileFromService(service)
  1844. {
  1845. // Drive requires special arguments for libraries and bypassing realtime
  1846. service.pickFile(function(id)
  1847. {
  1848. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1849. {
  1850. // NOTE The third argument in getFile says denyConvert to match
  1851. // the existing signature in the original DriveClient which has
  1852. // as slightly different semantic, but works the same way.
  1853. service.getFile(id, function(file)
  1854. {
  1855. var mime = (file.getData().substring(0, 11) == 'data:image/') ? getMimeType(file.getTitle()) : 'text/xml';
  1856. // Imports SVG as images
  1857. if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
  1858. {
  1859. file.setData(Editor.createSvgDataUri(file.getData()));
  1860. mime = 'image/svg+xml';
  1861. }
  1862. doImportFile(file.getData(), mime, file.getTitle());
  1863. },
  1864. function(resp)
  1865. {
  1866. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1867. }, service == editorUi.drive);
  1868. }
  1869. }, true);
  1870. };
  1871. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1872. {
  1873. if (editorUi.drive != null)
  1874. {
  1875. // Requires special arguments for libraries and realtime
  1876. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1877. {
  1878. pickFileFromService(editorUi.drive);
  1879. }, parent);
  1880. }
  1881. else if (googleEnabled && typeof window.DriveClient === 'function')
  1882. {
  1883. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1884. {
  1885. // do nothing
  1886. }, parent, null, false);
  1887. }
  1888. }
  1889. if (editorUi.oneDrive != null)
  1890. {
  1891. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1892. {
  1893. pickFileFromService(editorUi.oneDrive);
  1894. }, parent);
  1895. }
  1896. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  1897. {
  1898. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1899. {
  1900. // do nothing
  1901. }, parent, null, false);
  1902. }
  1903. if (editorUi.dropbox != null)
  1904. {
  1905. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1906. {
  1907. pickFileFromService(editorUi.dropbox);
  1908. }, parent);
  1909. }
  1910. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  1911. {
  1912. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1913. {
  1914. // do nothing
  1915. }, parent, null, false);
  1916. }
  1917. menu.addSeparator(parent);
  1918. if (editorUi.gitHub != null)
  1919. {
  1920. menu.addItem(mxResources.get('github') + '...', null, function()
  1921. {
  1922. pickFileFromService(editorUi.gitHub);
  1923. }, parent);
  1924. }
  1925. if (editorUi.gitLab != null)
  1926. {
  1927. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  1928. {
  1929. pickFileFromService(editorUi.gitLab);
  1930. }, parent);
  1931. }
  1932. if (editorUi.trello != null)
  1933. {
  1934. menu.addItem(mxResources.get('trello') + '...', null, function()
  1935. {
  1936. pickFileFromService(editorUi.trello);
  1937. }, parent);
  1938. }
  1939. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  1940. {
  1941. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  1942. {
  1943. // do nothing
  1944. }, parent, null, false);
  1945. }
  1946. menu.addSeparator(parent);
  1947. if (isLocalStorage && urlParams['browser'] != '0')
  1948. {
  1949. menu.addItem(mxResources.get('browser') + '...', null, function()
  1950. {
  1951. editorUi.importLocalFile(false);
  1952. }, parent);
  1953. }
  1954. menu.addItem(mxResources.get('device') + '...', null, function()
  1955. {
  1956. editorUi.importLocalFile(true);
  1957. }, parent);
  1958. if (!editorUi.isOffline())
  1959. {
  1960. menu.addSeparator(parent);
  1961. menu.addItem(mxResources.get('url') + '...', null, function()
  1962. {
  1963. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1964. {
  1965. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1966. {
  1967. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1968. // Uses proxy to avoid CORS issues
  1969. editorUi.editor.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1970. {
  1971. doImportFile(data, mime, fileUrl);
  1972. },
  1973. function ()
  1974. {
  1975. editorUi.spinner.stop();
  1976. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1977. }, mime == 'image/png');
  1978. }
  1979. }, mxResources.get('url'));
  1980. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1981. dlg.init();
  1982. }, parent);
  1983. }
  1984. }))).isEnabled = isGraphEnabled;
  1985. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1986. {
  1987. var theme = mxSettings.getUi();
  1988. var item = menu.addItem(mxResources.get('automatic'), null, function()
  1989. {
  1990. mxSettings.setUi('');
  1991. mxSettings.save();
  1992. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1993. }, parent);
  1994. if (theme != 'kennedy' && theme != 'atlas' &&
  1995. theme != 'dark' && theme != 'min')
  1996. {
  1997. menu.addCheckmark(item, Editor.checkmarkImage);
  1998. }
  1999. menu.addSeparator(parent);
  2000. item = menu.addItem(mxResources.get('kennedy'), null, function()
  2001. {
  2002. mxSettings.setUi('kennedy');
  2003. mxSettings.save();
  2004. editorUi.alert(mxResources.get('restartForChangeRequired'));
  2005. }, parent);
  2006. if (theme == 'kennedy')
  2007. {
  2008. menu.addCheckmark(item, Editor.checkmarkImage);
  2009. }
  2010. item = menu.addItem(mxResources.get('minimal'), null, function()
  2011. {
  2012. mxSettings.setUi('min');
  2013. mxSettings.save();
  2014. editorUi.alert(mxResources.get('restartForChangeRequired'));
  2015. }, parent);
  2016. if (theme == 'min')
  2017. {
  2018. menu.addCheckmark(item, Editor.checkmarkImage);
  2019. }
  2020. item = menu.addItem(mxResources.get('atlas'), null, function()
  2021. {
  2022. mxSettings.setUi('atlas');
  2023. mxSettings.save();
  2024. editorUi.alert(mxResources.get('restartForChangeRequired'));
  2025. }, parent);
  2026. if (theme == 'atlas')
  2027. {
  2028. menu.addCheckmark(item, Editor.checkmarkImage);
  2029. }
  2030. item = menu.addItem(mxResources.get('dark'), null, function()
  2031. {
  2032. mxSettings.setUi('dark');
  2033. mxSettings.save();
  2034. editorUi.alert(mxResources.get('restartForChangeRequired'));
  2035. }, parent);
  2036. if (theme == 'dark')
  2037. {
  2038. menu.addCheckmark(item, Editor.checkmarkImage);
  2039. }
  2040. })));
  2041. var renameAction = this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  2042. {
  2043. var file = this.editorUi.getCurrentFile();
  2044. if (file != null)
  2045. {
  2046. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  2047. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  2048. {
  2049. if (title != null && title.length > 0 && file != null && title != file.getTitle() &&
  2050. this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  2051. {
  2052. // Delete old file, save new file in dropbox if autosize is enabled
  2053. file.rename(title, mxUtils.bind(this, function(resp)
  2054. {
  2055. this.editorUi.spinner.stop();
  2056. }),
  2057. mxUtils.bind(this, function(resp)
  2058. {
  2059. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  2060. }));
  2061. }
  2062. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  2063. mxResources.get('diagramName') : null, function(name)
  2064. {
  2065. if (name != null && name.length > 0)
  2066. {
  2067. return true;
  2068. }
  2069. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  2070. return false;
  2071. }, null, null, null, null, editorUi.editor.fileExtensions);
  2072. this.editorUi.showDialog(dlg.container, 340, 90, true, true);
  2073. dlg.init();
  2074. }
  2075. }));
  2076. renameAction.isEnabled = function()
  2077. {
  2078. return this.enabled && isGraphEnabled.apply(this, arguments);
  2079. }
  2080. renameAction.visible = urlParams['embed'] != '1';
  2081. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  2082. {
  2083. var file = editorUi.getCurrentFile();
  2084. if (file != null)
  2085. {
  2086. var title = editorUi.getCopyFilename(file);
  2087. if (file.constructor == DriveFile)
  2088. {
  2089. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  2090. {
  2091. // Mode is "download" if Create button is pressed, means use Google Drive
  2092. if (mode == 'download')
  2093. {
  2094. mode = App.MODE_GOOGLE;
  2095. }
  2096. if (newTitle != null && newTitle.length > 0)
  2097. {
  2098. if (mode == App.MODE_GOOGLE)
  2099. {
  2100. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  2101. {
  2102. // Saveas does not update the file descriptor in Google Drive
  2103. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  2104. {
  2105. // Replaces file descriptor in-place and saves
  2106. file.desc = resp;
  2107. // Makes sure the latest XML is in the file
  2108. file.save(false, mxUtils.bind(this, function()
  2109. {
  2110. editorUi.spinner.stop();
  2111. file.setModified(false);
  2112. file.addAllSavedStatus();
  2113. }), mxUtils.bind(this, function(resp)
  2114. {
  2115. editorUi.handleError(resp);
  2116. }));
  2117. }), mxUtils.bind(this, function(resp)
  2118. {
  2119. editorUi.handleError(resp);
  2120. }));
  2121. }
  2122. }
  2123. else
  2124. {
  2125. editorUi.createFile(newTitle, editorUi.getFileData(true), null, mode);
  2126. }
  2127. }
  2128. }), mxUtils.bind(this, function()
  2129. {
  2130. editorUi.hideDialog();
  2131. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  2132. null, null, null, true, null, null, null, null,
  2133. editorUi.editor.fileExtensions);
  2134. editorUi.showDialog(dlg.container, 420, 380, true, true);
  2135. dlg.init();
  2136. }
  2137. else
  2138. {
  2139. // Creates a copy with no predefined storage
  2140. editorUi.editor.editAsNew(this.editorUi.getFileData(true), title);
  2141. }
  2142. }
  2143. }));
  2144. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  2145. {
  2146. var file = editorUi.getCurrentFile();
  2147. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  2148. {
  2149. var isInRoot = false;
  2150. if (file.getMode() == App.MODE_GOOGLE && file.desc.parents != null)
  2151. {
  2152. for (var i = 0; i < file.desc.parents.length; i++)
  2153. {
  2154. if (file.desc.parents[i].isRoot)
  2155. {
  2156. isInRoot = true;
  2157. break;
  2158. }
  2159. }
  2160. }
  2161. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  2162. {
  2163. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  2164. {
  2165. file.move(folderId, mxUtils.bind(this, function(resp)
  2166. {
  2167. editorUi.spinner.stop();
  2168. }), mxUtils.bind(this, function(resp)
  2169. {
  2170. editorUi.handleError(resp);
  2171. }));
  2172. }
  2173. }), null, true, isInRoot);
  2174. }
  2175. }));
  2176. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  2177. {
  2178. this.addMenuItems(menu, ['publishLink'], parent);
  2179. })));
  2180. editorUi.actions.put('useOffline', new Action(mxResources.get('useOffline') + '...', function()
  2181. {
  2182. editorUi.openLink('https://app.draw.io/')
  2183. }));
  2184. editorUi.actions.put('downloadDesktop', new Action(mxResources.get('downloadDesktop') + '...', function()
  2185. {
  2186. editorUi.openLink('https://get.draw.io/')
  2187. }));
  2188. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  2189. {
  2190. try
  2191. {
  2192. var file = editorUi.getCurrentFile();
  2193. if (file != null)
  2194. {
  2195. file.share();
  2196. }
  2197. }
  2198. catch (e)
  2199. {
  2200. editorUi.handleError(e);
  2201. }
  2202. }));
  2203. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  2204. {
  2205. var file = editorUi.getCurrentFile();
  2206. if (file != null && (file.getMode() == App.MODE_GOOGLE ||
  2207. file.getMode() == App.MODE_GITHUB) && /(\.png)$/i.test(file.getTitle()))
  2208. {
  2209. this.addMenuItems(menu, ['liveImage', '-'], parent);
  2210. }
  2211. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  2212. if (!navigator.standalone && !editorUi.isOffline())
  2213. {
  2214. this.addMenuItems(menu, ['embedIframe'], parent);
  2215. }
  2216. if (urlParams['embed'] != '1' && !editorUi.isOffline())
  2217. {
  2218. this.addMenuItems(menu, ['-', 'googleDocs', 'googleSlides', 'googleSheets', '-', 'microsoftOffice'], parent);
  2219. }
  2220. })));
  2221. var addInsertItem = function(menu, parent, title, method)
  2222. {
  2223. if (method != 'plantUml' || (EditorUi.enablePlantUml && !editorUi.isOffline()))
  2224. {
  2225. menu.addItem(title, null, mxUtils.bind(this, function()
  2226. {
  2227. if (method == 'fromText' || method == 'formatSql' ||
  2228. method == 'plantUml' || method == 'mermaid')
  2229. {
  2230. var dlg = new ParseDialog(editorUi, title, method);
  2231. editorUi.showDialog(dlg.container, 620, 420, true, false);
  2232. editorUi.dialog.container.style.overflow = 'auto';
  2233. dlg.init();
  2234. }
  2235. else
  2236. {
  2237. var dlg = new CreateGraphDialog(editorUi, title, method);
  2238. editorUi.showDialog(dlg.container, 620, 420, true, false);
  2239. // Executed after dialog is added to dom
  2240. dlg.init();
  2241. }
  2242. }), parent, null, isGraphEnabled());
  2243. }
  2244. };
  2245. var insertVertex = function(value, w, h, style)
  2246. {
  2247. var cell = new mxCell(value, new mxGeometry(0, 0, w, h), style);
  2248. cell.vertex = true;
  2249. var pt = graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry([cell], true));
  2250. cell.geometry.x = pt.x;
  2251. cell.geometry.y = pt.y;
  2252. graph.getModel().beginUpdate();
  2253. try
  2254. {
  2255. cell = graph.addCell(cell);
  2256. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', [cell]));
  2257. }
  2258. finally
  2259. {
  2260. graph.getModel().endUpdate();
  2261. }
  2262. graph.scrollCellToVisible(cell);
  2263. graph.setSelectionCell(cell);
  2264. graph.container.focus();
  2265. if (graph.editAfterInsert)
  2266. {
  2267. graph.startEditing(cell);
  2268. }
  2269. // Async call is workaroun for touch events resetting hover icons
  2270. window.setTimeout(function()
  2271. {
  2272. if (editorUi.hoverIcons != null)
  2273. {
  2274. editorUi.hoverIcons.update(graph.view.getState(cell));
  2275. }
  2276. }, 0);
  2277. return cell;
  2278. };
  2279. editorUi.actions.put('insertText', new Action(mxResources.get('text'), function()
  2280. {
  2281. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2282. {
  2283. graph.startEditingAtCell(insertVertex('Text', 40, 20, 'text;html=1;resizable=0;autosize=1;' +
  2284. 'align=center;verticalAlign=middle;points=[];fillColor=none;strokeColor=none;rounded=0;'));
  2285. }
  2286. }), null, null, Editor.ctrlKey + '+Shift+X').isEnabled = isGraphEnabled;
  2287. editorUi.actions.put('insertRectangle', new Action(mxResources.get('rectangle'), function()
  2288. {
  2289. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2290. {
  2291. insertVertex('', 120, 60, 'whiteSpace=wrap;html=1;');
  2292. }
  2293. }), null, null, Editor.ctrlKey + '+K').isEnabled = isGraphEnabled;
  2294. editorUi.actions.put('insertEllipse', new Action(mxResources.get('ellipse'), function()
  2295. {
  2296. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2297. {
  2298. insertVertex('', 80, 80, 'ellipse;whiteSpace=wrap;html=1;');
  2299. }
  2300. }), null, null, Editor.ctrlKey + '+Shift+K').isEnabled = isGraphEnabled;
  2301. editorUi.actions.put('insertRhombus', new Action(mxResources.get('rhombus'), function()
  2302. {
  2303. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  2304. {
  2305. insertVertex('', 80, 80, 'rhombus;whiteSpace=wrap;html=1;');
  2306. }
  2307. })).isEnabled = isGraphEnabled;
  2308. var addInsertMenuItems = mxUtils.bind(this, function(menu, parent, methods)
  2309. {
  2310. for (var i = 0; i < methods.length; i++)
  2311. {
  2312. if (methods[i] == '-')
  2313. {
  2314. menu.addSeparator(parent);
  2315. }
  2316. else
  2317. {
  2318. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  2319. }
  2320. }
  2321. });
  2322. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  2323. {
  2324. this.addMenuItems(menu, ['insertRectangle', 'insertEllipse',
  2325. 'insertRhombus', '-', 'insertText', 'insertLink', '-',
  2326. 'createShape', 'insertFreehand', '-', 'insertImage'], parent);
  2327. if (editorUi.insertTemplateEnabled && !editorUi.isOffline())
  2328. {
  2329. this.addMenuItems(menu, ['insertTemplate'], parent);
  2330. }
  2331. menu.addSeparator(parent);
  2332. this.addSubmenu('insertLayout', menu, parent, mxResources.get('layout'));
  2333. this.addSubmenu('insertAdvanced', menu, parent, mxResources.get('advanced'));
  2334. })));
  2335. this.put('insertLayout', new Menu(mxUtils.bind(this, function(menu, parent)
  2336. {
  2337. addInsertMenuItems(menu, parent, ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree',
  2338. 'verticalTree', 'radialTree', '-', 'organic', 'circle']);
  2339. })));
  2340. this.put('insertAdvanced', new Menu(mxUtils.bind(this, function(menu, parent)
  2341. {
  2342. addInsertMenuItems(menu, parent, ['fromText', 'plantUml', 'mermaid', '-', 'formatSql']);
  2343. menu.addItem(mxResources.get('csv') + '...', null, function()
  2344. {
  2345. editorUi.showImportCsvDialog();
  2346. }, parent, null, isGraphEnabled());
  2347. })));
  2348. this.put('openRecent', new Menu(function(menu, parent)
  2349. {
  2350. var recent = editorUi.getRecent();
  2351. if (recent != null)
  2352. {
  2353. for (var i = 0; i < recent.length; i++)
  2354. {
  2355. (function(entry)
  2356. {
  2357. var modeKey = entry.mode;
  2358. // Google and oneDrive use different keys
  2359. if (modeKey == App.MODE_GOOGLE)
  2360. {
  2361. modeKey = 'googleDrive';
  2362. }
  2363. else if (modeKey == App.MODE_ONEDRIVE)
  2364. {
  2365. modeKey = 'oneDrive';
  2366. }
  2367. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  2368. {
  2369. editorUi.loadFile(entry.id);
  2370. }, parent);
  2371. })(recent[i]);
  2372. }
  2373. menu.addSeparator(parent);
  2374. }
  2375. menu.addItem(mxResources.get('reset'), null, function()
  2376. {
  2377. editorUi.resetRecent();
  2378. }, parent);
  2379. }));
  2380. this.put('openFrom', new Menu(function(menu, parent)
  2381. {
  2382. if (editorUi.drive != null)
  2383. {
  2384. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2385. {
  2386. editorUi.pickFile(App.MODE_GOOGLE);
  2387. }, parent);
  2388. }
  2389. else if (googleEnabled && typeof window.DriveClient === 'function')
  2390. {
  2391. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2392. {
  2393. // do nothing
  2394. }, parent, null, false);
  2395. }
  2396. if (editorUi.oneDrive != null)
  2397. {
  2398. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2399. {
  2400. editorUi.pickFile(App.MODE_ONEDRIVE);
  2401. }, parent);
  2402. }
  2403. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  2404. {
  2405. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2406. {
  2407. // do nothing
  2408. }, parent, null, false);
  2409. }
  2410. if (editorUi.dropbox != null)
  2411. {
  2412. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2413. {
  2414. editorUi.pickFile(App.MODE_DROPBOX);
  2415. }, parent);
  2416. }
  2417. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  2418. {
  2419. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2420. {
  2421. // do nothing
  2422. }, parent, null, false);
  2423. }
  2424. menu.addSeparator(parent);
  2425. if (editorUi.gitHub != null)
  2426. {
  2427. menu.addItem(mxResources.get('github') + '...', null, function()
  2428. {
  2429. editorUi.pickFile(App.MODE_GITHUB);
  2430. }, parent);
  2431. }
  2432. if (editorUi.gitLab != null)
  2433. {
  2434. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  2435. {
  2436. editorUi.pickFile(App.MODE_GITLAB);
  2437. }, parent);
  2438. }
  2439. if (editorUi.trello != null)
  2440. {
  2441. menu.addItem(mxResources.get('trello') + '...', null, function()
  2442. {
  2443. editorUi.pickFile(App.MODE_TRELLO);
  2444. }, parent);
  2445. }
  2446. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  2447. {
  2448. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2449. {
  2450. // do nothing
  2451. }, parent, null, false);
  2452. }
  2453. menu.addSeparator(parent);
  2454. if (isLocalStorage && urlParams['browser'] != '0')
  2455. {
  2456. menu.addItem(mxResources.get('browser') + '...', null, function()
  2457. {
  2458. editorUi.pickFile(App.MODE_BROWSER);
  2459. }, parent);
  2460. }
  2461. //if (!mxClient.IS_IOS)
  2462. {
  2463. menu.addItem(mxResources.get('device') + '...', null, function()
  2464. {
  2465. editorUi.pickFile(App.MODE_DEVICE);
  2466. }, parent);
  2467. }
  2468. if (!editorUi.isOffline())
  2469. {
  2470. menu.addSeparator(parent);
  2471. menu.addItem(mxResources.get('url') + '...', null, function()
  2472. {
  2473. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  2474. {
  2475. if (fileUrl != null && fileUrl.length > 0)
  2476. {
  2477. if (editorUi.getCurrentFile() == null)
  2478. {
  2479. window.location.hash = '#U' + encodeURIComponent(fileUrl);
  2480. }
  2481. else
  2482. {
  2483. window.openWindow(((mxClient.IS_CHROMEAPP) ?
  2484. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  2485. window.location.search + '#U' + encodeURIComponent(fileUrl));
  2486. }
  2487. }
  2488. }, mxResources.get('url'));
  2489. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2490. dlg.init();
  2491. }, parent);
  2492. }
  2493. }));
  2494. if (Editor.enableCustomLibraries)
  2495. {
  2496. this.put('newLibrary', new Menu(function(menu, parent)
  2497. {
  2498. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2499. {
  2500. if (editorUi.drive != null)
  2501. {
  2502. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2503. {
  2504. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  2505. }, parent);
  2506. }
  2507. else if (googleEnabled && typeof window.DriveClient === 'function')
  2508. {
  2509. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2510. {
  2511. // do nothing
  2512. }, parent, null, false);
  2513. }
  2514. }
  2515. if (editorUi.oneDrive != null)
  2516. {
  2517. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2518. {
  2519. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  2520. }, parent);
  2521. }
  2522. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  2523. {
  2524. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2525. {
  2526. // do nothing
  2527. }, parent, null, false);
  2528. }
  2529. if (editorUi.dropbox != null)
  2530. {
  2531. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2532. {
  2533. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  2534. }, parent);
  2535. }
  2536. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  2537. {
  2538. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2539. {
  2540. // do nothing
  2541. }, parent, null, false);
  2542. }
  2543. menu.addSeparator(parent);
  2544. if (editorUi.gitHub != null)
  2545. {
  2546. menu.addItem(mxResources.get('github') + '...', null, function()
  2547. {
  2548. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
  2549. }, parent);
  2550. }
  2551. if (editorUi.gitLab != null)
  2552. {
  2553. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  2554. {
  2555. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITLAB);
  2556. }, parent);
  2557. }
  2558. if (editorUi.trello != null)
  2559. {
  2560. menu.addItem(mxResources.get('trello') + '...', null, function()
  2561. {
  2562. editorUi.showLibraryDialog(null, null, null, null, App.MODE_TRELLO);
  2563. }, parent);
  2564. }
  2565. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  2566. {
  2567. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2568. {
  2569. // do nothing
  2570. }, parent, null, false);
  2571. }
  2572. menu.addSeparator(parent);
  2573. if (isLocalStorage && urlParams['browser'] != '0')
  2574. {
  2575. menu.addItem(mxResources.get('browser') + '...', null, function()
  2576. {
  2577. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  2578. }, parent);
  2579. }
  2580. //if (!mxClient.IS_IOS)
  2581. {
  2582. menu.addItem(mxResources.get('device') + '...', null, function()
  2583. {
  2584. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  2585. }, parent);
  2586. }
  2587. }));
  2588. this.put('openLibraryFrom', new Menu(function(menu, parent)
  2589. {
  2590. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2591. {
  2592. if (editorUi.drive != null)
  2593. {
  2594. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2595. {
  2596. editorUi.pickLibrary(App.MODE_GOOGLE);
  2597. }, parent);
  2598. }
  2599. else if (googleEnabled && typeof window.DriveClient === 'function')
  2600. {
  2601. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2602. {
  2603. // do nothing
  2604. }, parent, null, false);
  2605. }
  2606. }
  2607. if (editorUi.oneDrive != null)
  2608. {
  2609. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2610. {
  2611. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  2612. }, parent);
  2613. }
  2614. else if (oneDriveEnabled && typeof window.OneDriveClient === 'function')
  2615. {
  2616. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2617. {
  2618. // do nothing
  2619. }, parent, null, false);
  2620. }
  2621. if (editorUi.dropbox != null)
  2622. {
  2623. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2624. {
  2625. editorUi.pickLibrary(App.MODE_DROPBOX);
  2626. }, parent);
  2627. }
  2628. else if (dropboxEnabled && typeof window.DropboxClient === 'function')
  2629. {
  2630. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2631. {
  2632. // do nothing
  2633. }, parent, null, false);
  2634. }
  2635. menu.addSeparator(parent);
  2636. if (editorUi.gitHub != null)
  2637. {
  2638. menu.addItem(mxResources.get('github') + '...', null, function()
  2639. {
  2640. editorUi.pickLibrary(App.MODE_GITHUB);
  2641. }, parent);
  2642. }
  2643. if (editorUi.gitLab != null)
  2644. {
  2645. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  2646. {
  2647. editorUi.pickLibrary(App.MODE_GITLAB);
  2648. }, parent);
  2649. }
  2650. if (editorUi.trello != null)
  2651. {
  2652. menu.addItem(mxResources.get('trello') + '...', null, function()
  2653. {
  2654. editorUi.pickLibrary(App.MODE_TRELLO);
  2655. }, parent);
  2656. }
  2657. else if (trelloEnabled && typeof window.TrelloClient === 'function')
  2658. {
  2659. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2660. {
  2661. // do nothing
  2662. }, parent, null, false);
  2663. }
  2664. menu.addSeparator(parent);
  2665. if (isLocalStorage && urlParams['browser'] != '0')
  2666. {
  2667. menu.addItem(mxResources.get('browser') + '...', null, function()
  2668. {
  2669. editorUi.pickLibrary(App.MODE_BROWSER);
  2670. }, parent);
  2671. }
  2672. //if (!mxClient.IS_IOS)
  2673. {
  2674. menu.addItem(mxResources.get('device') + '...', null, function()
  2675. {
  2676. editorUi.pickLibrary(App.MODE_DEVICE);
  2677. }, parent);
  2678. }
  2679. if (!editorUi.isOffline())
  2680. {
  2681. menu.addSeparator(parent);
  2682. menu.addItem(mxResources.get('url') + '...', null, function()
  2683. {
  2684. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  2685. {
  2686. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2687. {
  2688. var realUrl = fileUrl;
  2689. if (!editorUi.editor.isCorsEnabledForUrl(fileUrl))
  2690. {
  2691. realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
  2692. }
  2693. // Uses proxy to avoid CORS issues
  2694. mxUtils.get(realUrl, function(req)
  2695. {
  2696. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  2697. {
  2698. editorUi.spinner.stop();
  2699. try
  2700. {
  2701. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  2702. }
  2703. catch (e)
  2704. {
  2705. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  2706. }
  2707. }
  2708. else
  2709. {
  2710. editorUi.spinner.stop();
  2711. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2712. }
  2713. }, function()
  2714. {
  2715. editorUi.spinner.stop();
  2716. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2717. });
  2718. }
  2719. }, mxResources.get('url'));
  2720. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2721. dlg.init();
  2722. }, parent);
  2723. }
  2724. if (urlParams['confLib'] == '1')
  2725. {
  2726. menu.addSeparator(parent);
  2727. menu.addItem(mxResources.get('confluenceCloud') + '...', null, function()
  2728. {
  2729. editorUi.showRemotelyStoredLibrary(mxResources.get('libraries'));
  2730. }, parent);
  2731. }
  2732. }));
  2733. }
  2734. // Overrides edit menu to add find and editGeometry
  2735. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  2736. {
  2737. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy']);
  2738. if (EditorUi.isElectronApp)
  2739. {
  2740. this.addMenuItems(menu, ['copyAsImage']);
  2741. }
  2742. this.addMenuItems(menu, ['paste', 'delete', '-', 'duplicate', '-', 'find', '-', 'editData', 'editTooltip', '-',
  2743. 'editStyle', 'editGeometry', '-', 'edit', '-', 'editLink', 'openLink', '-',
  2744. 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
  2745. })));
  2746. var action = editorUi.actions.addAction('comments', mxUtils.bind(this, function()
  2747. {
  2748. if (this.commentsWindow == null)
  2749. {
  2750. // LATER: Check outline window for initial placement
  2751. this.commentsWindow = new CommentsWindow(editorUi, document.body.offsetWidth - 380, 120, 300, 350);
  2752. //TODO Are these events needed?
  2753. this.commentsWindow.window.addListener('show', function()
  2754. {
  2755. editorUi.fireEvent(new mxEventObject('comments'));
  2756. });
  2757. this.commentsWindow.window.addListener('hide', function()
  2758. {
  2759. editorUi.fireEvent(new mxEventObject('comments'));
  2760. });
  2761. this.commentsWindow.window.setVisible(true);
  2762. editorUi.fireEvent(new mxEventObject('comments'));
  2763. }
  2764. else
  2765. {
  2766. var isVisible = !this.commentsWindow.window.isVisible();
  2767. this.commentsWindow.window.setVisible(isVisible);
  2768. this.commentsWindow.refreshCommentsTime();
  2769. if (isVisible && this.commentsWindow.hasError)
  2770. {
  2771. this.commentsWindow.refreshComments();
  2772. }
  2773. }
  2774. }));
  2775. action.setToggleAction(true);
  2776. action.setSelectedCallback(mxUtils.bind(this, function() { return this.commentsWindow != null && this.commentsWindow.window.isVisible(); }));
  2777. // Destroys comments window to force update or disable if not supported
  2778. editorUi.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  2779. {
  2780. if (this.commentsWindow != null)
  2781. {
  2782. this.commentsWindow.destroy();
  2783. this.commentsWindow = null;
  2784. }
  2785. }));
  2786. // Extends toolbar dropdown to add comments
  2787. var viewPanelsMenu = this.get('viewPanels');
  2788. var viewPanelsFunct = viewPanelsMenu.funct;
  2789. viewPanelsMenu.funct = function(menu, parent)
  2790. {
  2791. viewPanelsFunct.apply(this, arguments);
  2792. if (editorUi.commentsSupported())
  2793. {
  2794. editorUi.menus.addMenuItems(menu, ['comments'], parent);
  2795. }
  2796. };
  2797. // Overrides view menu to add search and scratchpad
  2798. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  2799. {
  2800. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  2801. concat(['outline', 'layers']).concat((editorUi.commentsSupported()) ?
  2802. ['comments', '-'] : ['-']));
  2803. this.addMenuItems(menu, ['-', 'search'], parent);
  2804. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  2805. {
  2806. var item = this.addMenuItem(menu, 'scratchpad', parent);
  2807. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2808. {
  2809. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000042367');
  2810. }
  2811. }
  2812. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale']);
  2813. this.addSubmenu('units', menu, parent);
  2814. this.addMenuItems(menu, ['-', 'scrollbars', 'tooltips', 'ruler', '-',
  2815. 'grid', 'guides'], parent);
  2816. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  2817. {
  2818. this.addMenuItem(menu, 'shadowVisible', parent);
  2819. }
  2820. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  2821. 'resetView', 'zoomIn', 'zoomOut'], parent);
  2822. })));
  2823. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  2824. {
  2825. if (urlParams['embed'] != '1')
  2826. {
  2827. this.addSubmenu('theme', menu, parent);
  2828. menu.addSeparator(parent);
  2829. }
  2830. if (typeof(MathJax) !== 'undefined')
  2831. {
  2832. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  2833. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2834. {
  2835. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  2836. }
  2837. }
  2838. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  2839. if (urlParams['embed'] != '1' && (isLocalStorage || mxClient.IS_CHROMEAPP))
  2840. {
  2841. this.addMenuItems(menu, ['showStartScreen'], parent);
  2842. }
  2843. if (urlParams['embed'] != '1')
  2844. {
  2845. this.addMenuItems(menu, ['autosave'], parent);
  2846. }
  2847. menu.addSeparator(parent);
  2848. if (!editorUi.isOfflineApp() && isLocalStorage)
  2849. {
  2850. this.addMenuItem(menu, 'plugins', parent);
  2851. }
  2852. this.addMenuItems(menu, ['tags', '-', 'editDiagram', '-', 'configuration'], parent);
  2853. // Adds trailing separator in case new plugin entries are added
  2854. menu.addSeparator(parent);
  2855. if (urlParams['newTempDlg'] == '1')
  2856. {
  2857. editorUi.actions.addAction('templates', function()
  2858. {
  2859. var tempDlg = new TemplatesDialog();
  2860. editorUi.showDialog(tempDlg.container, tempDlg.width, tempDlg.height, true, false, null, false, true);
  2861. tempDlg.init(editorUi, function(xml){console.log(xml)}, null,
  2862. null, null, 'user', function(callback, username)
  2863. {
  2864. setTimeout(function(){
  2865. username? callback([
  2866. {url: '123', title: 'Test 1Test 1Test 1Test 1Test 1Test 1Test 11Test 1Test 11Test 1Test 1dgdsgdfg fdg dfgdfg dfg dfg'},
  2867. {url: '123', title: 'Test 2', imgUrl: 'https://www.google.com.eg/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
  2868. {url: '123', title: 'Test 3', changedBy: 'Ashraf Teleb', lastModifiedOn: 'Yesterday'},
  2869. {url: '123', title: 'Test 4'},
  2870. {url: '123', title: 'Test 5'},
  2871. {url: '123', title: 'Test 6'}
  2872. ]) : callback([
  2873. {url: '123', title: 'Test 4', imgUrl: 'https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg'},
  2874. {url: '123', title: 'Test 5'},
  2875. {url: '123', title: 'Test 6'},
  2876. {url: '123', title: 'Test 1Test 1Test 1Test 1Test 1Test 1Test 11Test 1Test 11Test 1Test 1dgdsgdfg fdg dfgdfg dfg dfg'},
  2877. {url: '123', title: 'Test 2', imgUrl: 'https://www.google.com.eg/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'},
  2878. {url: '123', title: 'Test 3', changedBy: 'Ashraf Teleb', lastModifiedOn: 'Yesterday'}
  2879. ]);
  2880. console.log(username);
  2881. }, 1000);
  2882. }, function(str, callback, username)
  2883. {
  2884. setTimeout(function(){
  2885. callback(username? [
  2886. {url: '123', title: str +'Test 1Test 1Test 1Test 1Test 1Test 1Test 1'},
  2887. {url: '123', title: str +'Test 2'},
  2888. {url: '123', title: str +'Test 3'},
  2889. {url: '123', title: str +'Test 4'},
  2890. {url: '123', title: str +'Test 5'},
  2891. {url: '123', title: str +'Test 6'}
  2892. ]: [
  2893. {url: '123', title: str +'Test 5'},
  2894. {url: '123', title: str +'Test 6'},
  2895. {url: '123', title: str +'Test 1Test 1Test 1Test 1Test 1Test 1Test 1'},
  2896. {url: '123', title: str +'Test 2'},
  2897. {url: '123', title: str +'Test 3'},
  2898. {url: '123', title: str +'Test 4'}
  2899. ]);
  2900. }, 2000);
  2901. }, null);
  2902. });
  2903. this.addMenuItem(menu, 'templates', parent);
  2904. }
  2905. })));
  2906. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  2907. {
  2908. if (urlParams['embed'] == '1')
  2909. {
  2910. this.addSubmenu('importFrom', menu, parent);
  2911. this.addSubmenu('exportAs', menu, parent);
  2912. this.addSubmenu('embed', menu, parent);
  2913. if (urlParams['libraries'] == '1')
  2914. {
  2915. this.addMenuItems(menu, ['-'], parent);
  2916. this.addSubmenu('newLibrary', menu, parent);
  2917. this.addSubmenu('openLibraryFrom', menu, parent);
  2918. }
  2919. if (editorUi.isRevisionHistorySupported())
  2920. {
  2921. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  2922. }
  2923. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'rename'], parent);
  2924. if (urlParams['noSaveBtn'] == '1')
  2925. {
  2926. if (urlParams['saveAndExit'] != '0')
  2927. {
  2928. this.addMenuItems(menu, ['saveAndExit'], parent);
  2929. }
  2930. }
  2931. else
  2932. {
  2933. this.addMenuItems(menu, ['save'], parent);
  2934. if (urlParams['saveAndExit'] == '1')
  2935. {
  2936. this.addMenuItems(menu, ['saveAndExit'], parent);
  2937. }
  2938. }
  2939. if (urlParams['noExitBtn'] != '1')
  2940. {
  2941. this.addMenuItems(menu, ['exit'], parent);
  2942. }
  2943. }
  2944. else
  2945. {
  2946. var file = this.editorUi.getCurrentFile();
  2947. if (file != null && file.constructor == DriveFile)
  2948. {
  2949. if (file.isRestricted())
  2950. {
  2951. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  2952. }
  2953. this.addMenuItems(menu, ['save', '-', 'share'], parent);
  2954. var item = this.addMenuItem(menu, 'synchronize', parent);
  2955. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2956. {
  2957. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000087947');
  2958. }
  2959. menu.addSeparator(parent);
  2960. }
  2961. else
  2962. {
  2963. this.addMenuItems(menu, ['new'], parent);
  2964. }
  2965. this.addSubmenu('openFrom', menu, parent);
  2966. if (isLocalStorage)
  2967. {
  2968. this.addSubmenu('openRecent', menu, parent);
  2969. }
  2970. if (file != null && file.constructor == DriveFile)
  2971. {
  2972. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  2973. }
  2974. else
  2975. {
  2976. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  2977. file != null && (file.constructor != LocalFile ||
  2978. file.fileHandle != null))
  2979. {
  2980. menu.addSeparator(parent);
  2981. var item = this.addMenuItem(menu, 'synchronize', parent);
  2982. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2983. {
  2984. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000087947');
  2985. }
  2986. }
  2987. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-'], parent);
  2988. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  2989. editorUi.getServiceName() == 'draw.io' &&
  2990. !editorUi.isOfflineApp() && file != null)
  2991. {
  2992. this.addMenuItems(menu, ['share', '-'], parent);
  2993. }
  2994. this.addMenuItems(menu, ['rename'], parent);
  2995. if (editorUi.isOfflineApp())
  2996. {
  2997. if (navigator.onLine && urlParams['stealth'] != '1')
  2998. {
  2999. this.addMenuItems(menu, ['upload'], parent);
  3000. }
  3001. }
  3002. else
  3003. {
  3004. this.addMenuItems(menu, ['makeCopy'], parent);
  3005. if (file != null && file.constructor == OneDriveFile)
  3006. {
  3007. this.addMenuItems(menu, ['moveToFolder'], parent);
  3008. }
  3009. }
  3010. }
  3011. menu.addSeparator(parent);
  3012. this.addSubmenu('importFrom', menu, parent);
  3013. this.addSubmenu('exportAs', menu, parent);
  3014. menu.addSeparator(parent);
  3015. this.addSubmenu('embed', menu, parent);
  3016. this.addSubmenu('publish', menu, parent);
  3017. menu.addSeparator(parent);
  3018. this.addSubmenu('newLibrary', menu, parent);
  3019. this.addSubmenu('openLibraryFrom', menu, parent);
  3020. if (editorUi.isRevisionHistorySupported())
  3021. {
  3022. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  3023. }
  3024. if (file != null && editorUi.fileNode != null)
  3025. {
  3026. var filename = (file.getTitle() != null) ?
  3027. file.getTitle() : editorUi.defaultFilename;
  3028. if (!/(\.html)$/i.test(filename) &&
  3029. !/(\.svg)$/i.test(filename))
  3030. {
  3031. this.addMenuItems(menu, ['-', 'properties']);
  3032. }
  3033. }
  3034. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  3035. // Cannot use print in standalone mode on iOS as we cannot open new windows
  3036. if (!mxClient.IS_IOS || !navigator.standalone)
  3037. {
  3038. this.addMenuItems(menu, ['print'], parent);
  3039. }
  3040. this.addMenuItems(menu, ['-', 'close']);
  3041. }
  3042. })));
  3043. /**
  3044. * External Fonts undoable change
  3045. */
  3046. function ChangeExtFonts(ui, extFonts, customFonts)
  3047. {
  3048. this.ui = ui;
  3049. this.extFonts = extFonts;
  3050. this.previousExtFonts = extFonts;
  3051. this.customFonts = customFonts;
  3052. this.prevCustomFonts = customFonts;
  3053. };
  3054. /**
  3055. * Implementation of the undoable External Fonts Change.
  3056. */
  3057. ChangeExtFonts.prototype.execute = function()
  3058. {
  3059. var graph = this.ui.editor.graph;
  3060. this.customFonts = this.prevCustomFonts;
  3061. this.prevCustomFonts = this.ui.menus.customFonts;
  3062. this.ui.fireEvent(new mxEventObject('customFontsChanged', 'customFonts', this.customFonts));
  3063. this.extFonts = this.previousExtFonts;
  3064. var tmp = graph.extFonts;
  3065. for (var i = 0; tmp != null && i < tmp.length; i++)
  3066. {
  3067. var fontElem = document.getElementById('extFont_' + tmp[i].name);
  3068. if (fontElem != null)
  3069. {
  3070. fontElem.parentNode.removeChild(fontElem);
  3071. }
  3072. }
  3073. graph.extFonts = [];
  3074. for (var i = 0; this.previousExtFonts != null && i < this.previousExtFonts.length; i++)
  3075. {
  3076. this.ui.editor.graph.addExtFont(this.previousExtFonts[i].name, this.previousExtFonts[i].url);
  3077. }
  3078. this.previousExtFonts = tmp;
  3079. };
  3080. //Replace the default font family menu
  3081. this.put('fontFamily', new Menu(mxUtils.bind(this, function(menu, parent)
  3082. {
  3083. var addItem = mxUtils.bind(this, function(fontName, fontUrl, deletable, fontLabel, tooltip)
  3084. {
  3085. var graph = this.editorUi.editor.graph;
  3086. var tr = this.styleChange(menu, fontLabel || fontName,
  3087. (urlParams['ext-fonts'] != '1') ?
  3088. [mxConstants.STYLE_FONTFAMILY, 'fontSource', 'FType'] : [mxConstants.STYLE_FONTFAMILY],
  3089. (urlParams['ext-fonts'] != '1') ?
  3090. [fontName, (fontUrl != null) ? encodeURIComponent(fontUrl) : null, null] : [fontName],
  3091. null, parent, function()
  3092. {
  3093. if (urlParams['ext-fonts'] != '1')
  3094. {
  3095. graph.setFont(fontName, fontUrl);
  3096. }
  3097. else
  3098. {
  3099. document.execCommand('fontname', false, fontName);
  3100. //Add the font to the file in case it was a previous font from the settings
  3101. graph.addExtFont(fontName, fontUrl);
  3102. }
  3103. }, function()
  3104. {
  3105. graph.updateLabelElements(graph.getSelectionCells(), function(elt)
  3106. {
  3107. elt.removeAttribute('face');
  3108. elt.style.fontFamily = null;
  3109. if (elt.nodeName == 'PRE')
  3110. {
  3111. graph.replaceElement(elt, 'div');
  3112. }
  3113. });
  3114. //Add the font to the file in case it was a previous font from the settings
  3115. if (urlParams['ext-fonts'] == '1')
  3116. {
  3117. graph.addExtFont(fontName, fontUrl);
  3118. }
  3119. });
  3120. if (deletable)
  3121. {
  3122. var img = document.createElement('span');
  3123. img.className = 'geSprite geSprite-delete';
  3124. img.style.cursor = 'pointer';
  3125. img.style.display = 'inline-block';
  3126. tr.firstChild.nextSibling.nextSibling.appendChild(img);
  3127. mxEvent.addListener(img, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', mxUtils.bind(this, function(evt)
  3128. {
  3129. if (urlParams['ext-fonts'] != '1')
  3130. {
  3131. delete Graph.recentCustomFonts[fontName.toLowerCase()];
  3132. for (var i = 0; i < this.customFonts.length; i++)
  3133. {
  3134. if (this.customFonts[i].name == fontName &&
  3135. this.customFonts[i].url == fontUrl)
  3136. {
  3137. this.customFonts.splice(i, 1);
  3138. editorUi.fireEvent(new mxEventObject('customFontsChanged'));
  3139. break;
  3140. }
  3141. }
  3142. }
  3143. else
  3144. {
  3145. var extFonts = mxUtils.clone(this.editorUi.editor.graph.extFonts);
  3146. if (extFonts != null && extFonts.length > 0)
  3147. {
  3148. for (var i = 0; i < extFonts.length; i++)
  3149. {
  3150. if (extFonts[i].name == fontName)
  3151. {
  3152. extFonts.splice(i, 1);
  3153. break;
  3154. }
  3155. }
  3156. }
  3157. var customFonts = mxUtils.clone(this.customFonts);
  3158. for (var i = 0; i < customFonts.length; i++)
  3159. {
  3160. if (customFonts[i].name == fontName)
  3161. {
  3162. customFonts.splice(i, 1);
  3163. break;
  3164. }
  3165. }
  3166. var change = new ChangeExtFonts(this.editorUi, extFonts, customFonts);
  3167. this.editorUi.editor.graph.model.execute(change);
  3168. }
  3169. this.editorUi.menubar.hideMenu();
  3170. mxEvent.consume(evt);
  3171. }));
  3172. }
  3173. Graph.addFont(fontName, fontUrl);
  3174. tr.firstChild.nextSibling.style.fontFamily = fontName;
  3175. if (tooltip != null)
  3176. {
  3177. tr.setAttribute('title', tooltip);
  3178. }
  3179. });
  3180. for (var i = 0; i < this.defaultFonts.length; i++)
  3181. {
  3182. addItem(this.defaultFonts[i]);
  3183. }
  3184. menu.addSeparator(parent);
  3185. if (urlParams['ext-fonts'] != '1')
  3186. {
  3187. // Special entries in the font menu are composed of custom fonts
  3188. // from the local storage and actual used fonts in the file
  3189. var duplicates = {};
  3190. var fontNames = {};
  3191. var entries = [];
  3192. function addEntry(entry)
  3193. {
  3194. var key = encodeURIComponent(entry.name) +
  3195. ((entry.url == null) ? '' :
  3196. '@' + encodeURIComponent(entry.url));
  3197. var label = entry.name;
  3198. var counter = 0;
  3199. while (fontNames[label.toLowerCase()] != null)
  3200. {
  3201. label = entry.name + ' (' + (++counter) + ')';
  3202. }
  3203. if (duplicates[key] == null)
  3204. {
  3205. entries.push({name: entry.name, url: entry.url,
  3206. label: label, title: entry.url});
  3207. fontNames[label.toLowerCase()] = entry;
  3208. duplicates[key] = entry;
  3209. }
  3210. };
  3211. // Adds custom user defined fonts from local storage
  3212. for (var i = 0; i < this.customFonts.length; i++)
  3213. {
  3214. addEntry(this.customFonts[i], false);
  3215. }
  3216. // Adds fonts that were recently used in the editor
  3217. for (var key in Graph.recentCustomFonts)
  3218. {
  3219. addEntry(Graph.recentCustomFonts[key], true);
  3220. }
  3221. // Sorts by label
  3222. entries.sort(function(a, b)
  3223. {
  3224. if (a.label < b.label)
  3225. {
  3226. return -1;
  3227. }
  3228. else if (a.label > b.label)
  3229. {
  3230. return 1;
  3231. }
  3232. else
  3233. {
  3234. return 0;
  3235. }
  3236. });
  3237. if (entries.length > 0)
  3238. {
  3239. for (var i = 0; i < entries.length; i++)
  3240. {
  3241. addItem(entries[i].name, entries[i].url, true,
  3242. entries[i].label, entries[i].url);
  3243. }
  3244. menu.addSeparator(parent);
  3245. }
  3246. menu.addItem(mxResources.get('reset'), null, mxUtils.bind(this, function()
  3247. {
  3248. Graph.recentCustomFonts = {};
  3249. this.customFonts = [];
  3250. editorUi.fireEvent(new mxEventObject('customFontsChanged'));
  3251. }), parent);
  3252. menu.addSeparator(parent);
  3253. }
  3254. else
  3255. {
  3256. //Load custom fonts already in the Graph
  3257. var extFonts = this.editorUi.editor.graph.extFonts;
  3258. //Merge external fonts with custom fonts
  3259. if (extFonts != null && extFonts.length > 0)
  3260. {
  3261. var custMap = {}, changed = false;
  3262. for (var i = 0; i < this.customFonts.length; i++)
  3263. {
  3264. custMap[this.customFonts[i].name] = true;
  3265. }
  3266. for (var i = 0; i < extFonts.length; i++)
  3267. {
  3268. if (!custMap[extFonts[i].name])
  3269. {
  3270. this.customFonts.push(extFonts[i]);
  3271. changed = true;
  3272. }
  3273. }
  3274. if (changed)
  3275. {
  3276. this.editorUi.fireEvent(new mxEventObject('customFontsChanged', 'customFonts', this.customFonts));
  3277. }
  3278. }
  3279. if (this.customFonts.length > 0)
  3280. {
  3281. for (var i = 0; i < this.customFonts.length; i++)
  3282. {
  3283. var name = this.customFonts[i].name, url = this.customFonts[i].url;
  3284. addItem(name, url, true);
  3285. //Load external fonts without saving them to the file
  3286. this.editorUi.editor.graph.addExtFont(name, url, true);
  3287. }
  3288. menu.addSeparator(parent);
  3289. menu.addItem(mxResources.get('reset'), null, mxUtils.bind(this, function()
  3290. {
  3291. var change = new ChangeExtFonts(this.editorUi, [], []);
  3292. editorUi.editor.graph.model.execute(change);
  3293. }), parent);
  3294. menu.addSeparator(parent);
  3295. }
  3296. }
  3297. menu.addItem(mxResources.get('custom') + '...', null, mxUtils.bind(this, function()
  3298. {
  3299. var graph = this.editorUi.editor.graph;
  3300. var curFontName = graph.getStylesheet().getDefaultVertexStyle()
  3301. [mxConstants.STYLE_FONTFAMILY];
  3302. var curType = 's';
  3303. var curUrl = null;
  3304. // Handles in-place editing custom fonts via font family lookup
  3305. if (urlParams['ext-fonts'] != '1' && graph.isEditing())
  3306. {
  3307. var node = graph.getSelectedEditingElement();
  3308. if (node != null)
  3309. {
  3310. var css = mxUtils.getCurrentStyle(node);
  3311. if (css != null)
  3312. {
  3313. curFontName = Graph.stripQuotes(css.fontFamily);
  3314. curUrl = Graph.getFontUrl(curFontName, null);
  3315. if (curUrl != null)
  3316. {
  3317. if (Graph.isGoogleFontUrl(curUrl))
  3318. {
  3319. curUrl = null;
  3320. curType = 'g';
  3321. }
  3322. else
  3323. {
  3324. curType = 'w';
  3325. }
  3326. }
  3327. }
  3328. }
  3329. }
  3330. else
  3331. {
  3332. var state = graph.getView().getState(graph.getSelectionCell());
  3333. if (state != null)
  3334. {
  3335. curFontName = state.style[mxConstants.STYLE_FONTFAMILY] || curFontName;
  3336. if (urlParams['ext-fonts'] != '1')
  3337. {
  3338. var temp = state.style['fontSource'];
  3339. if (temp != null)
  3340. {
  3341. temp = decodeURIComponent(temp);
  3342. if (Graph.isGoogleFontUrl(temp))
  3343. {
  3344. curType = 'g';
  3345. }
  3346. else
  3347. {
  3348. curType = 'w';
  3349. curUrl = temp;
  3350. }
  3351. }
  3352. }
  3353. else
  3354. {
  3355. curType = state.style['FType'] || curType;
  3356. if (curType == 'w')
  3357. {
  3358. var extFonts = this.editorUi.editor.graph.extFonts;
  3359. var webFont = null;
  3360. if (extFonts != null)
  3361. {
  3362. webFont = extFonts.find(function(ef)
  3363. {
  3364. return ef.name == curFontName;
  3365. });
  3366. }
  3367. // TODO: Resource is not defined
  3368. curUrl = webFont != null? webFont.url : mxResources.get('urlNotFound', null, 'URL not found');
  3369. }
  3370. }
  3371. }
  3372. }
  3373. if (curUrl != null && curUrl.substring(0, PROXY_URL.length) == PROXY_URL)
  3374. {
  3375. curUrl = decodeURIComponent(curUrl.substr((PROXY_URL + '?url=').length));
  3376. }
  3377. // Saves the current selection state
  3378. var selState = null;
  3379. if (document.activeElement == graph.cellEditor.textarea)
  3380. {
  3381. selState = graph.cellEditor.saveSelection();
  3382. }
  3383. var dlg = new FontDialog(this.editorUi, curFontName, curUrl, curType, mxUtils.bind(this, function(fontName, fontUrl, type)
  3384. {
  3385. // Restores the selection state
  3386. if (selState != null)
  3387. {
  3388. graph.cellEditor.restoreSelection(selState);
  3389. selState = null;
  3390. }
  3391. if (fontName != null && fontName.length > 0)
  3392. {
  3393. if (urlParams['ext-fonts'] != '1' && graph.isEditing())
  3394. {
  3395. graph.setFont(fontName, fontUrl);
  3396. }
  3397. else
  3398. {
  3399. graph.getModel().beginUpdate();
  3400. try
  3401. {
  3402. graph.stopEditing(false);
  3403. if (urlParams['ext-fonts'] != '1')
  3404. {
  3405. graph.setCellStyles(mxConstants.STYLE_FONTFAMILY, fontName);
  3406. graph.setCellStyles('fontSource', (fontUrl != null) ?
  3407. encodeURIComponent(fontUrl) : null);
  3408. graph.setCellStyles('FType', null);
  3409. }
  3410. else
  3411. {
  3412. graph.setCellStyles(mxConstants.STYLE_FONTFAMILY, fontName);
  3413. if (type != 's')
  3414. {
  3415. graph.setCellStyles('FType', type);
  3416. if (fontUrl.indexOf('http://') == 0)
  3417. {
  3418. fontUrl = PROXY_URL + '?url=' + encodeURIComponent(fontUrl);
  3419. }
  3420. this.editorUi.editor.graph.addExtFont(fontName, fontUrl);
  3421. }
  3422. }
  3423. var addToCustom = true;
  3424. for (var i = 0; i < this.customFonts.length; i++)
  3425. {
  3426. if (this.customFonts[i].name == fontName)
  3427. {
  3428. addToCustom = false;
  3429. break;
  3430. }
  3431. }
  3432. if (addToCustom)
  3433. {
  3434. this.customFonts.push({name: fontName, url: fontUrl});
  3435. this.editorUi.fireEvent(new mxEventObject('customFontsChanged', 'customFonts', this.customFonts));
  3436. }
  3437. }
  3438. finally
  3439. {
  3440. graph.getModel().endUpdate();
  3441. }
  3442. }
  3443. }
  3444. }));
  3445. this.editorUi.showDialog(dlg.container, 380, 250, true, true);
  3446. dlg.init();
  3447. }), parent, null, true);
  3448. })));
  3449. };
  3450. })();