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.
24 public State state = State.NONE;
26 public bool children_loaded = false;
28 public Project.Project project;
29 public JsRender.JsRender file;
31 public Xcls_WindowLeftTree left_tree;
32 public Xcls_PopoverAddProp add_props;
33 public Xcls_LeftProps left_props;
34 public Xcls_RooProjectSettings roo_projectsettings_pop;
35 public Xcls_ValaProjectSettingsPopover vala_projectsettings_pop;
36 public Xcls_PopoverAddObject rightpalete;
37 public Xcls_PopoverEditor code_editor_popover;
38 public Editor code_editor_tab;
39 public Xcls_WindowRooView window_rooview;
40 public Xcls_GtkView window_gladeview;
41 public Xcls_PopoverFiles popover_files;
43 //public Xcls_ClutterFiles clutterfiles;
44 //public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
46 public DialogTemplateSelect template_select;
48 public Xcls_PopoverFileDetails file_details;
51 public Xcls_ValaCompileResults compile_results;
54 public Xcls_DialogPluginWebkit webkit_plugin;
57 public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
58 public Json.Object last_compile_result;
61 public WindowState(Xcls_MainWindow win)
70 // on clutter space...
71 this.projectEditInit();
73 this.codePopoverEditInit();
74 //this.projectListInit();
75 //this.fileViewInit();
84 this.webkitViewInit();
88 this.fileDetailsInit();
90 this.webkit_plugin = new Xcls_DialogPluginWebkit();
91 this.template_select = new DialogTemplateSelect();
92 this.children_loaded = true;
95 this.valasource = new Palete.ValaSource(this.win);
97 this.valasource.compiled.connect(this.showCompileResult);
99 this.compile_results = new Xcls_ValaCompileResults();
100 this.compile_results.window = this.win;
101 this.valasource.compile_output.connect(this.compile_results.addLine);
103 this.win.statusbar_compilestatus_label.el.hide();
104 this.win.statusbar_run.el.hide();
105 this.win.search_results.el.hide();
107 this.popover_files = new Xcls_PopoverFiles();
108 this.popover_files.setMainWindow(this.win);
114 public void leftTreeInit()
117 this.left_tree = new Xcls_WindowLeftTree();
118 this.left_tree.ref();
119 this.left_tree.main_window = this.win;
121 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
122 this.left_tree.el.show_all();
124 this.left_tree.before_node_change.connect(() => {
125 // if the node change is caused by the editor (code preview)
126 if (this.left_tree.view.lastEventSource == "editor") {
129 return this.leftTreeBeforeChange();
132 // node selected -- only by clicking?
133 this.left_tree.node_selected.connect((sel, source) => {
134 if (source == "editor") {
137 if (this.file.xtype == "Roo") {
138 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
140 this.window_gladeview.sourceview.nodeSelected(sel);
144 this.left_tree.node_selected.connect((sel, source) => {
145 this.leftTreeNodeSelected(sel, source);
148 this.left_tree.changed.connect(() => {
149 print("LEFT TREE: Changed fired\n");
151 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
152 this.window_rooview.requestRedraw();
154 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
161 public bool leftTreeBeforeChange()
163 // in theory code editor has to hide before tree change occurs.
164 //if (this.state != State.CODE) {
165 this.left_props.finish_editing();
169 //if (!this.code_editor.saveContents()) {
175 public void leftTreeNodeSelected(JsRender.Node? sel, string source)
178 // do we really want to flip paletes if differnt nodes are selected
179 // showing palete should be deliberate thing..
182 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
185 this.left_props.el.hide();
187 this.left_props.el.show();
188 this.left_props.load(this.left_tree.getActiveFile(), sel);
191 // if either of these are active.. then we should update them??
193 this.add_props.hide(); // always hide add node/add listener if we change node.
194 this.rightpalete.hide();
198 switch (this.state) {
201 this.switchState(State.PREVIEW);
216 public void propsListInit()
219 this.left_props =new Xcls_LeftProps();
220 this.left_props.ref();
221 this.left_props.main_window = this.win;
222 this.win.props.el.pack_start(this.left_props.el,true, true,0);
223 this.left_props.el.show_all();
225 this.left_props.show_editor.connect( (file, node, type, key) => {
226 //this.switchState(State.CODE);
227 this.code_editor_popover.show(
238 // not sure if this is needed - as closing the popvoer should save it.
239 this.left_props.stop_editor.connect( () => {
240 //if (this.state != State.CODE) {
244 var ret = this.code_editor_popover.editor.saveContents();
248 //this.switchState(State.PREVIEW);
252 this.left_props.changed.connect(() => {
253 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
254 this.window_rooview.requestRedraw();
256 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
258 this.left_tree.model.updateSelected();
260 if (this.file.xtype=="Gtk") {
261 this.valasource.checkFileSpawn(this.file);
269 //------------- projects edit
271 public void projectEditInit()
273 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
274 this.roo_projectsettings_pop.ref(); /// really?
276 this.vala_projectsettings_pop =new Xcls_ValaProjectSettingsPopover();
277 this.vala_projectsettings_pop.ref();
278 this.vala_projectsettings_pop.window = this.win;
280 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
283 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
284 // in theory active file can only be rooo...
285 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
287 this.window_rooview.view.renderJS(true);
288 this.roo_projectsettings_pop.el.hide();
290 if (btn == "apply") {
291 this.window_rooview.view.renderJS(true);
295 // do nothing for gtk..
297 if (btn == "save" || btn == "apply") {
298 this.win.project.save();
301 //this.switchState (State.PREVIEW);
306 public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr)
313 var active_file = this.left_tree.getActiveFile() ;
314 if (active_file != null) {
315 xtype = active_file.xtype;
318 return; // no active project
319 // we might be on the file brower..
320 //pr = this.left_projects.getSelectedProject();
326 if (pr.xtype == "") {
329 if (pr.xtype == "Roo" ) {
330 this.roo_projectsettings_pop.show(btn,pr);
335 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
340 // ----------- object adding
341 public void objectAddInit()
344 this.rightpalete = new Xcls_PopoverAddObject();
345 this.rightpalete.mainwindow = this.win;
346 this.rightpalete.ref(); /// really?
347 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
350 var stage = this.win.objectview.el.get_stage();
351 stage.set_background_color( Clutter.Color.from_string("#000"));
355 // ----------- properties adding list...
356 // listener uses the properties
357 public void propsAddInit()
360 this.add_props = new Xcls_PopoverAddProp();
361 this.add_props.mainwindow = this.win;
362 this.add_props.ref(); /// really?
363 // don't need to add it..
364 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
367 //var stage = this.win.addpropsview.el.get_stage();
368 //stage.set_background_color( Clutter.Color.from_string("#000"));
371 this.add_props.select.connect( (key,type,skel, etype) => {
373 this.left_props.addProp(etype, key, skel, type);
377 public void propsAddShow()
381 public void propsAddHide()
387 // ----------- Add / Edit listener
388 // listener uses the properties
389 //public void listenerInit() { }
390 public void listenerShow()
394 public void listenerHide()
399 // -------------- codeEditor
401 public void codeEditInit()
403 this.code_editor_tab = new Editor();
404 //this.code_editor.ref(); /// really?
405 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor_tab.el);
407 this.code_editor_tab.window = this.win;
410 var stage = this.win.codeeditview.el.get_stage();
411 stage.set_background_color( Clutter.Color.from_string("#000"));
414 this.code_editor_tab.save.connect( () => {
416 this.left_tree.model.updateSelected();
417 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
418 this.window_rooview.requestRedraw();
420 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
422 // we do not need to call spawn... - as it's already called by the editor?
427 public void codePopoverEditInit()
429 this.code_editor_popover = new Xcls_PopoverEditor();
430 //this.code_editor.ref(); /// really?
432 this.code_editor_popover.setMainWindow( this.win);
434 this.code_editor_popover.editor.save.connect( () => {
436 this.left_tree.model.updateSelected();
437 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
438 this.window_rooview.requestRedraw();
440 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
442 // we do not need to call spawn... - as it's already called by the editor?
447 // ----------- list of projects on left
449 public void projectListInit()
452 this.left_projects = new Xcls_WindowLeftProjects();
453 this.left_projects.ref();
454 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
455 this.left_projects.el.show_all();
456 this.left_projects.project_selected.connect((proj) => {
457 this.buttonsShowHide();
459 this.clutterfiles.loadProject(proj);
467 // ----------- file view
468 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project)
470 this.popover_files.show(btn, project);
476 public void fileViewInit()
478 var stage = this.win.rooview.el.get_stage(); // seems odd...
479 this.clutterfiles = new Xcls_ClutterFiles();
480 this.clutterfiles.ref();
481 stage.add_child(this.clutterfiles.el);
482 this.clutterfiles.el.show();
485 this.clutterfiles.open.connect((file) => {
486 this.fileViewOpen(file);
488 this.clutterfiles.el.transitions_completed.connect(() => {
489 if (this.state == State.FILES) {
490 this.win.rooview.el.hide();
492 this.clutterfiles.el.hide();
501 public void fileDetailsInit()
503 this.file_details = new Xcls_PopoverFileDetails();
504 this.file_details.mainwindow = this.win;
505 // force it modal to the main window..
507 this.file_details.success.connect((project,file) =>
509 this.fileViewOpen(file);
514 public void fileViewOpen(JsRender.JsRender file, int line = -1)
516 this.win.project = file.project;
517 this.project = file.project;
521 if (file.xtype == "PlainFile") {
522 this.switchState (State.CODEONLY);
524 this.code_editor_tab.show(file, null, "", "");
526 this.code_editor_tab.scroll_to_line(line);
530 this.switchState (State.PREVIEW);
531 // this triggers loadItems..
532 this.left_tree.model.loadFile(file);
533 if (file.project.xtype == "Gtk" && line> -1 ) {
534 this.window_gladeview.scroll_to_line(line);
540 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
543 if (file.project.xtype == "Roo" ) {
544 ctr.foreach( (w) => { ctr.remove(w); });
546 ctr.add(this.window_rooview.el);
548 if (file.xtype != "PlainFile") {
549 this.window_rooview.loadFile(file);
550 this.window_rooview.el.show_all();
556 ctr.foreach( (w) => { ctr.remove(w); });
558 ctr.add(this.window_gladeview.el);
560 if (file.xtype != "PlainFile") {
561 this.window_gladeview.loadFile(file);
562 this.window_gladeview.el.show_all();
566 print("OPEN : " + file.name);
567 if (file.xtype != "PlainFile") {
568 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
570 this.win.setTitle(file.project.name + " : " + file.name);
577 public void fileViewOpenPlain(string fname)
580 this.switchState (State.CODEONLY);
581 this.code_editor.showPlainFile(fname);
585 // --------- webkit view
586 public void webkitViewInit()
588 this.window_rooview =new Xcls_WindowRooView();
589 this.window_rooview.main_window = this.win;
590 this.window_rooview.ref();
591 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
592 this.window_rooview.el.show_all();
594 var stage = this.win.rooview.el.get_stage();
595 stage.set_background_color( Clutter.Color.from_string("#000"));
600 public void gtkViewInit()
602 this.window_gladeview =new Xcls_GtkView();
603 this.window_gladeview.ref();
604 this.window_gladeview.main_window = this.win;
607 public void easingSaveAll()
609 this.win.addpropsview.el.save_easing_state();
610 this.win.codeeditview.el.save_easing_state();
611 this.win.objectview.el.save_easing_state();
612 this.win.rooview.el.save_easing_state();
613 // this.clutterfiles.el.save_easing_state();
616 public void easingRestoreAll()
618 this.win.addpropsview.el.restore_easing_state();
619 this.win.codeeditview.el.restore_easing_state();
620 this.win.objectview.el.restore_easing_state();
621 this.win.rooview.el.restore_easing_state();
622 //this.clutterfiles.el.restore_easing_state();
627 public void showProps(Gtk.Widget btn, string sig_or_listen)
629 var ae = this.left_tree.getActiveElement();
633 this.rightpalete.hide();
635 this.add_props.el.show_all();
637 this.win.project.palete, //Palete.factory(this.win.project.xtype),
638 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
645 public void showAddObject(Gtk.Widget btn)
648 var n = this.left_tree.getActiveElement();
649 this.add_props.hide();
650 this.rightpalete.el.show_all();
651 this.rightpalete.show(
652 this.left_tree.getActiveFile().palete(),
653 n == null ? "*top" : n.fqn(),
657 public void showFilesPopover(Gtk.Widget btn)
659 this.popover_files.el.show_all();
660 this.popover_files.show(btn, this.win.project);
665 public void switchState(State new_state)
668 // if the new state and the old state are the same..
670 if (new_state == this.state) {
674 // stop werid stuff happening
676 //if (this.state == State.FILES
677 //&& new_state == State.FILEPROJECT
678 // && this.left_projects.getSelectedProject() == null) {
681 // save the easing state of everything..
682 this.easingSaveAll();
684 switch (this.state) {
687 if (this.left_tree.getActiveFile() != null) {
688 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
689 this.window_rooview.createThumb();
691 this.window_gladeview.createThumb();
694 // normally we are going from preview to another state.
695 // and different windows hide the preview in differnt ways..
703 // going from codeonly..
705 // enable re-calc of canvas..
707 //this.code_editor.saveContents(); << not yet...
709 this.win.rooview.el.show();
710 this.win.leftpane.el.show();
711 this.win.codeeditview.el.set_scale(0.0f,0.0f);
715 while (Gtk.events_pending()) {
716 Gtk.main_iteration();
719 // hides it completely...
724 case State.FILES: // goes to preview or codeonly...
729 if (new_state == State.CODEONLY) {
730 this.win.rooview.el.hide();
732 this.win.rooview.el.show();
735 this.win.rooview.el.set_easing_duration(1000);
736 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
737 this.win.rooview.el.set_scale(1.0f,1.0f);
738 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
739 this.win.rooview.el.set_opacity(0xff);
741 this.clutterfiles.el.set_easing_duration(1000);
742 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
743 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
744 this.clutterfiles.el.set_opacity(0);
747 //this.clutterfiles.el.hide();
755 var oldstate =this.state;
756 this.state = new_state;
760 this.buttonsShowHide();
763 switch (this.state) {
765 case State.PREVIEW: // this is the default state when working...
766 this.win.editpane.el.show(); // holder for tree and properties..
769 // this.left_projects.el.hide();
770 // if (oldstate != State.FILES) {
771 // it's handled above..
772 // print ("changing state to preview from NOT files..");
775 this.win.rooview.el.set_scale(1.0f,1.0f);
782 // going to codeonly..
783 this.win.codeeditview.el.show();
785 //while (Gtk.events_pending()) {
786 // Gtk.main_iteration();
789 this.win.leftpane.el.hide();
790 this.win.codeeditview.el.show();
791 //while (Gtk.events_pending()) {
792 // Gtk.main_iteration();
796 this.code_editor_tab.el.show_all();
798 this.win.codeeditview.el.set_scale(1.0f,1.0f);
799 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
803 case State.FILES: // can only get here from PREVIEW (or code-only) state.. in theory..
806 this.win.editpane.el.hide(); // holder for tree and properties..
808 this.left_projects.el.show();
810 // rotate the preview to hidden...
811 this.win.rooview.el.set_easing_duration(1000);
812 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
813 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
814 this.win.rooview.el.set_opacity(0);
819 if (this.win.project != null) {
820 this.left_projects.selectProject(this.win.project);
824 this.clutterfiles.el.show();
826 this.clutterfiles.el.set_easing_duration(1000);
827 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
828 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
829 this.clutterfiles.el.set_opacity(0xff);
837 this.resizeCanvasElements();
838 this.easingRestoreAll();
840 // run the animation.. - then load files...
841 GLib.Timeout.add(500, () =>{
842 this.resizeCanvasElements();
848 public int redraw_count = 0;
849 public void resizeCanvas() // called by window resize .. delays redraw
851 var rc = this.redraw_count;
852 this.redraw_count = 2;
854 GLib.Timeout.add(100, () =>{
855 return this.resizeCanvasQueue();
859 public bool resizeCanvasQueue()
861 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
863 if (this.redraw_count < 1) {
864 return false; // should not really happen...
870 if (this.redraw_count > 0) {
871 return true; // do it again in 1 second...
873 // got down to 0 or -1....
874 this.redraw_count = 0;
875 this.resizeCanvasElements();
879 public void resizeCanvasElements()
881 Gtk.Allocation alloc;
882 this.win.clutterembed.el.get_allocation(out alloc);
884 // print("WindowState.resizeCanvasElements\n");
885 if (!this.children_loaded || this.win.clutterembed == null) {
886 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
890 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
891 var palsize = avail < 300.0f ? avail : 300.0f;
894 // -------- code edit min 600
896 var codesize = avail < 800.0f ? avail : 800.0f;
899 //print("set code size %f\n", codesize);
903 switch ( this.state) {
906 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
910 //this.clutterfiles.set_size(alloc.width-50, alloc.height);
916 this.win.codeeditview.el.set_size(codesize, alloc.height);
917 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
918 //this.win.rooview.el.save_easing_state();
919 this.win.rooview.el.hide();
920 this.win.rooview.el.set_scale(scale,scale);
921 // this.win.rooview.el.restore_easing_state();
927 // -- buttons show hide.....
929 public void buttonsShowHide()
931 // basically hide everything, then show the relivant..
934 //this.win.openbtn.el.hide();
935 //this.win.openbackbtn.el.hide();
937 //this.win.backbutton.el.hide();
942 this.win.objectshowbutton.el.hide(); // add objects
943 this.win.addpropbutton.el.hide();
944 this.win.addlistenerbutton.el.hide();
948 this.win.search_entry.el.hide();
949 this.win.search_results.el.hide();
950 switch (this.state) {
952 case State.PREVIEW: // this is the default state when working...
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();
962 // this.win.openbtn.el.show();
967 // this.win.openbtn.el.show();
968 this.win.search_entry.el.show();
974 if (this.left_projects.getSelectedProject() != null ) {
975 if (this.left_tree.getActiveFile() != null) {
977 this.win.openbackbtn.el.show();
979 this.win.addfilebutton.el.show();
980 this.win.search_entry.el.show();
981 this.win.projecteditbutton.el.show();
985 this.win.addprojectbutton.el.show();
986 this.win.delprojectbutton.el.show();
1000 public void showCompileResult(Json.Object obj)
1002 // vala has finished compiling...
1003 print("vala compiled");
1004 // stop the spinner...
1007 var generator = new Json.Generator ();
1008 var n = new Json.Node(Json.NodeType.OBJECT);
1010 generator.set_root (n);
1011 print("result :%s", generator.to_data (null));
1014 var buf = this.code_editor_tab.buffer;
1015 buf.check_running = false;
1016 var has_errors = false;
1018 if (obj.has_member("ERR-TOTAL")) {
1019 if (obj.get_int_member("ERR-TOTAL")> 0) {
1022 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
1024 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1027 if (obj.has_member("WARN-TOTAL")) {
1029 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1031 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1034 if (obj.has_member("DEPR-TOTAL")) {
1036 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
1039 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1041 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
1042 if ( this.state == State.CODEONLY) {
1043 buf.highlightErrorsJson("ERR", obj);
1044 buf.highlightErrorsJson("WARN", obj);
1045 buf.highlightErrorsJson("DEPR", obj);
1048 this.win.statusbar_compilestatus_label.el.hide();
1049 this.win.statusbar_run.el.hide();
1051 this.win.statusbar_compilestatus_label.el.show();
1052 this.win.statusbar_run.el.show();
1054 if (this.file.xtype == "Gtk") {
1055 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
1056 var gbuf = this.window_gladeview.sourceview;
1057 gbuf.highlightErrorsJson("ERR", obj);
1058 gbuf.highlightErrorsJson("WARN", obj);
1059 gbuf.highlightErrorsJson("DEPR", obj);
1062 this.win.statusbar_run.el.show();
1067 if (this.file.xtype == "Roo") {
1068 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
1069 var gbuf = this.window_rooview.sourceview;
1070 gbuf.highlightErrorsJson("ERR", obj);
1071 gbuf.highlightErrorsJson("WARN", obj);
1072 gbuf.highlightErrorsJson("DEPR", obj);
1076 this.last_compile_result = obj;