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