EditorUi.js 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015
  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. addButton(mxUtils.bind(this, function(evt)
  1384. {
  1385. this.actions.get('print').funct();
  1386. mxEvent.consume(evt);
  1387. }), Editor.printLargeImage, mxResources.get('print'));
  1388. if (this.editor.editButtonLink != null)
  1389. {
  1390. addButton(mxUtils.bind(this, function(evt)
  1391. {
  1392. if (this.editor.editButtonLink == '_blank')
  1393. {
  1394. this.editor.editAsNew(this.getEditBlankXml(), null, true);
  1395. }
  1396. else
  1397. {
  1398. window.open(this.editor.editButtonLink, 'editWindow');
  1399. }
  1400. mxEvent.consume(evt);
  1401. }), Editor.editLargeImage, mxResources.get('openInNewWindow'));
  1402. }
  1403. if (graph.lightbox && (urlParams['close'] == '1' || this.container != document.body))
  1404. {
  1405. addButton(mxUtils.bind(this, function(evt)
  1406. {
  1407. if (urlParams['close'] == '1')
  1408. {
  1409. window.close();
  1410. }
  1411. else
  1412. {
  1413. this.destroy();
  1414. mxEvent.consume(evt);
  1415. }
  1416. }), Editor.closeLargeImage, mxResources.get('close') + ' (Escape)');
  1417. }
  1418. // Initial state invisible
  1419. this.chromelessToolbar.style.display = 'none';
  1420. mxUtils.setPrefixedStyle(this.chromelessToolbar.style, 'transform', 'translate(-50%,0)');
  1421. graph.container.appendChild(this.chromelessToolbar);
  1422. // Installs handling of hightligh and handling links to relative links and anchors
  1423. this.addChromelessClickHandler();
  1424. mxEvent.addListener(graph.container, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', mxUtils.bind(this, function(evt)
  1425. {
  1426. if (!mxEvent.isTouchEvent(evt))
  1427. {
  1428. if (!mxEvent.isShiftDown(evt))
  1429. {
  1430. fadeIn(30);
  1431. }
  1432. fadeOut();
  1433. }
  1434. }));
  1435. mxEvent.addListener(this.chromelessToolbar, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', function(evt)
  1436. {
  1437. mxEvent.consume(evt);
  1438. });
  1439. mxEvent.addListener(this.chromelessToolbar, 'mouseenter', mxUtils.bind(this, function(evt)
  1440. {
  1441. if (!mxEvent.isShiftDown(evt))
  1442. {
  1443. fadeIn(100);
  1444. }
  1445. else
  1446. {
  1447. fadeOut();
  1448. }
  1449. }));
  1450. mxEvent.addListener(this.chromelessToolbar, 'mousemove', mxUtils.bind(this, function(evt)
  1451. {
  1452. if (!mxEvent.isShiftDown(evt))
  1453. {
  1454. fadeIn(100);
  1455. }
  1456. else
  1457. {
  1458. fadeOut();
  1459. }
  1460. mxEvent.consume(evt);
  1461. }));
  1462. mxEvent.addListener(this.chromelessToolbar, 'mouseleave', mxUtils.bind(this, function(evt)
  1463. {
  1464. if (!mxEvent.isTouchEvent(evt))
  1465. {
  1466. fadeIn(30);
  1467. }
  1468. }));
  1469. // Shows/hides toolbar for touch devices
  1470. var tol = graph.getTolerance();
  1471. var ui = this;
  1472. graph.addMouseListener(
  1473. {
  1474. startX: 0,
  1475. startY: 0,
  1476. scrollLeft: 0,
  1477. scrollTop: 0,
  1478. mouseDown: function(sender, me)
  1479. {
  1480. this.startX = me.getGraphX();
  1481. this.startY = me.getGraphY();
  1482. this.scrollLeft = graph.container.scrollLeft;
  1483. this.scrollTop = graph.container.scrollTop;
  1484. },
  1485. mouseMove: function(sender, me) {},
  1486. mouseUp: function(sender, me)
  1487. {
  1488. if (mxEvent.isTouchEvent(me.getEvent()))
  1489. {
  1490. if ((Math.abs(this.scrollLeft - graph.container.scrollLeft) < tol &&
  1491. Math.abs(this.scrollTop - graph.container.scrollTop) < tol) &&
  1492. (Math.abs(this.startX - me.getGraphX()) < tol &&
  1493. Math.abs(this.startY - me.getGraphY()) < tol))
  1494. {
  1495. if (parseFloat(ui.chromelessToolbar.style.opacity || 0) > 0)
  1496. {
  1497. fadeOut();
  1498. }
  1499. else
  1500. {
  1501. fadeIn(30);
  1502. }
  1503. }
  1504. }
  1505. }
  1506. });
  1507. }
  1508. else if (this.editor.extendCanvas)
  1509. {
  1510. /**
  1511. * Guesses autoTranslate to avoid another repaint (see below).
  1512. * Works if only the scale of the graph changes or if pages
  1513. * are visible and the visible pages do not change.
  1514. */
  1515. var graphViewValidate = graph.view.validate;
  1516. graph.view.validate = function()
  1517. {
  1518. if (this.graph.container != null && mxUtils.hasScrollbars(this.graph.container))
  1519. {
  1520. var pad = this.graph.getPagePadding();
  1521. var size = this.graph.getPageSize();
  1522. // Updating scrollbars here causes flickering in quirks and is not needed
  1523. // if zoom method is always used to set the current scale on the graph.
  1524. var tx = this.translate.x;
  1525. var ty = this.translate.y;
  1526. this.translate.x = pad.x - (this.x0 || 0) * size.width;
  1527. this.translate.y = pad.y - (this.y0 || 0) * size.height;
  1528. }
  1529. graphViewValidate.apply(this, arguments);
  1530. };
  1531. var graphSizeDidChange = graph.sizeDidChange;
  1532. graph.sizeDidChange = function()
  1533. {
  1534. if (this.container != null && mxUtils.hasScrollbars(this.container))
  1535. {
  1536. var pages = this.getPageLayout();
  1537. var pad = this.getPagePadding();
  1538. var size = this.getPageSize();
  1539. // Updates the minimum graph size
  1540. var minw = Math.ceil(2 * pad.x + pages.width * size.width);
  1541. var minh = Math.ceil(2 * pad.y + pages.height * size.height);
  1542. var min = graph.minimumGraphSize;
  1543. // LATER: Fix flicker of scrollbar size in IE quirks mode
  1544. // after delayed call in window.resize event handler
  1545. if (min == null || min.width != minw || min.height != minh)
  1546. {
  1547. graph.minimumGraphSize = new mxRectangle(0, 0, minw, minh);
  1548. }
  1549. // Updates auto-translate to include padding and graph size
  1550. var dx = pad.x - pages.x * size.width;
  1551. var dy = pad.y - pages.y * size.height;
  1552. if (!this.autoTranslate && (this.view.translate.x != dx || this.view.translate.y != dy))
  1553. {
  1554. this.autoTranslate = true;
  1555. this.view.x0 = pages.x;
  1556. this.view.y0 = pages.y;
  1557. // NOTE: THIS INVOKES THIS METHOD AGAIN. UNFORTUNATELY THERE IS NO WAY AROUND THIS SINCE THE
  1558. // BOUNDS ARE KNOWN AFTER THE VALIDATION AND SETTING THE TRANSLATE TRIGGERS A REVALIDATION.
  1559. // SHOULD MOVE TRANSLATE/SCALE TO VIEW.
  1560. var tx = graph.view.translate.x;
  1561. var ty = graph.view.translate.y;
  1562. graph.view.setTranslate(dx, dy);
  1563. // LATER: Fix rounding errors for small zoom
  1564. graph.container.scrollLeft += Math.round((dx - tx) * graph.view.scale);
  1565. graph.container.scrollTop += Math.round((dy - ty) * graph.view.scale);
  1566. this.autoTranslate = false;
  1567. return;
  1568. }
  1569. graphSizeDidChange.apply(this, arguments);
  1570. }
  1571. };
  1572. }
  1573. // Accumulates the zoom factor while the rendering is taking place
  1574. // so that not the complete sequence of zoom steps must be painted
  1575. graph.updateZoomTimeout = null;
  1576. graph.cumulativeZoomFactor = 1;
  1577. var cursorPosition = null;
  1578. graph.lazyZoom = function(zoomIn)
  1579. {
  1580. if (this.updateZoomTimeout != null)
  1581. {
  1582. window.clearTimeout(this.updateZoomTimeout);
  1583. }
  1584. // Switches to 1% zoom steps below 15%
  1585. // Lower bound depdends on rounding below
  1586. if (zoomIn)
  1587. {
  1588. if (this.view.scale * this.cumulativeZoomFactor < 0.15)
  1589. {
  1590. this.cumulativeZoomFactor = (this.view.scale + 0.01) / this.view.scale;
  1591. }
  1592. else
  1593. {
  1594. // Uses to 5% zoom steps for better grid rendering in webkit
  1595. // and to avoid rounding errors for zoom steps
  1596. this.cumulativeZoomFactor *= this.zoomFactor;
  1597. this.cumulativeZoomFactor = Math.round(this.view.scale * this.cumulativeZoomFactor * 20) / 20 / this.view.scale;
  1598. }
  1599. }
  1600. else
  1601. {
  1602. if (this.view.scale * this.cumulativeZoomFactor <= 0.15)
  1603. {
  1604. this.cumulativeZoomFactor = (this.view.scale - 0.01) / this.view.scale;
  1605. }
  1606. else
  1607. {
  1608. // Uses to 5% zoom steps for better grid rendering in webkit
  1609. // and to avoid rounding errors for zoom steps
  1610. this.cumulativeZoomFactor /= this.zoomFactor;
  1611. this.cumulativeZoomFactor = Math.round(this.view.scale * this.cumulativeZoomFactor * 20) / 20 / this.view.scale;
  1612. }
  1613. }
  1614. this.cumulativeZoomFactor = Math.max(0.01, Math.min(this.view.scale * this.cumulativeZoomFactor, 160) / this.view.scale);
  1615. this.updateZoomTimeout = window.setTimeout(mxUtils.bind(this, function()
  1616. {
  1617. this.zoom(this.cumulativeZoomFactor);
  1618. if (resize != null)
  1619. {
  1620. resize(false);
  1621. }
  1622. // Zooms to mouse position if scrollbars enabled
  1623. if (cursorPosition != null && mxUtils.hasScrollbars(graph.container))
  1624. {
  1625. var offset = mxUtils.getOffset(graph.container);
  1626. var dx = graph.container.offsetWidth / 2 - cursorPosition.x + offset.x;
  1627. var dy = graph.container.offsetHeight / 2 - cursorPosition.y + offset.y;
  1628. graph.container.scrollLeft -= dx * (this.cumulativeZoomFactor - 1);
  1629. graph.container.scrollTop -= dy * (this.cumulativeZoomFactor - 1);
  1630. }
  1631. this.cumulativeZoomFactor = 1;
  1632. this.updateZoomTimeout = null;
  1633. }), 20);
  1634. };
  1635. mxEvent.addMouseWheelListener(mxUtils.bind(this, function(evt, up)
  1636. {
  1637. // Ctrl+wheel (or pinch on touchpad) is a native browser zoom event is OS X
  1638. // LATER: Add support for zoom via pinch on trackpad for Chrome in OS X
  1639. if ((mxEvent.isAltDown(evt) || (mxEvent.isControlDown(evt) && !mxClient.IS_MAC) ||
  1640. graph.panningHandler.isActive()) && (this.dialogs == null || this.dialogs.length == 0))
  1641. {
  1642. var source = mxEvent.getSource(evt);
  1643. while (source != null)
  1644. {
  1645. if (source == graph.container)
  1646. {
  1647. cursorPosition = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  1648. graph.lazyZoom(up);
  1649. mxEvent.consume(evt);
  1650. return;
  1651. }
  1652. source = source.parentNode;
  1653. }
  1654. }
  1655. }));
  1656. };
  1657. /**
  1658. * Creates a temporary graph instance for rendering off-screen content.
  1659. */
  1660. EditorUi.prototype.createTemporaryGraph = function(stylesheet)
  1661. {
  1662. var graph = new Graph(document.createElement('div'), null, null, stylesheet);
  1663. graph.resetViewOnRootChange = false;
  1664. graph.setConnectable(false);
  1665. graph.gridEnabled = false;
  1666. graph.autoScroll = false;
  1667. graph.setTooltips(false);
  1668. graph.setEnabled(false);
  1669. // Container must be in the DOM for correct HTML rendering
  1670. graph.container.style.visibility = 'hidden';
  1671. graph.container.style.position = 'absolute';
  1672. graph.container.style.overflow = 'hidden';
  1673. graph.container.style.height = '1px';
  1674. graph.container.style.width = '1px';
  1675. return graph;
  1676. };
  1677. /**
  1678. *
  1679. */
  1680. EditorUi.prototype.addChromelessClickHandler = function()
  1681. {
  1682. var hl = urlParams['highlight'];
  1683. // Adds leading # for highlight color code
  1684. if (hl != null && hl.length > 0)
  1685. {
  1686. hl = '#' + hl;
  1687. }
  1688. this.editor.graph.addClickHandler(hl);
  1689. };
  1690. /**
  1691. *
  1692. */
  1693. EditorUi.prototype.toggleFormatPanel = function(forceHide)
  1694. {
  1695. this.formatWidth = (forceHide || this.formatWidth > 0) ? 0 : 240;
  1696. this.formatContainer.style.display = (forceHide || this.formatWidth > 0) ? '' : 'none';
  1697. this.refresh();
  1698. this.format.refresh();
  1699. this.fireEvent(new mxEventObject('formatWidthChanged'));
  1700. };
  1701. /**
  1702. * Adds support for placeholders in labels.
  1703. */
  1704. EditorUi.prototype.lightboxFit = function()
  1705. {
  1706. // LATER: Use initial graph bounds to avoid rounding errors
  1707. this.editor.graph.maxFitScale = 2;
  1708. this.editor.graph.fit(60);
  1709. this.editor.graph.maxFitScale = null;
  1710. };
  1711. /**
  1712. * Hook for allowing selection and context menu for certain events.
  1713. */
  1714. EditorUi.prototype.isSelectionAllowed = function(evt)
  1715. {
  1716. return mxEvent.getSource(evt).nodeName == 'SELECT' || (mxEvent.getSource(evt).nodeName == 'INPUT' &&
  1717. mxUtils.isAncestorNode(this.formatContainer, mxEvent.getSource(evt)));
  1718. };
  1719. /**
  1720. * Installs dialog if browser window is closed without saving
  1721. * This must be disabled during save and image export.
  1722. */
  1723. EditorUi.prototype.addBeforeUnloadListener = function()
  1724. {
  1725. // Installs dialog if browser window is closed without saving
  1726. // This must be disabled during save and image export
  1727. window.onbeforeunload = mxUtils.bind(this, function()
  1728. {
  1729. if (!this.editor.chromeless)
  1730. {
  1731. return this.onBeforeUnload();
  1732. }
  1733. });
  1734. };
  1735. /**
  1736. * Sets the onbeforeunload for the application
  1737. */
  1738. EditorUi.prototype.onBeforeUnload = function()
  1739. {
  1740. if (this.editor.modified)
  1741. {
  1742. return mxResources.get('allChangesLost');
  1743. }
  1744. };
  1745. /**
  1746. * Opens the current diagram via the window.opener if one exists.
  1747. */
  1748. EditorUi.prototype.open = function()
  1749. {
  1750. // Cross-domain window access is not allowed in FF, so if we
  1751. // were opened from another domain then this will fail.
  1752. try
  1753. {
  1754. if (window.opener != null && window.opener.openFile != null)
  1755. {
  1756. window.opener.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  1757. {
  1758. try
  1759. {
  1760. var doc = mxUtils.parseXml(xml);
  1761. this.editor.setGraphXml(doc.documentElement);
  1762. this.editor.setModified(false);
  1763. this.editor.undoManager.clear();
  1764. if (filename != null)
  1765. {
  1766. this.editor.setFilename(filename);
  1767. this.updateDocumentTitle();
  1768. }
  1769. return;
  1770. }
  1771. catch (e)
  1772. {
  1773. mxUtils.alert(mxResources.get('invalidOrMissingFile') + ': ' + e.message);
  1774. }
  1775. }));
  1776. }
  1777. }
  1778. catch(e)
  1779. {
  1780. // ignore
  1781. }
  1782. // Fires as the last step if no file was loaded
  1783. this.editor.graph.view.validate();
  1784. // Required only in special cases where an initial file is opened
  1785. // and the minimumGraphSize changes and CSS must be updated.
  1786. this.editor.graph.sizeDidChange();
  1787. this.editor.fireEvent(new mxEventObject('resetGraphView'));
  1788. };
  1789. /**
  1790. * Sets the current menu and element.
  1791. */
  1792. EditorUi.prototype.setCurrentMenu = function(menu, elt)
  1793. {
  1794. this.currentMenuElt = elt;
  1795. this.currentMenu = menu;
  1796. };
  1797. /**
  1798. * Resets the current menu and element.
  1799. */
  1800. EditorUi.prototype.resetCurrentMenu = function()
  1801. {
  1802. this.currentMenuElt = null;
  1803. this.currentMenu = null;
  1804. };
  1805. /**
  1806. * Hides and destroys the current menu.
  1807. */
  1808. EditorUi.prototype.hideCurrentMenu = function(menu, elt)
  1809. {
  1810. if (this.currentMenu != null)
  1811. {
  1812. this.currentMenu.hideMenu();
  1813. this.resetCurrentMenu();
  1814. }
  1815. };
  1816. /**
  1817. * Updates the document title.
  1818. */
  1819. EditorUi.prototype.updateDocumentTitle = function()
  1820. {
  1821. var title = this.editor.getOrCreateFilename();
  1822. if (this.editor.appName != null)
  1823. {
  1824. title += ' - ' + this.editor.appName;
  1825. }
  1826. document.title = title;
  1827. };
  1828. /**
  1829. * Updates the document title.
  1830. */
  1831. EditorUi.prototype.createHoverIcons = function()
  1832. {
  1833. return new HoverIcons(this.editor.graph);
  1834. };
  1835. /**
  1836. * Returns the URL for a copy of this editor with no state.
  1837. */
  1838. EditorUi.prototype.redo = function()
  1839. {
  1840. try
  1841. {
  1842. var graph = this.editor.graph;
  1843. if (graph.isEditing())
  1844. {
  1845. document.execCommand('redo', false, null);
  1846. }
  1847. else
  1848. {
  1849. this.editor.undoManager.redo();
  1850. }
  1851. }
  1852. catch (e)
  1853. {
  1854. // ignore all errors
  1855. }
  1856. };
  1857. /**
  1858. * Returns the URL for a copy of this editor with no state.
  1859. */
  1860. EditorUi.prototype.undo = function()
  1861. {
  1862. try
  1863. {
  1864. var graph = this.editor.graph;
  1865. if (graph.isEditing())
  1866. {
  1867. // Stops editing and executes undo on graph if native undo
  1868. // does not affect current editing value
  1869. var value = graph.cellEditor.textarea.innerHTML;
  1870. document.execCommand('undo', false, null);
  1871. if (value == graph.cellEditor.textarea.innerHTML)
  1872. {
  1873. graph.stopEditing(true);
  1874. this.editor.undoManager.undo();
  1875. }
  1876. }
  1877. else
  1878. {
  1879. this.editor.undoManager.undo();
  1880. }
  1881. }
  1882. catch (e)
  1883. {
  1884. // ignore all errors
  1885. }
  1886. };
  1887. /**
  1888. * Returns the URL for a copy of this editor with no state.
  1889. */
  1890. EditorUi.prototype.canRedo = function()
  1891. {
  1892. return this.editor.graph.isEditing() || this.editor.undoManager.canRedo();
  1893. };
  1894. /**
  1895. * Returns the URL for a copy of this editor with no state.
  1896. */
  1897. EditorUi.prototype.canUndo = function()
  1898. {
  1899. return this.editor.graph.isEditing() || this.editor.undoManager.canUndo();
  1900. };
  1901. /**
  1902. *
  1903. */
  1904. EditorUi.prototype.getEditBlankXml = function()
  1905. {
  1906. return mxUtils.getXml(this.getGraphXml());
  1907. };
  1908. /**
  1909. * Returns the URL for a copy of this editor with no state.
  1910. */
  1911. EditorUi.prototype.getUrl = function(pathname)
  1912. {
  1913. var href = (pathname != null) ? pathname : window.location.pathname;
  1914. var parms = (href.indexOf('?') > 0) ? 1 : 0;
  1915. // Removes template URL parameter for new blank diagram
  1916. for (var key in urlParams)
  1917. {
  1918. if (parms == 0)
  1919. {
  1920. href += '?';
  1921. }
  1922. else
  1923. {
  1924. href += '&';
  1925. }
  1926. href += key + '=' + urlParams[key];
  1927. parms++;
  1928. }
  1929. return href;
  1930. };
  1931. /**
  1932. * Specifies if the graph has scrollbars.
  1933. */
  1934. EditorUi.prototype.setScrollbars = function(value)
  1935. {
  1936. var graph = this.editor.graph;
  1937. var prev = graph.container.style.overflow;
  1938. graph.scrollbars = value;
  1939. this.editor.updateGraphComponents();
  1940. if (prev != graph.container.style.overflow)
  1941. {
  1942. if (graph.container.style.overflow == 'hidden')
  1943. {
  1944. var t = graph.view.translate;
  1945. graph.view.setTranslate(t.x - graph.container.scrollLeft / graph.view.scale, t.y - graph.container.scrollTop / graph.view.scale);
  1946. graph.container.scrollLeft = 0;
  1947. graph.container.scrollTop = 0;
  1948. graph.minimumGraphSize = null;
  1949. graph.sizeDidChange();
  1950. }
  1951. else
  1952. {
  1953. var dx = graph.view.translate.x;
  1954. var dy = graph.view.translate.y;
  1955. graph.view.translate.x = 0;
  1956. graph.view.translate.y = 0;
  1957. graph.sizeDidChange();
  1958. graph.container.scrollLeft -= Math.round(dx * graph.view.scale);
  1959. graph.container.scrollTop -= Math.round(dy * graph.view.scale);
  1960. }
  1961. }
  1962. this.fireEvent(new mxEventObject('scrollbarsChanged'));
  1963. };
  1964. /**
  1965. * Returns true if the graph has scrollbars.
  1966. */
  1967. EditorUi.prototype.hasScrollbars = function()
  1968. {
  1969. return this.editor.graph.scrollbars;
  1970. };
  1971. /**
  1972. * Resets the state of the scrollbars.
  1973. */
  1974. EditorUi.prototype.resetScrollbars = function()
  1975. {
  1976. var graph = this.editor.graph;
  1977. if (!this.editor.extendCanvas)
  1978. {
  1979. graph.container.scrollTop = 0;
  1980. graph.container.scrollLeft = 0;
  1981. if (!mxUtils.hasScrollbars(graph.container))
  1982. {
  1983. graph.view.setTranslate(0, 0);
  1984. }
  1985. }
  1986. else if (!this.editor.chromeless)
  1987. {
  1988. if (mxUtils.hasScrollbars(graph.container))
  1989. {
  1990. if (graph.pageVisible)
  1991. {
  1992. var pad = graph.getPagePadding();
  1993. graph.container.scrollTop = Math.floor(pad.y - this.editor.initialTopSpacing);
  1994. graph.container.scrollLeft = Math.floor(Math.min(pad.x, (graph.container.scrollWidth - graph.container.clientWidth) / 2));
  1995. // Scrolls graph to visible area
  1996. var bounds = graph.getGraphBounds();
  1997. if (bounds.width > 0 && bounds.height > 0)
  1998. {
  1999. if (bounds.x > graph.container.scrollLeft + graph.container.clientWidth * 0.9)
  2000. {
  2001. graph.container.scrollLeft = Math.min(bounds.x + bounds.width - graph.container.clientWidth, bounds.x - 10);
  2002. }
  2003. if (bounds.y > graph.container.scrollTop + graph.container.clientHeight * 0.9)
  2004. {
  2005. graph.container.scrollTop = Math.min(bounds.y + bounds.height - graph.container.clientHeight, bounds.y - 10);
  2006. }
  2007. }
  2008. }
  2009. else
  2010. {
  2011. var bounds = graph.getGraphBounds();
  2012. var width = Math.max(bounds.width, graph.scrollTileSize.width * graph.view.scale);
  2013. var height = Math.max(bounds.height, graph.scrollTileSize.height * graph.view.scale);
  2014. graph.container.scrollTop = Math.floor(Math.max(0, bounds.y - Math.max(20, (graph.container.clientHeight - height) / 4)));
  2015. graph.container.scrollLeft = Math.floor(Math.max(0, bounds.x - Math.max(0, (graph.container.clientWidth - width) / 2)));
  2016. }
  2017. }
  2018. else
  2019. {
  2020. // This code is not actively used since the default for scrollbars is always true
  2021. if (graph.pageVisible)
  2022. {
  2023. var b = graph.view.getBackgroundPageBounds();
  2024. graph.view.setTranslate(Math.floor(Math.max(0, (graph.container.clientWidth - b.width) / 2) - b.x),
  2025. Math.floor(Math.max(0, (graph.container.clientHeight - b.height) / 2) - b.y));
  2026. }
  2027. else
  2028. {
  2029. var bounds = graph.getGraphBounds();
  2030. graph.view.setTranslate(Math.floor(Math.max(0, Math.max(0, (graph.container.clientWidth - bounds.width) / 2) - bounds.x)),
  2031. Math.floor(Math.max(0, Math.max(20, (graph.container.clientHeight - bounds.height) / 4)) - bounds.y));
  2032. }
  2033. }
  2034. }
  2035. };
  2036. /**
  2037. * Loads the stylesheet for this graph.
  2038. */
  2039. EditorUi.prototype.setPageVisible = function(value)
  2040. {
  2041. var graph = this.editor.graph;
  2042. var hasScrollbars = mxUtils.hasScrollbars(graph.container);
  2043. var tx = 0;
  2044. var ty = 0;
  2045. if (hasScrollbars)
  2046. {
  2047. tx = graph.view.translate.x * graph.view.scale - graph.container.scrollLeft;
  2048. ty = graph.view.translate.y * graph.view.scale - graph.container.scrollTop;
  2049. }
  2050. graph.pageVisible = value;
  2051. graph.pageBreaksVisible = value;
  2052. graph.preferPageSize = value;
  2053. graph.view.validateBackground();
  2054. // Workaround for possible handle offset
  2055. if (hasScrollbars)
  2056. {
  2057. var cells = graph.getSelectionCells();
  2058. graph.clearSelection();
  2059. graph.setSelectionCells(cells);
  2060. }
  2061. // Calls updatePageBreaks
  2062. graph.sizeDidChange();
  2063. if (hasScrollbars)
  2064. {
  2065. graph.container.scrollLeft = graph.view.translate.x * graph.view.scale - tx;
  2066. graph.container.scrollTop = graph.view.translate.y * graph.view.scale - ty;
  2067. }
  2068. this.fireEvent(new mxEventObject('pageViewChanged'));
  2069. };
  2070. /**
  2071. * Change types
  2072. */
  2073. function ChangePageSetup(ui, color, image, format)
  2074. {
  2075. this.ui = ui;
  2076. this.previousColor = color;
  2077. this.previousImage = image;
  2078. this.previousFormat = format;
  2079. // Needed since null are valid values for color and image
  2080. this.ignoreColor = false;
  2081. this.ignoreImage = false;
  2082. }
  2083. /**
  2084. * Implementation of the undoable page rename.
  2085. */
  2086. ChangePageSetup.prototype.execute = function()
  2087. {
  2088. var graph = this.ui.editor.graph;
  2089. if (!this.ignoreColor)
  2090. {
  2091. var tmp = graph.background;
  2092. this.ui.setBackgroundColor(this.previousColor);
  2093. this.previousColor = tmp;
  2094. }
  2095. if (!this.ignoreImage)
  2096. {
  2097. var tmp = graph.backgroundImage;
  2098. this.ui.setBackgroundImage(this.previousImage);
  2099. this.previousImage = tmp;
  2100. }
  2101. if (this.previousFormat != null)
  2102. {
  2103. var tmp = graph.pageFormat;
  2104. if (this.previousFormat.width != tmp.width ||
  2105. this.previousFormat.height != tmp.height)
  2106. {
  2107. this.ui.setPageFormat(this.previousFormat);
  2108. this.previousFormat = tmp;
  2109. }
  2110. }
  2111. };
  2112. /**
  2113. * Loads the stylesheet for this graph.
  2114. */
  2115. EditorUi.prototype.setBackgroundColor = function(value)
  2116. {
  2117. this.editor.graph.background = value;
  2118. this.editor.graph.view.validateBackground();
  2119. this.fireEvent(new mxEventObject('backgroundColorChanged'));
  2120. };
  2121. /**
  2122. * Loads the stylesheet for this graph.
  2123. */
  2124. EditorUi.prototype.setFoldingEnabled = function(value)
  2125. {
  2126. this.editor.graph.foldingEnabled = value;
  2127. this.editor.graph.view.revalidate();
  2128. this.fireEvent(new mxEventObject('foldingEnabledChanged'));
  2129. };
  2130. /**
  2131. * Loads the stylesheet for this graph.
  2132. */
  2133. EditorUi.prototype.setPageFormat = function(value)
  2134. {
  2135. this.editor.graph.pageFormat = value;
  2136. if (!this.editor.graph.pageVisible)
  2137. {
  2138. this.actions.get('pageView').funct();
  2139. }
  2140. else
  2141. {
  2142. this.editor.graph.view.validateBackground();
  2143. this.editor.graph.sizeDidChange();
  2144. }
  2145. this.fireEvent(new mxEventObject('pageFormatChanged'));
  2146. };
  2147. /**
  2148. * Loads the stylesheet for this graph.
  2149. */
  2150. EditorUi.prototype.setPageScale = function(value)
  2151. {
  2152. this.editor.graph.pageScale = value;
  2153. if (!this.editor.graph.pageVisible)
  2154. {
  2155. this.actions.get('pageView').funct();
  2156. }
  2157. else
  2158. {
  2159. this.editor.graph.view.validateBackground();
  2160. this.editor.graph.sizeDidChange();
  2161. }
  2162. this.fireEvent(new mxEventObject('pageScaleChanged'));
  2163. };
  2164. /**
  2165. * Loads the stylesheet for this graph.
  2166. */
  2167. EditorUi.prototype.setGridColor = function(value)
  2168. {
  2169. this.editor.graph.view.gridColor = value;
  2170. this.editor.graph.view.validateBackground();
  2171. this.fireEvent(new mxEventObject('gridColorChanged'));
  2172. };
  2173. /**
  2174. * Updates the states of the given undo/redo items.
  2175. */
  2176. EditorUi.prototype.addUndoListener = function()
  2177. {
  2178. var undo = this.actions.get('undo');
  2179. var redo = this.actions.get('redo');
  2180. var undoMgr = this.editor.undoManager;
  2181. var undoListener = mxUtils.bind(this, function()
  2182. {
  2183. undo.setEnabled(this.canUndo());
  2184. redo.setEnabled(this.canRedo());
  2185. });
  2186. undoMgr.addListener(mxEvent.ADD, undoListener);
  2187. undoMgr.addListener(mxEvent.UNDO, undoListener);
  2188. undoMgr.addListener(mxEvent.REDO, undoListener);
  2189. undoMgr.addListener(mxEvent.CLEAR, undoListener);
  2190. // Overrides cell editor to update action states
  2191. var cellEditorStartEditing = this.editor.graph.cellEditor.startEditing;
  2192. this.editor.graph.cellEditor.startEditing = function()
  2193. {
  2194. cellEditorStartEditing.apply(this, arguments);
  2195. undoListener();
  2196. };
  2197. var cellEditorStopEditing = this.editor.graph.cellEditor.stopEditing;
  2198. this.editor.graph.cellEditor.stopEditing = function(cell, trigger)
  2199. {
  2200. cellEditorStopEditing.apply(this, arguments);
  2201. undoListener();
  2202. };
  2203. // Updates the button states once
  2204. undoListener();
  2205. };
  2206. /**
  2207. * Updates the states of the given toolbar items based on the selection.
  2208. */
  2209. EditorUi.prototype.updateActionStates = function()
  2210. {
  2211. var graph = this.editor.graph;
  2212. var selected = !graph.isSelectionEmpty();
  2213. var vertexSelected = false;
  2214. var edgeSelected = false;
  2215. var cells = graph.getSelectionCells();
  2216. if (cells != null)
  2217. {
  2218. for (var i = 0; i < cells.length; i++)
  2219. {
  2220. var cell = cells[i];
  2221. if (graph.getModel().isEdge(cell))
  2222. {
  2223. edgeSelected = true;
  2224. }
  2225. if (graph.getModel().isVertex(cell))
  2226. {
  2227. vertexSelected = true;
  2228. }
  2229. if (edgeSelected && vertexSelected)
  2230. {
  2231. break;
  2232. }
  2233. }
  2234. }
  2235. // Updates action states
  2236. var actions = ['cut', 'copy', 'bold', 'italic', 'underline', 'delete', 'duplicate',
  2237. 'editStyle', 'editTooltip', 'editLink', 'backgroundColor', 'borderColor',
  2238. 'edit', 'toFront', 'toBack', 'lockUnlock', 'solid', 'dashed',
  2239. 'dotted', 'fillColor', 'gradientColor', 'shadow', 'fontColor',
  2240. 'formattedText', 'rounded', 'toggleRounded', 'sharp', 'strokeColor'];
  2241. for (var i = 0; i < actions.length; i++)
  2242. {
  2243. this.actions.get(actions[i]).setEnabled(selected);
  2244. }
  2245. this.actions.get('setAsDefaultStyle').setEnabled(graph.getSelectionCount() == 1);
  2246. this.actions.get('clearWaypoints').setEnabled(!graph.isSelectionEmpty());
  2247. this.actions.get('turn').setEnabled(!graph.isSelectionEmpty());
  2248. this.actions.get('curved').setEnabled(edgeSelected);
  2249. this.actions.get('rotation').setEnabled(vertexSelected);
  2250. this.actions.get('wordWrap').setEnabled(vertexSelected);
  2251. this.actions.get('autosize').setEnabled(vertexSelected);
  2252. var oneVertexSelected = vertexSelected && graph.getSelectionCount() == 1;
  2253. this.actions.get('group').setEnabled(graph.getSelectionCount() > 1 ||
  2254. (oneVertexSelected && !graph.isContainer(graph.getSelectionCell())));
  2255. this.actions.get('ungroup').setEnabled(graph.getSelectionCount() == 1 &&
  2256. (graph.getModel().getChildCount(graph.getSelectionCell()) > 0 ||
  2257. (oneVertexSelected && graph.isContainer(graph.getSelectionCell()))));
  2258. this.actions.get('removeFromGroup').setEnabled(oneVertexSelected &&
  2259. graph.getModel().isVertex(graph.getModel().getParent(graph.getSelectionCell())));
  2260. // Updates menu states
  2261. var state = graph.view.getState(graph.getSelectionCell());
  2262. this.menus.get('navigation').setEnabled(selected || graph.view.currentRoot != null);
  2263. this.actions.get('collapsible').setEnabled(vertexSelected &&
  2264. (graph.isContainer(graph.getSelectionCell()) || graph.model.getChildCount(graph.getSelectionCell()) > 0));
  2265. this.actions.get('home').setEnabled(graph.view.currentRoot != null);
  2266. this.actions.get('exitGroup').setEnabled(graph.view.currentRoot != null);
  2267. this.actions.get('enterGroup').setEnabled(graph.getSelectionCount() == 1 && graph.isValidRoot(graph.getSelectionCell()));
  2268. var foldable = graph.getSelectionCount() == 1 && graph.isCellFoldable(graph.getSelectionCell())
  2269. this.actions.get('expand').setEnabled(foldable);
  2270. this.actions.get('collapse').setEnabled(foldable);
  2271. this.actions.get('editLink').setEnabled(graph.getSelectionCount() == 1);
  2272. this.actions.get('openLink').setEnabled(graph.getSelectionCount() == 1 &&
  2273. graph.getLinkForCell(graph.getSelectionCell()) != null);
  2274. this.actions.get('guides').setEnabled(graph.isEnabled());
  2275. this.actions.get('grid').setEnabled(!this.editor.chromeless);
  2276. var unlocked = graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent());
  2277. this.menus.get('layout').setEnabled(unlocked);
  2278. this.menus.get('insert').setEnabled(unlocked);
  2279. this.menus.get('direction').setEnabled(unlocked && vertexSelected);
  2280. this.menus.get('align').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2281. this.menus.get('distribute').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2282. this.actions.get('selectVertices').setEnabled(unlocked);
  2283. this.actions.get('selectEdges').setEnabled(unlocked);
  2284. this.actions.get('selectAll').setEnabled(unlocked);
  2285. this.actions.get('selectNone').setEnabled(unlocked);
  2286. this.updatePasteActionStates();
  2287. };
  2288. /**
  2289. * Refreshes the viewport.
  2290. */
  2291. EditorUi.prototype.refresh = function(sizeDidChange)
  2292. {
  2293. sizeDidChange = (sizeDidChange != null) ? sizeDidChange : true;
  2294. var quirks = mxClient.IS_IE && (document.documentMode == null || document.documentMode == 5);
  2295. var w = this.container.clientWidth;
  2296. var h = this.container.clientHeight;
  2297. if (this.container == document.body)
  2298. {
  2299. w = document.body.clientWidth || document.documentElement.clientWidth;
  2300. h = (quirks) ? document.body.clientHeight || document.documentElement.clientHeight : document.documentElement.clientHeight;
  2301. }
  2302. // Workaround for bug on iOS see
  2303. // http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
  2304. // FIXME: Fix if footer visible
  2305. var off = 0;
  2306. if (mxClient.IS_IOS && !window.navigator.standalone)
  2307. {
  2308. if (window.innerHeight != document.documentElement.clientHeight)
  2309. {
  2310. off = document.documentElement.clientHeight - window.innerHeight;
  2311. window.scrollTo(0, 0);
  2312. }
  2313. }
  2314. var effHsplitPosition = Math.max(0, Math.min(this.hsplitPosition, w - this.splitSize - 20));
  2315. var tmp = 0;
  2316. if (this.menubar != null)
  2317. {
  2318. this.menubarContainer.style.height = this.menubarHeight + 'px';
  2319. tmp += this.menubarHeight;
  2320. }
  2321. if (this.toolbar != null)
  2322. {
  2323. this.toolbarContainer.style.top = this.menubarHeight + 'px';
  2324. this.toolbarContainer.style.height = this.toolbarHeight + 'px';
  2325. tmp += this.toolbarHeight;
  2326. }
  2327. if (tmp > 0 && !mxClient.IS_QUIRKS)
  2328. {
  2329. tmp += 1;
  2330. }
  2331. var sidebarFooterHeight = 0;
  2332. if (this.sidebarFooterContainer != null)
  2333. {
  2334. var bottom = this.footerHeight + off;
  2335. sidebarFooterHeight = Math.max(0, Math.min(h - tmp - bottom, this.sidebarFooterHeight));
  2336. this.sidebarFooterContainer.style.width = effHsplitPosition + 'px';
  2337. this.sidebarFooterContainer.style.height = sidebarFooterHeight + 'px';
  2338. this.sidebarFooterContainer.style.bottom = bottom + 'px';
  2339. }
  2340. var fw = (this.format != null) ? this.formatWidth : 0;
  2341. this.sidebarContainer.style.top = tmp + 'px';
  2342. this.sidebarContainer.style.width = effHsplitPosition + 'px';
  2343. this.formatContainer.style.top = tmp + 'px';
  2344. this.formatContainer.style.width = fw + 'px';
  2345. this.formatContainer.style.display = (this.format != null) ? '' : 'none';
  2346. this.diagramContainer.style.left = (this.hsplit.parentNode != null) ? (effHsplitPosition + this.splitSize) + 'px' : '0px';
  2347. this.diagramContainer.style.top = this.sidebarContainer.style.top;
  2348. this.footerContainer.style.height = this.footerHeight + 'px';
  2349. this.hsplit.style.top = this.sidebarContainer.style.top;
  2350. this.hsplit.style.bottom = (this.footerHeight + off) + 'px';
  2351. this.hsplit.style.left = effHsplitPosition + 'px';
  2352. if (this.tabContainer != null)
  2353. {
  2354. this.tabContainer.style.left = this.diagramContainer.style.left;
  2355. }
  2356. if (quirks)
  2357. {
  2358. this.menubarContainer.style.width = w + 'px';
  2359. this.toolbarContainer.style.width = this.menubarContainer.style.width;
  2360. var sidebarHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2361. this.sidebarContainer.style.height = (sidebarHeight - sidebarFooterHeight) + 'px';
  2362. this.formatContainer.style.height = sidebarHeight + 'px';
  2363. this.diagramContainer.style.width = (this.hsplit.parentNode != null) ? Math.max(0, w - effHsplitPosition - this.splitSize - fw) + 'px' : w + 'px';
  2364. this.footerContainer.style.width = this.menubarContainer.style.width;
  2365. var diagramHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2366. if (this.tabContainer != null)
  2367. {
  2368. this.tabContainer.style.width = this.diagramContainer.style.width;
  2369. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2370. diagramHeight -= this.tabContainer.clientHeight;
  2371. }
  2372. this.diagramContainer.style.height = diagramHeight + 'px';
  2373. this.hsplit.style.height = diagramHeight + 'px';
  2374. }
  2375. else
  2376. {
  2377. if (this.footerHeight > 0)
  2378. {
  2379. this.footerContainer.style.bottom = off + 'px';
  2380. }
  2381. this.diagramContainer.style.right = fw + 'px';
  2382. var th = 0;
  2383. if (this.tabContainer != null)
  2384. {
  2385. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2386. this.tabContainer.style.right = this.diagramContainer.style.right;
  2387. th = this.tabContainer.clientHeight;
  2388. }
  2389. this.sidebarContainer.style.bottom = (this.footerHeight + sidebarFooterHeight + off) + 'px';
  2390. this.formatContainer.style.bottom = (this.footerHeight + off) + 'px';
  2391. this.diagramContainer.style.bottom = (this.footerHeight + off + th) + 'px';
  2392. }
  2393. if (sizeDidChange)
  2394. {
  2395. this.editor.graph.sizeDidChange();
  2396. }
  2397. };
  2398. /**
  2399. * Creates the required containers.
  2400. */
  2401. EditorUi.prototype.createTabContainer = function()
  2402. {
  2403. return null;
  2404. };
  2405. /**
  2406. * Creates the required containers.
  2407. */
  2408. EditorUi.prototype.createDivs = function()
  2409. {
  2410. this.menubarContainer = this.createDiv('geMenubarContainer');
  2411. this.toolbarContainer = this.createDiv('geToolbarContainer');
  2412. this.sidebarContainer = this.createDiv('geSidebarContainer');
  2413. this.formatContainer = this.createDiv('geSidebarContainer');
  2414. this.diagramContainer = this.createDiv('geDiagramContainer');
  2415. this.footerContainer = this.createDiv('geFooterContainer');
  2416. this.hsplit = this.createDiv('geHsplit');
  2417. this.hsplit.setAttribute('title', mxResources.get('collapseExpand'));
  2418. // Sets static style for containers
  2419. this.menubarContainer.style.top = '0px';
  2420. this.menubarContainer.style.left = '0px';
  2421. this.menubarContainer.style.right = '0px';
  2422. this.toolbarContainer.style.left = '0px';
  2423. this.toolbarContainer.style.right = '0px';
  2424. this.sidebarContainer.style.left = '0px';
  2425. this.formatContainer.style.right = '0px';
  2426. this.formatContainer.style.zIndex = '1';
  2427. this.diagramContainer.style.right = ((this.format != null) ? this.formatWidth : 0) + 'px';
  2428. this.footerContainer.style.left = '0px';
  2429. this.footerContainer.style.right = '0px';
  2430. this.footerContainer.style.bottom = '0px';
  2431. this.footerContainer.style.zIndex = mxPopupMenu.prototype.zIndex - 2;
  2432. this.hsplit.style.width = this.splitSize + 'px';
  2433. // Only vertical scrollbars, no background in format sidebar
  2434. this.formatContainer.style.backgroundColor = 'whiteSmoke';
  2435. this.formatContainer.style.overflowX = 'hidden';
  2436. this.formatContainer.style.overflowY = 'auto';
  2437. this.formatContainer.style.fontSize = '12px';
  2438. this.sidebarFooterContainer = this.createSidebarFooterContainer();
  2439. if (this.sidebarFooterContainer)
  2440. {
  2441. this.sidebarFooterContainer.style.left = '0px';
  2442. }
  2443. if (!this.editor.chromeless)
  2444. {
  2445. this.tabContainer = this.createTabContainer();
  2446. }
  2447. };
  2448. /**
  2449. * Hook for sidebar footer container. This implementation returns null.
  2450. */
  2451. EditorUi.prototype.createSidebarFooterContainer = function()
  2452. {
  2453. return null;
  2454. };
  2455. /**
  2456. * Creates the required containers.
  2457. */
  2458. EditorUi.prototype.createUi = function()
  2459. {
  2460. // Creates menubar
  2461. this.menubar = (this.editor.chromeless) ? null : this.menus.createMenubar(this.createDiv('geMenubar'));
  2462. if (this.menubar != null)
  2463. {
  2464. this.menubarContainer.appendChild(this.menubar.container);
  2465. }
  2466. // Adds status bar in menubar
  2467. if (this.menubar != null)
  2468. {
  2469. this.statusContainer = this.createStatusContainer();
  2470. // Connects the status bar to the editor status
  2471. this.editor.addListener('statusChanged', mxUtils.bind(this, function()
  2472. {
  2473. this.setStatusText(this.editor.getStatus());
  2474. }));
  2475. this.setStatusText(this.editor.getStatus());
  2476. this.menubar.container.appendChild(this.statusContainer);
  2477. // Inserts into DOM
  2478. this.container.appendChild(this.menubarContainer);
  2479. }
  2480. // Creates the sidebar
  2481. this.sidebar = (this.editor.chromeless) ? null : this.createSidebar(this.sidebarContainer);
  2482. if (this.sidebar != null)
  2483. {
  2484. this.container.appendChild(this.sidebarContainer);
  2485. }
  2486. // Creates the format sidebar
  2487. this.format = (this.editor.chromeless || !this.formatEnabled) ? null : this.createFormat(this.formatContainer);
  2488. if (this.format != null)
  2489. {
  2490. this.container.appendChild(this.formatContainer);
  2491. }
  2492. // Creates the footer
  2493. var footer = (this.editor.chromeless) ? null : this.createFooter();
  2494. if (footer != null)
  2495. {
  2496. this.footerContainer.appendChild(footer);
  2497. this.container.appendChild(this.footerContainer);
  2498. }
  2499. if (this.sidebar != null && this.sidebarFooterContainer)
  2500. {
  2501. this.container.appendChild(this.sidebarFooterContainer);
  2502. }
  2503. this.container.appendChild(this.diagramContainer);
  2504. if (this.container != null && this.tabContainer != null)
  2505. {
  2506. this.container.appendChild(this.tabContainer);
  2507. }
  2508. // Creates toolbar
  2509. this.toolbar = (this.editor.chromeless) ? null : this.createToolbar(this.createDiv('geToolbar'));
  2510. if (this.toolbar != null)
  2511. {
  2512. this.toolbarContainer.appendChild(this.toolbar.container);
  2513. this.container.appendChild(this.toolbarContainer);
  2514. }
  2515. // HSplit
  2516. if (this.sidebar != null)
  2517. {
  2518. this.container.appendChild(this.hsplit);
  2519. this.addSplitHandler(this.hsplit, true, 0, mxUtils.bind(this, function(value)
  2520. {
  2521. this.hsplitPosition = value;
  2522. this.refresh();
  2523. }));
  2524. }
  2525. };
  2526. /**
  2527. * Creates a new toolbar for the given container.
  2528. */
  2529. EditorUi.prototype.createStatusContainer = function()
  2530. {
  2531. var container = document.createElement('a');
  2532. container.className = 'geItem geStatus';
  2533. if (screen.width < 420)
  2534. {
  2535. container.style.maxWidth = Math.max(20, screen.width - 320) + 'px';
  2536. container.style.overflow = 'hidden';
  2537. }
  2538. return container;
  2539. };
  2540. /**
  2541. * Creates a new toolbar for the given container.
  2542. */
  2543. EditorUi.prototype.setStatusText = function(value)
  2544. {
  2545. this.statusContainer.innerHTML = value;
  2546. };
  2547. /**
  2548. * Creates a new toolbar for the given container.
  2549. */
  2550. EditorUi.prototype.createToolbar = function(container)
  2551. {
  2552. return new Toolbar(this, container);
  2553. };
  2554. /**
  2555. * Creates a new sidebar for the given container.
  2556. */
  2557. EditorUi.prototype.createSidebar = function(container)
  2558. {
  2559. return new Sidebar(this, container);
  2560. };
  2561. /**
  2562. * Creates a new sidebar for the given container.
  2563. */
  2564. EditorUi.prototype.createFormat = function(container)
  2565. {
  2566. return new Format(this, container);
  2567. };
  2568. /**
  2569. * Creates and returns a new footer.
  2570. */
  2571. EditorUi.prototype.createFooter = function()
  2572. {
  2573. return this.createDiv('geFooter');
  2574. };
  2575. /**
  2576. * Creates the actual toolbar for the toolbar container.
  2577. */
  2578. EditorUi.prototype.createDiv = function(classname)
  2579. {
  2580. var elt = document.createElement('div');
  2581. elt.className = classname;
  2582. return elt;
  2583. };
  2584. /**
  2585. * Updates the states of the given undo/redo items.
  2586. */
  2587. EditorUi.prototype.addSplitHandler = function(elt, horizontal, dx, onChange)
  2588. {
  2589. var start = null;
  2590. var initial = null;
  2591. var ignoreClick = true;
  2592. var last = null;
  2593. // Disables built-in pan and zoom in IE10 and later
  2594. if (mxClient.IS_POINTER)
  2595. {
  2596. elt.style.touchAction = 'none';
  2597. }
  2598. var getValue = mxUtils.bind(this, function()
  2599. {
  2600. var result = parseInt(((horizontal) ? elt.style.left : elt.style.bottom));
  2601. // Takes into account hidden footer
  2602. if (!horizontal)
  2603. {
  2604. result = result + dx - this.footerHeight;
  2605. }
  2606. return result;
  2607. });
  2608. function moveHandler(evt)
  2609. {
  2610. if (start != null)
  2611. {
  2612. var pt = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2613. onChange(Math.max(0, initial + ((horizontal) ? (pt.x - start.x) : (start.y - pt.y)) - dx));
  2614. mxEvent.consume(evt);
  2615. if (initial != getValue())
  2616. {
  2617. ignoreClick = true;
  2618. last = null;
  2619. }
  2620. }
  2621. };
  2622. function dropHandler(evt)
  2623. {
  2624. moveHandler(evt);
  2625. initial = null;
  2626. start = null;
  2627. };
  2628. mxEvent.addGestureListeners(elt, function(evt)
  2629. {
  2630. start = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2631. initial = getValue();
  2632. ignoreClick = false;
  2633. mxEvent.consume(evt);
  2634. });
  2635. mxEvent.addListener(elt, 'click', function(evt)
  2636. {
  2637. if (!ignoreClick)
  2638. {
  2639. var next = (last != null) ? last - dx : 0;
  2640. last = getValue();
  2641. onChange(next);
  2642. mxEvent.consume(evt);
  2643. }
  2644. });
  2645. mxEvent.addGestureListeners(document, null, moveHandler, dropHandler);
  2646. this.destroyFunctions.push(function()
  2647. {
  2648. mxEvent.removeGestureListeners(document, null, moveHandler, dropHandler);
  2649. });
  2650. };
  2651. /**
  2652. * Displays a print dialog.
  2653. */
  2654. EditorUi.prototype.showDialog = function(elt, w, h, modal, closable, onClose)
  2655. {
  2656. this.editor.graph.tooltipHandler.hideTooltip();
  2657. if (this.dialogs == null)
  2658. {
  2659. this.dialogs = [];
  2660. }
  2661. this.dialog = new Dialog(this, elt, w, h, modal, closable, onClose);
  2662. this.dialogs.push(this.dialog);
  2663. };
  2664. /**
  2665. * Displays a print dialog.
  2666. */
  2667. EditorUi.prototype.hideDialog = function(cancel)
  2668. {
  2669. if (this.dialogs != null && this.dialogs.length > 0)
  2670. {
  2671. var dlg = this.dialogs.pop();
  2672. dlg.close(cancel);
  2673. this.dialog = (this.dialogs.length > 0) ? this.dialogs[this.dialogs.length - 1] : null;
  2674. if (this.dialog == null && this.editor.graph.container.style.visibility != 'hidden')
  2675. {
  2676. this.editor.graph.container.focus();
  2677. }
  2678. this.editor.fireEvent(new mxEventObject('hideDialog'));
  2679. }
  2680. };
  2681. /**
  2682. * Display a color dialog.
  2683. */
  2684. EditorUi.prototype.pickColor = function(color, apply)
  2685. {
  2686. var graph = this.editor.graph;
  2687. var selState = graph.cellEditor.saveSelection();
  2688. var dlg = new ColorDialog(this, color || 'none', function(color)
  2689. {
  2690. graph.cellEditor.restoreSelection(selState);
  2691. apply(color);
  2692. }, function()
  2693. {
  2694. graph.cellEditor.restoreSelection(selState);
  2695. });
  2696. this.showDialog(dlg.container, 220, 430, true, false);
  2697. dlg.init();
  2698. };
  2699. /**
  2700. * Adds the label menu items to the given menu and parent.
  2701. */
  2702. EditorUi.prototype.openFile = function()
  2703. {
  2704. // Closes dialog after open
  2705. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2706. {
  2707. this.hideDialog(cancel);
  2708. }));
  2709. // Removes openFile if dialog is closed
  2710. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 320,
  2711. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2712. {
  2713. window.openFile = null;
  2714. });
  2715. };
  2716. /**
  2717. * Extracs the graph model from the given HTML data from a data transfer event.
  2718. */
  2719. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  2720. {
  2721. var result = null;
  2722. try
  2723. {
  2724. var idx = data.indexOf('&lt;mxGraphModel ');
  2725. if (idx >= 0)
  2726. {
  2727. var idx2 = data.lastIndexOf('&lt;/mxGraphModel&gt;');
  2728. if (idx2 > idx)
  2729. {
  2730. result = data.substring(idx, idx2 + 21).replace(/&gt;/g, '>').
  2731. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  2732. }
  2733. }
  2734. }
  2735. catch (e)
  2736. {
  2737. // ignore
  2738. }
  2739. return result;
  2740. };
  2741. /**
  2742. * Opens the given files in the editor.
  2743. */
  2744. EditorUi.prototype.extractGraphModelFromEvent = function(evt)
  2745. {
  2746. var result = null;
  2747. var data = null;
  2748. if (evt != null)
  2749. {
  2750. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  2751. if (provider != null)
  2752. {
  2753. if (document.documentMode == 10 || document.documentMode == 11)
  2754. {
  2755. data = provider.getData('Text');
  2756. }
  2757. else
  2758. {
  2759. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  2760. if (mxUtils.indexOf(provider.types, 'text/plain' && (data == null || data.length == 0)))
  2761. {
  2762. data = provider.getData('text/plain');
  2763. }
  2764. }
  2765. if (data != null)
  2766. {
  2767. data = this.editor.graph.zapGremlins(mxUtils.trim(data));
  2768. // Tries parsing as HTML document with embedded XML
  2769. var xml = this.extractGraphModelFromHtml(data);
  2770. if (xml != null)
  2771. {
  2772. data = xml;
  2773. }
  2774. }
  2775. }
  2776. }
  2777. if (data != null && this.isCompatibleString(data))
  2778. {
  2779. result = data;
  2780. }
  2781. return result;
  2782. };
  2783. /**
  2784. * Hook for subclassers to return true if event data is a supported format.
  2785. * This implementation always returns false.
  2786. */
  2787. EditorUi.prototype.isCompatibleString = function(data)
  2788. {
  2789. return false;
  2790. };
  2791. /**
  2792. * Adds the label menu items to the given menu and parent.
  2793. */
  2794. EditorUi.prototype.saveFile = function(forceDialog)
  2795. {
  2796. if (!forceDialog && this.editor.filename != null)
  2797. {
  2798. this.save(this.editor.getOrCreateFilename());
  2799. }
  2800. else
  2801. {
  2802. var dlg = new FilenameDialog(this, this.editor.getOrCreateFilename(), mxResources.get('save'), mxUtils.bind(this, function(name)
  2803. {
  2804. this.save(name);
  2805. }), null, mxUtils.bind(this, function(name)
  2806. {
  2807. if (name != null && name.length > 0)
  2808. {
  2809. return true;
  2810. }
  2811. mxUtils.confirm(mxResources.get('invalidName'));
  2812. return false;
  2813. }));
  2814. this.showDialog(dlg.container, 300, 100, true, true);
  2815. dlg.init();
  2816. }
  2817. };
  2818. /**
  2819. * Saves the current graph under the given filename.
  2820. */
  2821. EditorUi.prototype.save = function(name)
  2822. {
  2823. if (name != null)
  2824. {
  2825. if (this.editor.graph.isEditing())
  2826. {
  2827. this.editor.graph.stopEditing();
  2828. }
  2829. var xml = mxUtils.getXml(this.editor.getGraphXml());
  2830. try
  2831. {
  2832. if (Editor.useLocalStorage)
  2833. {
  2834. if (localStorage.getItem(name) != null &&
  2835. !mxUtils.confirm(mxResources.get('replaceIt', [name])))
  2836. {
  2837. return;
  2838. }
  2839. localStorage.setItem(name, xml);
  2840. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('saved')) + ' ' + new Date());
  2841. }
  2842. else
  2843. {
  2844. if (xml.length < MAX_REQUEST_SIZE)
  2845. {
  2846. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(name) +
  2847. '&xml=' + encodeURIComponent(xml)).simulate(document, '_blank');
  2848. }
  2849. else
  2850. {
  2851. mxUtils.alert(mxResources.get('drawingTooLarge'));
  2852. mxUtils.popup(xml);
  2853. return;
  2854. }
  2855. }
  2856. this.editor.setModified(false);
  2857. this.editor.setFilename(name);
  2858. this.updateDocumentTitle();
  2859. }
  2860. catch (e)
  2861. {
  2862. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('errorSavingFile')));
  2863. }
  2864. }
  2865. };
  2866. /**
  2867. * Executes the given layout.
  2868. */
  2869. EditorUi.prototype.executeLayout = function(exec, animate, post)
  2870. {
  2871. var graph = this.editor.graph;
  2872. if (graph.isEnabled())
  2873. {
  2874. graph.getModel().beginUpdate();
  2875. try
  2876. {
  2877. exec();
  2878. }
  2879. catch (e)
  2880. {
  2881. throw e;
  2882. }
  2883. finally
  2884. {
  2885. // Animates the changes in the graph model except
  2886. // for Camino, where animation is too slow
  2887. if (this.allowAnimation && animate && navigator.userAgent.indexOf('Camino') < 0)
  2888. {
  2889. // New API for animating graph layout results asynchronously
  2890. var morph = new mxMorphing(graph);
  2891. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  2892. {
  2893. graph.getModel().endUpdate();
  2894. if (post != null)
  2895. {
  2896. post();
  2897. }
  2898. }));
  2899. morph.startAnimation();
  2900. }
  2901. else
  2902. {
  2903. graph.getModel().endUpdate();
  2904. if (post != null)
  2905. {
  2906. post();
  2907. }
  2908. }
  2909. }
  2910. }
  2911. };
  2912. /**
  2913. * Hides the current menu.
  2914. */
  2915. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting)
  2916. {
  2917. var cellEditor = this.editor.graph.cellEditor;
  2918. var selState = cellEditor.saveSelection();
  2919. var newValue = mxUtils.prompt(title, value);
  2920. cellEditor.restoreSelection(selState);
  2921. if (newValue != null && newValue.length > 0)
  2922. {
  2923. var img = new Image();
  2924. img.onload = function()
  2925. {
  2926. fn(newValue, img.width, img.height);
  2927. };
  2928. img.onerror = function()
  2929. {
  2930. fn(null);
  2931. mxUtils.alert(mxResources.get('fileNotFound'));
  2932. };
  2933. img.src = newValue;
  2934. }
  2935. else
  2936. {
  2937. fn(null);
  2938. }
  2939. };
  2940. /**
  2941. * Hides the current menu.
  2942. */
  2943. EditorUi.prototype.showLinkDialog = function(value, btnLabel, fn)
  2944. {
  2945. var dlg = new LinkDialog(this, value, btnLabel, fn);
  2946. this.showDialog(dlg.container, 420, 90, true, true);
  2947. dlg.init();
  2948. };
  2949. /**
  2950. * Hides the current menu.
  2951. */
  2952. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  2953. {
  2954. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  2955. {
  2956. var change = new ChangeGraphBackground(this, null, image);
  2957. change.ignoreColor = true;
  2958. this.editor.graph.model.execute(change);
  2959. });
  2960. var newValue = mxUtils.prompt(mxResources.get('backgroundImage'), '');
  2961. if (newValue != null && newValue.length > 0)
  2962. {
  2963. var img = new Image();
  2964. img.onload = function()
  2965. {
  2966. apply(new mxImage(newValue, img.width, img.height));
  2967. };
  2968. img.onerror = function()
  2969. {
  2970. apply(null);
  2971. mxUtils.alert(mxResources.get('fileNotFound'));
  2972. };
  2973. img.src = newValue;
  2974. }
  2975. else
  2976. {
  2977. apply(null);
  2978. }
  2979. };
  2980. /**
  2981. * Loads the stylesheet for this graph.
  2982. */
  2983. EditorUi.prototype.setBackgroundImage = function(image)
  2984. {
  2985. this.editor.graph.setBackgroundImage(image);
  2986. this.editor.graph.view.validateBackgroundImage();
  2987. this.fireEvent(new mxEventObject('backgroundImageChanged'));
  2988. };
  2989. /**
  2990. * Creates the keyboard event handler for the current graph and history.
  2991. */
  2992. EditorUi.prototype.confirm = function(msg, okFn, cancelFn)
  2993. {
  2994. if (mxUtils.confirm(msg))
  2995. {
  2996. if (okFn != null)
  2997. {
  2998. okFn();
  2999. }
  3000. }
  3001. else if (cancelFn != null)
  3002. {
  3003. cancelFn();
  3004. }
  3005. };
  3006. /**
  3007. * Creates the keyboard event handler for the current graph and history.
  3008. */
  3009. EditorUi.prototype.createOutline = function(wnd)
  3010. {
  3011. var outline = new mxOutline(this.editor.graph);
  3012. outline.border = 20;
  3013. mxEvent.addListener(window, 'resize', function()
  3014. {
  3015. outline.update();
  3016. });
  3017. this.addListener('pageFormatChanged', function()
  3018. {
  3019. outline.update();
  3020. });
  3021. return outline;
  3022. };
  3023. /**
  3024. * Creates the keyboard event handler for the current graph and history.
  3025. */
  3026. EditorUi.prototype.createKeyHandler = function(editor)
  3027. {
  3028. var editorUi = this;
  3029. var graph = this.editor.graph;
  3030. var keyHandler = new mxKeyHandler(graph);
  3031. var isEventIgnored = keyHandler.isEventIgnored;
  3032. keyHandler.isEventIgnored = function(evt)
  3033. {
  3034. // Handles undo/redo/ctrl+./,/u via action and allows ctrl+b/i only if editing value is HTML (except for FF and Safari)
  3035. return (!this.isControlDown(evt) || mxEvent.isShiftDown(evt) || (evt.keyCode != 90 && evt.keyCode != 89 &&
  3036. evt.keyCode != 188 && evt.keyCode != 190 && evt.keyCode != 85)) && ((evt.keyCode != 66 && evt.keyCode != 73) ||
  3037. !this.isControlDown(evt) || (this.graph.cellEditor.isContentEditing() && !mxClient.IS_FF && !mxClient.IS_SF)) &&
  3038. isEventIgnored.apply(this, arguments);
  3039. };
  3040. // Ignores graph enabled state but not chromeless state
  3041. keyHandler.isEnabledForEvent = function(evt)
  3042. {
  3043. return (!mxEvent.isConsumed(evt) && this.isGraphEvent(evt) && this.isEnabled());
  3044. };
  3045. // Routes command-key to control-key on Mac
  3046. keyHandler.isControlDown = function(evt)
  3047. {
  3048. return mxEvent.isControlDown(evt) || (mxClient.IS_MAC && evt.metaKey);
  3049. };
  3050. var queue = [];
  3051. var thread = null;
  3052. // Helper function to move cells with the cursor keys
  3053. function nudge(keyCode, stepSize, resize)
  3054. {
  3055. queue.push(function()
  3056. {
  3057. if (!graph.isSelectionEmpty() && graph.isEnabled())
  3058. {
  3059. stepSize = (stepSize != null) ? stepSize : 1;
  3060. if (resize)
  3061. {
  3062. // Resizes all selected vertices
  3063. graph.getModel().beginUpdate();
  3064. try
  3065. {
  3066. var cells = graph.getSelectionCells();
  3067. for (var i = 0; i < cells.length; i++)
  3068. {
  3069. if (graph.getModel().isVertex(cells[i]) && graph.isCellResizable(cells[i]))
  3070. {
  3071. var geo = graph.getCellGeometry(cells[i]);
  3072. if (geo != null)
  3073. {
  3074. geo = geo.clone();
  3075. if (keyCode == 37)
  3076. {
  3077. geo.width = Math.max(0, geo.width - stepSize);
  3078. }
  3079. else if (keyCode == 38)
  3080. {
  3081. geo.height = Math.max(0, geo.height - stepSize);
  3082. }
  3083. else if (keyCode == 39)
  3084. {
  3085. geo.width += stepSize;
  3086. }
  3087. else if (keyCode == 40)
  3088. {
  3089. geo.height += stepSize;
  3090. }
  3091. graph.getModel().setGeometry(cells[i], geo);
  3092. }
  3093. }
  3094. }
  3095. }
  3096. finally
  3097. {
  3098. graph.getModel().endUpdate();
  3099. }
  3100. }
  3101. else
  3102. {
  3103. // Moves vertices up/down in a stack layout
  3104. var cell = graph.getSelectionCell();
  3105. var parent = graph.model.getParent(cell);
  3106. var layout = null;
  3107. if (graph.getSelectionCount() == 1 && graph.model.isVertex(cell) &&
  3108. graph.layoutManager != null && !graph.isCellLocked(cell))
  3109. {
  3110. layout = graph.layoutManager.getLayout(parent);
  3111. }
  3112. if (layout != null && layout.constructor == mxStackLayout)
  3113. {
  3114. var index = parent.getIndex(cell);
  3115. if (keyCode == 37 || keyCode == 38)
  3116. {
  3117. graph.model.add(parent, cell, Math.max(0, index - 1));
  3118. }
  3119. else if (keyCode == 39 ||keyCode == 40)
  3120. {
  3121. graph.model.add(parent, cell, Math.min(graph.model.getChildCount(parent), index + 1));
  3122. }
  3123. }
  3124. else
  3125. {
  3126. var dx = 0;
  3127. var dy = 0;
  3128. if (keyCode == 37)
  3129. {
  3130. dx = -stepSize;
  3131. }
  3132. else if (keyCode == 38)
  3133. {
  3134. dy = -stepSize;
  3135. }
  3136. else if (keyCode == 39)
  3137. {
  3138. dx = stepSize;
  3139. }
  3140. else if (keyCode == 40)
  3141. {
  3142. dy = stepSize;
  3143. }
  3144. graph.moveCells(graph.getMovableCells(graph.getSelectionCells()), dx, dy);
  3145. }
  3146. }
  3147. }
  3148. });
  3149. if (thread != null)
  3150. {
  3151. window.clearTimeout(thread);
  3152. }
  3153. thread = window.setTimeout(function()
  3154. {
  3155. if (queue.length > 0)
  3156. {
  3157. graph.getModel().beginUpdate();
  3158. try
  3159. {
  3160. for (var i = 0; i < queue.length; i++)
  3161. {
  3162. queue[i]();
  3163. }
  3164. queue = [];
  3165. }
  3166. finally
  3167. {
  3168. graph.getModel().endUpdate();
  3169. }
  3170. graph.scrollCellToVisible(graph.getSelectionCell());
  3171. }
  3172. }, 200);
  3173. };
  3174. // Overridden to handle special alt+shift+cursor keyboard shortcuts
  3175. var directions = {37: mxConstants.DIRECTION_WEST, 38: mxConstants.DIRECTION_NORTH,
  3176. 39: mxConstants.DIRECTION_EAST, 40: mxConstants.DIRECTION_SOUTH};
  3177. var keyHandlerGetFunction = keyHandler.getFunction;
  3178. // Alt+Shift+Keycode mapping to action
  3179. var altShiftActions = {67: this.actions.get('clearWaypoints'), // Alt+Shift+C
  3180. 65: this.actions.get('connectionArrows'), // Alt+Shift+A
  3181. 80: this.actions.get('connectionPoints') // Alt+Shift+P
  3182. };
  3183. mxKeyHandler.prototype.getFunction = function(evt)
  3184. {
  3185. if (graph.isEnabled())
  3186. {
  3187. // TODO: Add alt modified state in core API, here are some specific cases
  3188. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3189. {
  3190. var action = altShiftActions[evt.keyCode];
  3191. if (action != null)
  3192. {
  3193. return action.funct;
  3194. }
  3195. }
  3196. if (evt.keyCode == 9 && mxEvent.isAltDown(evt))
  3197. {
  3198. if (mxEvent.isShiftDown(evt))
  3199. {
  3200. // Alt+Shift+Tab
  3201. return function()
  3202. {
  3203. graph.selectParentCell();
  3204. };
  3205. }
  3206. else
  3207. {
  3208. // Alt+Tab
  3209. return function()
  3210. {
  3211. graph.selectChildCell();
  3212. };
  3213. }
  3214. }
  3215. else if (directions[evt.keyCode] != null && !graph.isSelectionEmpty())
  3216. {
  3217. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3218. {
  3219. if (graph.model.isVertex(graph.getSelectionCell()))
  3220. {
  3221. return function()
  3222. {
  3223. var cells = graph.connectVertex(graph.getSelectionCell(), directions[evt.keyCode],
  3224. graph.defaultEdgeLength, evt, true);
  3225. if (cells != null && cells.length > 0)
  3226. {
  3227. if (cells.length == 1 && graph.model.isEdge(cells[0]))
  3228. {
  3229. graph.setSelectionCell(graph.model.getTerminal(cells[0], false));
  3230. }
  3231. else
  3232. {
  3233. graph.setSelectionCell(cells[cells.length - 1]);
  3234. }
  3235. if (editorUi.hoverIcons != null)
  3236. {
  3237. editorUi.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  3238. }
  3239. }
  3240. };
  3241. }
  3242. }
  3243. else
  3244. {
  3245. // Avoids consuming event if no vertex is selected by returning null below
  3246. // Cursor keys move and resize (ctrl) cells
  3247. if (this.isControlDown(evt))
  3248. {
  3249. return function()
  3250. {
  3251. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null, true);
  3252. };
  3253. }
  3254. else
  3255. {
  3256. return function()
  3257. {
  3258. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null);
  3259. };
  3260. }
  3261. }
  3262. }
  3263. }
  3264. return keyHandlerGetFunction.apply(this, arguments);
  3265. };
  3266. // Binds keystrokes to actions
  3267. keyHandler.bindAction = mxUtils.bind(this, function(code, control, key, shift)
  3268. {
  3269. var action = this.actions.get(key);
  3270. if (action != null)
  3271. {
  3272. var f = function()
  3273. {
  3274. if (action.isEnabled())
  3275. {
  3276. action.funct();
  3277. }
  3278. };
  3279. if (control)
  3280. {
  3281. if (shift)
  3282. {
  3283. keyHandler.bindControlShiftKey(code, f);
  3284. }
  3285. else
  3286. {
  3287. keyHandler.bindControlKey(code, f);
  3288. }
  3289. }
  3290. else
  3291. {
  3292. if (shift)
  3293. {
  3294. keyHandler.bindShiftKey(code, f);
  3295. }
  3296. else
  3297. {
  3298. keyHandler.bindKey(code, f);
  3299. }
  3300. }
  3301. }
  3302. });
  3303. var ui = this;
  3304. var keyHandlerEscape = keyHandler.escape;
  3305. keyHandler.escape = function(evt)
  3306. {
  3307. keyHandlerEscape.apply(this, arguments);
  3308. };
  3309. // Ignores enter keystroke. Remove this line if you want the
  3310. // enter keystroke to stop editing. N, W, T are reserved.
  3311. keyHandler.enter = function() {};
  3312. keyHandler.bindControlShiftKey(36, function() { graph.exitGroup(); }); // Ctrl+Shift+Home
  3313. keyHandler.bindControlShiftKey(35, function() { graph.enterGroup(); }); // Ctrl+Shift+End
  3314. keyHandler.bindKey(36, function() { graph.home(); }); // Home
  3315. keyHandler.bindKey(35, function() { graph.refresh(); }); // End
  3316. keyHandler.bindAction(107, true, 'zoomIn'); // Ctrl+Plus
  3317. keyHandler.bindAction(109, true, 'zoomOut'); // Ctrl+Minus
  3318. keyHandler.bindAction(80, true, 'print'); // Ctrl+P
  3319. keyHandler.bindAction(79, true, 'outline', true); // Ctrl+Shift+O
  3320. keyHandler.bindAction(112, false, 'about'); // F1
  3321. if (!this.editor.chromeless)
  3322. {
  3323. keyHandler.bindControlKey(36, function() { if (graph.isEnabled()) { graph.foldCells(true); }}); // Ctrl+Home
  3324. keyHandler.bindControlKey(35, function() { if (graph.isEnabled()) { graph.foldCells(false); }}); // Ctrl+End
  3325. keyHandler.bindControlKey(13, function() { if (graph.isEnabled()) { graph.setSelectionCells(graph.duplicateCells(graph.getSelectionCells(), false)); }}); // Ctrl+Enter
  3326. keyHandler.bindAction(8, false, 'delete'); // Backspace
  3327. keyHandler.bindAction(8, true, 'deleteAll'); // Backspace
  3328. keyHandler.bindAction(46, false, 'delete'); // Delete
  3329. keyHandler.bindAction(46, true, 'deleteAll'); // Ctrl+Delete
  3330. keyHandler.bindAction(72, true, 'resetView'); // Ctrl+H
  3331. keyHandler.bindAction(72, true, 'fitWindow', true); // Ctrl+Shift+H
  3332. keyHandler.bindAction(74, true, 'fitPage'); // Ctrl+J
  3333. keyHandler.bindAction(74, true, 'fitTwoPages', true); // Ctrl+Shift+J
  3334. keyHandler.bindAction(48, true, 'customZoom'); // Ctrl+0
  3335. keyHandler.bindAction(82, true, 'turn'); // Ctrl+R
  3336. keyHandler.bindAction(82, true, 'clearDefaultStyle', true); // Ctrl+Shift+R
  3337. keyHandler.bindAction(83, true, 'save'); // Ctrl+S
  3338. keyHandler.bindAction(83, true, 'saveAs', true); // Ctrl+Shift+S
  3339. keyHandler.bindAction(65, true, 'selectAll'); // Ctrl+A
  3340. keyHandler.bindAction(65, true, 'selectNone', true); // Ctrl+A
  3341. keyHandler.bindAction(73, true, 'selectVertices', true); // Ctrl+Shift+I
  3342. keyHandler.bindAction(69, true, 'selectEdges', true); // Ctrl+Shift+E
  3343. keyHandler.bindAction(69, true, 'editStyle'); // Ctrl+E
  3344. keyHandler.bindAction(66, true, 'bold'); // Ctrl+B
  3345. keyHandler.bindAction(66, true, 'toBack', true); // Ctrl+Shift+B
  3346. keyHandler.bindAction(70, true, 'toFront', true); // Ctrl+Shift+F
  3347. keyHandler.bindAction(68, true, 'duplicate'); // Ctrl+D
  3348. keyHandler.bindAction(68, true, 'setAsDefaultStyle', true); // Ctrl+Shift+D
  3349. keyHandler.bindAction(90, true, 'undo'); // Ctrl+Z
  3350. keyHandler.bindAction(89, true, 'autosize', true); // Ctrl+Shift+Y
  3351. keyHandler.bindAction(88, true, 'cut'); // Ctrl+X
  3352. keyHandler.bindAction(67, true, 'copy'); // Ctrl+C
  3353. keyHandler.bindAction(86, true, 'paste'); // Ctrl+V
  3354. keyHandler.bindAction(71, true, 'group'); // Ctrl+G
  3355. keyHandler.bindAction(77, true, 'editData'); // Ctrl+M
  3356. keyHandler.bindAction(71, true, 'grid', true); // Ctrl+Shift+G
  3357. keyHandler.bindAction(73, true, 'italic'); // Ctrl+I
  3358. keyHandler.bindAction(76, true, 'lockUnlock'); // Ctrl+L
  3359. keyHandler.bindAction(76, true, 'layers', true); // Ctrl+Shift+L
  3360. keyHandler.bindAction(80, true, 'formatPanel', true); // Ctrl+Shift+P
  3361. keyHandler.bindAction(85, true, 'underline'); // Ctrl+U
  3362. keyHandler.bindAction(85, true, 'ungroup', true); // Ctrl+Shift+U
  3363. keyHandler.bindAction(190, true, 'superscript'); // Ctrl+.
  3364. keyHandler.bindAction(188, true, 'subscript'); // Ctrl+,
  3365. keyHandler.bindKey(13, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // Enter
  3366. keyHandler.bindKey(113, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // F2
  3367. }
  3368. if (!mxClient.IS_WIN)
  3369. {
  3370. keyHandler.bindAction(90, true, 'redo', true); // Ctrl+Shift+Z
  3371. }
  3372. else
  3373. {
  3374. keyHandler.bindAction(89, true, 'redo'); // Ctrl+Y
  3375. }
  3376. return keyHandler;
  3377. };
  3378. /**
  3379. * Creates the keyboard event handler for the current graph and history.
  3380. */
  3381. EditorUi.prototype.destroy = function()
  3382. {
  3383. if (this.editor != null)
  3384. {
  3385. this.editor.destroy();
  3386. this.editor = null;
  3387. }
  3388. if (this.menubar != null)
  3389. {
  3390. this.menubar.destroy();
  3391. this.menubar = null;
  3392. }
  3393. if (this.toolbar != null)
  3394. {
  3395. this.toolbar.destroy();
  3396. this.toolbar = null;
  3397. }
  3398. if (this.sidebar != null)
  3399. {
  3400. this.sidebar.destroy();
  3401. this.sidebar = null;
  3402. }
  3403. if (this.keyHandler != null)
  3404. {
  3405. this.keyHandler.destroy();
  3406. this.keyHandler = null;
  3407. }
  3408. if (this.keydownHandler != null)
  3409. {
  3410. mxEvent.removeListener(document, 'keydown', this.keydownHandler);
  3411. this.keydownHandler = null;
  3412. }
  3413. if (this.keyupHandler != null)
  3414. {
  3415. mxEvent.removeListener(document, 'keyup', this.keyupHandler);
  3416. this.keyupHandler = null;
  3417. }
  3418. if (this.resizeHandler != null)
  3419. {
  3420. mxEvent.removeListener(window, 'resize', this.resizeHandler);
  3421. this.resizeHandler = null;
  3422. }
  3423. if (this.gestureHandler != null)
  3424. {
  3425. mxEvent.removeGestureListeners(document, this.gestureHandler);
  3426. this.gestureHandler = null;
  3427. }
  3428. if (this.orientationChangeHandler != null)
  3429. {
  3430. mxEvent.removeListener(window, 'orientationchange', this.orientationChangeHandler);
  3431. this.orientationChangeHandler = null;
  3432. }
  3433. if (this.scrollHandler != null)
  3434. {
  3435. mxEvent.removeListener(window, 'scroll', this.scrollHandler);
  3436. this.scrollHandler = null;
  3437. }
  3438. if (this.destroyFunctions != null)
  3439. {
  3440. for (var i = 0; i < this.destroyFunctions.length; i++)
  3441. {
  3442. this.destroyFunctions[i]();
  3443. }
  3444. this.destroyFunctions = null;
  3445. }
  3446. var c = [this.menubarContainer, this.toolbarContainer, this.sidebarContainer,
  3447. this.formatContainer, this.diagramContainer, this.footerContainer,
  3448. this.chromelessToolbar, this.hsplit, this.sidebarFooterContainer,
  3449. this.layersDialog];
  3450. for (var i = 0; i < c.length; i++)
  3451. {
  3452. if (c[i] != null && c[i].parentNode != null)
  3453. {
  3454. c[i].parentNode.removeChild(c[i]);
  3455. }
  3456. }
  3457. };