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 DialogTemplateSelect template_select;
45 public Xcls_DialogPluginWebkit webkit_plugin;
48 public WindowState(Xcls_MainWindow win)
57 // on clutter space...
58 this.projectEditInit();
60 this.projectListInit();
70 this.webkitViewInit();
76 this.webkit_plugin = new Xcls_DialogPluginWebkit();
77 this.template_select = new DialogTemplateSelect();
78 this.children_loaded = true;
84 public void leftTreeInit()
87 this.left_tree = new Xcls_WindowLeftTree();
89 this.left_tree.main_window = this.win;
91 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
92 this.left_tree.el.show_all();
94 this.left_tree.before_node_change.connect(() => {
95 return this.leftTreeBeforeChange();
99 this.left_tree.node_selected.connect((sel) => {
100 this.leftTreeNodeSelected(sel);
103 this.left_tree.changed.connect(() => {
104 this.window_rooview.requestRedraw();
105 this.left_tree.model.file.save();
110 public bool leftTreeBeforeChange()
112 if (this.state != State.CODE) {
113 this.left_props.finish_editing();
116 if (!this.code_editor.saveContents()) {
122 public void leftTreeNodeSelected(JsRender.Node? sel)
125 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
128 this.left_props.el.hide();
130 this.left_props.el.show();
131 this.left_props.load(this.left_tree.getActiveFile(), sel);
132 switch (this.state) {
137 this.rightpalete.clear();
140 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
146 this.add_props.clear();
149 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
155 this.add_props.clear();
158 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
162 this.switchState(State.PREVIEW);
175 public void propsListInit()
178 this.left_props =new Xcls_LeftProps();
179 this.left_props.ref();
180 this.left_props.main_window = this.win;
181 this.win.props.el.pack_start(this.left_props.el,true, true,0);
182 this.left_props.el.show_all();
184 this.left_props.show_editor.connect( (file, node, type, key) => {
185 this.switchState(State.CODE);
186 this.code_editor.show(
197 this.left_props.stop_editor.connect( () => {
198 if (this.state != State.CODE) {
202 var ret = this.code_editor.saveContents();
206 this.switchState(State.PREVIEW);
210 this.left_props.changed.connect(() => {
211 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
212 this.window_rooview.requestRedraw();
215 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
217 this.left_tree.model.updateSelected();
218 this.left_tree.model.file.save();
225 //------------- projects edit
227 public void projectEditInit()
229 this.projectsettings =new Xcls_ProjectSettings();
230 this.projectsettings.ref(); /// really?
232 this.vala_projectsettings =new ValaProjectSettings();
233 this.vala_projectsettings.ref();
234 this.vala_projectsettings.window = this.win;
236 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
237 //this.projectsettings.el.show_all();
239 var stage = this.win.projecteditview.el.get_stage();
240 stage.set_background_color( Clutter.Color.from_string("#000"));
242 this.projectsettings.buttonPressed.connect((btn) => {
243 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
245 this.window_rooview.view.renderJS(true);
247 if (btn == "apply") {
248 this.window_rooview.view.renderJS(true);
252 // do nothing for gtk..
254 if (btn == "save" || btn == "apply") {
255 this.win.project.save();
258 this.switchState (State.PREVIEW);
263 // ----------- object adding
264 public void objectAddInit()
267 this.rightpalete = new Xcls_RightPalete();
268 this.rightpalete.ref(); /// really?
269 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
270 //this.projectsettings.el.show_all();
272 var stage = this.win.objectview.el.get_stage();
273 stage.set_background_color( Clutter.Color.from_string("#000"));
277 // ----------- properties adding list...
278 // listener uses the properties
279 public void propsAddInit()
282 this.add_props = new Xcls_WindowAddProp();
283 this.add_props.ref(); /// really?
284 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
285 //this.projectsettings.el.show_all();
287 var stage = this.win.addpropsview.el.get_stage();
288 stage.set_background_color( Clutter.Color.from_string("#000"));
291 this.add_props.select.connect( (key,type,skel, etype) => {
292 this.left_props.addProp(etype, key, skel, type);
296 public void propsAddShow()
300 public void propsAddHide()
308 // ----------- Add / Edit listener
309 // listener uses the properties
310 //public void listenerInit() { }
311 public void listenerShow()
315 public void listenerHide()
320 // -------------- codeEditor
322 public void codeEditInit()
324 this.code_editor = new Editor();
325 this.code_editor.ref(); /// really?
326 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
327 //this.projectsettings.el.show_all();
329 var stage = this.win.codeeditview.el.get_stage();
330 stage.set_background_color( Clutter.Color.from_string("#000"));
333 this.code_editor.save.connect( () => {
334 this.left_tree.model.file.save();
335 this.left_tree.model.updateSelected();
340 // ----------- list of projects on left
341 public void projectListInit()
344 this.left_projects = new Xcls_WindowLeftProjects();
345 this.left_projects.ref();
346 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
347 this.left_projects.el.show_all();
348 this.left_projects.project_selected.connect((proj) => {
350 this.clutterfiles.loadProject(proj);
355 // ----------- file view
357 public void fileViewInit()
359 var stage = this.win.rooview.el.get_stage(); // seems odd...
360 this.clutterfiles = new Xcls_ClutterFiles();
361 this.clutterfiles.ref();
362 stage.add_child(this.clutterfiles.el);
363 this.clutterfiles.el.show_all();
366 this.clutterfiles.open.connect((file) => {
367 this.fileViewOpen(file);
369 this.clutterfiles.el.transitions_completed.connect(() => {
370 if (this.state == State.FILES) {
371 this.win.rooview.el.hide();
373 this.clutterfiles.el.hide();
380 public void fileNewInit()
382 this.new_file_dialog = new Xcls_DialogNewComponent();
383 // force it modal to the main window..
384 this.new_file_dialog.el.set_transient_for(this.win.el);
385 this.new_file_dialog.el.set_modal(true);
387 this.new_file_dialog.success.connect((project,file) =>
389 this.fileViewOpen(file);
395 public void fileViewOpen(JsRender.JsRender file)
397 this.win.project = file.project;
398 this.switchState (State.PREVIEW);
400 this.left_tree.model.loadFile(file);
402 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
403 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
405 if (file.xtype == "Roo" ) {
406 ctr.foreach( (w) => { ctr.remove(w); });
407 ctr_p.foreach( (w) => { ctr_p.remove(w); });
408 ctr.add(this.window_rooview.el);
409 ctr_p.add(this.projectsettings.el);
410 this.window_rooview.loadFile(file);
411 this.window_rooview.el.show_all();
412 this.projectsettings.el.show_all();
415 ctr.foreach( (w) => { ctr.remove(w); });
416 ctr_p.foreach( (w) => { ctr_p.remove(w); });
417 ctr.add(this.window_gladeview.el);
418 ctr_p.add(this.vala_projectsettings.el);
419 this.window_gladeview.loadFile(file);
420 this.window_gladeview.el.show_all();
421 this.vala_projectsettings.el.show_all();
423 print("OPEN : " + file.name);
424 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
425 this.win.setTitle(file.project.name + " : " +file.name);
431 // --------- webkit view
432 public void webkitViewInit()
434 this.window_rooview =new Xcls_WindowRooView();
435 this.window_rooview.ref();
436 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
437 this.window_rooview.el.show_all();
439 var stage = this.win.rooview.el.get_stage();
440 stage.set_background_color( Clutter.Color.from_string("#000"));
445 public void gtkViewInit()
447 this.window_gladeview =new Xcls_GtkView();
448 this.window_gladeview.ref();
449 this.window_gladeview.main_window = this.win;
452 public void easingSaveAll()
454 this.win.addpropsview.el.save_easing_state();
455 this.win.codeeditview.el.save_easing_state();
456 this.win.objectview.el.save_easing_state();
457 this.win.projecteditview.el.save_easing_state();
458 this.win.rooview.el.save_easing_state();
459 this.clutterfiles.el.save_easing_state();
462 public void easingRestoreAll()
464 this.win.addpropsview.el.restore_easing_state();
465 this.win.codeeditview.el.restore_easing_state();
466 this.win.objectview.el.restore_easing_state();
467 this.win.projecteditview.el.restore_easing_state();
468 this.win.rooview.el.restore_easing_state();
469 this.clutterfiles.el.restore_easing_state();
472 public void switchState(State new_state)
475 // save the easing state of everything..
476 this.easingSaveAll();
478 switch (this.state) {
481 if (this.left_tree.getActiveFile() != null) {
482 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
483 this.window_rooview.createThumb();
485 this.window_gladeview.createThumb();
488 // normally we are going from preview to another state.
489 // and different windows hide the preview in differnt ways..
496 this.win.addpropsview.el.set_scale(0.0f,0.0f);
502 this.code_editor.saveContents();
504 this.win.codeeditview.el.set_scale(0.0f,0.0f);
510 this.win.objectview.el.set_scale(0.0f,0.0f);
514 if (this.win.project.xtype == "Gtk") {
515 this.vala_projectsettings.save();
518 this.win.projecteditview.el.set_scale(0.0f,0.0f);
524 this.win.rooview.el.show_all();
525 this.win.rooview.el.set_easing_duration(1000);
526 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
527 this.win.rooview.el.set_scale(1.0f,1.0f);
528 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
529 this.win.rooview.el.set_opacity(0xff);
533 this.clutterfiles.el.set_easing_duration(1000);
534 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
535 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
536 this.clutterfiles.el.set_opacity(0);
538 //this.clutterfiles.el.hide();
546 var oldstate =this.state;
547 this.state = new_state;
551 this.buttonsShowHide();
554 switch (this.state) {
556 case State.PREVIEW: // this is the default state when working...
557 this.win.editpane.el.show(); // holder for tree and properties..
560 this.left_projects.el.hide();
561 if (oldstate != State.FILES) {
562 // it's handled above..
563 print ("changing state to preview from NOT files..");
566 this.win.rooview.el.set_scale(1.0f,1.0f);
575 var ae = this.left_tree.getActiveElement();
577 this.state = oldstate;
578 this.buttonsShowHide();
579 this.resizeCanvasElements();
580 this.easingRestoreAll();
583 this.add_props.el.show_all();
585 Palete.factory(this.win.project.xtype),
586 this.state == State.LISTENER ? "signals" : "props",
593 // -- FIXME? this needs to be State aware?
595 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
597 this.win.addpropsview.el.set_scale(1.0f,1.0f);
601 var n = this.left_tree.getActiveElement();
603 if (this.left_tree.model.file == null) {
604 this.state =oldstate;
605 this.buttonsShowHide();
606 this.resizeCanvasElements();
607 this.easingRestoreAll();
611 if (n == null && this.left_tree.model.file.tree != null) {
612 this.state = oldstate;
613 this.buttonsShowHide();
614 this.resizeCanvasElements();
615 this.easingRestoreAll();
619 this.rightpalete.el.show_all();
620 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
625 this.win.objectview.el.set_scale(1.0f,1.0f);
632 this.code_editor.el.show_all();
634 // caller needs to call editor - show....
637 this.win.codeeditview.el.set_scale(1.0f,1.0f);
644 if (this.win.project.xtype == "Roo") {
645 this.projectsettings.el.show_all();
646 this.projectsettings.show(this.win.project);
648 this.vala_projectsettings.el.show_all();
649 this.vala_projectsettings.show((Project.Gtk)this.win.project);
652 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
654 this.win.projecteditview.el.set_scale(1.0f,1.0f);
659 case State.FILES: // can only get here from PREVIEW state.. in theory..
662 this.win.editpane.el.hide(); // holder for tree and properties..
664 this.left_projects.el.show();
666 this.win.rooview.el.set_easing_duration(1000);
667 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
668 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
669 this.win.rooview.el.set_opacity(0);
670 //el.set_scale(0.0f,0.0f);
673 if (this.win.project != null) {
674 this.left_projects.selectProject(this.win.project);
678 this.clutterfiles.el.show_all();
680 this.clutterfiles.el.set_easing_duration(1000);
681 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
682 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
683 this.clutterfiles.el.set_opacity(0xff);
691 this.resizeCanvasElements();
692 this.easingRestoreAll();
697 public int redraw_count = 0;
698 public void resizeCanvas() // called by window resize .. delays redraw
700 var rc = this.redraw_count;
701 this.redraw_count = 2;
703 GLib.Timeout.add(100, () =>{
704 return this.resizeCanvasQueue();
708 public bool resizeCanvasQueue()
710 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
712 if (this.redraw_count < 1) {
713 return false; // should not really happen...
719 if (this.redraw_count > 0) {
720 return true; // do it again in 1 second...
722 // got down to 0 or -1....
723 this.redraw_count = 0;
724 this.resizeCanvasElements();
728 public void resizeCanvasElements()
730 Gtk.Allocation alloc;
731 this.win.clutterembed.el.get_allocation(out alloc);
733 // print("WindowState.resizeCanvasElements\n");
734 if (!this.children_loaded || this.win.clutterembed == null) {
735 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
739 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
740 var palsize = avail < 300.0f ? avail : 300.0f;
743 // -------- code edit min 600
745 var codesize = avail < 800.0f ? avail : 800.0f;
748 //print("set code size %f\n", codesize);
752 switch ( this.state) {
754 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
758 this.clutterfiles.set_size(alloc.width-50, alloc.height);
763 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
765 // this.win.rooview.el.save_easing_state();
766 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
767 this.win.rooview.el.set_scale(0.5f, 0.5f);
768 //this.win.rooview.el.restore_easing_state();
772 this.win.codeeditview.el.set_size(codesize, alloc.height);
773 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
774 //this.win.rooview.el.save_easing_state();
776 this.win.rooview.el.set_scale(scale,scale);
777 // this.win.rooview.el.restore_easing_state();
782 this.win.addpropsview.el.set_size(palsize, alloc.height);
783 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
784 this.win.rooview.el.set_scale(scale,scale);
788 this.win.objectview.el.set_size(palsize, alloc.height);
789 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
790 //this.win.rooview.el.save_easing_state();
791 this.win.rooview.el.set_scale(scale,scale);
792 // this.win.rooview.el.restore_easing_state();
797 // -- buttons show hide.....
799 public void buttonsShowHide()
801 // basically hide everything, then show the relivant..
803 this.win.backbutton.el.hide();
805 this.win.projectbutton.el.hide(); // show file nav...
806 this.win.editfilebutton.el.hide();
807 this.win.projecteditbutton.el.hide();
810 this.win.objectshowbutton.el.hide(); // add objects
811 this.win.addpropbutton.el.hide();
812 this.win.addlistenerbutton.el.hide();
816 this.win.addprojectbutton.el.hide();
817 this.win.addfilebutton.el.hide();
818 this.win.delprojectbutton.el.hide();
819 this.win.new_window.el.hide();
820 this.win.reload_resources.el.hide();
822 switch (this.state) {
824 case State.PREVIEW: // this is the default state when working...
826 this.win.projectbutton.el.show(); // show file nav...
827 this.win.editfilebutton.el.show();
828 this.win.projecteditbutton.el.show();
831 this.win.objectshowbutton.el.show(); // add objects
832 this.win.addpropbutton.el.show();
833 this.win.addlistenerbutton.el.show();
842 this.win.backbutton.el.show();
843 this.win.objectshowbutton.el.show(); // add objects
844 this.win.addpropbutton.el.show();
845 this.win.addlistenerbutton.el.show();
850 this.win.backbutton.el.show();
855 this.win.backbutton.el.show();
857 this.win.addprojectbutton.el.show();
858 this.win.addfilebutton.el.show();
859 this.win.delprojectbutton.el.show();
860 this.win.new_window.el.show();
861 this.win.reload_resources.el.show();