EditorUi.js 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016
  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. this.actions.get('collapsible').setEnabled(vertexSelected);
  2253. var oneVertexSelected = vertexSelected && graph.getSelectionCount() == 1;
  2254. this.actions.get('group').setEnabled(graph.getSelectionCount() > 1 ||
  2255. (oneVertexSelected && !graph.isContainer(graph.getSelectionCell())));
  2256. this.actions.get('ungroup').setEnabled(graph.getSelectionCount() == 1 &&
  2257. (graph.getModel().getChildCount(graph.getSelectionCell()) > 0 ||
  2258. (oneVertexSelected && graph.isContainer(graph.getSelectionCell()))));
  2259. this.actions.get('removeFromGroup').setEnabled(oneVertexSelected &&
  2260. graph.getModel().isVertex(graph.getModel().getParent(graph.getSelectionCell())));
  2261. // Updates menu states
  2262. var state = graph.view.getState(graph.getSelectionCell());
  2263. this.menus.get('navigation').setEnabled(selected || graph.view.currentRoot != null);
  2264. this.actions.get('collapsible').setEnabled(vertexSelected && graph.getSelectionCount() == 1 &&
  2265. (graph.isContainer(graph.getSelectionCell()) || graph.model.getChildCount(graph.getSelectionCell()) > 0));
  2266. this.actions.get('home').setEnabled(graph.view.currentRoot != null);
  2267. this.actions.get('exitGroup').setEnabled(graph.view.currentRoot != null);
  2268. this.actions.get('enterGroup').setEnabled(graph.getSelectionCount() == 1 && graph.isValidRoot(graph.getSelectionCell()));
  2269. var foldable = graph.getSelectionCount() == 1 && graph.isCellFoldable(graph.getSelectionCell())
  2270. this.actions.get('expand').setEnabled(foldable);
  2271. this.actions.get('collapse').setEnabled(foldable);
  2272. this.actions.get('editLink').setEnabled(graph.getSelectionCount() == 1);
  2273. this.actions.get('openLink').setEnabled(graph.getSelectionCount() == 1 &&
  2274. graph.getLinkForCell(graph.getSelectionCell()) != null);
  2275. this.actions.get('guides').setEnabled(graph.isEnabled());
  2276. this.actions.get('grid').setEnabled(!this.editor.chromeless);
  2277. var unlocked = graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent());
  2278. this.menus.get('layout').setEnabled(unlocked);
  2279. this.menus.get('insert').setEnabled(unlocked);
  2280. this.menus.get('direction').setEnabled(unlocked && vertexSelected);
  2281. this.menus.get('align').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2282. this.menus.get('distribute').setEnabled(unlocked && vertexSelected && graph.getSelectionCount() > 1);
  2283. this.actions.get('selectVertices').setEnabled(unlocked);
  2284. this.actions.get('selectEdges').setEnabled(unlocked);
  2285. this.actions.get('selectAll').setEnabled(unlocked);
  2286. this.actions.get('selectNone').setEnabled(unlocked);
  2287. this.updatePasteActionStates();
  2288. };
  2289. /**
  2290. * Refreshes the viewport.
  2291. */
  2292. EditorUi.prototype.refresh = function(sizeDidChange)
  2293. {
  2294. sizeDidChange = (sizeDidChange != null) ? sizeDidChange : true;
  2295. var quirks = mxClient.IS_IE && (document.documentMode == null || document.documentMode == 5);
  2296. var w = this.container.clientWidth;
  2297. var h = this.container.clientHeight;
  2298. if (this.container == document.body)
  2299. {
  2300. w = document.body.clientWidth || document.documentElement.clientWidth;
  2301. h = (quirks) ? document.body.clientHeight || document.documentElement.clientHeight : document.documentElement.clientHeight;
  2302. }
  2303. // Workaround for bug on iOS see
  2304. // http://stackoverflow.com/questions/19012135/ios-7-ipad-safari-landscape-innerheight-outerheight-layout-issue
  2305. // FIXME: Fix if footer visible
  2306. var off = 0;
  2307. if (mxClient.IS_IOS && !window.navigator.standalone)
  2308. {
  2309. if (window.innerHeight != document.documentElement.clientHeight)
  2310. {
  2311. off = document.documentElement.clientHeight - window.innerHeight;
  2312. window.scrollTo(0, 0);
  2313. }
  2314. }
  2315. var effHsplitPosition = Math.max(0, Math.min(this.hsplitPosition, w - this.splitSize - 20));
  2316. var tmp = 0;
  2317. if (this.menubar != null)
  2318. {
  2319. this.menubarContainer.style.height = this.menubarHeight + 'px';
  2320. tmp += this.menubarHeight;
  2321. }
  2322. if (this.toolbar != null)
  2323. {
  2324. this.toolbarContainer.style.top = this.menubarHeight + 'px';
  2325. this.toolbarContainer.style.height = this.toolbarHeight + 'px';
  2326. tmp += this.toolbarHeight;
  2327. }
  2328. if (tmp > 0 && !mxClient.IS_QUIRKS)
  2329. {
  2330. tmp += 1;
  2331. }
  2332. var sidebarFooterHeight = 0;
  2333. if (this.sidebarFooterContainer != null)
  2334. {
  2335. var bottom = this.footerHeight + off;
  2336. sidebarFooterHeight = Math.max(0, Math.min(h - tmp - bottom, this.sidebarFooterHeight));
  2337. this.sidebarFooterContainer.style.width = effHsplitPosition + 'px';
  2338. this.sidebarFooterContainer.style.height = sidebarFooterHeight + 'px';
  2339. this.sidebarFooterContainer.style.bottom = bottom + 'px';
  2340. }
  2341. var fw = (this.format != null) ? this.formatWidth : 0;
  2342. this.sidebarContainer.style.top = tmp + 'px';
  2343. this.sidebarContainer.style.width = effHsplitPosition + 'px';
  2344. this.formatContainer.style.top = tmp + 'px';
  2345. this.formatContainer.style.width = fw + 'px';
  2346. this.formatContainer.style.display = (this.format != null) ? '' : 'none';
  2347. this.diagramContainer.style.left = (this.hsplit.parentNode != null) ? (effHsplitPosition + this.splitSize) + 'px' : '0px';
  2348. this.diagramContainer.style.top = this.sidebarContainer.style.top;
  2349. this.footerContainer.style.height = this.footerHeight + 'px';
  2350. this.hsplit.style.top = this.sidebarContainer.style.top;
  2351. this.hsplit.style.bottom = (this.footerHeight + off) + 'px';
  2352. this.hsplit.style.left = effHsplitPosition + 'px';
  2353. if (this.tabContainer != null)
  2354. {
  2355. this.tabContainer.style.left = this.diagramContainer.style.left;
  2356. }
  2357. if (quirks)
  2358. {
  2359. this.menubarContainer.style.width = w + 'px';
  2360. this.toolbarContainer.style.width = this.menubarContainer.style.width;
  2361. var sidebarHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2362. this.sidebarContainer.style.height = (sidebarHeight - sidebarFooterHeight) + 'px';
  2363. this.formatContainer.style.height = sidebarHeight + 'px';
  2364. this.diagramContainer.style.width = (this.hsplit.parentNode != null) ? Math.max(0, w - effHsplitPosition - this.splitSize - fw) + 'px' : w + 'px';
  2365. this.footerContainer.style.width = this.menubarContainer.style.width;
  2366. var diagramHeight = Math.max(0, h - this.footerHeight - this.menubarHeight - this.toolbarHeight);
  2367. if (this.tabContainer != null)
  2368. {
  2369. this.tabContainer.style.width = this.diagramContainer.style.width;
  2370. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2371. diagramHeight -= this.tabContainer.clientHeight;
  2372. }
  2373. this.diagramContainer.style.height = diagramHeight + 'px';
  2374. this.hsplit.style.height = diagramHeight + 'px';
  2375. }
  2376. else
  2377. {
  2378. if (this.footerHeight > 0)
  2379. {
  2380. this.footerContainer.style.bottom = off + 'px';
  2381. }
  2382. this.diagramContainer.style.right = fw + 'px';
  2383. var th = 0;
  2384. if (this.tabContainer != null)
  2385. {
  2386. this.tabContainer.style.bottom = (this.footerHeight + off) + 'px';
  2387. this.tabContainer.style.right = this.diagramContainer.style.right;
  2388. th = this.tabContainer.clientHeight;
  2389. }
  2390. this.sidebarContainer.style.bottom = (this.footerHeight + sidebarFooterHeight + off) + 'px';
  2391. this.formatContainer.style.bottom = (this.footerHeight + off) + 'px';
  2392. this.diagramContainer.style.bottom = (this.footerHeight + off + th) + 'px';
  2393. }
  2394. if (sizeDidChange)
  2395. {
  2396. this.editor.graph.sizeDidChange();
  2397. }
  2398. };
  2399. /**
  2400. * Creates the required containers.
  2401. */
  2402. EditorUi.prototype.createTabContainer = function()
  2403. {
  2404. return null;
  2405. };
  2406. /**
  2407. * Creates the required containers.
  2408. */
  2409. EditorUi.prototype.createDivs = function()
  2410. {
  2411. this.menubarContainer = this.createDiv('geMenubarContainer');
  2412. this.toolbarContainer = this.createDiv('geToolbarContainer');
  2413. this.sidebarContainer = this.createDiv('geSidebarContainer');
  2414. this.formatContainer = this.createDiv('geSidebarContainer');
  2415. this.diagramContainer = this.createDiv('geDiagramContainer');
  2416. this.footerContainer = this.createDiv('geFooterContainer');
  2417. this.hsplit = this.createDiv('geHsplit');
  2418. this.hsplit.setAttribute('title', mxResources.get('collapseExpand'));
  2419. // Sets static style for containers
  2420. this.menubarContainer.style.top = '0px';
  2421. this.menubarContainer.style.left = '0px';
  2422. this.menubarContainer.style.right = '0px';
  2423. this.toolbarContainer.style.left = '0px';
  2424. this.toolbarContainer.style.right = '0px';
  2425. this.sidebarContainer.style.left = '0px';
  2426. this.formatContainer.style.right = '0px';
  2427. this.formatContainer.style.zIndex = '1';
  2428. this.diagramContainer.style.right = ((this.format != null) ? this.formatWidth : 0) + 'px';
  2429. this.footerContainer.style.left = '0px';
  2430. this.footerContainer.style.right = '0px';
  2431. this.footerContainer.style.bottom = '0px';
  2432. this.footerContainer.style.zIndex = mxPopupMenu.prototype.zIndex - 2;
  2433. this.hsplit.style.width = this.splitSize + 'px';
  2434. // Only vertical scrollbars, no background in format sidebar
  2435. this.formatContainer.style.backgroundColor = 'whiteSmoke';
  2436. this.formatContainer.style.overflowX = 'hidden';
  2437. this.formatContainer.style.overflowY = 'auto';
  2438. this.formatContainer.style.fontSize = '12px';
  2439. this.sidebarFooterContainer = this.createSidebarFooterContainer();
  2440. if (this.sidebarFooterContainer)
  2441. {
  2442. this.sidebarFooterContainer.style.left = '0px';
  2443. }
  2444. if (!this.editor.chromeless)
  2445. {
  2446. this.tabContainer = this.createTabContainer();
  2447. }
  2448. };
  2449. /**
  2450. * Hook for sidebar footer container. This implementation returns null.
  2451. */
  2452. EditorUi.prototype.createSidebarFooterContainer = function()
  2453. {
  2454. return null;
  2455. };
  2456. /**
  2457. * Creates the required containers.
  2458. */
  2459. EditorUi.prototype.createUi = function()
  2460. {
  2461. // Creates menubar
  2462. this.menubar = (this.editor.chromeless) ? null : this.menus.createMenubar(this.createDiv('geMenubar'));
  2463. if (this.menubar != null)
  2464. {
  2465. this.menubarContainer.appendChild(this.menubar.container);
  2466. }
  2467. // Adds status bar in menubar
  2468. if (this.menubar != null)
  2469. {
  2470. this.statusContainer = this.createStatusContainer();
  2471. // Connects the status bar to the editor status
  2472. this.editor.addListener('statusChanged', mxUtils.bind(this, function()
  2473. {
  2474. this.setStatusText(this.editor.getStatus());
  2475. }));
  2476. this.setStatusText(this.editor.getStatus());
  2477. this.menubar.container.appendChild(this.statusContainer);
  2478. // Inserts into DOM
  2479. this.container.appendChild(this.menubarContainer);
  2480. }
  2481. // Creates the sidebar
  2482. this.sidebar = (this.editor.chromeless) ? null : this.createSidebar(this.sidebarContainer);
  2483. if (this.sidebar != null)
  2484. {
  2485. this.container.appendChild(this.sidebarContainer);
  2486. }
  2487. // Creates the format sidebar
  2488. this.format = (this.editor.chromeless || !this.formatEnabled) ? null : this.createFormat(this.formatContainer);
  2489. if (this.format != null)
  2490. {
  2491. this.container.appendChild(this.formatContainer);
  2492. }
  2493. // Creates the footer
  2494. var footer = (this.editor.chromeless) ? null : this.createFooter();
  2495. if (footer != null)
  2496. {
  2497. this.footerContainer.appendChild(footer);
  2498. this.container.appendChild(this.footerContainer);
  2499. }
  2500. if (this.sidebar != null && this.sidebarFooterContainer)
  2501. {
  2502. this.container.appendChild(this.sidebarFooterContainer);
  2503. }
  2504. this.container.appendChild(this.diagramContainer);
  2505. if (this.container != null && this.tabContainer != null)
  2506. {
  2507. this.container.appendChild(this.tabContainer);
  2508. }
  2509. // Creates toolbar
  2510. this.toolbar = (this.editor.chromeless) ? null : this.createToolbar(this.createDiv('geToolbar'));
  2511. if (this.toolbar != null)
  2512. {
  2513. this.toolbarContainer.appendChild(this.toolbar.container);
  2514. this.container.appendChild(this.toolbarContainer);
  2515. }
  2516. // HSplit
  2517. if (this.sidebar != null)
  2518. {
  2519. this.container.appendChild(this.hsplit);
  2520. this.addSplitHandler(this.hsplit, true, 0, mxUtils.bind(this, function(value)
  2521. {
  2522. this.hsplitPosition = value;
  2523. this.refresh();
  2524. }));
  2525. }
  2526. };
  2527. /**
  2528. * Creates a new toolbar for the given container.
  2529. */
  2530. EditorUi.prototype.createStatusContainer = function()
  2531. {
  2532. var container = document.createElement('a');
  2533. container.className = 'geItem geStatus';
  2534. if (screen.width < 420)
  2535. {
  2536. container.style.maxWidth = Math.max(20, screen.width - 320) + 'px';
  2537. container.style.overflow = 'hidden';
  2538. }
  2539. return container;
  2540. };
  2541. /**
  2542. * Creates a new toolbar for the given container.
  2543. */
  2544. EditorUi.prototype.setStatusText = function(value)
  2545. {
  2546. this.statusContainer.innerHTML = value;
  2547. };
  2548. /**
  2549. * Creates a new toolbar for the given container.
  2550. */
  2551. EditorUi.prototype.createToolbar = function(container)
  2552. {
  2553. return new Toolbar(this, container);
  2554. };
  2555. /**
  2556. * Creates a new sidebar for the given container.
  2557. */
  2558. EditorUi.prototype.createSidebar = function(container)
  2559. {
  2560. return new Sidebar(this, container);
  2561. };
  2562. /**
  2563. * Creates a new sidebar for the given container.
  2564. */
  2565. EditorUi.prototype.createFormat = function(container)
  2566. {
  2567. return new Format(this, container);
  2568. };
  2569. /**
  2570. * Creates and returns a new footer.
  2571. */
  2572. EditorUi.prototype.createFooter = function()
  2573. {
  2574. return this.createDiv('geFooter');
  2575. };
  2576. /**
  2577. * Creates the actual toolbar for the toolbar container.
  2578. */
  2579. EditorUi.prototype.createDiv = function(classname)
  2580. {
  2581. var elt = document.createElement('div');
  2582. elt.className = classname;
  2583. return elt;
  2584. };
  2585. /**
  2586. * Updates the states of the given undo/redo items.
  2587. */
  2588. EditorUi.prototype.addSplitHandler = function(elt, horizontal, dx, onChange)
  2589. {
  2590. var start = null;
  2591. var initial = null;
  2592. var ignoreClick = true;
  2593. var last = null;
  2594. // Disables built-in pan and zoom in IE10 and later
  2595. if (mxClient.IS_POINTER)
  2596. {
  2597. elt.style.touchAction = 'none';
  2598. }
  2599. var getValue = mxUtils.bind(this, function()
  2600. {
  2601. var result = parseInt(((horizontal) ? elt.style.left : elt.style.bottom));
  2602. // Takes into account hidden footer
  2603. if (!horizontal)
  2604. {
  2605. result = result + dx - this.footerHeight;
  2606. }
  2607. return result;
  2608. });
  2609. function moveHandler(evt)
  2610. {
  2611. if (start != null)
  2612. {
  2613. var pt = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2614. onChange(Math.max(0, initial + ((horizontal) ? (pt.x - start.x) : (start.y - pt.y)) - dx));
  2615. mxEvent.consume(evt);
  2616. if (initial != getValue())
  2617. {
  2618. ignoreClick = true;
  2619. last = null;
  2620. }
  2621. }
  2622. };
  2623. function dropHandler(evt)
  2624. {
  2625. moveHandler(evt);
  2626. initial = null;
  2627. start = null;
  2628. };
  2629. mxEvent.addGestureListeners(elt, function(evt)
  2630. {
  2631. start = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2632. initial = getValue();
  2633. ignoreClick = false;
  2634. mxEvent.consume(evt);
  2635. });
  2636. mxEvent.addListener(elt, 'click', function(evt)
  2637. {
  2638. if (!ignoreClick)
  2639. {
  2640. var next = (last != null) ? last - dx : 0;
  2641. last = getValue();
  2642. onChange(next);
  2643. mxEvent.consume(evt);
  2644. }
  2645. });
  2646. mxEvent.addGestureListeners(document, null, moveHandler, dropHandler);
  2647. this.destroyFunctions.push(function()
  2648. {
  2649. mxEvent.removeGestureListeners(document, null, moveHandler, dropHandler);
  2650. });
  2651. };
  2652. /**
  2653. * Displays a print dialog.
  2654. */
  2655. EditorUi.prototype.showDialog = function(elt, w, h, modal, closable, onClose)
  2656. {
  2657. this.editor.graph.tooltipHandler.hideTooltip();
  2658. if (this.dialogs == null)
  2659. {
  2660. this.dialogs = [];
  2661. }
  2662. this.dialog = new Dialog(this, elt, w, h, modal, closable, onClose);
  2663. this.dialogs.push(this.dialog);
  2664. };
  2665. /**
  2666. * Displays a print dialog.
  2667. */
  2668. EditorUi.prototype.hideDialog = function(cancel)
  2669. {
  2670. if (this.dialogs != null && this.dialogs.length > 0)
  2671. {
  2672. var dlg = this.dialogs.pop();
  2673. dlg.close(cancel);
  2674. this.dialog = (this.dialogs.length > 0) ? this.dialogs[this.dialogs.length - 1] : null;
  2675. if (this.dialog == null && this.editor.graph.container.style.visibility != 'hidden')
  2676. {
  2677. this.editor.graph.container.focus();
  2678. }
  2679. this.editor.fireEvent(new mxEventObject('hideDialog'));
  2680. }
  2681. };
  2682. /**
  2683. * Display a color dialog.
  2684. */
  2685. EditorUi.prototype.pickColor = function(color, apply)
  2686. {
  2687. var graph = this.editor.graph;
  2688. var selState = graph.cellEditor.saveSelection();
  2689. var dlg = new ColorDialog(this, color || 'none', function(color)
  2690. {
  2691. graph.cellEditor.restoreSelection(selState);
  2692. apply(color);
  2693. }, function()
  2694. {
  2695. graph.cellEditor.restoreSelection(selState);
  2696. });
  2697. this.showDialog(dlg.container, 220, 430, true, false);
  2698. dlg.init();
  2699. };
  2700. /**
  2701. * Adds the label menu items to the given menu and parent.
  2702. */
  2703. EditorUi.prototype.openFile = function()
  2704. {
  2705. // Closes dialog after open
  2706. window.openFile = new OpenFile(mxUtils.bind(this, function(cancel)
  2707. {
  2708. this.hideDialog(cancel);
  2709. }));
  2710. // Removes openFile if dialog is closed
  2711. this.showDialog(new OpenDialog(this).container, (Editor.useLocalStorage) ? 640 : 320,
  2712. (Editor.useLocalStorage) ? 480 : 220, true, true, function()
  2713. {
  2714. window.openFile = null;
  2715. });
  2716. };
  2717. /**
  2718. * Extracs the graph model from the given HTML data from a data transfer event.
  2719. */
  2720. EditorUi.prototype.extractGraphModelFromHtml = function(data)
  2721. {
  2722. var result = null;
  2723. try
  2724. {
  2725. var idx = data.indexOf('&lt;mxGraphModel ');
  2726. if (idx >= 0)
  2727. {
  2728. var idx2 = data.lastIndexOf('&lt;/mxGraphModel&gt;');
  2729. if (idx2 > idx)
  2730. {
  2731. result = data.substring(idx, idx2 + 21).replace(/&gt;/g, '>').
  2732. replace(/&lt;/g, '<').replace(/\\&quot;/g, '"').replace(/\n/g, '');
  2733. }
  2734. }
  2735. }
  2736. catch (e)
  2737. {
  2738. // ignore
  2739. }
  2740. return result;
  2741. };
  2742. /**
  2743. * Opens the given files in the editor.
  2744. */
  2745. EditorUi.prototype.extractGraphModelFromEvent = function(evt)
  2746. {
  2747. var result = null;
  2748. var data = null;
  2749. if (evt != null)
  2750. {
  2751. var provider = (evt.dataTransfer != null) ? evt.dataTransfer : evt.clipboardData;
  2752. if (provider != null)
  2753. {
  2754. if (document.documentMode == 10 || document.documentMode == 11)
  2755. {
  2756. data = provider.getData('Text');
  2757. }
  2758. else
  2759. {
  2760. data = (mxUtils.indexOf(provider.types, 'text/html') >= 0) ? provider.getData('text/html') : null;
  2761. if (mxUtils.indexOf(provider.types, 'text/plain' && (data == null || data.length == 0)))
  2762. {
  2763. data = provider.getData('text/plain');
  2764. }
  2765. }
  2766. if (data != null)
  2767. {
  2768. data = this.editor.graph.zapGremlins(mxUtils.trim(data));
  2769. // Tries parsing as HTML document with embedded XML
  2770. var xml = this.extractGraphModelFromHtml(data);
  2771. if (xml != null)
  2772. {
  2773. data = xml;
  2774. }
  2775. }
  2776. }
  2777. }
  2778. if (data != null && this.isCompatibleString(data))
  2779. {
  2780. result = data;
  2781. }
  2782. return result;
  2783. };
  2784. /**
  2785. * Hook for subclassers to return true if event data is a supported format.
  2786. * This implementation always returns false.
  2787. */
  2788. EditorUi.prototype.isCompatibleString = function(data)
  2789. {
  2790. return false;
  2791. };
  2792. /**
  2793. * Adds the label menu items to the given menu and parent.
  2794. */
  2795. EditorUi.prototype.saveFile = function(forceDialog)
  2796. {
  2797. if (!forceDialog && this.editor.filename != null)
  2798. {
  2799. this.save(this.editor.getOrCreateFilename());
  2800. }
  2801. else
  2802. {
  2803. var dlg = new FilenameDialog(this, this.editor.getOrCreateFilename(), mxResources.get('save'), mxUtils.bind(this, function(name)
  2804. {
  2805. this.save(name);
  2806. }), null, mxUtils.bind(this, function(name)
  2807. {
  2808. if (name != null && name.length > 0)
  2809. {
  2810. return true;
  2811. }
  2812. mxUtils.confirm(mxResources.get('invalidName'));
  2813. return false;
  2814. }));
  2815. this.showDialog(dlg.container, 300, 100, true, true);
  2816. dlg.init();
  2817. }
  2818. };
  2819. /**
  2820. * Saves the current graph under the given filename.
  2821. */
  2822. EditorUi.prototype.save = function(name)
  2823. {
  2824. if (name != null)
  2825. {
  2826. if (this.editor.graph.isEditing())
  2827. {
  2828. this.editor.graph.stopEditing();
  2829. }
  2830. var xml = mxUtils.getXml(this.editor.getGraphXml());
  2831. try
  2832. {
  2833. if (Editor.useLocalStorage)
  2834. {
  2835. if (localStorage.getItem(name) != null &&
  2836. !mxUtils.confirm(mxResources.get('replaceIt', [name])))
  2837. {
  2838. return;
  2839. }
  2840. localStorage.setItem(name, xml);
  2841. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('saved')) + ' ' + new Date());
  2842. }
  2843. else
  2844. {
  2845. if (xml.length < MAX_REQUEST_SIZE)
  2846. {
  2847. new mxXmlRequest(SAVE_URL, 'filename=' + encodeURIComponent(name) +
  2848. '&xml=' + encodeURIComponent(xml)).simulate(document, '_blank');
  2849. }
  2850. else
  2851. {
  2852. mxUtils.alert(mxResources.get('drawingTooLarge'));
  2853. mxUtils.popup(xml);
  2854. return;
  2855. }
  2856. }
  2857. this.editor.setModified(false);
  2858. this.editor.setFilename(name);
  2859. this.updateDocumentTitle();
  2860. }
  2861. catch (e)
  2862. {
  2863. this.editor.setStatus(mxUtils.htmlEntities(mxResources.get('errorSavingFile')));
  2864. }
  2865. }
  2866. };
  2867. /**
  2868. * Executes the given layout.
  2869. */
  2870. EditorUi.prototype.executeLayout = function(exec, animate, post)
  2871. {
  2872. var graph = this.editor.graph;
  2873. if (graph.isEnabled())
  2874. {
  2875. graph.getModel().beginUpdate();
  2876. try
  2877. {
  2878. exec();
  2879. }
  2880. catch (e)
  2881. {
  2882. throw e;
  2883. }
  2884. finally
  2885. {
  2886. // Animates the changes in the graph model except
  2887. // for Camino, where animation is too slow
  2888. if (this.allowAnimation && animate && navigator.userAgent.indexOf('Camino') < 0)
  2889. {
  2890. // New API for animating graph layout results asynchronously
  2891. var morph = new mxMorphing(graph);
  2892. morph.addListener(mxEvent.DONE, mxUtils.bind(this, function()
  2893. {
  2894. graph.getModel().endUpdate();
  2895. if (post != null)
  2896. {
  2897. post();
  2898. }
  2899. }));
  2900. morph.startAnimation();
  2901. }
  2902. else
  2903. {
  2904. graph.getModel().endUpdate();
  2905. if (post != null)
  2906. {
  2907. post();
  2908. }
  2909. }
  2910. }
  2911. }
  2912. };
  2913. /**
  2914. * Hides the current menu.
  2915. */
  2916. EditorUi.prototype.showImageDialog = function(title, value, fn, ignoreExisting)
  2917. {
  2918. var cellEditor = this.editor.graph.cellEditor;
  2919. var selState = cellEditor.saveSelection();
  2920. var newValue = mxUtils.prompt(title, value);
  2921. cellEditor.restoreSelection(selState);
  2922. if (newValue != null && newValue.length > 0)
  2923. {
  2924. var img = new Image();
  2925. img.onload = function()
  2926. {
  2927. fn(newValue, img.width, img.height);
  2928. };
  2929. img.onerror = function()
  2930. {
  2931. fn(null);
  2932. mxUtils.alert(mxResources.get('fileNotFound'));
  2933. };
  2934. img.src = newValue;
  2935. }
  2936. else
  2937. {
  2938. fn(null);
  2939. }
  2940. };
  2941. /**
  2942. * Hides the current menu.
  2943. */
  2944. EditorUi.prototype.showLinkDialog = function(value, btnLabel, fn)
  2945. {
  2946. var dlg = new LinkDialog(this, value, btnLabel, fn);
  2947. this.showDialog(dlg.container, 420, 90, true, true);
  2948. dlg.init();
  2949. };
  2950. /**
  2951. * Hides the current menu.
  2952. */
  2953. EditorUi.prototype.showBackgroundImageDialog = function(apply)
  2954. {
  2955. apply = (apply != null) ? apply : mxUtils.bind(this, function(image)
  2956. {
  2957. var change = new ChangeGraphBackground(this, null, image);
  2958. change.ignoreColor = true;
  2959. this.editor.graph.model.execute(change);
  2960. });
  2961. var newValue = mxUtils.prompt(mxResources.get('backgroundImage'), '');
  2962. if (newValue != null && newValue.length > 0)
  2963. {
  2964. var img = new Image();
  2965. img.onload = function()
  2966. {
  2967. apply(new mxImage(newValue, img.width, img.height));
  2968. };
  2969. img.onerror = function()
  2970. {
  2971. apply(null);
  2972. mxUtils.alert(mxResources.get('fileNotFound'));
  2973. };
  2974. img.src = newValue;
  2975. }
  2976. else
  2977. {
  2978. apply(null);
  2979. }
  2980. };
  2981. /**
  2982. * Loads the stylesheet for this graph.
  2983. */
  2984. EditorUi.prototype.setBackgroundImage = function(image)
  2985. {
  2986. this.editor.graph.setBackgroundImage(image);
  2987. this.editor.graph.view.validateBackgroundImage();
  2988. this.fireEvent(new mxEventObject('backgroundImageChanged'));
  2989. };
  2990. /**
  2991. * Creates the keyboard event handler for the current graph and history.
  2992. */
  2993. EditorUi.prototype.confirm = function(msg, okFn, cancelFn)
  2994. {
  2995. if (mxUtils.confirm(msg))
  2996. {
  2997. if (okFn != null)
  2998. {
  2999. okFn();
  3000. }
  3001. }
  3002. else if (cancelFn != null)
  3003. {
  3004. cancelFn();
  3005. }
  3006. };
  3007. /**
  3008. * Creates the keyboard event handler for the current graph and history.
  3009. */
  3010. EditorUi.prototype.createOutline = function(wnd)
  3011. {
  3012. var outline = new mxOutline(this.editor.graph);
  3013. outline.border = 20;
  3014. mxEvent.addListener(window, 'resize', function()
  3015. {
  3016. outline.update();
  3017. });
  3018. this.addListener('pageFormatChanged', function()
  3019. {
  3020. outline.update();
  3021. });
  3022. return outline;
  3023. };
  3024. /**
  3025. * Creates the keyboard event handler for the current graph and history.
  3026. */
  3027. EditorUi.prototype.createKeyHandler = function(editor)
  3028. {
  3029. var editorUi = this;
  3030. var graph = this.editor.graph;
  3031. var keyHandler = new mxKeyHandler(graph);
  3032. var isEventIgnored = keyHandler.isEventIgnored;
  3033. keyHandler.isEventIgnored = function(evt)
  3034. {
  3035. // Handles undo/redo/ctrl+./,/u via action and allows ctrl+b/i only if editing value is HTML (except for FF and Safari)
  3036. return (!this.isControlDown(evt) || mxEvent.isShiftDown(evt) || (evt.keyCode != 90 && evt.keyCode != 89 &&
  3037. evt.keyCode != 188 && evt.keyCode != 190 && evt.keyCode != 85)) && ((evt.keyCode != 66 && evt.keyCode != 73) ||
  3038. !this.isControlDown(evt) || (this.graph.cellEditor.isContentEditing() && !mxClient.IS_FF && !mxClient.IS_SF)) &&
  3039. isEventIgnored.apply(this, arguments);
  3040. };
  3041. // Ignores graph enabled state but not chromeless state
  3042. keyHandler.isEnabledForEvent = function(evt)
  3043. {
  3044. return (!mxEvent.isConsumed(evt) && this.isGraphEvent(evt) && this.isEnabled());
  3045. };
  3046. // Routes command-key to control-key on Mac
  3047. keyHandler.isControlDown = function(evt)
  3048. {
  3049. return mxEvent.isControlDown(evt) || (mxClient.IS_MAC && evt.metaKey);
  3050. };
  3051. var queue = [];
  3052. var thread = null;
  3053. // Helper function to move cells with the cursor keys
  3054. function nudge(keyCode, stepSize, resize)
  3055. {
  3056. queue.push(function()
  3057. {
  3058. if (!graph.isSelectionEmpty() && graph.isEnabled())
  3059. {
  3060. stepSize = (stepSize != null) ? stepSize : 1;
  3061. if (resize)
  3062. {
  3063. // Resizes all selected vertices
  3064. graph.getModel().beginUpdate();
  3065. try
  3066. {
  3067. var cells = graph.getSelectionCells();
  3068. for (var i = 0; i < cells.length; i++)
  3069. {
  3070. if (graph.getModel().isVertex(cells[i]) && graph.isCellResizable(cells[i]))
  3071. {
  3072. var geo = graph.getCellGeometry(cells[i]);
  3073. if (geo != null)
  3074. {
  3075. geo = geo.clone();
  3076. if (keyCode == 37)
  3077. {
  3078. geo.width = Math.max(0, geo.width - stepSize);
  3079. }
  3080. else if (keyCode == 38)
  3081. {
  3082. geo.height = Math.max(0, geo.height - stepSize);
  3083. }
  3084. else if (keyCode == 39)
  3085. {
  3086. geo.width += stepSize;
  3087. }
  3088. else if (keyCode == 40)
  3089. {
  3090. geo.height += stepSize;
  3091. }
  3092. graph.getModel().setGeometry(cells[i], geo);
  3093. }
  3094. }
  3095. }
  3096. }
  3097. finally
  3098. {
  3099. graph.getModel().endUpdate();
  3100. }
  3101. }
  3102. else
  3103. {
  3104. // Moves vertices up/down in a stack layout
  3105. var cell = graph.getSelectionCell();
  3106. var parent = graph.model.getParent(cell);
  3107. var layout = null;
  3108. if (graph.getSelectionCount() == 1 && graph.model.isVertex(cell) &&
  3109. graph.layoutManager != null && !graph.isCellLocked(cell))
  3110. {
  3111. layout = graph.layoutManager.getLayout(parent);
  3112. }
  3113. if (layout != null && layout.constructor == mxStackLayout)
  3114. {
  3115. var index = parent.getIndex(cell);
  3116. if (keyCode == 37 || keyCode == 38)
  3117. {
  3118. graph.model.add(parent, cell, Math.max(0, index - 1));
  3119. }
  3120. else if (keyCode == 39 ||keyCode == 40)
  3121. {
  3122. graph.model.add(parent, cell, Math.min(graph.model.getChildCount(parent), index + 1));
  3123. }
  3124. }
  3125. else
  3126. {
  3127. var dx = 0;
  3128. var dy = 0;
  3129. if (keyCode == 37)
  3130. {
  3131. dx = -stepSize;
  3132. }
  3133. else if (keyCode == 38)
  3134. {
  3135. dy = -stepSize;
  3136. }
  3137. else if (keyCode == 39)
  3138. {
  3139. dx = stepSize;
  3140. }
  3141. else if (keyCode == 40)
  3142. {
  3143. dy = stepSize;
  3144. }
  3145. graph.moveCells(graph.getMovableCells(graph.getSelectionCells()), dx, dy);
  3146. }
  3147. }
  3148. }
  3149. });
  3150. if (thread != null)
  3151. {
  3152. window.clearTimeout(thread);
  3153. }
  3154. thread = window.setTimeout(function()
  3155. {
  3156. if (queue.length > 0)
  3157. {
  3158. graph.getModel().beginUpdate();
  3159. try
  3160. {
  3161. for (var i = 0; i < queue.length; i++)
  3162. {
  3163. queue[i]();
  3164. }
  3165. queue = [];
  3166. }
  3167. finally
  3168. {
  3169. graph.getModel().endUpdate();
  3170. }
  3171. graph.scrollCellToVisible(graph.getSelectionCell());
  3172. }
  3173. }, 200);
  3174. };
  3175. // Overridden to handle special alt+shift+cursor keyboard shortcuts
  3176. var directions = {37: mxConstants.DIRECTION_WEST, 38: mxConstants.DIRECTION_NORTH,
  3177. 39: mxConstants.DIRECTION_EAST, 40: mxConstants.DIRECTION_SOUTH};
  3178. var keyHandlerGetFunction = keyHandler.getFunction;
  3179. // Alt+Shift+Keycode mapping to action
  3180. var altShiftActions = {67: this.actions.get('clearWaypoints'), // Alt+Shift+C
  3181. 65: this.actions.get('connectionArrows'), // Alt+Shift+A
  3182. 80: this.actions.get('connectionPoints') // Alt+Shift+P
  3183. };
  3184. mxKeyHandler.prototype.getFunction = function(evt)
  3185. {
  3186. if (graph.isEnabled())
  3187. {
  3188. // TODO: Add alt modified state in core API, here are some specific cases
  3189. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3190. {
  3191. var action = altShiftActions[evt.keyCode];
  3192. if (action != null)
  3193. {
  3194. return action.funct;
  3195. }
  3196. }
  3197. if (evt.keyCode == 9 && mxEvent.isAltDown(evt))
  3198. {
  3199. if (mxEvent.isShiftDown(evt))
  3200. {
  3201. // Alt+Shift+Tab
  3202. return function()
  3203. {
  3204. graph.selectParentCell();
  3205. };
  3206. }
  3207. else
  3208. {
  3209. // Alt+Tab
  3210. return function()
  3211. {
  3212. graph.selectChildCell();
  3213. };
  3214. }
  3215. }
  3216. else if (directions[evt.keyCode] != null && !graph.isSelectionEmpty())
  3217. {
  3218. if (mxEvent.isShiftDown(evt) && mxEvent.isAltDown(evt))
  3219. {
  3220. if (graph.model.isVertex(graph.getSelectionCell()))
  3221. {
  3222. return function()
  3223. {
  3224. var cells = graph.connectVertex(graph.getSelectionCell(), directions[evt.keyCode],
  3225. graph.defaultEdgeLength, evt, true);
  3226. if (cells != null && cells.length > 0)
  3227. {
  3228. if (cells.length == 1 && graph.model.isEdge(cells[0]))
  3229. {
  3230. graph.setSelectionCell(graph.model.getTerminal(cells[0], false));
  3231. }
  3232. else
  3233. {
  3234. graph.setSelectionCell(cells[cells.length - 1]);
  3235. }
  3236. if (editorUi.hoverIcons != null)
  3237. {
  3238. editorUi.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  3239. }
  3240. }
  3241. };
  3242. }
  3243. }
  3244. else
  3245. {
  3246. // Avoids consuming event if no vertex is selected by returning null below
  3247. // Cursor keys move and resize (ctrl) cells
  3248. if (this.isControlDown(evt))
  3249. {
  3250. return function()
  3251. {
  3252. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null, true);
  3253. };
  3254. }
  3255. else
  3256. {
  3257. return function()
  3258. {
  3259. nudge(evt.keyCode, (mxEvent.isShiftDown(evt)) ? graph.gridSize : null);
  3260. };
  3261. }
  3262. }
  3263. }
  3264. }
  3265. return keyHandlerGetFunction.apply(this, arguments);
  3266. };
  3267. // Binds keystrokes to actions
  3268. keyHandler.bindAction = mxUtils.bind(this, function(code, control, key, shift)
  3269. {
  3270. var action = this.actions.get(key);
  3271. if (action != null)
  3272. {
  3273. var f = function()
  3274. {
  3275. if (action.isEnabled())
  3276. {
  3277. action.funct();
  3278. }
  3279. };
  3280. if (control)
  3281. {
  3282. if (shift)
  3283. {
  3284. keyHandler.bindControlShiftKey(code, f);
  3285. }
  3286. else
  3287. {
  3288. keyHandler.bindControlKey(code, f);
  3289. }
  3290. }
  3291. else
  3292. {
  3293. if (shift)
  3294. {
  3295. keyHandler.bindShiftKey(code, f);
  3296. }
  3297. else
  3298. {
  3299. keyHandler.bindKey(code, f);
  3300. }
  3301. }
  3302. }
  3303. });
  3304. var ui = this;
  3305. var keyHandlerEscape = keyHandler.escape;
  3306. keyHandler.escape = function(evt)
  3307. {
  3308. keyHandlerEscape.apply(this, arguments);
  3309. };
  3310. // Ignores enter keystroke. Remove this line if you want the
  3311. // enter keystroke to stop editing. N, W, T are reserved.
  3312. keyHandler.enter = function() {};
  3313. keyHandler.bindControlShiftKey(36, function() { graph.exitGroup(); }); // Ctrl+Shift+Home
  3314. keyHandler.bindControlShiftKey(35, function() { graph.enterGroup(); }); // Ctrl+Shift+End
  3315. keyHandler.bindKey(36, function() { graph.home(); }); // Home
  3316. keyHandler.bindKey(35, function() { graph.refresh(); }); // End
  3317. keyHandler.bindAction(107, true, 'zoomIn'); // Ctrl+Plus
  3318. keyHandler.bindAction(109, true, 'zoomOut'); // Ctrl+Minus
  3319. keyHandler.bindAction(80, true, 'print'); // Ctrl+P
  3320. keyHandler.bindAction(79, true, 'outline', true); // Ctrl+Shift+O
  3321. keyHandler.bindAction(112, false, 'about'); // F1
  3322. if (!this.editor.chromeless)
  3323. {
  3324. keyHandler.bindControlKey(36, function() { if (graph.isEnabled()) { graph.foldCells(true); }}); // Ctrl+Home
  3325. keyHandler.bindControlKey(35, function() { if (graph.isEnabled()) { graph.foldCells(false); }}); // Ctrl+End
  3326. keyHandler.bindControlKey(13, function() { if (graph.isEnabled()) { graph.setSelectionCells(graph.duplicateCells(graph.getSelectionCells(), false)); }}); // Ctrl+Enter
  3327. keyHandler.bindAction(8, false, 'delete'); // Backspace
  3328. keyHandler.bindAction(8, true, 'deleteAll'); // Backspace
  3329. keyHandler.bindAction(46, false, 'delete'); // Delete
  3330. keyHandler.bindAction(46, true, 'deleteAll'); // Ctrl+Delete
  3331. keyHandler.bindAction(72, true, 'resetView'); // Ctrl+H
  3332. keyHandler.bindAction(72, true, 'fitWindow', true); // Ctrl+Shift+H
  3333. keyHandler.bindAction(74, true, 'fitPage'); // Ctrl+J
  3334. keyHandler.bindAction(74, true, 'fitTwoPages', true); // Ctrl+Shift+J
  3335. keyHandler.bindAction(48, true, 'customZoom'); // Ctrl+0
  3336. keyHandler.bindAction(82, true, 'turn'); // Ctrl+R
  3337. keyHandler.bindAction(82, true, 'clearDefaultStyle', true); // Ctrl+Shift+R
  3338. keyHandler.bindAction(83, true, 'save'); // Ctrl+S
  3339. keyHandler.bindAction(83, true, 'saveAs', true); // Ctrl+Shift+S
  3340. keyHandler.bindAction(65, true, 'selectAll'); // Ctrl+A
  3341. keyHandler.bindAction(65, true, 'selectNone', true); // Ctrl+A
  3342. keyHandler.bindAction(73, true, 'selectVertices', true); // Ctrl+Shift+I
  3343. keyHandler.bindAction(69, true, 'selectEdges', true); // Ctrl+Shift+E
  3344. keyHandler.bindAction(69, true, 'editStyle'); // Ctrl+E
  3345. keyHandler.bindAction(66, true, 'bold'); // Ctrl+B
  3346. keyHandler.bindAction(66, true, 'toBack', true); // Ctrl+Shift+B
  3347. keyHandler.bindAction(70, true, 'toFront', true); // Ctrl+Shift+F
  3348. keyHandler.bindAction(68, true, 'duplicate'); // Ctrl+D
  3349. keyHandler.bindAction(68, true, 'setAsDefaultStyle', true); // Ctrl+Shift+D
  3350. keyHandler.bindAction(90, true, 'undo'); // Ctrl+Z
  3351. keyHandler.bindAction(89, true, 'autosize', true); // Ctrl+Shift+Y
  3352. keyHandler.bindAction(88, true, 'cut'); // Ctrl+X
  3353. keyHandler.bindAction(67, true, 'copy'); // Ctrl+C
  3354. keyHandler.bindAction(86, true, 'paste'); // Ctrl+V
  3355. keyHandler.bindAction(71, true, 'group'); // Ctrl+G
  3356. keyHandler.bindAction(77, true, 'editData'); // Ctrl+M
  3357. keyHandler.bindAction(71, true, 'grid', true); // Ctrl+Shift+G
  3358. keyHandler.bindAction(73, true, 'italic'); // Ctrl+I
  3359. keyHandler.bindAction(76, true, 'lockUnlock'); // Ctrl+L
  3360. keyHandler.bindAction(76, true, 'layers', true); // Ctrl+Shift+L
  3361. keyHandler.bindAction(80, true, 'formatPanel', true); // Ctrl+Shift+P
  3362. keyHandler.bindAction(85, true, 'underline'); // Ctrl+U
  3363. keyHandler.bindAction(85, true, 'ungroup', true); // Ctrl+Shift+U
  3364. keyHandler.bindAction(190, true, 'superscript'); // Ctrl+.
  3365. keyHandler.bindAction(188, true, 'subscript'); // Ctrl+,
  3366. keyHandler.bindKey(13, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // Enter
  3367. keyHandler.bindKey(113, function() { if (graph.isEnabled()) { graph.startEditingAtCell(); }}); // F2
  3368. }
  3369. if (!mxClient.IS_WIN)
  3370. {
  3371. keyHandler.bindAction(90, true, 'redo', true); // Ctrl+Shift+Z
  3372. }
  3373. else
  3374. {
  3375. keyHandler.bindAction(89, true, 'redo'); // Ctrl+Y
  3376. }
  3377. return keyHandler;
  3378. };
  3379. /**
  3380. * Creates the keyboard event handler for the current graph and history.
  3381. */
  3382. EditorUi.prototype.destroy = function()
  3383. {
  3384. if (this.editor != null)
  3385. {
  3386. this.editor.destroy();
  3387. this.editor = null;
  3388. }
  3389. if (this.menubar != null)
  3390. {
  3391. this.menubar.destroy();
  3392. this.menubar = null;
  3393. }
  3394. if (this.toolbar != null)
  3395. {
  3396. this.toolbar.destroy();
  3397. this.toolbar = null;
  3398. }
  3399. if (this.sidebar != null)
  3400. {
  3401. this.sidebar.destroy();
  3402. this.sidebar = null;
  3403. }
  3404. if (this.keyHandler != null)
  3405. {
  3406. this.keyHandler.destroy();
  3407. this.keyHandler = null;
  3408. }
  3409. if (this.keydownHandler != null)
  3410. {
  3411. mxEvent.removeListener(document, 'keydown', this.keydownHandler);
  3412. this.keydownHandler = null;
  3413. }
  3414. if (this.keyupHandler != null)
  3415. {
  3416. mxEvent.removeListener(document, 'keyup', this.keyupHandler);
  3417. this.keyupHandler = null;
  3418. }
  3419. if (this.resizeHandler != null)
  3420. {
  3421. mxEvent.removeListener(window, 'resize', this.resizeHandler);
  3422. this.resizeHandler = null;
  3423. }
  3424. if (this.gestureHandler != null)
  3425. {
  3426. mxEvent.removeGestureListeners(document, this.gestureHandler);
  3427. this.gestureHandler = null;
  3428. }
  3429. if (this.orientationChangeHandler != null)
  3430. {
  3431. mxEvent.removeListener(window, 'orientationchange', this.orientationChangeHandler);
  3432. this.orientationChangeHandler = null;
  3433. }
  3434. if (this.scrollHandler != null)
  3435. {
  3436. mxEvent.removeListener(window, 'scroll', this.scrollHandler);
  3437. this.scrollHandler = null;
  3438. }
  3439. if (this.destroyFunctions != null)
  3440. {
  3441. for (var i = 0; i < this.destroyFunctions.length; i++)
  3442. {
  3443. this.destroyFunctions[i]();
  3444. }
  3445. this.destroyFunctions = null;
  3446. }
  3447. var c = [this.menubarContainer, this.toolbarContainer, this.sidebarContainer,
  3448. this.formatContainer, this.diagramContainer, this.footerContainer,
  3449. this.chromelessToolbar, this.hsplit, this.sidebarFooterContainer,
  3450. this.layersDialog];
  3451. for (var i = 0; i < c.length; i++)
  3452. {
  3453. if (c[i] != null && c[i].parentNode != null)
  3454. {
  3455. c[i].parentNode.removeChild(c[i]);
  3456. }
  3457. }
  3458. };