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);
108 public void leftTreeInit()
111 this.left_tree = new Xcls_WindowLeftTree();
112 this.left_tree.ref();
113 this.left_tree.main_window = this.win;
115 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
116 this.left_tree.el.show_all();
118 this.left_tree.before_node_change.connect(() => {
119 return this.leftTreeBeforeChange();
123 this.left_tree.node_selected.connect((sel) => {
124 this.leftTreeNodeSelected(sel);
127 this.left_tree.changed.connect(() => {
130 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
131 this.window_rooview.requestRedraw();
133 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
140 public bool leftTreeBeforeChange()
142 if (this.state != State.CODE) {
143 this.left_props.finish_editing();
146 if (!this.code_editor.saveContents()) {
152 public void leftTreeNodeSelected(JsRender.Node? sel)
155 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
158 this.left_props.el.hide();
160 this.left_props.el.show();
161 this.left_props.load(this.left_tree.getActiveFile(), sel);
162 switch (this.state) {
167 this.rightpalete.clear();
170 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
176 this.add_props.clear();
179 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
185 this.add_props.clear();
188 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
192 this.switchState(State.PREVIEW);
205 public void propsListInit()
208 this.left_props =new Xcls_LeftProps();
209 this.left_props.ref();
210 this.left_props.main_window = this.win;
211 this.win.props.el.pack_start(this.left_props.el,true, true,0);
212 this.left_props.el.show_all();
214 this.left_props.show_editor.connect( (file, node, type, key) => {
215 this.switchState(State.CODE);
216 this.code_editor.show(
227 this.left_props.stop_editor.connect( () => {
228 if (this.state != State.CODE) {
232 var ret = this.code_editor.saveContents();
236 this.switchState(State.PREVIEW);
240 this.left_props.changed.connect(() => {
241 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
242 this.window_rooview.requestRedraw();
244 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
246 this.left_tree.model.updateSelected();
248 if (this.file.xtype=="Gtk") {
249 this.valasource.checkFileSpawn(this.file);
257 //------------- projects edit
259 public void projectEditInit()
261 this.projectsettings =new Xcls_ProjectSettings();
262 this.projectsettings.ref(); /// really?
264 this.vala_projectsettings =new ValaProjectSettings();
265 this.vala_projectsettings.ref();
266 this.vala_projectsettings.window = this.win;
268 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
269 //this.projectsettings.el.show_all();
271 var stage = this.win.projecteditview.el.get_stage();
272 stage.set_background_color( Clutter.Color.from_string("#000"));
274 this.projectsettings.buttonPressed.connect((btn) => {
275 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
277 this.window_rooview.view.renderJS(true);
279 if (btn == "apply") {
280 this.window_rooview.view.renderJS(true);
284 // do nothing for gtk..
286 if (btn == "save" || btn == "apply") {
287 this.win.project.save();
290 this.switchState (State.PREVIEW);
295 // ----------- object adding
296 public void objectAddInit()
299 this.rightpalete = new Xcls_RightPalete();
300 this.rightpalete.ref(); /// really?
301 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
302 //this.projectsettings.el.show_all();
304 var stage = this.win.objectview.el.get_stage();
305 stage.set_background_color( Clutter.Color.from_string("#000"));
309 // ----------- properties adding list...
310 // listener uses the properties
311 public void propsAddInit()
314 this.add_props = new Xcls_WindowAddProp();
315 this.add_props.ref(); /// really?
316 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
317 //this.projectsettings.el.show_all();
319 var stage = this.win.addpropsview.el.get_stage();
320 stage.set_background_color( Clutter.Color.from_string("#000"));
323 this.add_props.select.connect( (key,type,skel, etype) => {
324 this.left_props.addProp(etype, key, skel, type);
328 public void propsAddShow()
332 public void propsAddHide()
340 // ----------- Add / Edit listener
341 // listener uses the properties
342 //public void listenerInit() { }
343 public void listenerShow()
347 public void listenerHide()
352 // -------------- codeEditor
354 public void codeEditInit()
356 this.code_editor = new Editor();
357 //this.code_editor.ref(); /// really?
358 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
360 this.code_editor.window = this.win;
361 //this.projectsettings.el.show_all();
363 var stage = this.win.codeeditview.el.get_stage();
364 stage.set_background_color( Clutter.Color.from_string("#000"));
367 this.code_editor.save.connect( () => {
369 this.left_tree.model.updateSelected();
370 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
371 this.window_rooview.requestRedraw();
373 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
375 // we do not need to call spawn... - as it's already called by the editor?
381 // ----------- list of projects on left
382 public void projectListInit()
385 this.left_projects = new Xcls_WindowLeftProjects();
386 this.left_projects.ref();
387 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
388 this.left_projects.el.show_all();
389 this.left_projects.project_selected.connect((proj) => {
390 this.buttonsShowHide();
392 this.clutterfiles.loadProject(proj);
397 // ----------- file view
399 public void fileViewInit()
401 var stage = this.win.rooview.el.get_stage(); // seems odd...
402 this.clutterfiles = new Xcls_ClutterFiles();
403 this.clutterfiles.ref();
404 stage.add_child(this.clutterfiles.el);
405 this.clutterfiles.el.show();
408 this.clutterfiles.open.connect((file) => {
409 this.fileViewOpen(file);
411 this.clutterfiles.el.transitions_completed.connect(() => {
412 if (this.state == State.FILES) {
413 this.win.rooview.el.hide();
415 this.clutterfiles.el.hide();
423 public void fileDetailsInit()
425 this.file_details = new Xcls_PopoverFileDetails();
426 this.file_details.mainwindow = this.win;
427 // force it modal to the main window..
429 this.file_details.success.connect((project,file) =>
431 this.fileViewOpen(file);
436 public void fileViewOpen(JsRender.JsRender file)
438 this.win.project = file.project;
439 this.project = project;
443 if (file.xtype == "PlainFile") {
444 this.switchState (State.CODEONLY);
446 this.code_editor.show(file, null, "", "");
449 this.switchState (State.PREVIEW);
450 // this triggers loadItems..
451 this.left_tree.model.loadFile(file);
456 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
457 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
459 if (file.project.xtype == "Roo" ) {
460 ctr.foreach( (w) => { ctr.remove(w); });
461 ctr_p.foreach( (w) => { ctr_p.remove(w); });
462 ctr.add(this.window_rooview.el);
463 ctr_p.add(this.projectsettings.el);
464 if (file.xtype != "PlainFile") {
465 this.window_rooview.loadFile(file);
466 this.window_rooview.el.show_all();
468 this.projectsettings.el.show_all();
472 ctr.foreach( (w) => { ctr.remove(w); });
473 ctr_p.foreach( (w) => { ctr_p.remove(w); });
474 ctr.add(this.window_gladeview.el);
475 ctr_p.add(this.vala_projectsettings.el);
476 if (file.xtype != "PlainFile") {
477 this.window_gladeview.loadFile(file);
478 this.window_gladeview.el.show_all();
480 this.vala_projectsettings.el.show_all();
482 print("OPEN : " + file.name);
483 if (file.xtype != "PlainFile") {
484 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
486 this.win.setTitle(file.project.name + " : " + file.name);
492 // --------- webkit view
493 public void webkitViewInit()
495 this.window_rooview =new Xcls_WindowRooView();
496 this.window_rooview.ref();
497 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
498 this.window_rooview.el.show_all();
500 var stage = this.win.rooview.el.get_stage();
501 stage.set_background_color( Clutter.Color.from_string("#000"));
506 public void gtkViewInit()
508 this.window_gladeview =new Xcls_GtkView();
509 this.window_gladeview.ref();
510 this.window_gladeview.main_window = this.win;
513 public void easingSaveAll()
515 this.win.addpropsview.el.save_easing_state();
516 this.win.codeeditview.el.save_easing_state();
517 this.win.objectview.el.save_easing_state();
518 this.win.projecteditview.el.save_easing_state();
519 this.win.rooview.el.save_easing_state();
520 this.clutterfiles.el.save_easing_state();
523 public void easingRestoreAll()
525 this.win.addpropsview.el.restore_easing_state();
526 this.win.codeeditview.el.restore_easing_state();
527 this.win.objectview.el.restore_easing_state();
528 this.win.projecteditview.el.restore_easing_state();
529 this.win.rooview.el.restore_easing_state();
530 this.clutterfiles.el.restore_easing_state();
533 public void switchState(State new_state)
536 // if the new state and the old state are the same..
538 if (new_state == this.state) {
542 // save the easing state of everything..
543 this.easingSaveAll();
545 switch (this.state) {
548 if (this.left_tree.getActiveFile() != null) {
549 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
550 this.window_rooview.createThumb();
552 this.window_gladeview.createThumb();
555 // normally we are going from preview to another state.
556 // and different windows hide the preview in differnt ways..
563 this.win.addpropsview.el.set_scale(0.0f,0.0f);
567 this.code_editor.saveContents();
569 this.win.codeeditview.el.set_scale(0.0f,0.0f);
573 // going from codeonly..
574 this.win.leftpane.el.show();
575 // enable re-calc of canvas..
576 while (Gtk.events_pending()) {
577 Gtk.main_iteration();
579 //this.code_editor.saveContents(); << not yet...
581 this.win.rooview.el.show();
582 this.win.codeeditview.el.set_scale(0.0f,0.0f);
588 this.win.objectview.el.set_scale(0.0f,0.0f);
592 if (this.win.project.xtype == "Gtk") {
593 this.vala_projectsettings.save();
596 this.win.projecteditview.el.set_scale(0.0f,0.0f);
599 case State.FILES: // goes to preview or codeonly...
602 if (new_state == State.CODEONLY) {
603 this.win.rooview.el.hide();
605 this.win.rooview.el.show();
608 this.win.rooview.el.set_easing_duration(1000);
609 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
610 this.win.rooview.el.set_scale(1.0f,1.0f);
611 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
612 this.win.rooview.el.set_opacity(0xff);
616 this.clutterfiles.el.set_easing_duration(1000);
617 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
618 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
619 this.clutterfiles.el.set_opacity(0);
621 //this.clutterfiles.el.hide();
629 var oldstate =this.state;
630 this.state = new_state;
634 this.buttonsShowHide();
637 switch (this.state) {
639 case State.PREVIEW: // this is the default state when working...
640 this.win.editpane.el.show(); // holder for tree and properties..
643 this.left_projects.el.hide();
644 if (oldstate != State.FILES) {
645 // it's handled above..
646 print ("changing state to preview from NOT files..");
649 this.win.rooview.el.set_scale(1.0f,1.0f);
658 var ae = this.left_tree.getActiveElement();
660 this.state = oldstate;
661 this.buttonsShowHide();
662 this.resizeCanvasElements();
663 this.easingRestoreAll();
666 this.add_props.el.show_all();
668 Palete.factory(this.win.project.xtype),
669 this.state == State.LISTENER ? "signals" : "props",
676 // -- FIXME? this needs to be State aware?
678 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
680 this.win.addpropsview.el.set_scale(1.0f,1.0f);
684 var n = this.left_tree.getActiveElement();
686 if (this.file == null) {
687 this.state =oldstate;
688 this.buttonsShowHide();
689 this.resizeCanvasElements();
690 this.easingRestoreAll();
694 if (n == null && this.file.tree != null) {
695 this.state = oldstate;
696 this.buttonsShowHide();
697 this.resizeCanvasElements();
698 this.easingRestoreAll();
702 this.rightpalete.el.show_all();
703 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
707 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
708 this.win.objectview.el.set_scale(1.0f,1.0f);
714 this.win.codeeditview.el.show();
715 this.code_editor.el.show_all();
716 // caller needs to call editor - show....
717 this.win.codeeditview.el.set_scale(1.0f,1.0f);
718 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
723 // going to codeonly..
724 this.win.codeeditview.el.show();
726 //while (Gtk.events_pending()) {
727 // Gtk.main_iteration();
730 this.win.leftpane.el.hide();
731 this.win.codeeditview.el.show();
732 //while (Gtk.events_pending()) {
733 // Gtk.main_iteration();
737 this.code_editor.el.show_all();
739 this.win.codeeditview.el.set_scale(1.0f,1.0f);
740 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
745 if (this.win.project.xtype == "Roo") {
746 this.projectsettings.el.show_all();
747 this.projectsettings.show(this.win.project);
749 this.vala_projectsettings.el.show_all();
750 this.vala_projectsettings.show((Project.Gtk)this.win.project);
753 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
755 this.win.projecteditview.el.set_scale(1.0f,1.0f);
760 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
763 this.win.editpane.el.hide(); // holder for tree and properties..
765 this.left_projects.el.show();
767 // rotate the preview to hidden...
768 this.win.rooview.el.set_easing_duration(1000);
769 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
770 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
771 this.win.rooview.el.set_opacity(0);
776 if (this.win.project != null) {
777 this.left_projects.selectProject(this.win.project);
781 this.clutterfiles.el.show();
783 this.clutterfiles.el.set_easing_duration(1000);
784 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
785 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
786 this.clutterfiles.el.set_opacity(0xff);
794 this.resizeCanvasElements();
795 this.easingRestoreAll();
797 // run the animation.. - then load files...
802 public int redraw_count = 0;
803 public void resizeCanvas() // called by window resize .. delays redraw
805 var rc = this.redraw_count;
806 this.redraw_count = 2;
808 GLib.Timeout.add(100, () =>{
809 return this.resizeCanvasQueue();
813 public bool resizeCanvasQueue()
815 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
817 if (this.redraw_count < 1) {
818 return false; // should not really happen...
824 if (this.redraw_count > 0) {
825 return true; // do it again in 1 second...
827 // got down to 0 or -1....
828 this.redraw_count = 0;
829 this.resizeCanvasElements();
833 public void resizeCanvasElements()
835 Gtk.Allocation alloc;
836 this.win.clutterembed.el.get_allocation(out alloc);
838 // print("WindowState.resizeCanvasElements\n");
839 if (!this.children_loaded || this.win.clutterembed == null) {
840 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
844 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
845 var palsize = avail < 300.0f ? avail : 300.0f;
848 // -------- code edit min 600
850 var codesize = avail < 800.0f ? avail : 800.0f;
853 //print("set code size %f\n", codesize);
857 switch ( this.state) {
860 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
864 this.clutterfiles.set_size(alloc.width-50, alloc.height);
869 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
871 // this.win.rooview.el.save_easing_state();
872 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
874 this.win.rooview.el.set_scale(0.5f, 0.5f);
875 //this.win.rooview.el.restore_easing_state();
879 this.win.codeeditview.el.set_size(codesize, alloc.height);
880 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
881 //this.win.rooview.el.save_easing_state();
883 this.win.rooview.el.set_scale(scale,scale);
884 // this.win.rooview.el.restore_easing_state();
888 this.win.codeeditview.el.set_size(codesize, alloc.height);
889 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
890 //this.win.rooview.el.save_easing_state();
891 this.win.rooview.el.hide();
892 this.win.rooview.el.set_scale(scale,scale);
893 // this.win.rooview.el.restore_easing_state();
897 this.win.addpropsview.el.set_size(palsize, alloc.height);
898 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
899 this.win.rooview.el.set_scale(scale,scale);
903 this.win.objectview.el.set_size(palsize, alloc.height);
904 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
905 //this.win.rooview.el.save_easing_state();
906 this.win.rooview.el.set_scale(scale,scale);
907 // this.win.rooview.el.restore_easing_state();
912 // -- buttons show hide.....
914 public void buttonsShowHide()
916 // basically hide everything, then show the relivant..
918 this.win.backbutton.el.hide();
920 this.win.projectbutton.el.hide(); // show file nav...
921 this.win.editfilebutton.el.hide();
922 this.win.projecteditbutton.el.hide();
925 this.win.objectshowbutton.el.hide(); // add objects
926 this.win.addpropbutton.el.hide();
927 this.win.addlistenerbutton.el.hide();
931 this.win.addprojectbutton.el.hide();
932 this.win.addfilebutton.el.hide();
933 this.win.delprojectbutton.el.hide();
936 switch (this.state) {
938 case State.PREVIEW: // this is the default state when working...
940 this.win.projectbutton.el.show(); // show file nav...
941 this.win.editfilebutton.el.show();
942 this.win.projecteditbutton.el.show();
945 this.win.objectshowbutton.el.show(); // add objects
946 this.win.addpropbutton.el.show();
947 this.win.addlistenerbutton.el.show();
951 this.win.projectbutton.el.show();
959 this.win.backbutton.el.show();
960 this.win.objectshowbutton.el.show(); // add objects
961 this.win.addpropbutton.el.show();
962 this.win.addlistenerbutton.el.show();
967 this.win.backbutton.el.show();
972 if (this.left_projects.getSelectedProject() != null ) {
973 if (this.left_tree.getActiveFile() != null) {
974 this.win.backbutton.el.show();
976 this.win.addfilebutton.el.show();
979 this.win.addprojectbutton.el.show();
980 this.win.delprojectbutton.el.show();
990 public void valaCompiled(Json.Object obj)
992 // vala has finished compiling...
993 print("vala compiled");
995 var buf = this.code_editor.buffer;
996 buf.check_running = false;
998 if (obj.has_member("ERR-TOTAL")) {
999 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
1001 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1004 if (obj.has_member("WARN-TOTAL")) {
1006 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1008 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1011 if (obj.has_member("DEPR-TOTAL")) {
1013 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1016 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1019 buf.highlightErrorsJson("ERR", obj);
1020 buf.highlightErrorsJson("WARN", obj);
1021 buf.highlightErrorsJson("DEPR", obj);
1023 if (this.file.xtype == "Gtk") {
1024 var gbuf = this.window_gladeview.sourceview;
1025 gbuf.highlightErrorsJson("ERR", obj);
1026 gbuf.highlightErrorsJson("WARN", obj);
1027 gbuf.highlightErrorsJson("DEPR", obj);
1030 this.last_compile_result = obj;