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);
444 this.code_editor.show(file, null, "", "");
447 this.switchState (State.PREVIEW);
448 // this triggers loadItems..
449 this.left_tree.model.loadFile(file);
454 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
455 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
457 if (file.project.xtype == "Roo" ) {
458 ctr.foreach( (w) => { ctr.remove(w); });
459 ctr_p.foreach( (w) => { ctr_p.remove(w); });
460 ctr.add(this.window_rooview.el);
461 ctr_p.add(this.projectsettings.el);
462 if (file.xtype != "PlainFile") {
463 this.window_rooview.loadFile(file);
464 this.window_rooview.el.show_all();
466 this.projectsettings.el.show_all();
470 ctr.foreach( (w) => { ctr.remove(w); });
471 ctr_p.foreach( (w) => { ctr_p.remove(w); });
472 ctr.add(this.window_gladeview.el);
473 ctr_p.add(this.vala_projectsettings.el);
474 if (file.xtype != "PlainFile") {
475 this.window_gladeview.loadFile(file);
476 this.window_gladeview.el.show_all();
478 this.vala_projectsettings.el.show_all();
480 print("OPEN : " + file.name);
481 if (file.xtype != "PlainFile") {
482 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
484 this.win.setTitle(file.project.name + " : " + file.name);
490 // --------- webkit view
491 public void webkitViewInit()
493 this.window_rooview =new Xcls_WindowRooView();
494 this.window_rooview.ref();
495 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
496 this.window_rooview.el.show_all();
498 var stage = this.win.rooview.el.get_stage();
499 stage.set_background_color( Clutter.Color.from_string("#000"));
504 public void gtkViewInit()
506 this.window_gladeview =new Xcls_GtkView();
507 this.window_gladeview.ref();
508 this.window_gladeview.main_window = this.win;
511 public void easingSaveAll()
513 this.win.addpropsview.el.save_easing_state();
514 this.win.codeeditview.el.save_easing_state();
515 this.win.objectview.el.save_easing_state();
516 this.win.projecteditview.el.save_easing_state();
517 this.win.rooview.el.save_easing_state();
518 this.clutterfiles.el.save_easing_state();
521 public void easingRestoreAll()
523 this.win.addpropsview.el.restore_easing_state();
524 this.win.codeeditview.el.restore_easing_state();
525 this.win.objectview.el.restore_easing_state();
526 this.win.projecteditview.el.restore_easing_state();
527 this.win.rooview.el.restore_easing_state();
528 this.clutterfiles.el.restore_easing_state();
531 public void switchState(State new_state)
534 // if the new state and the old state are the same..
536 if (new_state == this.state) {
540 // save the easing state of everything..
541 this.easingSaveAll();
543 switch (this.state) {
546 if (this.left_tree.getActiveFile() != null) {
547 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
548 this.window_rooview.createThumb();
550 this.window_gladeview.createThumb();
553 // normally we are going from preview to another state.
554 // and different windows hide the preview in differnt ways..
561 this.win.addpropsview.el.set_scale(0.0f,0.0f);
565 this.code_editor.saveContents();
567 this.win.codeeditview.el.set_scale(0.0f,0.0f);
571 // going from codeonly..
572 this.win.leftpane.el.show();
573 // enable re-calc of canvas..
574 while (Gtk.events_pending()) {
575 Gtk.main_iteration();
577 //this.code_editor.saveContents(); << not yet...
579 this.win.rooview.el.show();
580 this.win.codeeditview.el.set_scale(0.0f,0.0f);
586 this.win.objectview.el.set_scale(0.0f,0.0f);
590 if (this.win.project.xtype == "Gtk") {
591 this.vala_projectsettings.save();
594 this.win.projecteditview.el.set_scale(0.0f,0.0f);
597 case State.FILES: // goes to preview or codeonly...
600 if (new_state == State.CODEONLY) {
601 this.win.rooview.el.hide();
603 this.win.rooview.el.show();
606 this.win.rooview.el.set_easing_duration(1000);
607 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
608 this.win.rooview.el.set_scale(1.0f,1.0f);
609 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
610 this.win.rooview.el.set_opacity(0xff);
614 this.clutterfiles.el.set_easing_duration(1000);
615 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
616 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
617 this.clutterfiles.el.set_opacity(0);
619 //this.clutterfiles.el.hide();
627 var oldstate =this.state;
628 this.state = new_state;
632 this.buttonsShowHide();
635 switch (this.state) {
637 case State.PREVIEW: // this is the default state when working...
638 this.win.editpane.el.show(); // holder for tree and properties..
641 this.left_projects.el.hide();
642 if (oldstate != State.FILES) {
643 // it's handled above..
644 print ("changing state to preview from NOT files..");
647 this.win.rooview.el.set_scale(1.0f,1.0f);
656 var ae = this.left_tree.getActiveElement();
658 this.state = oldstate;
659 this.buttonsShowHide();
660 this.resizeCanvasElements();
661 this.easingRestoreAll();
664 this.add_props.el.show_all();
666 Palete.factory(this.win.project.xtype),
667 this.state == State.LISTENER ? "signals" : "props",
674 // -- FIXME? this needs to be State aware?
676 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
678 this.win.addpropsview.el.set_scale(1.0f,1.0f);
682 var n = this.left_tree.getActiveElement();
684 if (this.file == null) {
685 this.state =oldstate;
686 this.buttonsShowHide();
687 this.resizeCanvasElements();
688 this.easingRestoreAll();
692 if (n == null && this.file.tree != null) {
693 this.state = oldstate;
694 this.buttonsShowHide();
695 this.resizeCanvasElements();
696 this.easingRestoreAll();
700 this.rightpalete.el.show_all();
701 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
705 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
706 this.win.objectview.el.set_scale(1.0f,1.0f);
712 this.win.codeeditview.el.show();
713 this.code_editor.el.show_all();
714 // caller needs to call editor - show....
715 this.win.codeeditview.el.set_scale(1.0f,1.0f);
716 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
721 // going to codeonly..
722 this.win.codeeditview.el.show();
724 //while (Gtk.events_pending()) {
725 // Gtk.main_iteration();
728 this.win.leftpane.el.hide();
729 this.win.codeeditview.el.show();
730 //while (Gtk.events_pending()) {
731 // Gtk.main_iteration();
735 this.code_editor.el.show_all();
737 this.win.codeeditview.el.set_scale(1.0f,1.0f);
738 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
743 if (this.win.project.xtype == "Roo") {
744 this.projectsettings.el.show_all();
745 this.projectsettings.show(this.win.project);
747 this.vala_projectsettings.el.show_all();
748 this.vala_projectsettings.show((Project.Gtk)this.win.project);
751 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
753 this.win.projecteditview.el.set_scale(1.0f,1.0f);
758 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
761 this.win.editpane.el.hide(); // holder for tree and properties..
763 this.left_projects.el.show();
765 // rotate the preview to hidden...
766 this.win.rooview.el.set_easing_duration(1000);
767 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
768 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
769 this.win.rooview.el.set_opacity(0);
774 if (this.win.project != null) {
775 this.left_projects.selectProject(this.win.project);
779 this.clutterfiles.el.show();
781 this.clutterfiles.el.set_easing_duration(1000);
782 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
783 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
784 this.clutterfiles.el.set_opacity(0xff);
792 this.resizeCanvasElements();
793 this.easingRestoreAll();
795 // run the animation.. - then load files...
800 public int redraw_count = 0;
801 public void resizeCanvas() // called by window resize .. delays redraw
803 var rc = this.redraw_count;
804 this.redraw_count = 2;
806 GLib.Timeout.add(100, () =>{
807 return this.resizeCanvasQueue();
811 public bool resizeCanvasQueue()
813 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
815 if (this.redraw_count < 1) {
816 return false; // should not really happen...
822 if (this.redraw_count > 0) {
823 return true; // do it again in 1 second...
825 // got down to 0 or -1....
826 this.redraw_count = 0;
827 this.resizeCanvasElements();
831 public void resizeCanvasElements()
833 Gtk.Allocation alloc;
834 this.win.clutterembed.el.get_allocation(out alloc);
836 // print("WindowState.resizeCanvasElements\n");
837 if (!this.children_loaded || this.win.clutterembed == null) {
838 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
842 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
843 var palsize = avail < 300.0f ? avail : 300.0f;
846 // -------- code edit min 600
848 var codesize = avail < 800.0f ? avail : 800.0f;
851 //print("set code size %f\n", codesize);
855 switch ( this.state) {
858 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
862 this.clutterfiles.set_size(alloc.width-50, alloc.height);
867 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
869 // this.win.rooview.el.save_easing_state();
870 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
872 this.win.rooview.el.set_scale(0.5f, 0.5f);
873 //this.win.rooview.el.restore_easing_state();
877 this.win.codeeditview.el.set_size(codesize, alloc.height);
878 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
879 //this.win.rooview.el.save_easing_state();
881 this.win.rooview.el.set_scale(scale,scale);
882 // this.win.rooview.el.restore_easing_state();
886 this.win.codeeditview.el.set_size(codesize, alloc.height);
887 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
888 //this.win.rooview.el.save_easing_state();
889 this.win.rooview.el.hide();
890 this.win.rooview.el.set_scale(scale,scale);
891 // this.win.rooview.el.restore_easing_state();
895 this.win.addpropsview.el.set_size(palsize, alloc.height);
896 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
897 this.win.rooview.el.set_scale(scale,scale);
901 this.win.objectview.el.set_size(palsize, alloc.height);
902 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
903 //this.win.rooview.el.save_easing_state();
904 this.win.rooview.el.set_scale(scale,scale);
905 // this.win.rooview.el.restore_easing_state();
910 // -- buttons show hide.....
912 public void buttonsShowHide()
914 // basically hide everything, then show the relivant..
916 this.win.backbutton.el.hide();
918 this.win.projectbutton.el.hide(); // show file nav...
919 this.win.editfilebutton.el.hide();
920 this.win.projecteditbutton.el.hide();
923 this.win.objectshowbutton.el.hide(); // add objects
924 this.win.addpropbutton.el.hide();
925 this.win.addlistenerbutton.el.hide();
929 this.win.addprojectbutton.el.hide();
930 this.win.addfilebutton.el.hide();
931 this.win.delprojectbutton.el.hide();
934 switch (this.state) {
936 case State.PREVIEW: // this is the default state when working...
938 this.win.projectbutton.el.show(); // show file nav...
939 this.win.editfilebutton.el.show();
940 this.win.projecteditbutton.el.show();
943 this.win.objectshowbutton.el.show(); // add objects
944 this.win.addpropbutton.el.show();
945 this.win.addlistenerbutton.el.show();
949 this.win.projectbutton.el.show();
957 this.win.backbutton.el.show();
958 this.win.objectshowbutton.el.show(); // add objects
959 this.win.addpropbutton.el.show();
960 this.win.addlistenerbutton.el.show();
965 this.win.backbutton.el.show();
970 if (this.left_projects.getSelectedProject() != null ) {
971 if (this.left_tree.getActiveFile() != null) {
972 this.win.backbutton.el.show();
974 this.win.addfilebutton.el.show();
977 this.win.addprojectbutton.el.show();
978 this.win.delprojectbutton.el.show();
988 public void valaCompiled(Json.Object obj)
990 // vala has finished compiling...
991 print("vala compiled");
993 var buf = this.code_editor.buffer;
994 buf.check_running = false;
996 if (obj.has_member("ERR-TOTAL")) {
997 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
999 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1002 if (obj.has_member("WARN-TOTAL")) {
1004 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1006 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1009 if (obj.has_member("DEPR-TOTAL")) {
1011 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1014 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1017 buf.highlightErrorsJson("ERR", obj);
1018 buf.highlightErrorsJson("WARN", obj);
1019 buf.highlightErrorsJson("DEPR", obj);
1021 var gbuf = this.window_gladeview.sourceview;
1022 gbuf.highlightErrorsJson("ERR", obj);
1023 gbuf.highlightErrorsJson("WARN", obj);
1024 gbuf.highlightErrorsJson("DEPR", obj);
1026 this.last_compile_result = obj;