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.propsInit();
36         this.listenerInit();
37     }
38
39
40     // left tree
41
42     public void leftTreeInit()
43     {
44          
45         this.left_tree = new Xcls_WindowLeftTree();
46         this.left_tree.ref();
47         this.left_tree.main_window = _this.win;
48         
49         this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
50         this.left_tree.el.show_all();
51        
52         this.left_tree.before_node_change.connect(() => {
53             return this.leftTreeBeforeChange();
54
55         });
56
57         this.left_tree.node_selected.connect((sel) => {
58             this.leftTreeNodeSelected(sel);
59         });
60  
61         this.left_tree.changed.connect(() => {
62             this.window_rooview.requestRedraw();
63             this.left_tree.model.file.save();
64         });
65      
66     }
67
68     public bool leftTreeBeforeChange(JsRender.Node? sel)
69     {
70         if (this.state != "codeedit") {
71             this.left_props.finish_editing();
72             return true;
73         }
74         if (!this.code_editor.saveContents()) {
75             return false;
76         }
77         return false;
78     }
79     
80     public void leftTreeNodeSelected(JsRender.Node? sel)
81     {
82
83         print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
84
85         if (sel == null) {
86             this.left_props.el.hide();
87         } 
88         this.left_props.el.show();
89         this.left_props.load(this.left_tree.getActiveFile(), sel);
90         switch (this.state) {
91             
92             case State.OBJECT: 
93                   
94                  if (sel == null) {
95                     this.rightpalete.clear();
96                     break;
97                 }
98                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
99                 break;
100                  
101                 
102            case State.PROP:
103                 if (sel == null) {
104                     this.add_props.clear();
105                     break;
106                 }
107                 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
108                 break;
109
110             case State.LISTENER:
111            
112                 if (sel == null) {
113                     this.add_props.clear();
114                     break;
115                 }
116                 this.add_props.show(_this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
117                 break;
118             case State.CODEEDIT:
119                 // SAVE FIRST???
120                 
121                 this.codeEditHide();
122                 break;
123                
124                                 
125         }
126          
127
128     }
129     // -----------  properties
130     // listener uses the properties 
131     public void propsInit()
132     {
133         // Add properties
134         this.add_props  = new Xcls_WindowAddProp();
135         this.add_props.ref();  /// really?
136         ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.win.add_props.el);
137         //this.projectsettings.el.show_all();
138
139         var  stage = _this.win.addpropsview.el.get_stage();
140         stage.set_background_color(  Clutter.Color.from_string("#000"));
141
142
143         _this.win.add_props.select.connect( (key,type,skel, etype) => {
144         this.win.left_props.addProp(etype, key, skel, type);
145         });
146         
147     }
148     public void propsShow()
149     {
150
151     }
152     public propsHide()
153     {
154         
155     }
156     
157     // ----------- Add / Edit listener
158     // listener uses the properties 
159     public listenerInit()
160     {
161
162     }
163     public listenerShow()
164     {
165
166     }
167     public listenerHide()
168     {
169         
170     }