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();
240 //------------- projects edit
242 public void projectEditInit()
244 this.projectsettings =new Xcls_ProjectSettings();
245 this.projectsettings.ref(); /// really?
247 this.vala_projectsettings =new ValaProjectSettings();
248 this.vala_projectsettings.ref();
249 this.vala_projectsettings.window = this.win;
251 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
252 //this.projectsettings.el.show_all();
254 var stage = this.win.projecteditview.el.get_stage();
255 stage.set_background_color( Clutter.Color.from_string("#000"));
257 this.projectsettings.buttonPressed.connect((btn) => {
258 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
260 this.window_rooview.view.renderJS(true);
262 if (btn == "apply") {
263 this.window_rooview.view.renderJS(true);
267 // do nothing for gtk..
269 if (btn == "save" || btn == "apply") {
270 this.win.project.save();
273 this.switchState (State.PREVIEW);
278 // ----------- object adding
279 public void objectAddInit()
282 this.rightpalete = new Xcls_RightPalete();
283 this.rightpalete.ref(); /// really?
284 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
285 //this.projectsettings.el.show_all();
287 var stage = this.win.objectview.el.get_stage();
288 stage.set_background_color( Clutter.Color.from_string("#000"));
292 // ----------- properties adding list...
293 // listener uses the properties
294 public void propsAddInit()
297 this.add_props = new Xcls_WindowAddProp();
298 this.add_props.ref(); /// really?
299 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
300 //this.projectsettings.el.show_all();
302 var stage = this.win.addpropsview.el.get_stage();
303 stage.set_background_color( Clutter.Color.from_string("#000"));
306 this.add_props.select.connect( (key,type,skel, etype) => {
307 this.left_props.addProp(etype, key, skel, type);
311 public void propsAddShow()
315 public void propsAddHide()
323 // ----------- Add / Edit listener
324 // listener uses the properties
325 //public void listenerInit() { }
326 public void listenerShow()
330 public void listenerHide()
335 // -------------- codeEditor
337 public void codeEditInit()
339 this.code_editor = new Editor();
340 //this.code_editor.ref(); /// really?
341 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
343 this.code_editor.window = this.win;
344 //this.projectsettings.el.show_all();
346 var stage = this.win.codeeditview.el.get_stage();
347 stage.set_background_color( Clutter.Color.from_string("#000"));
350 this.code_editor.save.connect( () => {
351 this.left_tree.model.file.save();
352 this.left_tree.model.updateSelected();
357 // ----------- list of projects on left
358 public void projectListInit()
361 this.left_projects = new Xcls_WindowLeftProjects();
362 this.left_projects.ref();
363 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
364 this.left_projects.el.show_all();
365 this.left_projects.project_selected.connect((proj) => {
366 this.buttonsShowHide();
368 this.clutterfiles.loadProject(proj);
373 // ----------- file view
375 public void fileViewInit()
377 var stage = this.win.rooview.el.get_stage(); // seems odd...
378 this.clutterfiles = new Xcls_ClutterFiles();
379 this.clutterfiles.ref();
380 stage.add_child(this.clutterfiles.el);
381 this.clutterfiles.el.show_all();
384 this.clutterfiles.open.connect((file) => {
385 this.fileViewOpen(file);
387 this.clutterfiles.el.transitions_completed.connect(() => {
388 if (this.state == State.FILES) {
389 this.win.rooview.el.hide();
391 this.clutterfiles.el.hide();
399 public void fileDetailsInit()
401 this.file_details = new Xcls_PopoverFileDetails();
402 this.file_details.mainwindow = this.win;
403 // force it modal to the main window..
405 this.file_details.success.connect((project,file) =>
407 this.fileViewOpen(file);
412 public void fileViewOpen(JsRender.JsRender file)
414 this.win.project = file.project;
415 this.switchState (State.PREVIEW);
417 this.left_tree.model.loadFile(file);
419 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
420 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
422 if (file.xtype == "Roo" ) {
423 ctr.foreach( (w) => { ctr.remove(w); });
424 ctr_p.foreach( (w) => { ctr_p.remove(w); });
425 ctr.add(this.window_rooview.el);
426 ctr_p.add(this.projectsettings.el);
427 this.window_rooview.loadFile(file);
428 this.window_rooview.el.show_all();
429 this.projectsettings.el.show_all();
432 ctr.foreach( (w) => { ctr.remove(w); });
433 ctr_p.foreach( (w) => { ctr_p.remove(w); });
434 ctr.add(this.window_gladeview.el);
435 ctr_p.add(this.vala_projectsettings.el);
436 this.window_gladeview.loadFile(file);
437 this.window_gladeview.el.show_all();
438 this.vala_projectsettings.el.show_all();
440 print("OPEN : " + file.name);
441 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
442 this.win.setTitle(file.project.name + " : " +file.name);
448 // --------- webkit view
449 public void webkitViewInit()
451 this.window_rooview =new Xcls_WindowRooView();
452 this.window_rooview.ref();
453 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
454 this.window_rooview.el.show_all();
456 var stage = this.win.rooview.el.get_stage();
457 stage.set_background_color( Clutter.Color.from_string("#000"));
462 public void gtkViewInit()
464 this.window_gladeview =new Xcls_GtkView();
465 this.window_gladeview.ref();
466 this.window_gladeview.main_window = this.win;
469 public void easingSaveAll()
471 this.win.addpropsview.el.save_easing_state();
472 this.win.codeeditview.el.save_easing_state();
473 this.win.objectview.el.save_easing_state();
474 this.win.projecteditview.el.save_easing_state();
475 this.win.rooview.el.save_easing_state();
476 this.clutterfiles.el.save_easing_state();
479 public void easingRestoreAll()
481 this.win.addpropsview.el.restore_easing_state();
482 this.win.codeeditview.el.restore_easing_state();
483 this.win.objectview.el.restore_easing_state();
484 this.win.projecteditview.el.restore_easing_state();
485 this.win.rooview.el.restore_easing_state();
486 this.clutterfiles.el.restore_easing_state();
489 public void switchState(State new_state)
492 // save the easing state of everything..
493 this.easingSaveAll();
495 switch (this.state) {
498 if (this.left_tree.getActiveFile() != null) {
499 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
500 this.window_rooview.createThumb();
502 this.window_gladeview.createThumb();
505 // normally we are going from preview to another state.
506 // and different windows hide the preview in differnt ways..
513 this.win.addpropsview.el.set_scale(0.0f,0.0f);
519 this.code_editor.saveContents();
521 this.win.codeeditview.el.set_scale(0.0f,0.0f);
527 this.win.objectview.el.set_scale(0.0f,0.0f);
531 if (this.win.project.xtype == "Gtk") {
532 this.vala_projectsettings.save();
535 this.win.projecteditview.el.set_scale(0.0f,0.0f);
541 this.win.rooview.el.show_all();
542 this.win.rooview.el.set_easing_duration(1000);
543 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
544 this.win.rooview.el.set_scale(1.0f,1.0f);
545 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
546 this.win.rooview.el.set_opacity(0xff);
550 this.clutterfiles.el.set_easing_duration(1000);
551 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
552 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
553 this.clutterfiles.el.set_opacity(0);
555 //this.clutterfiles.el.hide();
563 var oldstate =this.state;
564 this.state = new_state;
568 this.buttonsShowHide();
571 switch (this.state) {
573 case State.PREVIEW: // this is the default state when working...
574 this.win.editpane.el.show(); // holder for tree and properties..
577 this.left_projects.el.hide();
578 if (oldstate != State.FILES) {
579 // it's handled above..
580 print ("changing state to preview from NOT files..");
583 this.win.rooview.el.set_scale(1.0f,1.0f);
592 var ae = this.left_tree.getActiveElement();
594 this.state = oldstate;
595 this.buttonsShowHide();
596 this.resizeCanvasElements();
597 this.easingRestoreAll();
600 this.add_props.el.show_all();
602 Palete.factory(this.win.project.xtype),
603 this.state == State.LISTENER ? "signals" : "props",
610 // -- FIXME? this needs to be State aware?
612 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
614 this.win.addpropsview.el.set_scale(1.0f,1.0f);
618 var n = this.left_tree.getActiveElement();
620 if (this.left_tree.model.file == null) {
621 this.state =oldstate;
622 this.buttonsShowHide();
623 this.resizeCanvasElements();
624 this.easingRestoreAll();
628 if (n == null && this.left_tree.model.file.tree != null) {
629 this.state = oldstate;
630 this.buttonsShowHide();
631 this.resizeCanvasElements();
632 this.easingRestoreAll();
636 this.rightpalete.el.show_all();
637 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
642 this.win.objectview.el.set_scale(1.0f,1.0f);
649 this.code_editor.el.show_all();
651 // caller needs to call editor - show....
654 this.win.codeeditview.el.set_scale(1.0f,1.0f);
661 if (this.win.project.xtype == "Roo") {
662 this.projectsettings.el.show_all();
663 this.projectsettings.show(this.win.project);
665 this.vala_projectsettings.el.show_all();
666 this.vala_projectsettings.show((Project.Gtk)this.win.project);
669 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
671 this.win.projecteditview.el.set_scale(1.0f,1.0f);
676 case State.FILES: // can only get here from PREVIEW state.. in theory..
679 this.win.editpane.el.hide(); // holder for tree and properties..
681 this.left_projects.el.show();
683 this.win.rooview.el.set_easing_duration(1000);
684 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
685 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
686 this.win.rooview.el.set_opacity(0);
687 //el.set_scale(0.0f,0.0f);
690 if (this.win.project != null) {
691 this.left_projects.selectProject(this.win.project);
695 this.clutterfiles.el.show_all();
697 this.clutterfiles.el.set_easing_duration(1000);
698 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
699 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
700 this.clutterfiles.el.set_opacity(0xff);
708 this.resizeCanvasElements();
709 this.easingRestoreAll();
714 public int redraw_count = 0;
715 public void resizeCanvas() // called by window resize .. delays redraw
717 var rc = this.redraw_count;
718 this.redraw_count = 2;
720 GLib.Timeout.add(100, () =>{
721 return this.resizeCanvasQueue();
725 public bool resizeCanvasQueue()
727 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
729 if (this.redraw_count < 1) {
730 return false; // should not really happen...
736 if (this.redraw_count > 0) {
737 return true; // do it again in 1 second...
739 // got down to 0 or -1....
740 this.redraw_count = 0;
741 this.resizeCanvasElements();
745 public void resizeCanvasElements()
747 Gtk.Allocation alloc;
748 this.win.clutterembed.el.get_allocation(out alloc);
750 // print("WindowState.resizeCanvasElements\n");
751 if (!this.children_loaded || this.win.clutterembed == null) {
752 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
756 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
757 var palsize = avail < 300.0f ? avail : 300.0f;
760 // -------- code edit min 600
762 var codesize = avail < 800.0f ? avail : 800.0f;
765 //print("set code size %f\n", codesize);
769 switch ( this.state) {
771 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
775 this.clutterfiles.set_size(alloc.width-50, alloc.height);
780 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
782 // this.win.rooview.el.save_easing_state();
783 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
784 this.win.rooview.el.set_scale(0.5f, 0.5f);
785 //this.win.rooview.el.restore_easing_state();
789 this.win.codeeditview.el.set_size(codesize, alloc.height);
790 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
791 //this.win.rooview.el.save_easing_state();
793 this.win.rooview.el.set_scale(scale,scale);
794 // this.win.rooview.el.restore_easing_state();
799 this.win.addpropsview.el.set_size(palsize, alloc.height);
800 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
801 this.win.rooview.el.set_scale(scale,scale);
805 this.win.objectview.el.set_size(palsize, alloc.height);
806 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
807 //this.win.rooview.el.save_easing_state();
808 this.win.rooview.el.set_scale(scale,scale);
809 // this.win.rooview.el.restore_easing_state();
814 // -- buttons show hide.....
816 public void buttonsShowHide()
818 // basically hide everything, then show the relivant..
820 this.win.backbutton.el.hide();
822 this.win.projectbutton.el.hide(); // show file nav...
823 this.win.editfilebutton.el.hide();
824 this.win.projecteditbutton.el.hide();
827 this.win.objectshowbutton.el.hide(); // add objects
828 this.win.addpropbutton.el.hide();
829 this.win.addlistenerbutton.el.hide();
833 this.win.addprojectbutton.el.hide();
834 this.win.addfilebutton.el.hide();
835 this.win.delprojectbutton.el.hide();
838 switch (this.state) {
840 case State.PREVIEW: // this is the default state when working...
842 this.win.projectbutton.el.show(); // show file nav...
843 this.win.editfilebutton.el.show();
844 this.win.projecteditbutton.el.show();
847 this.win.objectshowbutton.el.show(); // add objects
848 this.win.addpropbutton.el.show();
849 this.win.addlistenerbutton.el.show();
858 this.win.backbutton.el.show();
859 this.win.objectshowbutton.el.show(); // add objects
860 this.win.addpropbutton.el.show();
861 this.win.addlistenerbutton.el.show();
866 this.win.backbutton.el.show();
871 if (this.left_projects.getSelectedProject() != null ) {
872 if (this.left_tree.getActiveFile() != null) {
873 this.win.backbutton.el.show();
875 this.win.addfilebutton.el.show();
878 this.win.addprojectbutton.el.show();
879 this.win.delprojectbutton.el.show();
889 public void valaCompiled(Json.Object obj)
891 // vala has finished compiling...
892 print("vala compiled");
894 var buf = this.code_editor.buffer;
895 buf.check_running = false;
897 if (obj.has_member("ERR-TOTAL")) {
898 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
900 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
903 if (obj.has_member("WARN-TOTAL")) {
905 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
907 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
910 if (obj.has_member("DEPR-TOTAL")) {
912 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
915 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
918 buf.highlightErrorsJson("ERR", obj);
919 buf.highlightErrorsJson("WARN", obj);
920 buf.highlightErrorsJson("DEPR", obj);