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;
55 public Xcls_DialogPluginWebkit webkit_plugin;
58 public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
59 public Json.Object last_compile_result;
62 public WindowState(Xcls_MainWindow win)
71 // on clutter space...
72 this.projectEditInit();
74 this.projectListInit();
84 this.webkitViewInit();
88 this.fileDetailsInit();
90 this.webkit_plugin = new Xcls_DialogPluginWebkit();
91 this.template_select = new DialogTemplateSelect();
92 this.children_loaded = true;
94 this.left_tree.node_selected.connect((sel) => {
95 this.window_gladeview.sourceview.nodeSelected(sel);
97 this.valasource = new Palete.ValaSource();
98 this.valasource.compiled.connect(this.valaCompiled);
106 public void leftTreeInit()
109 this.left_tree = new Xcls_WindowLeftTree();
110 this.left_tree.ref();
111 this.left_tree.main_window = this.win;
113 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
114 this.left_tree.el.show_all();
116 this.left_tree.before_node_change.connect(() => {
117 return this.leftTreeBeforeChange();
121 this.left_tree.node_selected.connect((sel) => {
122 this.leftTreeNodeSelected(sel);
125 this.left_tree.changed.connect(() => {
128 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
129 this.window_rooview.requestRedraw();
131 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
138 public bool leftTreeBeforeChange()
140 if (this.state != State.CODE) {
141 this.left_props.finish_editing();
144 if (!this.code_editor.saveContents()) {
150 public void leftTreeNodeSelected(JsRender.Node? sel)
153 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
156 this.left_props.el.hide();
158 this.left_props.el.show();
159 this.left_props.load(this.left_tree.getActiveFile(), sel);
160 switch (this.state) {
165 this.rightpalete.clear();
168 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
174 this.add_props.clear();
177 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
183 this.add_props.clear();
186 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
190 this.switchState(State.PREVIEW);
203 public void propsListInit()
206 this.left_props =new Xcls_LeftProps();
207 this.left_props.ref();
208 this.left_props.main_window = this.win;
209 this.win.props.el.pack_start(this.left_props.el,true, true,0);
210 this.left_props.el.show_all();
212 this.left_props.show_editor.connect( (file, node, type, key) => {
213 this.switchState(State.CODE);
214 this.code_editor.show(
225 this.left_props.stop_editor.connect( () => {
226 if (this.state != State.CODE) {
230 var ret = this.code_editor.saveContents();
234 this.switchState(State.PREVIEW);
238 this.left_props.changed.connect(() => {
239 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
240 this.window_rooview.requestRedraw();
242 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
244 this.left_tree.model.updateSelected();
246 if (this.file.xtype=="Gtk") {
247 this.valasource.checkFileSpawn(this.file);
255 //------------- projects edit
257 public void projectEditInit()
259 this.projectsettings =new Xcls_ProjectSettings();
260 this.projectsettings.ref(); /// really?
262 this.vala_projectsettings =new ValaProjectSettings();
263 this.vala_projectsettings.ref();
264 this.vala_projectsettings.window = this.win;
266 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
267 //this.projectsettings.el.show_all();
269 var stage = this.win.projecteditview.el.get_stage();
270 stage.set_background_color( Clutter.Color.from_string("#000"));
272 this.projectsettings.buttonPressed.connect((btn) => {
273 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
275 this.window_rooview.view.renderJS(true);
277 if (btn == "apply") {
278 this.window_rooview.view.renderJS(true);
282 // do nothing for gtk..
284 if (btn == "save" || btn == "apply") {
285 this.win.project.save();
288 this.switchState (State.PREVIEW);
293 // ----------- object adding
294 public void objectAddInit()
297 this.rightpalete = new Xcls_RightPalete();
298 this.rightpalete.ref(); /// really?
299 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
300 //this.projectsettings.el.show_all();
302 var stage = this.win.objectview.el.get_stage();
303 stage.set_background_color( Clutter.Color.from_string("#000"));
307 // ----------- properties adding list...
308 // listener uses the properties
309 public void propsAddInit()
312 this.add_props = new Xcls_WindowAddProp();
313 this.add_props.ref(); /// really?
314 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
315 //this.projectsettings.el.show_all();
317 var stage = this.win.addpropsview.el.get_stage();
318 stage.set_background_color( Clutter.Color.from_string("#000"));
321 this.add_props.select.connect( (key,type,skel, etype) => {
322 this.left_props.addProp(etype, key, skel, type);
326 public void propsAddShow()
330 public void propsAddHide()
338 // ----------- Add / Edit listener
339 // listener uses the properties
340 //public void listenerInit() { }
341 public void listenerShow()
345 public void listenerHide()
350 // -------------- codeEditor
352 public void codeEditInit()
354 this.code_editor = new Editor();
355 //this.code_editor.ref(); /// really?
356 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
358 this.code_editor.window = this.win;
359 //this.projectsettings.el.show_all();
361 var stage = this.win.codeeditview.el.get_stage();
362 stage.set_background_color( Clutter.Color.from_string("#000"));
365 this.code_editor.save.connect( () => {
367 this.left_tree.model.updateSelected();
368 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
369 this.window_rooview.requestRedraw();
371 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
373 // we do not need to call spawn... - as it's already called by the editor?
379 // ----------- list of projects on left
380 public void projectListInit()
383 this.left_projects = new Xcls_WindowLeftProjects();
384 this.left_projects.ref();
385 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
386 this.left_projects.el.show_all();
387 this.left_projects.project_selected.connect((proj) => {
388 this.buttonsShowHide();
390 this.clutterfiles.loadProject(proj);
395 // ----------- file view
397 public void fileViewInit()
399 var stage = this.win.rooview.el.get_stage(); // seems odd...
400 this.clutterfiles = new Xcls_ClutterFiles();
401 this.clutterfiles.ref();
402 stage.add_child(this.clutterfiles.el);
403 this.clutterfiles.el.show();
406 this.clutterfiles.open.connect((file) => {
407 this.fileViewOpen(file);
409 this.clutterfiles.el.transitions_completed.connect(() => {
410 if (this.state == State.FILES) {
411 this.win.rooview.el.hide();
413 this.clutterfiles.el.hide();
421 public void fileDetailsInit()
423 this.file_details = new Xcls_PopoverFileDetails();
424 this.file_details.mainwindow = this.win;
425 // force it modal to the main window..
427 this.file_details.success.connect((project,file) =>
429 this.fileViewOpen(file);
434 public void fileViewOpen(JsRender.JsRender file)
436 this.win.project = file.project;
438 if (file.xtype == "PlainFile") {
439 this.switchState (State.CODEONLY);
443 this.switchState (State.PREVIEW);
444 this.left_tree.model.loadFile(file);
449 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
450 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
452 if (file.project.xtype == "Roo" ) {
453 ctr.foreach( (w) => { ctr.remove(w); });
454 ctr_p.foreach( (w) => { ctr_p.remove(w); });
455 ctr.add(this.window_rooview.el);
456 ctr_p.add(this.projectsettings.el);
457 if (file.xtype != "PlainFile") {
458 this.window_rooview.loadFile(file);
459 this.window_rooview.el.show_all();
461 this.projectsettings.el.show_all();
465 ctr.foreach( (w) => { ctr.remove(w); });
466 ctr_p.foreach( (w) => { ctr_p.remove(w); });
467 ctr.add(this.window_gladeview.el);
468 ctr_p.add(this.vala_projectsettings.el);
469 if (file.xtype != "PlainFile") {
470 this.window_gladeview.loadFile(file);
471 this.window_gladeview.el.show_all();
473 this.vala_projectsettings.el.show_all();
475 print("OPEN : " + file.name);
476 if (file.xtype != "PlainFile") {
477 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
479 this.win.setTitle(file.project.name + " : " + file.name);
485 // --------- webkit view
486 public void webkitViewInit()
488 this.window_rooview =new Xcls_WindowRooView();
489 this.window_rooview.ref();
490 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
491 this.window_rooview.el.show_all();
493 var stage = this.win.rooview.el.get_stage();
494 stage.set_background_color( Clutter.Color.from_string("#000"));
499 public void gtkViewInit()
501 this.window_gladeview =new Xcls_GtkView();
502 this.window_gladeview.ref();
503 this.window_gladeview.main_window = this.win;
506 public void easingSaveAll()
508 this.win.addpropsview.el.save_easing_state();
509 this.win.codeeditview.el.save_easing_state();
510 this.win.objectview.el.save_easing_state();
511 this.win.projecteditview.el.save_easing_state();
512 this.win.rooview.el.save_easing_state();
513 this.clutterfiles.el.save_easing_state();
516 public void easingRestoreAll()
518 this.win.addpropsview.el.restore_easing_state();
519 this.win.codeeditview.el.restore_easing_state();
520 this.win.objectview.el.restore_easing_state();
521 this.win.projecteditview.el.restore_easing_state();
522 this.win.rooview.el.restore_easing_state();
523 this.clutterfiles.el.restore_easing_state();
526 public void switchState(State new_state)
529 // if the new state and the old state are the same..
531 if (new_state == this.state) {
535 // save the easing state of everything..
536 this.easingSaveAll();
538 switch (this.state) {
541 if (this.left_tree.getActiveFile() != null) {
542 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
543 this.window_rooview.createThumb();
545 this.window_gladeview.createThumb();
548 // normally we are going from preview to another state.
549 // and different windows hide the preview in differnt ways..
556 this.win.addpropsview.el.set_scale(0.0f,0.0f);
560 this.code_editor.saveContents();
562 this.win.codeeditview.el.set_scale(0.0f,0.0f);
566 // going from codeonly..
567 this.win.leftpane.el.show();
568 // enable re-calc of canvas..
569 while (Gtk.events_pending()) {
570 Gtk.main_iteration();
572 //this.code_editor.saveContents(); << not yet...
574 this.win.rooview.el.show();
575 this.win.codeeditview.el.set_scale(0.0f,0.0f);
581 this.win.objectview.el.set_scale(0.0f,0.0f);
585 if (this.win.project.xtype == "Gtk") {
586 this.vala_projectsettings.save();
589 this.win.projecteditview.el.set_scale(0.0f,0.0f);
592 case State.FILES: // goes to preview or codeonly...
595 if (new_state == State.CODEONLY) {
596 this.win.rooview.el.hide();
598 this.win.rooview.el.show();
601 this.win.rooview.el.set_easing_duration(1000);
602 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
603 this.win.rooview.el.set_scale(1.0f,1.0f);
604 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
605 this.win.rooview.el.set_opacity(0xff);
609 this.clutterfiles.el.set_easing_duration(1000);
610 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
611 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
612 this.clutterfiles.el.set_opacity(0);
614 //this.clutterfiles.el.hide();
622 var oldstate =this.state;
623 this.state = new_state;
627 this.buttonsShowHide();
630 switch (this.state) {
632 case State.PREVIEW: // this is the default state when working...
633 this.win.editpane.el.show(); // holder for tree and properties..
636 this.left_projects.el.hide();
637 if (oldstate != State.FILES) {
638 // it's handled above..
639 print ("changing state to preview from NOT files..");
642 this.win.rooview.el.set_scale(1.0f,1.0f);
651 var ae = this.left_tree.getActiveElement();
653 this.state = oldstate;
654 this.buttonsShowHide();
655 this.resizeCanvasElements();
656 this.easingRestoreAll();
659 this.add_props.el.show_all();
661 Palete.factory(this.win.project.xtype),
662 this.state == State.LISTENER ? "signals" : "props",
669 // -- FIXME? this needs to be State aware?
671 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
673 this.win.addpropsview.el.set_scale(1.0f,1.0f);
677 var n = this.left_tree.getActiveElement();
679 if (this.file == null) {
680 this.state =oldstate;
681 this.buttonsShowHide();
682 this.resizeCanvasElements();
683 this.easingRestoreAll();
687 if (n == null && this.file.tree != null) {
688 this.state = oldstate;
689 this.buttonsShowHide();
690 this.resizeCanvasElements();
691 this.easingRestoreAll();
695 this.rightpalete.el.show_all();
696 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
700 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
701 this.win.objectview.el.set_scale(1.0f,1.0f);
707 this.win.codeeditview.el.show();
708 this.code_editor.el.show_all();
709 // caller needs to call editor - show....
710 this.win.codeeditview.el.set_scale(1.0f,1.0f);
711 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
716 // going to codeonly..
717 this.win.codeeditview.el.show();
719 while (Gtk.events_pending()) {
720 Gtk.main_iteration();
723 this.win.leftpane.el.hide();
724 this.win.codeeditview.el.show();
725 //while (Gtk.events_pending()) {
726 // Gtk.main_iteration();
730 this.code_editor.el.show_all();
732 this.win.codeeditview.el.set_scale(1.0f,1.0f);
733 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
738 if (this.win.project.xtype == "Roo") {
739 this.projectsettings.el.show_all();
740 this.projectsettings.show(this.win.project);
742 this.vala_projectsettings.el.show_all();
743 this.vala_projectsettings.show((Project.Gtk)this.win.project);
746 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
748 this.win.projecteditview.el.set_scale(1.0f,1.0f);
753 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
756 this.win.editpane.el.hide(); // holder for tree and properties..
758 this.left_projects.el.show();
760 // rotate the preview to hidden...
761 this.win.rooview.el.set_easing_duration(1000);
762 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
763 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
764 this.win.rooview.el.set_opacity(0);
769 if (this.win.project != null) {
770 this.left_projects.selectProject(this.win.project);
774 this.clutterfiles.el.show();
776 this.clutterfiles.el.set_easing_duration(1000);
777 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
778 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
779 this.clutterfiles.el.set_opacity(0xff);
787 this.resizeCanvasElements();
788 this.easingRestoreAll();
790 // run the animation.. - then load files...
795 public int redraw_count = 0;
796 public void resizeCanvas() // called by window resize .. delays redraw
798 var rc = this.redraw_count;
799 this.redraw_count = 2;
801 GLib.Timeout.add(100, () =>{
802 return this.resizeCanvasQueue();
806 public bool resizeCanvasQueue()
808 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
810 if (this.redraw_count < 1) {
811 return false; // should not really happen...
817 if (this.redraw_count > 0) {
818 return true; // do it again in 1 second...
820 // got down to 0 or -1....
821 this.redraw_count = 0;
822 this.resizeCanvasElements();
826 public void resizeCanvasElements()
828 Gtk.Allocation alloc;
829 this.win.clutterembed.el.get_allocation(out alloc);
831 // print("WindowState.resizeCanvasElements\n");
832 if (!this.children_loaded || this.win.clutterembed == null) {
833 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
837 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
838 var palsize = avail < 300.0f ? avail : 300.0f;
841 // -------- code edit min 600
843 var codesize = avail < 800.0f ? avail : 800.0f;
846 //print("set code size %f\n", codesize);
850 switch ( this.state) {
853 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
857 this.clutterfiles.set_size(alloc.width-50, alloc.height);
862 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
864 // this.win.rooview.el.save_easing_state();
865 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
867 this.win.rooview.el.set_scale(0.5f, 0.5f);
868 //this.win.rooview.el.restore_easing_state();
872 this.win.codeeditview.el.set_size(codesize, alloc.height);
873 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
874 //this.win.rooview.el.save_easing_state();
876 this.win.rooview.el.set_scale(scale,scale);
877 // this.win.rooview.el.restore_easing_state();
881 this.win.codeeditview.el.set_size(codesize, alloc.height);
882 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
883 //this.win.rooview.el.save_easing_state();
884 this.win.rooview.el.hide();
885 this.win.rooview.el.set_scale(scale,scale);
886 // this.win.rooview.el.restore_easing_state();
890 this.win.addpropsview.el.set_size(palsize, alloc.height);
891 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
892 this.win.rooview.el.set_scale(scale,scale);
896 this.win.objectview.el.set_size(palsize, alloc.height);
897 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
898 //this.win.rooview.el.save_easing_state();
899 this.win.rooview.el.set_scale(scale,scale);
900 // this.win.rooview.el.restore_easing_state();
905 // -- buttons show hide.....
907 public void buttonsShowHide()
909 // basically hide everything, then show the relivant..
911 this.win.backbutton.el.hide();
913 this.win.projectbutton.el.hide(); // show file nav...
914 this.win.editfilebutton.el.hide();
915 this.win.projecteditbutton.el.hide();
918 this.win.objectshowbutton.el.hide(); // add objects
919 this.win.addpropbutton.el.hide();
920 this.win.addlistenerbutton.el.hide();
924 this.win.addprojectbutton.el.hide();
925 this.win.addfilebutton.el.hide();
926 this.win.delprojectbutton.el.hide();
929 switch (this.state) {
931 case State.PREVIEW: // this is the default state when working...
933 this.win.projectbutton.el.show(); // show file nav...
934 this.win.editfilebutton.el.show();
935 this.win.projecteditbutton.el.show();
938 this.win.objectshowbutton.el.show(); // add objects
939 this.win.addpropbutton.el.show();
940 this.win.addlistenerbutton.el.show();
944 this.win.projectbutton.el.show();
952 this.win.backbutton.el.show();
953 this.win.objectshowbutton.el.show(); // add objects
954 this.win.addpropbutton.el.show();
955 this.win.addlistenerbutton.el.show();
960 this.win.backbutton.el.show();
965 if (this.left_projects.getSelectedProject() != null ) {
966 if (this.left_tree.getActiveFile() != null) {
967 this.win.backbutton.el.show();
969 this.win.addfilebutton.el.show();
972 this.win.addprojectbutton.el.show();
973 this.win.delprojectbutton.el.show();
983 public void valaCompiled(Json.Object obj)
985 // vala has finished compiling...
986 print("vala compiled");
988 var buf = this.code_editor.buffer;
989 buf.check_running = false;
991 if (obj.has_member("ERR-TOTAL")) {
992 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
994 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
997 if (obj.has_member("WARN-TOTAL")) {
999 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1001 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1004 if (obj.has_member("DEPR-TOTAL")) {
1006 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1009 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1012 buf.highlightErrorsJson("ERR", obj);
1013 buf.highlightErrorsJson("WARN", obj);
1014 buf.highlightErrorsJson("DEPR", obj);
1016 var gbuf = this.window_gladeview.sourceview;
1017 gbuf.highlightErrorsJson("ERR", obj);
1018 gbuf.highlightErrorsJson("WARN", obj);
1019 gbuf.highlightErrorsJson("DEPR", obj);
1021 this.last_compile_result = obj;