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);
102 this.compile_results = new Xcls_ValaCompileResults();
103 this.compile_results.window = this.win;
104 this.valasource.compile_output.connect(this.compile_results.addLine);
110 public void leftTreeInit()
113 this.left_tree = new Xcls_WindowLeftTree();
114 this.left_tree.ref();
115 this.left_tree.main_window = this.win;
117 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
118 this.left_tree.el.show_all();
120 this.left_tree.before_node_change.connect(() => {
121 return this.leftTreeBeforeChange();
125 this.left_tree.node_selected.connect((sel) => {
126 this.leftTreeNodeSelected(sel);
129 this.left_tree.changed.connect(() => {
132 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
133 this.window_rooview.requestRedraw();
135 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
142 public bool leftTreeBeforeChange()
144 if (this.state != State.CODE) {
145 this.left_props.finish_editing();
148 if (!this.code_editor.saveContents()) {
154 public void leftTreeNodeSelected(JsRender.Node? sel)
157 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
160 this.left_props.el.hide();
162 this.left_props.el.show();
163 this.left_props.load(this.left_tree.getActiveFile(), sel);
164 switch (this.state) {
169 this.rightpalete.clear();
172 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
178 this.add_props.clear();
181 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
187 this.add_props.clear();
190 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
194 this.switchState(State.PREVIEW);
207 public void propsListInit()
210 this.left_props =new Xcls_LeftProps();
211 this.left_props.ref();
212 this.left_props.main_window = this.win;
213 this.win.props.el.pack_start(this.left_props.el,true, true,0);
214 this.left_props.el.show_all();
216 this.left_props.show_editor.connect( (file, node, type, key) => {
217 this.switchState(State.CODE);
218 this.code_editor.show(
229 this.left_props.stop_editor.connect( () => {
230 if (this.state != State.CODE) {
234 var ret = this.code_editor.saveContents();
238 this.switchState(State.PREVIEW);
242 this.left_props.changed.connect(() => {
243 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
244 this.window_rooview.requestRedraw();
246 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
248 this.left_tree.model.updateSelected();
250 if (this.file.xtype=="Gtk") {
251 this.valasource.checkFileSpawn(this.file);
259 //------------- projects edit
261 public void projectEditInit()
263 this.projectsettings =new Xcls_ProjectSettings();
264 this.projectsettings.ref(); /// really?
266 this.vala_projectsettings =new ValaProjectSettings();
267 this.vala_projectsettings.ref();
268 this.vala_projectsettings.window = this.win;
270 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
271 //this.projectsettings.el.show_all();
273 var stage = this.win.projecteditview.el.get_stage();
274 stage.set_background_color( Clutter.Color.from_string("#000"));
276 this.projectsettings.buttonPressed.connect((btn) => {
277 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
279 this.window_rooview.view.renderJS(true);
281 if (btn == "apply") {
282 this.window_rooview.view.renderJS(true);
286 // do nothing for gtk..
288 if (btn == "save" || btn == "apply") {
289 this.win.project.save();
292 this.switchState (State.PREVIEW);
297 // ----------- object adding
298 public void objectAddInit()
301 this.rightpalete = new Xcls_RightPalete();
302 this.rightpalete.ref(); /// really?
303 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
304 //this.projectsettings.el.show_all();
306 var stage = this.win.objectview.el.get_stage();
307 stage.set_background_color( Clutter.Color.from_string("#000"));
311 // ----------- properties adding list...
312 // listener uses the properties
313 public void propsAddInit()
316 this.add_props = new Xcls_WindowAddProp();
317 this.add_props.ref(); /// really?
318 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
319 //this.projectsettings.el.show_all();
321 var stage = this.win.addpropsview.el.get_stage();
322 stage.set_background_color( Clutter.Color.from_string("#000"));
325 this.add_props.select.connect( (key,type,skel, etype) => {
326 this.left_props.addProp(etype, key, skel, type);
330 public void propsAddShow()
334 public void propsAddHide()
342 // ----------- Add / Edit listener
343 // listener uses the properties
344 //public void listenerInit() { }
345 public void listenerShow()
349 public void listenerHide()
354 // -------------- codeEditor
356 public void codeEditInit()
358 this.code_editor = new Editor();
359 //this.code_editor.ref(); /// really?
360 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
362 this.code_editor.window = this.win;
363 //this.projectsettings.el.show_all();
365 var stage = this.win.codeeditview.el.get_stage();
366 stage.set_background_color( Clutter.Color.from_string("#000"));
369 this.code_editor.save.connect( () => {
371 this.left_tree.model.updateSelected();
372 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
373 this.window_rooview.requestRedraw();
375 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
377 // we do not need to call spawn... - as it's already called by the editor?
383 // ----------- list of projects on left
384 public void projectListInit()
387 this.left_projects = new Xcls_WindowLeftProjects();
388 this.left_projects.ref();
389 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
390 this.left_projects.el.show_all();
391 this.left_projects.project_selected.connect((proj) => {
392 this.buttonsShowHide();
394 this.clutterfiles.loadProject(proj);
399 // ----------- file view
401 public void fileViewInit()
403 var stage = this.win.rooview.el.get_stage(); // seems odd...
404 this.clutterfiles = new Xcls_ClutterFiles();
405 this.clutterfiles.ref();
406 stage.add_child(this.clutterfiles.el);
407 this.clutterfiles.el.show();
410 this.clutterfiles.open.connect((file) => {
411 this.fileViewOpen(file);
413 this.clutterfiles.el.transitions_completed.connect(() => {
414 if (this.state == State.FILES) {
415 this.win.rooview.el.hide();
417 this.clutterfiles.el.hide();
425 public void fileDetailsInit()
427 this.file_details = new Xcls_PopoverFileDetails();
428 this.file_details.mainwindow = this.win;
429 // force it modal to the main window..
431 this.file_details.success.connect((project,file) =>
433 this.fileViewOpen(file);
438 public void fileViewOpen(JsRender.JsRender file, int line = -1)
440 this.win.project = file.project;
441 this.project = file.project;
445 if (file.xtype == "PlainFile") {
446 this.switchState (State.CODEONLY);
448 this.code_editor.show(file, null, "", "");
450 this.code_editor.scroll_to_line(line);
454 this.switchState (State.PREVIEW);
455 // this triggers loadItems..
456 this.left_tree.model.loadFile(file);
457 if (file.project.xtype == "Gtk" && line> -1 ) {
458 this.window_gladeview.scroll_to_line(line);
464 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
465 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
467 if (file.project.xtype == "Roo" ) {
468 ctr.foreach( (w) => { ctr.remove(w); });
469 ctr_p.foreach( (w) => { ctr_p.remove(w); });
470 ctr.add(this.window_rooview.el);
471 ctr_p.add(this.projectsettings.el);
472 if (file.xtype != "PlainFile") {
473 this.window_rooview.loadFile(file);
474 this.window_rooview.el.show_all();
476 this.projectsettings.el.show_all();
480 ctr.foreach( (w) => { ctr.remove(w); });
481 ctr_p.foreach( (w) => { ctr_p.remove(w); });
482 ctr.add(this.window_gladeview.el);
483 ctr_p.add(this.vala_projectsettings.el);
484 if (file.xtype != "PlainFile") {
485 this.window_gladeview.loadFile(file);
486 this.window_gladeview.el.show_all();
488 this.vala_projectsettings.el.show_all();
490 print("OPEN : " + file.name);
491 if (file.xtype != "PlainFile") {
492 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
494 this.win.setTitle(file.project.name + " : " + file.name);
500 // --------- webkit view
501 public void webkitViewInit()
503 this.window_rooview =new Xcls_WindowRooView();
504 this.window_rooview.ref();
505 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
506 this.window_rooview.el.show_all();
508 var stage = this.win.rooview.el.get_stage();
509 stage.set_background_color( Clutter.Color.from_string("#000"));
514 public void gtkViewInit()
516 this.window_gladeview =new Xcls_GtkView();
517 this.window_gladeview.ref();
518 this.window_gladeview.main_window = this.win;
521 public void easingSaveAll()
523 this.win.addpropsview.el.save_easing_state();
524 this.win.codeeditview.el.save_easing_state();
525 this.win.objectview.el.save_easing_state();
526 this.win.projecteditview.el.save_easing_state();
527 this.win.rooview.el.save_easing_state();
528 this.clutterfiles.el.save_easing_state();
531 public void easingRestoreAll()
533 this.win.addpropsview.el.restore_easing_state();
534 this.win.codeeditview.el.restore_easing_state();
535 this.win.objectview.el.restore_easing_state();
536 this.win.projecteditview.el.restore_easing_state();
537 this.win.rooview.el.restore_easing_state();
538 this.clutterfiles.el.restore_easing_state();
541 public void switchState(State new_state)
544 // if the new state and the old state are the same..
546 if (new_state == this.state) {
550 // save the easing state of everything..
551 this.easingSaveAll();
553 switch (this.state) {
556 if (this.left_tree.getActiveFile() != null) {
557 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
558 this.window_rooview.createThumb();
560 this.window_gladeview.createThumb();
563 // normally we are going from preview to another state.
564 // and different windows hide the preview in differnt ways..
571 this.win.addpropsview.el.set_scale(0.0f,0.0f);
575 this.code_editor.saveContents();
577 this.win.codeeditview.el.set_scale(0.0f,0.0f);
581 // going from codeonly..
582 this.win.leftpane.el.show();
583 // enable re-calc of canvas..
584 while (Gtk.events_pending()) {
585 Gtk.main_iteration();
587 //this.code_editor.saveContents(); << not yet...
589 this.win.rooview.el.show();
590 this.win.codeeditview.el.set_scale(0.0f,0.0f);
596 this.win.objectview.el.set_scale(0.0f,0.0f);
600 if (this.win.project.xtype == "Gtk") {
601 this.vala_projectsettings.save();
604 this.win.projecteditview.el.set_scale(0.0f,0.0f);
607 case State.FILES: // goes to preview or codeonly...
610 if (new_state == State.CODEONLY) {
611 this.win.rooview.el.hide();
613 this.win.rooview.el.show();
616 this.win.rooview.el.set_easing_duration(1000);
617 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
618 this.win.rooview.el.set_scale(1.0f,1.0f);
619 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
620 this.win.rooview.el.set_opacity(0xff);
624 this.clutterfiles.el.set_easing_duration(1000);
625 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
626 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
627 this.clutterfiles.el.set_opacity(0);
629 //this.clutterfiles.el.hide();
637 var oldstate =this.state;
638 this.state = new_state;
642 this.buttonsShowHide();
645 switch (this.state) {
647 case State.PREVIEW: // this is the default state when working...
648 this.win.editpane.el.show(); // holder for tree and properties..
651 this.left_projects.el.hide();
652 if (oldstate != State.FILES) {
653 // it's handled above..
654 print ("changing state to preview from NOT files..");
657 this.win.rooview.el.set_scale(1.0f,1.0f);
666 var ae = this.left_tree.getActiveElement();
668 this.state = oldstate;
669 this.buttonsShowHide();
670 this.resizeCanvasElements();
671 this.easingRestoreAll();
674 this.add_props.el.show_all();
676 Palete.factory(this.win.project.xtype),
677 this.state == State.LISTENER ? "signals" : "props",
684 // -- FIXME? this needs to be State aware?
686 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
688 this.win.addpropsview.el.set_scale(1.0f,1.0f);
692 var n = this.left_tree.getActiveElement();
694 if (this.file == null) {
695 this.state =oldstate;
696 this.buttonsShowHide();
697 this.resizeCanvasElements();
698 this.easingRestoreAll();
702 if (n == null && this.file.tree != null) {
703 this.state = oldstate;
704 this.buttonsShowHide();
705 this.resizeCanvasElements();
706 this.easingRestoreAll();
710 this.rightpalete.el.show_all();
711 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
715 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
716 this.win.objectview.el.set_scale(1.0f,1.0f);
722 this.win.codeeditview.el.show();
723 this.code_editor.el.show_all();
724 // caller needs to call editor - show....
725 this.win.codeeditview.el.set_scale(1.0f,1.0f);
726 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
731 // going to codeonly..
732 this.win.codeeditview.el.show();
734 //while (Gtk.events_pending()) {
735 // Gtk.main_iteration();
738 this.win.leftpane.el.hide();
739 this.win.codeeditview.el.show();
740 //while (Gtk.events_pending()) {
741 // Gtk.main_iteration();
745 this.code_editor.el.show_all();
747 this.win.codeeditview.el.set_scale(1.0f,1.0f);
748 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
753 if (this.win.project.xtype == "Roo") {
754 this.projectsettings.el.show_all();
755 this.projectsettings.show(this.win.project);
757 this.vala_projectsettings.el.show_all();
758 this.vala_projectsettings.show((Project.Gtk)this.win.project);
761 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
763 this.win.projecteditview.el.set_scale(1.0f,1.0f);
768 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
771 this.win.editpane.el.hide(); // holder for tree and properties..
773 this.left_projects.el.show();
775 // rotate the preview to hidden...
776 this.win.rooview.el.set_easing_duration(1000);
777 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
778 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
779 this.win.rooview.el.set_opacity(0);
784 if (this.win.project != null) {
785 this.left_projects.selectProject(this.win.project);
789 this.clutterfiles.el.show();
791 this.clutterfiles.el.set_easing_duration(1000);
792 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
793 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
794 this.clutterfiles.el.set_opacity(0xff);
802 this.resizeCanvasElements();
803 this.easingRestoreAll();
805 // run the animation.. - then load files...
806 GLib.Timeout.add(500, () =>{
807 this.resizeCanvasElements();
813 public int redraw_count = 0;
814 public void resizeCanvas() // called by window resize .. delays redraw
816 var rc = this.redraw_count;
817 this.redraw_count = 2;
819 GLib.Timeout.add(100, () =>{
820 return this.resizeCanvasQueue();
824 public bool resizeCanvasQueue()
826 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
828 if (this.redraw_count < 1) {
829 return false; // should not really happen...
835 if (this.redraw_count > 0) {
836 return true; // do it again in 1 second...
838 // got down to 0 or -1....
839 this.redraw_count = 0;
840 this.resizeCanvasElements();
844 public void resizeCanvasElements()
846 Gtk.Allocation alloc;
847 this.win.clutterembed.el.get_allocation(out alloc);
849 // print("WindowState.resizeCanvasElements\n");
850 if (!this.children_loaded || this.win.clutterembed == null) {
851 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
855 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
856 var palsize = avail < 300.0f ? avail : 300.0f;
859 // -------- code edit min 600
861 var codesize = avail < 800.0f ? avail : 800.0f;
864 //print("set code size %f\n", codesize);
868 switch ( this.state) {
871 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
875 this.clutterfiles.set_size(alloc.width-50, alloc.height);
880 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
882 // this.win.rooview.el.save_easing_state();
883 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
885 this.win.rooview.el.set_scale(0.5f, 0.5f);
886 //this.win.rooview.el.restore_easing_state();
890 this.win.codeeditview.el.set_size(codesize, alloc.height);
891 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
892 //this.win.rooview.el.save_easing_state();
894 this.win.rooview.el.set_scale(scale,scale);
895 // this.win.rooview.el.restore_easing_state();
899 this.win.codeeditview.el.set_size(codesize, alloc.height);
900 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
901 //this.win.rooview.el.save_easing_state();
902 this.win.rooview.el.hide();
903 this.win.rooview.el.set_scale(scale,scale);
904 // this.win.rooview.el.restore_easing_state();
908 this.win.addpropsview.el.set_size(palsize, alloc.height);
909 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
910 this.win.rooview.el.set_scale(scale,scale);
914 this.win.objectview.el.set_size(palsize, alloc.height);
915 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
916 //this.win.rooview.el.save_easing_state();
917 this.win.rooview.el.set_scale(scale,scale);
918 // this.win.rooview.el.restore_easing_state();
923 // -- buttons show hide.....
925 public void buttonsShowHide()
927 // basically hide everything, then show the relivant..
929 this.win.backbutton.el.hide();
931 this.win.projectbutton.el.hide(); // show file nav...
932 this.win.editfilebutton.el.hide();
933 this.win.projecteditbutton.el.hide();
936 this.win.objectshowbutton.el.hide(); // add objects
937 this.win.addpropbutton.el.hide();
938 this.win.addlistenerbutton.el.hide();
942 this.win.addprojectbutton.el.hide();
943 this.win.addfilebutton.el.hide();
944 this.win.delprojectbutton.el.hide();
946 this.win.search_entry.el.hide();
947 this.win.search_results.el.hide();
948 switch (this.state) {
950 case State.PREVIEW: // this is the default state when working...
952 this.win.projectbutton.el.show(); // show file nav...
953 this.win.editfilebutton.el.show();
954 this.win.projecteditbutton.el.show();
957 this.win.objectshowbutton.el.show(); // add objects
958 this.win.addpropbutton.el.show();
959 this.win.addlistenerbutton.el.show();
960 this.win.search_entry.el.show();
961 this.win.search_results.el.show();
966 this.win.projectbutton.el.show();
967 this.win.search_entry.el.show();
968 this.win.search_results.el.show();
976 this.win.backbutton.el.show();
977 this.win.objectshowbutton.el.show(); // add objects
978 this.win.addpropbutton.el.show();
979 this.win.addlistenerbutton.el.show();
984 this.win.backbutton.el.show();
990 if (this.left_projects.getSelectedProject() != null ) {
991 if (this.left_tree.getActiveFile() != null) {
992 this.win.backbutton.el.show();
994 this.win.addfilebutton.el.show();
995 this.win.search_entry.el.show();
996 this.win.search_results.el.show();
1000 this.win.addprojectbutton.el.show();
1001 this.win.delprojectbutton.el.show();
1014 public void valaCompiled(Json.Object obj)
1016 // vala has finished compiling...
1017 print("vala compiled");
1019 var buf = this.code_editor.buffer;
1020 buf.check_running = false;
1022 if (obj.has_member("ERR-TOTAL")) {
1023 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
1025 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1028 if (obj.has_member("WARN-TOTAL")) {
1030 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1032 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1035 if (obj.has_member("DEPR-TOTAL")) {
1037 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1040 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1043 buf.highlightErrorsJson("ERR", obj);
1044 buf.highlightErrorsJson("WARN", obj);
1045 buf.highlightErrorsJson("DEPR", obj);
1047 if (this.file.xtype == "Gtk") {
1048 var gbuf = this.window_gladeview.sourceview;
1049 gbuf.highlightErrorsJson("ERR", obj);
1050 gbuf.highlightErrorsJson("WARN", obj);
1051 gbuf.highlightErrorsJson("DEPR", obj);
1054 this.last_compile_result = obj;