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;
21 PROJECT // project settings..
24 public State state = State.NONE;
26 public bool children_loaded = false;
30 public Project.Project project;
31 public JsRender.JsRender file;
35 public Xcls_WindowLeftTree left_tree;
36 public Xcls_WindowAddProp add_props;
37 public Xcls_LeftProps left_props;
38 public Xcls_ProjectSettings projectsettings;
39 public ValaProjectSettings vala_projectsettings;
40 public Xcls_RightPalete rightpalete;
41 public Editor code_editor;
42 public Xcls_WindowRooView window_rooview;
43 public Xcls_GtkView window_gladeview;
45 public Xcls_ClutterFiles clutterfiles;
47 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
49 public DialogTemplateSelect template_select;
51 public Xcls_PopoverFileDetails file_details;
54 public Xcls_ValaCompileResults compile_results;
57 public Xcls_DialogPluginWebkit webkit_plugin;
60 public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
61 public Json.Object last_compile_result;
64 public WindowState(Xcls_MainWindow win)
73 // on clutter space...
74 this.projectEditInit();
76 this.projectListInit();
86 this.webkitViewInit();
90 this.fileDetailsInit();
92 this.webkit_plugin = new Xcls_DialogPluginWebkit();
93 this.template_select = new DialogTemplateSelect();
94 this.children_loaded = true;
96 this.left_tree.node_selected.connect((sel) => {
97 this.window_gladeview.sourceview.nodeSelected(sel);
99 this.valasource = new Palete.ValaSource();
100 this.valasource.compiled.connect(this.valaCompiled);
102 this.compile_results = new Xcls_ValaCompileResults();
103 this.compile_results.window = this.win;
109 public void leftTreeInit()
112 this.left_tree = new Xcls_WindowLeftTree();
113 this.left_tree.ref();
114 this.left_tree.main_window = this.win;
116 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
117 this.left_tree.el.show_all();
119 this.left_tree.before_node_change.connect(() => {
120 return this.leftTreeBeforeChange();
124 this.left_tree.node_selected.connect((sel) => {
125 this.leftTreeNodeSelected(sel);
128 this.left_tree.changed.connect(() => {
131 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
132 this.window_rooview.requestRedraw();
134 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
141 public bool leftTreeBeforeChange()
143 if (this.state != State.CODE) {
144 this.left_props.finish_editing();
147 if (!this.code_editor.saveContents()) {
153 public void leftTreeNodeSelected(JsRender.Node? sel)
156 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
159 this.left_props.el.hide();
161 this.left_props.el.show();
162 this.left_props.load(this.left_tree.getActiveFile(), sel);
163 switch (this.state) {
168 this.rightpalete.clear();
171 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
177 this.add_props.clear();
180 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
186 this.add_props.clear();
189 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
193 this.switchState(State.PREVIEW);
206 public void propsListInit()
209 this.left_props =new Xcls_LeftProps();
210 this.left_props.ref();
211 this.left_props.main_window = this.win;
212 this.win.props.el.pack_start(this.left_props.el,true, true,0);
213 this.left_props.el.show_all();
215 this.left_props.show_editor.connect( (file, node, type, key) => {
216 this.switchState(State.CODE);
217 this.code_editor.show(
228 this.left_props.stop_editor.connect( () => {
229 if (this.state != State.CODE) {
233 var ret = this.code_editor.saveContents();
237 this.switchState(State.PREVIEW);
241 this.left_props.changed.connect(() => {
242 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
243 this.window_rooview.requestRedraw();
245 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
247 this.left_tree.model.updateSelected();
249 if (this.file.xtype=="Gtk") {
250 this.valasource.checkFileSpawn(this.file);
258 //------------- projects edit
260 public void projectEditInit()
262 this.projectsettings =new Xcls_ProjectSettings();
263 this.projectsettings.ref(); /// really?
265 this.vala_projectsettings =new ValaProjectSettings();
266 this.vala_projectsettings.ref();
267 this.vala_projectsettings.window = this.win;
269 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
270 //this.projectsettings.el.show_all();
272 var stage = this.win.projecteditview.el.get_stage();
273 stage.set_background_color( Clutter.Color.from_string("#000"));
275 this.projectsettings.buttonPressed.connect((btn) => {
276 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
278 this.window_rooview.view.renderJS(true);
280 if (btn == "apply") {
281 this.window_rooview.view.renderJS(true);
285 // do nothing for gtk..
287 if (btn == "save" || btn == "apply") {
288 this.win.project.save();
291 this.switchState (State.PREVIEW);
296 // ----------- object adding
297 public void objectAddInit()
300 this.rightpalete = new Xcls_RightPalete();
301 this.rightpalete.ref(); /// really?
302 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
303 //this.projectsettings.el.show_all();
305 var stage = this.win.objectview.el.get_stage();
306 stage.set_background_color( Clutter.Color.from_string("#000"));
310 // ----------- properties adding list...
311 // listener uses the properties
312 public void propsAddInit()
315 this.add_props = new Xcls_WindowAddProp();
316 this.add_props.ref(); /// really?
317 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
318 //this.projectsettings.el.show_all();
320 var stage = this.win.addpropsview.el.get_stage();
321 stage.set_background_color( Clutter.Color.from_string("#000"));
324 this.add_props.select.connect( (key,type,skel, etype) => {
325 this.left_props.addProp(etype, key, skel, type);
329 public void propsAddShow()
333 public void propsAddHide()
341 // ----------- Add / Edit listener
342 // listener uses the properties
343 //public void listenerInit() { }
344 public void listenerShow()
348 public void listenerHide()
353 // -------------- codeEditor
355 public void codeEditInit()
357 this.code_editor = new Editor();
358 //this.code_editor.ref(); /// really?
359 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
361 this.code_editor.window = this.win;
362 //this.projectsettings.el.show_all();
364 var stage = this.win.codeeditview.el.get_stage();
365 stage.set_background_color( Clutter.Color.from_string("#000"));
368 this.code_editor.save.connect( () => {
370 this.left_tree.model.updateSelected();
371 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
372 this.window_rooview.requestRedraw();
374 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
376 // we do not need to call spawn... - as it's already called by the editor?
382 // ----------- list of projects on left
383 public void projectListInit()
386 this.left_projects = new Xcls_WindowLeftProjects();
387 this.left_projects.ref();
388 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
389 this.left_projects.el.show_all();
390 this.left_projects.project_selected.connect((proj) => {
391 this.buttonsShowHide();
393 this.clutterfiles.loadProject(proj);
398 // ----------- file view
400 public void fileViewInit()
402 var stage = this.win.rooview.el.get_stage(); // seems odd...
403 this.clutterfiles = new Xcls_ClutterFiles();
404 this.clutterfiles.ref();
405 stage.add_child(this.clutterfiles.el);
406 this.clutterfiles.el.show();
409 this.clutterfiles.open.connect((file) => {
410 this.fileViewOpen(file);
412 this.clutterfiles.el.transitions_completed.connect(() => {
413 if (this.state == State.FILES) {
414 this.win.rooview.el.hide();
416 this.clutterfiles.el.hide();
424 public void fileDetailsInit()
426 this.file_details = new Xcls_PopoverFileDetails();
427 this.file_details.mainwindow = this.win;
428 // force it modal to the main window..
430 this.file_details.success.connect((project,file) =>
432 this.fileViewOpen(file);
437 public void fileViewOpen(JsRender.JsRender file)
439 this.win.project = file.project;
440 this.project = project;
444 if (file.xtype == "PlainFile") {
445 this.switchState (State.CODEONLY);
447 this.code_editor.show(file, null, "", "");
450 this.switchState (State.PREVIEW);
451 // this triggers loadItems..
452 this.left_tree.model.loadFile(file);
457 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
458 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
460 if (file.project.xtype == "Roo" ) {
461 ctr.foreach( (w) => { ctr.remove(w); });
462 ctr_p.foreach( (w) => { ctr_p.remove(w); });
463 ctr.add(this.window_rooview.el);
464 ctr_p.add(this.projectsettings.el);
465 if (file.xtype != "PlainFile") {
466 this.window_rooview.loadFile(file);
467 this.window_rooview.el.show_all();
469 this.projectsettings.el.show_all();
473 ctr.foreach( (w) => { ctr.remove(w); });
474 ctr_p.foreach( (w) => { ctr_p.remove(w); });
475 ctr.add(this.window_gladeview.el);
476 ctr_p.add(this.vala_projectsettings.el);
477 if (file.xtype != "PlainFile") {
478 this.window_gladeview.loadFile(file);
479 this.window_gladeview.el.show_all();
481 this.vala_projectsettings.el.show_all();
483 print("OPEN : " + file.name);
484 if (file.xtype != "PlainFile") {
485 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
487 this.win.setTitle(file.project.name + " : " + file.name);
493 // --------- webkit view
494 public void webkitViewInit()
496 this.window_rooview =new Xcls_WindowRooView();
497 this.window_rooview.ref();
498 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
499 this.window_rooview.el.show_all();
501 var stage = this.win.rooview.el.get_stage();
502 stage.set_background_color( Clutter.Color.from_string("#000"));
507 public void gtkViewInit()
509 this.window_gladeview =new Xcls_GtkView();
510 this.window_gladeview.ref();
511 this.window_gladeview.main_window = this.win;
514 public void easingSaveAll()
516 this.win.addpropsview.el.save_easing_state();
517 this.win.codeeditview.el.save_easing_state();
518 this.win.objectview.el.save_easing_state();
519 this.win.projecteditview.el.save_easing_state();
520 this.win.rooview.el.save_easing_state();
521 this.clutterfiles.el.save_easing_state();
524 public void easingRestoreAll()
526 this.win.addpropsview.el.restore_easing_state();
527 this.win.codeeditview.el.restore_easing_state();
528 this.win.objectview.el.restore_easing_state();
529 this.win.projecteditview.el.restore_easing_state();
530 this.win.rooview.el.restore_easing_state();
531 this.clutterfiles.el.restore_easing_state();
534 public void switchState(State new_state)
537 // if the new state and the old state are the same..
539 if (new_state == this.state) {
543 // save the easing state of everything..
544 this.easingSaveAll();
546 switch (this.state) {
549 if (this.left_tree.getActiveFile() != null) {
550 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
551 this.window_rooview.createThumb();
553 this.window_gladeview.createThumb();
556 // normally we are going from preview to another state.
557 // and different windows hide the preview in differnt ways..
564 this.win.addpropsview.el.set_scale(0.0f,0.0f);
568 this.code_editor.saveContents();
570 this.win.codeeditview.el.set_scale(0.0f,0.0f);
574 // going from codeonly..
575 this.win.leftpane.el.show();
576 // enable re-calc of canvas..
577 while (Gtk.events_pending()) {
578 Gtk.main_iteration();
580 //this.code_editor.saveContents(); << not yet...
582 this.win.rooview.el.show();
583 this.win.codeeditview.el.set_scale(0.0f,0.0f);
589 this.win.objectview.el.set_scale(0.0f,0.0f);
593 if (this.win.project.xtype == "Gtk") {
594 this.vala_projectsettings.save();
597 this.win.projecteditview.el.set_scale(0.0f,0.0f);
600 case State.FILES: // goes to preview or codeonly...
603 if (new_state == State.CODEONLY) {
604 this.win.rooview.el.hide();
606 this.win.rooview.el.show();
609 this.win.rooview.el.set_easing_duration(1000);
610 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
611 this.win.rooview.el.set_scale(1.0f,1.0f);
612 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
613 this.win.rooview.el.set_opacity(0xff);
617 this.clutterfiles.el.set_easing_duration(1000);
618 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
619 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
620 this.clutterfiles.el.set_opacity(0);
622 //this.clutterfiles.el.hide();
630 var oldstate =this.state;
631 this.state = new_state;
635 this.buttonsShowHide();
638 switch (this.state) {
640 case State.PREVIEW: // this is the default state when working...
641 this.win.editpane.el.show(); // holder for tree and properties..
644 this.left_projects.el.hide();
645 if (oldstate != State.FILES) {
646 // it's handled above..
647 print ("changing state to preview from NOT files..");
650 this.win.rooview.el.set_scale(1.0f,1.0f);
659 var ae = this.left_tree.getActiveElement();
661 this.state = oldstate;
662 this.buttonsShowHide();
663 this.resizeCanvasElements();
664 this.easingRestoreAll();
667 this.add_props.el.show_all();
669 Palete.factory(this.win.project.xtype),
670 this.state == State.LISTENER ? "signals" : "props",
677 // -- FIXME? this needs to be State aware?
679 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
681 this.win.addpropsview.el.set_scale(1.0f,1.0f);
685 var n = this.left_tree.getActiveElement();
687 if (this.file == null) {
688 this.state =oldstate;
689 this.buttonsShowHide();
690 this.resizeCanvasElements();
691 this.easingRestoreAll();
695 if (n == null && this.file.tree != null) {
696 this.state = oldstate;
697 this.buttonsShowHide();
698 this.resizeCanvasElements();
699 this.easingRestoreAll();
703 this.rightpalete.el.show_all();
704 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
708 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
709 this.win.objectview.el.set_scale(1.0f,1.0f);
715 this.win.codeeditview.el.show();
716 this.code_editor.el.show_all();
717 // caller needs to call editor - show....
718 this.win.codeeditview.el.set_scale(1.0f,1.0f);
719 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
724 // going to codeonly..
725 this.win.codeeditview.el.show();
727 //while (Gtk.events_pending()) {
728 // Gtk.main_iteration();
731 this.win.leftpane.el.hide();
732 this.win.codeeditview.el.show();
733 //while (Gtk.events_pending()) {
734 // Gtk.main_iteration();
738 this.code_editor.el.show_all();
740 this.win.codeeditview.el.set_scale(1.0f,1.0f);
741 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
746 if (this.win.project.xtype == "Roo") {
747 this.projectsettings.el.show_all();
748 this.projectsettings.show(this.win.project);
750 this.vala_projectsettings.el.show_all();
751 this.vala_projectsettings.show((Project.Gtk)this.win.project);
754 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
756 this.win.projecteditview.el.set_scale(1.0f,1.0f);
761 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
764 this.win.editpane.el.hide(); // holder for tree and properties..
766 this.left_projects.el.show();
768 // rotate the preview to hidden...
769 this.win.rooview.el.set_easing_duration(1000);
770 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
771 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
772 this.win.rooview.el.set_opacity(0);
777 if (this.win.project != null) {
778 this.left_projects.selectProject(this.win.project);
782 this.clutterfiles.el.show();
784 this.clutterfiles.el.set_easing_duration(1000);
785 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
786 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
787 this.clutterfiles.el.set_opacity(0xff);
795 this.resizeCanvasElements();
796 this.easingRestoreAll();
798 // run the animation.. - then load files...
803 public int redraw_count = 0;
804 public void resizeCanvas() // called by window resize .. delays redraw
806 var rc = this.redraw_count;
807 this.redraw_count = 2;
809 GLib.Timeout.add(100, () =>{
810 return this.resizeCanvasQueue();
814 public bool resizeCanvasQueue()
816 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
818 if (this.redraw_count < 1) {
819 return false; // should not really happen...
825 if (this.redraw_count > 0) {
826 return true; // do it again in 1 second...
828 // got down to 0 or -1....
829 this.redraw_count = 0;
830 this.resizeCanvasElements();
834 public void resizeCanvasElements()
836 Gtk.Allocation alloc;
837 this.win.clutterembed.el.get_allocation(out alloc);
839 // print("WindowState.resizeCanvasElements\n");
840 if (!this.children_loaded || this.win.clutterembed == null) {
841 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
845 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
846 var palsize = avail < 300.0f ? avail : 300.0f;
849 // -------- code edit min 600
851 var codesize = avail < 800.0f ? avail : 800.0f;
854 //print("set code size %f\n", codesize);
858 switch ( this.state) {
861 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
865 this.clutterfiles.set_size(alloc.width-50, alloc.height);
870 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
872 // this.win.rooview.el.save_easing_state();
873 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
875 this.win.rooview.el.set_scale(0.5f, 0.5f);
876 //this.win.rooview.el.restore_easing_state();
880 this.win.codeeditview.el.set_size(codesize, alloc.height);
881 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
882 //this.win.rooview.el.save_easing_state();
884 this.win.rooview.el.set_scale(scale,scale);
885 // this.win.rooview.el.restore_easing_state();
889 this.win.codeeditview.el.set_size(codesize, alloc.height);
890 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
891 //this.win.rooview.el.save_easing_state();
892 this.win.rooview.el.hide();
893 this.win.rooview.el.set_scale(scale,scale);
894 // this.win.rooview.el.restore_easing_state();
898 this.win.addpropsview.el.set_size(palsize, alloc.height);
899 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
900 this.win.rooview.el.set_scale(scale,scale);
904 this.win.objectview.el.set_size(palsize, alloc.height);
905 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
906 //this.win.rooview.el.save_easing_state();
907 this.win.rooview.el.set_scale(scale,scale);
908 // this.win.rooview.el.restore_easing_state();
913 // -- buttons show hide.....
915 public void buttonsShowHide()
917 // basically hide everything, then show the relivant..
919 this.win.backbutton.el.hide();
921 this.win.projectbutton.el.hide(); // show file nav...
922 this.win.editfilebutton.el.hide();
923 this.win.projecteditbutton.el.hide();
926 this.win.objectshowbutton.el.hide(); // add objects
927 this.win.addpropbutton.el.hide();
928 this.win.addlistenerbutton.el.hide();
932 this.win.addprojectbutton.el.hide();
933 this.win.addfilebutton.el.hide();
934 this.win.delprojectbutton.el.hide();
937 switch (this.state) {
939 case State.PREVIEW: // this is the default state when working...
941 this.win.projectbutton.el.show(); // show file nav...
942 this.win.editfilebutton.el.show();
943 this.win.projecteditbutton.el.show();
946 this.win.objectshowbutton.el.show(); // add objects
947 this.win.addpropbutton.el.show();
948 this.win.addlistenerbutton.el.show();
952 this.win.projectbutton.el.show();
960 this.win.backbutton.el.show();
961 this.win.objectshowbutton.el.show(); // add objects
962 this.win.addpropbutton.el.show();
963 this.win.addlistenerbutton.el.show();
968 this.win.backbutton.el.show();
973 if (this.left_projects.getSelectedProject() != null ) {
974 if (this.left_tree.getActiveFile() != null) {
975 this.win.backbutton.el.show();
977 this.win.addfilebutton.el.show();
980 this.win.addprojectbutton.el.show();
981 this.win.delprojectbutton.el.show();
991 public void valaCompiled(Json.Object obj)
993 // vala has finished compiling...
994 print("vala compiled");
996 var buf = this.code_editor.buffer;
997 buf.check_running = false;
999 if (obj.has_member("ERR-TOTAL")) {
1000 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
1002 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1005 if (obj.has_member("WARN-TOTAL")) {
1007 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1009 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1012 if (obj.has_member("DEPR-TOTAL")) {
1014 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1017 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1020 buf.highlightErrorsJson("ERR", obj);
1021 buf.highlightErrorsJson("WARN", obj);
1022 buf.highlightErrorsJson("DEPR", obj);
1024 if (this.file.xtype == "Gtk") {
1025 var gbuf = this.window_gladeview.sourceview;
1026 gbuf.highlightErrorsJson("ERR", obj);
1027 gbuf.highlightErrorsJson("WARN", obj);
1028 gbuf.highlightErrorsJson("DEPR", obj);
1031 this.last_compile_result = obj;