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..
43 public Xcls_DialogPluginWebkit webkit_plugin;
46 public WindowState(Xcls_MainWindow win)
55 // on clutter space...
56 this.projectEditInit();
58 this.projectListInit();
68 this.webkitViewInit();
74 this.webkit_plugin = new Xcls_DialogPluginWebkit();
76 this.children_loaded = true;
82 public void leftTreeInit()
85 this.left_tree = new Xcls_WindowLeftTree();
87 this.left_tree.main_window = this.win;
89 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
90 this.left_tree.el.show_all();
92 this.left_tree.before_node_change.connect(() => {
93 return this.leftTreeBeforeChange();
97 this.left_tree.node_selected.connect((sel) => {
98 this.leftTreeNodeSelected(sel);
101 this.left_tree.changed.connect(() => {
102 this.window_rooview.requestRedraw();
103 this.left_tree.model.file.save();
108 public bool leftTreeBeforeChange()
110 if (this.state != State.CODE) {
111 this.left_props.finish_editing();
114 if (!this.code_editor.saveContents()) {
120 public void leftTreeNodeSelected(JsRender.Node? sel)
123 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
126 this.left_props.el.hide();
128 this.left_props.el.show();
129 this.left_props.load(this.left_tree.getActiveFile(), sel);
130 switch (this.state) {
135 this.rightpalete.clear();
138 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
144 this.add_props.clear();
147 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
153 this.add_props.clear();
156 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
160 this.switchState(State.PREVIEW);
173 public void propsListInit()
176 this.left_props =new Xcls_LeftProps();
177 this.left_props.ref();
178 this.left_props.main_window = this.win;
179 this.win.props.el.pack_start(this.left_props.el,true, true,0);
180 this.left_props.el.show_all();
182 this.left_props.show_editor.connect( (file, node, type, key) => {
183 this.switchState(State.CODE);
184 this.code_editor.show(
195 this.left_props.stop_editor.connect( () => {
196 if (this.state != State.CODE) {
200 var ret = this.code_editor.saveContents();
204 this.switchState(State.PREVIEW);
208 this.left_props.changed.connect(() => {
209 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
210 this.window_rooview.requestRedraw();
213 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
215 this.left_tree.model.updateSelected();
216 this.left_tree.model.file.save();
223 //------------- projects edit
225 public void projectEditInit()
227 this.projectsettings =new Xcls_ProjectSettings();
228 this.projectsettings.ref(); /// really?
230 this.vala_projectsettings =new ValaProjectSettings();
231 this.vala_projectsettings.ref();
232 this.vala_projectsettings.window = this.win;
234 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
235 //this.projectsettings.el.show_all();
237 var stage = this.win.projecteditview.el.get_stage();
238 stage.set_background_color( Clutter.Color.from_string("#000"));
240 this.projectsettings.buttonPressed.connect((btn) => {
241 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
243 this.window_rooview.view.renderJS(true);
245 if (btn == "apply") {
246 this.window_rooview.view.renderJS(true);
250 // do nothing for gtk..
252 if (btn == "save" || btn == "apply") {
253 this.win.project.save();
256 this.switchState (State.PREVIEW);
261 // ----------- object adding
262 public void objectAddInit()
265 this.rightpalete = new Xcls_RightPalete();
266 this.rightpalete.ref(); /// really?
267 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
268 //this.projectsettings.el.show_all();
270 var stage = this.win.objectview.el.get_stage();
271 stage.set_background_color( Clutter.Color.from_string("#000"));
275 // ----------- properties adding list...
276 // listener uses the properties
277 public void propsAddInit()
280 this.add_props = new Xcls_WindowAddProp();
281 this.add_props.ref(); /// really?
282 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
283 //this.projectsettings.el.show_all();
285 var stage = this.win.addpropsview.el.get_stage();
286 stage.set_background_color( Clutter.Color.from_string("#000"));
289 this.add_props.select.connect( (key,type,skel, etype) => {
290 this.left_props.addProp(etype, key, skel, type);
294 public void propsAddShow()
298 public void propsAddHide()
306 // ----------- Add / Edit listener
307 // listener uses the properties
308 //public void listenerInit() { }
309 public void listenerShow()
313 public void listenerHide()
318 // -------------- codeEditor
320 public void codeEditInit()
322 this.code_editor = new Editor();
323 this.code_editor.ref(); /// really?
324 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
325 //this.projectsettings.el.show_all();
327 var stage = this.win.codeeditview.el.get_stage();
328 stage.set_background_color( Clutter.Color.from_string("#000"));
331 this.code_editor.save.connect( () => {
332 this.left_tree.model.file.save();
333 this.left_tree.model.updateSelected();
338 // ----------- list of projects on left
339 public void projectListInit()
342 this.left_projects = new Xcls_WindowLeftProjects();
343 this.left_projects.ref();
344 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
345 this.left_projects.el.show_all();
346 this.left_projects.project_selected.connect((proj) => {
348 this.clutterfiles.loadProject(proj);
353 // ----------- file view
355 public void fileViewInit()
357 var stage = this.win.rooview.el.get_stage(); // seems odd...
358 this.clutterfiles = new Xcls_ClutterFiles();
359 this.clutterfiles.ref();
360 stage.add_child(this.clutterfiles.el);
361 this.clutterfiles.el.show_all();
364 this.clutterfiles.open.connect((file) => {
365 this.fileViewOpen(file);
367 this.clutterfiles.el.transitions_completed.connect(() => {
368 if (this.state == State.FILES) {
369 this.win.rooview.el.hide();
371 this.clutterfiles.el.hide();
378 public void fileNewInit()
380 this.new_file_dialog = new Xcls_DialogNewComponent();
381 // force it modal to the main window..
382 this.new_file_dialog.el.set_transient_for(this.win.el);
383 this.new_file_dialog.el.set_modal(true);
385 this.new_file_dialog.success.connect((project,file) =>
387 this.fileViewOpen(file);
393 public void fileViewOpen(JsRender.JsRender file)
395 this.win.project = file.project;
396 this.switchState (State.PREVIEW);
398 this.left_tree.model.loadFile(file);
400 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
401 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
403 if (file.xtype == "Roo" ) {
404 ctr.foreach( (w) => { ctr.remove(w); });
405 ctr_p.foreach( (w) => { ctr_p.remove(w); });
406 ctr.add(this.window_rooview.el);
407 ctr_p.add(this.projectsettings.el);
408 this.window_rooview.loadFile(file);
409 this.window_rooview.el.show_all();
410 this.projectsettings.el.show_all();
413 ctr.foreach( (w) => { ctr.remove(w); });
414 ctr_p.foreach( (w) => { ctr_p.remove(w); });
415 ctr.add(this.window_gladeview.el);
416 ctr_p.add(this.vala_projectsettings.el);
417 this.window_gladeview.loadFile(file);
418 this.window_gladeview.el.show_all();
419 this.vala_projectsettings.el.show_all();
421 print("OPEN : " + file.name);
422 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
423 this.win.setTitle(file.project.name + " : " +file.name);
429 // --------- webkit view
430 public void webkitViewInit()
432 this.window_rooview =new Xcls_WindowRooView();
433 this.window_rooview.ref();
434 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
435 this.window_rooview.el.show_all();
437 var stage = this.win.rooview.el.get_stage();
438 stage.set_background_color( Clutter.Color.from_string("#000"));
443 public void gtkViewInit()
445 this.window_gladeview =new Xcls_GtkView();
446 this.window_gladeview.ref();
449 public void easingSaveAll()
451 this.win.addpropsview.el.save_easing_state();
452 this.win.codeeditview.el.save_easing_state();
453 this.win.objectview.el.save_easing_state();
454 this.win.projecteditview.el.save_easing_state();
455 this.win.rooview.el.save_easing_state();
456 this.clutterfiles.el.save_easing_state();
459 public void easingRestoreAll()
461 this.win.addpropsview.el.restore_easing_state();
462 this.win.codeeditview.el.restore_easing_state();
463 this.win.objectview.el.restore_easing_state();
464 this.win.projecteditview.el.restore_easing_state();
465 this.win.rooview.el.restore_easing_state();
466 this.clutterfiles.el.restore_easing_state();
469 public void switchState(State new_state)
472 // save the easing state of everything..
473 this.easingSaveAll();
475 switch (this.state) {
478 if (this.left_tree.getActiveFile() != null) {
479 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
480 this.window_rooview.createThumb();
482 this.window_gladeview.createThumb();
485 // normally we are going from preview to another state.
486 // and different windows hide the preview in differnt ways..
493 this.win.addpropsview.el.set_scale(0.0f,0.0f);
499 this.code_editor.saveContents();
501 this.win.codeeditview.el.set_scale(0.0f,0.0f);
507 this.win.objectview.el.set_scale(0.0f,0.0f);
511 if (this.win.project.xtype == "Gtk") {
512 this.vala_projectsettings.save();
515 this.win.projecteditview.el.set_scale(0.0f,0.0f);
521 this.win.rooview.el.show_all();
522 this.win.rooview.el.set_easing_duration(1000);
523 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
524 this.win.rooview.el.set_scale(1.0f,1.0f);
525 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
526 this.win.rooview.el.set_opacity(0xff);
530 this.clutterfiles.el.set_easing_duration(1000);
531 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
532 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
533 this.clutterfiles.el.set_opacity(0);
535 //this.clutterfiles.el.hide();
543 var oldstate =this.state;
544 this.state = new_state;
548 this.buttonsShowHide();
551 switch (this.state) {
553 case State.PREVIEW: // this is the default state when working...
554 this.win.editpane.el.show(); // holder for tree and properties..
557 this.left_projects.el.hide();
558 if (oldstate != State.FILES) {
559 // it's handled above..
560 print ("changing state to preview from NOT files..");
563 this.win.rooview.el.set_scale(1.0f,1.0f);
572 var ae = this.left_tree.getActiveElement();
574 this.state = oldstate;
575 this.buttonsShowHide();
576 this.resizeCanvasElements();
577 this.easingRestoreAll();
580 this.add_props.el.show_all();
582 Palete.factory(this.win.project.xtype),
583 this.state == State.LISTENER ? "signals" : "props",
590 // -- FIXME? this needs to be State aware?
592 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
594 this.win.addpropsview.el.set_scale(1.0f,1.0f);
598 var n = this.left_tree.getActiveElement();
600 if (this.left_tree.model.file == null) {
601 this.state =oldstate;
602 this.buttonsShowHide();
603 this.resizeCanvasElements();
604 this.easingRestoreAll();
608 if (n == null && this.left_tree.model.file.tree != null) {
609 this.state = oldstate;
610 this.buttonsShowHide();
611 this.resizeCanvasElements();
612 this.easingRestoreAll();
616 this.rightpalete.el.show_all();
617 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
622 this.win.objectview.el.set_scale(1.0f,1.0f);
629 this.code_editor.el.show_all();
631 // caller needs to call editor - show....
634 this.win.codeeditview.el.set_scale(1.0f,1.0f);
641 if (this.win.project.xtype == "Roo") {
642 this.projectsettings.el.show_all();
643 this.projectsettings.show(this.win.project);
645 this.vala_projectsettings.el.show_all();
646 this.vala_projectsettings.show((Project.Gtk)this.win.project);
649 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
651 this.win.projecteditview.el.set_scale(1.0f,1.0f);
656 case State.FILES: // can only get here from PREVIEW state.. in theory..
659 this.win.editpane.el.hide(); // holder for tree and properties..
661 this.left_projects.el.show();
663 this.win.rooview.el.set_easing_duration(1000);
664 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
665 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
666 this.win.rooview.el.set_opacity(0);
667 //el.set_scale(0.0f,0.0f);
670 if (this.win.project != null) {
671 this.left_projects.selectProject(this.win.project);
675 this.clutterfiles.el.show_all();
677 this.clutterfiles.el.set_easing_duration(1000);
678 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
679 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
680 this.clutterfiles.el.set_opacity(0xff);
688 this.resizeCanvasElements();
689 this.easingRestoreAll();
694 public int redraw_count = 0;
695 public void resizeCanvas() // called by window resize .. delays redraw
697 var rc = this.redraw_count;
698 this.redraw_count = 2;
700 GLib.Timeout.add(100, () =>{
701 return this.resizeCanvasQueue();
705 public bool resizeCanvasQueue()
707 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
709 if (this.redraw_count < 1) {
710 return false; // should not really happen...
716 if (this.redraw_count > 0) {
717 return true; // do it again in 1 second...
719 // got down to 0 or -1....
720 this.redraw_count = 0;
721 this.resizeCanvasElements();
725 public void resizeCanvasElements()
727 Gtk.Allocation alloc;
728 this.win.clutterembed.el.get_allocation(out alloc);
730 // print("WindowState.resizeCanvasElements\n");
731 if (!this.children_loaded || this.win.clutterembed == null) {
732 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
736 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
737 var palsize = avail < 300.0f ? avail : 300.0f;
740 // -------- code edit min 600
742 var codesize = avail < 800.0f ? avail : 800.0f;
745 //print("set code size %f\n", codesize);
749 switch ( this.state) {
751 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
755 this.clutterfiles.set_size(alloc.width-50, alloc.height);
760 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
762 // this.win.rooview.el.save_easing_state();
763 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
764 this.win.rooview.el.set_scale(0.5f, 0.5f);
765 //this.win.rooview.el.restore_easing_state();
769 this.win.codeeditview.el.set_size(codesize, alloc.height);
770 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
771 //this.win.rooview.el.save_easing_state();
773 this.win.rooview.el.set_scale(scale,scale);
774 // this.win.rooview.el.restore_easing_state();
779 this.win.addpropsview.el.set_size(palsize, alloc.height);
780 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
781 this.win.rooview.el.set_scale(scale,scale);
785 this.win.objectview.el.set_size(palsize, alloc.height);
786 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
787 //this.win.rooview.el.save_easing_state();
788 this.win.rooview.el.set_scale(scale,scale);
789 // this.win.rooview.el.restore_easing_state();
794 // -- buttons show hide.....
796 public void buttonsShowHide()
798 // basically hide everything, then show the relivant..
800 this.win.backbutton.el.hide();
802 this.win.projectbutton.el.hide(); // show file nav...
803 this.win.editfilebutton.el.hide();
804 this.win.projecteditbutton.el.hide();
807 this.win.objectshowbutton.el.hide(); // add objects
808 this.win.addpropbutton.el.hide();
809 this.win.addlistenerbutton.el.hide();
813 this.win.addprojectbutton.el.hide();
814 this.win.addfilebutton.el.hide();
815 this.win.delprojectbutton.el.hide();
816 this.win.new_window.el.hide();
817 this.win.reload_resources.el.hide();
819 switch (this.state) {
821 case State.PREVIEW: // this is the default state when working...
823 this.win.projectbutton.el.show(); // show file nav...
824 this.win.editfilebutton.el.show();
825 this.win.projecteditbutton.el.show();
828 this.win.objectshowbutton.el.show(); // add objects
829 this.win.addpropbutton.el.show();
830 this.win.addlistenerbutton.el.show();
839 this.win.backbutton.el.show();
840 this.win.objectshowbutton.el.show(); // add objects
841 this.win.addpropbutton.el.show();
842 this.win.addlistenerbutton.el.show();
847 this.win.backbutton.el.show();
852 this.win.backbutton.el.show();
854 this.win.addprojectbutton.el.show();
855 this.win.addfilebutton.el.show();
856 this.win.delprojectbutton.el.show();
857 this.win.new_window.el.show();
858 this.win.reload_resources.el.show();