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