2 * as state management is a bit too complicated inside the builder
3 * it's better to seperate this into this class
5 * This class has references to all the Class instances that make up the window..
8 public class WindowState : Object
10 public Xcls_MainWindow win;
20 PROJECT // project settings..
23 public State state = State.NONE;
25 public bool children_loaded = false;
28 public Xcls_WindowLeftTree left_tree;
29 public Xcls_WindowAddProp add_props;
30 public Xcls_LeftProps left_props;
31 public Xcls_ProjectSettings projectsettings;
32 public ValaProjectSettings vala_projectsettings;
33 public Xcls_RightPalete rightpalete;
34 public Editor code_editor;
35 public Xcls_WindowRooView window_rooview;
36 public Xcls_GtkView window_gladeview;
37 public Xcls_DialogNewComponent new_file_dialog;
38 public Xcls_ClutterFiles clutterfiles;
40 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
42 public WindowState(Xcls_MainWindow win)
51 // on clutter space...
52 this.projectEditInit();
54 this.projectListInit();
64 this.webkitViewInit();
70 this.children_loaded = true;
76 public void leftTreeInit()
79 this.left_tree = new Xcls_WindowLeftTree();
81 this.left_tree.main_window = this.win;
83 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
84 this.left_tree.el.show_all();
86 this.left_tree.before_node_change.connect(() => {
87 return this.leftTreeBeforeChange();
91 this.left_tree.node_selected.connect((sel) => {
92 this.leftTreeNodeSelected(sel);
95 this.left_tree.changed.connect(() => {
96 this.window_rooview.requestRedraw();
97 this.left_tree.model.file.save();
102 public bool leftTreeBeforeChange()
104 if (this.state != State.CODE) {
105 this.left_props.finish_editing();
108 if (!this.code_editor.saveContents()) {
114 public void leftTreeNodeSelected(JsRender.Node? sel)
117 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
120 this.left_props.el.hide();
122 this.left_props.el.show();
123 this.left_props.load(this.left_tree.getActiveFile(), sel);
124 switch (this.state) {
129 this.rightpalete.clear();
132 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
138 this.add_props.clear();
141 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
147 this.add_props.clear();
150 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
154 this.switchState(State.PREVIEW);
167 public void propsListInit()
170 this.left_props =new Xcls_LeftProps();
171 this.left_props.ref();
172 this.left_props.main_window = this.win;
173 this.win.props.el.pack_start(this.left_props.el,true, true,0);
174 this.left_props.el.show_all();
176 this.left_props.show_editor.connect( (file, node, type, key) => {
177 this.switchState(State.CODE);
178 this.code_editor.show(
189 this.left_props.stop_editor.connect( () => {
190 if (this.state != State.CODE) {
194 var ret = this.code_editor.saveContents();
198 this.switchState(State.PREVIEW);
202 this.left_props.changed.connect(() => {
203 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
204 this.win.window_rooview.requestRedraw();
207 this.win.window_gladeview.loadFile(this.left_tree.getActiveFile());
209 this.left_tree.model.updateSelected();
210 this.left_tree.model.file.save();
217 //------------- projects edit
219 public void projectEditInit()
221 this.projectsettings =new Xcls_ProjectSettings();
222 this.projectsettings.ref(); /// really?
224 this.vala_projectsettings =new ValaProjectSettings();
225 this.vala_projectsettings.ref();
226 this.vala_projectsettings.window = this.win;
228 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
229 //this.projectsettings.el.show_all();
231 var stage = this.win.projecteditview.el.get_stage();
232 stage.set_background_color( Clutter.Color.from_string("#000"));
234 this.projectsettings.buttonPressed.connect((btn) => {
235 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
237 this.window_rooview.view.renderJS(true);
239 if (btn == "apply") {
240 this.window_rooview.view.renderJS(true);
244 // do nothing for gtk..
246 if (btn == "save" || btn == "apply") {
247 this.win.project.save();
250 this.switchState (State.PREVIEW);
255 // ----------- object adding
256 public void objectAddInit()
259 this.rightpalete = new Xcls_RightPalete();
260 this.rightpalete.ref(); /// really?
261 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
262 //this.projectsettings.el.show_all();
264 var stage = this.win.objectview.el.get_stage();
265 stage.set_background_color( Clutter.Color.from_string("#000"));
269 // ----------- properties adding list...
270 // listener uses the properties
271 public void propsAddInit()
274 this.add_props = new Xcls_WindowAddProp();
275 this.add_props.ref(); /// really?
276 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
277 //this.projectsettings.el.show_all();
279 var stage = this.win.addpropsview.el.get_stage();
280 stage.set_background_color( Clutter.Color.from_string("#000"));
283 this.add_props.select.connect( (key,type,skel, etype) => {
284 this.left_props.addProp(etype, key, skel, type);
288 public void propsAddShow()
292 public void propsAddHide()
300 // ----------- Add / Edit listener
301 // listener uses the properties
302 //public void listenerInit() { }
303 public void listenerShow()
307 public void listenerHide()
312 // -------------- codeEditor
314 public void codeEditInit()
316 this.code_editor = new Editor();
317 this.code_editor.ref(); /// really?
318 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
319 //this.projectsettings.el.show_all();
321 var stage = this.win.codeeditview.el.get_stage();
322 stage.set_background_color( Clutter.Color.from_string("#000"));
325 this.code_editor.save.connect( () => {
326 this.left_tree.model.file.save();
327 this.left_tree.model.updateSelected();
332 // ----------- list of projects on left
333 public void projectListInit()
336 this.left_projects = new Xcls_WindowLeftProjects();
337 this.left_projects.ref();
338 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
339 this.left_projects.el.show_all();
340 this.left_projects.project_selected.connect((proj) => {
342 this.clutterfiles.loadProject(proj);
347 // ----------- file view
349 public void fileViewInit()
351 var stage = this.win.rooview.el.get_stage(); // seems odd...
352 this.clutterfiles = new Xcls_ClutterFiles();
353 this.clutterfiles.ref();
354 stage.add_child(this.clutterfiles.el);
355 this.clutterfiles.el.show_all();
358 this.clutterfiles.open.connect((file) => {
359 this.fileViewOpen(file);
363 public void fileNewInit()
365 this.new_file_dialog = new Xcls_DialogNewComponent();
366 // force it modal to the main window..
367 this.new_file_dialog.el.set_transient_for(this.win.el);
368 this.new_file_dialog.el.set_modal(true);
370 this.new_file_dialog.success.connect((project,file) =>
372 this.fileViewOpen(file);
378 public void fileViewOpen(JsRender.JsRender file)
380 this.win.project = file.project;
381 this.switchState (State.PREVIEW);
383 this.left_tree.model.loadFile(file);
385 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
386 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
388 if (file.xtype == "Roo" ) {
389 ctr.foreach( (w) => { ctr.remove(w); });
390 ctr_p.foreach( (w) => { ctr_p.remove(w); });
391 ctr.add(this.window_rooview.el);
392 ctr_p.add(this.projectsettings.el);
393 this.window_rooview.loadFile(file);
394 this.window_rooview.el.show_all();
395 this.projectsettings.el.show_all();
398 ctr.foreach( (w) => { ctr.remove(w); });
399 ctr_p.foreach( (w) => { ctr_p.remove(w); });
400 ctr.add(this.window_gladeview.el);
401 ctr_p.add(this.vala_projectsettings.el);
402 this.window_gladeview.loadFile(file);
403 this.window_gladeview.el.show_all();
404 this.vala_projectsettings.el.show_all();
406 print("OPEN : " + file.name);
407 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
408 this.win.setTitle(file.project.name + " : " +file.name);
414 // --------- webkit view
415 public void webkitViewInit()
417 this.window_rooview =new Xcls_WindowRooView();
418 this.window_rooview.ref();
419 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
420 this.window_rooview.el.show_all();
422 var stage = this.win.rooview.el.get_stage();
423 stage.set_background_color( Clutter.Color.from_string("#000"));
428 public void gtkViewInit()
430 this.window_gladeview =new Xcls_GtkView();
431 this.window_gladeview.ref();
434 public void switchState(State new_state)
439 switch (this.state) {
442 if (this.left_tree.getActiveFile() != null) {
443 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
444 this.window_rooview.createThumb();
446 this.window_gladeview.createThumb();
449 // normally we are going from preview to another state.
450 // and different windows hide the preview in differnt ways..
456 this.win.addpropsview.el.save_easing_state();
457 this.win.addpropsview.el.set_scale(0.0f,0.0f);
458 this.win.addpropsview.el.restore_easing_state();
464 this.code_editor.saveContents();
465 this.win.codeeditview.el.save_easing_state();
466 this.win.codeeditview.el.set_scale(0.0f,0.0f);
467 this.win.codeeditview.el.restore_easing_state();
472 this.win.objectview.el.save_easing_state();
473 this.win.objectview.el.set_scale(0.0f,0.0f);
474 this.win.objectview.el.restore_easing_state();
478 this.win.projecteditview.el.save_easing_state();
479 this.win.projecteditview.el.set_scale(0.0f,0.0f);
480 this.win.projecteditview.el.restore_easing_state();
484 this.win.rooview.el.save_easing_state();
485 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
486 this.win.rooview.el.set_scale(1.0f,1.0f);
487 this.win.rooview.el.restore_easing_state();
488 this.clutterfiles.el.hide();
496 var oldstate =this.state;
497 this.state = new_state;
500 this.buttonsShowHide();
502 switch (this.state) {
504 case State.PREVIEW: // this is the default state when working...
505 this.win.editpane.el.show(); // holder for tree and properties..
507 this.left_projects.el.hide();
510 this.win.rooview.el.save_easing_state();
511 this.win.rooview.el.set_scale(1.0f,1.0f);
512 this.win.rooview.el.el.set_opacity(0);
513 this.win.rooview.el.restore_easing_state();
521 var ae = this.left_tree.getActiveElement();
523 this.state = oldstate;
524 this.buttonsShowHide();
527 this.add_props.el.show_all();
529 Palete.factory(this.win.project.xtype),
530 this.state == State.LISTENER ? "signals" : "props",
536 this.win.rooview.el.save_easing_state();
537 // -- FIXME? this needs to be State aware?
538 this.resizeCanvasElements();
539 this.win.rooview.el.restore_easing_state();
542 this.win.addpropsview.el.save_easing_state();
543 this.win.addpropsview.el.set_scale(1.0f,1.0f);
544 this.win.addpropsview.el.restore_easing_state();
549 this.code_editor.el.show_all();
551 // caller needs to call editor - show....
552 this.win.rooview.el.save_easing_state();
553 this.resizeCanvasElements();
554 this.win.rooview.el.restore_easing_state();
557 this.win.codeeditview.el.save_easing_state();
558 this.win.codeeditview.el.set_scale(1.0f,1.0f);
559 this.win.codeeditview.el.restore_easing_state();
564 var n = this.left_tree.getActiveElement();
566 if (this.left_tree.model.file == null) {
567 this.state =oldstate;
568 this.buttonsShowHide();
572 if (n == null && this.left_tree.model.file.tree != null) {
573 this.state = oldstate;
574 this.buttonsShowHide();
578 this.rightpalete.el.show_all();
579 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
581 this.win.rooview.el.save_easing_state();
582 this.resizeCanvasElements();
583 this.win.rooview.el.restore_easing_state();
586 this.win.objectview.el.save_easing_state();
587 this.win.objectview.el.set_scale(1.0f,1.0f);
588 this.win.objectview.el.restore_easing_state();
593 if (this.win.project.xtype == "Roo") {
594 this.projectsettings.el.show_all();
595 this.projectsettings.show(this.win.project);
597 this.vala_projectsettings.el.show_all();
598 this.vala_projectsettings.show((Project.Gtk)this.win.project);
601 this.win.rooview.el.save_easing_state();
602 this.resizeCanvasElements();
603 this.win.rooview.el.restore_easing_state();
605 this.win.projecteditview.el.save_easing_state();
606 this.win.projecteditview.el.set_scale(1.0f,1.0f);
607 this.win.projecteditview.el.restore_easing_state();
610 case State.FILES: // can only get here from PREVIEW state.. in theory..
613 this.win.editpane.el.hide(); // holder for tree and properties..
615 this.left_projects.el.show();
617 var el = this.win.rooview.el;
618 el.save_easing_state();
619 el.set_easing_duration(1000);
621 el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
623 //el.set_scale(0.0f,0.0f);
626 if (this.win.project != null) {
627 this.left_projects.selectProject(this.win.project);
630 el.restore_easing_state();
640 // -- buttons show hide.....
642 public void buttonsShowHide()
644 // basically hide everything, then show the relivant..
646 this.win.backbutton.el.hide();
648 this.win.projectbutton.el.hide(); // show file nav...
649 this.win.editfilebutton.el.hide();
650 this.win.projecteditbutton.el.hide();
653 this.win.objectshowbutton.el.hide(); // add objects
654 this.win.addpropbutton.el.hide();
655 this.win.addlistenerbutton.el.hide();
659 this.win.addprojectbutton.el.hide();
660 this.win.addfilebutton.el.hide();
661 this.win.delprojectbutton.el.hide();
662 this.win.new_window.el.hide();
665 switch (this.state) {
667 case State.PREVIEW: // this is the default state when working...
669 this.win.projectbutton.el.show(); // show file nav...
670 this.win.editfilebutton.el.show();
671 this.win.projecteditbutton.el.show();
674 this.win.objectshowbutton.el.show(); // add objects
675 this.win.addpropbutton.el.show();
676 this.win.addlistenerbutton.el.show();
685 this.win.backbutton.el.show();
686 this.win.objectshowbutton.el.show(); // add objects
687 this.win.addpropbutton.el.show();
688 this.win.addlistenerbutton.el.show();
693 this.win.backbutton.el.show();
698 this.win.backbutton.el.show();
700 this.win.addprojectbutton.el.show();
701 this.win.addfilebutton.el.show();
702 this.win.delprojectbutton.el.show();
703 this.win.new_window.el.show();
709 public int redraw_count = 0;
710 public void resizeCanvas() // called by window resize .. delays redraw
712 var rc = this.redraw_count;
713 this.redraw_count = 2;
715 GLib.Timeout.add(100, () =>{
716 return this.resizeCanvasQueue();
720 public bool resizeCanvasQueue()
722 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
724 if (this.redraw_count < 1) {
725 return false; // should not really happen...
731 if (this.redraw_count > 0) {
732 return true; // do it again in 1 second...
734 // got down to 0 or -1....
735 this.redraw_count = 0;
736 this.resizeCanvasElements();
740 public void resizeCanvasElements()
742 Gtk.Allocation alloc;
743 this.win.clutterembed.el.get_allocation(out alloc);
745 // print("WindowState.resizeCanvasElements\n");
746 if (!this.children_loaded || this.win.clutterembed == null) {
747 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
750 //print("WindowState.resizeCanvasElements = running");
753 // ------- project view appears at top...
756 // ------- add property/object left - max 300px, min 50... (or disapear..)
758 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
759 var palsize = avail < 300.0f ? avail : 300.0f;
760 //print("set palsize size %f\n", palsize);
761 // palate / props : fixed 300 pix
764 // -------- code edit min 600
766 var codesize = avail < 800.0f ? avail : 800.0f;
767 //print("set code size %f\n", codesize);
774 switch ( this.state) {
776 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
780 this.clutterfiles.set_size(alloc.width-50, alloc.height);
784 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
788 this.win.codeeditview.el.set_size(codesize, alloc.height);
789 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
790 this.win.rooview.el.set_scale(scale,scale);
796 this.win.objectview.el.set_size(palsize, alloc.height);
797 this.win.addpropsview.el.set_size(palsize, alloc.height);
798 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
799 this.win.rooview.el.set_scale(scale,scale);