src/Builder4/WindowState.vala
[app.Builder.js] / src / Builder4 / WindowState.vala
1 /**
2  * as state management is a bit too complicated inside the builder
3  * it's better to seperate this into this class
4  * 
5  * This class has references to all the Class instances that make up the window..
6  * 
7  */
8 public class WindowState : Object 
9 {
10     public MainWindow win;
11
12     public enum State {
13         OBJECT,
14         PROP,
15         LISTENER,
16         CODEEDIT
17     };
18
19     public State state;
20
21     
22     public Xcls_WindowLeftTree  left_tree;
23     public Xcls_WindowAddProp   add_props;
24     public Xcls_LeftProps       left_props;
25     
26     code_editor
27     rightpalete
28         window_rooview
29         // my vars (def)
30
31     // ctor 
32     public About(MainWindow win)
33     {
34         this.win = win;
35         // initialize
36         this.leftTreeInit();
37         this.propsListInit();
38         this.propsAddInit();
39         this.listenerInit();
40     }
41
42
43     // left tree
44
45     public void leftTreeInit()
46     {
47          
48         this.left_tree = new Xcls_WindowLeftTree();
49         this.left_tree.ref();
50         this.left_tree.main_window = _this.win;
51         
52         this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
53         this.left_tree.el.show_all();
54        
55         this.left_tree.before_node_change.connect(() => {
56             return this.leftTreeBeforeChange();
57
58         });
59
60         this.left_tree.node_selected.connect((sel) => {
61             this.leftTreeNodeSelected(sel);
62         });
63  
64         this.left_tree.changed.connect(() => {
65             this.window_rooview.requestRedraw();
66             this.left_tree.model.file.save();
67         });
68      
69     }
70
71     public bool leftTreeBeforeChange(JsRender.Node? sel)
72     {
73         if (this.state != "codeedit") {
74             this.left_props.finish_editing();
75             return true;
76         }
77         if (!this.code_editor.saveContents()) {
78             return false;
79         }
80         return false;
81     }
82     
83     public void leftTreeNodeSelected(JsRender.Node? sel)
84     {
85
86         print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
87
88         if (sel == null) {
89             this.left_props.el.hide();
90         } 
91         this.left_props.el.show();
92         this.left_props.load(this.left_tree.getActiveFile(), sel);
93         switch (this.state) {
94             
95             case State.OBJECT: 
96                   
97                  if (sel == null) {
98                     this.rightpalete.clear();
99                     break;
100                 }
101                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
102                 break;
103                  
104                 
105            case State.PROP:
106                 if (sel == null) {
107                     this.add_props.clear();
108                     break;
109                 }
110                 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
111                 break;
112
113             case State.LISTENER:
114            
115                 if (sel == null) {
116                     this.add_props.clear();
117                     break;
118                 }
119                 this.add_props.show(_this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
120                 break;
121             case State.CODEEDIT:
122                 // SAVE FIRST???
123                 
124                 this.codeEditHide();
125                 break;
126                
127                                 
128         }
129          
130
131     }
132
133
134
135
136     public void propsListInit()
137     {
138         
139         this.left_props =new Xcls_LeftProps();
140         this.left_props.ref();
141         this.left_props.main_window = _this;
142         this.win.props.el.pack_start(this.left_props.el,true, true,0);
143         this.left_props.el.show_all();
144         
145         this.left_props.show_editor.connect( (file, node, type,  key) => {
146             this.codeEditShow(file, node, type,  key);
147         });
148
149         
150         this.left_props.stop_editor.connect( () => {
151             if (this.state != "codeedit") {
152                 return true;
153             }
154         
155             var ret =  this.code_editor.saveContents();
156             if (!ret) {
157                 return false;
158             }
159             this.codeEditHide();
160             return ret;
161         });
162         
163         this.left_props.changed.connect(() => {
164               if (this.left_tree.getActiveFile().xtype == "Roo" ) {
165                    this.window_rooview.requestRedraw();
166                    
167                } else {
168                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
169               }
170               this.left_tree.model.updateSelected();
171               this.left_tree.model.file.save();
172         });
173         
174
175
176     }
177
178
179     
180     // -----------  properties adding list...
181     // listener uses the properties 
182     public void propsAddInit()
183     {
184         // Add properties
185         this.add_props  = new Xcls_WindowAddProp();
186         this.add_props.ref();  /// really?
187         ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
188         //this.projectsettings.el.show_all();
189
190         var  stage = _this.win.addpropsview.el.get_stage();
191         stage.set_background_color(  Clutter.Color.from_string("#000"));
192
193         
194         this.add_props.select.connect( (key,type,skel, etype) => {
195             this.left_props.addProp(etype, key, skel, type);
196         });
197         
198     }
199     public void propsAddShow()
200     {
201
202     }
203     public void propsAddHide()
204     {
205         
206     }
207     
208     // ----------- Add / Edit listener
209     // listener uses the properties 
210     public void listenerInit()
211     {
212
213     }
214     public void listenerShow()
215     {
216
217     }
218     public void listenerHide()
219     {
220         
221     }