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;
37 public Xcls_DialogNewComponent new_file_dialog;
38 public Xcls_ClutterFiles clutterfiles;
40 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
42 public DialogTemplateSelect template_select;
45 public Xcls_DialogPluginWebkit webkit_plugin;
48 public WindowState(Xcls_MainWindow win)
57 // on clutter space...
58 this.projectEditInit();
60 this.projectListInit();
70 this.webkitViewInit();
76 this.webkit_plugin = new Xcls_DialogPluginWebkit();
77 this.template_select = new DialogTemplateSelect();
78 this.children_loaded = true;
84 public void leftTreeInit()
87 this.left_tree = new Xcls_WindowLeftTree();
89 this.left_tree.main_window = this.win;
91 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
92 this.left_tree.el.show_all();
94 this.left_tree.before_node_change.connect(() => {
95 return this.leftTreeBeforeChange();
99 this.left_tree.node_selected.connect((sel) => {
100 this.leftTreeNodeSelected(sel);
103 this.left_tree.changed.connect(() => {
104 this.window_rooview.requestRedraw();
105 this.left_tree.model.file.save();
110 public bool leftTreeBeforeChange()
112 if (this.state != State.CODE) {
113 this.left_props.finish_editing();
116 if (!this.code_editor.saveContents()) {
122 public void leftTreeNodeSelected(JsRender.Node? sel)
125 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
128 this.left_props.el.hide();
130 this.left_props.el.show();
131 this.left_props.load(this.left_tree.getActiveFile(), sel);
132 switch (this.state) {
137 this.rightpalete.clear();
140 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
146 this.add_props.clear();
149 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
155 this.add_props.clear();
158 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
162 this.switchState(State.PREVIEW);
175 public void propsListInit()
178 this.left_props =new Xcls_LeftProps();
179 this.left_props.ref();
180 this.left_props.main_window = this.win;
181 this.win.props.el.pack_start(this.left_props.el,true, true,0);
182 this.left_props.el.show_all();
184 this.left_props.show_editor.connect( (file, node, type, key) => {
185 this.switchState(State.CODE);
186 this.code_editor.show(
197 this.left_props.stop_editor.connect( () => {
198 if (this.state != State.CODE) {
202 var ret = this.code_editor.saveContents();
206 this.switchState(State.PREVIEW);
210 this.left_props.changed.connect(() => {
211 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
212 this.window_rooview.requestRedraw();
215 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
217 this.left_tree.model.updateSelected();
218 this.left_tree.model.file.save();
225 //------------- projects edit
227 public void projectEditInit()
229 this.projectsettings =new Xcls_ProjectSettings();
230 this.projectsettings.ref(); /// really?
232 this.vala_projectsettings =new ValaProjectSettings();
233 this.vala_projectsettings.ref();
234 this.vala_projectsettings.window = this.win;
236 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
237 //this.projectsettings.el.show_all();
239 var stage = this.win.projecteditview.el.get_stage();
240 stage.set_background_color( Clutter.Color.from_string("#000"));
242 this.projectsettings.buttonPressed.connect((btn) => {
243 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
245 this.window_rooview.view.renderJS(true);
247 if (btn == "apply") {
248 this.window_rooview.view.renderJS(true);
252 // do nothing for gtk..
254 if (btn == "save" || btn == "apply") {
255 this.win.project.save();
258 this.switchState (State.PREVIEW);
263 // ----------- object adding
264 public void objectAddInit()
267 this.rightpalete = new Xcls_RightPalete();
268 this.rightpalete.ref(); /// really?
269 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
270 //this.projectsettings.el.show_all();
272 var stage = this.win.objectview.el.get_stage();
273 stage.set_background_color( Clutter.Color.from_string("#000"));
277 // ----------- properties adding list...
278 // listener uses the properties
279 public void propsAddInit()
282 this.add_props = new Xcls_WindowAddProp();
283 this.add_props.ref(); /// really?
284 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
285 //this.projectsettings.el.show_all();
287 var stage = this.win.addpropsview.el.get_stage();
288 stage.set_background_color( Clutter.Color.from_string("#000"));
291 this.add_props.select.connect( (key,type,skel, etype) => {
292 this.left_props.addProp(etype, key, skel, type);
296 public void propsAddShow()
300 public void propsAddHide()
308 // ----------- Add / Edit listener
309 // listener uses the properties
310 //public void listenerInit() { }
311 public void listenerShow()
315 public void listenerHide()
320 // -------------- codeEditor
322 public void codeEditInit()
324 this.code_editor = new Editor();
325 this.code_editor.ref(); /// really?
326 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
327 //this.projectsettings.el.show_all();
329 var stage = this.win.codeeditview.el.get_stage();
330 stage.set_background_color( Clutter.Color.from_string("#000"));
333 this.code_editor.save.connect( () => {
334 this.left_tree.model.file.save();
335 this.left_tree.model.updateSelected();
340 // ----------- list of projects on left
341 public void projectListInit()
344 this.left_projects = new Xcls_WindowLeftProjects();
345 this.left_projects.ref();
346 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
347 this.left_projects.el.show_all();
348 this.left_projects.project_selected.connect((proj) => {
350 this.clutterfiles.loadProject(proj);
355 // ----------- file view
357 public void fileViewInit()
359 var stage = this.win.rooview.el.get_stage(); // seems odd...
360 this.clutterfiles = new Xcls_ClutterFiles();
361 this.clutterfiles.ref();
362 stage.add_child(this.clutterfiles.el);
363 this.clutterfiles.el.show_all();
366 this.clutterfiles.open.connect((file) => {
367 this.fileViewOpen(file);
369 this.clutterfiles.el.transitions_completed.connect(() => {
370 if (this.state == State.FILES) {
371 this.win.rooview.el.hide();
373 this.clutterfiles.el.hide();
380 public void fileNewInit()
382 this.new_file_dialog = new Xcls_DialogNewComponent();
383 // force it modal to the main window..
384 this.new_file_dialog.el.set_transient_for(this.win.el);
385 this.new_file_dialog.el.set_modal(true);
387 this.new_file_dialog.success.connect((project,file) =>
389 this.fileViewOpen(file);
395 public void fileViewOpen(JsRender.JsRender file)
397 this.win.project = file.project;
398 this.switchState (State.PREVIEW);
400 this.left_tree.model.loadFile(file);
402 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
403 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
405 if (file.xtype == "Roo" ) {
406 ctr.foreach( (w) => { ctr.remove(w); });
407 ctr_p.foreach( (w) => { ctr_p.remove(w); });
408 ctr.add(this.window_rooview.el);
409 ctr_p.add(this.projectsettings.el);
410 this.window_rooview.loadFile(file);
411 this.window_rooview.el.show_all();
412 this.projectsettings.el.show_all();
415 ctr.foreach( (w) => { ctr.remove(w); });
416 ctr_p.foreach( (w) => { ctr_p.remove(w); });
417 ctr.add(this.window_gladeview.el);
418 ctr_p.add(this.vala_projectsettings.el);
419 this.window_gladeview.loadFile(file);
420 this.window_gladeview.el.show_all();
421 this.vala_projectsettings.el.show_all();
423 print("OPEN : " + file.name);
424 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
425 this.win.setTitle(file.project.name + " : " +file.name);
431 // --------- webkit view
432 public void webkitViewInit()
434 this.window_rooview =new Xcls_WindowRooView();
435 this.window_rooview.ref();
436 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
437 this.window_rooview.el.show_all();
439 var stage = this.win.rooview.el.get_stage();
440 stage.set_background_color( Clutter.Color.from_string("#000"));
445 public void gtkViewInit()
447 this.window_gladeview =new Xcls_GtkView();
448 this.window_gladeview.ref();
451 public void easingSaveAll()
453 this.win.addpropsview.el.save_easing_state();
454 this.win.codeeditview.el.save_easing_state();
455 this.win.objectview.el.save_easing_state();
456 this.win.projecteditview.el.save_easing_state();
457 this.win.rooview.el.save_easing_state();
458 this.clutterfiles.el.save_easing_state();
461 public void easingRestoreAll()
463 this.win.addpropsview.el.restore_easing_state();
464 this.win.codeeditview.el.restore_easing_state();
465 this.win.objectview.el.restore_easing_state();
466 this.win.projecteditview.el.restore_easing_state();
467 this.win.rooview.el.restore_easing_state();
468 this.clutterfiles.el.restore_easing_state();
471 public void switchState(State new_state)
474 // save the easing state of everything..
475 this.easingSaveAll();
477 switch (this.state) {
480 if (this.left_tree.getActiveFile() != null) {
481 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
482 this.window_rooview.createThumb();
484 this.window_gladeview.createThumb();
487 // normally we are going from preview to another state.
488 // and different windows hide the preview in differnt ways..
495 this.win.addpropsview.el.set_scale(0.0f,0.0f);
501 this.code_editor.saveContents();
503 this.win.codeeditview.el.set_scale(0.0f,0.0f);
509 this.win.objectview.el.set_scale(0.0f,0.0f);
513 if (this.win.project.xtype == "Gtk") {
514 this.vala_projectsettings.save();
517 this.win.projecteditview.el.set_scale(0.0f,0.0f);
523 this.win.rooview.el.show_all();
524 this.win.rooview.el.set_easing_duration(1000);
525 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
526 this.win.rooview.el.set_scale(1.0f,1.0f);
527 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
528 this.win.rooview.el.set_opacity(0xff);
532 this.clutterfiles.el.set_easing_duration(1000);
533 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
534 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
535 this.clutterfiles.el.set_opacity(0);
537 //this.clutterfiles.el.hide();
545 var oldstate =this.state;
546 this.state = new_state;
550 this.buttonsShowHide();
553 switch (this.state) {
555 case State.PREVIEW: // this is the default state when working...
556 this.win.editpane.el.show(); // holder for tree and properties..
559 this.left_projects.el.hide();
560 if (oldstate != State.FILES) {
561 // it's handled above..
562 print ("changing state to preview from NOT files..");
565 this.win.rooview.el.set_scale(1.0f,1.0f);
574 var ae = this.left_tree.getActiveElement();
576 this.state = oldstate;
577 this.buttonsShowHide();
578 this.resizeCanvasElements();
579 this.easingRestoreAll();
582 this.add_props.el.show_all();
584 Palete.factory(this.win.project.xtype),
585 this.state == State.LISTENER ? "signals" : "props",
592 // -- FIXME? this needs to be State aware?
594 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
596 this.win.addpropsview.el.set_scale(1.0f,1.0f);
600 var n = this.left_tree.getActiveElement();
602 if (this.left_tree.model.file == null) {
603 this.state =oldstate;
604 this.buttonsShowHide();
605 this.resizeCanvasElements();
606 this.easingRestoreAll();
610 if (n == null && this.left_tree.model.file.tree != null) {
611 this.state = oldstate;
612 this.buttonsShowHide();
613 this.resizeCanvasElements();
614 this.easingRestoreAll();
618 this.rightpalete.el.show_all();
619 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
624 this.win.objectview.el.set_scale(1.0f,1.0f);
631 this.code_editor.el.show_all();
633 // caller needs to call editor - show....
636 this.win.codeeditview.el.set_scale(1.0f,1.0f);
643 if (this.win.project.xtype == "Roo") {
644 this.projectsettings.el.show_all();
645 this.projectsettings.show(this.win.project);
647 this.vala_projectsettings.el.show_all();
648 this.vala_projectsettings.show((Project.Gtk)this.win.project);
651 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
653 this.win.projecteditview.el.set_scale(1.0f,1.0f);
658 case State.FILES: // can only get here from PREVIEW state.. in theory..
661 this.win.editpane.el.hide(); // holder for tree and properties..
663 this.left_projects.el.show();
665 this.win.rooview.el.set_easing_duration(1000);
666 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
667 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
668 this.win.rooview.el.set_opacity(0);
669 //el.set_scale(0.0f,0.0f);
672 if (this.win.project != null) {
673 this.left_projects.selectProject(this.win.project);
677 this.clutterfiles.el.show_all();
679 this.clutterfiles.el.set_easing_duration(1000);
680 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
681 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
682 this.clutterfiles.el.set_opacity(0xff);
690 this.resizeCanvasElements();
691 this.easingRestoreAll();
696 public int redraw_count = 0;
697 public void resizeCanvas() // called by window resize .. delays redraw
699 var rc = this.redraw_count;
700 this.redraw_count = 2;
702 GLib.Timeout.add(100, () =>{
703 return this.resizeCanvasQueue();
707 public bool resizeCanvasQueue()
709 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
711 if (this.redraw_count < 1) {
712 return false; // should not really happen...
718 if (this.redraw_count > 0) {
719 return true; // do it again in 1 second...
721 // got down to 0 or -1....
722 this.redraw_count = 0;
723 this.resizeCanvasElements();
727 public void resizeCanvasElements()
729 Gtk.Allocation alloc;
730 this.win.clutterembed.el.get_allocation(out alloc);
732 // print("WindowState.resizeCanvasElements\n");
733 if (!this.children_loaded || this.win.clutterembed == null) {
734 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
738 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
739 var palsize = avail < 300.0f ? avail : 300.0f;
742 // -------- code edit min 600
744 var codesize = avail < 800.0f ? avail : 800.0f;
747 //print("set code size %f\n", codesize);
751 switch ( this.state) {
753 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
757 this.clutterfiles.set_size(alloc.width-50, alloc.height);
762 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
764 // this.win.rooview.el.save_easing_state();
765 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
766 this.win.rooview.el.set_scale(0.5f, 0.5f);
767 //this.win.rooview.el.restore_easing_state();
771 this.win.codeeditview.el.set_size(codesize, alloc.height);
772 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
773 //this.win.rooview.el.save_easing_state();
775 this.win.rooview.el.set_scale(scale,scale);
776 // this.win.rooview.el.restore_easing_state();
781 this.win.addpropsview.el.set_size(palsize, alloc.height);
782 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
783 this.win.rooview.el.set_scale(scale,scale);
787 this.win.objectview.el.set_size(palsize, alloc.height);
788 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
789 //this.win.rooview.el.save_easing_state();
790 this.win.rooview.el.set_scale(scale,scale);
791 // this.win.rooview.el.restore_easing_state();
796 // -- buttons show hide.....
798 public void buttonsShowHide()
800 // basically hide everything, then show the relivant..
802 this.win.backbutton.el.hide();
804 this.win.projectbutton.el.hide(); // show file nav...
805 this.win.editfilebutton.el.hide();
806 this.win.projecteditbutton.el.hide();
809 this.win.objectshowbutton.el.hide(); // add objects
810 this.win.addpropbutton.el.hide();
811 this.win.addlistenerbutton.el.hide();
815 this.win.addprojectbutton.el.hide();
816 this.win.addfilebutton.el.hide();
817 this.win.delprojectbutton.el.hide();
818 this.win.new_window.el.hide();
819 this.win.reload_resources.el.hide();
821 switch (this.state) {
823 case State.PREVIEW: // this is the default state when working...
825 this.win.projectbutton.el.show(); // show file nav...
826 this.win.editfilebutton.el.show();
827 this.win.projecteditbutton.el.show();
830 this.win.objectshowbutton.el.show(); // add objects
831 this.win.addpropbutton.el.show();
832 this.win.addlistenerbutton.el.show();
841 this.win.backbutton.el.show();
842 this.win.objectshowbutton.el.show(); // add objects
843 this.win.addpropbutton.el.show();
844 this.win.addlistenerbutton.el.show();
849 this.win.backbutton.el.show();
854 this.win.backbutton.el.show();
856 this.win.addprojectbutton.el.show();
857 this.win.addfilebutton.el.show();
858 this.win.delprojectbutton.el.show();
859 this.win.new_window.el.show();
860 this.win.reload_resources.el.show();