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(() => {
120 this.left_tree.model.file.save();
121 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
122 this.window_rooview.requestRedraw();
124 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
131 public bool leftTreeBeforeChange()
133 if (this.state != State.CODE) {
134 this.left_props.finish_editing();
137 if (!this.code_editor.saveContents()) {
143 public void leftTreeNodeSelected(JsRender.Node? sel)
146 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
149 this.left_props.el.hide();
151 this.left_props.el.show();
152 this.left_props.load(this.left_tree.getActiveFile(), sel);
153 switch (this.state) {
158 this.rightpalete.clear();
161 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
167 this.add_props.clear();
170 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
176 this.add_props.clear();
179 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
183 this.switchState(State.PREVIEW);
196 public void propsListInit()
199 this.left_props =new Xcls_LeftProps();
200 this.left_props.ref();
201 this.left_props.main_window = this.win;
202 this.win.props.el.pack_start(this.left_props.el,true, true,0);
203 this.left_props.el.show_all();
205 this.left_props.show_editor.connect( (file, node, type, key) => {
206 this.switchState(State.CODE);
207 this.code_editor.show(
218 this.left_props.stop_editor.connect( () => {
219 if (this.state != State.CODE) {
223 var ret = this.code_editor.saveContents();
227 this.switchState(State.PREVIEW);
231 this.left_props.changed.connect(() => {
232 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
233 this.window_rooview.requestRedraw();
235 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
237 this.left_tree.model.updateSelected();
238 this.left_tree.model.file.save();
239 if (this.left_tree.model.file.xtype=="Gtk") {
240 this.valasource.checkFileSpawn(this.left_tree.model.file);
248 //------------- projects edit
250 public void projectEditInit()
252 this.projectsettings =new Xcls_ProjectSettings();
253 this.projectsettings.ref(); /// really?
255 this.vala_projectsettings =new ValaProjectSettings();
256 this.vala_projectsettings.ref();
257 this.vala_projectsettings.window = this.win;
259 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
260 //this.projectsettings.el.show_all();
262 var stage = this.win.projecteditview.el.get_stage();
263 stage.set_background_color( Clutter.Color.from_string("#000"));
265 this.projectsettings.buttonPressed.connect((btn) => {
266 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
268 this.window_rooview.view.renderJS(true);
270 if (btn == "apply") {
271 this.window_rooview.view.renderJS(true);
275 // do nothing for gtk..
277 if (btn == "save" || btn == "apply") {
278 this.win.project.save();
281 this.switchState (State.PREVIEW);
286 // ----------- object adding
287 public void objectAddInit()
290 this.rightpalete = new Xcls_RightPalete();
291 this.rightpalete.ref(); /// really?
292 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
293 //this.projectsettings.el.show_all();
295 var stage = this.win.objectview.el.get_stage();
296 stage.set_background_color( Clutter.Color.from_string("#000"));
300 // ----------- properties adding list...
301 // listener uses the properties
302 public void propsAddInit()
305 this.add_props = new Xcls_WindowAddProp();
306 this.add_props.ref(); /// really?
307 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
308 //this.projectsettings.el.show_all();
310 var stage = this.win.addpropsview.el.get_stage();
311 stage.set_background_color( Clutter.Color.from_string("#000"));
314 this.add_props.select.connect( (key,type,skel, etype) => {
315 this.left_props.addProp(etype, key, skel, type);
319 public void propsAddShow()
323 public void propsAddHide()
331 // ----------- Add / Edit listener
332 // listener uses the properties
333 //public void listenerInit() { }
334 public void listenerShow()
338 public void listenerHide()
343 // -------------- codeEditor
345 public void codeEditInit()
347 this.code_editor = new Editor();
348 //this.code_editor.ref(); /// really?
349 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
351 this.code_editor.window = this.win;
352 //this.projectsettings.el.show_all();
354 var stage = this.win.codeeditview.el.get_stage();
355 stage.set_background_color( Clutter.Color.from_string("#000"));
358 this.code_editor.save.connect( () => {
359 this.left_tree.model.file.save();
360 this.left_tree.model.updateSelected();
361 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
362 this.window_rooview.requestRedraw();
364 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
366 // we do not need to call spawn... - as it's already called by the editor?
372 // ----------- list of projects on left
373 public void projectListInit()
376 this.left_projects = new Xcls_WindowLeftProjects();
377 this.left_projects.ref();
378 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
379 this.left_projects.el.show_all();
380 this.left_projects.project_selected.connect((proj) => {
381 this.buttonsShowHide();
383 this.clutterfiles.loadProject(proj);
388 // ----------- file view
390 public void fileViewInit()
392 var stage = this.win.rooview.el.get_stage(); // seems odd...
393 this.clutterfiles = new Xcls_ClutterFiles();
394 this.clutterfiles.ref();
395 stage.add_child(this.clutterfiles.el);
396 this.clutterfiles.el.show();
399 this.clutterfiles.open.connect((file) => {
400 this.fileViewOpen(file);
402 this.clutterfiles.el.transitions_completed.connect(() => {
403 if (this.state == State.FILES) {
404 this.win.rooview.el.hide();
406 this.clutterfiles.el.hide();
414 public void fileDetailsInit()
416 this.file_details = new Xcls_PopoverFileDetails();
417 this.file_details.mainwindow = this.win;
418 // force it modal to the main window..
420 this.file_details.success.connect((project,file) =>
422 this.fileViewOpen(file);
427 public void fileViewOpen(JsRender.JsRender file)
429 this.win.project = file.project;
430 this.switchState (State.PREVIEW);
432 this.left_tree.model.loadFile(file);
434 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
435 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
437 if (file.xtype == "Roo" ) {
438 ctr.foreach( (w) => { ctr.remove(w); });
439 ctr_p.foreach( (w) => { ctr_p.remove(w); });
440 ctr.add(this.window_rooview.el);
441 ctr_p.add(this.projectsettings.el);
442 this.window_rooview.loadFile(file);
443 this.window_rooview.el.show_all();
444 this.projectsettings.el.show_all();
447 ctr.foreach( (w) => { ctr.remove(w); });
448 ctr_p.foreach( (w) => { ctr_p.remove(w); });
449 ctr.add(this.window_gladeview.el);
450 ctr_p.add(this.vala_projectsettings.el);
451 this.window_gladeview.loadFile(file);
452 this.window_gladeview.el.show_all();
453 this.vala_projectsettings.el.show_all();
455 print("OPEN : " + file.name);
456 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
457 this.win.setTitle(file.project.name + " : " +file.name);
461 public void fileViewOpenPlain(string file)
463 this.win.leftpane.hide();
468 // --------- webkit view
469 public void webkitViewInit()
471 this.window_rooview =new Xcls_WindowRooView();
472 this.window_rooview.ref();
473 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
474 this.window_rooview.el.show_all();
476 var stage = this.win.rooview.el.get_stage();
477 stage.set_background_color( Clutter.Color.from_string("#000"));
482 public void gtkViewInit()
484 this.window_gladeview =new Xcls_GtkView();
485 this.window_gladeview.ref();
486 this.window_gladeview.main_window = this.win;
489 public void easingSaveAll()
491 this.win.addpropsview.el.save_easing_state();
492 this.win.codeeditview.el.save_easing_state();
493 this.win.objectview.el.save_easing_state();
494 this.win.projecteditview.el.save_easing_state();
495 this.win.rooview.el.save_easing_state();
496 this.clutterfiles.el.save_easing_state();
499 public void easingRestoreAll()
501 this.win.addpropsview.el.restore_easing_state();
502 this.win.codeeditview.el.restore_easing_state();
503 this.win.objectview.el.restore_easing_state();
504 this.win.projecteditview.el.restore_easing_state();
505 this.win.rooview.el.restore_easing_state();
506 this.clutterfiles.el.restore_easing_state();
509 public void switchState(State new_state)
512 // save the easing state of everything..
513 this.easingSaveAll();
515 switch (this.state) {
518 if (this.left_tree.getActiveFile() != null) {
519 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
520 this.window_rooview.createThumb();
522 this.window_gladeview.createThumb();
525 // normally we are going from preview to another state.
526 // and different windows hide the preview in differnt ways..
533 this.win.addpropsview.el.set_scale(0.0f,0.0f);
539 this.code_editor.saveContents();
541 this.win.codeeditview.el.set_scale(0.0f,0.0f);
547 this.win.objectview.el.set_scale(0.0f,0.0f);
551 if (this.win.project.xtype == "Gtk") {
552 this.vala_projectsettings.save();
555 this.win.projecteditview.el.set_scale(0.0f,0.0f);
561 this.win.rooview.el.show();
562 this.win.rooview.el.set_easing_duration(1000);
563 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
564 this.win.rooview.el.set_scale(1.0f,1.0f);
565 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
566 this.win.rooview.el.set_opacity(0xff);
570 this.clutterfiles.el.set_easing_duration(1000);
571 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
572 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
573 this.clutterfiles.el.set_opacity(0);
575 //this.clutterfiles.el.hide();
583 var oldstate =this.state;
584 this.state = new_state;
588 this.buttonsShowHide();
591 switch (this.state) {
593 case State.PREVIEW: // this is the default state when working...
594 this.win.editpane.el.show(); // holder for tree and properties..
597 this.left_projects.el.hide();
598 if (oldstate != State.FILES) {
599 // it's handled above..
600 print ("changing state to preview from NOT files..");
603 this.win.rooview.el.set_scale(1.0f,1.0f);
612 var ae = this.left_tree.getActiveElement();
614 this.state = oldstate;
615 this.buttonsShowHide();
616 this.resizeCanvasElements();
617 this.easingRestoreAll();
620 this.add_props.el.show_all();
622 Palete.factory(this.win.project.xtype),
623 this.state == State.LISTENER ? "signals" : "props",
630 // -- FIXME? this needs to be State aware?
632 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
634 this.win.addpropsview.el.set_scale(1.0f,1.0f);
638 var n = this.left_tree.getActiveElement();
640 if (this.left_tree.model.file == null) {
641 this.state =oldstate;
642 this.buttonsShowHide();
643 this.resizeCanvasElements();
644 this.easingRestoreAll();
648 if (n == null && this.left_tree.model.file.tree != null) {
649 this.state = oldstate;
650 this.buttonsShowHide();
651 this.resizeCanvasElements();
652 this.easingRestoreAll();
656 this.rightpalete.el.show_all();
657 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
662 this.win.objectview.el.set_scale(1.0f,1.0f);
669 this.code_editor.el.show_all();
671 // caller needs to call editor - show....
674 this.win.codeeditview.el.set_scale(1.0f,1.0f);
681 if (this.win.project.xtype == "Roo") {
682 this.projectsettings.el.show_all();
683 this.projectsettings.show(this.win.project);
685 this.vala_projectsettings.el.show_all();
686 this.vala_projectsettings.show((Project.Gtk)this.win.project);
689 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
691 this.win.projecteditview.el.set_scale(1.0f,1.0f);
696 case State.FILES: // can only get here from PREVIEW state.. in theory..
699 this.win.editpane.el.hide(); // holder for tree and properties..
701 this.left_projects.el.show();
703 this.win.rooview.el.set_easing_duration(1000);
704 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
705 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
706 this.win.rooview.el.set_opacity(0);
707 //el.set_scale(0.0f,0.0f);
710 if (this.win.project != null) {
711 this.left_projects.selectProject(this.win.project);
715 this.clutterfiles.el.show();
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, 0.0f);
720 this.clutterfiles.el.set_opacity(0xff);
728 this.resizeCanvasElements();
729 this.easingRestoreAll();
734 public int redraw_count = 0;
735 public void resizeCanvas() // called by window resize .. delays redraw
737 var rc = this.redraw_count;
738 this.redraw_count = 2;
740 GLib.Timeout.add(100, () =>{
741 return this.resizeCanvasQueue();
745 public bool resizeCanvasQueue()
747 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
749 if (this.redraw_count < 1) {
750 return false; // should not really happen...
756 if (this.redraw_count > 0) {
757 return true; // do it again in 1 second...
759 // got down to 0 or -1....
760 this.redraw_count = 0;
761 this.resizeCanvasElements();
765 public void resizeCanvasElements()
767 Gtk.Allocation alloc;
768 this.win.clutterembed.el.get_allocation(out alloc);
770 // print("WindowState.resizeCanvasElements\n");
771 if (!this.children_loaded || this.win.clutterembed == null) {
772 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
776 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
777 var palsize = avail < 300.0f ? avail : 300.0f;
780 // -------- code edit min 600
782 var codesize = avail < 800.0f ? avail : 800.0f;
785 //print("set code size %f\n", codesize);
789 switch ( this.state) {
791 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
795 this.clutterfiles.set_size(alloc.width-50, alloc.height);
800 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
802 // this.win.rooview.el.save_easing_state();
803 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
804 this.win.rooview.el.set_scale(0.5f, 0.5f);
805 //this.win.rooview.el.restore_easing_state();
809 this.win.codeeditview.el.set_size(codesize, alloc.height);
810 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
811 //this.win.rooview.el.save_easing_state();
813 this.win.rooview.el.set_scale(scale,scale);
814 // this.win.rooview.el.restore_easing_state();
819 this.win.addpropsview.el.set_size(palsize, alloc.height);
820 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
821 this.win.rooview.el.set_scale(scale,scale);
825 this.win.objectview.el.set_size(palsize, alloc.height);
826 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
827 //this.win.rooview.el.save_easing_state();
828 this.win.rooview.el.set_scale(scale,scale);
829 // this.win.rooview.el.restore_easing_state();
834 // -- buttons show hide.....
836 public void buttonsShowHide()
838 // basically hide everything, then show the relivant..
840 this.win.backbutton.el.hide();
842 this.win.projectbutton.el.hide(); // show file nav...
843 this.win.editfilebutton.el.hide();
844 this.win.projecteditbutton.el.hide();
847 this.win.objectshowbutton.el.hide(); // add objects
848 this.win.addpropbutton.el.hide();
849 this.win.addlistenerbutton.el.hide();
853 this.win.addprojectbutton.el.hide();
854 this.win.addfilebutton.el.hide();
855 this.win.delprojectbutton.el.hide();
858 switch (this.state) {
860 case State.PREVIEW: // this is the default state when working...
862 this.win.projectbutton.el.show(); // show file nav...
863 this.win.editfilebutton.el.show();
864 this.win.projecteditbutton.el.show();
867 this.win.objectshowbutton.el.show(); // add objects
868 this.win.addpropbutton.el.show();
869 this.win.addlistenerbutton.el.show();
878 this.win.backbutton.el.show();
879 this.win.objectshowbutton.el.show(); // add objects
880 this.win.addpropbutton.el.show();
881 this.win.addlistenerbutton.el.show();
886 this.win.backbutton.el.show();
891 if (this.left_projects.getSelectedProject() != null ) {
892 if (this.left_tree.getActiveFile() != null) {
893 this.win.backbutton.el.show();
895 this.win.addfilebutton.el.show();
898 this.win.addprojectbutton.el.show();
899 this.win.delprojectbutton.el.show();
909 public void valaCompiled(Json.Object obj)
911 // vala has finished compiling...
912 print("vala compiled");
914 var buf = this.code_editor.buffer;
915 buf.check_running = false;
917 if (obj.has_member("ERR-TOTAL")) {
918 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
920 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
923 if (obj.has_member("WARN-TOTAL")) {
925 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
927 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
930 if (obj.has_member("DEPR-TOTAL")) {
932 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
935 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
938 buf.highlightErrorsJson("ERR", obj);
939 buf.highlightErrorsJson("WARN", obj);
940 buf.highlightErrorsJson("DEPR", obj);
942 var gbuf = this.window_gladeview.sourceview;
943 gbuf.highlightErrorsJson("ERR", obj);
944 gbuf.highlightErrorsJson("WARN", obj);
945 gbuf.highlightErrorsJson("DEPR", obj);
947 this.last_compile_result = obj;