EditorUi.js 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Constructs a new graph editor
  6. */
  7. EditorUi = function(editor, container, lightbox)
  8. {
  9. mxEventSource.call(this);
  10. this.destroyFunctions = [];
  11. this.editor = editor || new Editor();
  12. this.container = container || document.body;
  13. var graph = this.editor.graph;
  14. graph.lightbox = lightbox;
  15. // Pre-fetches submenu image or replaces with embedded image if supported
  16. if (mxClient.IS_SVG)
  17. {
  18. mxPopupMenu.prototype.submenuImage = 'data:image/gif;base64,R0lGODlhCQAJAIAAAP///zMzMyH5BAEAAAAALAAAAAAJAAkAAAIPhI8WebHsHopSOVgb26AAADs=';
  19. }
  20. else
  21. {
  22. new Image().src = mxPopupMenu.prototype.submenuImage;
  23. }
  24. // Pre-fetches connect image
  25. if (!mxClient.IS_SVG && mxConnectionHandler.prototype.connectImage != null)
  26. {
  27. new Image().src = mxConnectionHandler.prototype.connectImage.src;
  28. }
  29. // Disables graph and forced panning in chromeless mode
  30. if (this.editor.chromeless)
  31. {
  32. this.footerHeight = 0;
  33. graph.isEnabled = function() { return false; };
  34. graph.panningHandler.isForcePanningEvent = function(me)
  35. {
  36. return !mxEvent.isPopupTrigger(me.getEvent());
  37. };
  38. }
  39. // Creates the user interface
  40. this.actions = new Actions(this);
  41. this.menus = this.createMenus();
  42. this.createDivs();
  43. this.createUi();
  44. this.refresh();
  45. // Disables HTML and text selection
  46. var textEditing = mxUtils.bind(this, function(evt)
  47. {
  48. if (evt == null)
  49. {
  50. evt = window.event;
  51. }
  52. return this.isSelectionAllowed(evt) || graph.isEditing();
  53. });
  54. // Disables text selection while not editing and no dialog visible
  55. if (this.container == document.body)
  56. {
  57. this.menubarContainer.onselectstart = textEditing;
  58. this.menubarContainer.onmousedown = textEditing;
  59. this.toolbarContainer.onselectstart = textEditing;
  60. this.toolbarContainer.onmousedown = textEditing;
  61. this.diagramContainer.onselectstart = textEditing;
  62. this.diagramContainer.onmousedown = textEditing;
  63. this.sidebarContainer.onselectstart = textEditing;
  64. this.sidebarContainer.onmousedown = textEditing;
  65. this.formatContainer.onselectstart = textEditing;
  66. this.formatContainer.onmousedown = textEditing;
  67. this.footerContainer.onselectstart = textEditing;
  68. this.footerContainer.onmousedown = textEditing;
  69. if (this.tabContainer != null)
  70. {
  71. // Mouse down is needed for drag and drop
  72. this.tabContainer.onselectstart = textEditing;
  73. }
  74. }
  75. // And uses built-in context menu while editing
  76. if (!this.editor.chromeless)
  77. {
  78. if (mxClient.IS_IE && (typeof(document.documentMode) === 'undefined' || document.documentMode < 9))
  79. {
  80. mxEvent.addListener(this.diagramContainer, 'contextmenu', textEditing);
  81. }
  82. else
  83. {
  84. // Allows browser context menu outside of diagram and sidebar
  85. this.diagramContainer.oncontextmenu = textEditing;
  86. }
  87. }
  88. else
  89. {
  90. graph.panningHandler.usePopupTrigger = false;
  91. }
  92. // Contains the main graph instance inside the given panel
  93. graph.init(this.diagramContainer);
  94. // Creates hover icons
  95. this.hoverIcons = this.createHoverIcons();
  96. // Adds tooltip when mouse is over scrollbars to show space-drag panning option
  97. mxEvent.addListener(this.diagramContainer, 'mousemove', mxUtils.bind(this, function(evt)
  98. {
  99. var off = mxUtils.getOffset(this.diagramContainer);
  100. if (mxEvent.getClientX(evt) - off.x - this.diagramContainer.clientWidth > 0 ||
  101. mxEvent.getClientY(evt) - off.y - this.diagramContainer.clientHeight > 0)
  102. {
  103. this.diagramContainer.setAttribute('title', mxResources.get('panTooltip'));
  104. }
  105. else
  106. {
  107. this.diagramContainer.removeAttribute('title');
  108. }
  109. }));
  110. // Escape key hides dialogs, adds space+drag panning
  111. var spaceKeyPressed = false;
  112. // Overrides hovericons to disable while space key is pressed
  113. var hoverIconsIsResetEvent = this.hoverIcons.isResetEvent;
  114. this.hoverIcons.isResetEvent = function(evt, allowShift)
  115. {
  116. return spaceKeyPressed || hoverIconsIsResetEvent.apply(this, arguments);
  117. };
  118. this.keydownHandler = mxUtils.bind(this, function(evt)
  119. {
  120. if (evt.which == 32 /* Space */)
  121. {
  122. spaceKeyPressed = true;
  123. this.hoverIcons.reset();
  124. graph.container.style.cursor = 'move';
  125. // Disables scroll after space keystroke with scrollbars
  126. if (!graph.isEditing() && mxEvent.getSource(evt) == graph.container)
  127. {
  128. mxEvent.consume(evt);
  129. }
  130. }
  131. else if (!mxEvent.isConsumed(evt) && evt.keyCode == 27 /* Escape */)
  132. {
  133. this.hideDialog();
  134. }
  135. });
  136. mxEvent.addListener(document, 'keydown', this.keydownHandler);
  137. this.keyupHandler = mxUtils.bind(this, function(evt)
  138. {
  139. graph.container.style.cursor = '';
  140. spaceKeyPressed = false;
  141. });
  142. mxEvent.addListener(document, 'keyup', this.keyupHandler);
  143. // Forces panning for middle and right mouse buttons
  144. var panningHandlerIsForcePanningEvent = graph.panningHandler.isForcePanningEvent;
  145. graph.panningHandler.isForcePanningEvent = function(me)
  146. {
  147. // Ctrl+left button is reported as right button in FF on Mac
  148. return panningHandlerIsForcePanningEvent.apply(this, arguments) ||
  149. spaceKeyPressed || (mxEvent.isMouseEvent(me.getEvent()) &&
  150. (this.usePopupTrigger || !mxEvent.isPopupTrigger(me.getEvent())) &&
  151. ((!mxEvent.isControlDown(me.getEvent()) &&
  152. mxEvent.isRightMouseButton(me.getEvent())) ||
  153. mxEvent.isMiddleMouseButton(me.getEvent())));
  154. };
  155. // Ctrl/Cmd+Enter applies editing value except in Safari where Ctrl+Enter creates
  156. // a new line (while Enter creates a new paragraph and Shift+Enter stops)
  157. var cellEditorIsStopEditingEvent = graph.cellEditor.isStopEditingEvent;
  158. graph.cellEditor.isStopEditingEvent = function(evt)
  159. {
  160. return cellEditorIsStopEditingEvent.apply(this, arguments) ||
  161. (evt.keyCode == 13 && ((!mxClient.IS_SF && mxEvent.isControlDown(evt)) ||
  162. (mxClient.IS_MAC && mxEvent.isMetaDown(evt)) ||
  163. (mxClient.IS_SF && mxEvent.isShiftDown(evt))));
  164. };
  165. // Switches toolbar for text editing
  166. var textMode = false;
  167. var fontMenu = null;
  168. var sizeMenu = null;
  169. var nodes = null;
  170. var updateToolbar = mxUtils.bind(this, function()
  171. {
  172. if (textMode != graph.cellEditor.isContentEditing())
  173. {
  174. var node = this.toolbar.container.firstChild;
  175. var newNodes = [];
  176. while (node != null)
  177. {
  178. var tmp = node.nextSibling;
  179. if (mxUtils.indexOf(this.toolbar.staticElements, node) < 0)
  180. {
  181. node.parentNode.removeChild(node);
  182. newNodes.push(node);
  183. }
  184. node = tmp;
  185. }
  186. // Saves references to special items
  187. var tmp1 = this.toolbar.fontMenu;
  188. var tmp2 = this.toolbar.sizeMenu;
  189. if (nodes == null)
  190. {
  191. this.toolbar.createTextToolbar();
  192. }
  193. else
  194. {
  195. for (var i = 0; i < nodes.length; i++)
  196. {
  197. this.toolbar.container.appendChild(nodes[i]);
  198. }
  199. // Restores references to special items
  200. this.toolbar.fontMenu = fontMenu;
  201. this.toolbar.sizeMenu = sizeMenu;
  202. }
  203. textMode = graph.cellEditor.isContentEditing();
  204. fontMenu = tmp1;
  205. sizeMenu = tmp2;
  206. nodes = newNodes;
  207. }
  208. });
  209. var ui = this;
  210. // Overrides cell editor to update toolbar
  211. var cellEditorStartEditing = graph.cellEditor.startEditing;
  212. graph.cellEditor.startEditing = function()
  213. {
  214. cellEditorStartEditing.apply(this, arguments);
  215. updateToolbar();
  216. if (graph.cellEditor.isContentEditing())
  217. {
  218. var updating = false;
  219. var updateCssHandler = function()
  220. {
  221. if (!updating)
  222. {
  223. updating = true;
  224. window.setTimeout(function()
  225. {
  226. var selectedElement = graph.getSelectedElement();
  227. var node = selectedElement;
  228. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  229. {
  230. node = node.parentNode;
  231. }
  232. if (node != null)
  233. {
  234. var css = mxUtils.getCurrentStyle(node);
  235. if (css != null && ui.toolbar != null)
  236. {
  237. // Strips leading and trailing quotes
  238. var ff = css.fontFamily;
  239. if (ff.charAt(0) == '\'')
  240. {
  241. ff = ff.substring(1);
  242. }
  243. if (ff.charAt(ff.length - 1) == '\'')
  244. {
  245. ff = ff.substring(0, ff.length - 1);
  246. }
  247. ui.toolbar.setFontName(ff);
  248. ui.toolbar.setFontSize(parseInt(css.fontSize));
  249. }
  250. }
  251. updating = false;
  252. }, 0);
  253. }
  254. };
  255. mxEvent.addListener(graph.cellEditor.textarea, 'input', updateCssHandler)
  256. mxEvent.addListener(graph.cellEditor.textarea, 'touchend', updateCssHandler);
  257. mxEvent.addListener(graph.cellEditor.textarea, 'mouseup', updateCssHandler);
  258. mxEvent.addListener(graph.cellEditor.textarea, 'keyup', updateCssHandler);
  259. updateCssHandler();
  260. }
  261. };
  262. var cellEditorStopEditing = graph.cellEditor.stopEditing;
  263. graph.cellEditor.stopEditing = function(cell, trigger)
  264. {
  265. cellEditorStopEditing.apply(this, arguments);
  266. updateToolbar();
  267. };
  268. // Enables scrollbars and sets cursor style for the container
  269. graph.container.setAttribute('tabindex', '0');
  270. graph.container.style.cursor = 'default';
  271. // Workaround for page scroll if embedded via iframe
  272. if (window.self === window.top && graph.container.parentNode != null)
  273. {
  274. try
  275. {
  276. graph.container.focus();
  277. }
  278. catch (e)
  279. {
  280. // ignores error in old versions of IE
  281. }
  282. }
  283. // Keeps graph container focused on mouse down
  284. var graphFireMouseEvent = graph.fireMouseEvent;
  285. graph.fireMouseEvent = function(evtName, me, sender)
  286. {
  287. if (evtName == mxEvent.MOUSE_DOWN)
  288. {
  289. this.container.focus();
  290. }
  291. graphFireMouseEvent.apply(this, arguments);
  292. };
  293. // Configures automatic expand on mouseover
  294. graph.popupMenuHandler.autoExpand = true;
  295. // Installs context menu
  296. if (this.menus != null)
  297. {
  298. graph.popupMenuHandler.factoryMethod = mxUtils.bind(this, function(menu, cell, evt)
  299. {
  300. this.menus.createPopupMenu(menu, cell, evt);
  301. });
  302. }
  303. // Hides context menu
  304. mxEvent.addGestureListeners(document, mxUtils.bind(this, function(evt)
  305. {
  306. graph.popupMenuHandler.hideMenu();
  307. }));
  308. // Create handler for key events
  309. this.keyHandler = this.createKeyHandler(editor);
  310. // Getter for key handler
  311. this.getKeyHandler = function()
  312. {
  313. return keyHandler;
  314. };
  315. // Stores the current style and assigns it to new cells
  316. var styles = ['rounded', 'shadow', 'glass', 'dashed', 'dashPattern', 'comic', 'labelBackgroundColor'];
  317. var connectStyles = ['shape', 'edgeStyle', 'curved', 'rounded', 'elbow', 'comic', 'jumpStyle', 'jumpSize'];
  318. // Note: Everything that is not in styles is ignored (styles is augmented below)
  319. this.setDefaultStyle = function(cell)
  320. {
  321. var state = graph.view.getState(cell);
  322. if (state != null)
  323. {
  324. // Ignores default styles
  325. var clone = cell.clone();
  326. clone.style = ''
  327. var defaultStyle = graph.getCellStyle(clone);
  328. var values = [];
  329. var keys = [];
  330. for (var key in state.style)
  331. {
  332. if (defaultStyle[key] != state.style[key])
  333. {
  334. values.push(state.style[key]);
  335. keys.push(key);
  336. }
  337. }
  338. // Handles special case for value "none"
  339. var cellStyle = graph.getModel().getStyle(state.cell);
  340. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  341. for (var i = 0; i < tokens.length; i++)
  342. {
  343. var tmp = tokens[i];
  344. var pos = tmp.indexOf('=');
  345. if (pos >= 0)
  346. {
  347. var key = tmp.substring(0, pos);
  348. var value = tmp.substring(pos + 1);
  349. if (defaultStyle[key] != null && value == 'none')
  350. {
  351. values.push(value);
  352. keys.push(key);
  353. }
  354. }
  355. }
  356. // Resets current style
  357. if (graph.getModel().isEdge(state.cell))
  358. {
  359. graph.currentEdgeStyle = {};
  360. }
  361. else
  362. {
  363. graph.currentVertexStyle = {}
  364. }
  365. this.fireEvent(new mxEventObject('styleChanged', 'keys', keys, 'values', values, 'cells', [state.cell]));
  366. }
  367. };
  368. this.clearDefaultStyle = function()
  369. {
  370. graph.currentEdgeStyle = mxUtils.clone(graph.defaultEdgeStyle);
  371. graph.currentVertexStyle = mxUtils.clone(graph.defaultVertexStyle);
  372. // Updates UI
  373. this.fireEvent(new mxEventObject('styleChanged', 'keys', [], 'values', [], 'cells', []));
  374. };
  375. // Keys that should be ignored if the cell has a value (known: new default for all cells is html=1 so
  376. // for the html key this effecticely only works for edges inserted via the connection handler)
  377. var valueStyles = ['fontFamily', 'fontSize', 'fontColor'];
  378. // Keys that always update the current edge style regardless of selection
  379. var alwaysEdgeStyles = ['edgeStyle', 'startArrow', 'startFill', 'startSize', 'endArrow',
  380. 'endFill', 'endSize', 'jettySize', 'orthogonalLoop'];
  381. // Keys that are ignored together (if one appears all are ignored)
  382. var keyGroups = [['startArrow', 'startFill', 'startSize', 'endArrow', 'endFill', 'endSize', 'jettySize', 'orthogonalLoop'],
  383. ['strokeColor', 'strokeWidth'],
  384. ['fillColor', 'gradientColor'],
  385. valueStyles,
  386. ['align'],
  387. ['html']];
  388. // Adds all keys used above to the styles array
  389. for (var i = 0; i < keyGroups.length; i++)
  390. {
  391. for (var j = 0; j < keyGroups[i].length; j++)
  392. {
  393. styles.push(keyGroups[i][j]);
  394. }
  395. }
  396. for (var i = 0; i < connectStyles.length; i++)
  397. {
  398. if (mxUtils.indexOf(styles, connectStyles[i]) < 0)
  399. {
  400. styles.push(connectStyles[i]);
  401. }
  402. }
  403. // Implements a global current style for edges and vertices that is applied to new cells
  404. var insertHandler = function(cells, asText)
  405. {
  406. graph.getModel().beginUpdate();
  407. try
  408. {
  409. // Applies only basic text styles
  410. if (asText)
  411. {
  412. var edge = graph.getModel().isEdge(cell);
  413. var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
  414. var textStyles = ['fontSize', 'fontFamily', 'fontColor'];
  415. for (var j = 0; j < textStyles.length; j++)
  416. {
  417. var value = current[textStyles[j]];
  418. if (value != null)
  419. {
  420. graph.setCellStyles(textStyles[j], value, cells);
  421. }
  422. }
  423. }
  424. else
  425. {
  426. for (var i = 0; i < cells.length; i++)
  427. {
  428. var cell = cells[i];
  429. // Removes styles defined in the cell style from the styles to be applied
  430. var cellStyle = graph.getModel().getStyle(cell);
  431. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  432. var appliedStyles = styles.slice();
  433. for (var j = 0; j < tokens.length; j++)
  434. {
  435. var tmp = tokens[j];
  436. var pos = tmp.indexOf('=');
  437. if (pos >= 0)
  438. {
  439. var key = tmp.substring(0, pos);
  440. var index = mxUtils.indexOf(appliedStyles, key);
  441. if (index >= 0)
  442. {
  443. appliedStyles.splice(index, 1);
  444. }
  445. // Handles special cases where one defined style ignores other styles
  446. for (var k = 0; k < keyGroups.length; k++)
  447. {
  448. var group = keyGroups[k];
  449. if (mxUtils.indexOf(group, key) >= 0)
  450. {
  451. for (var l = 0; l < group.length; l++)
  452. {
  453. var index2 = mxUtils.indexOf(appliedStyles, group[l]);
  454. if (index2 >= 0)
  455. {
  456. appliedStyles.splice(index2, 1);
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. // Applies the current style to the cell
  464. var edge = graph.getModel().isEdge(cell);
  465. var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
  466. for (var j = 0; j < appliedStyles.length; j++)
  467. {
  468. var key = appliedStyles[j];
  469. var styleValue = current[key];
  470. if (styleValue != null && (key != 'shape' || edge))
  471. {
  472. // Special case: Connect styles are not applied here but in the connection handler
  473. if (!edge || mxUtils.indexOf(connectStyles, key) < 0)
  474. {
  475. graph.setCellStyles(key, styleValue, [cell]);
  476. }
  477. }
  478. }
  479. }
  480. }
  481. }
  482. finally
  483. {
  484. graph.getModel().endUpdate();
  485. }
  486. };
  487. graph.addListener('cellsInserted', function(sender, evt)
  488. {
  489. insertHandler(evt.getProperty('cells'));
  490. });
  491. graph.addListener('textInserted', function(sender, evt)
  492. {
  493. insertHandler(evt.getProperty('cells'), true);
  494. });
  495. graph.connectionHandler.addListener(mxEvent.CONNECT, function(sender, evt)
  496. {
  497. var cells = [evt.getProperty('cell')];
  498. if (evt.getProperty('terminalInserted'))
  499. {
  500. cells.push(evt.getProperty('terminal'));
  501. }
  502. insertHandler(cells);
  503. });
  504. this.addListener('styleChanged', mxUtils.bind(this, function(sender, evt)
  505. {
  506. // Checks if edges and/or vertices were modified
  507. var cells = evt.getProperty('cells');
  508. var vertex = false;
  509. var edge = false;
  510. if (cells.length > 0)
  511. {
  512. for (var i = 0; i < cells.length; i++)
  513. {
  514. vertex = graph.getModel().isVertex(cells[i]) || vertex;
  515. edge = graph.getModel().isEdge(cells[i]) || edge;
  516. if (edge && vertex)
  517. {
  518. break;
  519. }
  520. }
  521. }
  522. else
  523. {
  524. vertex = true;
  525. edge = true;
  526. }
  527. var keys = evt.getProperty('keys');
  528. var values = evt.getProperty('values');
  529. for (var i = 0; i < keys.length; i++)
  530. {
  531. var common = mxUtils.indexOf(valueStyles, keys[i]) >= 0;
  532. // Ignores transparent stroke colors
  533. if (keys[i] != 'strokeColor' || (values[i] != null && values[i] != 'none'))
  534. {
  535. // Special case: Edge style and shape
  536. if (mxUtils.indexOf(connectStyles, keys[i]) >= 0)
  537. {
  538. if (edge || mxUtils.indexOf(alwaysEdgeStyles, keys[i]) >= 0)
  539. {
  540. if (values[i] == null)
  541. {
  542. delete graph.currentEdgeStyle[keys[i]];
  543. }
  544. else
  545. {
  546. graph.currentEdgeStyle[keys[i]] = values[i];
  547. }
  548. }
  549. // Uses style for vertex if defined in styles
  550. else if (vertex && mxUtils.indexOf(styles, keys[i]) >= 0)
  551. {
  552. if (values[i] == null)
  553. {
  554. delete graph.currentVertexStyle[keys[i]];
  555. }
  556. else
  557. {
  558. graph.currentVertexStyle[keys[i]] = values[i];
  559. }
  560. }
  561. }
  562. else if (mxUtils.indexOf(styles, keys[i]) >= 0)
  563. {
  564. if (vertex || common)
  565. {
  566. if (values[i] == null)
  567. {
  568. delete graph.currentVertexStyle[keys[i]];
  569. }
  570. else
  571. {
  572. graph.currentVertexStyle[keys[i]] = values[i];
  573. }
  574. }
  575. if (edge || common || mxUtils.indexOf(alwaysEdgeStyles, keys[i]) >= 0)
  576. {
  577. if (values[i] == null)
  578. {
  579. delete graph.currentEdgeStyle[keys[i]];
  580. }
  581. else
  582. {
  583. graph.currentEdgeStyle[keys[i]] = values[i];
  584. }
  585. }
  586. }
  587. }
  588. }
  589. if (this.toolbar != null)
  590. {
  591. this.toolbar.setFontName(graph.currentVertexStyle['fontFamily'] || Menus.prototype.defaultFont);
  592. this.toolbar.setFontSize(graph.currentVertexStyle['fontSize'] || Menus.prototype.defaultFontSize);
  593. if (this.toolbar.edgeStyleMenu != null)
  594. {
  595. // Updates toolbar icon for edge style
  596. var edgeStyleDiv = this.toolbar.edgeStyleMenu.getElementsByTagName('div')[0];
  597. if (graph.currentEdgeStyle['edgeStyle'] == 'orthogonalEdgeStyle' && graph.currentEdgeStyle['curved'] == '1')
  598. {
  599. edgeStyleDiv.className = 'geSprite geSprite-curved';
  600. }
  601. else if (graph.currentEdgeStyle['edgeStyle'] == 'straight' || graph.currentEdgeStyle['edgeStyle'] == 'none' ||
  602. graph.currentEdgeStyle['edgeStyle'] == null)
  603. {
  604. edgeStyleDiv.className = 'geSprite geSprite-straight';
  605. }
  606. else if (graph.currentEdgeStyle['edgeStyle'] == 'entityRelationEdgeStyle')
  607. {
  608. edgeStyleDiv.className = 'geSprite geSprite-entity';
  609. }
  610. else if (graph.currentEdgeStyle['edgeStyle'] == 'elbowEdgeStyle')
  611. {
  612. edgeStyleDiv.className = 'geSprite geSprite-' + ((graph.currentEdgeStyle['elbow'] == 'vertical') ?
  613. 'verticalelbow' : 'horizontalelbow');
  614. }
  615. else if (graph.currentEdgeStyle['edgeStyle'] == 'isometricEdgeStyle')
  616. {
  617. edgeStyleDiv.className = 'geSprite geSprite-' + ((graph.currentEdgeStyle['elbow'] == 'vertical') ?
  618. 'verticalisometric' : 'horizontalisometric');
  619. }
  620. else
  621. {
  622. edgeStyleDiv.className = 'geSprite geSprite-orthogonal';
  623. }
  624. }
  625. if (this.toolbar.edgeShapeMenu != null)
  626. {
  627. // Updates icon for edge shape
  628. var edgeShapeDiv = this.toolbar.edgeShapeMenu.getElementsByTagName('div')[0];
  629. if (graph.currentEdgeStyle['shape'] == 'link')
  630. {
  631. edgeShapeDiv.className = 'geSprite geSprite-linkedge';
  632. }
  633. else if (graph.currentEdgeStyle['shape'] == 'flexArrow')
  634. {
  635. edgeShapeDiv.className = 'geSprite geSprite-arrow';
  636. }
  637. else if (graph.currentEdgeStyle['shape'] == 'arrow')
  638. {
  639. edgeShapeDiv.className = 'geSprite geSprite-simplearrow';
  640. }
  641. else
  642. {
  643. edgeShapeDiv.className = 'geSprite geSprite-connection';
  644. }
  645. }
  646. // Updates icon for optinal line start shape
  647. if (this.toolbar.lineStartMenu != null)
  648. {
  649. var lineStartDiv = this.toolbar.lineStartMenu.getElementsByTagName('div')[0];
  650. lineStartDiv.className = this.getCssClassForMarker('start',
  651. graph.currentEdgeStyle['shape'], graph.currentEdgeStyle[mxConstants.STYLE_STARTARROW],
  652. mxUtils.getValue(graph.currentEdgeStyle, 'startFill', '1'));
  653. }
  654. // Updates icon for optinal line end shape
  655. if (this.toolbar.lineEndMenu != null)
  656. {
  657. var lineEndDiv = this.toolbar.lineEndMenu.getElementsByTagName('div')[0];
  658. lineEndDiv.className = this.getCssClassForMarker('end',
  659. graph.currentEdgeStyle['shape'], graph.currentEdgeStyle[mxConstants.STYLE_ENDARROW],
  660. mxUtils.getValue(graph.currentEdgeStyle, 'endFill', '1'));
  661. }
  662. }
  663. }));
  664. // Update font size and font family labels
  665. if (this.toolbar != null)
  666. {
  667. var update = mxUtils.bind(this, function()
  668. {
  669. var ff = graph.currentVertexStyle['fontFamily'] || 'Helvetica';
  670. var fs = String(graph.currentVertexStyle['fontSize'] || '12');
  671. var state = graph.getView().getState(graph.getSelectionCell());
  672. if (state != null)
  673. {
  674. ff = state.style[mxConstants.STYLE_FONTFAMILY] || ff;
  675. fs = state.style[mxConstants.STYLE_FONTSIZE] || fs;
  676. if (ff.length > 10)
  677. {
  678. ff = ff.substring(0, 8) + '...';
  679. }
  680. }
  681. this.toolbar.setFontName(ff);
  682. this.toolbar.setFontSize(fs);
  683. });
  684. graph.getSelectionModel().addListener(mxEvent.CHANGE, update);
  685. graph.getModel().addListener(mxEvent.CHANGE, update);
  686. }
  687. // Makes sure the current layer is visible when cells are added
  688. graph.addListener(mxEvent.CELLS_ADDED, function(sender, evt)
  689. {
  690. var cells = evt.getProperty('cells');
  691. var parent = evt.getProperty('parent');
  692. if (graph.getModel().isLayer(parent) && !graph.isCellVisible(parent) && cells != null && cells.length > 0)
  693. {
  694. graph.getModel().setVisible(parent, true);
  695. }
  696. });
  697. // Global handler to hide the current menu
  698. this.gestureHandler = mxUtils.bind(this, function(evt)
  699. {
  700. if (this.currentMenu != null && mxEvent.getSource(evt) != this.currentMenu.div)
  701. {
  702. this.hideCurrentMenu();
  703. }
  704. });
  705. mxEvent.addGestureListeners(document, this.gestureHandler);
  706. // Updates the editor UI after the window has been resized or the orientation changes
  707. // Timeout is workaround for old IE versions which have a delay for DOM client sizes.
  708. // Should not use delay > 0 to avoid handle multiple repaints during window resize
  709. this.resizeHandler = mxUtils.bind(this, function()
  710. {
  711. window.setTimeout(mxUtils.bind(this, function()
  712. {
  713. this.refresh();
  714. }), 0);
  715. });
  716. mxEvent.addListener(window, 'resize', this.resizeHandler);
  717. this.orientationChangeHandler = mxUtils.bind(this, function()
  718. {
  719. this.refresh();
  720. });
  721. mxEvent.addListener(window, 'orientationchange', this.orientationChangeHandler);
  722. // Workaround for bug on iOS see
  723. // http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
  724. if (mxClient.IS_IOS && !window.navigator.standalone)
  725. {
  726. this.scrollHandler = mxUtils.bind(this, function()
  727. {
  728. window.scrollTo(0, 0);
  729. });
  730. mxEvent.addListener(window, 'scroll', this.scrollHandler);
  731. }
  732. /**
  733. * Sets the initial scrollbar locations after a file was loaded.
  734. */
  735. this.editor.addListener('resetGraphView', mxUtils.bind(this, function()
  736. {
  737. this.resetScrollbars();
  738. }));
  739. /**
  740. * Repaints the grid.
  741. */
  742. this.addListener('gridEnabledChanged', mxUtils.bind(this, function()
  743. {
  744. graph.view.validateBackground();
  745. }));
  746. this.addListener('backgroundColorChanged', mxUtils.bind(this, function()
  747. {
  748. graph.view.validateBackground();
  749. }));
  750. /**
  751. * Repaints the grid.
  752. */
  753. graph.addListener('gridSizeChanged', mxUtils.bind(this, function()
  754. {
  755. if (graph.isGridEnabled())
  756. {
  757. graph.view.validateBackground();
  758. }
  759. }));
  760. // Resets UI, updates action and menu states
  761. this.editor.resetGraph();
  762. this.init();
  763. this.open();
  764. };
  765. // Extends mxEventSource
  766. mxUtils.extend(EditorUi, mxEventSource);
  767. /**
  768. * Global config that specifies if the compact UI elements should be used.
  769. */
  770. EditorUi.compactUi = true;
  771. /**
  772. * Specifies the size of the split bar.
  773. */
  774. EditorUi.prototype.splitSize = (mxClient.IS_TOUCH || mxClient.IS_POINTER) ? 12 : 8;
  775. /**
  776. * Specifies the height of the menubar. Default is 34.
  777. */
  778. EditorUi.prototype.menubarHeight = 30;
  779. /**
  780. * Specifies the width of the format panel should be enabled. Default is true.
  781. */
  782. EditorUi.prototype.formatEnabled = true;
  783. /**
  784. * Specifies the width of the format panel. Default is 240.
  785. */
  786. EditorUi.prototype.formatWidth = 240;
  787. /**
  788. * Specifies the height of the toolbar. Default is 36.
  789. */
  790. EditorUi.prototype.toolbarHeight = 34;
  791. /**
  792. * Specifies the height of the footer. Default is 28.
  793. */
  794. EditorUi.prototype.footerHeight = 28;
  795. /**
  796. * Specifies the height of the optional sidebarFooterContainer. Default is 34.
  797. */
  798. EditorUi.prototype.sidebarFooterHeight = 34;
  799. /**
  800. * Specifies the link for the edit button in chromeless mode.
  801. */
  802. EditorUi.prototype.editButtonLink = null;
  803. /**
  804. * Specifies the position of the horizontal split bar. Default is 208 or 118 for
  805. * screen widths <= 640px.
  806. */
  807. EditorUi.prototype.hsplitPosition = (screen.width <= 640) ? 118 : 208;
  808. /**
  809. * Specifies if animations are allowed in <executeLayout>. Default is true.
  810. */
  811. EditorUi.prototype.allowAnimation = true;
  812. /**
  813. * Installs the listeners to update the action states.
  814. */
  815. EditorUi.prototype.init = function()
  816. {
  817. /**
  818. * Keypress starts immediate editing on selection cell
  819. */
  820. var graph = this.editor.graph;
  821. mxEvent.addListener(graph.container, 'keydown', mxUtils.bind(this, function(evt)
  822. {
  823. this.onKeyDown(evt);
  824. }));
  825. mxEvent.addListener(graph.container, 'keypress', mxUtils.bind(this, function(evt)
  826. {
  827. this.onKeyPress(evt);
  828. }));
  829. // Updates action states
  830. this.addUndoListener();
  831. this.addBeforeUnloadListener();
  832. graph.getSelectionModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  833. {
  834. this.updateActionStates();
  835. }));
  836. graph.getModel().addListener(mxEvent.CHANGE, mxUtils.bind(this, function()
  837. {
  838. this.updateActionStates();
  839. }));
  840. // Changes action states after change of default parent
  841. var graphSetDefaultParent = graph.setDefaultParent;
  842. var ui = this;
  843. this.editor.graph.setDefaultParent = function()
  844. {
  845. graphSetDefaultParent.apply(this, arguments);
  846. ui.updateActionStates();
  847. };
  848. // Hack to make editLink available in vertex handler
  849. graph.editLink = ui.actions.get('editLink').funct;
  850. this.updateActionStates();
  851. this.initClipboard();
  852. this.initCanvas();
  853. if (this.format != null)
  854. {
  855. this.format.init();
  856. }
  857. };
  858. /**
  859. * Returns true if the given event should start editing. This implementation returns true.
  860. */
  861. EditorUi.prototype.onKeyDown = function(evt)
  862. {
  863. var graph = this.editor.graph;
  864. // Tab selects next cell
  865. if (evt.which == 9 && graph.isEnabled() && !mxEvent.isAltDown(evt))
  866. {
  867. if (graph.isEditing())
  868. {
  869. graph.stopEditing(false);
  870. }
  871. else
  872. {
  873. graph.selectCell(!mxEvent.isShiftDown(evt));
  874. }
  875. mxEvent.consume(evt);
  876. }
  877. };
  878. /**
  879. * Returns true if the given event should start editing. This implementation returns true.
  880. */
  881. EditorUi.prototype.onKeyPress = function(evt)
  882. {
  883. var graph = this.editor.graph;
  884. // KNOWN: Focus does not work if label is empty in quirks mode
  885. if (this.isImmediateEditingEvent(evt) && !graph.isEditing() && !graph.isSelectionEmpty() && evt.which !== 0 &&
  886. !mxEvent.isAltDown(evt) && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt))
  887. {
  888. graph.escape();
  889. graph.startEditing();
  890. // Workaround for FF where char is lost if cursor is placed before char
  891. if (mxClient.IS_FF)
  892. {
  893. var ce = graph.cellEditor;
  894. ce.textarea.innerHTML = String.fromCharCode(evt.which);
  895. // Moves cursor to end of textarea
  896. var range = document.createRange();
  897. range.selectNodeContents(ce.textarea);
  898. range.collapse(false);
  899. var sel = window.getSelection();
  900. sel.removeAllRanges();
  901. sel.addRange(range);
  902. }
  903. }
  904. };
  905. /**
  906. * Returns true if the given event should start editing. This implementation returns true.
  907. */
  908. EditorUi.prototype.isImmediateEditingEvent = function(evt)
  909. {
  910. return true;
  911. };
  912. /**
  913. * Private helper method.
  914. */
  915. EditorUi.prototype.getCssClassForMarker = function(prefix, shape, marker, fill)
  916. {
  917. var result = '';
  918. if (shape == 'flexArrow')
  919. {
  920. result = (marker != null && marker != mxConstants.NONE) ?
  921. 'geSprite geSprite-' + prefix + 'blocktrans' : 'geSprite geSprite-noarrow';
  922. }
  923. else
  924. {
  925. if (marker == mxConstants.ARROW_CLASSIC)
  926. {
  927. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'classic' : 'geSprite geSprite-' + prefix + 'classictrans';
  928. }
  929. else if (marker == mxConstants.ARROW_CLASSIC_THIN)
  930. {
  931. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'classicthin' : 'geSprite geSprite-' + prefix + 'classicthintrans';
  932. }
  933. else if (marker == mxConstants.ARROW_OPEN)
  934. {
  935. result = 'geSprite geSprite-' + prefix + 'open';
  936. }
  937. else if (marker == mxConstants.ARROW_OPEN_THIN)
  938. {
  939. result = 'geSprite geSprite-' + prefix + 'openthin';
  940. }
  941. else if (marker == mxConstants.ARROW_BLOCK)
  942. {
  943. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'block' : 'geSprite geSprite-' + prefix + 'blocktrans';
  944. }
  945. else if (marker == mxConstants.ARROW_BLOCK_THIN)
  946. {
  947. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'blockthin' : 'geSprite geSprite-' + prefix + 'blockthintrans';
  948. }
  949. else if (marker == mxConstants.ARROW_OVAL)
  950. {
  951. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'oval' : 'geSprite geSprite-' + prefix + 'ovaltrans';
  952. }
  953. else if (marker == mxConstants.ARROW_DIAMOND)
  954. {
  955. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'diamond' : 'geSprite geSprite-' + prefix + 'diamondtrans';
  956. }
  957. else if (marker == mxConstants.ARROW_DIAMOND_THIN)
  958. {
  959. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'thindiamond' : 'geSprite geSprite-' + prefix + 'thindiamondtrans';
  960. }
  961. else if (marker == 'openAsync')
  962. {
  963. result = 'geSprite geSprite-' + prefix + 'openasync';
  964. }
  965. else if (marker == 'dash')
  966. {
  967. result = 'geSprite geSprite-' + prefix + 'dash';
  968. }
  969. else if (marker == 'cross')
  970. {
  971. result = 'geSprite geSprite-' + prefix + 'cross';
  972. }
  973. else if (marker == 'async')
  974. {
  975. result = (fill == '1') ? 'geSprite geSprite-' + prefix + 'async' : 'geSprite geSprite-' + prefix + 'asynctrans';
  976. }
  977. else if (marker == 'circle' || marker == 'circlePlus')
  978. {
  979. result = (fill == '1' || marker == 'circle') ? 'geSprite geSprite-' + prefix + 'circle' : 'geSprite geSprite-' + prefix + 'circleplus';
  980. }
  981. else if (marker == 'ERone')
  982. {
  983. result = 'geSprite geSprite-' + prefix + 'erone';
  984. }
  985. else if (marker == 'ERmandOne')
  986. {
  987. result = 'geSprite geSprite-' + prefix + 'eronetoone';
  988. }
  989. else if (marker == 'ERmany')
  990. {
  991. result = 'geSprite geSprite-' + prefix + 'ermany';
  992. }
  993. else if (marker == 'ERoneToMany')
  994. {
  995. result = 'geSprite geSprite-' + prefix + 'eronetomany';
  996. }
  997. else if (marker == 'ERzeroToOne')
  998. {
  999. result = 'geSprite geSprite-' + prefix + 'eroneopt';
  1000. }
  1001. else if (marker == 'ERzeroToMany')
  1002. {
  1003. result = 'geSprite geSprite-' + prefix + 'ermanyopt';
  1004. }
  1005. else
  1006. {
  1007. result = 'geSprite geSprite-noarrow';
  1008. }
  1009. }
  1010. return result;
  1011. };
  1012. /**
  1013. * Overridden in Menus.js
  1014. */
  1015. EditorUi.prototype.createMenus = function()
  1016. {
  1017. return null;
  1018. };
  1019. /**
  1020. * Hook for allowing selection and context menu for certain events.
  1021. */
  1022. EditorUi.prototype.updatePasteActionStates = function()
  1023. {
  1024. var graph = this.editor.graph;
  1025. var paste = this.actions.get('paste');
  1026. var pasteHere = this.actions.get('pasteHere');
  1027. paste.setEnabled(this.editor.graph.cellEditor.isContentEditing() || (!mxClipboard.isEmpty() &&
  1028. graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent())));
  1029. pasteHere.setEnabled(paste.isEnabled());
  1030. };
  1031. /**
  1032. * Hook for allowing selection and context menu for certain events.
  1033. */
  1034. EditorUi.prototype.initClipboard = function()
  1035. {
  1036. var ui = this;
  1037. var mxClipboardCut = mxClipboard.cut;
  1038. mxClipboard.cut = function(graph)
  1039. {
  1040. if (graph.cellEditor.isContentEditing())
  1041. {
  1042. document.execCommand('cut', false, null);
  1043. }
  1044. else
  1045. {
  1046. mxClipboardCut.apply(this, arguments);
  1047. }
  1048. ui.updatePasteActionStates();
  1049. };
  1050. var mxClipboardCopy = mxClipboard.copy;
  1051. mxClipboard.copy = function(graph)
  1052. {
  1053. if (graph.cellEditor.isContentEditing())
  1054. {
  1055. document.execCommand('copy', false, null);
  1056. }
  1057. else
  1058. {
  1059. mxClipboardCopy.apply(this, arguments);
  1060. }
  1061. ui.updatePasteActionStates();
  1062. };
  1063. var mxClipboardPaste = mxClipboard.paste;
  1064. mxClipboard.paste = function(graph)
  1065. {
  1066. var result = null;
  1067. if (graph.cellEditor.isContentEditing())
  1068. {
  1069. document.execCommand('paste', false, null);
  1070. }
  1071. else
  1072. {
  1073. result = mxClipboardPaste.apply(this, arguments);
  1074. }
  1075. ui.updatePasteActionStates();
  1076. return result;
  1077. };
  1078. // Overrides cell editor to update paste action state
  1079. var cellEditorStartEditing = this.editor.graph.cellEditor.startEditing;
  1080. this.editor.graph.cellEditor.startEditing = function()
  1081. {
  1082. cellEditorStartEditing.apply(this, arguments);
  1083. ui.updatePasteActionStates();
  1084. };
  1085. var cellEditorStopEditing = this.editor.graph.cellEditor.stopEditing;
  1086. this.editor.graph.cellEditor.stopEditing = function(cell, trigger)
  1087. {
  1088. cellEditorStopEditing.apply(this, arguments);
  1089. ui.updatePasteActionStates();
  1090. };
  1091. this.updatePasteActionStates();
  1092. };
  1093. /**
  1094. * Initializes the infinite canvas.
  1095. */
  1096. EditorUi.prototype.initCanvas = function()
  1097. {
  1098. var graph = this.editor.graph;
  1099. // Initial page layout view, scrollBuffer and timer-based scrolling
  1100. var graph = this.editor.graph;
  1101. graph.timerAutoScroll = true;
  1102. /**
  1103. * Returns the padding for pages in page view with scrollbars.
  1104. */
  1105. graph.getPagePadding = function()
  1106. {
  1107. return new mxPoint(Math.max(0, Math.round((graph.container.offsetWidth - 34) / graph.view.scale)),
  1108. Math.max(0, Math.round((graph.container.offsetHeight - 34) / graph.view.scale)));
  1109. };
  1110. // Fits the number of background pages to the graph
  1111. graph.view.getBackgroundPageBounds = function()
  1112. {
  1113. var layout = this.graph.getPageLayout();
  1114. var page = this.graph.getPageSize();
  1115. return new mxRectangle(this.scale * (this.translate.x + layout.x * page.width),
  1116. this.scale * (this.translate.y + layout.y * page.height),
  1117. this.scale * layout.width * page.width,
  1118. this.scale * layout.height * page.height);
  1119. };
  1120. graph.getPreferredPageSize = function(bounds, width, height)
  1121. {
  1122. var pages = this.getPageLayout();
  1123. var size = this.getPageSize();
  1124. return new mxRectangle(0, 0, pages.width * size.width, pages.height * size.height);
  1125. };
  1126. // Scales pages/graph to fit available size
  1127. var resize = null;
  1128. if (this.editor.chromeless)
  1129. {
  1130. resize = mxUtils.bind(this, function(autoscale, maxScale)
  1131. {
  1132. if (graph.container != null)
  1133. {
  1134. var b = (graph.pageVisible) ? graph.view.getBackgroundPageBounds() : graph.getGraphBounds();
  1135. var tr = graph.view.translate;
  1136. var s = graph.view.scale;
  1137. // Normalizes the bounds
  1138. b = mxRectangle.fromRectangle(b);
  1139. b.x = b.x / s - tr.x;
  1140. b.y = b.y / s - tr.y;
  1141. b.width /= s;
  1142. b.height /= s;
  1143. var st = graph.container.scrollTop;
  1144. var sl = graph.container.scrollLeft;
  1145. var sb = (mxClient.IS_QUIRKS || document.documentMode >= 8) ? 20 : 14;
  1146. if (document.documentMode == 8 || document.documentMode == 9)
  1147. {
  1148. sb += 3;
  1149. }
  1150. var cw = graph.container.offsetWidth - sb;
  1151. var ch = graph.container.offsetHeight - sb;
  1152. var ns = (autoscale) ? Math.max(0.3, Math.min(maxScale || 1, cw / b.width)) : s;
  1153. var dx = Math.max((cw - ns * b.width) / 2, 0) / ns;
  1154. var dy = Math.max((ch - ns * b.height) / 4, 0) / ns;
  1155. graph.view.scaleAndTranslate(ns, dx - b.x, dy - b.y);
  1156. graph.container.scrollTop = st * ns / s;
  1157. graph.container.scrollLeft = sl * ns/ s;
  1158. }
  1159. });
  1160. // Hack to make function available to subclassers
  1161. this.chromelessResize = resize;
  1162. // Removable resize listener
  1163. var autoscaleResize = mxUtils.bind(this, function()
  1164. {
  1165. resize(false);
  1166. });
  1167. mxEvent.addListener(window, 'resize', autoscaleResize);
  1168. this.destroyFunctions.push(function()
  1169. {
  1170. mxEvent.removeListener(window, 'resize', autoscaleResize);
  1171. });
  1172. this.editor.addListener('resetGraphView', mxUtils.bind(this, function()
  1173. {
  1174. resize(true);
  1175. }));
  1176. this.actions.get('zoomIn').funct = function(evt) { graph.zoomIn(); resize(false); };
  1177. this.actions.get('zoomOut').funct = function(evt) { graph.zoomOut(); resize(false); };
  1178. // Creates toolbar for viewer - do not use CSS here
  1179. // as this may be used in a viewer that has no CSS
  1180. this.chromelessToolbar = document.createElement('div');
  1181. this.chromelessToolbar.style.position = 'fixed';
  1182. this.chromelessToolbar.style.overflow = 'hidden';
  1183. this.chromelessToolbar.style.boxSizing = 'border-box';
  1184. this.chromelessToolbar.style.whiteSpace = 'nowrap';
  1185. this.chromelessToolbar.style.backgroundColor = '#000000';
  1186. this.chromelessToolbar.style.padding = '10px 10px 8px 10px';
  1187. this.chromelessToolbar.style.left = '50%';
  1188. if (!mxClient.IS_VML)
  1189. {
  1190. mxUtils.setPrefixedStyle(this.chromelessToolbar.style, 'borderRadius', '20px');
  1191. mxUtils.setPrefixedStyle(this.chromelessToolbar.style, 'transition', 'opacity 600ms ease-in-out');
  1192. }
  1193. var updateChromelessToolbarPosition = mxUtils.bind(this, function()
  1194. {
  1195. var css = mxUtils.getCurrentStyle(graph.container);
  1196. this.chromelessToolbar.style.bottom = ((css != null) ? parseInt(css['margin-bottom'] || 0) : 0) +
  1197. ((this.tabContainer != null) ? (20 + parseInt(this.tabContainer.style.height)) : 20) + 'px';
  1198. });
  1199. this.editor.addListener('resetGraphView', updateChromelessToolbarPosition);
  1200. updateChromelessToolbarPosition();
  1201. var btnCount = 0;
  1202. var addButton = mxUtils.bind(this, function(fn, imgSrc, tip)
  1203. {
  1204. btnCount++;
  1205. var a = document.createElement('span');
  1206. a.style.paddingLeft = '8px';
  1207. a.style.paddingRight = '8px';
  1208. a.style.cursor = 'pointer';
  1209. mxEvent.addListener(a, 'click', fn);
  1210. if (tip != null)
  1211. {
  1212. a.setAttribute('title', tip);
  1213. }
  1214. var img = document.createElement('img');
  1215. img.setAttribute('border', '0');
  1216. img.setAttribute('src', imgSrc);
  1217. a.appendChild(img);
  1218. this.chromelessToolbar.appendChild(a);
  1219. return a;
  1220. });
  1221. var prevButton = addButton(mxUtils.bind(this, function(evt)
  1222. {
  1223. this.actions.get('previousPage').funct();
  1224. mxEvent.consume(evt);
  1225. }), Editor.previousLargeImage, mxResources.get('previousPage'));
  1226. var pageInfo = document.createElement('div');
  1227. pageInfo.style.display = 'inline-block';
  1228. pageInfo.style.verticalAlign = 'top';
  1229. pageInfo.style.fontFamily = 'Helvetica,Arial';
  1230. pageInfo.style.marginTop = '8px';
  1231. pageInfo.style.color = '#ffffff';
  1232. this.chromelessToolbar.appendChild(pageInfo);
  1233. var nextButton = addButton(mxUtils.bind(this, function(evt)
  1234. {
  1235. this.actions.get('nextPage').funct();
  1236. mxEvent.consume(evt);
  1237. }), Editor.nextLargeImage, mxResources.get('nextPage'));
  1238. var updatePageInfo = mxUtils.bind(this, function()
  1239. {
  1240. if (this.pages != null && this.pages.length > 1 && this.currentPage != null)
  1241. {
  1242. pageInfo.innerHTML = '';
  1243. mxUtils.write(pageInfo, (mxUtils.indexOf(this.pages, this.currentPage) + 1) + ' / ' + this.pages.length);
  1244. }
  1245. });
  1246. prevButton.style.paddingLeft = '0px';
  1247. prevButton.style.paddingRight = '4px';
  1248. nextButton.style.paddingLeft = '4px';
  1249. nextButton.style.paddingRight = '0px';
  1250. var updatePageButtons = mxUtils.bind(this, function()
  1251. {
  1252. if (this.pages != null && this.pages.length > 1 && this.currentPage != null)
  1253. {
  1254. nextButton.style.display = '';
  1255. prevButton.style.display = '';
  1256. pageInfo.style.display = 'inline-block';
  1257. }
  1258. else
  1259. {
  1260. nextButton.style.display = 'none';
  1261. prevButton.style.display = 'none';
  1262. pageInfo.style.display = 'none';
  1263. }
  1264. updatePageInfo();
  1265. });
  1266. this.editor.addListener('resetGraphView', updatePageButtons);
  1267. this.editor.addListener('pageSelected', updatePageInfo);
  1268. addButton(mxUtils.bind(this, function(evt)
  1269. {
  1270. this.actions.get('zoomOut').funct();
  1271. mxEvent.consume(evt);
  1272. }), Editor.zoomOutLargeImage, mxResources.get('zoomOut') + ' (Alt+Mousewheel)');
  1273. addButton(mxUtils.bind(this, function(evt)
  1274. {
  1275. this.actions.get('zoomIn').funct();
  1276. mxEvent.consume(evt);
  1277. }), Editor.zoomInLargeImage, mxResources.get('zoomIn') + ' (Alt+Mousewheel)');
  1278. addButton(mxUtils.bind(this, function(evt)
  1279. {
  1280. if (graph.lightbox)
  1281. {
  1282. if (graph.view.scale == 1)
  1283. {
  1284. this.lightboxFit();
  1285. }
  1286. else
  1287. {
  1288. graph.zoomTo(1);
  1289. }
  1290. resize(false);
  1291. }
  1292. else
  1293. {
  1294. resize(true);
  1295. }
  1296. mxEvent.consume(evt);
  1297. }), Editor.actualSizeLargeImage, mxResources.get('fit'));
  1298. // Changes toolbar opacity on hover
  1299. var fadeThread = null;
  1300. var fadeThread2 = null;
  1301. var fadeOut = mxUtils.bind(this, function(delay)
  1302. {
  1303. if (fadeThread != null)
  1304. {
  1305. window.clearTimeout(fadeThread);
  1306. fadeThead = null;
  1307. }
  1308. if (fadeThread2 != null)
  1309. {
  1310. window.clearTimeout(fadeThread2);
  1311. fadeThead2 = null;
  1312. }
  1313. fadeThread = window.setTimeout(mxUtils.bind(this, function()
  1314. {
  1315. mxUtils.setOpacity(this.chromelessToolbar, 0);
  1316. fadeThread = null;
  1317. fadeThread2 = window.setTimeout(mxUtils.bind(this, function()
  1318. {
  1319. this.chromelessToolbar.style.display = 'none';
  1320. fadeThread2 = null;
  1321. }), 600);
  1322. }), delay || 200);
  1323. });
  1324. var fadeIn = mxUtils.bind(this, function(opacity)
  1325. {
  1326. if (fadeThread != null)
  1327. {
  1328. window.clearTimeout(fadeThread);
  1329. fadeThead = null;
  1330. }
  1331. if (fadeThread2 != null)
  1332. {
  1333. window.clearTimeout(fadeThread2);
  1334. fadeThead2 = null;
  1335. }
  1336. this.chromelessToolbar.style.display = '';
  1337. mxUtils.setOpacity(this.chromelessToolbar, opacity || 30);
  1338. });
  1339. if (urlParams['layers'] == '1')
  1340. {
  1341. this.layersDialog = null;
  1342. var layersButton = addButton(mxUtils.bind(this, function(evt)
  1343. {
  1344. if (this.layersDialog != null)
  1345. {
  1346. this.layersDialog.parentNode.removeChild(this.layersDialog);
  1347. this.layersDialog = null;
  1348. }
  1349. else
  1350. {
  1351. this.layersDialog = graph.createLayersDialog();
  1352. mxEvent.addListener(this.layersDialog, 'mouseleave', mxUtils.bind(this, function()
  1353. {
  1354. this.layersDialog.parentNode.removeChild(this.layersDialog);
  1355. this.layersDialog = null;
  1356. }));
  1357. var r = layersButton.getBoundingClientRect();
  1358. mxUtils.setPrefixedStyle(this.layersDialog.style, 'borderRadius', '5px');
  1359. this.layersDialog.style.position = 'fixed';
  1360. this.layersDialog.style.fontFamily = 'Helvetica,Arial';
  1361. this.layersDialog.style.backgroundColor = '#000000';
  1362. this.layersDialog.style.width = '160px';
  1363. this.layersDialog.style.padding = '4px 2px 4px 2px';
  1364. this.layersDialog.style.color = '#ffffff';
  1365. mxUtils.setOpacity(this.layersDialog, 70);
  1366. this.layersDialog.style.left = r.left + 'px';
  1367. this.layersDialog.style.bottom = parseInt(this.chromelessToolbar.style.bottom) +
  1368. this.chromelessToolbar.offsetHeight + 4 + 'px';
  1369. // Puts the dialog on top of the container z-index
  1370. var style = mxUtils.getCurrentStyle(this.editor.graph.container);
  1371. this.layersDialog.style.zIndex = style.zIndex;
  1372. document.body.appendChild(this.layersDialog);
  1373. }
  1374. mxEvent.consume(evt);
  1375. }), Editor.layersLargeImage, mxResources.get('layers'));
  1376. // Shows/hides layers button depending on content
  1377. var model = graph.getModel();
  1378. model.addListener(mxEvent.CHANGE, function()
  1379. {
  1380. layersButton.style.display = (model.getChildCount(model.root) > 1) ? '' : 'none';
  1381. });
  1382. }
  1383. this.addChromelessToolbarItems(addButton);
  1384. if (this.editor.editButtonLink != null)
  1385. {
  1386. addButton(mxUtils.bind(this, function(evt)
  1387. {
  1388. if (this.editor.editButtonLink == '_blank')
  1389. {
  1390. this.editor.editAsNew(this.getEditBlankXml(), null, true);
  1391. }
  1392. else
  1393. {
  1394. window.open(this.editor.editButtonLink, 'editWindow');
  1395. }
  1396. mxEvent.consume(evt);
  1397. }), Editor.editLargeImage, mxResources.get('openInNewWindow'));
  1398. }
  1399. if (graph.lightbox && (urlParams['close'] == '1' || this.container != document.body))
  1400. {
  1401. addButton(mxUtils.bind(this, function(evt)
  1402. {
  1403. if (urlParams['close'] == '1')
  1404. {
  1405. window.close();
  1406. }
  1407. else
  1408. {
  1409. this.destroy();
  1410. mxEvent.consume(evt);
  1411. }
  1412. }), Editor.closeLargeImage, mxResources.get('close') + ' (Escape)');
  1413. }
  1414. // Initial state invisible
  1415. this.chromelessToolbar.style.display = 'none';
  1416. mxUtils.setPrefixedStyle(this.chromelessToolbar.style, 'transform', 'translate(-50%,0)');
  1417. graph.container.appendChild(this.chromelessToolbar);
  1418. // Installs handling of hightligh and handling links to relative links and anchors
  1419. this.addChromelessClickHandler();
  1420. mxEvent.addListener(graph.container, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', mxUtils.bind(this, function(evt)
  1421. {
  1422. if (!mxEvent.isTouchEvent(evt))
  1423. {
  1424. if (!mxEvent.isShiftDown(evt))
  1425. {
  1426. fadeIn(30);
  1427. }
  1428. fadeOut();
  1429. }
  1430. }));
  1431. mxEvent.addListener(this.chromelessToolbar, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', function(evt)
  1432. {
  1433. mxEvent.consume(evt);
  1434. });
  1435. mxEvent.addListener(this.chromelessToolbar, 'mouseenter', mxUtils.bind(this, function(evt)
  1436. {
  1437. if (!mxEvent.isShiftDown(evt))
  1438. {
  1439. fadeIn(100);
  1440. }
  1441. else
  1442. {
  1443. fadeOut();
  1444. }
  1445. }));
  1446. mxEvent.addListener(this.chromelessToolbar, 'mousemove', mxUtils.bind(this, function(evt)
  1447. {
  1448. if (!mxEvent.isShiftDown(evt))
  1449. {
  1450. fadeIn(100);
  1451. }
  1452. else
  1453. {
  1454. fadeOut();
  1455. }
  1456. mxEvent.consume(evt);
  1457. }));
  1458. mxEvent.addListener(this.chromelessToolbar, 'mouseleave', mxUtils.bind(this, function(evt)
  1459. {
  1460. if (!mxEvent.isTouchEvent(evt))
  1461. {
  1462. fadeIn(30);
  1463. }
  1464. }));
  1465. // Shows/hides toolbar for touch devices
  1466. var tol = graph.getTolerance();
  1467. var ui = this;
  1468. graph.addMouseListener(
  1469. {
  1470. startX: 0,
  1471. startY: 0,
  1472. scrollLeft: 0,
  1473. scrollTop: 0,
  1474. mouseDown: function(sender, me)
  1475. {
  1476. this.startX = me.getGraphX();
  1477. this.startY = me.getGraphY();
  1478. this.scrollLeft = graph.container.scrollLeft;
  1479. this.scrollTop = graph.container.scrollTop;
  1480. },
  1481. mouseMove: function(sender, me) {},
  1482. mouseUp: function(sender, me)
  1483. {
  1484. if (mxEvent.isTouchEvent(me.getEvent()))
  1485. {
  1486. if ((Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  1487. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  1488. (Math.abs(this.startX - me.getGraphX()) < tol &&
  1489. Math.abs(this.startY - me.getGraphY()) < tol))
  1490. {
  1491. if (parseFloat(ui.chromelessToolbar.style.opacity || 0) > 0)
  1492. {
  1493. fadeOut();
  1494. }
  1495. else
  1496. {
  1497. fadeIn(30);
  1498. }
  1499. }
  1500. }
  1501. }
  1502. });
  1503. }
  1504. else if (this.editor.extendCanvas)
  1505. {
  1506. /**
  1507. * Guesses autoTranslate to avoid another repaint (see below).
  1508. * Works if only the scale of the graph changes or if pages
  1509. * are visible and the visible pages do not change.
  1510. */
  1511. var graphViewValidate = graph.view.validate;
  1512. graph.view.validate = function()
  1513. {
  1514. if (this.graph.container != null && mxUtils.hasScrollbars(this.graph.container))
  1515. {
  1516. var pad = this.graph.getPagePadding();
  1517. var size = this.graph.getPageSize();
  1518. // Updating scrollbars here causes flickering in quirks and is not needed
  1519. // if zoom method is always used to set the current scale on the graph.
  1520. var tx = this.translate.x;
  1521. var ty = this.translate.y;
  1522. this.translate.x = pad.x - (this.x0 || 0) * size.width;
  1523. this.translate.y = pad.y - (this.y0 || 0) * size.height;
  1524. }
  1525. graphViewValidate.apply(this, arguments);
  1526. };
  1527. var graphSizeDidChange = graph.sizeDidChange;
  1528. graph.sizeDidChange = function()
  1529. {
  1530. if (this.container != null && mxUtils.hasScrollbars(this.container))
  1531. {
  1532. var pages = this.getPageLayout();
  1533. var pad = this.getPagePadding();
  1534. var size = this.getPageSize();
  1535. // Updates the minimum graph size
  1536. var minw = Math.ceil(2 * pad.x + pages.width * size.width);
  1537. var minh = Math.ceil(2 * pad.y + pages.height * size.height);
  1538. var min = graph.minimumGraphSize;
  1539. // LATER: Fix flicker of scrollbar size in IE quirks mode
  1540. // after delayed call in window.resize event handler
  1541. if (min == null || min.width != minw || min.height != minh)
  1542. {
  1543. graph.minimumGraphSize = new mxRectangle(0, 0, minw, minh);
  1544. }
  1545. // Updates auto-translate to include padding and graph size
  1546. var dx = pad.x - pages.x * size.width;
  1547. var dy = pad.y - pages.y * size.height;
  1548. if (!this.autoTranslate && (this.view.translate.x != dx || this.view.translate.y != dy))
  1549. {
  1550. this.autoTranslate = true;
  1551. this.view.x0 = pages.x;
  1552. this.view.y0 = pages.y;
  1553. // NOTE: THIS INVOKES THIS METHOD AGAIN. UNFORTUNATELY THERE IS NO WAY AROUND THIS SINCE THE
  1554. // BOUNDS ARE KNOWN AFTER THE VALIDATION AND SETTING THE TRANSLATE TRIGGERS A REVALIDATION.
  1555. // SHOULD MOVE TRANSLATE/SCALE TO VIEW.
  1556. var tx = graph.view.translate.x;
  1557. var ty = graph.view.translate.y;
  1558. graph.view.setTranslate(dx, dy);
  1559. // LATER: Fix rounding errors for small zoom
  1560. graph.container.scrollLeft += Math.round((dx - tx) * graph.view.scale);
  1561. graph.container.scrollTop += Math.round((dy - ty) * graph.view.scale);
  1562. this.autoTranslate = false;
  1563. return;
  1564. }
  1565. graphSizeDidChange.apply(this, arguments);
  1566. }
  1567. };
  1568. }
  1569. // Accumulates the zoom factor while the rendering is taking place
  1570. // so that not the complete sequence of zoom steps must be painted
  1571. graph.updateZoomTimeout = null;
  1572. graph.cumulativeZoomFactor = 1;
  1573. var cursorPosition = null;
  1574. graph.lazyZoom = function(zoomIn)
  1575. {
  1576. if (this.updateZoomTimeout != null)
  1577. {
  1578. window.clearTimeout(this.updateZoomTimeout);
  1579. }
  1580. // Switches to 1% zoom steps below 15%
  1581. // Lower bound depdends on rounding below
  1582. if (zoomIn)
  1583. {
  1584. if (this.view.scale * this.cumulativeZoomFactor < 0.15)
  1585. {
  1586. this.cumulativeZoomFactor = (this.view.scale + 0.01) / this.view.scale;
  1587. }
  1588. else
  1589. {
  1590. // Uses to 5% zoom steps for better grid rendering in webkit
  1591. // and to avoid rounding errors for zoom steps
  1592. this.cumulativeZoomFactor *= this.zoomFactor;
  1593. this.cumulativeZoomFactor = Math.round(this.view.scale * this.cumulativeZoomFactor * 20) / 20 / this.view.scale;
  1594. }
  1595. }
  1596. else
  1597. {
  1598. if (this.view.scale * this.cumulativeZoomFactor <= 0.15)
  1599. {
  1600. this.cumulativeZoomFactor = (this.view.scale - 0.01) / this.view.scale;
  1601. }
  1602. else
  1603. {
  1604. // Uses to 5% zoom steps for better grid rendering in webkit
  1605. // and to avoid rounding errors for zoom steps
  1606. this.cumulativeZoomFactor /= this.zoomFactor;
  1607. this.cumulativeZoomFactor = Math.round(this.view.scale * this.cumulativeZoomFactor * 20) / 20 / this.view.scale;
  1608. }
  1609. }
  1610. this.cumulativeZoomFactor = Math.max(0.01, Math.min(this.view.scale * this.cumulativeZoomFactor, 160) / this.view.scale);
  1611. this.updateZoomTimeout = window.setTimeout(mxUtils.bind(this, function()
  1612. {
  1613. this.zoom(this.cumulativeZoomFactor);
  1614. if (resize != null)
  1615. {
  1616. resize(false);
  1617. }
  1618. // Zooms to mouse position if scrollbars enabled
  1619. if (cursorPosition != null && mxUtils.hasScrollbars(graph.container))
  1620. {
  1621. var offset = mxUtils.getOffset(graph.container);
  1622. var dx = graph.container.offsetWidth / 2 - cursorPosition.x + offset.x;
  1623. var dy = graph.container.offsetHeight / 2 - cursorPosition.y + offset.y;
  1624. graph.container.scrollLeft -= dx * (this.cumulativeZoomFactor - 1);
  1625. graph.container.scrollTop -= dy * (this.cumulativeZoomFactor - 1);
  1626. }
  1627. this.cumulativeZoomFactor = 1;
  1628. this.updateZoomTimeout = null;
  1629. }), 20);
  1630. };
  1631. mxEvent.addMouseWheelListener(mxUtils.bind(this, function(evt, up)
  1632. {
  1633. // Ctrl+wheel (or pinch on touchpad) is a native browser zoom event is OS X
  1634. // LATER: Add support for zoom via pinch on trackpad for Chrome in OS X
  1635. if ((mxEvent.isAltDown(evt) || (mxEvent.isControlDown(evt) && !mxClient.IS_MAC) ||
  1636. graph.panningHandler.isActive()) && (this.dialogs == null || this.dialogs.length == 0))
  1637. {
  1638. var source = mxEvent.getSource(evt);
  1639. while (source != null)
  1640. {
  1641. if (source == graph.container)
  1642. {
  1643. cursorPosition = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  1644. graph.lazyZoom(up);
  1645. mxEvent.consume(evt);
  1646. return;
  1647. }
  1648. source = source.parentNode;
  1649. }
  1650. }
  1651. }));
  1652. };
  1653. /**
  1654. * Creates a temporary graph instance for rendering off-screen content.
  1655. */
  1656. EditorUi.prototype.addChromelessToolbarItems = function(addButton)
  1657. {
  1658. addButton(mxUtils.bind(this, function(evt)
  1659. {
  1660. this.actions.get('print').funct();
  1661. mxEvent.consume(evt);
  1662. }), Editor.printLargeImage, mxResources.get('print'));
  1663. };
  1664. /**
  1665. * Creates a temporary graph instance for rendering off-screen content.
  1666. */
  1667. EditorUi.prototype.createTemporaryGraph = function(stylesheet)
  1668. {
  1669. var graph = new Graph(document.createElement('div'), null, null, stylesheet);
  1670. graph.resetViewOnRootChange = false;
  1671. graph.setConnectable(false);
  1672. graph.gridEnabled = false;
  1673. graph.autoScroll = false;
  1674. graph.setTooltips(false);
  1675. graph.setEnabled(false);
  1676. // Container must be in the DOM for correct HTML rendering
  1677. graph.container.style.visibility = 'hidden';
  1678. graph.container.style.position = 'absolute';
  1679. graph.container.style.overflow = 'hidden';
  1680. graph.container.style.height = '1px';
  1681. graph.container.style.width = '1px';
  1682. return graph;
  1683. };
  1684. /**
  1685. *
  1686. */
  1687. EditorUi.prototype.addChromelessClickHandler = function()
  1688. {
  1689. var hl = urlParams['highlight'];
  1690. // Adds leading # for highlight color code
  1691. if (hl != null && hl.length > 0)
  1692. {
  1693. hl = '#' + hl;
  1694. }
  1695. this.editor.graph.addClickHandler(hl);
  1696. };
  1697. /**
  1698. *
  1699. */
  1700. EditorUi.prototype.toggleFormatPanel = function(forceHide)
  1701. {
  1702. this.formatWidth = (forceHide || this.formatWidth > 0) ? 0 : 240;
  1703. this.formatContainer.style.display = (forceHide || this.formatWidth > 0) ? '' : 'none';
  1704. this.refresh();
  1705. this.format.refresh();
  1706. this.fireEvent(new mxEventObject('formatWidthChanged'));
  1707. };
  1708. /**
  1709. * Adds support for placeholders in labels.
  1710. */
  1711. EditorUi.prototype.lightboxFit = function()
  1712. {
  1713. // LATER: Use initial graph bounds to avoid rounding errors
  1714. this.editor.graph.maxFitScale = 2;
  1715. this.editor.graph.fit(60);
  1716. this.editor.graph.maxFitScale = null;
  1717. };
  1718. /**
  1719. * Hook for allowing selection and context menu for certain events.
  1720. */
  1721. EditorUi.prototype.isSelectionAllowed = function(evt)
  1722. {
  1723. return mxEvent.getSource(evt).nodeName == 'SELECT' || (mxEvent.getSource(evt).nodeName == 'INPUT' &&
  1724. mxUtils.isAncestorNode(this.formatContainer, mxEvent.getSource(evt)));
  1725. };
  1726. /**
  1727. * Installs dialog if browser window is closed without saving
  1728. * This must be disabled during save and image export.
  1729. */
  1730. EditorUi.prototype.addBeforeUnloadListener = function()
  1731. {
  1732. // Installs dialog if browser window is closed without saving
  1733. // This must be disabled during save and image export
  1734. window.onbeforeunload = mxUtils.bind(this, function()
  1735. {
  1736. if (!this.editor.chromeless)
  1737. {
  1738. return this.onBeforeUnload();
  1739. }
  1740. });
  1741. };
  1742. /**
  1743. * Sets the onbeforeunload for the application
  1744. */
  1745. EditorUi.prototype.onBeforeUnload = function()
  1746. {
  1747. if (this.editor.modified)
  1748. {
  1749. return mxResources.get('allChangesLost');
  1750. }
  1751. };
  1752. /**
  1753. * Opens the current diagram via the window.opener if one exists.
  1754. */
  1755. EditorUi.prototype.open = function()
  1756. {
  1757. // Cross-domain window access is not allowed in FF, so if we
  1758. // were opened from another domain then this will fail.
  1759. try
  1760. {
  1761. if (window.opener != null && window.opener.openFile != null)
  1762. {
  1763. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  1764. {
  1765. try
  1766. {
  1767. var doc = mxUtils.parseXml(xml);
  1768. this.editor.setGraphXml(doc.documentElement);
  1769. this.editor.setModified(false);
  1770. this.editor.undoManager.clear();
  1771. if (filename != null)
  1772. {
  1773. this.editor.setFilename(filename);
  1774. this.updateDocumentTitle();
  1775. }
  1776. return;
  1777. }
  1778. catch (e)
  1779. {
  1780. mxUtils.alert(mxResources.get('invalidOrMissingFile') + ': ' + e.message);
  1781. }
  1782. }));
  1783. }
  1784. }
  1785. catch(e)
  1786. {
  1787. // ignore
  1788. }
  1789. // Fires as the last step if no file was loaded
  1790. this.editor.graph.view.validate();
  1791. // Required only in special cases where an initial file is opened
  1792. // and the minimumGraphSize changes and CSS must be updated.
  1793. this.editor.graph.sizeDidChange();
  1794. this.editor.fireEvent(new mxEventObject('resetGraphView'));
  1795. };
  1796. /**
  1797. * Sets the current menu and element.
  1798. */
  1799. EditorUi.prototype.setCurrentMenu = function(menu, elt)
  1800. {
  1801. this.currentMenuElt = elt;
  1802. this.currentMenu = menu;
  1803. };
  1804. /**
  1805. * Resets the current menu and element.
  1806. */
  1807. EditorUi.prototype.resetCurrentMenu = function()
  1808. {
  1809. this.currentMenuElt = null;
  1810. this.currentMenu = null;
  1811. };
  1812. /**
  1813. * Hides and destroys the current menu.
  1814. */
  1815. EditorUi.prototype.hideCurrentMenu = function(menu, elt)
  1816. {
  1817. if (this.currentMenu != null)
  1818. {
  1819. this.currentMenu.hideMenu();
  1820. this.resetCurrentMenu();
  1821. }
  1822. };
  1823. /**
  1824. * Updates the document title.
  1825. */
  1826. EditorUi.prototype.updateDocumentTitle = function()
  1827. {
  1828. var title = this.editor.getOrCreateFilename();
  1829. if (this.editor.appName != null)
  1830. {
  1831. title += ' - ' + this.editor.appName;
  1832. }
  1833. document.title = title;
  1834. };
  1835. /**
  1836. * Updates the document title.
  1837. */
  1838. EditorUi.prototype.createHoverIcons = function()
  1839. {
  1840. return new HoverIcons(this.editor.graph);
  1841. };
  1842. /**
  1843. * Returns the URL for a copy of this editor with no state.
  1844. */
  1845. EditorUi.prototype.redo = function()
  1846. {
  1847. try
  1848. {
  1849. var graph = this.editor.graph;
  1850. if (graph.isEditing())
  1851. {
  1852. document.execCommand('redo', false, null);
  1853. }
  1854. else
  1855. {
  1856. this.editor.undoManager.redo();
  1857. }
  1858. }
  1859. catch (e)
  1860. {
  1861. // ignore all errors
  1862. }
  1863. };
  1864. /**
  1865. * Returns the URL for a copy of this editor with no state.
  1866. */
  1867. EditorUi.prototype.undo = function()
  1868. {
  1869. try
  1870. {
  1871. var graph = this.editor.graph;
  1872. if (graph.isEditing())
  1873. {
  1874. // Stops editing and executes undo on graph if native undo
  1875. // does not affect current editing value
  1876. var value = graph.cellEditor.textarea.innerHTML;
  1877. document.execCommand('undo', false, null);
  1878. if (value == graph.cellEditor.textarea.innerHTML)
  1879. {
  1880. graph.stopEditing(true);
  1881. this.editor.undoManager.undo();
  1882. }
  1883. }
  1884. else
  1885. {
  1886. this.editor.undoManager.undo();
  1887. }
  1888. }
  1889. catch (e)
  1890. {
  1891. // ignore all errors
  1892. }
  1893. };
  1894. /**
  1895. * Returns the URL for a copy of this editor with no state.
  1896. */
  1897. EditorUi.prototype.canRedo = function()
  1898. {
  1899. return this.editor.graph.isEditing() || this.editor.undoManager.canRedo();
  1900. };
  1901. /**
  1902. * Returns the URL for a copy of this editor with no state.
  1903. */
  1904. EditorUi.prototype.canUndo = function()
  1905. {
  1906. return this.editor.graph.isEditing() || this.editor.undoManager.canUndo();
  1907. };
  1908. /**
  1909. *
  1910. */
  1911. EditorUi.prototype.getEditBlankXml = function()
  1912. {
  1913. return mxUtils.getXml(this.getGraphXml());
  1914. };
  1915. /**
  1916. * Returns the URL for a copy of this editor with no state.
  1917. */
  1918. EditorUi.prototype.getUrl = function(pathname)
  1919. {
  1920. var href = (pathname != null) ? pathname : window.location.pathname;
  1921. var parms = (href.indexOf('?') > 0) ? 1 : 0;
  1922. // Removes template URL parameter for new blank diagram
  1923. for (var key in urlParams)
  1924. {
  1925. if (parms == 0)
  1926. {
  1927. href += '?';
  1928. }
  1929. else
  1930. {
  1931. href += '&';
  1932. }
  1933. href += key + '=' + urlParams[key];
  1934. parms++;
  1935. }
  1936. return href;
  1937. };
  1938. /**
  1939. * Specifies if the graph has scrollbars.
  1940. */
  1941. EditorUi.prototype.setScrollbars = function(value)
  1942. {
  1943. var graph = this.editor.graph;
  1944. var prev = graph.container.style.overflow;
  1945. graph.scrollbars = value;
  1946. this.editor.updateGraphComponents();
  1947. if (prev != graph.container.style.overflow)
  1948. {
  1949. if (graph.container.style.overflow == 'hidden')
  1950. {
  1951. var t = graph.view.translate;
  1952. graph.view.setTranslate(t.x - graph.container.scrollLeft / graph.view.scale, t.y - graph.container.scrollTop / graph.view.scale);
  1953. graph.container.scrollLeft = 0;
  1954. graph.container.scrollTop = 0;
  1955. graph.minimumGraphSize = null;
  1956. graph.sizeDidChange();
  1957. }
  1958. else
  1959. {
  1960. var dx = graph.view.translate.x;
  1961. var dy = graph.view.translate.y;
  1962. graph.view.translate.x = 0;
  1963. graph.view.translate.y = 0;
  1964. graph.sizeDidChange();
  1965. graph.container.scrollLeft -= Math.round(dx * graph.view.scale);
  1966. graph.container.scrollTop -= Math.round(dy * graph.view.scale);
  1967. }
  1968. }
  1969. this.fireEvent(new mxEventObject('scrollbarsChanged'));
  1970. };
  1971. /**
  1972. * Returns true if the graph has scrollbars.
  1973. */
  1974. EditorUi.prototype.hasScrollbars = function()
  1975. {
  1976. return this.editor.graph.scrollbars;
  1977. };
  1978. /**
  1979. * Resets the state of the scrollbars.
  1980. */
  1981. EditorUi.prototype.resetScrollbars = function()
  1982. {
  1983. var graph = this.editor.graph;
  1984. if (!this.editor.extendCanvas)
  1985. {
  1986. graph.container.scrollTop = 0;
  1987. graph.container.scrollLeft = 0;
  1988. if (!mxUtils.hasScrollbars(graph.container))
  1989. {
  1990. graph.view.setTranslate(0, 0);
  1991. }
  1992. }
  1993. else if (!this.editor.chromeless)
  1994. {
  1995. if (mxUtils.hasScrollbars(graph.container))
  1996. {
  1997. if (graph.pageVisible)
  1998. {
  1999. var pad = graph.getPagePadding();
  2000. graph.container.scrollTop = Math.floor(pad.y - this.editor.initialTopSpacing);
  2001. graph.container.scrollLeft = Math.floor(Math.min(pad.x, (graph.container.scrollWidth - graph.container.clientWidth) / 2));
  2002. // Scrolls graph to visible area
  2003. var bounds = graph.getGraphBounds();
  2004. if (bounds.width > 0 && bounds.height > 0)
  2005. {
  2006. if (bounds.x > graph.container.scrollLeft + graph.container.clientWidth * 0.9)
  2007. {
  2008. graph.container.scrollLeft = Math.min(bounds.x + bounds.width - graph.container.clientWidth, bounds.x - 10);
  2009. }
  2010. if (bounds.y > graph.container.scrollTop + graph.container.clientHeight * 0.9)
  2011. {
  2012. graph.container.scrollTop = Math.min(bounds.y + bounds.height - graph.container.clientHeight, bounds.y - 10);
  2013. }
  2014. }
  2015. }
  2016. else
  2017. {
  2018. var bounds = graph.getGraphBounds();
  2019. var width = Math.max(bounds.width, graph.scrollTileSize.width * graph.view.scale);
  2020. var height = Math.max(bounds.height, graph.scrollTileSize.height * graph.view.scale);
  2021. graph.container.scrollTop = Math.floor(Math.max(0, bounds.y - Math.max(20, (graph.container.clientHeight - height) / 4)));
  2022. graph.container.scrollLeft = Math.floor(Math.max(0, bounds.x - Math.max(0, (graph.container.clientWidth - width) / 2)));
  2023. }
  2024. }
  2025. else
  2026. {
  2027. // This code is not actively used since the default for scrollbars is always true
  2028. if (graph.pageVisible)
  2029. {
  2030. var b = graph.view.getBackgroundPageBounds();
  2031. graph.view.setTranslate(Math.floor(Math.max(0, (graph.container.clientWidth - b.width) / 2) - b.x),
  2032. Math.floor(Math.max(0, (graph.container.clientHeight - b.height) / 2) - b.y));
  2033. }
  2034. else
  2035. {
  2036. var bounds = graph.getGraphBounds();
  2037. graph.view.setTranslate(Math.floor(Math.max(0, Math.max(0, (graph.container.clientWidth - bounds.width) / 2) - bounds.x)),
  2038. Math.floor(Math.max(0, Math.max(20, (graph.container.clientHeight - bounds.height) / 4)) - bounds.y));
  2039. }
  2040. }
  2041. }
  2042. };
  2043. /**
  2044. * Loads the stylesheet for this graph.
  2045. */
  2046. EditorUi.prototype.setPageVisible = function(value)
  2047. {
  2048. var graph = this.editor.graph;
  2049. var hasScrollbars = mxUtils.hasScrollbars(graph.container);
  2050. var tx = 0;
  2051. var ty = 0;
  2052. if (hasScrollbars)
  2053. {
  2054. tx = graph.view.translate.x * graph.view.scale - graph.container.scrollLeft;
  2055. ty = graph.view.translate.y * graph.view.scale - graph.container.scrollTop;
  2056. }
  2057. graph.pageVisible = value;
  2058. graph.pageBreaksVisible = value;
  2059. graph.preferPageSize = value;
  2060. graph.view.validateBackground();
  2061. // Workaround for possible handle offset
  2062. if (hasScrollbars)
  2063. {
  2064. var cells = graph.getSelectionCells();
  2065. graph.clearSelection();
  2066. graph.setSelectionCells(cells);
  2067. }
  2068. // Calls updatePageBreaks
  2069. graph.sizeDidChange();
  2070. if (hasScrollbars)
  2071. {
  2072. graph.container.scrollLeft = graph.view.translate.x * graph.view.scale - tx;
  2073. graph.container.scrollTop = graph.view.translate.y * graph.view.scale - ty;
  2074. }
  2075. this.fireEvent(new mxEventObject('pageViewChanged'));
  2076. };
  2077. /**
  2078. * Change types
  2079. */
  2080. function ChangePageSetup(ui, color, image, format)
  2081. {
  2082. this.ui = ui;
  2083. this.previousColor = color;
  2084. this.previousImage = image;
  2085. this.previousFormat = format;
  2086. // Needed since null are valid values for color and image
  2087. this.ignoreColor = false;
  2088. this.ignoreImage = false;
  2089. }
  2090. /**
  2091. * Implementation of the undoable page rename.
  2092. */
  2093. ChangePageSetup.prototype.execute = function()
  2094. {
  2095. var graph = this.ui.editor.graph;
  2096. if (!this.ignoreColor)
  2097. {
  2098. var tmp = graph.background;
  2099. this.ui.setBackgroundColor(this.previousColor);
  2100. this.previousColor = tmp;
  2101. }
  2102. if (!this.ignoreImage)
  2103. {
  2104. var tmp = graph.backgroundImage;
  2105. this.ui.setBackgroundImage(this.previousImage);
  2106. this.previousImage = tmp;
  2107. }
  2108. if (this.previousFormat != null)
  2109. {
  2110. var tmp = graph.pageFormat;
  2111. if (this.previousFormat.width != tmp.width ||
  2112. this.previousFormat.height != tmp.height)
  2113. {
  2114. this.ui.setPageFormat(this.previousFormat);
  2115. this.previousFormat = tmp;
  2116. }
  2117. }
  2118. };
  2119. /**
  2120. * Loads the stylesheet for this graph.
  2121. */
  2122. EditorUi.prototype.setBackgroundColor = function(value)
  2123. {
  2124. this.editor.graph.background = value;
  2125. this.editor.graph.view.validateBackground();
  2126. this.fireEvent(new mxEventObject('backgroundColorChanged'));
  2127. };
  2128. /**
  2129. * Loads the stylesheet for this graph.
  2130. */
  2131. EditorUi.prototype.setFoldingEnabled = function(value)
  2132. {
  2133. this.editor.graph.foldingEnabled = value;
  2134. this.editor.graph.view.revalidate();
  2135. this.fireEvent(new mxEventObject('foldingEnabledChanged'));
  2136. };
  2137. /**
  2138. * Loads the stylesheet for this graph.
  2139. */
  2140. EditorUi.prototype.setPageFormat = function(value)
  2141. {
  2142. this.editor.graph.pageFormat = value;
  2143. if (!this.editor.graph.pageVisible)
  2144. {
  2145. this.actions.get('pageView').funct();
  2146. }
  2147. else
  2148. {
  2149. this.editor.graph.view.validateBackground();
  2150. this.editor.graph.sizeDidChange();
  2151. }
  2152. this.fireEvent(new mxEventObject('pageFormatChanged'));
  2153. };
  2154. /**
  2155. * Loads the stylesheet for this graph.
  2156. */
  2157. EditorUi.prototype.setPageScale = function(value)
  2158. {
  2159. this.editor.graph.pageScale = value;
  2160. if (!this.editor.graph.pageVisible)
  2161. {
  2162. this.actions.get('pageView').funct();
  2163. }
  2164. else
  2165. {
  2166. this.editor.graph.view.validateBackground();
  2167. this.editor.graph.sizeDidChange();
  2168. }
  2169. this.fireEvent(new mxEventObject('pageScaleChanged'));
  2170. };
  2171. /**
  2172. * Loads the stylesheet for this graph.
  2173. */
  2174. EditorUi.prototype.setGridColor = function(value)
  2175. {
  2176. this.editor.graph.view.gridColor = value;
  2177. this.editor.graph.view.validateBackground();
  2178. this.fireEvent(new mxEventObject('gridColorChanged'));
  2179. };
  2180. /**
  2181. * Updates the states of the given undo/redo items.
  2182. */
  2183. EditorUi.prototype.addUndoListener = function()
  2184. {
  2185. var undo = this.actions.get('undo');
  2186. var redo = this.actions.get('redo');
  2187. var undoMgr = this.editor.undoManager;
  2188. var undoListener = mxUtils.bind(this, function()
  2189. {
  2190. undo.setEnabled(this.canUndo());
  2191. redo.setEnabled(this.canRedo());
  2192. });
  2193. undoMgr.addListener(mxEvent.ADD, undoListener);
  2194. undoMgr.addListener(mxEvent.UNDO, undoListener);
  2195. undoMgr.addListener(mxEvent.REDO, undoListener);
  2196. undoMgr.addListener(mxEvent.CLEAR, undoListener);
  2197. // Overrides cell editor to update action states
  2198. var cellEditorStartEditing = this.editor.graph.cellEditor.startEditing;
  2199. this.editor.graph.cellEditor.startEditing = function()
  2200. {
  2201. cellEditorStartEditing.apply(this, arguments);
  2202. undoListener();
  2203. };
  2204. var cellEditorStopEditing = this.editor.graph.cellEditor.stopEditing;
  2205. this.editor.graph.cellEditor.stopEditing = function(cell, trigger)
  2206. {
  2207. cellEditorStopEditing.apply(this, arguments);
  2208. undoListener();
  2209. };
  2210. // Updates the button states once
  2211. undoListener();
  2212. };
  2213. /**
  2214. * Updates the states of the given toolbar items based on the selection.
  2215. */
  2216. EditorUi.prototype.updateActionStates = function()
  2217. {
  2218. var graph = this.editor.graph;
  2219. var selected = !graph.isSelectionEmpty();
  2220. var vertexSelected = false;
  2221. var edgeSelected = false;
  2222. var cells = graph.getSelectionCells();
  2223. if (cells != null)
  2224. {
  2225. for (var i = 0; i < cells.length; i++)
  2226. {
  2227. var cell = cells[i];
  2228. if (graph.getModel().isEdge(cell))
  2229. {
  2230. edgeSelected = true;
  2231. }
  2232. if (graph.getModel().isVertex(cell))
  2233. {
  2234. vertexSelected = true;
  2235. }
  2236. if (edgeSelected && vertexSelected)
  2237. {
  2238. break;
  2239. }
  2240. }
  2241. }
  2242. // Updates action states
  2243. var actions = ['cut', 'copy', 'bold', 'italic', 'underline', 'delete', 'duplicate',
  2244. 'editStyle', 'editTooltip', 'editLink', 'backgroundColor', 'borderColor',
  2245. 'edit', 'toFront', 'toBack', 'lockUnlock', 'solid', 'dashed',
  2246. 'dotted', 'fillColor', 'gradientColor', 'shadow', 'fontColor',
  2247. 'formattedText', 'rounded', 'toggleRounded', 'sharp', 'strokeColor'];
  2248. for (var i = 0; i < actions.length; i++)
  2249. {
  2250. this.actions.get(actions[i]).setEnabled(selected);
  2251. }
  2252. this.actions.get('setAsDefaultStyle').setEnabled(graph.getSelectionCount() == 1);
  2253. this.actions.get('clearWaypoints').setEnabled(!graph.isSelectionEmpty());
  2254. this.actions.get('turn').setEnabled(!graph.isSelectionEmpty());
  2255. this.actions.get('curved').setEnabled(edgeSelected);
  2256. this.actions.get('rotation').setEnabled(vertexSelected);
  2257. this.actions.get('wordWrap').setEnabled(vertexSelected);
  2258. this.actions.get('autosize').setEnabled(vertexSelected);
  2259. var oneVertexSelected = vertexSelected && graph.getSelectionCount() == 1;
  2260. this.actions.get('group').setEnabled(graph.getSelectionCount() > 1 ||
  2261. (oneVertexSelected && !graph.isContainer(graph.getSelectionCell())));
  2262. this.actions.get('ungroup').setEnabled(graph.getSelectionCount() == 1 &&
  2263. (graph.getModel().getChildCount(graph.getSelectionCell()) > 0 ||
  2264. (oneVertexSelected && graph.isContainer(graph.getSelectionCell()))));
  2265. this.actions.get('removeFromGroup').setEnabled(oneVertexSelected &&
  2266. graph.getModel().isVertex(graph.getModel().getParent(graph.getSelectionCell())));
  2267. // Updates menu states
  2268. var state = graph.view.getState(graph.getSelectionCell());
  2269. this.menus.get('navigation').setEnabled(selected || graph.view.currentRoot != null);
  2270. this.actions.get('collapsible').setEnabled(vertexSelected &&
  2271. (graph.isContainer(graph.getSelectionCell()) || graph.model.getChildCount(graph.getSelectionCell()) > 0));
  2272. this.actions.get('home').setEnabled(graph.view.currentRoot != null);
  2273. this.actions.get('exitGroup').setEnabled(graph.view.currentRoot != null);
  2274. this.actions.get('enterGroup').setEnabled(graph.getSelectionCount() == 1 && graph.isValidRoot(graph.getSelectionCell()));
  2275. var foldable = graph.getSelectionCount() == 1 && graph.isCellFoldable(graph.getSelectionCell())
  2276. this.actions.get('expand').setEnabled(foldable);
  2277. this.actions.get('collapse').setEnabled(foldable);
  2278. this.actions.get('editLink').setEnabled(graph.getSelectionCount() == 1);
  2279. this.actions.get('openLink').setEnabled(graph.getSelectionCount() == 1 &&
  2280. graph.getLinkForCell(graph.getSelectionCell()) != null);
  2281. this.actions.get('guides').setEnabled(graph.isEnabled());
  2282. this.actions.get('grid').setEnabled(!this.editor.chromeless);
  2283. var unlocked = graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent());
  2284. this.menus.get('layout').setEnabled(unlocked);
  2285. this.menus.get('insert').setEnabled(unlocked);
  2286. this.menus.get('direction').setEnabled(unlocked && vertexSelected);
  2287. this.menus.get('align').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2288. this.menus.get('distribute').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2289. this.actions.get('selectVertices').setEnabled(unlocked);
  2290. this.actions.get('selectEdges').setEnabled(unlocked);
  2291. this.actions.get('selectAll').setEnabled(unlocked);
  2292. this.actions.get('selectNone').setEnabled(unlocked);
  2293. this.updatePasteActionStates();
  2294. };
  2295. /**
  2296. * Refreshes the viewport.
  2297. */
  2298. EditorUi.prototype.refresh = function(sizeDidChange)
  2299. {
  2300. sizeDidChange = (sizeDidChange != null) ? sizeDidChange : true;
  2301. var quirks = mxClient.IS_IE && (document.documentMode == null || document.documentMode == 5);
  2302. var w = this.container.clientWidth;
  2303. var h = this.container.clientHeight;
  2304. if (this.container == document.body)
  2305. {
  2306. w = document.body.clientWidth || document.documentElement.clientWidth;
  2307. h = (quirks) ? document.body.clientHeight || document.documentElement.clientHeight : document.documentElement.clientHeight;
  2308. }
  2309. // Workaround for bug on iOS see
  2310. // http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
  2311. // FIXME: Fix if footer visible
  2312. var off = 0;
  2313. if (mxClient.IS_IOS && !window.navigator.standalone)
  2314. {
  2315. if (window.innerHeight != document.documentElement.clientHeight)
  2316. {
  2317. off = document.documentElement.clientHeight - window.innerHeight;
  2318. window.scrollTo(0, 0);
  2319. }
  2320. }
  2321. var effHsplitPosition = Math.max(0, Math.min(this.hsplitPosition, w - this.splitSize - 20));
  2322. var tmp = 0;
  2323. if (this.menubar != null)
  2324. {
  2325. this.menubarContainer.style.height = this.menubarHeight + 'px';
  2326. tmp += this.menubarHeight;
  2327. }
  2328. if (this.toolbar != null)
  2329. {
  2330. this.toolbarContainer.style.top = this.menubarHeight + 'px';
  2331. this.toolbarContainer.style.height = this.toolbarHeight + 'px';
  2332. tmp += this.toolbarHeight;
  2333. }
  2334. if (tmp > 0 && !mxClient.IS_QUIRKS)
  2335. {
  2336. tmp += 1;
  2337. }
  2338. var sidebarFooterHeight = 0;
  2339. if (this.sidebarFooterContainer != null)
  2340. {
  2341. var bottom = this.footerHeight + off;
  2342. sidebarFooterHeight = Math.max(0, Math.min(h - tmp - bottom, this.sidebarFooterHeight));
  2343. this.sidebarFooterContainer.style.width = effHsplitPosition + 'px';
  2344. this.sidebarFooterContainer.style.height = sidebarFooterHeight + 'px';
  2345. this.sidebarFooterContainer.style.bottom = bottom + 'px';
  2346. }
  2347. var fw = (this.format != null) ? this.formatWidth : 0;
  2348. this.sidebarContainer.style.top = tmp + 'px';
  2349. this.sidebarContainer.style.width = effHsplitPosition + 'px';
  2350. this.formatContainer.style.top = tmp + 'px';
  2351. this.formatContainer.style.width = fw + 'px';
  2352. this.formatContainer.style.display = (this.format != null) ? '' : 'none';
  2353. this.diagramContainer.style.left = (this.hsplit.parentNode != null) ? (effHsplitPosition + this.splitSize) + 'px' : '0px';
  2354. this.diagramContainer.style.top = this.sidebarContainer.style.top;
  2355. this.footerContainer.style.height = this.footerHeight + 'px';
  2356. this.hsplit.style.top = this.sidebarContainer.style.top;
  2357. this.hsplit.style.bottom = (this.footerHeight + off) + 'px';
  2358. this.hsplit.style.left = effHsplitPosition + 'px';
  2359. if (this.tabContainer != null)
  2360. {
  2361. this.tabContainer.style.left = this.diagramContainer.style.left;
  2362. }
  2363. if (quirks)
  2364. {
  2365. this.menubarContainer.style.width = w + 'px';
  2366. this.toolbarContainer.style.width = this.menubarContainer.style.width;
  2367. var sidebarHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2368. this.sidebarContainer.style.height = (sidebarHeight - sidebarFooterHeight) + 'px';
  2369. this.formatContainer.style.height = sidebarHeight + 'px';
  2370. this.diagramContainer.style.width = (this.hsplit.parentNode != null) ? Math.max(0, w - effHsplitPosition - this.splitSize - fw) + 'px' : w + 'px';
  2371. this.footerContainer.style.width = this.menubarContainer.style.width;
  2372. var diagramHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2373. if (this.tabContainer != null)
  2374. {
  2375. this.tabContainer.style.width = this.diagramContainer.style.width;
  2376. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2377. diagramHeight -= this.tabContainer.clientHeight;
  2378. }
  2379. this.diagramContainer.style.height = diagramHeight + 'px';
  2380. this.hsplit.style.height = diagramHeight + 'px';
  2381. }
  2382. else
  2383. {
  2384. if (this.footerHeight > 0)
  2385. {
  2386. this.footerContainer.style.bottom = off + 'px';
  2387. }
  2388. this.diagramContainer.style.right = fw + 'px';
  2389. var th = 0;
  2390. if (this.tabContainer != null)
  2391. {
  2392. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2393. this.tabContainer.style.right = this.diagramContainer.style.right;
  2394. th = this.tabContainer.clientHeight;
  2395. }
  2396. this.sidebarContainer.style.bottom = (this.footerHeight + sidebarFooterHeight + off) + 'px';
  2397. this.formatContainer.style.bottom = (this.footerHeight + off) + 'px';
  2398. this.diagramContainer.style.bottom = (this.footerHeight + off + th) + 'px';
  2399. }
  2400. if (sizeDidChange)
  2401. {
  2402. this.editor.graph.sizeDidChange();
  2403. }
  2404. };
  2405. /**
  2406. * Creates the required containers.
  2407. */
  2408. EditorUi.prototype.createTabContainer = function()
  2409. {
  2410. return null;
  2411. };
  2412. /**
  2413. * Creates the required containers.
  2414. */
  2415. EditorUi.prototype.createDivs = function()
  2416. {
  2417. this.menubarContainer = this.createDiv('geMenubarContainer');
  2418. this.toolbarContainer = this.createDiv('geToolbarContainer');
  2419. this.sidebarContainer = this.createDiv('geSidebarContainer');
  2420. this.formatContainer = this.createDiv('geSidebarContainer');
  2421. this.diagramContainer = this.createDiv('geDiagramContainer');
  2422. this.footerContainer = this.createDiv('geFooterContainer');
  2423. this.hsplit = this.createDiv('geHsplit');
  2424. this.hsplit.setAttribute('title', mxResources.get('collapseExpand'));
  2425. // Sets static style for containers
  2426. this.menubarContainer.style.top = '0px';
  2427. this.menubarContainer.style.left = '0px';
  2428. this.menubarContainer.style.right = '0px';
  2429. this.toolbarContainer.style.left = '0px';
  2430. this.toolbarContainer.style.right = '0px';
  2431. this.sidebarContainer.style.left = '0px';
  2432. this.formatContainer.style.right = '0px';
  2433. this.formatContainer.style.zIndex = '1';
  2434. this.diagramContainer.style.right = ((this.format != null) ? this.formatWidth : 0) + 'px';
  2435. this.footerContainer.style.left = '0px';
  2436. this.footerContainer.style.right = '0px';
  2437. this.footerContainer.style.bottom = '0px';
  2438. this.footerContainer.style.zIndex = mxPopupMenu.prototype.zIndex - 2;
  2439. this.hsplit.style.width = this.splitSize + 'px';
  2440. // Only vertical scrollbars, no background in format sidebar
  2441. this.formatContainer.style.backgroundColor = 'whiteSmoke';
  2442. this.formatContainer.style.overflowX = 'hidden';
  2443. this.formatContainer.style.overflowY = 'auto';
  2444. this.formatContainer.style.fontSize = '12px';
  2445. this.sidebarFooterContainer = this.createSidebarFooterContainer();
  2446. if (this.sidebarFooterContainer)
  2447. {
  2448. this.sidebarFooterContainer.style.left = '0px';
  2449. }
  2450. if (!this.editor.chromeless)
  2451. {
  2452. this.tabContainer = this.createTabContainer();
  2453. }
  2454. };
  2455. /**
  2456. * Hook for sidebar footer container. This implementation returns null.
  2457. */
  2458. EditorUi.prototype.createSidebarFooterContainer = function()
  2459. {
  2460. return null;
  2461. };
  2462. /**
  2463. * Creates the required containers.
  2464. */
  2465. EditorUi.prototype.createUi = function()
  2466. {
  2467. // Creates menubar
  2468. this.menubar = (this.editor.chromeless) ? null : this.menus.createMenubar(this.createDiv('geMenubar'));
  2469. if (this.menubar != null)
  2470. {
  2471. this.menubarContainer.appendChild(this.menubar.container);
  2472. }
  2473. // Adds status bar in menubar
  2474. if (this.menubar != null)
  2475. {
  2476. this.statusContainer = this.createStatusContainer();
  2477. // Connects the status bar to the editor status
  2478. this.editor.addListener('statusChanged', mxUtils.bind(this, function()
  2479. {
  2480. this.setStatusText(this.editor.getStatus());
  2481. }));
  2482. this.setStatusText(this.editor.getStatus());
  2483. this.menubar.container.appendChild(this.statusContainer);
  2484. // Inserts into DOM
  2485. this.container.appendChild(this.menubarContainer);
  2486. }
  2487. // Creates the sidebar
  2488. this.sidebar = (this.editor.chromeless) ? null : this.createSidebar(this.sidebarContainer);
  2489. if (this.sidebar != null)
  2490. {
  2491. this.container.appendChild(this.sidebarContainer);
  2492. }
  2493. // Creates the format sidebar
  2494. this.format = (this.editor.chromeless || !this.formatEnabled) ? null : this.createFormat(this.formatContainer);
  2495. if (this.format != null)
  2496. {
  2497. this.container.appendChild(this.formatContainer);
  2498. }
  2499. // Creates the footer
  2500. var footer = (this.editor.chromeless) ? null : this.createFooter();
  2501. if (footer != null)
  2502. {
  2503. this.footerContainer.appendChild(footer);
  2504. this.container.appendChild(this.footerContainer);
  2505. }
  2506. if (this.sidebar != null && this.sidebarFooterContainer)
  2507. {
  2508. this.container.appendChild(this.sidebarFooterContainer);
  2509. }
  2510. this.container.appendChild(this.diagramContainer);
  2511. if (this.container != null && this.tabContainer != null)
  2512. {
  2513. this.container.appendChild(this.tabContainer);
  2514. }
  2515. // Creates toolbar
  2516. this.toolbar = (this.editor.chromeless) ? null : this.createToolbar(this.createDiv('geToolbar'));
  2517. if (this.toolbar != null)
  2518. {
  2519. this.toolbarContainer.appendChild(this.toolbar.container);
  2520. this.container.appendChild(this.toolbarContainer);
  2521. }
  2522. // HSplit
  2523. if (this.sidebar != null)
  2524. {
  2525. this.container.appendChild(this.hsplit);
  2526. this.addSplitHandler(this.hsplit, true, 0, mxUtils.bind(this, function(value)
  2527. {
  2528. this.hsplitPosition = value;
  2529. this.refresh();
  2530. }));
  2531. }
  2532. };
  2533. /**
  2534. * Creates a new toolbar for the given container.
  2535. */
  2536. EditorUi.prototype.createStatusContainer = function()
  2537. {
  2538. var container = document.createElement('a');
  2539. container.className = 'geItem geStatus';
  2540. if (screen.width < 420)
  2541. {
  2542. container.style.maxWidth = Math.max(20, screen.width - 320) + 'px';
  2543. container.style.overflow = 'hidden';
  2544. }
  2545. return container;
  2546. };
  2547. /**
  2548. * Creates a new toolbar for the given container.
  2549. */
  2550. EditorUi.prototype.setStatusText = function(value)
  2551. {
  2552. this.statusContainer.innerHTML = value;
  2553. };
  2554. /**
  2555. * Creates a new toolbar for the given container.
  2556. */
  2557. EditorUi.prototype.createToolbar = function(container)
  2558. {
  2559. return new Toolbar(this, container);
  2560. };
  2561. /**
  2562. * Creates a new sidebar for the given container.
  2563. */
  2564. EditorUi.prototype.createSidebar = function(container)
  2565. {
  2566. return new Sidebar(this, container);
  2567. };
  2568. /**
  2569. * Creates a new sidebar for the given container.
  2570. */
  2571. EditorUi.prototype.createFormat = function(container)
  2572. {
  2573. return new Format(this, container);
  2574. };
  2575. /**
  2576. * Creates and returns a new footer.
  2577. */
  2578. EditorUi.prototype.createFooter = function()
  2579. {
  2580. return this.createDiv('geFooter');
  2581. };
  2582. /**
  2583. * Creates the actual toolbar for the toolbar container.
  2584. */
  2585. EditorUi.prototype.createDiv = function(classname)
  2586. {
  2587. var elt = document.createElement('div');
  2588. elt.className = classname;
  2589. return elt;
  2590. };
  2591. /**
  2592. * Updates the states of the given undo/redo items.
  2593. */
  2594. EditorUi.prototype.addSplitHandler = function(elt, horizontal, dx, onChange)
  2595. {
  2596. var start = null;
  2597. var initial = null;
  2598. var ignoreClick = true;
  2599. var last = null;
  2600. // Disables built-in pan and zoom in IE10 and later
  2601. if (mxClient.IS_POINTER)
  2602. {
  2603. elt.style.touchAction = 'none';
  2604. }
  2605. var getValue = mxUtils.bind(this, function()
  2606. {
  2607. var result = parseInt(((horizontal) ? elt.style.left : elt.style.bottom));
  2608. // Takes into account hidden footer
  2609. if (!horizontal)
  2610. {
  2611. result = result + dx - this.footerHeight;
  2612. }
  2613. return result;
  2614. });
  2615. function moveHandler(evt)
  2616. {
  2617. if (start != null)
  2618. {
  2619. var pt = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2620. onChange(Math.max(0, initial + ((horizontal) ? (pt.x - start.x) : (start.y - pt.y)) - dx));
  2621. mxEvent.consume(evt);
  2622. if (initial != getValue())
  2623. {
  2624. ignoreClick = true;
  2625. last = null;
  2626. }
  2627. }
  2628. };
  2629. function dropHandler(evt)
  2630. {
  2631. moveHandler(evt);
  2632. initial = null;
  2633. start = null;
  2634. };
  2635. mxEvent.addGestureListeners(elt, function(evt)
  2636. {
  2637. start = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2638. initial = getValue();
  2639. ignoreClick = false;
  2640. mxEvent.consume(evt);
  2641. });
  2642. mxEvent.addListener(elt, 'click', function(evt)
  2643. {
  2644. if (!ignoreClick)
  2645. {
  2646. var next = (last != null) ? last - dx : 0;
  2647. last = getValue();
  2648. onChange(next);
  2649. mxEvent.consume(evt);
  2650. }
  2651. });
  2652. mxEvent.addGestureListeners(document, null, moveHandler, dropHandler);
  2653. this.destroyFunctions.push(function()
  2654. {
  2655. mxEvent.removeGestureListeners(document, null, moveHandler, dropHandler);
  2656. });
  2657. };
  2658. /**
  2659. * Displays a print dialog.
  2660. */
  2661. EditorUi.prototype.showDialog = function(elt, w, h, modal, closable, onClose)
  2662. {
  2663. this.editor.graph.tooltipHandler.hideTooltip();
  2664. if (this.dialogs == null)
  2665. {
  2666. this.dialogs = [];
  2667. }
  2668. this.dialog = new Dialog(this, elt, w, h, modal, closable, onClose);
  2669. this.dialogs.push(this.dialog);
  2670. };
  2671. /**
  2672. * Displays a print dialog.
  2673. */
  2674. EditorUi.prototype.hideDialog = function(cancel)
  2675. {
  2676. if (this.dialogs != null && this.dialogs.length > 0)
  2677. {
  2678. var dlg = this.dialogs.pop();
  2679. dlg.close(cancel);
  2680. this.dialog = (this.dialogs.length > 0) ? this.dialogs[this.dialogs.length - 1] : null;
  2681. if (this.dialog == null && this.editor.graph.container.style.visibility != 'hidden')
  2682. {
  2683. this.editor.graph.container.focus();
  2684. }
  2685. this.editor.fireEvent(new mxEventObject('hideDialog'));
  2686. }
  2687. };
  2688. /**
  2689. * Display a color dialog.
  2690. */
  2691. EditorUi.prototype.pickColor = function(color, apply)
  2692. {
  2693. var graph = this.editor.graph;
  2694. var selState = graph.cellEditor.saveSelection();
  2695. var dlg = new ColorDialog(this, color || 'none', function(color)
  2696. {
  2697. graph.cellEditor.restoreSelection(selState);
  2698. apply(color);
  2699. }, function()
  2700. {
  2701. graph.cellEditor.restoreSelection(selState);
  2702. });
  2703. this.showDialog(dlg.container, 220, 430, true, false);
  2704. dlg.init();
  2705. };
  2706. /**
  2707. * Adds the label menu items to the given menu and parent.
  2708. */
  2709. EditorUi.prototype.openFile = function()
  2710. {
  2711. // Closes dialog after open
  2712. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2713. {
  2714. this.hideDialog(cancel);
  2715. }));
  2716. // Removes openFile if dialog is closed
  2717. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 320,
  2718. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2719. {
  2720. window.openFile = null;
  2721. });
  2722. };
  2723. /**
  2724. * Extracs the graph model from the given HTML data from a data transfer event.
  2725. */
  2726. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  2727. {
  2728. var result = null;
  2729. try
  2730. {
  2731. var idx = data.indexOf('&lt;mxGraphModel ');
  2732. if (idx >= 0)
  2733. {
  2734. var idx2 = data.lastIndexOf('&lt;/mxGraphModel&gt;');
  2735. if (idx2 > idx)
  2736. {
  2737. result = data.substring(idx, idx2 + 21).replace(/&gt;/g, '>').
  2738. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  2739. }
  2740. }
  2741. }
  2742. catch (e)
  2743. {
  2744. // ignore
  2745. }
  2746. return result;
  2747. };
  2748. /**
  2749. * Opens the given files in the editor.
  2750. */
  2751. EditorUi.prototype.extractGraphModelFromEvent = function(evt)
  2752. {
  2753. var result = null;
  2754. var data = null;
  2755. if (evt != null)
  2756. {
  2757. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  2758. if (provider != null)
  2759. {
  2760. if (document.documentMode == 10 || document.documentMode == 11)
  2761. {
  2762. data = provider.getData('Text');
  2763. }
  2764. else
  2765. {
  2766. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  2767. if (mxUtils.indexOf(provider.types, 'text/plain' && (data == null || data.length == 0)))
  2768. {
  2769. data = provider.getData('text/plain');
  2770. }
  2771. }
  2772. if (data != null)
  2773. {
  2774. data = this.editor.graph.zapGremlins(mxUtils.trim(data));
  2775. // Tries parsing as HTML document with embedded XML
  2776. var xml = this.extractGraphModelFromHtml(data);
  2777. if (xml != null)
  2778. {
  2779. data = xml;
  2780. }
  2781. }
  2782. }
  2783. }
  2784. if (data != null && this.isCompatibleString(data))
  2785. {
  2786. result = data;
  2787. }
  2788. return result;
  2789. };
  2790. /**
  2791. * Hook for subclassers to return true if event data is a supported format.
  2792. * This implementation always returns false.
  2793. */
  2794. EditorUi.prototype.isCompatibleString = function(data)
  2795. {
  2796. return false;
  2797. };
  2798. /**
  2799. * Adds the label menu items to the given menu and parent.
  2800. */
  2801. EditorUi.prototype.saveFile = function(forceDialog)
  2802. {
  2803. if (!forceDialog && this.editor.filename != null)
  2804. {
  2805. this.save(this.editor.getOrCreateFilename());
  2806. }
  2807. else
  2808. {
  2809. var dlg = new FilenameDialog(this, this.editor.getOrCreateFilename(), mxResources.get('save'), mxUtils.bind(this, function(name)
  2810. {
  2811. this.save(name);
  2812. }), null, mxUtils.bind(this, function(name)
  2813. {
  2814. if (name != null && name.length > 0)
  2815. {
  2816. return true;
  2817. }
  2818. mxUtils.confirm(mxResources.get('invalidName'));
  2819. return false;
  2820. }));
  2821. this.showDialog(dlg.container, 300, 100, true, true);
  2822. dlg.init();
  2823. }
  2824. };
  2825. /**
  2826. * Saves the current graph under the given filename.
  2827. */
  2828. EditorUi.prototype.save = function(name)
  2829. {
  2830. if (name != null)
  2831. {
  2832. if (this.editor.graph.isEditing())
  2833. {
  2834. this.editor.graph.stopEditing();
  2835. }
  2836. var xml = mxUtils.getXml(this.editor.getGraphXml());
  2837. try
  2838. {
  2839. if (Editor.useLocalStorage)
  2840. {
  2841. if (localStorage.getItem(name) != null &&
  2842. !mxUtils.confirm(mxResources.get('replaceIt', [name])))
  2843. {
  2844. return;
  2845. }
  2846. localStorage.setItem(name, xml);
  2847. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('saved')) + ' ' + new Date());
  2848. }
  2849. else
  2850. {
  2851. if (xml.length < MAX_REQUEST_SIZE)
  2852. {
  2853. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(name) +
  2854. '&xml=' + encodeURIComponent(xml)).simulate(document, '_blank');
  2855. }
  2856. else
  2857. {
  2858. mxUtils.alert(mxResources.get('drawingTooLarge'));
  2859. mxUtils.popup(xml);
  2860. return;
  2861. }
  2862. }
  2863. this.editor.setModified(false);
  2864. this.editor.setFilename(name);
  2865. this.updateDocumentTitle();
  2866. }
  2867. catch (e)
  2868. {
  2869. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('errorSavingFile')));
  2870. }
  2871. }
  2872. };
  2873. /**
  2874. * Executes the given layout.
  2875. */
  2876. EditorUi.prototype.executeLayout = function(exec, animate, post)
  2877. {
  2878. var graph = this.editor.graph;
  2879. if (graph.isEnabled())
  2880. {
  2881. graph.getModel().beginUpdate();
  2882. try
  2883. {
  2884. exec();
  2885. }
  2886. catch (e)
  2887. {
  2888. throw e;
  2889. }
  2890. finally
  2891. {
  2892. // Animates the changes in the graph model except
  2893. // for Camino, where animation is too slow
  2894. if (this.allowAnimation && animate && navigator.userAgent.indexOf('Camino') < 0)
  2895. {
  2896. // New API for animating graph layout results asynchronously
  2897. var morph = new mxMorphing(graph);
  2898. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  2899. {
  2900. graph.getModel().endUpdate();
  2901. if (post != null)
  2902. {
  2903. post();
  2904. }
  2905. }));
  2906. morph.startAnimation();
  2907. }
  2908. else
  2909. {
  2910. graph.getModel().endUpdate();
  2911. if (post != null)
  2912. {
  2913. post();
  2914. }
  2915. }
  2916. }
  2917. }
  2918. };
  2919. /**
  2920. * Hides the current menu.
  2921. */
  2922. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting)
  2923. {
  2924. var cellEditor = this.editor.graph.cellEditor;
  2925. var selState = cellEditor.saveSelection();
  2926. var newValue = mxUtils.prompt(title, value);
  2927. cellEditor.restoreSelection(selState);
  2928. if (newValue != null && newValue.length > 0)
  2929. {
  2930. var img = new Image();
  2931. img.onload = function()
  2932. {
  2933. fn(newValue, img.width, img.height);
  2934. };
  2935. img.onerror = function()
  2936. {
  2937. fn(null);
  2938. mxUtils.alert(mxResources.get('fileNotFound'));
  2939. };
  2940. img.src = newValue;
  2941. }
  2942. else
  2943. {
  2944. fn(null);
  2945. }
  2946. };
  2947. /**
  2948. * Hides the current menu.
  2949. */
  2950. EditorUi.prototype.showLinkDialog = function(value, btnLabel, fn)
  2951. {
  2952. var dlg = new LinkDialog(this, value, btnLabel, fn);
  2953. this.showDialog(dlg.container, 420, 90, true, true);
  2954. dlg.init();
  2955. };
  2956. /**
  2957. * Hides the current menu.
  2958. */
  2959. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  2960. {
  2961. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  2962. {
  2963. var change = new ChangeGraphBackground(this, null, image);
  2964. change.ignoreColor = true;
  2965. this.editor.graph.model.execute(change);
  2966. });
  2967. var newValue = mxUtils.prompt(mxResources.get('backgroundImage'), '');
  2968. if (newValue != null && newValue.length > 0)
  2969. {
  2970. var img = new Image();
  2971. img.onload = function()
  2972. {
  2973. apply(new mxImage(newValue, img.width, img.height));
  2974. };
  2975. img.onerror = function()
  2976. {
  2977. apply(null);
  2978. mxUtils.alert(mxResources.get('fileNotFound'));
  2979. };
  2980. img.src = newValue;
  2981. }
  2982. else
  2983. {
  2984. apply(null);
  2985. }
  2986. };
  2987. /**
  2988. * Loads the stylesheet for this graph.
  2989. */
  2990. EditorUi.prototype.setBackgroundImage = function(image)
  2991. {
  2992. this.editor.graph.setBackgroundImage(image);
  2993. this.editor.graph.view.validateBackgroundImage();
  2994. this.fireEvent(new mxEventObject('backgroundImageChanged'));
  2995. };
  2996. /**
  2997. * Creates the keyboard event handler for the current graph and history.
  2998. */
  2999. EditorUi.prototype.confirm = function(msg, okFn, cancelFn)
  3000. {
  3001. if (mxUtils.confirm(msg))
  3002. {
  3003. if (okFn != null)
  3004. {
  3005. okFn();
  3006. }
  3007. }
  3008. else if (cancelFn != null)
  3009. {
  3010. cancelFn();
  3011. }
  3012. };
  3013. /**
  3014. * Creates the keyboard event handler for the current graph and history.
  3015. */
  3016. EditorUi.prototype.createOutline = function(wnd)
  3017. {
  3018. var outline = new mxOutline(this.editor.graph);
  3019. outline.border = 20;
  3020. mxEvent.addListener(window, 'resize', function()
  3021. {
  3022. outline.update();
  3023. });
  3024. this.addListener('pageFormatChanged', function()
  3025. {
  3026. outline.update();
  3027. });
  3028. return outline;
  3029. };
  3030. /**
  3031. * Creates the keyboard event handler for the current graph and history.
  3032. */
  3033. EditorUi.prototype.createKeyHandler = function(editor)
  3034. {
  3035. var editorUi = this;
  3036. var graph = this.editor.graph;
  3037. var keyHandler = new mxKeyHandler(graph);
  3038. var isEventIgnored = keyHandler.isEventIgnored;
  3039. keyHandler.isEventIgnored = function(evt)
  3040. {
  3041. // Handles undo/redo/ctrl+./,/u via action and allows ctrl+b/i only if editing value is HTML (except for FF and Safari)
  3042. return (!this.isControlDown(evt) || mxEvent.isShiftDown(evt) || (evt.keyCode != 90 && evt.keyCode != 89 &&
  3043. evt.keyCode != 188 && evt.keyCode != 190 && evt.keyCode != 85)) && ((evt.keyCode != 66 && evt.keyCode != 73) ||
  3044. !this.isControlDown(evt) || (this.graph.cellEditor.isContentEditing() && !mxClient.IS_FF && !mxClient.IS_SF)) &&
  3045. isEventIgnored.apply(this, arguments);
  3046. };
  3047. // Ignores graph enabled state but not chromeless state
  3048. keyHandler.isEnabledForEvent = function(evt)
  3049. {
  3050. return (!mxEvent.isConsumed(evt) && this.isGraphEvent(evt) && this.isEnabled());
  3051. };
  3052. // Routes command-key to control-key on Mac
  3053. keyHandler.isControlDown = function(evt)
  3054. {
  3055. return mxEvent.isControlDown(evt) || (mxClient.IS_MAC && evt.metaKey);
  3056. };
  3057. var queue = [];
  3058. var thread = null;
  3059. // Helper function to move cells with the cursor keys
  3060. function nudge(keyCode, stepSize, resize)
  3061. {
  3062. queue.push(function()
  3063. {
  3064. if (!graph.isSelectionEmpty() && graph.isEnabled())
  3065. {
  3066. stepSize = (stepSize != null) ? stepSize : 1;
  3067. if (resize)
  3068. {
  3069. // Resizes all selected vertices
  3070. graph.getModel().beginUpdate();
  3071. try
  3072. {
  3073. var cells = graph.getSelectionCells();
  3074. for (var i = 0; i < cells.length; i++)
  3075. {
  3076. if (graph.getModel().isVertex(cells[i]) && graph.isCellResizable(cells[i]))
  3077. {
  3078. var geo = graph.getCellGeometry(cells[i]);
  3079. if (geo != null)
  3080. {
  3081. geo = geo.clone();
  3082. if (keyCode == 37)
  3083. {
  3084. geo.width = Math.max(0, geo.width - stepSize);
  3085. }
  3086. else if (keyCode == 38)
  3087. {
  3088. geo.height = Math.max(0, geo.height - stepSize);
  3089. }
  3090. else if (keyCode == 39)
  3091. {
  3092. geo.width += stepSize;
  3093. }
  3094. else if (keyCode == 40)
  3095. {
  3096. geo.height += stepSize;
  3097. }
  3098. graph.getModel().setGeometry(cells[i], geo);
  3099. }
  3100. }
  3101. }
  3102. }
  3103. finally
  3104. {
  3105. graph.getModel().endUpdate();
  3106. }
  3107. }
  3108. else
  3109. {
  3110. // Moves vertices up/down in a stack layout
  3111. var cell = graph.getSelectionCell();
  3112. var parent = graph.model.getParent(cell);
  3113. var layout = null;
  3114. if (graph.getSelectionCount() == 1 && graph.model.isVertex(cell) &&
  3115. graph.layoutManager != null && !graph.isCellLocked(cell))
  3116. {
  3117. layout = graph.layoutManager.getLayout(parent);
  3118. }
  3119. if (layout != null && layout.constructor == mxStackLayout)
  3120. {
  3121. var index = parent.getIndex(cell);
  3122. if (keyCode == 37 || keyCode == 38)
  3123. {
  3124. graph.model.add(parent, cell, Math.max(0, index - 1));
  3125. }
  3126. else if (keyCode == 39 ||keyCode == 40)
  3127. {
  3128. graph.model.add(parent, cell, Math.min(graph.model.getChildCount(parent), index + 1));
  3129. }
  3130. }
  3131. else
  3132. {
  3133. var dx = 0;
  3134. var dy = 0;
  3135. if (keyCode == 37)
  3136. {
  3137. dx = -stepSize;
  3138. }
  3139. else if (keyCode == 38)
  3140. {
  3141. dy = -stepSize;
  3142. }
  3143. else if (keyCode == 39)
  3144. {
  3145. dx = stepSize;
  3146. }
  3147. else if (keyCode == 40)
  3148. {
  3149. dy = stepSize;
  3150. }
  3151. graph.moveCells(graph.getMovableCells(graph.getSelectionCells()), dx, dy);
  3152. }
  3153. }
  3154. }
  3155. });
  3156. if (thread != null)
  3157. {
  3158. window.clearTimeout(thread);
  3159. }
  3160. thread = window.setTimeout(function()
  3161. {
  3162. if (queue.length > 0)
  3163. {
  3164. graph.getModel().beginUpdate();
  3165. try
  3166. {
  3167. for (var i = 0; i < queue.length; i++)
  3168. {
  3169. queue[i]();
  3170. }
  3171. queue = [];
  3172. }
  3173. finally
  3174. {
  3175. graph.getModel().endUpdate();
  3176. }
  3177. graph.scrollCellToVisible(graph.getSelectionCell());
  3178. }
  3179. }, 200);
  3180. };
  3181. // Overridden to handle special alt+shift+cursor keyboard shortcuts
  3182. var directions = {37: mxConstants.DIRECTION_WEST, 38: mxConstants.DIRECTION_NORTH,
  3183. 39: mxConstants.DIRECTION_EAST, 40: mxConstants.DIRECTION_SOUTH};
  3184. var keyHandlerGetFunction = keyHandler.getFunction;
  3185. // Alt+Shift+Keycode mapping to action
  3186. var altShiftActions = {67: this.actions.get('clearWaypoints'), // Alt+Shift+C
  3187. 65: this.actions.get('connectionArrows'), // Alt+Shift+A
  3188. 80: this.actions.get('connectionPoints') // Alt+Shift+P
  3189. };
  3190. mxKeyHandler.prototype.getFunction = function(evt)
  3191. {
  3192. if (graph.isEnabled())
  3193. {
  3194. // TODO: Add alt modified state in core API, here are some specific cases
  3195. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3196. {
  3197. var action = altShiftActions[evt.keyCode];
  3198. if (action != null)
  3199. {
  3200. return action.funct;
  3201. }
  3202. }
  3203. if (evt.keyCode == 9 && mxEvent.isAltDown(evt))
  3204. {
  3205. if (mxEvent.isShiftDown(evt))
  3206. {
  3207. // Alt+Shift+Tab
  3208. return function()
  3209. {
  3210. graph.selectParentCell();
  3211. };
  3212. }
  3213. else
  3214. {
  3215. // Alt+Tab
  3216. return function()
  3217. {
  3218. graph.selectChildCell();
  3219. };
  3220. }
  3221. }
  3222. else if (directions[evt.keyCode] != null && !graph.isSelectionEmpty())
  3223. {
  3224. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3225. {
  3226. if (graph.model.isVertex(graph.getSelectionCell()))
  3227. {
  3228. return function()
  3229. {
  3230. var cells = graph.connectVertex(graph.getSelectionCell(), directions[evt.keyCode],
  3231. graph.defaultEdgeLength, evt, true);
  3232. if (cells != null && cells.length > 0)
  3233. {
  3234. if (cells.length == 1 && graph.model.isEdge(cells[0]))
  3235. {
  3236. graph.setSelectionCell(graph.model.getTerminal(cells[0], false));
  3237. }
  3238. else
  3239. {
  3240. graph.setSelectionCell(cells[cells.length - 1]);
  3241. }
  3242. if (editorUi.hoverIcons != null)
  3243. {
  3244. editorUi.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  3245. }
  3246. }
  3247. };
  3248. }
  3249. }
  3250. else
  3251. {
  3252. // Avoids consuming event if no vertex is selected by returning null below
  3253. // Cursor keys move and resize (ctrl) cells
  3254. if (this.isControlDown(evt))
  3255. {
  3256. return function()
  3257. {
  3258. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null, true);
  3259. };
  3260. }
  3261. else
  3262. {
  3263. return function()
  3264. {
  3265. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null);
  3266. };
  3267. }
  3268. }
  3269. }
  3270. }
  3271. return keyHandlerGetFunction.apply(this, arguments);
  3272. };
  3273. // Binds keystrokes to actions
  3274. keyHandler.bindAction = mxUtils.bind(this, function(code, control, key, shift)
  3275. {
  3276. var action = this.actions.get(key);
  3277. if (action != null)
  3278. {
  3279. var f = function()
  3280. {
  3281. if (action.isEnabled())
  3282. {
  3283. action.funct();
  3284. }
  3285. };
  3286. if (control)
  3287. {
  3288. if (shift)
  3289. {
  3290. keyHandler.bindControlShiftKey(code, f);
  3291. }
  3292. else
  3293. {
  3294. keyHandler.bindControlKey(code, f);
  3295. }
  3296. }
  3297. else
  3298. {
  3299. if (shift)
  3300. {
  3301. keyHandler.bindShiftKey(code, f);
  3302. }
  3303. else
  3304. {
  3305. keyHandler.bindKey(code, f);
  3306. }
  3307. }
  3308. }
  3309. });
  3310. var ui = this;
  3311. var keyHandlerEscape = keyHandler.escape;
  3312. keyHandler.escape = function(evt)
  3313. {
  3314. keyHandlerEscape.apply(this, arguments);
  3315. };
  3316. // Ignores enter keystroke. Remove this line if you want the
  3317. // enter keystroke to stop editing. N, W, T are reserved.
  3318. keyHandler.enter = function() {};
  3319. keyHandler.bindControlShiftKey(36, function() { graph.exitGroup(); }); // Ctrl+Shift+Home
  3320. keyHandler.bindControlShiftKey(35, function() { graph.enterGroup(); }); // Ctrl+Shift+End
  3321. keyHandler.bindKey(36, function() { graph.home(); }); // Home
  3322. keyHandler.bindKey(35, function() { graph.refresh(); }); // End
  3323. keyHandler.bindAction(107, true, 'zoomIn'); // Ctrl+Plus
  3324. keyHandler.bindAction(109, true, 'zoomOut'); // Ctrl+Minus
  3325. keyHandler.bindAction(80, true, 'print'); // Ctrl+P
  3326. keyHandler.bindAction(79, true, 'outline', true); // Ctrl+Shift+O
  3327. keyHandler.bindAction(112, false, 'about'); // F1
  3328. if (!this.editor.chromeless)
  3329. {
  3330. keyHandler.bindControlKey(36, function() { if (graph.isEnabled()) { graph.foldCells(true); }}); // Ctrl+Home
  3331. keyHandler.bindControlKey(35, function() { if (graph.isEnabled()) { graph.foldCells(false); }}); // Ctrl+End
  3332. keyHandler.bindControlKey(13, function() { if (graph.isEnabled()) { graph.setSelectionCells(graph.duplicateCells(graph.getSelectionCells(), false)); }}); // Ctrl+Enter
  3333. keyHandler.bindAction(8, false, 'delete'); // Backspace
  3334. keyHandler.bindAction(8, true, 'deleteAll'); // Backspace
  3335. keyHandler.bindAction(46, false, 'delete'); // Delete
  3336. keyHandler.bindAction(46, true, 'deleteAll'); // Ctrl+Delete
  3337. keyHandler.bindAction(72, true, 'resetView'); // Ctrl+H
  3338. keyHandler.bindAction(72, true, 'fitWindow', true); // Ctrl+Shift+H
  3339. keyHandler.bindAction(74, true, 'fitPage'); // Ctrl+J
  3340. keyHandler.bindAction(74, true, 'fitTwoPages', true); // Ctrl+Shift+J
  3341. keyHandler.bindAction(48, true, 'customZoom'); // Ctrl+0
  3342. keyHandler.bindAction(82, true, 'turn'); // Ctrl+R
  3343. keyHandler.bindAction(82, true, 'clearDefaultStyle', true); // Ctrl+Shift+R
  3344. keyHandler.bindAction(83, true, 'save'); // Ctrl+S
  3345. keyHandler.bindAction(83, true, 'saveAs', true); // Ctrl+Shift+S
  3346. keyHandler.bindAction(65, true, 'selectAll'); // Ctrl+A
  3347. keyHandler.bindAction(65, true, 'selectNone', true); // Ctrl+A
  3348. keyHandler.bindAction(73, true, 'selectVertices', true); // Ctrl+Shift+I
  3349. keyHandler.bindAction(69, true, 'selectEdges', true); // Ctrl+Shift+E
  3350. keyHandler.bindAction(69, true, 'editStyle'); // Ctrl+E
  3351. keyHandler.bindAction(66, true, 'bold'); // Ctrl+B
  3352. keyHandler.bindAction(66, true, 'toBack', true); // Ctrl+Shift+B
  3353. keyHandler.bindAction(70, true, 'toFront', true); // Ctrl+Shift+F
  3354. keyHandler.bindAction(68, true, 'duplicate'); // Ctrl+D
  3355. keyHandler.bindAction(68, true, 'setAsDefaultStyle', true); // Ctrl+Shift+D
  3356. keyHandler.bindAction(90, true, 'undo'); // Ctrl+Z
  3357. keyHandler.bindAction(89, true, 'autosize', true); // Ctrl+Shift+Y
  3358. keyHandler.bindAction(88, true, 'cut'); // Ctrl+X
  3359. keyHandler.bindAction(67, true, 'copy'); // Ctrl+C
  3360. keyHandler.bindAction(86, true, 'paste'); // Ctrl+V
  3361. keyHandler.bindAction(71, true, 'group'); // Ctrl+G
  3362. keyHandler.bindAction(77, true, 'editData'); // Ctrl+M
  3363. keyHandler.bindAction(71, true, 'grid', true); // Ctrl+Shift+G
  3364. keyHandler.bindAction(73, true, 'italic'); // Ctrl+I
  3365. keyHandler.bindAction(76, true, 'lockUnlock'); // Ctrl+L
  3366. keyHandler.bindAction(76, true, 'layers', true); // Ctrl+Shift+L
  3367. keyHandler.bindAction(80, true, 'formatPanel', true); // Ctrl+Shift+P
  3368. keyHandler.bindAction(85, true, 'underline'); // Ctrl+U
  3369. keyHandler.bindAction(85, true, 'ungroup', true); // Ctrl+Shift+U
  3370. keyHandler.bindAction(190, true, 'superscript'); // Ctrl+.
  3371. keyHandler.bindAction(188, true, 'subscript'); // Ctrl+,
  3372. keyHandler.bindKey(13, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // Enter
  3373. keyHandler.bindKey(113, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // F2
  3374. }
  3375. if (!mxClient.IS_WIN)
  3376. {
  3377. keyHandler.bindAction(90, true, 'redo', true); // Ctrl+Shift+Z
  3378. }
  3379. else
  3380. {
  3381. keyHandler.bindAction(89, true, 'redo'); // Ctrl+Y
  3382. }
  3383. return keyHandler;
  3384. };
  3385. /**
  3386. * Creates the keyboard event handler for the current graph and history.
  3387. */
  3388. EditorUi.prototype.destroy = function()
  3389. {
  3390. if (this.editor != null)
  3391. {
  3392. this.editor.destroy();
  3393. this.editor = null;
  3394. }
  3395. if (this.menubar != null)
  3396. {
  3397. this.menubar.destroy();
  3398. this.menubar = null;
  3399. }
  3400. if (this.toolbar != null)
  3401. {
  3402. this.toolbar.destroy();
  3403. this.toolbar = null;
  3404. }
  3405. if (this.sidebar != null)
  3406. {
  3407. this.sidebar.destroy();
  3408. this.sidebar = null;
  3409. }
  3410. if (this.keyHandler != null)
  3411. {
  3412. this.keyHandler.destroy();
  3413. this.keyHandler = null;
  3414. }
  3415. if (this.keydownHandler != null)
  3416. {
  3417. mxEvent.removeListener(document, 'keydown', this.keydownHandler);
  3418. this.keydownHandler = null;
  3419. }
  3420. if (this.keyupHandler != null)
  3421. {
  3422. mxEvent.removeListener(document, 'keyup', this.keyupHandler);
  3423. this.keyupHandler = null;
  3424. }
  3425. if (this.resizeHandler != null)
  3426. {
  3427. mxEvent.removeListener(window, 'resize', this.resizeHandler);
  3428. this.resizeHandler = null;
  3429. }
  3430. if (this.gestureHandler != null)
  3431. {
  3432. mxEvent.removeGestureListeners(document, this.gestureHandler);
  3433. this.gestureHandler = null;
  3434. }
  3435. if (this.orientationChangeHandler != null)
  3436. {
  3437. mxEvent.removeListener(window, 'orientationchange', this.orientationChangeHandler);
  3438. this.orientationChangeHandler = null;
  3439. }
  3440. if (this.scrollHandler != null)
  3441. {
  3442. mxEvent.removeListener(window, 'scroll', this.scrollHandler);
  3443. this.scrollHandler = null;
  3444. }
  3445. if (this.destroyFunctions != null)
  3446. {
  3447. for (var i = 0; i < this.destroyFunctions.length; i++)
  3448. {
  3449. this.destroyFunctions[i]();
  3450. }
  3451. this.destroyFunctions = null;
  3452. }
  3453. var c = [this.menubarContainer, this.toolbarContainer, this.sidebarContainer,
  3454. this.formatContainer, this.diagramContainer, this.footerContainer,
  3455. this.chromelessToolbar, this.hsplit, this.sidebarFooterContainer,
  3456. this.layersDialog];
  3457. for (var i = 0; i < c.length; i++)
  3458. {
  3459. if (c[i] != null && c[i].parentNode != null)
  3460. {
  3461. c[i].parentNode.removeChild(c[i]);
  3462. }
  3463. }
  3464. };