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_ValaCompileErrors valacompileerrors;
39 public Xcls_ClutterFiles clutterfiles;
41 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
43 public DialogTemplateSelect template_select;
45 public Xcls_PopoverFileDetails file_details;
49 public Xcls_DialogPluginWebkit webkit_plugin;
52 public WindowState(Xcls_MainWindow win)
61 // on clutter space...
62 this.projectEditInit();
64 this.projectListInit();
74 this.webkitViewInit();
78 this.fileDetailsInit();
80 this.webkit_plugin = new Xcls_DialogPluginWebkit();
81 this.template_select = new DialogTemplateSelect();
82 this.children_loaded = true;
88 public void leftTreeInit()
91 this.left_tree = new Xcls_WindowLeftTree();
93 this.left_tree.main_window = this.win;
95 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
96 this.left_tree.el.show_all();
98 this.left_tree.before_node_change.connect(() => {
99 return this.leftTreeBeforeChange();
103 this.left_tree.node_selected.connect((sel) => {
104 this.leftTreeNodeSelected(sel);
107 this.left_tree.changed.connect(() => {
108 this.window_rooview.requestRedraw();
109 this.left_tree.model.file.save();
114 public bool leftTreeBeforeChange()
116 if (this.state != State.CODE) {
117 this.left_props.finish_editing();
120 if (!this.code_editor.saveContents()) {
126 public void leftTreeNodeSelected(JsRender.Node? sel)
129 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
132 this.left_props.el.hide();
134 this.left_props.el.show();
135 this.left_props.load(this.left_tree.getActiveFile(), sel);
136 switch (this.state) {
141 this.rightpalete.clear();
144 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
150 this.add_props.clear();
153 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
159 this.add_props.clear();
162 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
166 this.switchState(State.PREVIEW);
179 public void propsListInit()
182 this.left_props =new Xcls_LeftProps();
183 this.left_props.ref();
184 this.left_props.main_window = this.win;
185 this.win.props.el.pack_start(this.left_props.el,true, true,0);
186 this.left_props.el.show_all();
188 this.left_props.show_editor.connect( (file, node, type, key) => {
189 this.switchState(State.CODE);
190 this.code_editor.show(
201 this.left_props.stop_editor.connect( () => {
202 if (this.state != State.CODE) {
206 var ret = this.code_editor.saveContents();
210 this.switchState(State.PREVIEW);
214 this.left_props.changed.connect(() => {
215 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
216 this.window_rooview.requestRedraw();
219 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
221 this.left_tree.model.updateSelected();
222 this.left_tree.model.file.save();
229 //------------- projects edit
231 public void projectEditInit()
233 this.projectsettings =new Xcls_ProjectSettings();
234 this.projectsettings.ref(); /// really?
236 this.vala_projectsettings =new ValaProjectSettings();
237 this.vala_projectsettings.ref();
238 this.vala_projectsettings.window = this.win;
240 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
241 //this.projectsettings.el.show_all();
243 var stage = this.win.projecteditview.el.get_stage();
244 stage.set_background_color( Clutter.Color.from_string("#000"));
246 this.projectsettings.buttonPressed.connect((btn) => {
247 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
249 this.window_rooview.view.renderJS(true);
251 if (btn == "apply") {
252 this.window_rooview.view.renderJS(true);
256 // do nothing for gtk..
258 if (btn == "save" || btn == "apply") {
259 this.win.project.save();
262 this.switchState (State.PREVIEW);
267 // ----------- object adding
268 public void objectAddInit()
271 this.rightpalete = new Xcls_RightPalete();
272 this.rightpalete.ref(); /// really?
273 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
274 //this.projectsettings.el.show_all();
276 var stage = this.win.objectview.el.get_stage();
277 stage.set_background_color( Clutter.Color.from_string("#000"));
281 // ----------- properties adding list...
282 // listener uses the properties
283 public void propsAddInit()
286 this.add_props = new Xcls_WindowAddProp();
287 this.add_props.ref(); /// really?
288 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
289 //this.projectsettings.el.show_all();
291 var stage = this.win.addpropsview.el.get_stage();
292 stage.set_background_color( Clutter.Color.from_string("#000"));
295 this.add_props.select.connect( (key,type,skel, etype) => {
296 this.left_props.addProp(etype, key, skel, type);
300 public void propsAddShow()
304 public void propsAddHide()
312 // ----------- Add / Edit listener
313 // listener uses the properties
314 //public void listenerInit() { }
315 public void listenerShow()
319 public void listenerHide()
324 // -------------- codeEditor
326 public void codeEditInit()
328 this.code_editor = new Editor();
329 //this.code_editor.ref(); /// really?
330 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
332 this.code_editor.window = this.win;
333 //this.projectsettings.el.show_all();
335 var stage = this.win.codeeditview.el.get_stage();
336 stage.set_background_color( Clutter.Color.from_string("#000"));
339 this.code_editor.save.connect( () => {
340 this.left_tree.model.file.save();
341 this.left_tree.model.updateSelected();
346 // ----------- list of projects on left
347 public void projectListInit()
350 this.left_projects = new Xcls_WindowLeftProjects();
351 this.left_projects.ref();
352 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
353 this.left_projects.el.show_all();
354 this.left_projects.project_selected.connect((proj) => {
355 this.buttonsShowHide();
357 this.clutterfiles.loadProject(proj);
362 // ----------- file view
364 public void fileViewInit()
366 var stage = this.win.rooview.el.get_stage(); // seems odd...
367 this.clutterfiles = new Xcls_ClutterFiles();
368 this.clutterfiles.ref();
369 stage.add_child(this.clutterfiles.el);
370 this.clutterfiles.el.show_all();
373 this.clutterfiles.open.connect((file) => {
374 this.fileViewOpen(file);
376 this.clutterfiles.el.transitions_completed.connect(() => {
377 if (this.state == State.FILES) {
378 this.win.rooview.el.hide();
380 this.clutterfiles.el.hide();
388 public void fileDetailsInit()
390 this.file_details = new Xcls_PopoverFileDetails();
391 this.file_details.mainwindow = this.win;
392 // force it modal to the main window..
394 this.file_details.success.connect((project,file) =>
396 this.fileViewOpen(file);
401 public void fileViewOpen(JsRender.JsRender file)
403 this.win.project = file.project;
404 this.switchState (State.PREVIEW);
406 this.left_tree.model.loadFile(file);
408 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
409 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
411 if (file.xtype == "Roo" ) {
412 ctr.foreach( (w) => { ctr.remove(w); });
413 ctr_p.foreach( (w) => { ctr_p.remove(w); });
414 ctr.add(this.window_rooview.el);
415 ctr_p.add(this.projectsettings.el);
416 this.window_rooview.loadFile(file);
417 this.window_rooview.el.show_all();
418 this.projectsettings.el.show_all();
421 ctr.foreach( (w) => { ctr.remove(w); });
422 ctr_p.foreach( (w) => { ctr_p.remove(w); });
423 ctr.add(this.window_gladeview.el);
424 ctr_p.add(this.vala_projectsettings.el);
425 this.window_gladeview.loadFile(file);
426 this.window_gladeview.el.show_all();
427 this.vala_projectsettings.el.show_all();
429 print("OPEN : " + file.name);
430 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
431 this.win.setTitle(file.project.name + " : " +file.name);
437 // --------- webkit view
438 public void webkitViewInit()
440 this.window_rooview =new Xcls_WindowRooView();
441 this.window_rooview.ref();
442 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
443 this.window_rooview.el.show_all();
445 var stage = this.win.rooview.el.get_stage();
446 stage.set_background_color( Clutter.Color.from_string("#000"));
451 public void gtkViewInit()
453 this.window_gladeview =new Xcls_GtkView();
454 this.window_gladeview.ref();
455 this.window_gladeview.main_window = this.win;
458 public void easingSaveAll()
460 this.win.addpropsview.el.save_easing_state();
461 this.win.codeeditview.el.save_easing_state();
462 this.win.objectview.el.save_easing_state();
463 this.win.projecteditview.el.save_easing_state();
464 this.win.rooview.el.save_easing_state();
465 this.clutterfiles.el.save_easing_state();
468 public void easingRestoreAll()
470 this.win.addpropsview.el.restore_easing_state();
471 this.win.codeeditview.el.restore_easing_state();
472 this.win.objectview.el.restore_easing_state();
473 this.win.projecteditview.el.restore_easing_state();
474 this.win.rooview.el.restore_easing_state();
475 this.clutterfiles.el.restore_easing_state();
478 public void switchState(State new_state)
481 // save the easing state of everything..
482 this.easingSaveAll();
484 switch (this.state) {
487 if (this.left_tree.getActiveFile() != null) {
488 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
489 this.window_rooview.createThumb();
491 this.window_gladeview.createThumb();
494 // normally we are going from preview to another state.
495 // and different windows hide the preview in differnt ways..
502 this.win.addpropsview.el.set_scale(0.0f,0.0f);
508 this.code_editor.saveContents();
510 this.win.codeeditview.el.set_scale(0.0f,0.0f);
516 this.win.objectview.el.set_scale(0.0f,0.0f);
520 if (this.win.project.xtype == "Gtk") {
521 this.vala_projectsettings.save();
524 this.win.projecteditview.el.set_scale(0.0f,0.0f);
530 this.win.rooview.el.show_all();
531 this.win.rooview.el.set_easing_duration(1000);
532 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
533 this.win.rooview.el.set_scale(1.0f,1.0f);
534 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
535 this.win.rooview.el.set_opacity(0xff);
539 this.clutterfiles.el.set_easing_duration(1000);
540 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
541 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
542 this.clutterfiles.el.set_opacity(0);
544 //this.clutterfiles.el.hide();
552 var oldstate =this.state;
553 this.state = new_state;
557 this.buttonsShowHide();
560 switch (this.state) {
562 case State.PREVIEW: // this is the default state when working...
563 this.win.editpane.el.show(); // holder for tree and properties..
566 this.left_projects.el.hide();
567 if (oldstate != State.FILES) {
568 // it's handled above..
569 print ("changing state to preview from NOT files..");
572 this.win.rooview.el.set_scale(1.0f,1.0f);
581 var ae = this.left_tree.getActiveElement();
583 this.state = oldstate;
584 this.buttonsShowHide();
585 this.resizeCanvasElements();
586 this.easingRestoreAll();
589 this.add_props.el.show_all();
591 Palete.factory(this.win.project.xtype),
592 this.state == State.LISTENER ? "signals" : "props",
599 // -- FIXME? this needs to be State aware?
601 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
603 this.win.addpropsview.el.set_scale(1.0f,1.0f);
607 var n = this.left_tree.getActiveElement();
609 if (this.left_tree.model.file == null) {
610 this.state =oldstate;
611 this.buttonsShowHide();
612 this.resizeCanvasElements();
613 this.easingRestoreAll();
617 if (n == null && this.left_tree.model.file.tree != null) {
618 this.state = oldstate;
619 this.buttonsShowHide();
620 this.resizeCanvasElements();
621 this.easingRestoreAll();
625 this.rightpalete.el.show_all();
626 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
631 this.win.objectview.el.set_scale(1.0f,1.0f);
638 this.code_editor.el.show_all();
640 // caller needs to call editor - show....
643 this.win.codeeditview.el.set_scale(1.0f,1.0f);
650 if (this.win.project.xtype == "Roo") {
651 this.projectsettings.el.show_all();
652 this.projectsettings.show(this.win.project);
654 this.vala_projectsettings.el.show_all();
655 this.vala_projectsettings.show((Project.Gtk)this.win.project);
658 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
660 this.win.projecteditview.el.set_scale(1.0f,1.0f);
665 case State.FILES: // can only get here from PREVIEW state.. in theory..
668 this.win.editpane.el.hide(); // holder for tree and properties..
670 this.left_projects.el.show();
672 this.win.rooview.el.set_easing_duration(1000);
673 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
674 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
675 this.win.rooview.el.set_opacity(0);
676 //el.set_scale(0.0f,0.0f);
679 if (this.win.project != null) {
680 this.left_projects.selectProject(this.win.project);
684 this.clutterfiles.el.show_all();
686 this.clutterfiles.el.set_easing_duration(1000);
687 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
688 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
689 this.clutterfiles.el.set_opacity(0xff);
697 this.resizeCanvasElements();
698 this.easingRestoreAll();
703 public int redraw_count = 0;
704 public void resizeCanvas() // called by window resize .. delays redraw
706 var rc = this.redraw_count;
707 this.redraw_count = 2;
709 GLib.Timeout.add(100, () =>{
710 return this.resizeCanvasQueue();
714 public bool resizeCanvasQueue()
716 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
718 if (this.redraw_count < 1) {
719 return false; // should not really happen...
725 if (this.redraw_count > 0) {
726 return true; // do it again in 1 second...
728 // got down to 0 or -1....
729 this.redraw_count = 0;
730 this.resizeCanvasElements();
734 public void resizeCanvasElements()
736 Gtk.Allocation alloc;
737 this.win.clutterembed.el.get_allocation(out alloc);
739 // print("WindowState.resizeCanvasElements\n");
740 if (!this.children_loaded || this.win.clutterembed == null) {
741 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
745 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
746 var palsize = avail < 300.0f ? avail : 300.0f;
749 // -------- code edit min 600
751 var codesize = avail < 800.0f ? avail : 800.0f;
754 //print("set code size %f\n", codesize);
758 switch ( this.state) {
760 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
764 this.clutterfiles.set_size(alloc.width-50, alloc.height);
769 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
771 // this.win.rooview.el.save_easing_state();
772 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
773 this.win.rooview.el.set_scale(0.5f, 0.5f);
774 //this.win.rooview.el.restore_easing_state();
778 this.win.codeeditview.el.set_size(codesize, alloc.height);
779 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
780 //this.win.rooview.el.save_easing_state();
782 this.win.rooview.el.set_scale(scale,scale);
783 // this.win.rooview.el.restore_easing_state();
788 this.win.addpropsview.el.set_size(palsize, alloc.height);
789 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
790 this.win.rooview.el.set_scale(scale,scale);
794 this.win.objectview.el.set_size(palsize, alloc.height);
795 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
796 //this.win.rooview.el.save_easing_state();
797 this.win.rooview.el.set_scale(scale,scale);
798 // this.win.rooview.el.restore_easing_state();
803 // -- buttons show hide.....
805 public void buttonsShowHide()
807 // basically hide everything, then show the relivant..
809 this.win.backbutton.el.hide();
811 this.win.projectbutton.el.hide(); // show file nav...
812 this.win.editfilebutton.el.hide();
813 this.win.projecteditbutton.el.hide();
816 this.win.objectshowbutton.el.hide(); // add objects
817 this.win.addpropbutton.el.hide();
818 this.win.addlistenerbutton.el.hide();
822 this.win.addprojectbutton.el.hide();
823 this.win.addfilebutton.el.hide();
824 this.win.delprojectbutton.el.hide();
827 switch (this.state) {
829 case State.PREVIEW: // this is the default state when working...
831 this.win.projectbutton.el.show(); // show file nav...
832 this.win.editfilebutton.el.show();
833 this.win.projecteditbutton.el.show();
836 this.win.objectshowbutton.el.show(); // add objects
837 this.win.addpropbutton.el.show();
838 this.win.addlistenerbutton.el.show();
847 this.win.backbutton.el.show();
848 this.win.objectshowbutton.el.show(); // add objects
849 this.win.addpropbutton.el.show();
850 this.win.addlistenerbutton.el.show();
855 this.win.backbutton.el.show();
860 if (this.left_projects.getSelectedProject() != null ) {
861 if (this.left_tree.getActiveFile() != null) {
862 this.win.backbutton.el.show();
864 this.win.addfilebutton.el.show();
867 this.win.addprojectbutton.el.show();
868 this.win.delprojectbutton.el.show();