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 WindowState(Xcls_MainWindow win)
60 // on clutter space...
61 this.projectEditInit();
63 this.projectListInit();
73 this.webkitViewInit();
77 this.fileDetailsInit();
79 this.webkit_plugin = new Xcls_DialogPluginWebkit();
80 this.template_select = new DialogTemplateSelect();
81 this.children_loaded = true;
87 public void leftTreeInit()
90 this.left_tree = new Xcls_WindowLeftTree();
92 this.left_tree.main_window = this.win;
94 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
95 this.left_tree.el.show_all();
97 this.left_tree.before_node_change.connect(() => {
98 return this.leftTreeBeforeChange();
102 this.left_tree.node_selected.connect((sel) => {
103 this.leftTreeNodeSelected(sel);
106 this.left_tree.changed.connect(() => {
107 this.window_rooview.requestRedraw();
108 this.left_tree.model.file.save();
113 public bool leftTreeBeforeChange()
115 if (this.state != State.CODE) {
116 this.left_props.finish_editing();
119 if (!this.code_editor.saveContents()) {
125 public void leftTreeNodeSelected(JsRender.Node? sel)
128 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
131 this.left_props.el.hide();
133 this.left_props.el.show();
134 this.left_props.load(this.left_tree.getActiveFile(), sel);
135 switch (this.state) {
140 this.rightpalete.clear();
143 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
149 this.add_props.clear();
152 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
158 this.add_props.clear();
161 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
165 this.switchState(State.PREVIEW);
178 public void propsListInit()
181 this.left_props =new Xcls_LeftProps();
182 this.left_props.ref();
183 this.left_props.main_window = this.win;
184 this.win.props.el.pack_start(this.left_props.el,true, true,0);
185 this.left_props.el.show_all();
187 this.left_props.show_editor.connect( (file, node, type, key) => {
188 this.switchState(State.CODE);
189 this.code_editor.show(
200 this.left_props.stop_editor.connect( () => {
201 if (this.state != State.CODE) {
205 var ret = this.code_editor.saveContents();
209 this.switchState(State.PREVIEW);
213 this.left_props.changed.connect(() => {
214 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
215 this.window_rooview.requestRedraw();
218 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
220 this.left_tree.model.updateSelected();
221 this.left_tree.model.file.save();
228 //------------- projects edit
230 public void projectEditInit()
232 this.projectsettings =new Xcls_ProjectSettings();
233 this.projectsettings.ref(); /// really?
235 this.vala_projectsettings =new ValaProjectSettings();
236 this.vala_projectsettings.ref();
237 this.vala_projectsettings.window = this.win;
239 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
240 //this.projectsettings.el.show_all();
242 var stage = this.win.projecteditview.el.get_stage();
243 stage.set_background_color( Clutter.Color.from_string("#000"));
245 this.projectsettings.buttonPressed.connect((btn) => {
246 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
248 this.window_rooview.view.renderJS(true);
250 if (btn == "apply") {
251 this.window_rooview.view.renderJS(true);
255 // do nothing for gtk..
257 if (btn == "save" || btn == "apply") {
258 this.win.project.save();
261 this.switchState (State.PREVIEW);
266 // ----------- object adding
267 public void objectAddInit()
270 this.rightpalete = new Xcls_RightPalete();
271 this.rightpalete.ref(); /// really?
272 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
273 //this.projectsettings.el.show_all();
275 var stage = this.win.objectview.el.get_stage();
276 stage.set_background_color( Clutter.Color.from_string("#000"));
280 // ----------- properties adding list...
281 // listener uses the properties
282 public void propsAddInit()
285 this.add_props = new Xcls_WindowAddProp();
286 this.add_props.ref(); /// really?
287 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
288 //this.projectsettings.el.show_all();
290 var stage = this.win.addpropsview.el.get_stage();
291 stage.set_background_color( Clutter.Color.from_string("#000"));
294 this.add_props.select.connect( (key,type,skel, etype) => {
295 this.left_props.addProp(etype, key, skel, type);
299 public void propsAddShow()
303 public void propsAddHide()
311 // ----------- Add / Edit listener
312 // listener uses the properties
313 //public void listenerInit() { }
314 public void listenerShow()
318 public void listenerHide()
323 // -------------- codeEditor
325 public void codeEditInit()
327 this.code_editor = new Editor();
328 this.code_editor.ref(); /// really?
329 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
330 //this.projectsettings.el.show_all();
332 var stage = this.win.codeeditview.el.get_stage();
333 stage.set_background_color( Clutter.Color.from_string("#000"));
336 this.code_editor.save.connect( () => {
337 this.left_tree.model.file.save();
338 this.left_tree.model.updateSelected();
343 // ----------- list of projects on left
344 public void projectListInit()
347 this.left_projects = new Xcls_WindowLeftProjects();
348 this.left_projects.ref();
349 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
350 this.left_projects.el.show_all();
351 this.left_projects.project_selected.connect((proj) => {
352 this.buttonsShowHide();
354 this.clutterfiles.loadProject(proj);
359 // ----------- file view
361 public void fileViewInit()
363 var stage = this.win.rooview.el.get_stage(); // seems odd...
364 this.clutterfiles = new Xcls_ClutterFiles();
365 this.clutterfiles.ref();
366 stage.add_child(this.clutterfiles.el);
367 this.clutterfiles.el.show_all();
370 this.clutterfiles.open.connect((file) => {
371 this.fileViewOpen(file);
373 this.clutterfiles.el.transitions_completed.connect(() => {
374 if (this.state == State.FILES) {
375 this.win.rooview.el.hide();
377 this.clutterfiles.el.hide();
385 public void fileDetailsInit()
387 this.file_details = new Xcls_PopoverFileDetails();
388 this.file_details.mainwindow = this.win;
389 // force it modal to the main window..
391 this.file_details.success.connect((project,file) =>
393 this.fileViewOpen(file);
398 public void fileViewOpen(JsRender.JsRender file)
400 this.win.project = file.project;
401 this.switchState (State.PREVIEW);
403 this.left_tree.model.loadFile(file);
405 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
406 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
408 if (file.xtype == "Roo" ) {
409 ctr.foreach( (w) => { ctr.remove(w); });
410 ctr_p.foreach( (w) => { ctr_p.remove(w); });
411 ctr.add(this.window_rooview.el);
412 ctr_p.add(this.projectsettings.el);
413 this.window_rooview.loadFile(file);
414 this.window_rooview.el.show_all();
415 this.projectsettings.el.show_all();
418 ctr.foreach( (w) => { ctr.remove(w); });
419 ctr_p.foreach( (w) => { ctr_p.remove(w); });
420 ctr.add(this.window_gladeview.el);
421 ctr_p.add(this.vala_projectsettings.el);
422 this.window_gladeview.loadFile(file);
423 this.window_gladeview.el.show_all();
424 this.vala_projectsettings.el.show_all();
426 print("OPEN : " + file.name);
427 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
428 this.win.setTitle(file.project.name + " : " +file.name);
434 // --------- webkit view
435 public void webkitViewInit()
437 this.window_rooview =new Xcls_WindowRooView();
438 this.window_rooview.ref();
439 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
440 this.window_rooview.el.show_all();
442 var stage = this.win.rooview.el.get_stage();
443 stage.set_background_color( Clutter.Color.from_string("#000"));
448 public void gtkViewInit()
450 this.window_gladeview =new Xcls_GtkView();
451 this.window_gladeview.ref();
452 this.window_gladeview.main_window = this.win;
455 public void easingSaveAll()
457 this.win.addpropsview.el.save_easing_state();
458 this.win.codeeditview.el.save_easing_state();
459 this.win.objectview.el.save_easing_state();
460 this.win.projecteditview.el.save_easing_state();
461 this.win.rooview.el.save_easing_state();
462 this.clutterfiles.el.save_easing_state();
465 public void easingRestoreAll()
467 this.win.addpropsview.el.restore_easing_state();
468 this.win.codeeditview.el.restore_easing_state();
469 this.win.objectview.el.restore_easing_state();
470 this.win.projecteditview.el.restore_easing_state();
471 this.win.rooview.el.restore_easing_state();
472 this.clutterfiles.el.restore_easing_state();
475 public void switchState(State new_state)
478 // save the easing state of everything..
479 this.easingSaveAll();
481 switch (this.state) {
484 if (this.left_tree.getActiveFile() != null) {
485 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
486 this.window_rooview.createThumb();
488 this.window_gladeview.createThumb();
491 // normally we are going from preview to another state.
492 // and different windows hide the preview in differnt ways..
499 this.win.addpropsview.el.set_scale(0.0f,0.0f);
505 this.code_editor.saveContents();
507 this.win.codeeditview.el.set_scale(0.0f,0.0f);
513 this.win.objectview.el.set_scale(0.0f,0.0f);
517 if (this.win.project.xtype == "Gtk") {
518 this.vala_projectsettings.save();
521 this.win.projecteditview.el.set_scale(0.0f,0.0f);
527 this.win.rooview.el.show_all();
528 this.win.rooview.el.set_easing_duration(1000);
529 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
530 this.win.rooview.el.set_scale(1.0f,1.0f);
531 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
532 this.win.rooview.el.set_opacity(0xff);
536 this.clutterfiles.el.set_easing_duration(1000);
537 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
538 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
539 this.clutterfiles.el.set_opacity(0);
541 //this.clutterfiles.el.hide();
549 var oldstate =this.state;
550 this.state = new_state;
554 this.buttonsShowHide();
557 switch (this.state) {
559 case State.PREVIEW: // this is the default state when working...
560 this.win.editpane.el.show(); // holder for tree and properties..
563 this.left_projects.el.hide();
564 if (oldstate != State.FILES) {
565 // it's handled above..
566 print ("changing state to preview from NOT files..");
569 this.win.rooview.el.set_scale(1.0f,1.0f);
578 var ae = this.left_tree.getActiveElement();
580 this.state = oldstate;
581 this.buttonsShowHide();
582 this.resizeCanvasElements();
583 this.easingRestoreAll();
586 this.add_props.el.show_all();
588 Palete.factory(this.win.project.xtype),
589 this.state == State.LISTENER ? "signals" : "props",
596 // -- FIXME? this needs to be State aware?
598 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
600 this.win.addpropsview.el.set_scale(1.0f,1.0f);
604 var n = this.left_tree.getActiveElement();
606 if (this.left_tree.model.file == null) {
607 this.state =oldstate;
608 this.buttonsShowHide();
609 this.resizeCanvasElements();
610 this.easingRestoreAll();
614 if (n == null && this.left_tree.model.file.tree != null) {
615 this.state = oldstate;
616 this.buttonsShowHide();
617 this.resizeCanvasElements();
618 this.easingRestoreAll();
622 this.rightpalete.el.show_all();
623 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
628 this.win.objectview.el.set_scale(1.0f,1.0f);
635 this.code_editor.el.show_all();
637 // caller needs to call editor - show....
640 this.win.codeeditview.el.set_scale(1.0f,1.0f);
647 if (this.win.project.xtype == "Roo") {
648 this.projectsettings.el.show_all();
649 this.projectsettings.show(this.win.project);
651 this.vala_projectsettings.el.show_all();
652 this.vala_projectsettings.show((Project.Gtk)this.win.project);
655 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
657 this.win.projecteditview.el.set_scale(1.0f,1.0f);
662 case State.FILES: // can only get here from PREVIEW state.. in theory..
665 this.win.editpane.el.hide(); // holder for tree and properties..
667 this.left_projects.el.show();
669 this.win.rooview.el.set_easing_duration(1000);
670 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
671 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
672 this.win.rooview.el.set_opacity(0);
673 //el.set_scale(0.0f,0.0f);
676 if (this.win.project != null) {
677 this.left_projects.selectProject(this.win.project);
681 this.clutterfiles.el.show_all();
683 this.clutterfiles.el.set_easing_duration(1000);
684 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
685 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
686 this.clutterfiles.el.set_opacity(0xff);
694 this.resizeCanvasElements();
695 this.easingRestoreAll();
700 public int redraw_count = 0;
701 public void resizeCanvas() // called by window resize .. delays redraw
703 var rc = this.redraw_count;
704 this.redraw_count = 2;
706 GLib.Timeout.add(100, () =>{
707 return this.resizeCanvasQueue();
711 public bool resizeCanvasQueue()
713 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
715 if (this.redraw_count < 1) {
716 return false; // should not really happen...
722 if (this.redraw_count > 0) {
723 return true; // do it again in 1 second...
725 // got down to 0 or -1....
726 this.redraw_count = 0;
727 this.resizeCanvasElements();
731 public void resizeCanvasElements()
733 Gtk.Allocation alloc;
734 this.win.clutterembed.el.get_allocation(out alloc);
736 // print("WindowState.resizeCanvasElements\n");
737 if (!this.children_loaded || this.win.clutterembed == null) {
738 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
742 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
743 var palsize = avail < 300.0f ? avail : 300.0f;
746 // -------- code edit min 600
748 var codesize = avail < 800.0f ? avail : 800.0f;
751 //print("set code size %f\n", codesize);
755 switch ( this.state) {
757 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
761 this.clutterfiles.set_size(alloc.width-50, alloc.height);
766 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
768 // this.win.rooview.el.save_easing_state();
769 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
770 this.win.rooview.el.set_scale(0.5f, 0.5f);
771 //this.win.rooview.el.restore_easing_state();
775 this.win.codeeditview.el.set_size(codesize, alloc.height);
776 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
777 //this.win.rooview.el.save_easing_state();
779 this.win.rooview.el.set_scale(scale,scale);
780 // this.win.rooview.el.restore_easing_state();
785 this.win.addpropsview.el.set_size(palsize, alloc.height);
786 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
787 this.win.rooview.el.set_scale(scale,scale);
791 this.win.objectview.el.set_size(palsize, alloc.height);
792 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
793 //this.win.rooview.el.save_easing_state();
794 this.win.rooview.el.set_scale(scale,scale);
795 // this.win.rooview.el.restore_easing_state();
800 // -- buttons show hide.....
802 public void buttonsShowHide()
804 // basically hide everything, then show the relivant..
806 this.win.backbutton.el.hide();
808 this.win.projectbutton.el.hide(); // show file nav...
809 this.win.editfilebutton.el.hide();
810 this.win.projecteditbutton.el.hide();
813 this.win.objectshowbutton.el.hide(); // add objects
814 this.win.addpropbutton.el.hide();
815 this.win.addlistenerbutton.el.hide();
819 this.win.addprojectbutton.el.hide();
820 this.win.addfilebutton.el.hide();
821 this.win.delprojectbutton.el.hide();
824 switch (this.state) {
826 case State.PREVIEW: // this is the default state when working...
828 this.win.projectbutton.el.show(); // show file nav...
829 this.win.editfilebutton.el.show();
830 this.win.projecteditbutton.el.show();
833 this.win.objectshowbutton.el.show(); // add objects
834 this.win.addpropbutton.el.show();
835 this.win.addlistenerbutton.el.show();
844 this.win.backbutton.el.show();
845 this.win.objectshowbutton.el.show(); // add objects
846 this.win.addpropbutton.el.show();
847 this.win.addlistenerbutton.el.show();
852 this.win.backbutton.el.show();
857 if (this.left_projects.getSelectedProject() != null ) {
858 if (this.left_tree.getActiveFile() != null) {
859 this.win.backbutton.el.show();
861 this.win.addfilebutton.el.show();
864 this.win.addprojectbutton.el.show();
865 this.win.delprojectbutton.el.show();