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