try and get ctrl-enter to add a clear all
[roojs1] / Roo / LayoutStateManager.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  
12  
13 /*
14  * Private internal class for reading and applying state
15  */
16 Roo.LayoutStateManager = function(layout){
17      // default empty state
18      this.state = {
19         north: {},
20         south: {},
21         east: {},
22         west: {}       
23     };
24 };
25
26 Roo.LayoutStateManager.prototype = {
27     init : function(layout, provider){
28         this.provider = provider;
29         var state = provider.get(layout.id+"-layout-state");
30         if(state){
31             var wasUpdating = layout.isUpdating();
32             if(!wasUpdating){
33                 layout.beginUpdate();
34             }
35             for(var key in state){
36                 if(typeof state[key] != "function"){
37                     var rstate = state[key];
38                     var r = layout.getRegion(key);
39                     if(r && rstate){
40                         if(rstate.size){
41                             r.resizeTo(rstate.size);
42                         }
43                         if(rstate.collapsed == true){
44                             r.collapse(true);
45                         }else{
46                             r.expand(null, true);
47                         }
48                     }
49                 }
50             }
51             if(!wasUpdating){
52                 layout.endUpdate();
53             }
54             this.state = state; 
55         }
56         this.layout = layout;
57         layout.on("regionresized", this.onRegionResized, this);
58         layout.on("regioncollapsed", this.onRegionCollapsed, this);
59         layout.on("regionexpanded", this.onRegionExpanded, this);
60     },
61     
62     storeState : function(){
63         this.provider.set(this.layout.id+"-layout-state", this.state);
64     },
65     
66     onRegionResized : function(region, newSize){
67         this.state[region.getPosition()].size = newSize;
68         this.storeState();
69     },
70     
71     onRegionCollapsed : function(region){
72         this.state[region.getPosition()].collapsed = true;
73         this.storeState();
74     },
75     
76     onRegionExpanded : function(region){
77         this.state[region.getPosition()].collapsed = false;
78         this.storeState();
79     }
80 };