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;
18 //CODE, // code editor.
25 public State state = State.NONE;
27 public bool children_loaded = false;
29 public Project.Project project;
30 public JsRender.JsRender file;
32 public Xcls_WindowLeftTree left_tree;
33 public Xcls_PopoverAddProp add_props;
34 public Xcls_LeftProps left_props;
35 public Xcls_RooProjectSettings roo_projectsettings_pop;
36 public Xcls_ValaProjectSettingsPopover vala_projectsettings_pop;
37 public Xcls_PopoverAddObject rightpalete;
38 public Xcls_PopoverEditor code_editor_popover;
39 public Editor code_editor_tab;
40 public Xcls_WindowRooView window_rooview;
41 public Xcls_GtkView window_gladeview;
43 public Xcls_ClutterFiles clutterfiles;
45 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
47 public DialogTemplateSelect template_select;
49 public Xcls_PopoverFileDetails file_details;
52 public Xcls_ValaCompileResults compile_results;
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.codePopoverEditInit();
75 this.projectListInit();
85 this.webkitViewInit();
89 this.fileDetailsInit();
91 this.webkit_plugin = new Xcls_DialogPluginWebkit();
92 this.template_select = new DialogTemplateSelect();
93 this.children_loaded = true;
96 this.valasource = new Palete.ValaSource(this.win);
98 this.valasource.compiled.connect(this.showCompileResult);
100 this.compile_results = new Xcls_ValaCompileResults();
101 this.compile_results.window = this.win;
102 this.valasource.compile_output.connect(this.compile_results.addLine);
104 this.win.statusbar_compilestatus_label.el.hide();
105 this.win.statusbar_run.el.hide();
106 this.win.search_results.el.hide();
112 public void leftTreeInit()
115 this.left_tree = new Xcls_WindowLeftTree();
116 this.left_tree.ref();
117 this.left_tree.main_window = this.win;
119 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
120 this.left_tree.el.show_all();
122 this.left_tree.before_node_change.connect(() => {
123 // if the node change is caused by the editor (code preview)
124 if (this.left_tree.view.lastEventSource == "editor") {
127 return this.leftTreeBeforeChange();
130 // node selected -- only by clicking?
131 this.left_tree.node_selected.connect((sel, source) => {
132 if (source == "editor") {
135 if (this.file.xtype == "Roo") {
136 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
138 this.window_gladeview.sourceview.nodeSelected(sel);
142 this.left_tree.node_selected.connect((sel, source) => {
143 this.leftTreeNodeSelected(sel, source);
146 this.left_tree.changed.connect(() => {
147 print("LEFT TREE: Changed fired\n");
149 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
150 this.window_rooview.requestRedraw();
152 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
159 public bool leftTreeBeforeChange()
161 // in theory code editor has to hide before tree change occurs.
162 //if (this.state != State.CODE) {
163 this.left_props.finish_editing();
167 //if (!this.code_editor.saveContents()) {
173 public void leftTreeNodeSelected(JsRender.Node? sel, string source)
176 // do we really want to flip paletes if differnt nodes are selected
177 // showing palete should be deliberate thing..
180 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
183 this.left_props.el.hide();
185 this.left_props.el.show();
186 this.left_props.load(this.left_tree.getActiveFile(), sel);
189 // if either of these are active.. then we should update them??
191 this.add_props.hide(); // always hide add node/add listener if we change node.
192 this.rightpalete.hide();
196 switch (this.state) {
199 this.switchState(State.PREVIEW);
214 public void propsListInit()
217 this.left_props =new Xcls_LeftProps();
218 this.left_props.ref();
219 this.left_props.main_window = this.win;
220 this.win.props.el.pack_start(this.left_props.el,true, true,0);
221 this.left_props.el.show_all();
223 this.left_props.show_editor.connect( (file, node, type, key) => {
224 //this.switchState(State.CODE);
225 this.code_editor_popover.show(
236 // not sure if this is needed - as closing the popvoer should save it.
237 this.left_props.stop_editor.connect( () => {
238 //if (this.state != State.CODE) {
242 var ret = this.code_editor_popover.editor.saveContents();
246 //this.switchState(State.PREVIEW);
250 this.left_props.changed.connect(() => {
251 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
252 this.window_rooview.requestRedraw();
254 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
256 this.left_tree.model.updateSelected();
258 if (this.file.xtype=="Gtk") {
259 this.valasource.checkFileSpawn(this.file);
267 //------------- projects edit
269 public void projectEditInit()
271 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
272 this.roo_projectsettings_pop.ref(); /// really?
274 this.vala_projectsettings_pop =new Xcls_ValaProjectSettingsPopover();
275 this.vala_projectsettings_pop.ref();
276 this.vala_projectsettings_pop.window = this.win;
278 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
281 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
282 // in theory active file can only be rooo...
283 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
285 this.window_rooview.view.renderJS(true);
286 this.roo_projectsettings_pop.el.hide();
288 if (btn == "apply") {
289 this.window_rooview.view.renderJS(true);
293 // do nothing for gtk..
295 if (btn == "save" || btn == "apply") {
296 this.win.project.save();
299 //this.switchState (State.PREVIEW);
304 public void projectPopoverShow(Gtk.Widget btn)
307 var pr = this.project;
308 var active_file = this.left_tree.getActiveFile() ;
309 if (active_file != null) {
310 xtype = active_file.xtype;
312 // we might be on the file brower..
313 pr = this.left_projects.getSelectedProject();
321 if (xtype == "Roo" ) {
322 this.roo_projectsettings_pop.show(btn,pr);
327 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
332 // ----------- object adding
333 public void objectAddInit()
336 this.rightpalete = new Xcls_PopoverAddObject();
337 this.rightpalete.mainwindow = this.win;
338 this.rightpalete.ref(); /// really?
339 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
342 var stage = this.win.objectview.el.get_stage();
343 stage.set_background_color( Clutter.Color.from_string("#000"));
347 // ----------- properties adding list...
348 // listener uses the properties
349 public void propsAddInit()
352 this.add_props = new Xcls_PopoverAddProp();
353 this.add_props.mainwindow = this.win;
354 this.add_props.ref(); /// really?
355 // don't need to add it..
356 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
359 //var stage = this.win.addpropsview.el.get_stage();
360 //stage.set_background_color( Clutter.Color.from_string("#000"));
363 this.add_props.select.connect( (key,type,skel, etype) => {
365 this.left_props.addProp(etype, key, skel, type);
369 public void propsAddShow()
373 public void propsAddHide()
379 // ----------- Add / Edit listener
380 // listener uses the properties
381 //public void listenerInit() { }
382 public void listenerShow()
386 public void listenerHide()
391 // -------------- codeEditor
393 public void codeEditInit()
395 this.code_editor_tab = new Editor();
396 //this.code_editor.ref(); /// really?
397 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor_tab.el);
399 this.code_editor_tab.window = this.win;
402 var stage = this.win.codeeditview.el.get_stage();
403 stage.set_background_color( Clutter.Color.from_string("#000"));
406 this.code_editor_tab.save.connect( () => {
408 this.left_tree.model.updateSelected();
409 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
410 this.window_rooview.requestRedraw();
412 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
414 // we do not need to call spawn... - as it's already called by the editor?
419 public void codePopoverEditInit()
421 this.code_editor_popover = new Xcls_PopoverEditor();
422 //this.code_editor.ref(); /// really?
424 this.code_editor_popover.setMainWindow( this.win);
426 this.code_editor_popover.editor.save.connect( () => {
428 this.left_tree.model.updateSelected();
429 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
430 this.window_rooview.requestRedraw();
432 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
434 // we do not need to call spawn... - as it's already called by the editor?
439 // ----------- list of projects on left
440 public void projectListInit()
443 this.left_projects = new Xcls_WindowLeftProjects();
444 this.left_projects.ref();
445 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
446 this.left_projects.el.show_all();
447 this.left_projects.project_selected.connect((proj) => {
448 this.buttonsShowHide();
450 this.clutterfiles.loadProject(proj);
455 // ----------- file view
457 public void fileViewInit()
459 var stage = this.win.rooview.el.get_stage(); // seems odd...
460 this.clutterfiles = new Xcls_ClutterFiles();
461 this.clutterfiles.ref();
462 stage.add_child(this.clutterfiles.el);
463 this.clutterfiles.el.show();
466 this.clutterfiles.open.connect((file) => {
467 this.fileViewOpen(file);
469 this.clutterfiles.el.transitions_completed.connect(() => {
470 if (this.state == State.FILES) {
471 this.win.rooview.el.hide();
473 this.clutterfiles.el.hide();
481 public void fileDetailsInit()
483 this.file_details = new Xcls_PopoverFileDetails();
484 this.file_details.mainwindow = this.win;
485 // force it modal to the main window..
487 this.file_details.success.connect((project,file) =>
489 this.fileViewOpen(file);
494 public void fileViewOpen(JsRender.JsRender file, int line = -1)
496 this.win.project = file.project;
497 this.project = file.project;
501 if (file.xtype == "PlainFile") {
502 this.switchState (State.CODEONLY);
504 this.code_editor_tab.show(file, null, "", "");
506 this.code_editor_tab.scroll_to_line(line);
510 this.switchState (State.PREVIEW);
511 // this triggers loadItems..
512 this.left_tree.model.loadFile(file);
513 if (file.project.xtype == "Gtk" && line> -1 ) {
514 this.window_gladeview.scroll_to_line(line);
520 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
523 if (file.project.xtype == "Roo" ) {
524 ctr.foreach( (w) => { ctr.remove(w); });
526 ctr.add(this.window_rooview.el);
528 if (file.xtype != "PlainFile") {
529 this.window_rooview.loadFile(file);
530 this.window_rooview.el.show_all();
536 ctr.foreach( (w) => { ctr.remove(w); });
538 ctr.add(this.window_gladeview.el);
540 if (file.xtype != "PlainFile") {
541 this.window_gladeview.loadFile(file);
542 this.window_gladeview.el.show_all();
546 print("OPEN : " + file.name);
547 if (file.xtype != "PlainFile") {
548 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
550 this.win.setTitle(file.project.name + " : " + file.name);
557 public void fileViewOpenPlain(string fname)
560 this.switchState (State.CODEONLY);
561 this.code_editor.showPlainFile(fname);
565 // --------- webkit view
566 public void webkitViewInit()
568 this.window_rooview =new Xcls_WindowRooView();
569 this.window_rooview.main_window = this.win;
570 this.window_rooview.ref();
571 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
572 this.window_rooview.el.show_all();
574 var stage = this.win.rooview.el.get_stage();
575 stage.set_background_color( Clutter.Color.from_string("#000"));
580 public void gtkViewInit()
582 this.window_gladeview =new Xcls_GtkView();
583 this.window_gladeview.ref();
584 this.window_gladeview.main_window = this.win;
587 public void easingSaveAll()
589 this.win.addpropsview.el.save_easing_state();
590 this.win.codeeditview.el.save_easing_state();
591 this.win.objectview.el.save_easing_state();
592 this.win.rooview.el.save_easing_state();
593 this.clutterfiles.el.save_easing_state();
596 public void easingRestoreAll()
598 this.win.addpropsview.el.restore_easing_state();
599 this.win.codeeditview.el.restore_easing_state();
600 this.win.objectview.el.restore_easing_state();
601 this.win.rooview.el.restore_easing_state();
602 this.clutterfiles.el.restore_easing_state();
607 public void showProps(Gtk.Widget btn, string sig_or_listen)
609 var ae = this.left_tree.getActiveElement();
613 this.rightpalete.hide();
615 this.add_props.el.show_all();
617 this.win.project.palete, //Palete.factory(this.win.project.xtype),
618 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
625 public void showAddObject(Gtk.Widget btn)
628 var n = this.left_tree.getActiveElement();
629 this.add_props.hide();
630 this.rightpalete.el.show_all();
631 this.rightpalete.show(
632 this.left_tree.getActiveFile().palete(),
633 n == null ? "*top" : n.fqn(),
641 public void switchState(State new_state)
644 // if the new state and the old state are the same..
646 if (new_state == this.state) {
650 // stop werid stuff happening
652 if (this.state == State.FILES
653 //&& new_state == State.FILEPROJECT
654 && this.left_projects.getSelectedProject() == null) {
657 // save the easing state of everything..
658 this.easingSaveAll();
660 switch (this.state) {
663 if (this.left_tree.getActiveFile() != null) {
664 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
665 this.window_rooview.createThumb();
667 this.window_gladeview.createThumb();
670 // normally we are going from preview to another state.
671 // and different windows hide the preview in differnt ways..
679 // going from codeonly..
681 // enable re-calc of canvas..
683 //this.code_editor.saveContents(); << not yet...
685 this.win.rooview.el.show();
686 this.win.leftpane.el.show();
687 this.win.codeeditview.el.set_scale(0.0f,0.0f);
691 while (Gtk.events_pending()) {
692 Gtk.main_iteration();
695 // hides it completely...
700 case State.FILES: // goes to preview or codeonly...
705 if (new_state == State.CODEONLY) {
706 this.win.rooview.el.hide();
708 this.win.rooview.el.show();
711 this.win.rooview.el.set_easing_duration(1000);
712 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
713 this.win.rooview.el.set_scale(1.0f,1.0f);
714 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
715 this.win.rooview.el.set_opacity(0xff);
717 this.clutterfiles.el.set_easing_duration(1000);
718 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
719 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
720 this.clutterfiles.el.set_opacity(0);
723 //this.clutterfiles.el.hide();
731 var oldstate =this.state;
732 this.state = new_state;
736 this.buttonsShowHide();
739 switch (this.state) {
741 case State.PREVIEW: // this is the default state when working...
742 this.win.editpane.el.show(); // holder for tree and properties..
745 this.left_projects.el.hide();
746 if (oldstate != State.FILES) {
747 // it's handled above..
748 print ("changing state to preview from NOT files..");
751 this.win.rooview.el.set_scale(1.0f,1.0f);
760 // going to codeonly..
761 this.win.codeeditview.el.show();
763 //while (Gtk.events_pending()) {
764 // Gtk.main_iteration();
767 this.win.leftpane.el.hide();
768 this.win.codeeditview.el.show();
769 //while (Gtk.events_pending()) {
770 // Gtk.main_iteration();
774 this.code_editor_tab.el.show_all();
776 this.win.codeeditview.el.set_scale(1.0f,1.0f);
777 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
781 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
784 this.win.editpane.el.hide(); // holder for tree and properties..
786 this.left_projects.el.show();
788 // rotate the preview to hidden...
789 this.win.rooview.el.set_easing_duration(1000);
790 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
791 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
792 this.win.rooview.el.set_opacity(0);
797 if (this.win.project != null) {
798 this.left_projects.selectProject(this.win.project);
802 this.clutterfiles.el.show();
804 this.clutterfiles.el.set_easing_duration(1000);
805 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
806 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
807 this.clutterfiles.el.set_opacity(0xff);
815 this.resizeCanvasElements();
816 this.easingRestoreAll();
818 // run the animation.. - then load files...
819 GLib.Timeout.add(500, () =>{
820 this.resizeCanvasElements();
826 public int redraw_count = 0;
827 public void resizeCanvas() // called by window resize .. delays redraw
829 var rc = this.redraw_count;
830 this.redraw_count = 2;
832 GLib.Timeout.add(100, () =>{
833 return this.resizeCanvasQueue();
837 public bool resizeCanvasQueue()
839 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
841 if (this.redraw_count < 1) {
842 return false; // should not really happen...
848 if (this.redraw_count > 0) {
849 return true; // do it again in 1 second...
851 // got down to 0 or -1....
852 this.redraw_count = 0;
853 this.resizeCanvasElements();
857 public void resizeCanvasElements()
859 Gtk.Allocation alloc;
860 this.win.clutterembed.el.get_allocation(out alloc);
862 // print("WindowState.resizeCanvasElements\n");
863 if (!this.children_loaded || this.win.clutterembed == null) {
864 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
868 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
869 var palsize = avail < 300.0f ? avail : 300.0f;
872 // -------- code edit min 600
874 var codesize = avail < 800.0f ? avail : 800.0f;
877 //print("set code size %f\n", codesize);
881 switch ( this.state) {
884 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
888 this.clutterfiles.set_size(alloc.width-50, alloc.height);
894 this.win.codeeditview.el.set_size(codesize, alloc.height);
895 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
896 //this.win.rooview.el.save_easing_state();
897 this.win.rooview.el.hide();
898 this.win.rooview.el.set_scale(scale,scale);
899 // this.win.rooview.el.restore_easing_state();
905 // -- buttons show hide.....
907 public void buttonsShowHide()
909 // basically hide everything, then show the relivant..
912 this.win.openbtn.el.hide();
913 this.win.openbackbtn.el.hide();
915 this.win.backbutton.el.hide();
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();
932 this.win.search_entry.el.hide();
933 this.win.search_results.el.hide();
934 switch (this.state) {
936 case State.PREVIEW: // this is the default state when working...
939 this.win.editfilebutton.el.show();
940 this.win.projecteditbutton.el.show();
944 this.win.objectshowbutton.el.show(); // add objects
945 this.win.addpropbutton.el.show();
946 this.win.addlistenerbutton.el.show();
947 this.win.search_entry.el.show();
949 this.win.openbtn.el.show();
954 this.win.openbtn.el.show();
955 this.win.projecteditbutton.el.show();
956 this.win.search_entry.el.show();
962 if (this.left_projects.getSelectedProject() != null ) {
963 if (this.left_tree.getActiveFile() != null) {
965 this.win.openbackbtn.el.show();
967 this.win.addfilebutton.el.show();
968 this.win.search_entry.el.show();
969 this.win.projecteditbutton.el.show();
973 this.win.addprojectbutton.el.show();
974 this.win.delprojectbutton.el.show();
987 public void showCompileResult(Json.Object obj)
989 // vala has finished compiling...
990 print("vala compiled");
991 // stop the spinner...
994 var generator = new Json.Generator ();
995 var n = new Json.Node(Json.NodeType.OBJECT);
997 generator.set_root (n);
998 print("result :%s", generator.to_data (null));
1001 var buf = this.code_editor_tab.buffer;
1002 buf.check_running = false;
1003 var has_errors = false;
1005 if (obj.has_member("ERR-TOTAL")) {
1006 if (obj.get_int_member("ERR-TOTAL")> 0) {
1009 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
1011 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1014 if (obj.has_member("WARN-TOTAL")) {
1016 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1018 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1021 if (obj.has_member("DEPR-TOTAL")) {
1023 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1026 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1028 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
1029 if ( this.state == State.CODEONLY) {
1030 buf.highlightErrorsJson("ERR", obj);
1031 buf.highlightErrorsJson("WARN", obj);
1032 buf.highlightErrorsJson("DEPR", obj);
1035 this.win.statusbar_compilestatus_label.el.hide();
1036 this.win.statusbar_run.el.hide();
1038 this.win.statusbar_compilestatus_label.el.show();
1039 this.win.statusbar_run.el.show();
1041 if (this.file.xtype == "Gtk") {
1042 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
1043 var gbuf = this.window_gladeview.sourceview;
1044 gbuf.highlightErrorsJson("ERR", obj);
1045 gbuf.highlightErrorsJson("WARN", obj);
1046 gbuf.highlightErrorsJson("DEPR", obj);
1049 this.win.statusbar_run.el.show();
1054 if (this.file.xtype == "Roo") {
1055 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
1056 var gbuf = this.window_rooview.sourceview;
1057 gbuf.highlightErrorsJson("ERR", obj);
1058 gbuf.highlightErrorsJson("WARN", obj);
1059 gbuf.highlightErrorsJson("DEPR", obj);
1063 this.last_compile_result = obj;