Menus.js 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585
  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. this.div.style.overflowY = 'auto';
  12. this.div.style.overflowX = 'hidden';
  13. var h0 = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
  14. this.div.style.maxHeight = (h0 - (EditorUi.isElectronApp? 50 : 10)) + 'px'; //In Electron and without titlebar, the top item is not selectable
  15. mxPopupMenuShowMenu.apply(this, arguments);
  16. };
  17. Menus.prototype.createHelpLink = function(href)
  18. {
  19. var link = document.createElement('div');
  20. link.setAttribute('title', mxResources.get('help'));
  21. link.style.display = 'inline-flex';
  22. link.style.alignItems = 'center';
  23. link.style.marginLeft = '4px';
  24. link.style.cursor = 'help';
  25. link.style.color = 'blue';
  26. var icon = document.createElement('img');
  27. icon.setAttribute('src', Editor.helpImage);
  28. icon.setAttribute('valign', 'bottom');
  29. icon.setAttribute('border', '0');
  30. icon.className = 'geAdaptiveAsset';
  31. mxUtils.setOpacity(icon, 60);
  32. icon.style.height = '16px';
  33. icon.style.width = '16px';
  34. link.appendChild(icon);
  35. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  36. {
  37. this.editorUi.hideCurrentMenu();
  38. this.editorUi.openLink(href);
  39. mxEvent.consume(evt);
  40. }));
  41. return link;
  42. };
  43. Menus.prototype.addLinkToItem = function(item, href)
  44. {
  45. if (item != null)
  46. {
  47. var link = this.createHelpLink(href);
  48. link.style.display = 'inline';
  49. link.style.marginLeft = '8px';
  50. item.firstChild.nextSibling.appendChild(link);
  51. }
  52. };
  53. /**
  54. * Removes the given font from the list of custom fonts.
  55. */
  56. Menus.prototype.removeCustomFont = function(name, url)
  57. {
  58. for (var i = 0; i < this.customFonts.length; i++)
  59. {
  60. if (this.customFonts[i].name == name &&
  61. this.customFonts[i].url == url)
  62. {
  63. this.customFonts.splice(i, 1);
  64. this.editorUi.fireEvent(
  65. new mxEventObject('customFontsChanged',
  66. 'customFonts', this.customFonts));
  67. break;
  68. }
  69. }
  70. };
  71. /**
  72. * Returns true if the given font is in the list of custom fonts.
  73. */
  74. Menus.prototype.containsFont = function(name, url)
  75. {
  76. for (var i = 0; i < this.customFonts.length; i++)
  77. {
  78. if (this.customFonts[i].name == name &&
  79. this.customFonts[i].url == url)
  80. {
  81. return true;
  82. }
  83. }
  84. for (var i = 0; i < this.defaultFonts.length; i++)
  85. {
  86. var value = this.defaultFonts[i];
  87. if ((typeof value !== 'string' &&
  88. value.fontFamily == name &&
  89. value.fontUrl == url) ||
  90. (typeof value === 'string' &&
  91. value == name && url == null))
  92. {
  93. return true;
  94. }
  95. }
  96. return false;
  97. };
  98. /**
  99. * Adds the given font to the list of custom fonts.
  100. */
  101. Menus.prototype.addCustomFont = function(name, url)
  102. {
  103. if (name != null && !this.containsFont(name, url))
  104. {
  105. this.customFonts.push({name: name, url: url});
  106. this.editorUi.fireEvent(
  107. new mxEventObject('customFontsChanged',
  108. 'customFonts', this.customFonts));
  109. }
  110. };
  111. var menusInit = Menus.prototype.init;
  112. Menus.prototype.init = function()
  113. {
  114. menusInit.apply(this, arguments);
  115. var editorUi = this.editorUi;
  116. var graph = editorUi.editor.graph;
  117. var isGraphEnabled = mxUtils.bind(graph, graph.isEnabled);
  118. if (!mxClient.IS_SVG && !editorUi.isOffline())
  119. {
  120. var img = new Image();
  121. img.src = IMAGE_PATH + '/help.png';
  122. }
  123. if (urlParams['noFileMenu'] == '1')
  124. {
  125. this.defaultMenuItems = this.defaultMenuItems.filter(function(m)
  126. {
  127. return m != 'file';
  128. });
  129. }
  130. editorUi.actions.addAction('new...', function()
  131. {
  132. var compact = editorUi.isOffline();
  133. var dlg = new NewDialog(editorUi, compact, !(editorUi.mode == App.MODE_DEVICE && 'chooseFileSystemEntries' in window));
  134. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 460, true, true, function(cancel)
  135. {
  136. editorUi.sidebar.hideTooltip();
  137. if (cancel && editorUi.getCurrentFile() == null)
  138. {
  139. editorUi.showSplash();
  140. }
  141. });
  142. dlg.init();
  143. });
  144. editorUi.actions.put('insertTemplate', new Action(mxResources.get('template') + '...', function()
  145. {
  146. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  147. {
  148. var dlg = new NewDialog(editorUi, null, false, function(xml)
  149. {
  150. editorUi.hideDialog();
  151. if (xml != null)
  152. {
  153. var insertPoint = editorUi.editor.graph.getFreeInsertPoint();
  154. graph.setSelectionCells(editorUi.importXml(xml,
  155. Math.max(insertPoint.x, 20),
  156. Math.max(insertPoint.y, 20),
  157. true, null, null, true));
  158. graph.scrollCellToVisible(graph.getSelectionCell());
  159. }
  160. }, null, null, null, null, null, null, null, null, null, null,
  161. false, mxResources.get('insert'));
  162. editorUi.showDialog(dlg.container, 620, 460, true, true, function()
  163. {
  164. editorUi.sidebar.hideTooltip();
  165. });
  166. dlg.init();
  167. }
  168. })).isEnabled = isGraphEnabled;
  169. var shareCursorAction = editorUi.actions.addAction('shareCursor', function()
  170. {
  171. editorUi.setShareCursorPosition(!editorUi.isShareCursorPosition());;
  172. });
  173. shareCursorAction.setToggleAction(true);
  174. shareCursorAction.setSelectedCallback(function() { return editorUi.isShareCursorPosition(); });
  175. var showRemoteCursorsAction = editorUi.actions.addAction('showRemoteCursors', function()
  176. {
  177. editorUi.setShowRemoteCursors(!editorUi.isShowRemoteCursors());;
  178. });
  179. showRemoteCursorsAction.setToggleAction(true);
  180. showRemoteCursorsAction.setSelectedCallback(function() { return editorUi.isShowRemoteCursors(); });
  181. var pointAction = editorUi.actions.addAction('points', function()
  182. {
  183. editorUi.editor.graph.view.setUnit(mxConstants.POINTS);
  184. });
  185. pointAction.setToggleAction(true);
  186. pointAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.POINTS; });
  187. var inchAction = editorUi.actions.addAction('inches', function()
  188. {
  189. editorUi.editor.graph.view.setUnit(mxConstants.INCHES);
  190. });
  191. inchAction.setToggleAction(true);
  192. inchAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.INCHES; });
  193. var mmAction = editorUi.actions.addAction('millimeters', function()
  194. {
  195. editorUi.editor.graph.view.setUnit(mxConstants.MILLIMETERS);
  196. });
  197. mmAction.setToggleAction(true);
  198. mmAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.MILLIMETERS; });
  199. var meterAction = editorUi.actions.addAction('meters', function()
  200. {
  201. editorUi.editor.graph.view.setUnit(mxConstants.METERS);
  202. });
  203. meterAction.setToggleAction(true);
  204. meterAction.setSelectedCallback(function() { return editorUi.editor.graph.view.unit == mxConstants.METERS; });
  205. this.put('units', new Menu(mxUtils.bind(this, function(menu, parent)
  206. {
  207. this.addMenuItems(menu, ['points', 'inches', 'millimeters', 'meters'], parent);
  208. if (Editor.currentTheme == 'min' ||
  209. Editor.currentTheme == 'simple' ||
  210. Editor.currentTheme == 'sketch')
  211. {
  212. editorUi.menus.addMenuItems(menu, ['-', 'pageScale'], parent);
  213. }
  214. })));
  215. var pagesAction = editorUi.actions.addAction('pageTabs', function()
  216. {
  217. editorUi.setTabContainerVisible(!editorUi.isTabContainerVisible());
  218. });
  219. pagesAction.setToggleAction(true);
  220. pagesAction.setSelectedCallback(function() { return editorUi.isTabContainerVisible(); });
  221. var rulerAction = editorUi.actions.addAction('ruler', function()
  222. {
  223. editorUi.setRulerVisible(!editorUi.isRulerVisible());
  224. });
  225. rulerAction.setEnabled(editorUi.canvasSupported && document.documentMode != 9);
  226. rulerAction.setToggleAction(true);
  227. rulerAction.setSelectedCallback(function() { return editorUi.isRulerVisible(); });
  228. var fullscreenAction = editorUi.actions.addAction('fullscreen', function()
  229. {
  230. if (urlParams['embedInline'] == '1')
  231. {
  232. editorUi.setInlineFullscreen(!Editor.inlineFullscreen);
  233. }
  234. else
  235. {
  236. if (document.fullscreenElement == null)
  237. {
  238. document.body.requestFullscreen();
  239. }
  240. else
  241. {
  242. document.exitFullscreen();
  243. }
  244. }
  245. });
  246. fullscreenAction.visible = urlParams['embedInline'] == '1' ||
  247. (window == window.top && document.fullscreenEnabled &&
  248. document.body.requestFullscreen != null);
  249. fullscreenAction.setToggleAction(true);
  250. fullscreenAction.setSelectedCallback(function()
  251. {
  252. return urlParams['embedInline'] == '1' ?
  253. Editor.inlineFullscreen :
  254. document.fullscreenElement != null;
  255. });
  256. var lightModeAction = editorUi.actions.put('lightMode', new Action(mxResources.get('light'), function(e)
  257. {
  258. editorUi.setAndPersistDarkMode(false);
  259. }));
  260. lightModeAction.setToggleAction(true);
  261. lightModeAction.setSelectedCallback(function()
  262. {
  263. return !editorUi.isAutoDarkMode(true) && !Editor.isDarkMode() && !Editor.cssDarkMode;
  264. });
  265. var darkModeAction = editorUi.actions.put('darkMode', new Action(mxResources.get('dark'), function(e)
  266. {
  267. editorUi.setAndPersistDarkMode(true);
  268. }));
  269. darkModeAction.setToggleAction(true);
  270. darkModeAction.setSelectedCallback(function()
  271. {
  272. return !editorUi.isAutoDarkMode(true) && (Editor.isDarkMode() || Editor.cssDarkMode);
  273. });
  274. var autoModeAction = editorUi.actions.put('autoMode', new Action(mxResources.get('automatic'), function(e)
  275. {
  276. editorUi.setAndPersistDarkMode('auto');
  277. }));
  278. autoModeAction.setToggleAction(true);
  279. autoModeAction.setSelectedCallback(function()
  280. {
  281. return editorUi.isAutoDarkMode(true);
  282. });
  283. if (mxUtils.indexOf(Editor.themes, 'simple') >= 0)
  284. {
  285. var toggleSimpleModeAction = editorUi.actions.put('toggleSimpleMode', new Action(mxResources.get('simple'), function(e)
  286. {
  287. editorUi.setCurrentTheme((Editor.currentTheme == 'simple') ?
  288. ((!Editor.isDarkMode()) ? 'kennedy' : 'dark') : 'simple');
  289. }));
  290. toggleSimpleModeAction.setToggleAction(true);
  291. toggleSimpleModeAction.visible = Editor.currentTheme != 'min' && Editor.currentTheme != 'sketch' &&
  292. Editor.currentTheme != 'atlas';
  293. toggleSimpleModeAction.setSelectedCallback(function() { return Editor.currentTheme == 'simple'; });
  294. }
  295. var toggleSketchModeAction = editorUi.actions.put('toggleSketchMode', new Action(mxResources.get('sketch'), function(e)
  296. {
  297. editorUi.setSketchMode(!Editor.sketchMode);
  298. }));
  299. toggleSketchModeAction.setToggleAction(true);
  300. toggleSketchModeAction.setSelectedCallback(function() { return Editor.sketchMode; });
  301. editorUi.actions.addAction('properties...', function()
  302. {
  303. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  304. {
  305. var dlg = new FilePropertiesDialog(editorUi, url);
  306. editorUi.showDialog(dlg.container, 340, 200, true, true);
  307. dlg.init();
  308. });
  309. }).isEnabled = isGraphEnabled;
  310. if (window.mxFreehand)
  311. {
  312. editorUi.actions.put('insertFreehand', new Action(mxResources.get('freehand') + '...', function()
  313. {
  314. if (graph.isEnabled())
  315. {
  316. if (editorUi.freehandWindow == null)
  317. {
  318. var withBrush = !mxClient.IS_IE && !mxClient.IS_IE11;
  319. editorUi.freehandWindow = new FreehandWindow(
  320. editorUi, document.body.offsetWidth - 420, 102, 176,
  321. withBrush? 126 : 90, withBrush);
  322. }
  323. if (graph.freehand.isDrawing())
  324. {
  325. graph.freehand.stopDrawing();
  326. }
  327. else
  328. {
  329. graph.freehand.startDrawing();
  330. }
  331. editorUi.freehandWindow.window.setVisible(graph.freehand.isDrawing());
  332. }
  333. }, null, null, 'X')).isEnabled = function()
  334. {
  335. return isGraphEnabled() && mxClient.IS_SVG;
  336. };
  337. }
  338. editorUi.actions.put('exportXml', new Action(mxResources.get('formatXml') + '...', function()
  339. {
  340. var div = document.createElement('div');
  341. div.style.whiteSpace = 'nowrap';
  342. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  343. var hd = document.createElement('h3');
  344. mxUtils.write(hd, mxResources.get('formatXml'));
  345. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  346. div.appendChild(hd);
  347. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  348. false, graph.isSelectionEmpty());
  349. var compressed = editorUi.addCheckbox(div, mxResources.get('compressed'), Editor.defaultCompressed);
  350. var pages = editorUi.addCheckbox(div, mxResources.get('allPages'), !noPages, noPages);
  351. pages.style.marginBottom = '16px';
  352. mxEvent.addListener(selection, 'change', function()
  353. {
  354. if (selection.checked)
  355. {
  356. pages.setAttribute('disabled', 'disabled');
  357. }
  358. else
  359. {
  360. pages.removeAttribute('disabled');
  361. }
  362. });
  363. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  364. {
  365. editorUi.downloadFile('xml', !compressed.checked, null,
  366. !selection.checked, noPages || !pages.checked);
  367. }), null, mxResources.get('export'));
  368. editorUi.showDialog(dlg.container, 300, 200, true, true);
  369. }));
  370. if (Editor.enableExportUrl)
  371. {
  372. editorUi.actions.put('exportUrl', new Action(mxResources.get('url') + '...', function()
  373. {
  374. editorUi.showPublishLinkDialog(mxResources.get('url'), null, null, null, null, null, null, null,
  375. function(linkTarget, linkColor, currentPage, lightbox, editLink, layers, width, height, tags)
  376. {
  377. var params = [];
  378. if (lightbox && tags)
  379. {
  380. params.push('tags=%7B%7D');
  381. }
  382. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget, linkColor,
  383. true, lightbox, editLink, layers, null, true, params, null, currentPage));
  384. editorUi.showDialog(dlg.container, 450, 240, true, true);
  385. dlg.init();
  386. });
  387. }));
  388. }
  389. editorUi.actions.put('exportHtml', new Action(mxResources.get('formatHtmlEmbedded') + '...', function()
  390. {
  391. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  392. {
  393. editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
  394. initialZoom, linkTarget, linkColor, fit, allPages, layers, tags, lightbox, editLink)
  395. {
  396. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages,
  397. layers, tags, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  398. {
  399. var basename = editorUi.getBaseFilename(allPages);
  400. var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
  401. '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
  402. '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
  403. editorUi.saveData(basename + ((basename.substring(basename.lenth - 7) ==
  404. '.drawio') ? '' : '.drawio') + '.html', 'html', result, 'text/html');
  405. }));
  406. });
  407. });
  408. }));
  409. editorUi.actions.put('exportPdf', new Action(mxResources.get('formatPdf') + '...', function()
  410. {
  411. if (!EditorUi.isElectronApp && (editorUi.isOffline() || editorUi.printPdfExport))
  412. {
  413. // Export PDF action for chrome OS (same as print with different dialog title)
  414. editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 320,
  415. (editorUi.pages != null && editorUi.pages.length > 1 && (editorUi.editor.editable ||
  416. urlParams['hide-pages'] != '1')) ? 350 : 280, true, true);
  417. }
  418. else
  419. {
  420. editorUi.showPrintDialog(mxResources.get('formatPdf'), mxUtils.bind(this, function(preview, args)
  421. {
  422. var pageCount = (editorUi.pages != null) ? editorUi.pages.length : 1;
  423. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  424. var idx = editorUi.getPageIndex(editorUi.currentPage);
  425. var currentPage = (idx != null) ? idx + 1 : 1;
  426. var pageRange = (!args.allPages && (args.pagesFrom != currentPage || args.pagesTo != currentPage)) ?
  427. {from: Math.max(0, Math.min(pageCount - 1, args.pagesFrom - 1)),
  428. to: Math.max(0, Math.min(pageCount - 1, args.pagesTo - 1))} : null;
  429. editorUi.downloadFile('pdf', null, null, !args.selection, noPages ||
  430. (!args.allPages && args.pagesFrom == currentPage && args.pagesTo == currentPage), !args.crop,
  431. args.transparent, args.scale, null, args.grid, args.includeCopy, pageRange, args.border,
  432. args.fit, args.sheetsAcross, args.sheetsDown);
  433. }));
  434. }
  435. }));
  436. editorUi.actions.addAction('open...', function()
  437. {
  438. editorUi.pickFile();
  439. });
  440. editorUi.actions.addAction('close', function()
  441. {
  442. var currentFile = editorUi.getCurrentFile();
  443. function fn()
  444. {
  445. if (currentFile != null)
  446. {
  447. currentFile.removeDraft();
  448. }
  449. editorUi.fileLoaded(null);
  450. };
  451. if (currentFile != null && currentFile.isModified())
  452. {
  453. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  454. mxResources.get('cancel'), mxResources.get('discardChanges'));
  455. }
  456. else
  457. {
  458. fn();
  459. }
  460. });
  461. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  462. {
  463. var cells = graph.getSelectionCells();
  464. if (graph.getSelectionCount() == 1)
  465. {
  466. var cell = graph.getSelectionCell();
  467. var state = graph.view.getState(cell);
  468. if (state != null && state.shape != null && state.shape.stencil != null)
  469. {
  470. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  471. editorUi.showDialog(dlg.container, 640, 480, true, false);
  472. dlg.init();
  473. }
  474. }
  475. }));
  476. editorUi.actions.addAction('revisionHistory...', function()
  477. {
  478. if (!editorUi.isRevisionHistorySupported())
  479. {
  480. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  481. }
  482. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  483. {
  484. editorUi.getRevisions(mxUtils.bind(this, function(revs, restoreFn)
  485. {
  486. editorUi.spinner.stop();
  487. var dlg = new RevisionDialog(editorUi, revs, restoreFn);
  488. editorUi.showDialog(dlg.container, 640, 480, true, true);
  489. dlg.init();
  490. }), mxUtils.bind(this, function(err)
  491. {
  492. editorUi.handleError((err != null) ? err : mxResources.get('notAvailable'));
  493. }));
  494. }
  495. });
  496. editorUi.actions.addAction('createRevision', function()
  497. {
  498. editorUi.actions.get('save').funct();
  499. }, null, null, Editor.ctrlKey + '+S');
  500. var action = editorUi.actions.addAction('synchronize', function()
  501. {
  502. editorUi.synchronizeCurrentFile(DrawioFile.SYNC == 'none');
  503. }, null, null, 'Alt+Shift+S');
  504. // Changes the label if synchronization is disabled
  505. if (DrawioFile.SYNC == 'none')
  506. {
  507. action.label = mxResources.get('refresh');
  508. }
  509. editorUi.actions.addAction('upload...', function()
  510. {
  511. var file = editorUi.getCurrentFile();
  512. if (file != null)
  513. {
  514. // Data is pulled from global variable after tab loads
  515. // LATER: Change to use message passing to deal with potential cross-domain
  516. window.drawdata = editorUi.getFileData();
  517. var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  518. editorUi.openLink(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
  519. ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
  520. 'title=' + encodeURIComponent(filename), null, true);
  521. }
  522. });
  523. if (typeof(MathJax) !== 'undefined')
  524. {
  525. var action = editorUi.actions.addAction('mathematicalTypesetting', function()
  526. {
  527. var change = new ChangePageSetup(editorUi);
  528. change.ignoreColor = true;
  529. change.ignoreImage = true;
  530. change.mathEnabled = !editorUi.isMathEnabled();
  531. graph.model.execute(change);
  532. });
  533. action.setToggleAction(true);
  534. action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
  535. action.isEnabled = isGraphEnabled;
  536. }
  537. if (isLocalStorage)
  538. {
  539. var action = editorUi.actions.addAction('showStartScreen', function()
  540. {
  541. mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
  542. mxSettings.save();
  543. });
  544. action.setToggleAction(true);
  545. action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
  546. }
  547. var autosaveAction = editorUi.actions.addAction('autosave', function()
  548. {
  549. editorUi.editor.setAutosave(!editorUi.editor.autosave);
  550. });
  551. autosaveAction.setToggleAction(true);
  552. autosaveAction.setSelectedCallback(function()
  553. {
  554. return autosaveAction.isEnabled() && editorUi.editor.autosave;
  555. });
  556. editorUi.actions.addAction('editGeometry...', function()
  557. {
  558. var cells = graph.getSelectionCells();
  559. var vertices = [];
  560. for (var i = 0; i < cells.length; i++)
  561. {
  562. if (graph.getModel().isVertex(cells[i]))
  563. {
  564. vertices.push(cells[i]);
  565. }
  566. }
  567. if (vertices.length > 0)
  568. {
  569. var dlg = new EditGeometryDialog(editorUi, vertices);
  570. editorUi.showDialog(dlg.container, 200, 270, true, true);
  571. dlg.init();
  572. }
  573. }, null, null, Editor.ctrlKey + '+Shift+M');
  574. editorUi.actions.addAction('copyStyle', function()
  575. {
  576. if (graph.isEnabled() && graph.getSelectionCount() == 1)
  577. {
  578. var cell = graph.getSelectionCell();
  579. var style = graph.getCellStyle(cell, false);
  580. editorUi.copiedStyle = {};
  581. var values = [];
  582. var keys = [];
  583. for (var key in style)
  584. {
  585. values.push(style[key]);
  586. keys.push(key);
  587. }
  588. graph.copyCellStyles([cell], keys, values,
  589. editorUi.copiedStyle, editorUi.copiedStyle,
  590. null, null, null, true);
  591. }
  592. }, null, null, 'Alt+C');
  593. editorUi.actions.addAction('pasteStyle', function()
  594. {
  595. if (graph.isEnabled() && !graph.isSelectionEmpty() && editorUi.copiedStyle != null)
  596. {
  597. graph.pasteCellStyles(graph.includeDescendants(graph.getSelectionCells()),
  598. editorUi.copiedStyle, editorUi.copiedStyle, true);
  599. }
  600. }, null, null, 'Alt+V');
  601. editorUi.actions.put('exportSvg', new Action(mxResources.get('formatSvg') + '...', function()
  602. {
  603. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  604. 'https://www.drawio.com/doc/faq/export-diagram',
  605. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  606. addShadow, editable, embedImages, border, cropImage, currentPage,
  607. linkTarget, grid, theme, exportType, embedFonts)
  608. {
  609. var val = parseInt(scale);
  610. editorUi.lastExportSvgEditable = editable;
  611. if (!isNaN(val) && val > 0)
  612. {
  613. editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection,
  614. addShadow, editable, embedImages, border, !cropImage, currentPage,
  615. linkTarget, theme, exportType, embedFonts);
  616. }
  617. }), true, editorUi.lastExportSvgEditable, 'svg', true);
  618. }));
  619. function exportImage(format, defaultEditable, done)
  620. {
  621. if (editorUi.isExportToCanvas())
  622. {
  623. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  624. 'https://www.drawio.com/doc/faq/export-diagram',
  625. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection, addShadow, editable,
  626. embedImages, border, cropImage, currentPage, dummy, grid, theme, exportType)
  627. {
  628. var val = parseInt(scale);
  629. if (!isNaN(val) && val > 0)
  630. {
  631. editorUi.exportImage(val / 100, transparentBackground && format == 'png',
  632. ignoreSelection, addShadow, editable && format == 'png', border,
  633. !cropImage, currentPage, format, grid, null, theme, exportType);
  634. if (done != null)
  635. {
  636. done(scale, transparentBackground, ignoreSelection, addShadow,
  637. editable, embedImages, border, cropImage, currentPage,
  638. dummy, grid, theme, exportType);
  639. }
  640. }
  641. }), true, defaultEditable, format, true);
  642. }
  643. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  644. {
  645. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this,
  646. function(ignoreSelection, editable, transparent, scale, border)
  647. {
  648. editorUi.downloadFile((editable && format == 'png') ? 'xmlpng' : format,
  649. null, null, ignoreSelection, null, null, transparent, scale, border);
  650. }), false, true);
  651. }
  652. };
  653. editorUi.actions.put('exportPng', new Action(mxResources.get('formatPng') + '...', function()
  654. {
  655. exportImage('png', editorUi.lastExportPngEditable, function(scale,
  656. transparentBackground, ignoreSelection, addShadow, editable)
  657. {
  658. editorUi.lastExportPngEditable = editable;
  659. });
  660. }));
  661. editorUi.actions.put('exportJpg', new Action(mxResources.get('formatJpg') + '...', function()
  662. {
  663. exportImage('jpeg');
  664. }));
  665. editorUi.actions.put('exportWebp', new Action(mxResources.get('formatWebp') + '...', function()
  666. {
  667. exportImage('webp');
  668. }));
  669. action = editorUi.actions.addAction('copyAsImage', mxUtils.bind(this, function()
  670. {
  671. var cells = mxUtils.sortCells(graph.model.getTopmostCells(graph.getSelectionCells()));
  672. var xml = mxUtils.getXml((cells.length == 0) ? editorUi.editor.getGraphXml() : graph.encodeCells(cells));
  673. editorUi.copyImage(cells, xml);
  674. }), null, null, 'Ctrl+Alt+X');
  675. // Disabled in Safari as operation is not allowed
  676. action.visible = Editor.enableNativeCipboard && editorUi.isExportToCanvas() && !mxClient.IS_SF;
  677. action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
  678. {
  679. graph.setShadowVisible(!graph.shadowVisible);
  680. }));
  681. action.setToggleAction(true);
  682. action.setSelectedCallback(function() { return graph.shadowVisible; });
  683. editorUi.actions.put('about', new Action('v' + EditorUi.VERSION, function(arg1, evt)
  684. {
  685. // do nothing
  686. }));
  687. editorUi.actions.addAction('support...', function()
  688. {
  689. if (EditorUi.isElectronApp)
  690. {
  691. editorUi.openLink('https://github.com/jgraph/drawio-desktop/wiki/Getting-Support');
  692. }
  693. else
  694. {
  695. editorUi.openLink('https://github.com/jgraph/drawio/wiki/Getting-Support');
  696. }
  697. });
  698. editorUi.actions.addAction('exportOptionsDisabled...', function()
  699. {
  700. editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
  701. mxResources.get('exportOptionsDisabled'));
  702. });
  703. editorUi.actions.addAction('keyboardShortcuts...', function()
  704. {
  705. if (mxClient.IS_SVG && !mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  706. {
  707. editorUi.openLink('shortcuts.svg');
  708. }
  709. else
  710. {
  711. editorUi.openLink('https://viewer.diagrams.net/#Uhttps%3A%2F%2Fviewer.diagrams.net%2Fshortcuts.svg');
  712. }
  713. });
  714. editorUi.actions.addAction('feedback...', function()
  715. {
  716. var dlg = new FeedbackDialog(editorUi);
  717. editorUi.showDialog(dlg.container, 610, 360, true, false);
  718. dlg.init();
  719. });
  720. editorUi.actions.addAction('quickStart...', function()
  721. {
  722. if ('ac.draw.io' === window.location.hostname)
  723. {
  724. editorUi.openLink('https://www.youtube.com/watch?v=s5BG0705MHU');
  725. }
  726. else
  727. {
  728. editorUi.openLink('https://www.youtube.com/watch?v=Z0D96ZikMkc');
  729. }
  730. });
  731. action = editorUi.actions.addAction('tags', mxUtils.bind(this, function()
  732. {
  733. if (this.tagsWindow == null)
  734. {
  735. this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 400, 60, 212, 200);
  736. this.tagsWindow.window.addListener('show', mxUtils.bind(this, function()
  737. {
  738. editorUi.fireEvent(new mxEventObject('tags'));
  739. }));
  740. this.tagsWindow.window.addListener('hide', function()
  741. {
  742. editorUi.fireEvent(new mxEventObject('tags'));
  743. });
  744. this.tagsWindow.window.setVisible(true);
  745. editorUi.fireEvent(new mxEventObject('tags'));
  746. }
  747. else
  748. {
  749. this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
  750. }
  751. }), null, null, Editor.ctrlKey + '+K');
  752. action.setToggleAction(true);
  753. action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
  754. if (Editor.gptApiKey != null && Editor.gptModel != null && Editor.gptUrl != null &&
  755. !editorUi.isOffline() && !EditorUi.isElectronApp)
  756. {
  757. action = editorUi.actions.addAction('chatWindowTitle', mxUtils.bind(this, function()
  758. {
  759. if (this.chatWindow == null)
  760. {
  761. this.chatWindow = new ChatWindow(editorUi, 220, document.body.offsetHeight - 380, 250, 320);
  762. this.chatWindow.window.addListener('show', mxUtils.bind(this, function()
  763. {
  764. editorUi.fireEvent(new mxEventObject('chat'));
  765. }));
  766. this.chatWindow.window.addListener('hide', function()
  767. {
  768. editorUi.fireEvent(new mxEventObject('chat'));
  769. });
  770. this.chatWindow.window.setVisible(true);
  771. editorUi.fireEvent(new mxEventObject('chat'));
  772. }
  773. else
  774. {
  775. this.chatWindow.window.setVisible(!this.chatWindow.window.isVisible());
  776. }
  777. }));
  778. action.setToggleAction(true);
  779. action.setSelectedCallback(mxUtils.bind(this, function() { return this.chatWindow != null && this.chatWindow.window.isVisible(); }));
  780. }
  781. action = editorUi.actions.addAction('findReplace', mxUtils.bind(this, function(arg1, evt)
  782. {
  783. var findReplace = graph.isEnabled() && (evt == null || !mxEvent.isShiftDown(evt));
  784. var evtName = (findReplace) ? 'findReplace' : 'find';
  785. var name = evtName + 'Window';
  786. if (this[name] == null)
  787. {
  788. var modern = (Editor.currentTheme == 'min' ||
  789. Editor.currentTheme == 'simple' ||
  790. Editor.currentTheme == 'sketch');
  791. var w = (findReplace) ? ((modern) ? 330 : 300) : 240;
  792. var h = (findReplace) ? ((modern) ? 304 : 288) : 170;
  793. this[name] = new FindWindow(editorUi,
  794. document.body.offsetWidth - (w + 20),
  795. 100, w, h, findReplace);
  796. this[name].window.addListener('show', function()
  797. {
  798. editorUi.fireEvent(new mxEventObject(evtName));
  799. });
  800. this[name].window.addListener('hide', function()
  801. {
  802. editorUi.fireEvent(new mxEventObject(evtName));
  803. });
  804. this[name].window.setVisible(true);
  805. }
  806. else
  807. {
  808. this[name].window.setVisible(!this[name].window.isVisible());
  809. }
  810. }), null, null, Editor.ctrlKey + '+F');
  811. action.setToggleAction(true);
  812. action.setSelectedCallback(mxUtils.bind(this, function()
  813. {
  814. var name = (graph.isEnabled()) ? 'findReplaceWindow' : 'findWindow';
  815. return this[name] != null && this[name].window.isVisible();
  816. }));
  817. editorUi.actions.put('exportVsdx', new Action(mxResources.get('formatVsdx') + ' (beta)...', function()
  818. {
  819. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  820. if (noPages)
  821. {
  822. editorUi.exportVisio();
  823. }
  824. else
  825. {
  826. var div = document.createElement('div');
  827. div.style.whiteSpace = 'nowrap';
  828. var hd = document.createElement('h3');
  829. mxUtils.write(hd, mxResources.get('formatVsdx'));
  830. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  831. div.appendChild(hd);
  832. var pages = editorUi.addCheckbox(div, mxResources.get('allPages'), !noPages, noPages);
  833. pages.style.marginBottom = '16px';
  834. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  835. {
  836. editorUi.exportVisio(!pages.checked);
  837. }), null, mxResources.get('export'));
  838. editorUi.showDialog(dlg.container, 300, 130, true, true);
  839. }
  840. }));
  841. if (isLocalStorage && localStorage != null && urlParams['embed'] != '1')
  842. {
  843. editorUi.actions.addAction('configuration...', function()
  844. {
  845. // Moves show start screen option to configuration dialog in sketch
  846. var splashCb = document.createElement('input');
  847. splashCb.setAttribute('type', 'checkbox');
  848. splashCb.style.marginRight = '8px';
  849. splashCb.checked = mxSettings.getShowStartScreen();
  850. splashCb.defaultChecked = splashCb.checked;
  851. if (Editor.isSettingsEnabled() && (Editor.currentTheme == 'sketch' ||
  852. Editor.currentTheme == 'simple' || Editor.currentTheme == 'min'))
  853. {
  854. var showSplash = document.createElement('span');
  855. showSplash.style.display = 'flex';
  856. showSplash.style.alignItems = 'center';
  857. showSplash.style['float'] = 'right';
  858. showSplash.style.cursor = 'pointer';
  859. showSplash.style.userSelect = 'none';
  860. showSplash.style.marginTop = '-3px';
  861. showSplash.appendChild(splashCb);
  862. mxUtils.write(showSplash, mxResources.get('showStartScreen'));
  863. mxEvent.addListener(showSplash, 'click', function(evt)
  864. {
  865. if (mxEvent.getSource(evt) != splashCb)
  866. {
  867. splashCb.checked = !splashCb.checked;
  868. }
  869. });
  870. header = showSplash;
  871. }
  872. var buttons = [[mxResources.get('reset'), function()
  873. {
  874. editorUi.confirm(mxResources.get('areYouSure'), function()
  875. {
  876. try
  877. {
  878. localStorage.removeItem(Editor.configurationKey);
  879. editorUi.hideDialog();
  880. editorUi.alert(mxResources.get('restartForChangeRequired'));
  881. }
  882. catch (e)
  883. {
  884. editorUi.handleError(e);
  885. }
  886. });
  887. }]];
  888. if (!editorUi.isOfflineApp() && isLocalStorage && editorUi.mode != App.MODE_ATLAS)
  889. {
  890. var pluginsAction = editorUi.actions.get('plugins');
  891. if (pluginsAction != null && (Editor.currentTheme == 'sketch' ||
  892. Editor.currentTheme == 'simple' || Editor.currentTheme == 'min'))
  893. {
  894. // TODO: Show change message only when plugins have changed
  895. buttons.push([mxResources.get('plugins'), pluginsAction.funct]);
  896. }
  897. }
  898. if (!EditorUi.isElectronApp)
  899. {
  900. buttons.push([mxResources.get('link'), function(evt, input)
  901. {
  902. if (input.value.length > 0)
  903. {
  904. try
  905. {
  906. var obj = JSON.parse(input.value);
  907. var url = window.location.protocol + '//' + window.location.host +
  908. '/' + editorUi.getSearch() + '#_CONFIG_' +
  909. Graph.compress(JSON.stringify(obj));
  910. var dlg = new EmbedDialog(editorUi, url);
  911. editorUi.showDialog(dlg.container, 450, 240, true);
  912. dlg.init();
  913. }
  914. catch (e)
  915. {
  916. editorUi.handleError(e);
  917. }
  918. }
  919. else
  920. {
  921. editorUi.handleError({message: mxResources.get('invalidInput')});
  922. }
  923. }])
  924. }
  925. if (editorUi.getServiceName() != 'atlassian' && urlParams['embed'] != '1')
  926. {
  927. buttons.push([mxResources.get('preferences'), function()
  928. {
  929. editorUi.showLocalStorageDialog(mxResources.get('preferences') + ':', Editor.settingsKey,
  930. [[mxResources.get('reset'), function()
  931. {
  932. editorUi.confirm(mxResources.get('areYouSure'), function()
  933. {
  934. try
  935. {
  936. localStorage.removeItem(Editor.settingsKey);
  937. localStorage.removeItem('.drawio-config');
  938. editorUi.hideDialog();
  939. editorUi.alert(mxResources.get('restartForChangeRequired'));
  940. }
  941. catch (e)
  942. {
  943. editorUi.handleError(e);
  944. }
  945. });
  946. }]]);
  947. }]);
  948. }
  949. editorUi.showLocalStorageDialog(mxResources.get('configuration') + ':', Editor.configurationKey,
  950. buttons, splashCb.parentNode, 'https://www.drawio.com/doc/faq/configure-diagram-editor',
  951. function()
  952. {
  953. if (splashCb.parentNode != null)
  954. {
  955. mxSettings.setShowStartScreen(splashCb.checked);
  956. mxSettings.save();
  957. }
  958. });
  959. });
  960. }
  961. // Adds language menu to options only if localStorage is available for
  962. // storing the choice. We do not want to use cookies for older browsers.
  963. // Note that the URL param lang=XX is available for setting the language
  964. // in older browsers. URL param has precedence over the saved setting.
  965. if (mxClient.IS_CHROMEAPP || isLocalStorage)
  966. {
  967. this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
  968. {
  969. var currentLanguage = mxLanguage;
  970. if (urlParams['lang'] == null && isLocalStorage)
  971. {
  972. currentLanguage = mxSettings.settings.language;
  973. }
  974. var addLangItem = mxUtils.bind(this, function (id)
  975. {
  976. var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
  977. var item = null;
  978. if (lang != '')
  979. {
  980. item = menu.addItem(lang, null, mxUtils.bind(this, function()
  981. {
  982. editorUi.setAndPersistLanguage(id);
  983. editorUi.alert(mxResources.get('restartForChangeRequired'));
  984. }), parent);
  985. if (id == currentLanguage || (id == '' && currentLanguage == null))
  986. {
  987. menu.addCheckmark(item, Editor.checkmarkImage);
  988. }
  989. }
  990. return item;
  991. });
  992. addLangItem('');
  993. menu.addSeparator(parent);
  994. // LATER: Sort menu by language name
  995. for(var langId in mxLanguageMap)
  996. {
  997. addLangItem(langId);
  998. }
  999. })));
  1000. // Extends the menubar with the language menu
  1001. var menusCreateMenuBar = Menus.prototype.createMenubar;
  1002. Menus.prototype.createMenubar = function(container)
  1003. {
  1004. var menubar = menusCreateMenuBar.apply(this, arguments);
  1005. if ((urlParams['embed'] != '1' || urlParams['atlas'] == '1') &&
  1006. menubar != null && Editor.enableSimpleTheme &&
  1007. editorUi.getServiceName() != 'atlassian')
  1008. {
  1009. var themeMenu = this.get('dynamicAppearance');
  1010. if (themeMenu != null)
  1011. {
  1012. var elt = menubar.addMenu('', themeMenu.funct);
  1013. elt.setAttribute('title', mxResources.get('appearance'));
  1014. elt.className = 'geToolbarButton geAdaptiveAsset';
  1015. elt.style.backgroundPosition = 'center center';
  1016. elt.style.backgroundRepeat = 'no-repeat';
  1017. elt.style.backgroundSize = '100% 100%';
  1018. elt.style.display = 'inline-block';
  1019. elt.style.cursor = 'pointer';
  1020. elt.style.zIndex = '1';
  1021. // Depends on theme
  1022. elt.style.position = 'absolute';
  1023. elt.style.height = '18px';
  1024. elt.style.width = '18px';
  1025. if (Editor.currentTheme == 'atlas')
  1026. {
  1027. elt.style.filter = 'invert(100%)';
  1028. elt.style.right = '11px';
  1029. elt.style.top = '10px';
  1030. }
  1031. else
  1032. {
  1033. elt.style.right = '10px';
  1034. elt.style.top = '5px';
  1035. }
  1036. document.body.appendChild(elt);
  1037. menubar.langIcon = elt;
  1038. var updateThemeElement = mxUtils.bind(this, function()
  1039. {
  1040. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1041. elt.style.display = (Editor.currentTheme == 'atlas' || Editor.currentTheme == 'min' ||
  1042. Editor.currentTheme == 'sketch') ? 'none' : '';
  1043. if (Editor.currentTheme == 'simple')
  1044. {
  1045. if (iw < 750)
  1046. {
  1047. elt.style.backgroundImage = 'url(' + Editor.thinDoubleArrowRightImage + ')';
  1048. }
  1049. else
  1050. {
  1051. elt.style.backgroundImage = 'url(' + ((Editor.isDarkMode() || Editor.cssDarkMode) ?
  1052. Editor.thinDarkImage : Editor.thinLightImage) + ')';
  1053. }
  1054. }
  1055. else
  1056. {
  1057. elt.style.backgroundImage = 'url(' + ((Editor.isDarkMode() || Editor.cssDarkMode) ?
  1058. Editor.darkModeImage : Editor.lightModeImage) + ')';
  1059. }
  1060. });
  1061. this.editorUi.addListener('currentThemeChanged', updateThemeElement);
  1062. this.editorUi.addListener('darkModeChanged', updateThemeElement);
  1063. mxEvent.addListener(window, 'resize', updateThemeElement);
  1064. updateThemeElement();
  1065. }
  1066. }
  1067. return menubar;
  1068. };
  1069. }
  1070. editorUi.customLayoutConfig = [{'layout': 'mxHierarchicalLayout',
  1071. 'config':
  1072. {'orientation': 'west',
  1073. 'intraCellSpacing': 30,
  1074. 'interRankCellSpacing': 100,
  1075. 'interHierarchySpacing': 60,
  1076. 'parallelEdgeSpacing': 10}}];
  1077. // Adds action for running layouts
  1078. editorUi.actions.addAction('runLayout', function()
  1079. {
  1080. editorUi.showCustomLayoutDialog(JSON.stringify(
  1081. editorUi.customLayoutConfig, null, 2));
  1082. });
  1083. // Adds action for converting dark mode colors
  1084. editorUi.actions.put('convertDarkModeColors', new Action('Dark Mode Colors...', function(evt)
  1085. {
  1086. if (Editor.enableCssDarkMode)
  1087. {
  1088. if (editorUi.darkModeColorsWindow == null)
  1089. {
  1090. editorUi.darkModeColorsWindow = new DarkModeColorsWindow(
  1091. editorUi, document.body.offsetWidth - 520, 80, 200, 100);
  1092. }
  1093. editorUi.darkModeColorsWindow.window.setVisible(true);
  1094. }
  1095. }));
  1096. // Adds fullscreen toggle to zoom menu in sketch and min
  1097. var viewZoomMenu = this.get('viewZoom');
  1098. var viewZoomMenuFunct = viewZoomMenu.funct;
  1099. viewZoomMenu.funct = mxUtils.bind(this, function(menu, parent)
  1100. {
  1101. viewZoomMenuFunct.apply(this, arguments);
  1102. if (Editor.currentTheme == 'sketch' || Editor.currentTheme == 'min')
  1103. {
  1104. this.addMenuItems(menu, ['-', 'outline', 'fullscreen'], parent);
  1105. }
  1106. });
  1107. var layoutMenu = this.get('layout');
  1108. var layoutMenuFunct = layoutMenu.funct;
  1109. layoutMenu.funct = function(menu, parent)
  1110. {
  1111. layoutMenuFunct.apply(this, arguments);
  1112. menu.addItem(mxResources.get('orgChart'), null, function()
  1113. {
  1114. var branchOptimizer = null, parentChildSpacingVal = 20, siblingSpacingVal = 20;
  1115. // Invoked when orgchart code was loaded
  1116. var delayed = function()
  1117. {
  1118. if (typeof mxOrgChartLayout !== 'undefined' && branchOptimizer != null)
  1119. {
  1120. editorUi.tryAndHandle(mxUtils.bind(this, function()
  1121. {
  1122. var graph = editorUi.editor.graph;
  1123. var orgChartLayout = new mxOrgChartLayout(graph,
  1124. branchOptimizer, parentChildSpacingVal, siblingSpacingVal);
  1125. var cell = graph.getDefaultParent();
  1126. if (graph.model.getChildCount(graph.getSelectionCell()) > 1)
  1127. {
  1128. cell = graph.getSelectionCell();
  1129. }
  1130. orgChartLayout.execute(cell);
  1131. }));
  1132. }
  1133. };
  1134. var div = document.createElement('div');
  1135. var title = document.createElement('div');
  1136. title.style.marginTop = '6px';
  1137. title.style.display = 'inline-block';
  1138. title.style.width = '180px';
  1139. mxUtils.write(title, mxResources.get('orgChartType') + ': ');
  1140. div.appendChild(title);
  1141. var typeSelect = document.createElement('select');
  1142. typeSelect.style.width = '160px';
  1143. typeSelect.style.boxSizing = 'border-box';
  1144. //Types are hardcoded here since the code is not loaded yet
  1145. var typesArr = [mxResources.get('linear'),
  1146. mxResources.get('hanger2'),
  1147. mxResources.get('hanger4'),
  1148. mxResources.get('fishbone1'),
  1149. mxResources.get('fishbone2'),
  1150. mxResources.get('1ColumnLeft'),
  1151. mxResources.get('1ColumnRight'),
  1152. mxResources.get('smart')
  1153. ];
  1154. for (var i = 0; i < typesArr.length; i++)
  1155. {
  1156. var option = document.createElement('option');
  1157. mxUtils.write(option, typesArr[i]);
  1158. option.value = i;
  1159. if (i == 2)
  1160. {
  1161. option.setAttribute('selected', 'selected');
  1162. }
  1163. typeSelect.appendChild(option);
  1164. }
  1165. mxEvent.addListener(typeSelect, 'change', function()
  1166. {
  1167. branchOptimizer = typeSelect.value;
  1168. });
  1169. div.appendChild(typeSelect);
  1170. title = document.createElement('div');
  1171. title.style.marginTop = '6px';
  1172. title.style.display = 'inline-block';
  1173. title.style.width = '180px';
  1174. mxUtils.write(title, mxResources.get('parentChildSpacing') + ': ');
  1175. div.appendChild(title);
  1176. var parentChildSpacing = document.createElement('input');
  1177. parentChildSpacing.type = 'number';
  1178. parentChildSpacing.value = parentChildSpacingVal;
  1179. parentChildSpacing.style.width = '160px';
  1180. parentChildSpacing.style.boxSizing = 'border-box';
  1181. div.appendChild(parentChildSpacing);
  1182. mxEvent.addListener(parentChildSpacing, 'change', function()
  1183. {
  1184. parentChildSpacingVal = parentChildSpacing.value;
  1185. });
  1186. title = document.createElement('div');
  1187. title.style.marginTop = '6px';
  1188. title.style.display = 'inline-block';
  1189. title.style.width = '180px';
  1190. mxUtils.write(title, mxResources.get('siblingSpacing') + ': ');
  1191. div.appendChild(title);
  1192. var siblingSpacing = document.createElement('input');
  1193. siblingSpacing.type = 'number';
  1194. siblingSpacing.value = siblingSpacingVal;
  1195. siblingSpacing.style.width = '160px';
  1196. siblingSpacing.style.boxSizing = 'border-box';
  1197. div.appendChild(siblingSpacing);
  1198. mxEvent.addListener(siblingSpacing, 'change', function()
  1199. {
  1200. siblingSpacingVal = siblingSpacing.value;
  1201. });
  1202. var customBtn = mxUtils.button(mxResources.get('custom') + '...', function()
  1203. {
  1204. var value = [{layout: 'mxOrgChartLayout',
  1205. config: {
  1206. branchOptimizer: parseInt(typeSelect.value),
  1207. parentChildSpacing: parseInt(parentChildSpacing.value),
  1208. siblingSpacing: parseInt(siblingSpacing.value)
  1209. }
  1210. }];
  1211. editorUi.hideDialog();
  1212. editorUi.showCustomLayoutDialog(
  1213. JSON.stringify(value, null, 2));
  1214. });
  1215. customBtn.className = 'geBtn';
  1216. var dlg = new CustomDialog(editorUi, div, function()
  1217. {
  1218. if (branchOptimizer == null)
  1219. {
  1220. branchOptimizer = 2;
  1221. }
  1222. editorUi.loadOrgChartLayouts(delayed);
  1223. }, null, null, null, customBtn);
  1224. editorUi.showDialog(dlg.container, 355, 140, true, true);
  1225. }, parent, null, isGraphEnabled());
  1226. menu.addSeparator(parent);
  1227. menu.addItem(mxResources.get('parallels'), null, mxUtils.bind(this, function()
  1228. {
  1229. editorUi.tryAndHandle(mxUtils.bind(this, function()
  1230. {
  1231. var layout = new mxParallelEdgeLayout(graph);
  1232. layout.checkOverlap = true;
  1233. editorUi.prompt(mxResources.get('spacing'), layout.spacing, mxUtils.bind(this, function(newValue)
  1234. {
  1235. editorUi.tryAndHandle(mxUtils.bind(this, function()
  1236. {
  1237. layout.spacing = newValue;
  1238. editorUi.executeLayout(function()
  1239. {
  1240. layout.execute(graph.getDefaultParent(), (!graph.isSelectionEmpty()) ?
  1241. graph.getSelectionCells() : null);
  1242. }, false);
  1243. }));
  1244. }));
  1245. }));
  1246. }), parent);
  1247. menu.addSeparator(parent);
  1248. editorUi.menus.addMenuItem(menu, 'runLayout', parent, null, null, mxResources.get('custom') + '...');
  1249. };
  1250. this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
  1251. {
  1252. if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
  1253. {
  1254. this.addMenuItems(menu, ['keyboardShortcuts', '-', 'about'], parent);
  1255. }
  1256. else
  1257. {
  1258. // No translation for menu item since help is english only
  1259. var item = menu.addItem('Search:', null, null, parent, null, null, false);
  1260. item.style.cursor = 'default';
  1261. var input = document.createElement('input');
  1262. input.setAttribute('type', 'text');
  1263. input.setAttribute('size', '25');
  1264. input.style.borderWidth = '1px';
  1265. input.style.marginLeft = '8px';
  1266. mxEvent.addListener(input, 'keydown', mxUtils.bind(this, function(e)
  1267. {
  1268. var term = mxUtils.trim(input.value);
  1269. if (e.keyCode == 13 && term.length > 0)
  1270. {
  1271. this.editorUi.openLink('https://www.drawio.com/search?src=' +
  1272. (EditorUi.isElectronApp ? 'DESKTOP' : encodeURIComponent(location.host)) +
  1273. '&search=' + encodeURIComponent(term));
  1274. input.value = '';
  1275. EditorUi.logEvent({category: 'SEARCH-HELP', action: 'search', label: term});
  1276. window.setTimeout(mxUtils.bind(this, function()
  1277. {
  1278. this.editorUi.hideCurrentMenu();
  1279. }), 0);
  1280. }
  1281. else if (e.keyCode == 27)
  1282. {
  1283. input.value = '';
  1284. }
  1285. }));
  1286. item.firstChild.nextSibling.appendChild(input);
  1287. mxEvent.addGestureListeners(input, function(evt)
  1288. {
  1289. if (document.activeElement != input)
  1290. {
  1291. input.focus();
  1292. }
  1293. mxEvent.consume(evt);
  1294. }, function(evt)
  1295. {
  1296. mxEvent.consume(evt);
  1297. }, function(evt)
  1298. {
  1299. mxEvent.consume(evt);
  1300. });
  1301. window.setTimeout(function()
  1302. {
  1303. input.focus();
  1304. }, 0);
  1305. if (EditorUi.isElectronApp)
  1306. {
  1307. editorUi.actions.addAction('website...', function()
  1308. {
  1309. editorUi.openLink('https://www.drawio.com');
  1310. });
  1311. editorUi.actions.addAction('check4Updates', function()
  1312. {
  1313. editorUi.checkForUpdates();
  1314. });
  1315. editorUi.actions.put('desktopZoomIn', new Action(mxResources.get('zoomIn'), function()
  1316. {
  1317. editorUi.desktopZoomIn();
  1318. }));
  1319. editorUi.actions.put('desktopZoomOut', new Action(mxResources.get('zoomOut'), function()
  1320. {
  1321. editorUi.desktopZoomOut();
  1322. }));
  1323. editorUi.actions.put('desktopResetZoom', new Action(mxResources.get('actualSize'), function()
  1324. {
  1325. editorUi.desktopResetZoom();
  1326. }));
  1327. this.addMenuItems(menu, ['-', 'keyboardShortcuts', 'quickStart',
  1328. 'website', 'support', '-'], parent);
  1329. if (urlParams['disableUpdate'] != '1')
  1330. {
  1331. this.addMenuItems(menu, ['check4Updates', '-'], parent);
  1332. }
  1333. this.addMenuItems(menu, ['desktopResetZoom', 'desktopZoomIn',
  1334. 'desktopZoomOut', '-', 'openDevTools', '-', 'about'], parent);
  1335. }
  1336. else
  1337. {
  1338. this.addMenuItems(menu, ['-', 'keyboardShortcuts',
  1339. 'quickStart', 'support', '-', 'about'], parent);
  1340. }
  1341. }
  1342. if (urlParams['test'] == '1')
  1343. {
  1344. menu.addSeparator(parent);
  1345. this.addSubmenu('testDevelop', menu, parent);
  1346. }
  1347. })));
  1348. editorUi.actions.addAction('languageCode...', function()
  1349. {
  1350. var lang = Graph.diagramLanguage || '';
  1351. var dlg = new FilenameDialog(editorUi, lang, mxResources.get('ok'),
  1352. mxUtils.bind(this, function(newLang)
  1353. {
  1354. if (newLang != null)
  1355. {
  1356. Graph.diagramLanguage = (newLang.length > 0) ? newLang : null;
  1357. Graph.translateDiagram = true;
  1358. graph.refresh();
  1359. }
  1360. }), mxResources.get('languageCode'), null, null,
  1361. 'https://www.drawio.com/blog/translate-diagrams');
  1362. editorUi.showDialog(dlg.container, 340, 80, true, true);
  1363. dlg.init();
  1364. });
  1365. this.put('diagramLanguage', new Menu(mxUtils.bind(this, function(menu, parent)
  1366. {
  1367. this.addMenuItems(menu, ['languageCode', '-'], parent);
  1368. var item = menu.addItem(mxResources.get('disabled'), null, function()
  1369. {
  1370. Graph.translateDiagram = false;
  1371. graph.refresh();
  1372. }, parent);
  1373. if (!Graph.translateDiagram)
  1374. {
  1375. menu.addCheckmark(item, Editor.checkmarkImage);
  1376. }
  1377. })));
  1378. // Only visible in test mode
  1379. if (urlParams['test'] == '1')
  1380. {
  1381. mxResources.parse('testDevelop=Develop');
  1382. mxResources.parse('showBoundingBox=Show bounding box');
  1383. mxResources.parse('createSidebarEntry=Create Sidebar Entry');
  1384. mxResources.parse('testCheckFile=Check File');
  1385. mxResources.parse('testDiff=Diff/Sync');
  1386. mxResources.parse('testChecksum=Checksum');
  1387. mxResources.parse('testCheckPages=Check Pages');
  1388. mxResources.parse('testFixPages=Fix Pages');
  1389. mxResources.parse('testInspect=Inspect');
  1390. mxResources.parse('testShowConsole=Show Console');
  1391. mxResources.parse('testXmlImageExport=XML Image Export');
  1392. mxResources.parse('testOptimize=Remove Inline Images');
  1393. mxResources.parse('testPerformance=Performance');
  1394. editorUi.actions.addAction('createSidebarEntry', mxUtils.bind(this, function()
  1395. {
  1396. if (!graph.isSelectionEmpty())
  1397. {
  1398. var cells = graph.cloneCells(graph.getSelectionCells());
  1399. var bbox = graph.getBoundingBoxFromGeometry(cells, true);
  1400. cells = graph.moveCells(cells, -bbox.x, -bbox.y);
  1401. editorUi.showTextDialog('Create Sidebar Entry', 'this.addDataEntry(\'tag1 tag2\', ' +
  1402. bbox.width + ', ' + bbox.height + ', \'The Title\', \'' +
  1403. Graph.compress(mxUtils.getXml(graph.encodeCells(cells))) + '\'),');
  1404. }
  1405. }));
  1406. editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  1407. {
  1408. var b = graph.getGraphBounds();
  1409. var tr = graph.view.translate;
  1410. var s = graph.view.scale;
  1411. graph.insertVertex(graph.getDefaultParent(), null, '',
  1412. b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s,
  1413. 'fillColor=none;strokeColor=red;');
  1414. // Checking bounding boxes
  1415. function checkBounds(shape)
  1416. {
  1417. return shape == null || shape.boundingBox == null || (!isNaN(shape.boundingBox.x) &&
  1418. !isNaN(shape.boundingBox.y) && !isNaN(shape.boundingBox.width) &&
  1419. !isNaN(shape.boundingBox.height));
  1420. };
  1421. var invalid = 0;
  1422. var count = 0;
  1423. graph.view.states.visit(function(id, state)
  1424. {
  1425. var valid = true;
  1426. if (!checkBounds(state.shape))
  1427. {
  1428. console.log('invalid shape', state.cell.id, state.shape);
  1429. valid = false;
  1430. }
  1431. if (!checkBounds(state.text))
  1432. {
  1433. console.log('invalid text', state.cell.id, state.text);
  1434. valid = false;
  1435. }
  1436. if (!valid)
  1437. {
  1438. invalid++;
  1439. }
  1440. count++;
  1441. });
  1442. console.log('states checked', count, 'invalid', invalid);
  1443. }));
  1444. editorUi.actions.addAction('testCheckFile', mxUtils.bind(this, function()
  1445. {
  1446. var xml = (editorUi.pages != null && editorUi.getCurrentFile() != null) ?
  1447. editorUi.getCurrentFile().getAnonymizedXmlForPages(editorUi.pages) : '';
  1448. var dlg = new TextareaDialog(editorUi, 'Paste Data:', xml,
  1449. function(newValue)
  1450. {
  1451. if (newValue.length > 0)
  1452. {
  1453. try
  1454. {
  1455. if (newValue.charAt(0) != '<')
  1456. {
  1457. newValue = Graph.decompress(newValue);
  1458. mxLog.debug('See console for uncompressed XML');
  1459. console.log('xml', newValue);
  1460. }
  1461. var doc = mxUtils.parseXml(newValue);
  1462. var pages = editorUi.getPagesForNode(doc.documentElement, 'mxGraphModel');
  1463. if (pages != null && pages.length > 0)
  1464. {
  1465. try
  1466. {
  1467. var checksum = editorUi.getHashValueForPages(pages);
  1468. mxLog.debug('Checksum: ', checksum);
  1469. }
  1470. catch (e)
  1471. {
  1472. mxLog.debug('Error: ', e.message);
  1473. }
  1474. }
  1475. else
  1476. {
  1477. mxLog.debug('No pages found for checksum');
  1478. }
  1479. // Checks for duplicates
  1480. function checkModel(node)
  1481. {
  1482. var pageId = node.parentNode.id;
  1483. var all = node.childNodes;
  1484. var allIds = {};
  1485. var childs = {};
  1486. var root = null;
  1487. var dups = {};
  1488. for (var i = 0; i < all.length; i++)
  1489. {
  1490. var el = all[i];
  1491. if (el.id != null && el.id.length > 0)
  1492. {
  1493. if (allIds[el.id] == null)
  1494. {
  1495. allIds[el.id] = el.id;
  1496. var pid = el.getAttribute('parent');
  1497. if (pid == null)
  1498. {
  1499. if (root != null)
  1500. {
  1501. mxLog.debug(pageId + ': Multiple roots: ' + el.id);
  1502. }
  1503. else
  1504. {
  1505. root = el.id;
  1506. }
  1507. }
  1508. else
  1509. {
  1510. if (childs[pid] == null)
  1511. {
  1512. childs[pid] = [];
  1513. }
  1514. childs[pid].push(el.id);
  1515. }
  1516. }
  1517. else
  1518. {
  1519. dups[el.id] = el.id;
  1520. }
  1521. }
  1522. }
  1523. var keys = Object.keys(dups);
  1524. if (keys.length > 0)
  1525. {
  1526. var log = pageId + ': ' + keys.length +
  1527. ' Duplicates: ' + keys.join(', ');
  1528. mxLog.debug(log + ' (see console)');
  1529. }
  1530. else
  1531. {
  1532. mxLog.debug(pageId + ': Checked');
  1533. }
  1534. // Checks tree for cycles
  1535. var visited = {};
  1536. function visit(id)
  1537. {
  1538. if (visited[id] == null)
  1539. {
  1540. visited[id] = true;
  1541. if (childs[id] != null)
  1542. {
  1543. while (childs[id].length > 0)
  1544. {
  1545. var temp = childs[id].pop();
  1546. visit(temp);
  1547. }
  1548. delete childs[id];
  1549. }
  1550. }
  1551. else
  1552. {
  1553. mxLog.debug(pageId + ': Visited: ' + id);
  1554. }
  1555. };
  1556. if (root == null)
  1557. {
  1558. mxLog.debug(pageId + ': No root');
  1559. }
  1560. else
  1561. {
  1562. visit(root);
  1563. if (Object.keys(visited).length != Object.keys(allIds).length)
  1564. {
  1565. mxLog.debug(pageId + ': Invalid tree: (see console)');
  1566. console.log(pageId + ': Invalid tree', childs);
  1567. }
  1568. }
  1569. };
  1570. var roots = doc.getElementsByTagName('root');
  1571. for (var i = 0; i < roots.length; i++)
  1572. {
  1573. checkModel(roots[i]);
  1574. }
  1575. mxLog.show();
  1576. }
  1577. catch (e)
  1578. {
  1579. editorUi.handleError(e);
  1580. if (window.console != null)
  1581. {
  1582. console.error(e);
  1583. }
  1584. }
  1585. }
  1586. });
  1587. editorUi.showDialog(dlg.container, 620, 460, true, true);
  1588. dlg.init();
  1589. }));
  1590. var snapshot = null;
  1591. editorUi.actions.addAction('testDiff', mxUtils.bind(this, function()
  1592. {
  1593. if (editorUi.pages != null)
  1594. {
  1595. var buttons = [['Snapshot', function(evt, input)
  1596. {
  1597. snapshot = editorUi.getPagesForXml(editorUi.getFileData(true));
  1598. dlg.textarea.value = 'Snapshot updated ' + new Date().toLocaleString() +
  1599. ' Checksum ' + editorUi.getHashValueForPages(snapshot);
  1600. }], ['Diff', function(evt, input)
  1601. {
  1602. try
  1603. {
  1604. dlg.textarea.value = JSON.stringify(editorUi.diffPages(
  1605. snapshot, editorUi.pages), null, 2);
  1606. }
  1607. catch (e)
  1608. {
  1609. editorUi.handleError(e);
  1610. }
  1611. }]];
  1612. var dlg = new TextareaDialog(editorUi, 'Diff/Sync:', '',
  1613. function(newValue)
  1614. {
  1615. var file = editorUi.getCurrentFile();
  1616. if (newValue.length > 0 && file != null)
  1617. {
  1618. try
  1619. {
  1620. var patch = JSON.parse(newValue);
  1621. file.patch([patch], null, true, true);
  1622. editorUi.hideDialog();
  1623. }
  1624. catch (e)
  1625. {
  1626. editorUi.handleError(e);
  1627. }
  1628. }
  1629. }, null, 'Close', null, null, null, true, null, 'Patch', null, buttons);
  1630. if (snapshot == null)
  1631. {
  1632. snapshot = editorUi.getPagesForXml(editorUi.getFileData(true));
  1633. dlg.textarea.value = 'Snapshot created ' + new Date().toLocaleString() +
  1634. ' Checksum ' + editorUi.getHashValueForPages(snapshot);
  1635. }
  1636. else
  1637. {
  1638. dlg.textarea.value = JSON.stringify(editorUi.diffPages(
  1639. snapshot, editorUi.pages), null, 2);
  1640. }
  1641. editorUi.showDialog(dlg.container, 620, 460, true, true);
  1642. dlg.init();
  1643. }
  1644. else
  1645. {
  1646. editorUi.alert('No pages');
  1647. }
  1648. }));
  1649. editorUi.actions.addAction('testChecksum', mxUtils.bind(this, function()
  1650. {
  1651. var file = editorUi.getCurrentFile();
  1652. if (editorUi.pages != null && file != null)
  1653. {
  1654. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1655. {
  1656. file.getLatestVersion(function(latestFile)
  1657. {
  1658. editorUi.spinner.stop();
  1659. var localChecksum = editorUi.getHashValueForPages(editorUi.pages);
  1660. var localRev = file.getCurrentRevisionId();
  1661. var remoteChecksum = editorUi.getHashValueForPages(
  1662. latestFile.getShadowPages());
  1663. var descChecksum = latestFile.getDescriptorChecksum(
  1664. latestFile.getDescriptor());
  1665. var remoteRev = latestFile.getCurrentRevisionId();
  1666. console.log('Local File', [file],
  1667. 'modified', file.isModified(),
  1668. 'checksum', localChecksum);
  1669. console.log('Remote File', [latestFile],
  1670. 'rev', remoteRev == localRev,
  1671. 'desc', descChecksum == remoteChecksum,
  1672. 'checksum', remoteChecksum);
  1673. editorUi.alert('Checksums ' +
  1674. (remoteChecksum == localChecksum ?
  1675. 'match' : 'no not match'));
  1676. }, function(err)
  1677. {
  1678. console.log('Error getLatestVersion', err);
  1679. editorUi.handleError(err);
  1680. });
  1681. }
  1682. }
  1683. else
  1684. {
  1685. console.log('Checksum: no file or pages');
  1686. }
  1687. }));
  1688. editorUi.actions.addAction('testCheckPages', mxUtils.bind(this, function()
  1689. {
  1690. var file = editorUi.getCurrentFile();
  1691. console.log('editorUi', editorUi, 'file', file);
  1692. if (file != null && file.isRealtime())
  1693. {
  1694. console.log('Checksum ownPages',
  1695. editorUi.getHashValueForPages(
  1696. file.ownPages));
  1697. console.log('Checksum theirPages',
  1698. editorUi.getHashValueForPages(
  1699. file.theirPages));
  1700. console.log('diff ownPages/theirPages',
  1701. editorUi.diffPages(file.ownPages,
  1702. file.theirPages));
  1703. var shadow = file.getShadowPages();
  1704. if (shadow != null)
  1705. {
  1706. console.log('Checksum shadowPages',
  1707. editorUi.getHashValueForPages(shadow));
  1708. console.log('diff shadowPages/ownPages',
  1709. editorUi.diffPages(shadow, file.ownPages));
  1710. console.log('diff ownPages/shadowPages',
  1711. editorUi.diffPages(file.ownPages, shadow));
  1712. console.log('diff theirPages/shadowPages',
  1713. editorUi.diffPages(file.theirPages, shadow));
  1714. }
  1715. if (file.sync != null && file.sync.snapshot != null)
  1716. {
  1717. console.log('Checksum snapshot',
  1718. editorUi.getHashValueForPages(
  1719. file.sync.snapshot));
  1720. console.log('diff ownPages/snapshot',
  1721. editorUi.diffPages(file.ownPages,
  1722. file.sync.snapshot));
  1723. console.log('diff theirPages/snapshot',
  1724. editorUi.diffPages(file.theirPages,
  1725. file.sync.snapshot));
  1726. if (editorUi.pages != null)
  1727. {
  1728. console.log('diff snapshot/actualPages',
  1729. editorUi.diffPages(file.sync.snapshot,
  1730. editorUi.pages));
  1731. }
  1732. }
  1733. if (editorUi.pages != null)
  1734. {
  1735. console.log('diff ownPages/actualPages',
  1736. editorUi.diffPages(file.ownPages,
  1737. editorUi.pages));
  1738. console.log('diff theirPages/actualPages',
  1739. editorUi.diffPages(file.theirPages,
  1740. editorUi.pages));
  1741. }
  1742. }
  1743. if (file != null)
  1744. {
  1745. console.log('Shadow pages',
  1746. [editorUi.getXmlForPages(
  1747. file.getShadowPages())]);
  1748. }
  1749. if (editorUi.pages != null)
  1750. {
  1751. console.log('Checksum actualPages',
  1752. editorUi.getHashValueForPages(
  1753. editorUi.pages));
  1754. }
  1755. }));
  1756. editorUi.actions.addAction('testFixPages', mxUtils.bind(this, function()
  1757. {
  1758. console.log('editorUi', editorUi);
  1759. var file = editorUi.getCurrentFile();
  1760. if (file != null && file.isRealtime() &&
  1761. file.shadowPages != null)
  1762. {
  1763. console.log('patching actualPages to shadowPages',
  1764. file.patch([editorUi.diffPages(
  1765. file.shadowPages, editorUi.pages)]));
  1766. file.ownPages = editorUi.clonePages(editorUi.pages);
  1767. file.theirPages = editorUi.clonePages(editorUi.pages);
  1768. file.shadowPages = editorUi.clonePages(editorUi.pages);
  1769. if (file.sync != null)
  1770. {
  1771. file.sync.snapshot = editorUi.clonePages(editorUi.pages);
  1772. }
  1773. }
  1774. }));
  1775. editorUi.actions.addAction('testOptimize', mxUtils.bind(this, function()
  1776. {
  1777. graph.model.beginUpdate();
  1778. try
  1779. {
  1780. var all = graph.model.cells;
  1781. var imageCount = 0;
  1782. var images = [];
  1783. var cells = [];
  1784. for (var id in all)
  1785. {
  1786. var cell = all[id];
  1787. var style = graph.getCurrentCellStyle(cell);
  1788. var image = style[mxConstants.STYLE_IMAGE];
  1789. if (image != null && image.substring(0, 5) == 'data:')
  1790. {
  1791. if (images[image] == null)
  1792. {
  1793. images[image] = (images[image] || 0) + 1;
  1794. imageCount++;
  1795. }
  1796. cells.push(cell);
  1797. }
  1798. }
  1799. graph.setCellStyles(mxConstants.STYLE_IMAGE, null, cells);
  1800. console.log('Removed', imageCount, 'image(s) from', cells.length, 'cell(s): ', [cells, images]);
  1801. }
  1802. finally
  1803. {
  1804. graph.model.endUpdate();
  1805. }
  1806. }));
  1807. editorUi.actions.addAction('testInspect', mxUtils.bind(this, function()
  1808. {
  1809. console.log(editorUi, graph.getModel());
  1810. }));
  1811. editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  1812. {
  1813. var scale = 1;
  1814. var b = 1;
  1815. var imgExport = new mxImageExport();
  1816. var bounds = graph.getGraphBounds();
  1817. var vs = graph.view.scale;
  1818. // New image export
  1819. var xmlDoc = mxUtils.createXmlDocument();
  1820. var root = xmlDoc.createElement('output');
  1821. xmlDoc.appendChild(root);
  1822. // Renders graph. Offset will be multiplied with state's scale when painting state.
  1823. var xmlCanvas = new mxXmlCanvas2D(root);
  1824. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs),
  1825. Math.floor((b / scale - bounds.y) / vs));
  1826. xmlCanvas.scale(scale / vs);
  1827. var stateCounter = 0;
  1828. var canvasSave = xmlCanvas.save;
  1829. xmlCanvas.save = function()
  1830. {
  1831. stateCounter++;
  1832. canvasSave.apply(this, arguments);
  1833. };
  1834. var canvasRestore = xmlCanvas.restore;
  1835. xmlCanvas.restore = function()
  1836. {
  1837. stateCounter--;
  1838. canvasRestore.apply(this, arguments);
  1839. };
  1840. var exportDrawShape = imgExport.drawShape;
  1841. imgExport.drawShape = function(state)
  1842. {
  1843. mxLog.debug('entering shape', state, stateCounter);
  1844. exportDrawShape.apply(this, arguments);
  1845. mxLog.debug('leaving shape', state, stateCounter);
  1846. };
  1847. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1848. // Puts request data together
  1849. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  1850. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  1851. mxLog.show();
  1852. mxLog.debug(mxUtils.getXml(root));
  1853. mxLog.debug('stateCounter', stateCounter);
  1854. }));
  1855. editorUi.actions.addAction('testShowConsole', function()
  1856. {
  1857. if (!mxLog.isVisible())
  1858. {
  1859. mxLog.show();
  1860. }
  1861. else
  1862. {
  1863. mxLog.window.fit();
  1864. }
  1865. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 2;
  1866. });
  1867. // Adds logging for performance
  1868. var prevRevalidate = null;
  1869. var prevSelectPage = null;
  1870. var prevDiffPages = null;
  1871. var prevPatchPages = null;
  1872. var prevClonePages = null;
  1873. var prevGetFileData = null;
  1874. var prevGetHashValueForPages = null;
  1875. var prevResolveCrossReferences = null;
  1876. editorUi.actions.addAction('testPerformance', mxUtils.bind(this, function()
  1877. {
  1878. if (prevRevalidate != null)
  1879. {
  1880. graph.view.revalidate = prevRevalidate;
  1881. prevRevalidate = null;
  1882. }
  1883. else
  1884. {
  1885. prevRevalidate = graph.view.revalidate;
  1886. graph.view.revalidate = function()
  1887. {
  1888. var t0 = Date.now();
  1889. var result = prevRevalidate.apply(this, arguments);
  1890. EditorUi.debug('[Performance] mxGraphView.revalidate',
  1891. [this], 'time', (Date.now() - t0) + ' ms',
  1892. 'args', arguments);
  1893. return result;
  1894. };
  1895. }
  1896. if (prevSelectPage != null)
  1897. {
  1898. editorUi.selectPage = prevSelectPage;
  1899. prevSelectPage = null;
  1900. }
  1901. else
  1902. {
  1903. prevSelectPage = editorUi.selectPage;
  1904. editorUi.selectPage = function()
  1905. {
  1906. var t0 = Date.now();
  1907. var result = prevSelectPage.apply(this, arguments);
  1908. EditorUi.debug('[Performance] EditorUi.selectPage',
  1909. [this], 'time', (Date.now() - t0) + ' ms',
  1910. 'args', arguments);
  1911. return result;
  1912. };
  1913. }
  1914. if (prevDiffPages != null)
  1915. {
  1916. editorUi.diffPages = prevDiffPages;
  1917. prevDiffPages = null;
  1918. }
  1919. else
  1920. {
  1921. prevDiffPages = editorUi.diffPages;
  1922. editorUi.diffPages = function()
  1923. {
  1924. var t0 = Date.now();
  1925. var result = prevDiffPages.apply(this, arguments);
  1926. EditorUi.debug('[Performance] EditorUi.diffPages',
  1927. [this], 'time', (Date.now() - t0) + ' ms',
  1928. 'args', arguments);
  1929. return result;
  1930. };
  1931. }
  1932. if (prevPatchPages != null)
  1933. {
  1934. editorUi.patchPages = prevPatchPages;
  1935. prevPatchPages = null;
  1936. }
  1937. else
  1938. {
  1939. prevPatchPages = editorUi.patchPages;
  1940. editorUi.patchPages = function()
  1941. {
  1942. var t0 = Date.now();
  1943. var result = prevPatchPages.apply(this, arguments);
  1944. EditorUi.debug('[Performance] EditorUi.patchPages',
  1945. [this], 'time', (Date.now() - t0) + ' ms',
  1946. 'args', arguments);
  1947. return result;
  1948. };
  1949. };
  1950. if (prevClonePages != null)
  1951. {
  1952. editorUi.clonePages = prevClonePages;
  1953. prevClonePages = null;
  1954. }
  1955. else
  1956. {
  1957. prevClonePages = editorUi.clonePages;
  1958. editorUi.clonePages = function()
  1959. {
  1960. var t0 = Date.now();
  1961. var result = prevClonePages.apply(this, arguments);
  1962. EditorUi.debug('[Performance] EditorUi.clonePages',
  1963. [this], 'time', (Date.now() - t0) + ' ms',
  1964. 'args', arguments);
  1965. return result;
  1966. };
  1967. };
  1968. if (prevGetHashValueForPages != null)
  1969. {
  1970. editorUi.getHashValueForPages = prevGetHashValueForPages;
  1971. prevGetHashValueForPages = null;
  1972. }
  1973. else
  1974. {
  1975. prevGetHashValueForPages = editorUi.getHashValueForPages;
  1976. editorUi.getHashValueForPages = function()
  1977. {
  1978. var t0 = Date.now();
  1979. var result = prevGetHashValueForPages.apply(this, arguments);
  1980. EditorUi.debug('[Performance] EditorUi.getHashValueForPages',
  1981. [this], 'time', (Date.now() - t0) + ' ms',
  1982. 'args', arguments);
  1983. return result;
  1984. };
  1985. }
  1986. if (prevResolveCrossReferences != null)
  1987. {
  1988. editorUi.resolveCrossReferences = prevResolveCrossReferences;
  1989. prevResolveCrossReferences = null;
  1990. }
  1991. else
  1992. {
  1993. prevResolveCrossReferences = editorUi.resolveCrossReferences;
  1994. editorUi.resolveCrossReferences = function()
  1995. {
  1996. var t0 = Date.now();
  1997. var result = prevResolveCrossReferences.apply(this, arguments);
  1998. EditorUi.debug('[Performance] EditorUi.resolveCrossReferences',
  1999. [this], 'time', (Date.now() - t0) + ' ms',
  2000. 'args', arguments);
  2001. return result;
  2002. };
  2003. }
  2004. if (prevGetFileData != null)
  2005. {
  2006. editorUi.getFileData = prevGetFileData;
  2007. prevGetFileData = null;
  2008. }
  2009. else
  2010. {
  2011. prevGetFileData = editorUi.getFileData;
  2012. editorUi.getFileData = function()
  2013. {
  2014. var t0 = Date.now();
  2015. var result = prevGetFileData.apply(this, arguments);
  2016. EditorUi.debug('[Performance] EditorUi.getFileData',
  2017. [this], 'time', (Date.now() - t0) + ' ms',
  2018. 'args', arguments);
  2019. return result;
  2020. };
  2021. }
  2022. EditorUi.debug('[Performance]', (prevRevalidate != null) ? 'Enabled' : 'Disabled');
  2023. }));
  2024. this.put('testDevelop', new Menu(mxUtils.bind(this, function(menu, parent)
  2025. {
  2026. this.addMenuItems(menu, ['createSidebarEntry', 'showBoundingBox', '-',
  2027. 'testCheckPages', 'testChecksum', 'testFixPages', '-',
  2028. 'testCheckFile', 'testDiff', '-', 'testInspect', 'testOptimize', '-',
  2029. 'testXmlImageExport', '-'], parent);
  2030. var item = menu.addItem(mxResources.get('testPerformance'), null, function()
  2031. {
  2032. editorUi.actions.get('testPerformance').funct();
  2033. }, parent);
  2034. if (prevRevalidate != null)
  2035. {
  2036. menu.addCheckmark(item, Editor.checkmarkImage);
  2037. }
  2038. this.addMenuItems(menu, ['-', 'testShowConsole'], parent);
  2039. })));
  2040. }
  2041. editorUi.actions.put('shapes', new Action(mxResources.get('moreShapes') + '...', function(evt)
  2042. {
  2043. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  2044. {
  2045. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  2046. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  2047. }
  2048. else
  2049. {
  2050. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  2051. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  2052. }
  2053. }));
  2054. editorUi.actions.put('createShape', new Action(mxResources.get('shape') + '...', function(evt)
  2055. {
  2056. if (graph.isEnabled())
  2057. {
  2058. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  2059. cell.vertex = true;
  2060. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  2061. editorUi.showDialog(dlg.container, 640, 480, true, false);
  2062. dlg.init();
  2063. }
  2064. })).isEnabled = isGraphEnabled;
  2065. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  2066. {
  2067. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  2068. {
  2069. editorUi.showHtmlDialog(mxResources.get('create'), 'https://www.drawio.com/doc/faq/embed-html-options',
  2070. url, function(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages, layers, tags, lightbox, editLink)
  2071. {
  2072. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages,
  2073. layers, tags, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  2074. {
  2075. // Comment is workaround for file data check in checkFileContent for Electron
  2076. var dlg = new EmbedDialog(editorUi, '<!-- ' + editorUi.editor.appName + ' diagram -->\n' +
  2077. html + '\n' + scriptTag + '\n', null, null, function()
  2078. {
  2079. var wnd = window.open();
  2080. var doc = wnd.document;
  2081. if (doc != null)
  2082. {
  2083. if (document.compatMode === 'CSS1Compat')
  2084. {
  2085. doc.writeln('<!DOCTYPE html>');
  2086. }
  2087. doc.writeln('<html>');
  2088. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  2089. '</title><meta charset="utf-8"></head>');
  2090. doc.writeln('<body>');
  2091. doc.writeln(html);
  2092. var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
  2093. if (direct)
  2094. {
  2095. doc.writeln(scriptTag);
  2096. }
  2097. doc.writeln('</body>');
  2098. doc.writeln('</html>');
  2099. doc.close();
  2100. // Adds script tag after closing page and delay to fix timing issues
  2101. if (!direct)
  2102. {
  2103. var info = wnd.document.createElement('div');
  2104. info.marginLeft = '26px';
  2105. info.marginTop = '26px';
  2106. mxUtils.write(info, mxResources.get('updatingDocument'));
  2107. var img = wnd.document.createElement('img');
  2108. img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
  2109. '/' + IMAGE_PATH + '/spin.gif');
  2110. img.style.marginLeft = '6px';
  2111. info.appendChild(img);
  2112. wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
  2113. window.setTimeout(function()
  2114. {
  2115. var script = document.createElement('script');
  2116. script.type = 'text/javascript';
  2117. script.src = /<script.*?src="(.*?)"/.exec(scriptTag)[1];
  2118. doc.body.appendChild(script);
  2119. info.parentNode.removeChild(info);
  2120. }, 20);
  2121. }
  2122. }
  2123. else
  2124. {
  2125. editorUi.handleError({message: mxResources.get('errorUpdatingPreview')});
  2126. }
  2127. });
  2128. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2129. dlg.init();
  2130. }));
  2131. });
  2132. });
  2133. }));
  2134. editorUi.actions.put('liveImage', new Action('Live image...', function()
  2135. {
  2136. var current = editorUi.getCurrentFile();
  2137. if (current != null)
  2138. {
  2139. editorUi.getPublicUrl(current, function(url)
  2140. {
  2141. if (url != null)
  2142. {
  2143. var dlg = new EmbedDialog(editorUi, '<img src="' + ((current.constructor != DriveFile) ?
  2144. url : 'https://drive.google.com/uc?id=' + current.getId()) + '"/>');
  2145. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2146. dlg.init();
  2147. }
  2148. else
  2149. {
  2150. editorUi.handleError({message: mxResources.get('invalidPublicUrl')});
  2151. }
  2152. });
  2153. }
  2154. }));
  2155. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  2156. {
  2157. editorUi.showEmbedImageDialog(function(fit, shadow, retina, lightbox, editLink, layers)
  2158. {
  2159. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2160. {
  2161. editorUi.createEmbedImage(fit, shadow, retina, lightbox, editLink, layers, function(result)
  2162. {
  2163. editorUi.spinner.stop();
  2164. var dlg = new EmbedDialog(editorUi, result);
  2165. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2166. dlg.init();
  2167. }, function(err)
  2168. {
  2169. editorUi.spinner.stop();
  2170. editorUi.handleError(err);
  2171. });
  2172. }
  2173. }, mxResources.get('image'), mxResources.get('retina'), editorUi.isExportToCanvas());
  2174. }));
  2175. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  2176. {
  2177. editorUi.showEmbedImageDialog(function(fit, shadow, image, lightbox, editLink, layers)
  2178. {
  2179. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2180. {
  2181. editorUi.createEmbedSvg(fit, shadow, image, lightbox, editLink, layers, function(result)
  2182. {
  2183. editorUi.spinner.stop();
  2184. var dlg = new EmbedDialog(editorUi, result);
  2185. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2186. dlg.init();
  2187. }, function(err)
  2188. {
  2189. editorUi.spinner.stop();
  2190. editorUi.handleError(err);
  2191. });
  2192. }
  2193. }, mxResources.get('formatSvg'), mxResources.get('image'),
  2194. true, 'https://www.drawio.com/doc/faq/embed-svg.html');
  2195. }));
  2196. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  2197. {
  2198. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(publicUrl)
  2199. {
  2200. var bounds = graph.getGraphBounds();
  2201. editorUi.showPublishLinkDialog(mxResources.get('iframe'), '100%',
  2202. Math.ceil(Math.max(100, bounds.height / graph.view.scale)) + 2, null, null, null,
  2203. publicUrl, editorUi.getCurrentFile(), function(linkTarget, linkColor,
  2204. currentPage, lightbox, editLink, layers, width, height, tags, link)
  2205. {
  2206. var params = [];
  2207. if (tags)
  2208. {
  2209. params.push('tags=%7B%7D');
  2210. }
  2211. var dlg = new EmbedDialog(editorUi, '<iframe frameborder="0" style="width:' + width +
  2212. ';height:' + height + ';" src="' + editorUi.createLink(linkTarget, linkColor,
  2213. true, lightbox, editLink, layers, (link == 'public') ? publicUrl : null,
  2214. null, params, null, currentPage) + '"></iframe>');
  2215. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2216. dlg.init();
  2217. }, true);
  2218. });
  2219. }));
  2220. editorUi.actions.put('embedNotion', new Action(mxResources.get('notion') + '...', function()
  2221. {
  2222. var footer = document.createElement('div');
  2223. footer.style.position = 'absolute';
  2224. footer.style.bottom = '30px';
  2225. footer.style.textAlign = 'center';
  2226. footer.style.width = '100%';
  2227. footer.style.left = '0px';
  2228. var link = document.createElement('a');
  2229. link.setAttribute('href', 'javascript:void(0);');
  2230. link.setAttribute('target', '_blank');
  2231. link.style.cursor = 'pointer';
  2232. mxUtils.write(link, mxResources.get('getNotionChromeExtension'));
  2233. footer.appendChild(link);
  2234. mxUtils.setPrefixedStyle(link.style, 'transition', 'all 1s ease');
  2235. mxUtils.setOpacity(link, 0);
  2236. window.setTimeout(function()
  2237. {
  2238. mxUtils.setOpacity(link, 100);
  2239. }, 300);
  2240. mxEvent.addListener(link, 'click', function(evt)
  2241. {
  2242. editorUi.openLink('https://chrome.google.com/webstore/detail/drawio-for-notion/plhaalebpkihaccllnkdaokdoeaokmle');
  2243. mxEvent.consume(evt);
  2244. });
  2245. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(publicUrl)
  2246. {
  2247. editorUi.showPublishLinkDialog(mxResources.get('notion'), null, null, true,
  2248. 'https://www.drawio.com/blog/drawio-notion', footer, publicUrl, editorUi.getCurrentFile(),
  2249. function(linkTarget, linkColor, currentPage, lightbox, editLink, layers, width, height, tags, link)
  2250. {
  2251. var params = ['border=0'];
  2252. if (tags)
  2253. {
  2254. params.push('tags=%7B%7D');
  2255. }
  2256. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget, linkColor,
  2257. true, lightbox, editLink, layers, (link == 'public') ? publicUrl : null,
  2258. null, params, null, currentPage));
  2259. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2260. dlg.init();
  2261. });
  2262. });
  2263. }));
  2264. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  2265. {
  2266. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(publicUrl)
  2267. {
  2268. editorUi.showPublishLinkDialog(null, null, null, null, null, null, publicUrl, editorUi.getCurrentFile(),
  2269. function(linkTarget, linkColor, currentPage, lightbox, editLink, layers, width, height, tags, link)
  2270. {
  2271. var params = [];
  2272. if (lightbox && tags)
  2273. {
  2274. params.push('tags=%7B%7D');
  2275. }
  2276. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget, linkColor,
  2277. true, lightbox, editLink, layers, (link == 'public') ? publicUrl : null,
  2278. null, params, null, currentPage));
  2279. editorUi.showDialog(dlg.container, 450, 240, true, true);
  2280. dlg.init();
  2281. });
  2282. });
  2283. }));
  2284. editorUi.actions.addAction('microsoftOffice...', function()
  2285. {
  2286. editorUi.openLink('https://office.draw.io');
  2287. });
  2288. editorUi.actions.addAction('googleDocs...', function()
  2289. {
  2290. editorUi.openLink('http://docsaddon.draw.io');
  2291. });
  2292. editorUi.actions.addAction('googleSlides...', function()
  2293. {
  2294. editorUi.openLink('https://slidesaddon.draw.io');
  2295. });
  2296. editorUi.actions.addAction('googleSheets...', function()
  2297. {
  2298. editorUi.openLink('https://sheetsaddon.draw.io');
  2299. });
  2300. editorUi.actions.addAction('googleSites...', function()
  2301. {
  2302. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  2303. {
  2304. var dlg = new GoogleSitesDialog(editorUi, url);
  2305. editorUi.showDialog(dlg.container, 420, 256, true, true);
  2306. dlg.init();
  2307. });
  2308. });
  2309. // Adds plugins menu item only if localStorage is available for storing the plugins
  2310. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  2311. {
  2312. var action = editorUi.actions.addAction('scratchpad', function()
  2313. {
  2314. editorUi.toggleScratchpad();
  2315. });
  2316. action.setToggleAction(true);
  2317. action.setSelectedCallback(function()
  2318. {
  2319. return editorUi.scratchpad != null;
  2320. });
  2321. if (urlParams['plugins'] != '0')
  2322. {
  2323. editorUi.actions.addAction('plugins...', function()
  2324. {
  2325. editorUi.showDialog(new PluginsDialog(editorUi).container, 380, 240, true, false);
  2326. });
  2327. }
  2328. }
  2329. var action = editorUi.actions.addAction('improveContrast', function()
  2330. {
  2331. editorUi.setCssDarkModeEnabled(!Editor.enableCssDarkMode);
  2332. });
  2333. action.setToggleAction(true);
  2334. action.setSelectedCallback(function()
  2335. {
  2336. return Editor.enableCssDarkMode;
  2337. });
  2338. if (window.matchMedia && document.getElementById('high-contrast-stylesheet') != null)
  2339. {
  2340. var action = editorUi.actions.addAction('highContrast', function()
  2341. {
  2342. editorUi.setAndPersistHighContrast(!editorUi.isHighContrast());
  2343. });
  2344. action.setToggleAction(true);
  2345. action.setSelectedCallback(function()
  2346. {
  2347. return editorUi.isHighContrast();
  2348. });
  2349. }
  2350. var action = editorUi.actions.addAction('search', function()
  2351. {
  2352. var visible = editorUi.sidebar.isEntryVisible('search');
  2353. editorUi.sidebar.showPalette('search', !visible);
  2354. if (Editor.isSettingsEnabled())
  2355. {
  2356. mxSettings.settings.search = !visible;
  2357. mxSettings.save();
  2358. }
  2359. });
  2360. action.label = mxResources.get('searchShapes');
  2361. action.setToggleAction(true);
  2362. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  2363. editorUi.actions.get('clearDefaultStyle').funct = function(exit)
  2364. {
  2365. if (graph.isEnabled())
  2366. {
  2367. editorUi.clearDefaultStyle();
  2368. if (Editor.sketchMode)
  2369. {
  2370. editorUi.setSketchMode(false);
  2371. }
  2372. }
  2373. };
  2374. if (urlParams['embed'] == '1')
  2375. {
  2376. editorUi.actions.get('save').funct = function(exit)
  2377. {
  2378. if (graph.isEditing())
  2379. {
  2380. graph.stopEditing();
  2381. }
  2382. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  2383. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  2384. if (urlParams['proto'] == 'json')
  2385. {
  2386. var msg = editorUi.createLoadMessage('save');
  2387. msg.xml = data;
  2388. if (exit)
  2389. {
  2390. msg.exit = true;
  2391. }
  2392. data = JSON.stringify(msg);
  2393. }
  2394. var parent = window.opener || window.parent;
  2395. parent.postMessage(data, '*');
  2396. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  2397. {
  2398. editorUi.editor.modified = false;
  2399. editorUi.editor.setStatus('');
  2400. }
  2401. //Add support to saving files if embedded mode is running with files
  2402. var file = editorUi.getCurrentFile();
  2403. if (file != null && file.constructor != EmbedFile &&
  2404. (file.constructor != LocalFile || file.mode != null))
  2405. {
  2406. editorUi.saveFile();
  2407. }
  2408. };
  2409. var saveAndExitAction = editorUi.actions.addAction('saveAndExit', function()
  2410. {
  2411. if (urlParams['toSvg'] == '1')
  2412. {
  2413. editorUi.sendEmbeddedSvgExport();
  2414. }
  2415. else
  2416. {
  2417. editorUi.actions.get('save').funct(true);
  2418. }
  2419. });
  2420. saveAndExitAction.label = urlParams['publishClose'] == '1' ? mxResources.get('publish') : mxResources.get('saveAndExit');
  2421. editorUi.actions.addAction('exit', function()
  2422. {
  2423. if (urlParams['embedInline'] == '1')
  2424. {
  2425. editorUi.sendEmbeddedSvgExport();
  2426. }
  2427. else
  2428. {
  2429. var fn = function()
  2430. {
  2431. editorUi.editor.modified = false;
  2432. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  2433. modified: editorUi.editor.modified}) : '';
  2434. var parent = window.opener || window.parent;
  2435. parent.postMessage(msg, '*');
  2436. }
  2437. if (!editorUi.editor.modified)
  2438. {
  2439. fn();
  2440. }
  2441. else
  2442. {
  2443. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  2444. mxResources.get('cancel'), mxResources.get('discardChanges'));
  2445. }
  2446. }
  2447. }, null, null, (urlParams['embedInline'] == '1') ? 'Escape' : null);
  2448. }
  2449. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  2450. {
  2451. if (editorUi.isExportToCanvas())
  2452. {
  2453. this.addMenuItems(menu, ['exportPng'], parent);
  2454. if (editorUi.jpgSupported)
  2455. {
  2456. this.addMenuItems(menu, ['exportJpg'], parent);
  2457. }
  2458. if (editorUi.webpSupported)
  2459. {
  2460. this.addMenuItems(menu, ['exportWebp'], parent);
  2461. }
  2462. }
  2463. // Disabled for standalone mode in iOS because new tab cannot be closed
  2464. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  2465. {
  2466. this.addMenuItems(menu, ['exportPng', 'exportJpg'], parent);
  2467. }
  2468. this.addMenuItems(menu, ['exportSvg', '-'], parent);
  2469. // Redirects export to PDF to print in Chrome App
  2470. if (editorUi.isOffline() || editorUi.printPdfExport)
  2471. {
  2472. this.addMenuItems(menu, ['exportPdf'], parent);
  2473. }
  2474. // Disabled for standalone mode in iOS because new tab cannot be closed
  2475. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  2476. {
  2477. this.addMenuItems(menu, ['exportPdf'], parent);
  2478. }
  2479. if (!mxClient.IS_IE && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
  2480. {
  2481. this.addMenuItems(menu, ['exportVsdx'], parent);
  2482. }
  2483. this.addMenuItems(menu, ['-', 'exportHtml', 'exportXml', 'exportUrl'], parent);
  2484. if (!editorUi.isOffline())
  2485. {
  2486. menu.addSeparator(parent);
  2487. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  2488. }
  2489. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp && Editor.currentTheme == 'min')
  2490. {
  2491. this.addMenuItems(menu, ['publishLink'], parent);
  2492. }
  2493. if (editorUi.mode != App.MODE_ATLAS && urlParams['extAuth'] != '1' &&
  2494. (Editor.currentTheme == 'simple' || Editor.currentTheme == 'sketch' ||
  2495. Editor.currentTheme == 'min'))
  2496. {
  2497. menu.addSeparator(parent);
  2498. editorUi.menus.addSubmenu('embed', menu, parent);
  2499. }
  2500. })));
  2501. this.put('importFrom', new Menu(mxUtils.bind(this, function(menu, parent)
  2502. {
  2503. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  2504. {
  2505. // Gets insert location
  2506. var view = graph.view;
  2507. var bds = graph.getGraphBounds();
  2508. var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
  2509. var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
  2510. if (data.substring(0, 11) == 'data:image/')
  2511. {
  2512. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  2513. {
  2514. var resizeImages = true;
  2515. var doInsert = mxUtils.bind(this, function()
  2516. {
  2517. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  2518. {
  2519. var s = (resizeImages) ? Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2)) : 1;
  2520. editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  2521. {
  2522. editorUi.spinner.stop();
  2523. graph.setSelectionCells(cells);
  2524. graph.scrollCellToVisible(graph.getSelectionCell());
  2525. });
  2526. }), resizeImages);
  2527. });
  2528. if (data.length > editorUi.resampleThreshold)
  2529. {
  2530. editorUi.confirmImageResize(function(doResize)
  2531. {
  2532. resizeImages = doResize;
  2533. doInsert();
  2534. });
  2535. }
  2536. else
  2537. {
  2538. doInsert();
  2539. }
  2540. }), mxUtils.bind(this, function()
  2541. {
  2542. editorUi.handleError({message: mxResources.get('cannotOpenFile')});
  2543. }));
  2544. }
  2545. else
  2546. {
  2547. editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
  2548. {
  2549. editorUi.spinner.stop();
  2550. graph.setSelectionCells(cells);
  2551. graph.scrollCellToVisible(graph.getSelectionCell());
  2552. });
  2553. }
  2554. });
  2555. var getMimeType = mxUtils.bind(this, function(filename)
  2556. {
  2557. var mime = 'text/xml';
  2558. if (/\.png$/i.test(filename))
  2559. {
  2560. mime = 'image/png';
  2561. }
  2562. else if (/\.jpe?g$/i.test(filename))
  2563. {
  2564. mime = 'image/jpg';
  2565. }
  2566. else if (/\.gif$/i.test(filename))
  2567. {
  2568. mime = 'image/gif';
  2569. }
  2570. else if (/\.pdf$/i.test(filename))
  2571. {
  2572. mime = 'application/pdf';
  2573. }
  2574. return mime;
  2575. });
  2576. function pickFileFromService(service)
  2577. {
  2578. // Drive requires special arguments for libraries and bypassing realtime
  2579. service.pickFile(function(id)
  2580. {
  2581. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2582. {
  2583. // NOTE The third argument in getFile says denyConvert to match
  2584. // the existing signature in the original DriveClient which has
  2585. // as slightly different semantic, but works the same way.
  2586. service.getFile(id, function(file)
  2587. {
  2588. var mime = (file.getData().substring(0, 11) == 'data:image/') ? getMimeType(file.getTitle()) : 'text/xml';
  2589. // Imports SVG as images
  2590. if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
  2591. {
  2592. file.setData(Editor.createSvgDataUri(file.getData()));
  2593. mime = 'image/svg+xml';
  2594. }
  2595. doImportFile(file.getData(), mime, file.getTitle());
  2596. },
  2597. function(resp)
  2598. {
  2599. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  2600. }, service == editorUi.drive);
  2601. }
  2602. }, true);
  2603. };
  2604. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  2605. {
  2606. if (editorUi.drive != null)
  2607. {
  2608. // Requires special arguments for libraries and realtime
  2609. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  2610. {
  2611. pickFileFromService(editorUi.drive);
  2612. }, parent);
  2613. }
  2614. else if (editorUi.isModeEnabled(App.MODE_GOOGLE))
  2615. {
  2616. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2617. {
  2618. // do nothing
  2619. }, parent, null, false);
  2620. }
  2621. }
  2622. if (editorUi.isModeReady(App.MODE_ONEDRIVE))
  2623. {
  2624. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  2625. {
  2626. pickFileFromService(editorUi.oneDrive);
  2627. }, parent);
  2628. }
  2629. else if (editorUi.isModeEnabled(App.MODE_ONEDRIVE))
  2630. {
  2631. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  2632. {
  2633. // do nothing
  2634. }, parent, null, false);
  2635. }
  2636. if (editorUi.isModeReady(App.MODE_DROPBOX))
  2637. {
  2638. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  2639. {
  2640. pickFileFromService(editorUi.dropbox);
  2641. }, parent);
  2642. }
  2643. else if (editorUi.isModeEnabled(App.MODE_DROPBOX))
  2644. {
  2645. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  2646. {
  2647. // do nothing
  2648. }, parent, null, false);
  2649. }
  2650. menu.addSeparator(parent);
  2651. if (editorUi.isModeReady(App.MODE_GITHUB))
  2652. {
  2653. menu.addItem(mxResources.get('github') + '...', null, function()
  2654. {
  2655. pickFileFromService(editorUi.gitHub);
  2656. }, parent);
  2657. }
  2658. if (editorUi.isModeReady(App.MODE_GITLAB))
  2659. {
  2660. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  2661. {
  2662. pickFileFromService(editorUi.gitLab);
  2663. }, parent);
  2664. }
  2665. if (editorUi.isModeReady(App.MODE_TRELLO))
  2666. {
  2667. menu.addItem(mxResources.get('trello') + '...', null, function()
  2668. {
  2669. pickFileFromService(editorUi.trello);
  2670. }, parent);
  2671. }
  2672. else if (editorUi.isModeEnabled(App.MODE_TRELLO))
  2673. {
  2674. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  2675. {
  2676. // do nothing
  2677. }, parent, null, false);
  2678. }
  2679. menu.addSeparator(parent);
  2680. if (isLocalStorage && urlParams['browser'] != '0')
  2681. {
  2682. menu.addItem(mxResources.get('browser') + '...', null, function()
  2683. {
  2684. editorUi.importLocalFile(false);
  2685. }, parent);
  2686. }
  2687. if (urlParams['noDevice'] != '1')
  2688. {
  2689. menu.addItem(mxResources.get('device') + '...', null, function()
  2690. {
  2691. editorUi.importLocalFile(true);
  2692. }, parent);
  2693. }
  2694. if (!editorUi.isOffline())
  2695. {
  2696. menu.addSeparator(parent);
  2697. menu.addItem(mxResources.get('url') + '...', null, function()
  2698. {
  2699. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  2700. {
  2701. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  2702. {
  2703. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  2704. // Uses proxy to avoid CORS issues
  2705. editorUi.editor.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  2706. {
  2707. doImportFile(data, mime, fileUrl);
  2708. },
  2709. function ()
  2710. {
  2711. editorUi.spinner.stop();
  2712. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  2713. }, mime == 'image/png');
  2714. }
  2715. }, mxResources.get('url'));
  2716. editorUi.showDialog(dlg.container, 300, 80, true, true);
  2717. dlg.init();
  2718. }, parent);
  2719. }
  2720. }))).isEnabled = isGraphEnabled;
  2721. this.put('dynamicAppearance', new Menu(mxUtils.bind(this, function(menu, parent)
  2722. {
  2723. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  2724. if (Editor.currentTheme == 'simple')
  2725. {
  2726. // Elements are hidden with the following widths:
  2727. // ViewZoom: <750
  2728. // Insert edge: <680
  2729. // Insert text: <660
  2730. // Comments: <560
  2731. // Insert Table: <500
  2732. // Pages: <480
  2733. // Insert Shapes: <440
  2734. // Insert Freehand: <390
  2735. // Share: <360
  2736. // Insert: <320
  2737. if (iw < 750)
  2738. {
  2739. this.addSubmenu('viewZoom', menu, parent, mxResources.get('zoom'));
  2740. }
  2741. if (iw < 460 && editorUi.isPageMenuVisible())
  2742. {
  2743. this.addSubmenu('pages', menu, parent);
  2744. }
  2745. if (iw < 320)
  2746. {
  2747. this.addSubmenu('insert', menu, parent);
  2748. }
  2749. if (iw < 360 && urlParams['embed'] != '1' &&
  2750. editorUi.getServiceName() == 'draw.io')
  2751. {
  2752. this.addSubmenu('share', menu, parent);
  2753. }
  2754. }
  2755. this.addMenuItems(menu, ['-', 'lightMode', 'darkMode'], parent);
  2756. if (editorUi.isAutoDarkModeSupported())
  2757. {
  2758. var item = editorUi.menus.addMenuItem(menu, 'autoMode', parent);
  2759. if (item != null)
  2760. {
  2761. item.setAttribute('title', mxResources.get('automatic') +
  2762. ' (' + mxResources.get(Editor.cssDarkMode || Editor.isDarkMode() ?
  2763. 'dark' : 'light') + ')');
  2764. }
  2765. }
  2766. if (urlParams['embed'] != '1')
  2767. {
  2768. this.addMenuItems(menu, ['-', 'toggleSimpleMode'], parent);
  2769. }
  2770. })));
  2771. this.put('appearance', new Menu(mxUtils.bind(this, function(menu, parent)
  2772. {
  2773. this.addMenuItems(menu, ['-', 'lightMode', 'darkMode'], parent);
  2774. if (editorUi.isAutoDarkModeSupported())
  2775. {
  2776. var item = editorUi.menus.addMenuItem(menu, 'autoMode', parent);
  2777. if (item != null)
  2778. {
  2779. item.setAttribute('title', mxResources.get('automatic') +
  2780. ' (' + mxResources.get(Editor.cssDarkMode || Editor.isDarkMode() ?
  2781. 'dark' : 'light') + ')');
  2782. }
  2783. }
  2784. menu.addSeparator(parent);
  2785. var item = editorUi.menus.addMenuItem(menu, 'improveContrast', parent);
  2786. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2787. {
  2788. editorUi.menus.addLinkToItem(item, 'https://github.com/jgraph/drawio/discussions/3701');
  2789. }
  2790. var item = editorUi.menus.addMenuItem(menu, 'highContrast', parent);
  2791. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  2792. {
  2793. editorUi.menus.addLinkToItem(item, 'https://github.com/jgraph/drawio/issues/4296');
  2794. }
  2795. })));
  2796. editorUi.actions.addAction('addToScratchpad', function(evt)
  2797. {
  2798. if (!graph.isSelectionEmpty() && editorUi.addSelectionToScratchpad != null)
  2799. {
  2800. editorUi.addSelectionToScratchpad(evt);
  2801. }
  2802. });
  2803. editorUi.actions.addAction('accounts...', function()
  2804. {
  2805. editorUi.toggleUserPanel();
  2806. editorUi.userPanel.style.right = '10px';
  2807. editorUi.userPanel.style.top = '10px';
  2808. });
  2809. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  2810. {
  2811. var theme = (urlParams['sketch'] == '1') ? 'sketch' : mxSettings.getUi();
  2812. var autoItem = menu.addItem(mxResources.get('automatic'), null, function()
  2813. {
  2814. editorUi.setCurrentTheme('');
  2815. }, parent);
  2816. var item = menu.addItem(mxResources.get('classic'), null, function()
  2817. {
  2818. editorUi.setCurrentTheme((!Editor.isDarkMode()) ? 'kennedy' : 'dark');
  2819. }, parent);
  2820. var themeFound = false;
  2821. if (theme == 'kennedy' || theme == 'dark')
  2822. {
  2823. menu.addCheckmark(item, Editor.checkmarkImage);
  2824. themeFound = true;
  2825. }
  2826. for (var i = 0; i < Editor.themes.length; i++)
  2827. {
  2828. (mxUtils.bind(this, function(key)
  2829. {
  2830. item = menu.addItem(mxResources.get((key == 'min') ?
  2831. 'minimal' : key), null, function()
  2832. {
  2833. editorUi.setCurrentTheme(key);
  2834. }, parent);
  2835. if (theme == key)
  2836. {
  2837. menu.addCheckmark(item, Editor.checkmarkImage);
  2838. themeFound = true;
  2839. }
  2840. })(Editor.themes[i]));
  2841. }
  2842. if (!themeFound)
  2843. {
  2844. menu.addCheckmark(autoItem, Editor.checkmarkImage);
  2845. }
  2846. })));
  2847. var renameAction = this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  2848. {
  2849. var file = this.editorUi.getCurrentFile();
  2850. if (file != null)
  2851. {
  2852. if (file.constructor == LocalFile && file.fileHandle != null)
  2853. {
  2854. editorUi.showSaveFilePicker(mxUtils.bind(editorUi, function(fileHandle, desc)
  2855. {
  2856. file.invalidFileHandle = null;
  2857. file.fileHandle = fileHandle;
  2858. file.title = desc.name;
  2859. file.desc = desc;
  2860. editorUi.save(desc.name);
  2861. }), null, editorUi.createFileSystemOptions(file.getTitle()));
  2862. }
  2863. else
  2864. {
  2865. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  2866. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  2867. {
  2868. if (title != null && title.length > 0 && file != null && title != file.getTitle() &&
  2869. this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  2870. {
  2871. // Delete old file, save new file in dropbox if autosize is enabled
  2872. file.rename(title, mxUtils.bind(this, function(resp)
  2873. {
  2874. this.editorUi.spinner.stop();
  2875. }),
  2876. mxUtils.bind(this, function(resp)
  2877. {
  2878. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  2879. }));
  2880. }
  2881. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  2882. mxResources.get('diagramName') : null, function(name)
  2883. {
  2884. if (name != null && name.length > 0)
  2885. {
  2886. return true;
  2887. }
  2888. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  2889. return false;
  2890. }, null, FilenameDialog.filenameHelpLink, null, null, editorUi.editor.fileExtensions);
  2891. this.editorUi.showDialog(dlg.container, 340, 96, true, true);
  2892. dlg.init();
  2893. }
  2894. }
  2895. }));
  2896. renameAction.isEnabled = function()
  2897. {
  2898. return this.enabled && isGraphEnabled.apply(this, arguments);
  2899. }
  2900. renameAction.visible = urlParams['embed'] != '1';
  2901. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  2902. {
  2903. var file = editorUi.getCurrentFile();
  2904. if (file != null)
  2905. {
  2906. var title = editorUi.getCopyFilename(file);
  2907. if (file.constructor == DriveFile)
  2908. {
  2909. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  2910. {
  2911. if (mode == '_blank')
  2912. {
  2913. editorUi.editor.editAsNew(editorUi.getFileData(), newTitle);
  2914. }
  2915. else
  2916. {
  2917. // Mode is "download" if Create button is pressed, means use Google Drive
  2918. if (mode == 'download')
  2919. {
  2920. mode = App.MODE_GOOGLE;
  2921. }
  2922. if (newTitle != null && newTitle.length > 0)
  2923. {
  2924. if (mode == App.MODE_GOOGLE)
  2925. {
  2926. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  2927. {
  2928. // Saveas does not update the file descriptor in Google Drive
  2929. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  2930. {
  2931. // Replaces file descriptor in-place and saves
  2932. file.desc = resp;
  2933. // Makes sure the latest XML is in the file
  2934. file.save(false, mxUtils.bind(this, function()
  2935. {
  2936. editorUi.spinner.stop();
  2937. file.setModified(false);
  2938. file.addAllSavedStatus();
  2939. }), mxUtils.bind(this, function(resp)
  2940. {
  2941. editorUi.handleError(resp);
  2942. }));
  2943. }), mxUtils.bind(this, function(resp)
  2944. {
  2945. editorUi.handleError(resp);
  2946. }));
  2947. }
  2948. }
  2949. else
  2950. {
  2951. editorUi.createFile(newTitle, editorUi.getFileData(true), null, mode);
  2952. }
  2953. }
  2954. }
  2955. }), mxUtils.bind(this, function()
  2956. {
  2957. editorUi.hideDialog();
  2958. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  2959. null, true, null, true, null, null, null, null,
  2960. editorUi.editor.fileExtensions);
  2961. editorUi.showDialog(dlg.container, 420, 380, true, true);
  2962. dlg.init();
  2963. }
  2964. else
  2965. {
  2966. // Creates a copy with no predefined storage
  2967. editorUi.editor.editAsNew(this.editorUi.getFileData(true), title);
  2968. }
  2969. }
  2970. }));
  2971. editorUi.actions.put('openFolder', new Action(mxResources.get('openIt', [mxResources.get('folder')]) + '...', function(evt, trigger)
  2972. {
  2973. var file = editorUi.getCurrentFile();
  2974. if (file != null)
  2975. {
  2976. editorUi.openLink(file.getFolderUrl());
  2977. }
  2978. }));
  2979. editorUi.actions.addAction('openFile...', mxUtils.bind(this, function()
  2980. {
  2981. var file = editorUi.getCurrentFile();
  2982. if (file != null)
  2983. {
  2984. editorUi.openLink(file.getFileUrl());
  2985. }
  2986. }));
  2987. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  2988. {
  2989. var file = editorUi.getCurrentFile();
  2990. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  2991. {
  2992. var isInRoot = false;
  2993. if (file.getMode() == App.MODE_GOOGLE && file.desc.parents != null)
  2994. {
  2995. for (var i = 0; i < file.desc.parents.length; i++)
  2996. {
  2997. if (file.desc.parents[i].isRoot)
  2998. {
  2999. isInRoot = true;
  3000. break;
  3001. }
  3002. }
  3003. }
  3004. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  3005. {
  3006. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  3007. {
  3008. file.move(folderId, mxUtils.bind(this, function(resp)
  3009. {
  3010. editorUi.spinner.stop();
  3011. }), mxUtils.bind(this, function(resp)
  3012. {
  3013. editorUi.handleError(resp);
  3014. }));
  3015. }
  3016. }), null, true, isInRoot);
  3017. }
  3018. }));
  3019. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  3020. {
  3021. this.addMenuItems(menu, ['publishLink'], parent);
  3022. })));
  3023. editorUi.actions.put('useOffline', new Action(mxResources.get('useOffline') + '...', function()
  3024. {
  3025. editorUi.openLink('https://app.draw.io/')
  3026. }));
  3027. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  3028. {
  3029. try
  3030. {
  3031. var file = editorUi.getCurrentFile();
  3032. if (file != null)
  3033. {
  3034. file.share();
  3035. }
  3036. }
  3037. catch (e)
  3038. {
  3039. editorUi.handleError(e);
  3040. }
  3041. })).isEnabled = isGraphEnabled;
  3042. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  3043. {
  3044. var file = editorUi.getCurrentFile();
  3045. if (file != null && (file.getMode() == App.MODE_GOOGLE ||
  3046. file.getMode() == App.MODE_GITHUB) && /(\.png)$/i.test(file.getTitle()))
  3047. {
  3048. this.addMenuItems(menu, ['liveImage', '-'], parent);
  3049. }
  3050. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  3051. if (!navigator.standalone && !editorUi.isOffline())
  3052. {
  3053. this.addMenuItems(menu, ['embedIframe'], parent);
  3054. }
  3055. if (urlParams['embed'] != '1' && !editorUi.isOffline())
  3056. {
  3057. this.addMenuItems(menu, ['-', 'googleDocs', 'googleSlides', 'googleSheets', '-', 'microsoftOffice', '-', 'embedNotion'], parent);
  3058. }
  3059. })));
  3060. editorUi.addInsertItem = function(menu, parent, title, method)
  3061. {
  3062. if (method != 'plantUml' || (EditorUi.enablePlantUml && !editorUi.isOffline()))
  3063. {
  3064. menu.addItem(title, null, mxUtils.bind(this, function()
  3065. {
  3066. if (method == 'fromText' || method == 'formatSql' ||
  3067. method == 'plantUml' || method == 'mermaid')
  3068. {
  3069. var dlg = new ParseDialog(editorUi, title, method);
  3070. editorUi.showDialog(dlg.container, 620, 420, true, false);
  3071. editorUi.dialog.container.style.overflow = 'auto';
  3072. dlg.init();
  3073. }
  3074. else
  3075. {
  3076. var dlg = new CreateGraphDialog(editorUi, title, method);
  3077. editorUi.showDialog(dlg.container, 620, 420, true, false, function(cancel, isEsc)
  3078. {
  3079. if (isEsc)
  3080. {
  3081. editorUi.confirm(mxResources.get('areYouSure'), function()
  3082. {
  3083. editorUi.hideDialog();
  3084. });
  3085. return false;
  3086. }
  3087. else if (dlg.graph != null)
  3088. {
  3089. if (dlg.graph.container.parentNode != null)
  3090. {
  3091. dlg.graph.container.parentNode.
  3092. removeChild(dlg.graph.container);
  3093. }
  3094. dlg.graph.destroy();
  3095. dlg.graph = null;
  3096. }
  3097. });
  3098. // Executed after dialog is added to dom
  3099. dlg.init();
  3100. }
  3101. }), parent, null, isGraphEnabled());
  3102. }
  3103. };
  3104. var insertCell = function(cell)
  3105. {
  3106. graph.getModel().beginUpdate();
  3107. try
  3108. {
  3109. cell = graph.addCell(cell);
  3110. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', [cell]));
  3111. if (graph.model.isVertex(cell) && graph.isAutoSizeCell(cell))
  3112. {
  3113. graph.updateCellSize(cell);
  3114. }
  3115. }
  3116. finally
  3117. {
  3118. graph.getModel().endUpdate();
  3119. }
  3120. graph.scrollCellToVisible(cell);
  3121. graph.setSelectionCell(cell);
  3122. graph.container.focus();
  3123. if (graph.editAfterInsert)
  3124. {
  3125. graph.startEditing(cell);
  3126. }
  3127. // Async call is workaroun for touch events resetting hover icons
  3128. window.setTimeout(function()
  3129. {
  3130. if (editorUi.hoverIcons != null)
  3131. {
  3132. editorUi.hoverIcons.update(graph.view.getState(cell));
  3133. }
  3134. }, 0);
  3135. return cell;
  3136. };
  3137. var insertVertex = function(value, w, h, style, pt)
  3138. {
  3139. var cell = new mxCell(value, new mxGeometry(0, 0, w, h), style);
  3140. cell.vertex = true;
  3141. if (pt == null)
  3142. {
  3143. pt = graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry([cell], true));
  3144. }
  3145. cell.geometry.x = pt.x;
  3146. cell.geometry.y = pt.y;
  3147. return insertCell(cell);
  3148. };
  3149. var insertEdge = function(value, length, style, pt)
  3150. {
  3151. if (pt == null)
  3152. {
  3153. pt = graph.getCenterInsertPoint(graph.getBoundingBoxFromGeometry([cell], true));
  3154. }
  3155. var cell = new mxCell('', new mxGeometry(0, 0, length, 0), style);
  3156. cell.geometry.setTerminalPoint(pt, true);
  3157. cell.geometry.setTerminalPoint(new mxPoint(pt.x + cell.geometry.width, pt.y), false);
  3158. cell.geometry.points = [];
  3159. cell.geometry.relative = true;
  3160. cell.edge = true;
  3161. return insertCell(cell);
  3162. };
  3163. editorUi.actions.put('insertText', new Action(mxResources.get('text'), function(evt)
  3164. {
  3165. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3166. {
  3167. graph.startEditingAtCell(insertVertex('Text', 60, 30, graph.appendFontSize(
  3168. 'text;strokeColor=none;align=center;fillColor=none;html=1;verticalAlign=middle;' +
  3169. 'whiteSpace=wrap;rounded=0;', graph.vertexFontSize), (evt != null &&
  3170. !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt) &&
  3171. graph.isMouseInsertPoint()) ? graph.getInsertPoint() : null));
  3172. }
  3173. }, null, null, 'A')).isEnabled = isGraphEnabled;
  3174. editorUi.actions.put('insertRectangle', new Action(mxResources.get('rectangle'), function(evt)
  3175. {
  3176. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3177. {
  3178. insertVertex('', 120, 60, 'whiteSpace=wrap;html=1;', (evt != null &&
  3179. !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt) &&
  3180. graph.isMouseInsertPoint()) ? graph.getInsertPoint() : null);
  3181. }
  3182. }, null, null, 'D')).isEnabled = isGraphEnabled;
  3183. editorUi.actions.put('insertNote', new Action(mxResources.get('note'), function(evt)
  3184. {
  3185. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3186. {
  3187. insertVertex('', 140, 160, 'shape=note;whiteSpace=wrap;html=1;backgroundOutline=1;' +
  3188. 'fontColor=#000000;darkOpacity=0.05;fillColor=#FFF9B2;strokeColor=none;fillStyle=solid;' +
  3189. 'direction=west;gradientDirection=north;gradientColor=#FFF2A1;shadow=1;size=20;pointerEvents=1;',
  3190. (evt != null && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt) &&
  3191. graph.isMouseInsertPoint()) ? graph.getInsertPoint() : null);
  3192. }
  3193. }, null, null, 'S')).isEnabled = isGraphEnabled;
  3194. editorUi.actions.put('insertEllipse', new Action(mxResources.get('ellipse'), function(evt)
  3195. {
  3196. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3197. {
  3198. insertVertex('', 80, 80, 'ellipse;whiteSpace=wrap;html=1;', (evt != null &&
  3199. !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt) &&
  3200. graph.isMouseInsertPoint()) ? graph.getInsertPoint() : null);
  3201. }
  3202. }, null, null, 'F')).isEnabled = isGraphEnabled;
  3203. editorUi.actions.put('insertRhombus', new Action(mxResources.get('rhombus'), function(evt)
  3204. {
  3205. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3206. {
  3207. insertVertex('', 80, 80, 'rhombus;whiteSpace=wrap;html=1;', (evt != null &&
  3208. !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt) &&
  3209. graph.isMouseInsertPoint()) ? graph.getInsertPoint() : null);
  3210. }
  3211. }, null, null, 'R')).isEnabled = isGraphEnabled;
  3212. editorUi.actions.put('insertEdge', new Action(mxResources.get('line'), function(evt)
  3213. {
  3214. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  3215. {
  3216. insertEdge('', graph.defaultEdgeLength, 'edgeStyle=none;orthogonalLoop=1;jettySize=auto;html=1;',
  3217. (evt != null && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt) &&
  3218. graph.isMouseInsertPoint()) ? graph.getInsertPoint() : null);
  3219. }
  3220. }, null, null, 'C')).isEnabled = isGraphEnabled;
  3221. var toggleShapes = editorUi.actions.put('toggleShapes', new Action(mxResources.get('shapes'), function()
  3222. {
  3223. if (editorUi.sidebarWindow != null)
  3224. {
  3225. editorUi.sidebarWindow.window.setVisible(
  3226. !editorUi.sidebarWindow.window.isVisible());
  3227. }
  3228. else
  3229. {
  3230. editorUi.toggleShapesPanel(!editorUi.isShapesPanelVisible());
  3231. }
  3232. }, null, null, Editor.ctrlKey + '+Shift+K'));
  3233. toggleShapes.setToggleAction(true);
  3234. toggleShapes.setSelectedCallback(mxUtils.bind(this, function()
  3235. {
  3236. return (editorUi.sidebarWindow != null && editorUi.sidebarWindow.window.isVisible()) ||
  3237. (editorUi.sidebarWindow == null && editorUi.hsplitPosition > 0);
  3238. }));
  3239. editorUi.addInsertMenuItems = mxUtils.bind(this, function(menu, parent, methods)
  3240. {
  3241. for (var i = 0; i < methods.length; i++)
  3242. {
  3243. if (methods[i] == '-')
  3244. {
  3245. menu.addSeparator(parent);
  3246. }
  3247. else
  3248. {
  3249. editorUi.addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  3250. }
  3251. }
  3252. });
  3253. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  3254. {
  3255. if (Editor.currentTheme == 'sketch')
  3256. {
  3257. editorUi.menus.addMenuItems(menu, ['toggleShapes'], parent);
  3258. editorUi.menus.addSubmenu('table', menu, parent);
  3259. menu.addSeparator(parent);
  3260. if (editorUi.insertTemplateEnabled && !editorUi.isOffline())
  3261. {
  3262. editorUi.menus.addMenuItems(menu, ['insertTemplate'], parent);
  3263. }
  3264. editorUi.menus.addMenuItems(menu, ['insertImage', 'insertLink', '-'], parent);
  3265. editorUi.menus.addSubmenu('insertAdvanced', menu, parent, mxResources.get('advanced'));
  3266. editorUi.menus.addSubmenu('layout', menu, parent);
  3267. }
  3268. else
  3269. {
  3270. this.addMenuItems(menu, ['insertRectangle', 'insertEllipse', 'insertRhombus',
  3271. '-', 'insertEdge', 'insertNote', '-', 'insertText', 'insertLink',
  3272. '-', 'createShape', 'insertFreehand', '-', 'insertImage'], parent);
  3273. if (editorUi.insertTemplateEnabled && !editorUi.isOffline())
  3274. {
  3275. this.addMenuItems(menu, ['insertTemplate'], parent);
  3276. }
  3277. menu.addSeparator(parent);
  3278. if (uiTheme == 'min' || Editor.currentTheme == 'simple')
  3279. {
  3280. this.addSubmenu('layout', menu, parent);
  3281. this.addSubmenu('insertLayout', menu, parent, mxResources.get('insert'));
  3282. menu.addSeparator(parent);
  3283. this.addSubmenu('table', menu, parent);
  3284. }
  3285. else
  3286. {
  3287. this.addSubmenu('insertLayout', menu, parent, mxResources.get('layout'));
  3288. }
  3289. this.addSubmenu('insertAdvanced', menu, parent, mxResources.get('advanced'));
  3290. }
  3291. })));
  3292. this.put('table', new Menu(mxUtils.bind(this, function(menu, parent)
  3293. {
  3294. editorUi.menus.addInsertTableCellItem(menu, parent);
  3295. })));
  3296. this.put('insertLayout', new Menu(mxUtils.bind(this, function(menu, parent)
  3297. {
  3298. editorUi.addInsertMenuItems(menu, parent, ['horizontalFlow',
  3299. 'verticalFlow', '-', 'horizontalTree', 'verticalTree',
  3300. 'radialTree', '-', 'organic', 'circle']);
  3301. })));
  3302. this.put('insertAdvanced', new Menu(mxUtils.bind(this, function(menu, parent)
  3303. {
  3304. var advancedItems = ['fromText', 'plantUml'].concat(window.isMermaidEnabled? ['mermaid'] : []).concat(['-', 'formatSql']);
  3305. editorUi.addInsertMenuItems(menu, parent, advancedItems);
  3306. menu.addItem(mxResources.get('csv') + '...', null, function()
  3307. {
  3308. graph.popupMenuHandler.hideMenu();
  3309. editorUi.showImportCsvDialog();
  3310. }, parent, null, isGraphEnabled());
  3311. if (Editor.currentTheme == 'simple' || Editor.currentTheme == 'min')
  3312. {
  3313. this.addMenuItems(menu, ['-', 'createShape', 'editDiagram'], parent);
  3314. }
  3315. })));
  3316. this.put('openRecent', new Menu(function(menu, parent)
  3317. {
  3318. var recent = editorUi.getRecent();
  3319. if (recent != null)
  3320. {
  3321. for (var i = 0; i < recent.length; i++)
  3322. {
  3323. (function(entry)
  3324. {
  3325. var modeKey = entry.mode;
  3326. // Google and oneDrive use different keys
  3327. if (modeKey == App.MODE_GOOGLE)
  3328. {
  3329. modeKey = 'googleDrive';
  3330. }
  3331. else if (modeKey == App.MODE_ONEDRIVE)
  3332. {
  3333. modeKey = 'oneDrive';
  3334. }
  3335. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  3336. {
  3337. editorUi.loadFile(entry.id);
  3338. }, parent);
  3339. })(recent[i]);
  3340. }
  3341. menu.addSeparator(parent);
  3342. }
  3343. menu.addItem(mxResources.get('reset'), null, function()
  3344. {
  3345. editorUi.resetRecent();
  3346. }, parent);
  3347. }));
  3348. this.put('openFrom', new Menu(function(menu, parent)
  3349. {
  3350. if (editorUi.drive != null)
  3351. {
  3352. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  3353. {
  3354. editorUi.pickFile(App.MODE_GOOGLE);
  3355. }, parent);
  3356. }
  3357. else if (editorUi.isModeEnabled(App.MODE_GOOGLE))
  3358. {
  3359. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  3360. {
  3361. // do nothing
  3362. }, parent, null, false);
  3363. }
  3364. if (editorUi.isModeReady(App.MODE_ONEDRIVE))
  3365. {
  3366. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  3367. {
  3368. editorUi.pickFile(App.MODE_ONEDRIVE);
  3369. }, parent);
  3370. }
  3371. else if (editorUi.isModeEnabled(App.MODE_ONEDRIVE))
  3372. {
  3373. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  3374. {
  3375. // do nothing
  3376. }, parent, null, false);
  3377. }
  3378. if (editorUi.isModeReady(App.MODE_DROPBOX))
  3379. {
  3380. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  3381. {
  3382. editorUi.pickFile(App.MODE_DROPBOX);
  3383. }, parent);
  3384. }
  3385. else if (editorUi.isModeEnabled(App.MODE_DROPBOX))
  3386. {
  3387. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  3388. {
  3389. // do nothing
  3390. }, parent, null, false);
  3391. }
  3392. menu.addSeparator(parent);
  3393. if (editorUi.isModeReady(App.MODE_GITHUB))
  3394. {
  3395. menu.addItem(mxResources.get('github') + '...', null, function()
  3396. {
  3397. editorUi.pickFile(App.MODE_GITHUB);
  3398. }, parent);
  3399. }
  3400. if (editorUi.isModeReady(App.MODE_GITLAB))
  3401. {
  3402. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  3403. {
  3404. editorUi.pickFile(App.MODE_GITLAB);
  3405. }, parent);
  3406. }
  3407. if (editorUi.isModeReady(App.MODE_TRELLO))
  3408. {
  3409. menu.addItem(mxResources.get('trello') + '...', null, function()
  3410. {
  3411. editorUi.pickFile(App.MODE_TRELLO);
  3412. }, parent);
  3413. }
  3414. else if (editorUi.isModeEnabled(App.MODE_TRELLO))
  3415. {
  3416. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  3417. {
  3418. // do nothing
  3419. }, parent, null, false);
  3420. }
  3421. menu.addSeparator(parent);
  3422. if (isLocalStorage && urlParams['browser'] != '0')
  3423. {
  3424. menu.addItem(mxResources.get('browser') + '...', null, function()
  3425. {
  3426. editorUi.pickFile(App.MODE_BROWSER);
  3427. }, parent);
  3428. }
  3429. //if (!mxClient.IS_IOS)
  3430. if (urlParams['noDevice'] != '1')
  3431. {
  3432. menu.addItem(mxResources.get('device') + '...', null, function()
  3433. {
  3434. editorUi.pickFile(App.MODE_DEVICE);
  3435. }, parent);
  3436. }
  3437. if (!editorUi.isOffline())
  3438. {
  3439. menu.addSeparator(parent);
  3440. menu.addItem(mxResources.get('url') + '...', null, function()
  3441. {
  3442. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  3443. {
  3444. if (fileUrl != null && fileUrl.length > 0)
  3445. {
  3446. if (editorUi.getCurrentFile() == null)
  3447. {
  3448. window.location.hash = '#U' + encodeURIComponent(fileUrl);
  3449. }
  3450. else
  3451. {
  3452. window.geOpenWindow(((mxClient.IS_CHROMEAPP) ?
  3453. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  3454. window.location.search + '#U' + encodeURIComponent(fileUrl));
  3455. }
  3456. }
  3457. }, mxResources.get('url'));
  3458. editorUi.showDialog(dlg.container, 300, 80, true, true);
  3459. dlg.init();
  3460. }, parent);
  3461. }
  3462. }));
  3463. if (Editor.enableCustomLibraries)
  3464. {
  3465. this.put('newLibrary', new Menu(function(menu, parent)
  3466. {
  3467. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  3468. {
  3469. if (editorUi.drive != null)
  3470. {
  3471. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  3472. {
  3473. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  3474. }, parent);
  3475. }
  3476. else if (editorUi.isModeEnabled(App.MODE_GOOGLE))
  3477. {
  3478. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  3479. {
  3480. // do nothing
  3481. }, parent, null, false);
  3482. }
  3483. }
  3484. if (editorUi.isModeReady(App.MODE_ONEDRIVE))
  3485. {
  3486. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  3487. {
  3488. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  3489. }, parent);
  3490. }
  3491. else if (editorUi.isModeEnabled(App.MODE_ONEDRIVE))
  3492. {
  3493. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  3494. {
  3495. // do nothing
  3496. }, parent, null, false);
  3497. }
  3498. if (editorUi.isModeReady(App.MODE_DROPBOX))
  3499. {
  3500. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  3501. {
  3502. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  3503. }, parent);
  3504. }
  3505. else if (editorUi.isModeEnabled(App.MODE_DROPBOX))
  3506. {
  3507. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  3508. {
  3509. // do nothing
  3510. }, parent, null, false);
  3511. }
  3512. menu.addSeparator(parent);
  3513. if (editorUi.isModeReady(App.MODE_GITHUB))
  3514. {
  3515. menu.addItem(mxResources.get('github') + '...', null, function()
  3516. {
  3517. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
  3518. }, parent);
  3519. }
  3520. if (editorUi.isModeReady(App.MODE_GITLAB))
  3521. {
  3522. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  3523. {
  3524. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITLAB);
  3525. }, parent);
  3526. }
  3527. if (editorUi.isModeReady(App.MODE_TRELLO))
  3528. {
  3529. menu.addItem(mxResources.get('trello') + '...', null, function()
  3530. {
  3531. editorUi.showLibraryDialog(null, null, null, null, App.MODE_TRELLO);
  3532. }, parent);
  3533. }
  3534. else if (editorUi.isModeEnabled(App.MODE_TRELLO))
  3535. {
  3536. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  3537. {
  3538. // do nothing
  3539. }, parent, null, false);
  3540. }
  3541. menu.addSeparator(parent);
  3542. if (isLocalStorage && urlParams['browser'] != '0')
  3543. {
  3544. menu.addItem(mxResources.get('browser') + '...', null, function()
  3545. {
  3546. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  3547. }, parent);
  3548. }
  3549. //if (!mxClient.IS_IOS)
  3550. if (urlParams['noDevice'] != '1')
  3551. {
  3552. menu.addItem(mxResources.get('device') + '...', null, function()
  3553. {
  3554. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  3555. }, parent);
  3556. }
  3557. }));
  3558. this.put('openLibraryFrom', new Menu(function(menu, parent)
  3559. {
  3560. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  3561. {
  3562. if (editorUi.drive != null)
  3563. {
  3564. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  3565. {
  3566. editorUi.pickLibrary(App.MODE_GOOGLE);
  3567. }, parent);
  3568. }
  3569. else if (editorUi.isModeEnabled(App.MODE_GOOGLE))
  3570. {
  3571. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  3572. {
  3573. // do nothing
  3574. }, parent, null, false);
  3575. }
  3576. }
  3577. if (editorUi.isModeReady(App.MODE_ONEDRIVE))
  3578. {
  3579. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  3580. {
  3581. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  3582. }, parent);
  3583. }
  3584. else if (editorUi.isModeEnabled(App.MODE_ONEDRIVE))
  3585. {
  3586. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  3587. {
  3588. // do nothing
  3589. }, parent, null, false);
  3590. }
  3591. if (editorUi.isModeReady(App.MODE_DROPBOX))
  3592. {
  3593. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  3594. {
  3595. editorUi.pickLibrary(App.MODE_DROPBOX);
  3596. }, parent);
  3597. }
  3598. else if (editorUi.isModeEnabled(App.MODE_DROPBOX))
  3599. {
  3600. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  3601. {
  3602. // do nothing
  3603. }, parent, null, false);
  3604. }
  3605. menu.addSeparator(parent);
  3606. if (editorUi.isModeReady(App.MODE_GITHUB))
  3607. {
  3608. menu.addItem(mxResources.get('github') + '...', null, function()
  3609. {
  3610. editorUi.pickLibrary(App.MODE_GITHUB);
  3611. }, parent);
  3612. }
  3613. if (editorUi.isModeReady(App.MODE_GITLAB))
  3614. {
  3615. menu.addItem(mxResources.get('gitlab') + '...', null, function()
  3616. {
  3617. editorUi.pickLibrary(App.MODE_GITLAB);
  3618. }, parent);
  3619. }
  3620. if (editorUi.isModeReady(App.MODE_TRELLO))
  3621. {
  3622. menu.addItem(mxResources.get('trello') + '...', null, function()
  3623. {
  3624. editorUi.pickLibrary(App.MODE_TRELLO);
  3625. }, parent);
  3626. }
  3627. else if (editorUi.isModeEnabled(App.MODE_TRELLO))
  3628. {
  3629. menu.addItem(mxResources.get('trello') + ' (' + mxResources.get('loading') + '...)', null, function()
  3630. {
  3631. // do nothing
  3632. }, parent, null, false);
  3633. }
  3634. menu.addSeparator(parent);
  3635. if (isLocalStorage && urlParams['browser'] != '0')
  3636. {
  3637. menu.addItem(mxResources.get('browser') + '...', null, function()
  3638. {
  3639. editorUi.pickLibrary(App.MODE_BROWSER);
  3640. }, parent);
  3641. }
  3642. //if (!mxClient.IS_IOS)
  3643. if (urlParams['noDevice'] != '1')
  3644. {
  3645. menu.addItem(mxResources.get('device') + '...', null, function()
  3646. {
  3647. editorUi.pickLibrary(App.MODE_DEVICE);
  3648. }, parent);
  3649. }
  3650. if (!editorUi.isOffline())
  3651. {
  3652. menu.addSeparator(parent);
  3653. menu.addItem(mxResources.get('url') + '...', null, function()
  3654. {
  3655. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  3656. {
  3657. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  3658. {
  3659. var realUrl = fileUrl;
  3660. if (!editorUi.editor.isCorsEnabledForUrl(fileUrl))
  3661. {
  3662. realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
  3663. }
  3664. // Uses proxy to avoid CORS issues
  3665. mxUtils.get(realUrl, function(req)
  3666. {
  3667. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  3668. {
  3669. editorUi.spinner.stop();
  3670. try
  3671. {
  3672. editorUi.loadLibrary(new UrlLibrary(
  3673. this, req.getText(), fileUrl));
  3674. editorUi.showSidebar();
  3675. }
  3676. catch (e)
  3677. {
  3678. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  3679. }
  3680. }
  3681. else
  3682. {
  3683. editorUi.spinner.stop();
  3684. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  3685. }
  3686. }, function()
  3687. {
  3688. editorUi.spinner.stop();
  3689. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  3690. });
  3691. }
  3692. }, mxResources.get('url'));
  3693. editorUi.showDialog(dlg.container, 300, 80, true, true);
  3694. dlg.init();
  3695. }, parent);
  3696. }
  3697. if (urlParams['confLib'] == '1')
  3698. {
  3699. menu.addSeparator(parent);
  3700. menu.addItem(mxResources.get('confluenceCloud') + '...', null, function()
  3701. {
  3702. editorUi.showRemotelyStoredLibrary(mxResources.get('libraries'));
  3703. }, parent);
  3704. }
  3705. }));
  3706. }
  3707. // Overrides edit menu to add find, copyAsImage editGeometry
  3708. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  3709. {
  3710. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'copyAsImage', 'paste',
  3711. 'delete', '-', 'duplicate', '-', 'findReplace', '-', 'editData', 'editTooltip', '-',
  3712. 'editStyle', 'editGeometry', '-', 'edit', '-', 'editLink', 'openLink', '-',
  3713. 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
  3714. })));
  3715. var action = editorUi.actions.addAction('comments', mxUtils.bind(this, function()
  3716. {
  3717. if (this.commentsWindow == null)
  3718. {
  3719. // LATER: Check outline window for initial placement
  3720. this.commentsWindow = new CommentsWindow(editorUi, document.body.offsetWidth - 380, 120, 300, 350);
  3721. //TODO Are these events needed?
  3722. this.commentsWindow.window.addListener('show', function()
  3723. {
  3724. editorUi.fireEvent(new mxEventObject('comments'));
  3725. });
  3726. this.commentsWindow.window.addListener('hide', function()
  3727. {
  3728. editorUi.fireEvent(new mxEventObject('comments'));
  3729. });
  3730. this.commentsWindow.window.setVisible(true);
  3731. editorUi.fireEvent(new mxEventObject('comments'));
  3732. }
  3733. else
  3734. {
  3735. var isVisible = !this.commentsWindow.window.isVisible();
  3736. this.commentsWindow.window.setVisible(isVisible);
  3737. this.commentsWindow.refreshCommentsTime();
  3738. if (isVisible && this.commentsWindow.hasError)
  3739. {
  3740. this.commentsWindow.refreshComments();
  3741. }
  3742. }
  3743. }));
  3744. action.setToggleAction(true);
  3745. action.setSelectedCallback(mxUtils.bind(this, function() { return this.commentsWindow != null && this.commentsWindow.window.isVisible(); }));
  3746. // Destroys comments window to force update or disable if not supported
  3747. editorUi.editor.addListener('fileLoaded', mxUtils.bind(this, function()
  3748. {
  3749. if (this.commentsWindow != null)
  3750. {
  3751. this.commentsWindow.destroy();
  3752. this.commentsWindow = null;
  3753. }
  3754. }));
  3755. // Extends toolbar dropdown
  3756. var viewPanelsMenu = this.get('viewPanels');
  3757. viewPanelsMenu.funct = function(menu, parent)
  3758. {
  3759. var file = editorUi.getCurrentFile();
  3760. editorUi.menus.addMenuItems(menu, ['toggleShapes', 'format', 'ruler', '-',
  3761. 'findReplace', 'layers', 'tags', 'chatWindowTitle', 'outline', '-'], parent);
  3762. if (editorUi.commentsSupported())
  3763. {
  3764. editorUi.menus.addMenuItems(menu, ['comments'], parent);
  3765. }
  3766. if (file != null && file.isRealtimeEnabled() && file.isRealtimeSupported())
  3767. {
  3768. editorUi.menus.addMenuItems(menu, ['showRemoteCursors'], parent);
  3769. }
  3770. editorUi.menus.addMenuItems(menu, ['-', 'fullscreen'], parent);
  3771. };
  3772. // Overrides view menu to add search and scratchpad
  3773. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  3774. {
  3775. if (Editor.currentTheme == 'simple')
  3776. {
  3777. var file = editorUi.getCurrentFile();
  3778. editorUi.menus.addMenuItems(menu, ['toggleShapes', 'format'], parent);
  3779. if (editorUi.isPageMenuVisible())
  3780. {
  3781. editorUi.menus.addMenuItems(menu, ['pageTabs'], parent);
  3782. }
  3783. editorUi.menus.addMenuItems(menu, ['ruler', '-', 'search'], parent);
  3784. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3785. {
  3786. var item = editorUi.menus.addMenuItem(menu, 'scratchpad', parent);
  3787. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  3788. {
  3789. editorUi.menus.addLinkToItem(item, 'https://www.drawio.com/doc/faq/scratchpad');
  3790. }
  3791. }
  3792. editorUi.menus.addMenuItems(menu, ['-', 'findReplace',
  3793. 'layers', 'tags', 'chatWindowTitle', 'outline', '-'], parent);
  3794. if (editorUi.commentsSupported())
  3795. {
  3796. editorUi.menus.addMenuItems(menu, ['comments'], parent);
  3797. }
  3798. if (file != null && file.isRealtimeEnabled() && file.isRealtimeSupported())
  3799. {
  3800. this.addMenuItems(menu, ['showRemoteCursors'], parent);
  3801. }
  3802. this.addMenuItems(menu, ['-', 'fullscreen'], parent);
  3803. }
  3804. else
  3805. {
  3806. this.addMenuItems(menu, (['format', 'outline', 'layers', 'tags', 'chatWindowTitle']).
  3807. concat((editorUi.commentsSupported()) ?
  3808. ['comments', '-'] : ['-']));
  3809. this.addMenuItems(menu, ['-', 'search'], parent);
  3810. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  3811. {
  3812. var item = this.addMenuItem(menu, 'scratchpad', parent);
  3813. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  3814. {
  3815. this.addLinkToItem(item, 'https://www.drawio.com/doc/faq/scratchpad');
  3816. }
  3817. }
  3818. this.addMenuItems(menu, ['toggleShapes', '-', 'pageView', 'pageScale']);
  3819. this.addSubmenu('units', menu, parent);
  3820. menu.addSeparator(parent);
  3821. if (editorUi.isPageMenuVisible())
  3822. {
  3823. editorUi.menus.addMenuItems(menu, ['pageTabs'], parent);
  3824. }
  3825. this.addMenuItems(menu, ['ruler', '-', 'tooltips', 'animations',
  3826. '-', 'grid', 'guides', '-', 'connectionArrows', 'connectionPoints', '-',
  3827. 'resetView', 'zoomIn', 'zoomOut'], parent);
  3828. if (urlParams['sketch'] != '1')
  3829. {
  3830. this.addMenuItems(menu, ['-', 'fullscreen'], parent);
  3831. }
  3832. }
  3833. })));
  3834. // Edit cell menu
  3835. this.put('editCell', new Menu(mxUtils.bind(this, function(menu, parent)
  3836. {
  3837. // Last entry edits cell label
  3838. this.addMenuItems(menu, ['editLink', 'editShape', 'editImage', 'crop', '-',
  3839. 'editData', 'copyData', 'pasteData', '-', 'editConnectionPoints',
  3840. 'editGeometry', '-', 'editTooltip', 'editStyle', '-', 'edit'], parent);
  3841. })));
  3842. // Current page menu
  3843. this.put('currentPage', new Menu(mxUtils.bind(this, function(menu, parent)
  3844. {
  3845. var page = editorUi.currentPage;
  3846. if (page != null)
  3847. {
  3848. menu.addItem(mxResources.get('rename') + '...', null, mxUtils.bind(this, function()
  3849. {
  3850. editorUi.renamePage(page, page.getName());
  3851. }), parent);
  3852. menu.addItem(mxResources.get('delete'), null, mxUtils.bind(this, function()
  3853. {
  3854. editorUi.removePage(page);
  3855. }), parent);
  3856. if (editorUi.pages.length > 1)
  3857. {
  3858. editorUi.menus.addSubmenu('movePage', menu, parent, mxResources.get('move'));
  3859. menu.addSeparator(parent);
  3860. }
  3861. menu.addSeparator(parent);
  3862. menu.addItem(mxResources.get('duplicate'), null, mxUtils.bind(this, function()
  3863. {
  3864. editorUi.duplicatePage(page, mxResources.get('copyOf', [page.getName()]));
  3865. }), parent);
  3866. if (urlParams['embed'] != 1)
  3867. {
  3868. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp && editorUi.getServiceName() == 'draw.io')
  3869. {
  3870. menu.addItem(mxResources.get('openInNewWindow'), null, mxUtils.bind(this, function()
  3871. {
  3872. editorUi.editor.editAsNew(editorUi.getFileData(true, null, null, null, true, true));
  3873. }), parent);
  3874. }
  3875. }
  3876. }
  3877. })));
  3878. // Pages menu
  3879. this.put('pages', new Menu(mxUtils.bind(this, function(menu, parent)
  3880. {
  3881. var page = editorUi.currentPage;
  3882. if (!editorUi.editor.graph.isLightboxView())
  3883. {
  3884. menu.addItem(mxResources.get('insertPage'), null, mxUtils.bind(this, function()
  3885. {
  3886. try
  3887. {
  3888. editorUi.insertPage();
  3889. }
  3890. catch (e)
  3891. {
  3892. editorUi.handleError(e);
  3893. }
  3894. }), parent, null, editorUi.editor.graph.isEnabled());
  3895. menu.addSeparator(parent);
  3896. }
  3897. if (editorUi.pages != null)
  3898. {
  3899. for (var i = 0; i < editorUi.pages.length; i++)
  3900. {
  3901. (mxUtils.bind(this, function(index)
  3902. {
  3903. var item = null;
  3904. if (editorUi.pages[index] == page && !editorUi.editor.graph.isLightboxView())
  3905. {
  3906. item = editorUi.menus.addSubmenu('currentPage', menu, parent,
  3907. editorUi.getShortPageName(page));
  3908. }
  3909. else
  3910. {
  3911. item = menu.addItem(editorUi.getShortPageName(editorUi.pages[index]),
  3912. null, mxUtils.bind(this, function()
  3913. {
  3914. editorUi.selectPage(editorUi.pages[index]);
  3915. }), parent);
  3916. }
  3917. var id = editorUi.pages[index].getId();
  3918. item.setAttribute('title', editorUi.pages[index].getName() +
  3919. ' (' + (index + 1) + '/' + editorUi.pages.length + ')' +
  3920. ((id != null) ? ' [' + id + ']' : ''));
  3921. // Adds checkmark to current page
  3922. if (editorUi.pages[index] == page)
  3923. {
  3924. menu.addCheckmark(item, Editor.checkmarkImage);
  3925. }
  3926. }))(i);
  3927. }
  3928. }
  3929. })));
  3930. if (EditorUi.isElectronApp)
  3931. {
  3932. var enableSpellCheck = urlParams['enableSpellCheck'] == '1';
  3933. var spellCheckAction = editorUi.actions.addAction('spellCheck', function()
  3934. {
  3935. editorUi.toggleSpellCheck();
  3936. enableSpellCheck = !enableSpellCheck;
  3937. editorUi.alert(mxResources.get('restartForChangeRequired'));
  3938. });
  3939. spellCheckAction.setToggleAction(true);
  3940. spellCheckAction.setSelectedCallback(function() { return enableSpellCheck; });
  3941. var enableStoreBkp = urlParams['enableStoreBkp'] == '1';
  3942. var storeBkpAction = editorUi.actions.addAction('autoBkp', function()
  3943. {
  3944. editorUi.toggleStoreBkp();
  3945. enableStoreBkp = !enableStoreBkp;
  3946. });
  3947. storeBkpAction.setToggleAction(true);
  3948. storeBkpAction.setSelectedCallback(function() { return enableStoreBkp; });
  3949. var enableGoogleFonts = urlParams['isGoogleFontsEnabled'] == '1';
  3950. var googleFontsAction = editorUi.actions.addAction('googleFonts', function()
  3951. {
  3952. editorUi.toggleGoogleFonts();
  3953. enableGoogleFonts = !enableGoogleFonts;
  3954. editorUi.alert(mxResources.get('restartForChangeRequired'));
  3955. });
  3956. googleFontsAction.setToggleAction(true);
  3957. googleFontsAction.setSelectedCallback(function() { return enableGoogleFonts; });
  3958. editorUi.actions.addAction('openDevTools', function()
  3959. {
  3960. editorUi.openDevTools();
  3961. });
  3962. editorUi.actions.addAction('drafts...', function()
  3963. {
  3964. var dlg = new FilenameDialog(editorUi, (EditorUi.draftSaveDelay / 1000) + '',
  3965. mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  3966. {
  3967. var val = parseInt(newValue);
  3968. if (val >= 0)
  3969. {
  3970. EditorUi.draftSaveDelay = val * 1000;
  3971. EditorUi.enableDrafts = val > 0; //Disable if zero
  3972. mxSettings.setDraftSaveDelay(val);
  3973. mxSettings.save();
  3974. }
  3975. }), mxResources.get('draftSaveInt'));
  3976. editorUi.showDialog(dlg.container, 320, 80, true, true);
  3977. dlg.init();
  3978. });
  3979. }
  3980. var langMenu = this.get('language');
  3981. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  3982. {
  3983. // Compatiblity code for live UI switch and static UI
  3984. if (Editor.currentTheme == 'simple' ||
  3985. Editor.currentTheme == 'sketch' ||
  3986. Editor.currentTheme == 'min')
  3987. {
  3988. if ((urlParams['embed'] != '1' || urlParams['atlas'] == '1') &&
  3989. urlParams['extAuth'] != '1' && editorUi.mode != App.MODE_ATLAS &&
  3990. urlParams['embedInline'] != '1' && (Editor.isDarkMode() ||
  3991. (!mxClient.IS_IE && !mxClient.IS_IE11)))
  3992. {
  3993. editorUi.menus.addSubmenu('appearance', menu, parent);
  3994. }
  3995. if (urlParams['embed'] != '1' && urlParams['extAuth'] != '1' &&
  3996. editorUi.mode != App.MODE_ATLAS)
  3997. {
  3998. editorUi.menus.addSubmenu('theme', menu, parent);
  3999. }
  4000. menu.addSeparator(parent);
  4001. if (langMenu != null && (urlParams['embed'] != '1' || urlParams['lang'] == null))
  4002. {
  4003. editorUi.menus.addSubmenu('language', menu, parent);
  4004. }
  4005. editorUi.menus.addSubmenu('units', menu, parent);
  4006. editorUi.menus.addMenuItems(menu, ['-', 'copyConnect',
  4007. 'collapseExpand', '-', 'tooltips', 'animations', '-'], parent);
  4008. var file = editorUi.getCurrentFile();
  4009. if (Editor.currentTheme != 'simple')
  4010. {
  4011. if (file != null && file.isRealtimeEnabled() && file.isRealtimeSupported())
  4012. {
  4013. this.addMenuItems(menu, ['showRemoteCursors'], parent);
  4014. }
  4015. editorUi.menus.addMenuItems(menu, ['ruler', '-'], parent);
  4016. }
  4017. if (EditorUi.isElectronApp)
  4018. {
  4019. editorUi.menus.addMenuItems(menu, ['-', 'googleFonts', 'spellCheck', 'autoBkp', 'drafts', '-'], parent);
  4020. }
  4021. this.addSubmenu('diagramLanguage', menu, parent);
  4022. menu.addSeparator(parent);
  4023. if (editorUi.mode != App.MODE_ATLAS)
  4024. {
  4025. editorUi.menus.addMenuItem(menu, 'configuration', parent);
  4026. }
  4027. // Adds trailing separator in case new plugin entries are added
  4028. menu.addSeparator(parent);
  4029. }
  4030. else
  4031. {
  4032. if (urlParams['embed'] != '1' || urlParams['lang'] == null)
  4033. {
  4034. this.addSubmenu('language', menu, parent);
  4035. }
  4036. if ((urlParams['embed'] != '1' || urlParams['atlas'] == '1') &&
  4037. Editor.currentTheme != 'atlas' && (Editor.isDarkMode() ||
  4038. (!mxClient.IS_IE && !mxClient.IS_IE11)))
  4039. {
  4040. editorUi.menus.addSubmenu('appearance', menu, parent);
  4041. }
  4042. if (urlParams['embed'] != '1' && urlParams['extAuth'] != '1' &&
  4043. editorUi.mode != App.MODE_ATLAS)
  4044. {
  4045. this.addSubmenu('theme', menu, parent);
  4046. }
  4047. menu.addSeparator(parent);
  4048. if (typeof(MathJax) !== 'undefined')
  4049. {
  4050. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  4051. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  4052. {
  4053. this.addLinkToItem(item, 'https://www.drawio.com/doc/faq/math-typesetting');
  4054. }
  4055. }
  4056. if (EditorUi.isElectronApp)
  4057. {
  4058. this.addMenuItems(menu, ['googleFonts', 'spellCheck', 'autoBkp', 'drafts', '-'], parent);
  4059. }
  4060. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  4061. if (urlParams['embed'] != '1')
  4062. {
  4063. var file = editorUi.getCurrentFile();
  4064. if (file != null && file.isRealtimeEnabled() && file.isRealtimeSupported())
  4065. {
  4066. this.addMenuItems(menu, ['showRemoteCursors', 'shareCursor'], parent);
  4067. }
  4068. this.addMenuItems(menu, ['autosave'], parent);
  4069. }
  4070. menu.addSeparator(parent);
  4071. if (!editorUi.isOfflineApp() && isLocalStorage)
  4072. {
  4073. this.addMenuItem(menu, 'plugins', parent);
  4074. }
  4075. this.addMenuItems(menu, ['-', 'editDiagram'], parent);
  4076. this.addSubmenu('diagramLanguage', menu, parent);
  4077. menu.addSeparator(parent);
  4078. if (urlParams['embed'] != '1' && (isLocalStorage || mxClient.IS_CHROMEAPP))
  4079. {
  4080. this.addMenuItems(menu, ['showStartScreen'], parent);
  4081. }
  4082. this.addMenuItems(menu, ['configuration'], parent);
  4083. }
  4084. })));
  4085. this.put('movePage', new Menu(mxUtils.bind(this, function(menu, parent)
  4086. {
  4087. var currentPage = editorUi.currentPage;
  4088. var current = editorUi.getPageIndex(currentPage);
  4089. if (editorUi.pages != null)
  4090. {
  4091. for (var i = 0; i < editorUi.pages.length; i++)
  4092. {
  4093. if (i != current)
  4094. {
  4095. (function(index)
  4096. {
  4097. menu.addItem(editorUi.getShortPageName(editorUi.pages[index]), null, function()
  4098. {
  4099. editorUi.movePage(current, index);
  4100. editorUi.scrollToPage(currentPage, true);
  4101. }, parent);
  4102. })(i);
  4103. }
  4104. }
  4105. }
  4106. })));
  4107. this.put('share', new Menu(mxUtils.bind(this, function(menu, parent)
  4108. {
  4109. if (!editorUi.isStandaloneApp())
  4110. {
  4111. var err = (editorUi.isOffline(true)) ?
  4112. mxResources.get('offline') :
  4113. editorUi.getNetworkStatus();
  4114. if (err != null)
  4115. {
  4116. menu.addItem(err, null, null, parent, null, false);
  4117. menu.addSeparator(parent);
  4118. }
  4119. editorUi.menus.addMenuItems(menu, ['share'], parent);
  4120. }
  4121. this.addMenuItem(menu, 'publishLink', parent, null,
  4122. null, mxResources.get('publish') + '...');
  4123. if (editorUi.getMainUser() != null)
  4124. {
  4125. this.addMenuItems(menu, ['accounts'], parent);
  4126. }
  4127. })));
  4128. this.put('diagram', new Menu(mxUtils.bind(this, function(menu, parent)
  4129. {
  4130. var file = editorUi.getCurrentFile();
  4131. if (Editor.currentTheme != 'simple')
  4132. {
  4133. editorUi.menus.addSubmenu('extras', menu, parent, mxResources.get('settings'));
  4134. menu.addSeparator(parent);
  4135. }
  4136. // Compatiblity code for live UI switch and static UI
  4137. var sketchTheme = Editor.currentTheme == 'simple' ||
  4138. Editor.currentTheme == 'sketch';
  4139. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  4140. {
  4141. editorUi.menus.addMenuItems(menu, ['new', 'open', '-',
  4142. 'synchronize', 'properties', '-',
  4143. 'save', 'saveAs', '-'], parent);
  4144. }
  4145. else if (editorUi.mode == App.MODE_ATLAS)
  4146. {
  4147. if (urlParams['noSaveBtn'] != '1' &&
  4148. urlParams['embedInline'] != '1')
  4149. {
  4150. editorUi.menus.addMenuItems(menu, ['-', 'save'], parent);
  4151. }
  4152. if (urlParams['saveAndExit'] == '1' ||
  4153. (urlParams['noSaveBtn'] == '1' &&
  4154. urlParams['saveAndExit'] != '0') || editorUi.mode == App.MODE_ATLAS)
  4155. {
  4156. editorUi.menus.addMenuItems(menu, ['saveAndExit'], parent);
  4157. if (file != null && file.isRevisionHistorySupported())
  4158. {
  4159. editorUi.menus.addMenuItems(menu, ['revisionHistory'], parent);
  4160. }
  4161. }
  4162. menu.addSeparator(parent);
  4163. }
  4164. else if (editorUi.mode == App.MODE_ATLAS)
  4165. {
  4166. editorUi.menus.addMenuItems(menu, ['save', 'synchronize', '-'], parent);
  4167. }
  4168. else if (urlParams['noFileMenu'] != '1')
  4169. {
  4170. editorUi.menus.addSubmenu('file', menu, parent);
  4171. menu.addSeparator(parent);
  4172. if (Editor.currentTheme == 'min')
  4173. {
  4174. editorUi.menus.addMenuItems(menu, ['toggleShapes', 'format',
  4175. 'layers', 'tags', 'chatWindowTitle', '-',
  4176. 'findReplace'], parent);
  4177. if (editorUi.commentsSupported())
  4178. {
  4179. editorUi.menus.addMenuItems(menu, ['comments'], parent);
  4180. }
  4181. menu.addSeparator(parent);
  4182. }
  4183. }
  4184. editorUi.menus.addSubmenu('exportAs', menu, parent);
  4185. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp || editorUi.getServiceName() == 'atlassian')
  4186. {
  4187. editorUi.menus.addMenuItems(menu, ['import'], parent);
  4188. }
  4189. else if (urlParams['noFileMenu'] != '1')
  4190. {
  4191. editorUi.menus.addSubmenu('importFrom', menu, parent);
  4192. }
  4193. if (Editor.currentTheme != 'simple' && Editor.currentTheme != 'min')
  4194. {
  4195. editorUi.menus.addMenuItems(menu, ['-', 'findReplace'], parent);
  4196. if (editorUi.commentsSupported())
  4197. {
  4198. editorUi.menus.addMenuItems(menu, ['comments', '-'], parent);
  4199. }
  4200. editorUi.menus.addMenuItems(menu, ['toggleShapes', 'format',
  4201. 'layers', 'tags', 'chatWindowTitle', '-'], parent);
  4202. editorUi.menus.addMenuItems(menu, ['pageSetup'], parent);
  4203. }
  4204. else if (Editor.currentTheme != 'min')
  4205. {
  4206. this.addMenuItems(menu, ['-'], parent);
  4207. this.addSubmenu('newLibrary', menu, parent);
  4208. this.addSubmenu('openLibraryFrom', menu, parent);
  4209. }
  4210. menu.addSeparator(parent);
  4211. // Cannot use print in standalone mode on iOS as we cannot open new windows
  4212. if (urlParams['noFileMenu'] != '1' && (!mxClient.IS_IOS || !navigator.standalone))
  4213. {
  4214. editorUi.menus.addMenuItems(menu, ['print'], parent);
  4215. }
  4216. if (!sketchTheme && Editor.currentTheme != 'min')
  4217. {
  4218. if (file != null && editorUi.fileNode != null && urlParams['embedInline'] != '1')
  4219. {
  4220. var filename = (file.getTitle() != null) ?
  4221. file.getTitle() : editorUi.defaultFilename;
  4222. if (!/(\.html)$/i.test(filename))
  4223. {
  4224. this.addMenuItems(menu, ['-', 'properties']);
  4225. }
  4226. }
  4227. }
  4228. menu.addSeparator(parent);
  4229. if (Editor.currentTheme == 'simple')
  4230. {
  4231. editorUi.menus.addSubmenu('extras', menu, parent, mxResources.get('settings'));
  4232. menu.addSeparator(parent);
  4233. }
  4234. editorUi.menus.addSubmenu('help', menu, parent);
  4235. menu.addSeparator(parent);
  4236. if (urlParams['embed'] == '1')
  4237. {
  4238. if (urlParams['noSaveBtn'] != '1' &&
  4239. urlParams['embedInline'] != '1')
  4240. {
  4241. editorUi.menus.addMenuItems(menu, ['save'], parent);
  4242. }
  4243. if (urlParams['saveAndExit'] == '1' ||
  4244. (urlParams['noSaveBtn'] == '1' &&
  4245. urlParams['saveAndExit'] != '0'))
  4246. {
  4247. editorUi.menus.addMenuItems(menu, ['saveAndExit'], parent);
  4248. if (file != null && file.isRevisionHistorySupported())
  4249. {
  4250. editorUi.menus.addMenuItems(menu, ['revisionHistory'], parent);
  4251. }
  4252. }
  4253. }
  4254. if (urlParams['embed'] == '1' || editorUi.mode == App.MODE_ATLAS)
  4255. {
  4256. if (urlParams['noExitBtn'] != '1' || editorUi.mode == App.MODE_ATLAS)
  4257. {
  4258. editorUi.menus.addMenuItems(menu, ['exit'], parent);
  4259. }
  4260. }
  4261. if (urlParams['embed'] != '1' && file != null)
  4262. {
  4263. editorUi.menus.addMenuItems(menu, ['-', 'close'], parent);
  4264. }
  4265. })));
  4266. this.put('save', new Menu(mxUtils.bind(this, function(menu, parent)
  4267. {
  4268. var file = editorUi.getCurrentFile();
  4269. if (file != null && (file.constructor == DriveFile || file.constructor == OneDriveFile))
  4270. {
  4271. editorUi.menus.addMenuItems(menu, ['save', 'makeCopy', '-', 'rename', 'moveToFolder'], parent);
  4272. }
  4273. else
  4274. {
  4275. editorUi.menus.addMenuItems(menu, ['save', 'saveAs', '-', 'rename'], parent);
  4276. if (editorUi.isOfflineApp())
  4277. {
  4278. if (navigator.onLine && urlParams['stealth'] != '1' && urlParams['lockdown'] != '1')
  4279. {
  4280. this.addMenuItems(menu, ['upload'], parent);
  4281. }
  4282. }
  4283. else
  4284. {
  4285. editorUi.menus.addMenuItems(menu, ['makeCopy'], parent);
  4286. }
  4287. }
  4288. editorUi.menus.addMenuItems(menu, ['-', 'autosave'], parent);
  4289. if (file != null && file.isRevisionHistorySupported())
  4290. {
  4291. editorUi.menus.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  4292. }
  4293. })));
  4294. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  4295. {
  4296. // Compatiblity code for live UI switch and static UI
  4297. var minTheme = Editor.currentTheme == 'simple' ||
  4298. Editor.currentTheme == 'sketch' ||
  4299. Editor.currentTheme == 'min';
  4300. if (urlParams['embed'] == '1')
  4301. {
  4302. this.addSubmenu('importFrom', menu, parent);
  4303. this.addSubmenu('exportAs', menu, parent);
  4304. this.addSubmenu('embed', menu, parent);
  4305. if (urlParams['libraries'] == '1')
  4306. {
  4307. this.addMenuItems(menu, ['-'], parent);
  4308. this.addSubmenu('newLibrary', menu, parent);
  4309. this.addSubmenu('openLibraryFrom', menu, parent);
  4310. }
  4311. if (editorUi.isRevisionHistorySupported())
  4312. {
  4313. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  4314. }
  4315. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'rename'], parent);
  4316. if (urlParams['embedInline'] != '1')
  4317. {
  4318. if (urlParams['noSaveBtn'] == '1')
  4319. {
  4320. if (urlParams['saveAndExit'] != '0')
  4321. {
  4322. this.addMenuItems(menu, ['saveAndExit'], parent);
  4323. }
  4324. }
  4325. else
  4326. {
  4327. this.addMenuItems(menu, ['save'], parent);
  4328. if (urlParams['saveAndExit'] == '1')
  4329. {
  4330. this.addMenuItems(menu, ['saveAndExit'], parent);
  4331. }
  4332. }
  4333. }
  4334. if (urlParams['noExitBtn'] != '1')
  4335. {
  4336. this.addMenuItems(menu, ['exit'], parent);
  4337. }
  4338. }
  4339. else if (minTheme)
  4340. {
  4341. var file = editorUi.getCurrentFile();
  4342. editorUi.menus.addMenuItems(menu, ['new'], parent);
  4343. editorUi.menus.addSubmenu('openFrom', menu, parent);
  4344. if (isLocalStorage)
  4345. {
  4346. this.addSubmenu('openRecent', menu, parent);
  4347. }
  4348. menu.addSeparator(parent);
  4349. editorUi.menus.addMenuItems(menu, ['-', 'save'], parent);
  4350. if (file == null || file.constructor != DriveFile)
  4351. {
  4352. editorUi.menus.addMenuItems(menu, ['saveAs'], parent);
  4353. }
  4354. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  4355. file != null && (file.constructor != LocalFile ||
  4356. file.fileHandle != null))
  4357. {
  4358. editorUi.menus.addMenuItems(menu, ['synchronize'], parent);
  4359. }
  4360. menu.addSeparator(parent);
  4361. if (file != null)
  4362. {
  4363. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  4364. Editor.currentTheme == 'sketch')
  4365. {
  4366. this.addMenuItem(menu, 'publishLink', parent, null, null, mxResources.get('publish') + '...');
  4367. }
  4368. if (Editor.currentTheme != 'simple' &&
  4369. (file.constructor == DriveFile ||
  4370. file.constructor == GitHubFile ||
  4371. file.constructor == OneDriveFile))
  4372. {
  4373. editorUi.menus.addMenuItems(menu, ['share'], parent);
  4374. }
  4375. }
  4376. menu.addSeparator(parent);
  4377. if (file != null && file.isRenamable())
  4378. {
  4379. this.addMenuItems(menu, ['rename'], parent);
  4380. }
  4381. if (editorUi.isOfflineApp())
  4382. {
  4383. if (navigator.onLine && urlParams['stealth'] != '1' && urlParams['lockdown'] != '1')
  4384. {
  4385. this.addMenuItems(menu, ['upload'], parent);
  4386. }
  4387. }
  4388. else
  4389. {
  4390. editorUi.menus.addMenuItems(menu, ['makeCopy'], parent);
  4391. if (file != null)
  4392. {
  4393. if (file.constructor == OneDriveFile ||
  4394. file.constructor == DriveFile)
  4395. {
  4396. editorUi.menus.addMenuItems(menu, ['moveToFolder'], parent);
  4397. }
  4398. menu.addSeparator(parent);
  4399. if (file.getFolderUrl() != null)
  4400. {
  4401. editorUi.menus.addMenuItems(menu, ['openFolder'], parent);
  4402. }
  4403. if (file.getFileUrl() != null)
  4404. {
  4405. editorUi.menus.addMenuItems(menu, ['openFile'], parent);
  4406. }
  4407. }
  4408. }
  4409. menu.addSeparator(parent);
  4410. if (file != null && file.isRevisionHistorySupported())
  4411. {
  4412. editorUi.menus.addMenuItems(menu, ['revisionHistory'], parent);
  4413. }
  4414. if (file != null && editorUi.fileNode != null && urlParams['embedInline'] != '1')
  4415. {
  4416. var filename = (file.getTitle() != null) ?
  4417. file.getTitle() : editorUi.defaultFilename;
  4418. if ((file.constructor == DriveFile && file.sync != null &&
  4419. file.sync.isConnected()) || !/(\.html)$/i.test(filename))
  4420. {
  4421. this.addMenuItems(menu, ['properties'], parent);
  4422. }
  4423. }
  4424. if (Editor.currentTheme == 'simple')
  4425. {
  4426. editorUi.menus.addMenuItems(menu, ['-', 'autosave'], parent);
  4427. }
  4428. }
  4429. else
  4430. {
  4431. var file = this.editorUi.getCurrentFile();
  4432. if (file != null && file.constructor == DriveFile)
  4433. {
  4434. if (file.isRestricted())
  4435. {
  4436. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  4437. }
  4438. this.addMenuItems(menu, ['save', '-', 'share'], parent);
  4439. var item = this.addMenuItem(menu, 'synchronize', parent);
  4440. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  4441. {
  4442. this.addLinkToItem(item, 'https://www.drawio.com/doc/faq/synchronize');
  4443. }
  4444. menu.addSeparator(parent);
  4445. }
  4446. else
  4447. {
  4448. this.addMenuItems(menu, ['new'], parent);
  4449. }
  4450. this.addSubmenu('openFrom', menu, parent);
  4451. if (isLocalStorage)
  4452. {
  4453. this.addSubmenu('openRecent', menu, parent);
  4454. }
  4455. if (file != null && file.constructor == DriveFile)
  4456. {
  4457. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy',
  4458. 'openFolder', 'moveToFolder'], parent);
  4459. }
  4460. else
  4461. {
  4462. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  4463. file != null && (file.constructor != LocalFile ||
  4464. file.fileHandle != null))
  4465. {
  4466. menu.addSeparator(parent);
  4467. var item = this.addMenuItem(menu, 'synchronize', parent);
  4468. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  4469. {
  4470. this.addLinkToItem(item, 'https://www.drawio.com/doc/faq/synchronize');
  4471. }
  4472. }
  4473. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-'], parent);
  4474. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  4475. editorUi.getServiceName() == 'draw.io' &&
  4476. !editorUi.isOfflineApp() && file != null)
  4477. {
  4478. this.addMenuItems(menu, ['share', '-'], parent);
  4479. }
  4480. if (file != null && file.isRenamable())
  4481. {
  4482. this.addMenuItems(menu, ['rename'], parent);
  4483. }
  4484. if (editorUi.isOfflineApp())
  4485. {
  4486. if (navigator.onLine && urlParams['stealth'] != '1' && urlParams['lockdown'] != '1')
  4487. {
  4488. this.addMenuItems(menu, ['upload'], parent);
  4489. }
  4490. }
  4491. else
  4492. {
  4493. this.addMenuItems(menu, ['makeCopy'], parent);
  4494. if (file != null)
  4495. {
  4496. if (file.constructor == OneDriveFile)
  4497. {
  4498. this.addMenuItems(menu, ['moveToFolder'], parent);
  4499. }
  4500. if (file.getFolderUrl() != null)
  4501. {
  4502. editorUi.menus.addMenuItems(menu, ['openFolder'], parent);
  4503. }
  4504. }
  4505. }
  4506. }
  4507. menu.addSeparator(parent);
  4508. this.addSubmenu('importFrom', menu, parent);
  4509. this.addSubmenu('exportAs', menu, parent);
  4510. menu.addSeparator(parent);
  4511. this.addSubmenu('embed', menu, parent);
  4512. this.addSubmenu('publish', menu, parent);
  4513. menu.addSeparator(parent);
  4514. this.addSubmenu('newLibrary', menu, parent);
  4515. this.addSubmenu('openLibraryFrom', menu, parent);
  4516. if (editorUi.isRevisionHistorySupported())
  4517. {
  4518. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  4519. }
  4520. if (file != null && editorUi.fileNode != null && urlParams['embedInline'] != '1')
  4521. {
  4522. var filename = (file.getTitle() != null) ?
  4523. file.getTitle() : editorUi.defaultFilename;
  4524. if ((file.constructor == DriveFile && file.sync != null &&
  4525. file.sync.isConnected()) || !/(\.html)$/i.test(filename))
  4526. {
  4527. this.addMenuItems(menu, ['-', 'properties']);
  4528. }
  4529. }
  4530. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  4531. // Cannot use print in standalone mode on iOS as we cannot open new windows
  4532. if (!mxClient.IS_IOS || !navigator.standalone)
  4533. {
  4534. this.addMenuItems(menu, ['print'], parent);
  4535. }
  4536. this.addMenuItems(menu, ['-', 'close']);
  4537. }
  4538. })));
  4539. //Replace the default font family menu
  4540. this.put('fontFamily', new Menu(mxUtils.bind(this, function(menu, parent)
  4541. {
  4542. var addItem = mxUtils.bind(this, function(fontName, fontUrl, deletable, fontLabel, tooltip)
  4543. {
  4544. var graph = editorUi.editor.graph;
  4545. var tr = this.styleChange(menu, (fontLabel != null) ? fontLabel : fontName,
  4546. [mxConstants.STYLE_FONTFAMILY, 'fontSource', 'FType'],
  4547. [fontName, (fontUrl != null) ? encodeURIComponent(fontUrl) : null, null],
  4548. null, parent, function()
  4549. {
  4550. graph.setFont(fontName, fontUrl);
  4551. editorUi.fireEvent(new mxEventObject('styleChanged',
  4552. 'keys', [mxConstants.STYLE_FONTFAMILY, 'fontSource', 'FType'],
  4553. 'values', [fontName, (fontUrl != null) ? encodeURIComponent(fontUrl) : null, null],
  4554. 'cells', [graph.cellEditor.getEditingCell()]));
  4555. }, function()
  4556. {
  4557. graph.updateLabelElements(graph.getSelectionCells(), function(elt)
  4558. {
  4559. elt.removeAttribute('face');
  4560. elt.style.fontFamily = null;
  4561. if (elt.nodeName == 'PRE')
  4562. {
  4563. graph.replaceElement(elt, 'div');
  4564. }
  4565. });
  4566. });
  4567. if (deletable)
  4568. {
  4569. var img = document.createElement('img');
  4570. img.className = 'geAdaptiveAsset';
  4571. img.setAttribute('src', Editor.crossImage);
  4572. img.setAttribute('title', mxResources.get('delete'));
  4573. img.setAttribute('valign', 'absmiddle');
  4574. img.setAttribute('border', '0');
  4575. img.style.position = 'relative';
  4576. img.style.top = '2px';
  4577. img.style.width = '14px';
  4578. img.style.cursor = 'default';
  4579. img.style.margin = '0 3px';
  4580. tr.firstChild.nextSibling.nextSibling.appendChild(img);
  4581. mxEvent.addListener(img, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', mxUtils.bind(this, function(evt)
  4582. {
  4583. this.removeCustomFont(fontName, fontUrl);
  4584. this.editorUi.hideCurrentMenu();
  4585. mxEvent.consume(evt);
  4586. }));
  4587. }
  4588. Graph.addFont(fontName, fontUrl);
  4589. tr.firstChild.nextSibling.style.fontFamily = fontName;
  4590. var tooltip = (fontLabel != null) ? fontLabel : fontName;
  4591. if (fontUrl != null)
  4592. {
  4593. tooltip += ' (' + fontUrl + ')';
  4594. }
  4595. tr.setAttribute('title', tooltip);
  4596. });
  4597. var reserved = {};
  4598. for (var i = 0; i < this.defaultFonts.length; i++)
  4599. {
  4600. var value = this.defaultFonts[i];
  4601. if (typeof value === 'string')
  4602. {
  4603. addItem(value);
  4604. }
  4605. else if (value.fontFamily != null && value.fontUrl != null)
  4606. {
  4607. reserved[encodeURIComponent(value.fontFamily) + '@' +
  4608. encodeURIComponent(value.fontUrl)] = true;
  4609. addItem(value.fontFamily, value.fontUrl);
  4610. }
  4611. }
  4612. menu.addSeparator(parent);
  4613. // Special entries in the font menu are composed of custom fonts
  4614. // from the local storage and actual used fonts in the file
  4615. var duplicates = {};
  4616. var fontNames = {};
  4617. var entries = [];
  4618. function addEntry(entry)
  4619. {
  4620. var key = encodeURIComponent(entry.name) +
  4621. ((entry.url == null) ? '' :
  4622. '@' + encodeURIComponent(entry.url));
  4623. if (!reserved[key])
  4624. {
  4625. var label = entry.name;
  4626. var counter = 0;
  4627. while (fontNames[label.toLowerCase()] != null)
  4628. {
  4629. label = entry.name + ' (' + (++counter) + ')';
  4630. }
  4631. if (duplicates[key] == null)
  4632. {
  4633. entries.push({name: entry.name, url: entry.url,
  4634. label: label, title: entry.url});
  4635. fontNames[label.toLowerCase()] = entry;
  4636. duplicates[key] = entry;
  4637. }
  4638. }
  4639. };
  4640. // Adds custom user-defined fonts from local storage
  4641. for (var i = 0; i < this.customFonts.length; i++)
  4642. {
  4643. addEntry(this.customFonts[i]);
  4644. }
  4645. // Sorts by label
  4646. entries.sort(function(a, b)
  4647. {
  4648. if (a.label < b.label)
  4649. {
  4650. return -1;
  4651. }
  4652. else if (a.label > b.label)
  4653. {
  4654. return 1;
  4655. }
  4656. else
  4657. {
  4658. return 0;
  4659. }
  4660. });
  4661. if (entries.length > 0)
  4662. {
  4663. for (var i = 0; i < entries.length; i++)
  4664. {
  4665. addItem(entries[i].name, entries[i].url,
  4666. true, entries[i].label);
  4667. }
  4668. menu.addSeparator(parent);
  4669. }
  4670. menu.addItem(mxResources.get('reset'), null, mxUtils.bind(this, function()
  4671. {
  4672. this.customFonts = [];
  4673. editorUi.fireEvent(new mxEventObject('customFontsChanged'));
  4674. }), parent);
  4675. menu.addSeparator(parent);
  4676. menu.addItem(mxResources.get('custom') + '...', null, mxUtils.bind(this, function()
  4677. {
  4678. var graph = this.editorUi.editor.graph;
  4679. var curFontName = graph.getStylesheet().getDefaultVertexStyle()
  4680. [mxConstants.STYLE_FONTFAMILY];
  4681. var curType = 's';
  4682. var curUrl = null;
  4683. // Handles in-place editing custom fonts via font family lookup
  4684. if (graph.isEditing())
  4685. {
  4686. var node = graph.getSelectedEditingElement();
  4687. if (node != null)
  4688. {
  4689. var css = mxUtils.getCurrentStyle(node);
  4690. if (css != null)
  4691. {
  4692. curFontName = mxUtils.getCssFontFamily(css.fontFamily);
  4693. // Finds the URL for the current font by finding the nearest parent element
  4694. // with a data-font-src attribute or the fontSource attribute from the cell
  4695. var state = graph.getView().getState(graph.cellEditor.getEditingCell());
  4696. var curUrl = (state != null) ? state.style['fontSource'] : null;
  4697. if (curUrl != null)
  4698. {
  4699. curUrl = decodeURIComponent(curUrl);
  4700. }
  4701. var temp = node;
  4702. while (temp != null && temp != graph.cellEditor.textarea)
  4703. {
  4704. if (temp.nodeType == mxConstants.NODETYPE_ELEMENT)
  4705. {
  4706. if (temp.getAttribute('data-font-src') != null)
  4707. {
  4708. curUrl = temp.getAttribute('data-font-src');
  4709. break;
  4710. }
  4711. else if (temp.getAttribute('face') == curFontName)
  4712. {
  4713. // Means that a system font is used for the element
  4714. curUrl = null;
  4715. break;
  4716. }
  4717. }
  4718. temp = temp.parentNode;
  4719. }
  4720. if (curUrl != null)
  4721. {
  4722. if (Graph.isGoogleFontUrl(curUrl))
  4723. {
  4724. curUrl = null;
  4725. curType = 'g';
  4726. }
  4727. else
  4728. {
  4729. curType = 'w';
  4730. }
  4731. }
  4732. }
  4733. }
  4734. }
  4735. else
  4736. {
  4737. var state = graph.getView().getState(graph.getSelectionCell());
  4738. if (state != null)
  4739. {
  4740. curFontName = state.style[mxConstants.STYLE_FONTFAMILY] || curFontName;
  4741. var temp = state.style['fontSource'];
  4742. if (temp != null)
  4743. {
  4744. temp = decodeURIComponent(temp);
  4745. if (Graph.isGoogleFontUrl(temp))
  4746. {
  4747. curType = 'g';
  4748. }
  4749. else
  4750. {
  4751. curType = 'w';
  4752. curUrl = temp;
  4753. }
  4754. }
  4755. }
  4756. }
  4757. if (curUrl != null && curUrl.substring(0, PROXY_URL.length) == PROXY_URL)
  4758. {
  4759. curUrl = decodeURIComponent(curUrl.substr((PROXY_URL + '?url=').length));
  4760. }
  4761. // Saves the current selection state
  4762. var selState = null;
  4763. if (document.activeElement == graph.cellEditor.textarea)
  4764. {
  4765. selState = graph.cellEditor.saveSelection();
  4766. }
  4767. var dlg = new FontDialog(this.editorUi, curFontName, curUrl, curType, mxUtils.bind(this, function(fontName, fontUrl, type)
  4768. {
  4769. // Restores the selection state
  4770. if (selState != null)
  4771. {
  4772. graph.cellEditor.restoreSelection(selState);
  4773. selState = null;
  4774. }
  4775. if (fontName != null && fontName.length > 0)
  4776. {
  4777. this.addCustomFont(fontName, fontUrl);
  4778. if (graph.isEditing())
  4779. {
  4780. graph.setFont(fontName, fontUrl);
  4781. }
  4782. else
  4783. {
  4784. graph.getModel().beginUpdate();
  4785. try
  4786. {
  4787. graph.stopEditing(false);
  4788. graph.setCellStyles(mxConstants.STYLE_FONTFAMILY, fontName);
  4789. graph.setCellStyles('fontSource', (fontUrl != null) ?
  4790. encodeURIComponent(fontUrl) : null);
  4791. graph.setCellStyles('FType', null);
  4792. }
  4793. finally
  4794. {
  4795. graph.getModel().endUpdate();
  4796. }
  4797. }
  4798. }
  4799. }));
  4800. this.editorUi.showDialog(dlg.container, 380,
  4801. 130 + (Editor.enableWebFonts ? 70 : 0) + (urlParams['isGoogleFontsEnabled'] != '0'? 50 : 0), true, true);
  4802. dlg.init();
  4803. }), parent, null, true);
  4804. })));
  4805. };
  4806. })();