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;
437 this.project = project;
441 if (file.xtype == "PlainFile") {
442 this.switchState (State.CODEONLY);
446 this.switchState (State.PREVIEW);
447 // this triggers loadItems..
448 this.left_tree.model.loadFile(file);
453 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
454 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
456 if (file.project.xtype == "Roo" ) {
457 ctr.foreach( (w) => { ctr.remove(w); });
458 ctr_p.foreach( (w) => { ctr_p.remove(w); });
459 ctr.add(this.window_rooview.el);
460 ctr_p.add(this.projectsettings.el);
461 if (file.xtype != "PlainFile") {
462 this.window_rooview.loadFile(file);
463 this.window_rooview.el.show_all();
465 this.projectsettings.el.show_all();
469 ctr.foreach( (w) => { ctr.remove(w); });
470 ctr_p.foreach( (w) => { ctr_p.remove(w); });
471 ctr.add(this.window_gladeview.el);
472 ctr_p.add(this.vala_projectsettings.el);
473 if (file.xtype != "PlainFile") {
474 this.window_gladeview.loadFile(file);
475 this.window_gladeview.el.show_all();
477 this.vala_projectsettings.el.show_all();
479 print("OPEN : " + file.name);
480 if (file.xtype != "PlainFile") {
481 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
483 this.win.setTitle(file.project.name + " : " + file.name);
489 // --------- webkit view
490 public void webkitViewInit()
492 this.window_rooview =new Xcls_WindowRooView();
493 this.window_rooview.ref();
494 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
495 this.window_rooview.el.show_all();
497 var stage = this.win.rooview.el.get_stage();
498 stage.set_background_color( Clutter.Color.from_string("#000"));
503 public void gtkViewInit()
505 this.window_gladeview =new Xcls_GtkView();
506 this.window_gladeview.ref();
507 this.window_gladeview.main_window = this.win;
510 public void easingSaveAll()
512 this.win.addpropsview.el.save_easing_state();
513 this.win.codeeditview.el.save_easing_state();
514 this.win.objectview.el.save_easing_state();
515 this.win.projecteditview.el.save_easing_state();
516 this.win.rooview.el.save_easing_state();
517 this.clutterfiles.el.save_easing_state();
520 public void easingRestoreAll()
522 this.win.addpropsview.el.restore_easing_state();
523 this.win.codeeditview.el.restore_easing_state();
524 this.win.objectview.el.restore_easing_state();
525 this.win.projecteditview.el.restore_easing_state();
526 this.win.rooview.el.restore_easing_state();
527 this.clutterfiles.el.restore_easing_state();
530 public void switchState(State new_state)
533 // if the new state and the old state are the same..
535 if (new_state == this.state) {
539 // save the easing state of everything..
540 this.easingSaveAll();
542 switch (this.state) {
545 if (this.left_tree.getActiveFile() != null) {
546 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
547 this.window_rooview.createThumb();
549 this.window_gladeview.createThumb();
552 // normally we are going from preview to another state.
553 // and different windows hide the preview in differnt ways..
560 this.win.addpropsview.el.set_scale(0.0f,0.0f);
564 this.code_editor.saveContents();
566 this.win.codeeditview.el.set_scale(0.0f,0.0f);
570 // going from codeonly..
571 this.win.leftpane.el.show();
572 // enable re-calc of canvas..
573 while (Gtk.events_pending()) {
574 Gtk.main_iteration();
576 //this.code_editor.saveContents(); << not yet...
578 this.win.rooview.el.show();
579 this.win.codeeditview.el.set_scale(0.0f,0.0f);
585 this.win.objectview.el.set_scale(0.0f,0.0f);
589 if (this.win.project.xtype == "Gtk") {
590 this.vala_projectsettings.save();
593 this.win.projecteditview.el.set_scale(0.0f,0.0f);
596 case State.FILES: // goes to preview or codeonly...
599 if (new_state == State.CODEONLY) {
600 this.win.rooview.el.hide();
602 this.win.rooview.el.show();
605 this.win.rooview.el.set_easing_duration(1000);
606 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
607 this.win.rooview.el.set_scale(1.0f,1.0f);
608 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
609 this.win.rooview.el.set_opacity(0xff);
613 this.clutterfiles.el.set_easing_duration(1000);
614 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
615 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
616 this.clutterfiles.el.set_opacity(0);
618 //this.clutterfiles.el.hide();
626 var oldstate =this.state;
627 this.state = new_state;
631 this.buttonsShowHide();
634 switch (this.state) {
636 case State.PREVIEW: // this is the default state when working...
637 this.win.editpane.el.show(); // holder for tree and properties..
640 this.left_projects.el.hide();
641 if (oldstate != State.FILES) {
642 // it's handled above..
643 print ("changing state to preview from NOT files..");
646 this.win.rooview.el.set_scale(1.0f,1.0f);
655 var ae = this.left_tree.getActiveElement();
657 this.state = oldstate;
658 this.buttonsShowHide();
659 this.resizeCanvasElements();
660 this.easingRestoreAll();
663 this.add_props.el.show_all();
665 Palete.factory(this.win.project.xtype),
666 this.state == State.LISTENER ? "signals" : "props",
673 // -- FIXME? this needs to be State aware?
675 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
677 this.win.addpropsview.el.set_scale(1.0f,1.0f);
681 var n = this.left_tree.getActiveElement();
683 if (this.file == null) {
684 this.state =oldstate;
685 this.buttonsShowHide();
686 this.resizeCanvasElements();
687 this.easingRestoreAll();
691 if (n == null && this.file.tree != null) {
692 this.state = oldstate;
693 this.buttonsShowHide();
694 this.resizeCanvasElements();
695 this.easingRestoreAll();
699 this.rightpalete.el.show_all();
700 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
704 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
705 this.win.objectview.el.set_scale(1.0f,1.0f);
711 this.win.codeeditview.el.show();
712 this.code_editor.el.show_all();
713 // caller needs to call editor - show....
714 this.win.codeeditview.el.set_scale(1.0f,1.0f);
715 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
720 // going to codeonly..
721 this.win.codeeditview.el.show();
723 while (Gtk.events_pending()) {
724 Gtk.main_iteration();
727 this.win.leftpane.el.hide();
728 this.win.codeeditview.el.show();
729 //while (Gtk.events_pending()) {
730 // Gtk.main_iteration();
734 this.code_editor.el.show_all();
736 this.win.codeeditview.el.set_scale(1.0f,1.0f);
737 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
742 if (this.win.project.xtype == "Roo") {
743 this.projectsettings.el.show_all();
744 this.projectsettings.show(this.win.project);
746 this.vala_projectsettings.el.show_all();
747 this.vala_projectsettings.show((Project.Gtk)this.win.project);
750 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
752 this.win.projecteditview.el.set_scale(1.0f,1.0f);
757 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
760 this.win.editpane.el.hide(); // holder for tree and properties..
762 this.left_projects.el.show();
764 // rotate the preview to hidden...
765 this.win.rooview.el.set_easing_duration(1000);
766 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
767 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
768 this.win.rooview.el.set_opacity(0);
773 if (this.win.project != null) {
774 this.left_projects.selectProject(this.win.project);
778 this.clutterfiles.el.show();
780 this.clutterfiles.el.set_easing_duration(1000);
781 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
782 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
783 this.clutterfiles.el.set_opacity(0xff);
791 this.resizeCanvasElements();
792 this.easingRestoreAll();
794 // run the animation.. - then load files...
799 public int redraw_count = 0;
800 public void resizeCanvas() // called by window resize .. delays redraw
802 var rc = this.redraw_count;
803 this.redraw_count = 2;
805 GLib.Timeout.add(100, () =>{
806 return this.resizeCanvasQueue();
810 public bool resizeCanvasQueue()
812 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
814 if (this.redraw_count < 1) {
815 return false; // should not really happen...
821 if (this.redraw_count > 0) {
822 return true; // do it again in 1 second...
824 // got down to 0 or -1....
825 this.redraw_count = 0;
826 this.resizeCanvasElements();
830 public void resizeCanvasElements()
832 Gtk.Allocation alloc;
833 this.win.clutterembed.el.get_allocation(out alloc);
835 // print("WindowState.resizeCanvasElements\n");
836 if (!this.children_loaded || this.win.clutterembed == null) {
837 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
841 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
842 var palsize = avail < 300.0f ? avail : 300.0f;
845 // -------- code edit min 600
847 var codesize = avail < 800.0f ? avail : 800.0f;
850 //print("set code size %f\n", codesize);
854 switch ( this.state) {
857 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
861 this.clutterfiles.set_size(alloc.width-50, alloc.height);
866 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
868 // this.win.rooview.el.save_easing_state();
869 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
871 this.win.rooview.el.set_scale(0.5f, 0.5f);
872 //this.win.rooview.el.restore_easing_state();
876 this.win.codeeditview.el.set_size(codesize, alloc.height);
877 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
878 //this.win.rooview.el.save_easing_state();
880 this.win.rooview.el.set_scale(scale,scale);
881 // this.win.rooview.el.restore_easing_state();
885 this.win.codeeditview.el.set_size(codesize, alloc.height);
886 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
887 //this.win.rooview.el.save_easing_state();
888 this.win.rooview.el.hide();
889 this.win.rooview.el.set_scale(scale,scale);
890 // this.win.rooview.el.restore_easing_state();
894 this.win.addpropsview.el.set_size(palsize, alloc.height);
895 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
896 this.win.rooview.el.set_scale(scale,scale);
900 this.win.objectview.el.set_size(palsize, alloc.height);
901 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
902 //this.win.rooview.el.save_easing_state();
903 this.win.rooview.el.set_scale(scale,scale);
904 // this.win.rooview.el.restore_easing_state();
909 // -- buttons show hide.....
911 public void buttonsShowHide()
913 // basically hide everything, then show the relivant..
915 this.win.backbutton.el.hide();
917 this.win.projectbutton.el.hide(); // show file nav...
918 this.win.editfilebutton.el.hide();
919 this.win.projecteditbutton.el.hide();
922 this.win.objectshowbutton.el.hide(); // add objects
923 this.win.addpropbutton.el.hide();
924 this.win.addlistenerbutton.el.hide();
928 this.win.addprojectbutton.el.hide();
929 this.win.addfilebutton.el.hide();
930 this.win.delprojectbutton.el.hide();
933 switch (this.state) {
935 case State.PREVIEW: // this is the default state when working...
937 this.win.projectbutton.el.show(); // show file nav...
938 this.win.editfilebutton.el.show();
939 this.win.projecteditbutton.el.show();
942 this.win.objectshowbutton.el.show(); // add objects
943 this.win.addpropbutton.el.show();
944 this.win.addlistenerbutton.el.show();
948 this.win.projectbutton.el.show();
956 this.win.backbutton.el.show();
957 this.win.objectshowbutton.el.show(); // add objects
958 this.win.addpropbutton.el.show();
959 this.win.addlistenerbutton.el.show();
964 this.win.backbutton.el.show();
969 if (this.left_projects.getSelectedProject() != null ) {
970 if (this.left_tree.getActiveFile() != null) {
971 this.win.backbutton.el.show();
973 this.win.addfilebutton.el.show();
976 this.win.addprojectbutton.el.show();
977 this.win.delprojectbutton.el.show();
987 public void valaCompiled(Json.Object obj)
989 // vala has finished compiling...
990 print("vala compiled");
992 var buf = this.code_editor.buffer;
993 buf.check_running = false;
995 if (obj.has_member("ERR-TOTAL")) {
996 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
998 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1001 if (obj.has_member("WARN-TOTAL")) {
1003 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1005 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1008 if (obj.has_member("DEPR-TOTAL")) {
1010 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1013 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1016 buf.highlightErrorsJson("ERR", obj);
1017 buf.highlightErrorsJson("WARN", obj);
1018 buf.highlightErrorsJson("DEPR", obj);
1020 var gbuf = this.window_gladeview.sourceview;
1021 gbuf.highlightErrorsJson("ERR", obj);
1022 gbuf.highlightErrorsJson("WARN", obj);
1023 gbuf.highlightErrorsJson("DEPR", obj);
1025 this.last_compile_result = obj;