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;
29 public Xcls_WindowLeftTree left_tree;
30 public Xcls_WindowAddProp add_props;
31 public Xcls_LeftProps left_props;
32 public Xcls_ProjectSettings projectsettings;
33 public ValaProjectSettings vala_projectsettings;
34 public Xcls_RightPalete rightpalete;
35 public Editor code_editor;
36 public Xcls_WindowRooView window_rooview;
37 public Xcls_GtkView window_gladeview;
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 Palete.ValaSource valasource; // the spawner that runs the vala compiler.
53 public Json.Object last_compile_result;
56 public WindowState(Xcls_MainWindow win)
65 // on clutter space...
66 this.projectEditInit();
68 this.projectListInit();
78 this.webkitViewInit();
82 this.fileDetailsInit();
84 this.webkit_plugin = new Xcls_DialogPluginWebkit();
85 this.template_select = new DialogTemplateSelect();
86 this.children_loaded = true;
88 this.left_tree.node_selected.connect((sel) => {
89 this.window_gladeview.sourceview.nodeSelected(sel);
91 this.valasource = new Palete.ValaSource();
92 this.valasource.compiled.connect(this.valaCompiled);
100 public void leftTreeInit()
103 this.left_tree = new Xcls_WindowLeftTree();
104 this.left_tree.ref();
105 this.left_tree.main_window = this.win;
107 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
108 this.left_tree.el.show_all();
110 this.left_tree.before_node_change.connect(() => {
111 return this.leftTreeBeforeChange();
115 this.left_tree.node_selected.connect((sel) => {
116 this.leftTreeNodeSelected(sel);
119 this.left_tree.changed.connect(() => {
121 this.left_tree.model.file.save();
122 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
123 this.window_rooview.requestRedraw();
125 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
132 public bool leftTreeBeforeChange()
134 if (this.state != State.CODE) {
135 this.left_props.finish_editing();
138 if (!this.code_editor.saveContents()) {
144 public void leftTreeNodeSelected(JsRender.Node? sel)
147 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
150 this.left_props.el.hide();
152 this.left_props.el.show();
153 this.left_props.load(this.left_tree.getActiveFile(), sel);
154 switch (this.state) {
159 this.rightpalete.clear();
162 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
168 this.add_props.clear();
171 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
177 this.add_props.clear();
180 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
184 this.switchState(State.PREVIEW);
197 public void propsListInit()
200 this.left_props =new Xcls_LeftProps();
201 this.left_props.ref();
202 this.left_props.main_window = this.win;
203 this.win.props.el.pack_start(this.left_props.el,true, true,0);
204 this.left_props.el.show_all();
206 this.left_props.show_editor.connect( (file, node, type, key) => {
207 this.switchState(State.CODE);
208 this.code_editor.show(
219 this.left_props.stop_editor.connect( () => {
220 if (this.state != State.CODE) {
224 var ret = this.code_editor.saveContents();
228 this.switchState(State.PREVIEW);
232 this.left_props.changed.connect(() => {
233 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
234 this.window_rooview.requestRedraw();
236 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
238 this.left_tree.model.updateSelected();
239 this.left_tree.model.file.save();
240 if (this.left_tree.model.file.xtype=="Gtk") {
241 this.valasource.checkFileSpawn(this.left_tree.model.file);
249 //------------- projects edit
251 public void projectEditInit()
253 this.projectsettings =new Xcls_ProjectSettings();
254 this.projectsettings.ref(); /// really?
256 this.vala_projectsettings =new ValaProjectSettings();
257 this.vala_projectsettings.ref();
258 this.vala_projectsettings.window = this.win;
260 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
261 //this.projectsettings.el.show_all();
263 var stage = this.win.projecteditview.el.get_stage();
264 stage.set_background_color( Clutter.Color.from_string("#000"));
266 this.projectsettings.buttonPressed.connect((btn) => {
267 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
269 this.window_rooview.view.renderJS(true);
271 if (btn == "apply") {
272 this.window_rooview.view.renderJS(true);
276 // do nothing for gtk..
278 if (btn == "save" || btn == "apply") {
279 this.win.project.save();
282 this.switchState (State.PREVIEW);
287 // ----------- object adding
288 public void objectAddInit()
291 this.rightpalete = new Xcls_RightPalete();
292 this.rightpalete.ref(); /// really?
293 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
294 //this.projectsettings.el.show_all();
296 var stage = this.win.objectview.el.get_stage();
297 stage.set_background_color( Clutter.Color.from_string("#000"));
301 // ----------- properties adding list...
302 // listener uses the properties
303 public void propsAddInit()
306 this.add_props = new Xcls_WindowAddProp();
307 this.add_props.ref(); /// really?
308 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
309 //this.projectsettings.el.show_all();
311 var stage = this.win.addpropsview.el.get_stage();
312 stage.set_background_color( Clutter.Color.from_string("#000"));
315 this.add_props.select.connect( (key,type,skel, etype) => {
316 this.left_props.addProp(etype, key, skel, type);
320 public void propsAddShow()
324 public void propsAddHide()
332 // ----------- Add / Edit listener
333 // listener uses the properties
334 //public void listenerInit() { }
335 public void listenerShow()
339 public void listenerHide()
344 // -------------- codeEditor
346 public void codeEditInit()
348 this.code_editor = new Editor();
349 //this.code_editor.ref(); /// really?
350 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
352 this.code_editor.window = this.win;
353 //this.projectsettings.el.show_all();
355 var stage = this.win.codeeditview.el.get_stage();
356 stage.set_background_color( Clutter.Color.from_string("#000"));
359 this.code_editor.save.connect( () => {
360 this.left_tree.model.file.save();
361 this.left_tree.model.updateSelected();
362 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
363 this.window_rooview.requestRedraw();
365 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
367 // we do not need to call spawn... - as it's already called by the editor?
373 // ----------- list of projects on left
374 public void projectListInit()
377 this.left_projects = new Xcls_WindowLeftProjects();
378 this.left_projects.ref();
379 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
380 this.left_projects.el.show_all();
381 this.left_projects.project_selected.connect((proj) => {
382 this.buttonsShowHide();
384 this.clutterfiles.loadProject(proj);
389 // ----------- file view
391 public void fileViewInit()
393 var stage = this.win.rooview.el.get_stage(); // seems odd...
394 this.clutterfiles = new Xcls_ClutterFiles();
395 this.clutterfiles.ref();
396 stage.add_child(this.clutterfiles.el);
397 this.clutterfiles.el.show();
400 this.clutterfiles.open.connect((file) => {
401 this.fileViewOpen(file);
403 this.clutterfiles.el.transitions_completed.connect(() => {
404 if (this.state == State.FILES) {
405 this.win.rooview.el.hide();
407 this.clutterfiles.el.hide();
415 public void fileDetailsInit()
417 this.file_details = new Xcls_PopoverFileDetails();
418 this.file_details.mainwindow = this.win;
419 // force it modal to the main window..
421 this.file_details.success.connect((project,file) =>
423 this.fileViewOpen(file);
428 public void fileViewOpen(JsRender.JsRender file)
430 this.win.project = file.project;
432 if (file.xtype == "PlainFile") {
433 this.switchState (State.CODEONLY);
436 this.switchState (State.PREVIEW);
437 this.left_tree.model.loadFile(file);
442 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
443 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
445 if (file.project.xtype == "Roo" ) {
446 ctr.foreach( (w) => { ctr.remove(w); });
447 ctr_p.foreach( (w) => { ctr_p.remove(w); });
448 ctr.add(this.window_rooview.el);
449 ctr_p.add(this.projectsettings.el);
450 if (file.xtype != "PlainFile") {
451 this.window_rooview.loadFile(file);
452 this.window_rooview.el.show_all();
454 this.projectsettings.el.show_all();
458 ctr.foreach( (w) => { ctr.remove(w); });
459 ctr_p.foreach( (w) => { ctr_p.remove(w); });
460 ctr.add(this.window_gladeview.el);
461 ctr_p.add(this.vala_projectsettings.el);
462 if (file.xtype != "PlainFile") {
463 this.window_gladeview.loadFile(file);
464 this.window_gladeview.el.show_all();
466 this.vala_projectsettings.el.show_all();
468 print("OPEN : " + file.name);
469 if (file.xtype != "PlainFile") {
470 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
472 this.win.setTitle(file.project.name + " : " + file.name);
476 public void fileViewOpenPlain(Project proj, string file)
478 this.win.project = proj;
479 this.switchState (State.CODEONLY);
480 if (project.xtype == "Roo" ) {
481 this.projectsettings.el.show_all();
483 this.vala_projectsettings.el.show_all();
488 // --------- webkit view
489 public void webkitViewInit()
491 this.window_rooview =new Xcls_WindowRooView();
492 this.window_rooview.ref();
493 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
494 this.window_rooview.el.show_all();
496 var stage = this.win.rooview.el.get_stage();
497 stage.set_background_color( Clutter.Color.from_string("#000"));
502 public void gtkViewInit()
504 this.window_gladeview =new Xcls_GtkView();
505 this.window_gladeview.ref();
506 this.window_gladeview.main_window = this.win;
509 public void easingSaveAll()
511 this.win.addpropsview.el.save_easing_state();
512 this.win.codeeditview.el.save_easing_state();
513 this.win.objectview.el.save_easing_state();
514 this.win.projecteditview.el.save_easing_state();
515 this.win.rooview.el.save_easing_state();
516 this.clutterfiles.el.save_easing_state();
519 public void easingRestoreAll()
521 this.win.addpropsview.el.restore_easing_state();
522 this.win.codeeditview.el.restore_easing_state();
523 this.win.objectview.el.restore_easing_state();
524 this.win.projecteditview.el.restore_easing_state();
525 this.win.rooview.el.restore_easing_state();
526 this.clutterfiles.el.restore_easing_state();
529 public void switchState(State new_state)
532 // if the new state and the old state are the same..
534 if (new_state == this.state) {
538 // save the easing state of everything..
539 this.easingSaveAll();
541 switch (this.state) {
544 if (this.left_tree.getActiveFile() != null) {
545 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
546 this.window_rooview.createThumb();
548 this.window_gladeview.createThumb();
551 // normally we are going from preview to another state.
552 // and different windows hide the preview in differnt ways..
559 this.win.addpropsview.el.set_scale(0.0f,0.0f);
563 this.code_editor.saveContents();
565 this.win.codeeditview.el.set_scale(0.0f,0.0f);
569 // going from codeonly..
570 this.win.leftpane.el.show();
571 // enable re-calc of canvas..
572 while (Gtk.events_pending()) {
573 Gtk.main_iteration();
575 //this.code_editor.saveContents(); << not yet...
577 this.win.rooview.el.show();
578 this.win.codeeditview.el.set_scale(0.0f,0.0f);
584 this.win.objectview.el.set_scale(0.0f,0.0f);
588 if (this.win.project.xtype == "Gtk") {
589 this.vala_projectsettings.save();
592 this.win.projecteditview.el.set_scale(0.0f,0.0f);
595 case State.FILES: // goes to preview or codeonly...
598 if (new_state == State.CODEONLY) {
599 this.win.rooview.el.hide();
601 this.win.rooview.el.show();
604 this.win.rooview.el.set_easing_duration(1000);
605 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
606 this.win.rooview.el.set_scale(1.0f,1.0f);
607 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
608 this.win.rooview.el.set_opacity(0xff);
612 this.clutterfiles.el.set_easing_duration(1000);
613 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
614 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
615 this.clutterfiles.el.set_opacity(0);
617 //this.clutterfiles.el.hide();
625 var oldstate =this.state;
626 this.state = new_state;
630 this.buttonsShowHide();
633 switch (this.state) {
635 case State.PREVIEW: // this is the default state when working...
636 this.win.editpane.el.show(); // holder for tree and properties..
639 this.left_projects.el.hide();
640 if (oldstate != State.FILES) {
641 // it's handled above..
642 print ("changing state to preview from NOT files..");
645 this.win.rooview.el.set_scale(1.0f,1.0f);
654 var ae = this.left_tree.getActiveElement();
656 this.state = oldstate;
657 this.buttonsShowHide();
658 this.resizeCanvasElements();
659 this.easingRestoreAll();
662 this.add_props.el.show_all();
664 Palete.factory(this.win.project.xtype),
665 this.state == State.LISTENER ? "signals" : "props",
672 // -- FIXME? this needs to be State aware?
674 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
676 this.win.addpropsview.el.set_scale(1.0f,1.0f);
680 var n = this.left_tree.getActiveElement();
682 if (this.left_tree.model.file == null) {
683 this.state =oldstate;
684 this.buttonsShowHide();
685 this.resizeCanvasElements();
686 this.easingRestoreAll();
690 if (n == null && this.left_tree.model.file.tree != null) {
691 this.state = oldstate;
692 this.buttonsShowHide();
693 this.resizeCanvasElements();
694 this.easingRestoreAll();
698 this.rightpalete.el.show_all();
699 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
703 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
704 this.win.objectview.el.set_scale(1.0f,1.0f);
710 this.win.codeeditview.el.show();
711 this.code_editor.el.show_all();
712 // caller needs to call editor - show....
713 this.win.codeeditview.el.set_scale(1.0f,1.0f);
714 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
719 // going to codeonly..
720 this.win.codeeditview.el.show();
722 while (Gtk.events_pending()) {
723 Gtk.main_iteration();
726 this.win.leftpane.el.hide();
727 this.win.codeeditview.el.show();
728 //while (Gtk.events_pending()) {
729 // Gtk.main_iteration();
733 this.code_editor.el.show_all();
735 this.win.codeeditview.el.set_scale(1.0f,1.0f);
736 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
741 if (this.win.project.xtype == "Roo") {
742 this.projectsettings.el.show_all();
743 this.projectsettings.show(this.win.project);
745 this.vala_projectsettings.el.show_all();
746 this.vala_projectsettings.show((Project.Gtk)this.win.project);
749 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
751 this.win.projecteditview.el.set_scale(1.0f,1.0f);
756 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
759 this.win.editpane.el.hide(); // holder for tree and properties..
761 this.left_projects.el.show();
763 // rotate the preview to hidden...
764 this.win.rooview.el.set_easing_duration(1000);
765 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
766 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
767 this.win.rooview.el.set_opacity(0);
772 if (this.win.project != null) {
773 this.left_projects.selectProject(this.win.project);
777 this.clutterfiles.el.show();
779 this.clutterfiles.el.set_easing_duration(1000);
780 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
781 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
782 this.clutterfiles.el.set_opacity(0xff);
790 this.resizeCanvasElements();
791 this.easingRestoreAll();
793 // run the animation.. - then load files...
798 public int redraw_count = 0;
799 public void resizeCanvas() // called by window resize .. delays redraw
801 var rc = this.redraw_count;
802 this.redraw_count = 2;
804 GLib.Timeout.add(100, () =>{
805 return this.resizeCanvasQueue();
809 public bool resizeCanvasQueue()
811 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
813 if (this.redraw_count < 1) {
814 return false; // should not really happen...
820 if (this.redraw_count > 0) {
821 return true; // do it again in 1 second...
823 // got down to 0 or -1....
824 this.redraw_count = 0;
825 this.resizeCanvasElements();
829 public void resizeCanvasElements()
831 Gtk.Allocation alloc;
832 this.win.clutterembed.el.get_allocation(out alloc);
834 // print("WindowState.resizeCanvasElements\n");
835 if (!this.children_loaded || this.win.clutterembed == null) {
836 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
840 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
841 var palsize = avail < 300.0f ? avail : 300.0f;
844 // -------- code edit min 600
846 var codesize = avail < 800.0f ? avail : 800.0f;
849 //print("set code size %f\n", codesize);
853 switch ( this.state) {
856 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
860 this.clutterfiles.set_size(alloc.width-50, alloc.height);
865 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
867 // this.win.rooview.el.save_easing_state();
868 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
870 this.win.rooview.el.set_scale(0.5f, 0.5f);
871 //this.win.rooview.el.restore_easing_state();
875 this.win.codeeditview.el.set_size(codesize, alloc.height);
876 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
877 //this.win.rooview.el.save_easing_state();
879 this.win.rooview.el.set_scale(scale,scale);
880 // this.win.rooview.el.restore_easing_state();
884 this.win.codeeditview.el.set_size(codesize, alloc.height);
885 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
886 //this.win.rooview.el.save_easing_state();
887 this.win.rooview.el.hide();
888 this.win.rooview.el.set_scale(scale,scale);
889 // this.win.rooview.el.restore_easing_state();
893 this.win.addpropsview.el.set_size(palsize, alloc.height);
894 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
895 this.win.rooview.el.set_scale(scale,scale);
899 this.win.objectview.el.set_size(palsize, alloc.height);
900 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
901 //this.win.rooview.el.save_easing_state();
902 this.win.rooview.el.set_scale(scale,scale);
903 // this.win.rooview.el.restore_easing_state();
908 // -- buttons show hide.....
910 public void buttonsShowHide()
912 // basically hide everything, then show the relivant..
914 this.win.backbutton.el.hide();
916 this.win.projectbutton.el.hide(); // show file nav...
917 this.win.editfilebutton.el.hide();
918 this.win.projecteditbutton.el.hide();
921 this.win.objectshowbutton.el.hide(); // add objects
922 this.win.addpropbutton.el.hide();
923 this.win.addlistenerbutton.el.hide();
927 this.win.addprojectbutton.el.hide();
928 this.win.addfilebutton.el.hide();
929 this.win.delprojectbutton.el.hide();
932 switch (this.state) {
934 case State.PREVIEW: // this is the default state when working...
936 this.win.projectbutton.el.show(); // show file nav...
937 this.win.editfilebutton.el.show();
938 this.win.projecteditbutton.el.show();
941 this.win.objectshowbutton.el.show(); // add objects
942 this.win.addpropbutton.el.show();
943 this.win.addlistenerbutton.el.show();
947 this.win.projectbutton.el.show();
955 this.win.backbutton.el.show();
956 this.win.objectshowbutton.el.show(); // add objects
957 this.win.addpropbutton.el.show();
958 this.win.addlistenerbutton.el.show();
963 this.win.backbutton.el.show();
968 if (this.left_projects.getSelectedProject() != null ) {
969 if (this.left_tree.getActiveFile() != null) {
970 this.win.backbutton.el.show();
972 this.win.addfilebutton.el.show();
975 this.win.addprojectbutton.el.show();
976 this.win.delprojectbutton.el.show();
986 public void valaCompiled(Json.Object obj)
988 // vala has finished compiling...
989 print("vala compiled");
991 var buf = this.code_editor.buffer;
992 buf.check_running = false;
994 if (obj.has_member("ERR-TOTAL")) {
995 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
997 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1000 if (obj.has_member("WARN-TOTAL")) {
1002 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1004 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1007 if (obj.has_member("DEPR-TOTAL")) {
1009 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1012 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1015 buf.highlightErrorsJson("ERR", obj);
1016 buf.highlightErrorsJson("WARN", obj);
1017 buf.highlightErrorsJson("DEPR", obj);
1019 var gbuf = this.window_gladeview.sourceview;
1020 gbuf.highlightErrorsJson("ERR", obj);
1021 gbuf.highlightErrorsJson("WARN", obj);
1022 gbuf.highlightErrorsJson("DEPR", obj);
1024 this.last_compile_result = obj;