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;
20 PROJECT // project settings..
23 public State state = State.NONE;
25 public bool children_loaded = false;
28 public Xcls_WindowLeftTree left_tree;
29 public Xcls_WindowAddProp add_props;
30 public Xcls_LeftProps left_props;
31 public Xcls_ProjectSettings projectsettings;
32 public ValaProjectSettings vala_projectsettings;
33 public Xcls_RightPalete rightpalete;
34 public Editor code_editor;
35 public Xcls_WindowRooView window_rooview;
36 public Xcls_GtkView window_gladeview;
38 public Xcls_ClutterFiles clutterfiles;
40 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
42 public DialogTemplateSelect template_select;
44 public Xcls_PopoverFileDetails file_details;
48 public Xcls_DialogPluginWebkit webkit_plugin;
51 public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
52 public Json.Object last_compile_result;
55 public WindowState(Xcls_MainWindow win)
64 // on clutter space...
65 this.projectEditInit();
67 this.projectListInit();
77 this.webkitViewInit();
81 this.fileDetailsInit();
83 this.webkit_plugin = new Xcls_DialogPluginWebkit();
84 this.template_select = new DialogTemplateSelect();
85 this.children_loaded = true;
87 this.left_tree.node_selected.connect((sel) => {
88 this.window_gladeview.sourceview.nodeSelected(sel);
90 this.valasource = new Palete.ValaSource();
91 this.valasource.compiled.connect(this.valaCompiled);
99 public void leftTreeInit()
102 this.left_tree = new Xcls_WindowLeftTree();
103 this.left_tree.ref();
104 this.left_tree.main_window = this.win;
106 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
107 this.left_tree.el.show_all();
109 this.left_tree.before_node_change.connect(() => {
110 return this.leftTreeBeforeChange();
114 this.left_tree.node_selected.connect((sel) => {
115 this.leftTreeNodeSelected(sel);
118 this.left_tree.changed.connect(() => {
119 this.window_rooview.requestRedraw();
120 this.left_tree.model.file.save();
125 public bool leftTreeBeforeChange()
127 if (this.state != State.CODE) {
128 this.left_props.finish_editing();
131 if (!this.code_editor.saveContents()) {
137 public void leftTreeNodeSelected(JsRender.Node? sel)
140 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
143 this.left_props.el.hide();
145 this.left_props.el.show();
146 this.left_props.load(this.left_tree.getActiveFile(), sel);
147 switch (this.state) {
152 this.rightpalete.clear();
155 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
161 this.add_props.clear();
164 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
170 this.add_props.clear();
173 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
177 this.switchState(State.PREVIEW);
190 public void propsListInit()
193 this.left_props =new Xcls_LeftProps();
194 this.left_props.ref();
195 this.left_props.main_window = this.win;
196 this.win.props.el.pack_start(this.left_props.el,true, true,0);
197 this.left_props.el.show_all();
199 this.left_props.show_editor.connect( (file, node, type, key) => {
200 this.switchState(State.CODE);
201 this.code_editor.show(
212 this.left_props.stop_editor.connect( () => {
213 if (this.state != State.CODE) {
217 var ret = this.code_editor.saveContents();
221 this.switchState(State.PREVIEW);
225 this.left_props.changed.connect(() => {
226 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
227 this.window_rooview.requestRedraw();
230 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
232 this.left_tree.model.updateSelected();
233 this.left_tree.model.file.save();
234 this.valasource.spawnFile(this.left_tree.model.file);
241 //------------- projects edit
243 public void projectEditInit()
245 this.projectsettings =new Xcls_ProjectSettings();
246 this.projectsettings.ref(); /// really?
248 this.vala_projectsettings =new ValaProjectSettings();
249 this.vala_projectsettings.ref();
250 this.vala_projectsettings.window = this.win;
252 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
253 //this.projectsettings.el.show_all();
255 var stage = this.win.projecteditview.el.get_stage();
256 stage.set_background_color( Clutter.Color.from_string("#000"));
258 this.projectsettings.buttonPressed.connect((btn) => {
259 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
261 this.window_rooview.view.renderJS(true);
263 if (btn == "apply") {
264 this.window_rooview.view.renderJS(true);
268 // do nothing for gtk..
270 if (btn == "save" || btn == "apply") {
271 this.win.project.save();
274 this.switchState (State.PREVIEW);
279 // ----------- object adding
280 public void objectAddInit()
283 this.rightpalete = new Xcls_RightPalete();
284 this.rightpalete.ref(); /// really?
285 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
286 //this.projectsettings.el.show_all();
288 var stage = this.win.objectview.el.get_stage();
289 stage.set_background_color( Clutter.Color.from_string("#000"));
293 // ----------- properties adding list...
294 // listener uses the properties
295 public void propsAddInit()
298 this.add_props = new Xcls_WindowAddProp();
299 this.add_props.ref(); /// really?
300 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
301 //this.projectsettings.el.show_all();
303 var stage = this.win.addpropsview.el.get_stage();
304 stage.set_background_color( Clutter.Color.from_string("#000"));
307 this.add_props.select.connect( (key,type,skel, etype) => {
308 this.left_props.addProp(etype, key, skel, type);
312 public void propsAddShow()
316 public void propsAddHide()
324 // ----------- Add / Edit listener
325 // listener uses the properties
326 //public void listenerInit() { }
327 public void listenerShow()
331 public void listenerHide()
336 // -------------- codeEditor
338 public void codeEditInit()
340 this.code_editor = new Editor();
341 //this.code_editor.ref(); /// really?
342 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
344 this.code_editor.window = this.win;
345 //this.projectsettings.el.show_all();
347 var stage = this.win.codeeditview.el.get_stage();
348 stage.set_background_color( Clutter.Color.from_string("#000"));
351 this.code_editor.save.connect( () => {
352 this.left_tree.model.file.save();
353 this.left_tree.model.updateSelected();
354 // we do not need to call spawn... - as it's already called by the editor?
360 // ----------- list of projects on left
361 public void projectListInit()
364 this.left_projects = new Xcls_WindowLeftProjects();
365 this.left_projects.ref();
366 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
367 this.left_projects.el.show_all();
368 this.left_projects.project_selected.connect((proj) => {
369 this.buttonsShowHide();
371 this.clutterfiles.loadProject(proj);
376 // ----------- file view
378 public void fileViewInit()
380 var stage = this.win.rooview.el.get_stage(); // seems odd...
381 this.clutterfiles = new Xcls_ClutterFiles();
382 this.clutterfiles.ref();
383 stage.add_child(this.clutterfiles.el);
384 this.clutterfiles.el.show_all();
387 this.clutterfiles.open.connect((file) => {
388 this.fileViewOpen(file);
390 this.clutterfiles.el.transitions_completed.connect(() => {
391 if (this.state == State.FILES) {
392 this.win.rooview.el.hide();
394 this.clutterfiles.el.hide();
402 public void fileDetailsInit()
404 this.file_details = new Xcls_PopoverFileDetails();
405 this.file_details.mainwindow = this.win;
406 // force it modal to the main window..
408 this.file_details.success.connect((project,file) =>
410 this.fileViewOpen(file);
415 public void fileViewOpen(JsRender.JsRender file)
417 this.win.project = file.project;
418 this.switchState (State.PREVIEW);
420 this.left_tree.model.loadFile(file);
422 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
423 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
425 if (file.xtype == "Roo" ) {
426 ctr.foreach( (w) => { ctr.remove(w); });
427 ctr_p.foreach( (w) => { ctr_p.remove(w); });
428 ctr.add(this.window_rooview.el);
429 ctr_p.add(this.projectsettings.el);
430 this.window_rooview.loadFile(file);
431 this.window_rooview.el.show_all();
432 this.projectsettings.el.show_all();
435 ctr.foreach( (w) => { ctr.remove(w); });
436 ctr_p.foreach( (w) => { ctr_p.remove(w); });
437 ctr.add(this.window_gladeview.el);
438 ctr_p.add(this.vala_projectsettings.el);
439 this.window_gladeview.loadFile(file);
440 this.window_gladeview.el.show_all();
441 this.vala_projectsettings.el.show_all();
443 print("OPEN : " + file.name);
444 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
445 this.win.setTitle(file.project.name + " : " +file.name);
451 // --------- webkit view
452 public void webkitViewInit()
454 this.window_rooview =new Xcls_WindowRooView();
455 this.window_rooview.ref();
456 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
457 this.window_rooview.el.show_all();
459 var stage = this.win.rooview.el.get_stage();
460 stage.set_background_color( Clutter.Color.from_string("#000"));
465 public void gtkViewInit()
467 this.window_gladeview =new Xcls_GtkView();
468 this.window_gladeview.ref();
469 this.window_gladeview.main_window = this.win;
472 public void easingSaveAll()
474 this.win.addpropsview.el.save_easing_state();
475 this.win.codeeditview.el.save_easing_state();
476 this.win.objectview.el.save_easing_state();
477 this.win.projecteditview.el.save_easing_state();
478 this.win.rooview.el.save_easing_state();
479 this.clutterfiles.el.save_easing_state();
482 public void easingRestoreAll()
484 this.win.addpropsview.el.restore_easing_state();
485 this.win.codeeditview.el.restore_easing_state();
486 this.win.objectview.el.restore_easing_state();
487 this.win.projecteditview.el.restore_easing_state();
488 this.win.rooview.el.restore_easing_state();
489 this.clutterfiles.el.restore_easing_state();
492 public void switchState(State new_state)
495 // save the easing state of everything..
496 this.easingSaveAll();
498 switch (this.state) {
501 if (this.left_tree.getActiveFile() != null) {
502 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
503 this.window_rooview.createThumb();
505 this.window_gladeview.createThumb();
508 // normally we are going from preview to another state.
509 // and different windows hide the preview in differnt ways..
516 this.win.addpropsview.el.set_scale(0.0f,0.0f);
522 this.code_editor.saveContents();
524 this.win.codeeditview.el.set_scale(0.0f,0.0f);
530 this.win.objectview.el.set_scale(0.0f,0.0f);
534 if (this.win.project.xtype == "Gtk") {
535 this.vala_projectsettings.save();
538 this.win.projecteditview.el.set_scale(0.0f,0.0f);
544 this.win.rooview.el.show_all();
545 this.win.rooview.el.set_easing_duration(1000);
546 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
547 this.win.rooview.el.set_scale(1.0f,1.0f);
548 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
549 this.win.rooview.el.set_opacity(0xff);
553 this.clutterfiles.el.set_easing_duration(1000);
554 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
555 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
556 this.clutterfiles.el.set_opacity(0);
558 //this.clutterfiles.el.hide();
566 var oldstate =this.state;
567 this.state = new_state;
571 this.buttonsShowHide();
574 switch (this.state) {
576 case State.PREVIEW: // this is the default state when working...
577 this.win.editpane.el.show(); // holder for tree and properties..
580 this.left_projects.el.hide();
581 if (oldstate != State.FILES) {
582 // it's handled above..
583 print ("changing state to preview from NOT files..");
586 this.win.rooview.el.set_scale(1.0f,1.0f);
595 var ae = this.left_tree.getActiveElement();
597 this.state = oldstate;
598 this.buttonsShowHide();
599 this.resizeCanvasElements();
600 this.easingRestoreAll();
603 this.add_props.el.show_all();
605 Palete.factory(this.win.project.xtype),
606 this.state == State.LISTENER ? "signals" : "props",
613 // -- FIXME? this needs to be State aware?
615 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
617 this.win.addpropsview.el.set_scale(1.0f,1.0f);
621 var n = this.left_tree.getActiveElement();
623 if (this.left_tree.model.file == null) {
624 this.state =oldstate;
625 this.buttonsShowHide();
626 this.resizeCanvasElements();
627 this.easingRestoreAll();
631 if (n == null && this.left_tree.model.file.tree != null) {
632 this.state = oldstate;
633 this.buttonsShowHide();
634 this.resizeCanvasElements();
635 this.easingRestoreAll();
639 this.rightpalete.el.show_all();
640 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
645 this.win.objectview.el.set_scale(1.0f,1.0f);
652 this.code_editor.el.show_all();
654 // caller needs to call editor - show....
657 this.win.codeeditview.el.set_scale(1.0f,1.0f);
664 if (this.win.project.xtype == "Roo") {
665 this.projectsettings.el.show_all();
666 this.projectsettings.show(this.win.project);
668 this.vala_projectsettings.el.show_all();
669 this.vala_projectsettings.show((Project.Gtk)this.win.project);
672 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
674 this.win.projecteditview.el.set_scale(1.0f,1.0f);
679 case State.FILES: // can only get here from PREVIEW state.. in theory..
682 this.win.editpane.el.hide(); // holder for tree and properties..
684 this.left_projects.el.show();
686 this.win.rooview.el.set_easing_duration(1000);
687 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
688 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
689 this.win.rooview.el.set_opacity(0);
690 //el.set_scale(0.0f,0.0f);
693 if (this.win.project != null) {
694 this.left_projects.selectProject(this.win.project);
698 this.clutterfiles.el.show_all();
700 this.clutterfiles.el.set_easing_duration(1000);
701 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
702 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
703 this.clutterfiles.el.set_opacity(0xff);
711 this.resizeCanvasElements();
712 this.easingRestoreAll();
717 public int redraw_count = 0;
718 public void resizeCanvas() // called by window resize .. delays redraw
720 var rc = this.redraw_count;
721 this.redraw_count = 2;
723 GLib.Timeout.add(100, () =>{
724 return this.resizeCanvasQueue();
728 public bool resizeCanvasQueue()
730 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
732 if (this.redraw_count < 1) {
733 return false; // should not really happen...
739 if (this.redraw_count > 0) {
740 return true; // do it again in 1 second...
742 // got down to 0 or -1....
743 this.redraw_count = 0;
744 this.resizeCanvasElements();
748 public void resizeCanvasElements()
750 Gtk.Allocation alloc;
751 this.win.clutterembed.el.get_allocation(out alloc);
753 // print("WindowState.resizeCanvasElements\n");
754 if (!this.children_loaded || this.win.clutterembed == null) {
755 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
759 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
760 var palsize = avail < 300.0f ? avail : 300.0f;
763 // -------- code edit min 600
765 var codesize = avail < 800.0f ? avail : 800.0f;
768 //print("set code size %f\n", codesize);
772 switch ( this.state) {
774 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
778 this.clutterfiles.set_size(alloc.width-50, alloc.height);
783 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
785 // this.win.rooview.el.save_easing_state();
786 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
787 this.win.rooview.el.set_scale(0.5f, 0.5f);
788 //this.win.rooview.el.restore_easing_state();
792 this.win.codeeditview.el.set_size(codesize, alloc.height);
793 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
794 //this.win.rooview.el.save_easing_state();
796 this.win.rooview.el.set_scale(scale,scale);
797 // this.win.rooview.el.restore_easing_state();
802 this.win.addpropsview.el.set_size(palsize, alloc.height);
803 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
804 this.win.rooview.el.set_scale(scale,scale);
808 this.win.objectview.el.set_size(palsize, alloc.height);
809 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
810 //this.win.rooview.el.save_easing_state();
811 this.win.rooview.el.set_scale(scale,scale);
812 // this.win.rooview.el.restore_easing_state();
817 // -- buttons show hide.....
819 public void buttonsShowHide()
821 // basically hide everything, then show the relivant..
823 this.win.backbutton.el.hide();
825 this.win.projectbutton.el.hide(); // show file nav...
826 this.win.editfilebutton.el.hide();
827 this.win.projecteditbutton.el.hide();
830 this.win.objectshowbutton.el.hide(); // add objects
831 this.win.addpropbutton.el.hide();
832 this.win.addlistenerbutton.el.hide();
836 this.win.addprojectbutton.el.hide();
837 this.win.addfilebutton.el.hide();
838 this.win.delprojectbutton.el.hide();
841 switch (this.state) {
843 case State.PREVIEW: // this is the default state when working...
845 this.win.projectbutton.el.show(); // show file nav...
846 this.win.editfilebutton.el.show();
847 this.win.projecteditbutton.el.show();
850 this.win.objectshowbutton.el.show(); // add objects
851 this.win.addpropbutton.el.show();
852 this.win.addlistenerbutton.el.show();
861 this.win.backbutton.el.show();
862 this.win.objectshowbutton.el.show(); // add objects
863 this.win.addpropbutton.el.show();
864 this.win.addlistenerbutton.el.show();
869 this.win.backbutton.el.show();
874 if (this.left_projects.getSelectedProject() != null ) {
875 if (this.left_tree.getActiveFile() != null) {
876 this.win.backbutton.el.show();
878 this.win.addfilebutton.el.show();
881 this.win.addprojectbutton.el.show();
882 this.win.delprojectbutton.el.show();
892 public void valaCompiled(Json.Object obj)
894 // vala has finished compiling...
895 print("vala compiled");
897 var buf = this.code_editor.buffer;
898 buf.check_running = false;
900 if (obj.has_member("ERR-TOTAL")) {
901 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
903 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
906 if (obj.has_member("WARN-TOTAL")) {
908 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
910 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
913 if (obj.has_member("DEPR-TOTAL")) {
915 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
918 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
921 buf.highlightErrorsJson("ERR", obj);
922 buf.highlightErrorsJson("WARN", obj);
923 buf.highlightErrorsJson("DEPR", obj);
925 var gbuf = this.window_gladeview.sourceview;
926 gbuf.highlightErrorsJson("ERR", obj);
927 gbuf.highlightErrorsJson("WARN", obj);
928 gbuf.highlightErrorsJson("DEPR", obj);
930 this.last_compile_result = obj;