159cc50a2cc3e716b784edcd88810b6891155c00.svn-base 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. /*
  7. * Private internal class for reading and applying state
  8. */
  9. Ext.LayoutStateManager = function(layout) {
  10. // default empty state
  11. this.state = {
  12. north : {},
  13. south : {},
  14. east : {},
  15. west : {}
  16. };
  17. };
  18. Ext.LayoutStateManager.prototype = {
  19. init : function(layout, provider) {
  20. this.provider = provider;
  21. var state = provider.get(layout.id + "-layout-state");
  22. if (state) {
  23. var wasUpdating = layout.isUpdating();
  24. if (!wasUpdating) {
  25. layout.beginUpdate();
  26. }
  27. for (var key in state) {
  28. if (typeof state[key] != "function") {
  29. var rstate = state[key];
  30. var r = layout.getRegion(key);
  31. if (r && rstate) {
  32. if (rstate.size) {
  33. r.resizeTo(rstate.size);
  34. }
  35. if (rstate.collapsed == true) {
  36. r.collapse(true);
  37. } else {
  38. r.expand(null, true);
  39. }
  40. }
  41. }
  42. }
  43. if (!wasUpdating) {
  44. layout.endUpdate();
  45. }
  46. this.state = state;
  47. }
  48. this.layout = layout;
  49. layout.on("regionresized", this.onRegionResized, this);
  50. layout.on("regioncollapsed", this.onRegionCollapsed, this);
  51. layout.on("regionexpanded", this.onRegionExpanded, this);
  52. },
  53. storeState : function() {
  54. this.provider.set(this.layout.id + "-layout-state", this.state);
  55. },
  56. onRegionResized : function(region, newSize) {
  57. this.state[region.getPosition()].size = newSize;
  58. this.storeState();
  59. },
  60. onRegionCollapsed : function(region) {
  61. this.state[region.getPosition()].collapsed = true;
  62. this.storeState();
  63. },
  64. onRegionExpanded : function(region) {
  65. this.state[region.getPosition()].collapsed = false;
  66. this.storeState();
  67. }
  68. };