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