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_DialogNewComponent new_file_dialog;
45 public Xcls_PopoverFileDetails file_details;
49 public Xcls_DialogPluginWebkit webkit_plugin;
52 public WindowState(Xcls_MainWindow win)
61 // on clutter space...
62 this.projectEditInit();
64 this.projectListInit();
74 this.webkitViewInit();
78 this.fileNewInit(); // depricated...
79 this.fileDetailsInit();
81 this.webkit_plugin = new Xcls_DialogPluginWebkit();
82 this.template_select = new DialogTemplateSelect();
83 this.children_loaded = true;
89 public void leftTreeInit()
92 this.left_tree = new Xcls_WindowLeftTree();
94 this.left_tree.main_window = this.win;
96 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
97 this.left_tree.el.show_all();
99 this.left_tree.before_node_change.connect(() => {
100 return this.leftTreeBeforeChange();
104 this.left_tree.node_selected.connect((sel) => {
105 this.leftTreeNodeSelected(sel);
108 this.left_tree.changed.connect(() => {
109 this.window_rooview.requestRedraw();
110 this.left_tree.model.file.save();
115 public bool leftTreeBeforeChange()
117 if (this.state != State.CODE) {
118 this.left_props.finish_editing();
121 if (!this.code_editor.saveContents()) {
127 public void leftTreeNodeSelected(JsRender.Node? sel)
130 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
133 this.left_props.el.hide();
135 this.left_props.el.show();
136 this.left_props.load(this.left_tree.getActiveFile(), sel);
137 switch (this.state) {
142 this.rightpalete.clear();
145 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
151 this.add_props.clear();
154 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
160 this.add_props.clear();
163 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
167 this.switchState(State.PREVIEW);
180 public void propsListInit()
183 this.left_props =new Xcls_LeftProps();
184 this.left_props.ref();
185 this.left_props.main_window = this.win;
186 this.win.props.el.pack_start(this.left_props.el,true, true,0);
187 this.left_props.el.show_all();
189 this.left_props.show_editor.connect( (file, node, type, key) => {
190 this.switchState(State.CODE);
191 this.code_editor.show(
202 this.left_props.stop_editor.connect( () => {
203 if (this.state != State.CODE) {
207 var ret = this.code_editor.saveContents();
211 this.switchState(State.PREVIEW);
215 this.left_props.changed.connect(() => {
216 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
217 this.window_rooview.requestRedraw();
220 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
222 this.left_tree.model.updateSelected();
223 this.left_tree.model.file.save();
230 //------------- projects edit
232 public void projectEditInit()
234 this.projectsettings =new Xcls_ProjectSettings();
235 this.projectsettings.ref(); /// really?
237 this.vala_projectsettings =new ValaProjectSettings();
238 this.vala_projectsettings.ref();
239 this.vala_projectsettings.window = this.win;
241 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
242 //this.projectsettings.el.show_all();
244 var stage = this.win.projecteditview.el.get_stage();
245 stage.set_background_color( Clutter.Color.from_string("#000"));
247 this.projectsettings.buttonPressed.connect((btn) => {
248 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
250 this.window_rooview.view.renderJS(true);
252 if (btn == "apply") {
253 this.window_rooview.view.renderJS(true);
257 // do nothing for gtk..
259 if (btn == "save" || btn == "apply") {
260 this.win.project.save();
263 this.switchState (State.PREVIEW);
268 // ----------- object adding
269 public void objectAddInit()
272 this.rightpalete = new Xcls_RightPalete();
273 this.rightpalete.ref(); /// really?
274 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
275 //this.projectsettings.el.show_all();
277 var stage = this.win.objectview.el.get_stage();
278 stage.set_background_color( Clutter.Color.from_string("#000"));
282 // ----------- properties adding list...
283 // listener uses the properties
284 public void propsAddInit()
287 this.add_props = new Xcls_WindowAddProp();
288 this.add_props.ref(); /// really?
289 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
290 //this.projectsettings.el.show_all();
292 var stage = this.win.addpropsview.el.get_stage();
293 stage.set_background_color( Clutter.Color.from_string("#000"));
296 this.add_props.select.connect( (key,type,skel, etype) => {
297 this.left_props.addProp(etype, key, skel, type);
301 public void propsAddShow()
305 public void propsAddHide()
313 // ----------- Add / Edit listener
314 // listener uses the properties
315 //public void listenerInit() { }
316 public void listenerShow()
320 public void listenerHide()
325 // -------------- codeEditor
327 public void codeEditInit()
329 this.code_editor = new Editor();
330 this.code_editor.ref(); /// really?
331 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
332 //this.projectsettings.el.show_all();
334 var stage = this.win.codeeditview.el.get_stage();
335 stage.set_background_color( Clutter.Color.from_string("#000"));
338 this.code_editor.save.connect( () => {
339 this.left_tree.model.file.save();
340 this.left_tree.model.updateSelected();
345 // ----------- list of projects on left
346 public void projectListInit()
349 this.left_projects = new Xcls_WindowLeftProjects();
350 this.left_projects.ref();
351 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
352 this.left_projects.el.show_all();
353 this.left_projects.project_selected.connect((proj) => {
355 this.clutterfiles.loadProject(proj);
360 // ----------- file view
362 public void fileViewInit()
364 var stage = this.win.rooview.el.get_stage(); // seems odd...
365 this.clutterfiles = new Xcls_ClutterFiles();
366 this.clutterfiles.ref();
367 stage.add_child(this.clutterfiles.el);
368 this.clutterfiles.el.show_all();
371 this.clutterfiles.open.connect((file) => {
372 this.fileViewOpen(file);
374 this.clutterfiles.el.transitions_completed.connect(() => {
375 if (this.state == State.FILES) {
376 this.win.rooview.el.hide();
378 this.clutterfiles.el.hide();
385 public void fileNewInit()
387 this.new_file_dialog = new Xcls_DialogNewComponent();
388 // force it modal to the main window..
389 this.new_file_dialog.el.set_transient_for(this.win.el);
390 this.new_file_dialog.el.set_modal(true);
392 this.new_file_dialog.success.connect((project,file) =>
394 this.fileViewOpen(file);
398 public void fileDetailsInit()
400 this.file_details = new Xcls_PopoverFileDetails();
401 this.file_details.mainwindow = this.win;
402 // force it modal to the main window..
404 this.file_details.success.connect((project,file) =>
406 this.fileViewOpen(file);
411 public void fileViewOpen(JsRender.JsRender file)
413 this.win.project = file.project;
414 this.switchState (State.PREVIEW);
416 this.left_tree.model.loadFile(file);
418 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
419 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
421 if (file.xtype == "Roo" ) {
422 ctr.foreach( (w) => { ctr.remove(w); });
423 ctr_p.foreach( (w) => { ctr_p.remove(w); });
424 ctr.add(this.window_rooview.el);
425 ctr_p.add(this.projectsettings.el);
426 this.window_rooview.loadFile(file);
427 this.window_rooview.el.show_all();
428 this.projectsettings.el.show_all();
431 ctr.foreach( (w) => { ctr.remove(w); });
432 ctr_p.foreach( (w) => { ctr_p.remove(w); });
433 ctr.add(this.window_gladeview.el);
434 ctr_p.add(this.vala_projectsettings.el);
435 this.window_gladeview.loadFile(file);
436 this.window_gladeview.el.show_all();
437 this.vala_projectsettings.el.show_all();
439 print("OPEN : " + file.name);
440 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
441 this.win.setTitle(file.project.name + " : " +file.name);
447 // --------- webkit view
448 public void webkitViewInit()
450 this.window_rooview =new Xcls_WindowRooView();
451 this.window_rooview.ref();
452 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
453 this.window_rooview.el.show_all();
455 var stage = this.win.rooview.el.get_stage();
456 stage.set_background_color( Clutter.Color.from_string("#000"));
461 public void gtkViewInit()
463 this.window_gladeview =new Xcls_GtkView();
464 this.window_gladeview.ref();
465 this.window_gladeview.main_window = this.win;
468 public void easingSaveAll()
470 this.win.addpropsview.el.save_easing_state();
471 this.win.codeeditview.el.save_easing_state();
472 this.win.objectview.el.save_easing_state();
473 this.win.projecteditview.el.save_easing_state();
474 this.win.rooview.el.save_easing_state();
475 this.clutterfiles.el.save_easing_state();
478 public void easingRestoreAll()
480 this.win.addpropsview.el.restore_easing_state();
481 this.win.codeeditview.el.restore_easing_state();
482 this.win.objectview.el.restore_easing_state();
483 this.win.projecteditview.el.restore_easing_state();
484 this.win.rooview.el.restore_easing_state();
485 this.clutterfiles.el.restore_easing_state();
488 public void switchState(State new_state)
491 // save the easing state of everything..
492 this.easingSaveAll();
494 switch (this.state) {
497 if (this.left_tree.getActiveFile() != null) {
498 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
499 this.window_rooview.createThumb();
501 this.window_gladeview.createThumb();
504 // normally we are going from preview to another state.
505 // and different windows hide the preview in differnt ways..
512 this.win.addpropsview.el.set_scale(0.0f,0.0f);
518 this.code_editor.saveContents();
520 this.win.codeeditview.el.set_scale(0.0f,0.0f);
526 this.win.objectview.el.set_scale(0.0f,0.0f);
530 if (this.win.project.xtype == "Gtk") {
531 this.vala_projectsettings.save();
534 this.win.projecteditview.el.set_scale(0.0f,0.0f);
540 this.win.rooview.el.show_all();
541 this.win.rooview.el.set_easing_duration(1000);
542 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
543 this.win.rooview.el.set_scale(1.0f,1.0f);
544 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
545 this.win.rooview.el.set_opacity(0xff);
549 this.clutterfiles.el.set_easing_duration(1000);
550 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
551 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
552 this.clutterfiles.el.set_opacity(0);
554 //this.clutterfiles.el.hide();
562 var oldstate =this.state;
563 this.state = new_state;
567 this.buttonsShowHide();
570 switch (this.state) {
572 case State.PREVIEW: // this is the default state when working...
573 this.win.editpane.el.show(); // holder for tree and properties..
576 this.left_projects.el.hide();
577 if (oldstate != State.FILES) {
578 // it's handled above..
579 print ("changing state to preview from NOT files..");
582 this.win.rooview.el.set_scale(1.0f,1.0f);
591 var ae = this.left_tree.getActiveElement();
593 this.state = oldstate;
594 this.buttonsShowHide();
595 this.resizeCanvasElements();
596 this.easingRestoreAll();
599 this.add_props.el.show_all();
601 Palete.factory(this.win.project.xtype),
602 this.state == State.LISTENER ? "signals" : "props",
609 // -- FIXME? this needs to be State aware?
611 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
613 this.win.addpropsview.el.set_scale(1.0f,1.0f);
617 var n = this.left_tree.getActiveElement();
619 if (this.left_tree.model.file == null) {
620 this.state =oldstate;
621 this.buttonsShowHide();
622 this.resizeCanvasElements();
623 this.easingRestoreAll();
627 if (n == null && this.left_tree.model.file.tree != null) {
628 this.state = oldstate;
629 this.buttonsShowHide();
630 this.resizeCanvasElements();
631 this.easingRestoreAll();
635 this.rightpalete.el.show_all();
636 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
641 this.win.objectview.el.set_scale(1.0f,1.0f);
648 this.code_editor.el.show_all();
650 // caller needs to call editor - show....
653 this.win.codeeditview.el.set_scale(1.0f,1.0f);
660 if (this.win.project.xtype == "Roo") {
661 this.projectsettings.el.show_all();
662 this.projectsettings.show(this.win.project);
664 this.vala_projectsettings.el.show_all();
665 this.vala_projectsettings.show((Project.Gtk)this.win.project);
668 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
670 this.win.projecteditview.el.set_scale(1.0f,1.0f);
675 case State.FILES: // can only get here from PREVIEW state.. in theory..
678 this.win.editpane.el.hide(); // holder for tree and properties..
680 this.left_projects.el.show();
682 this.win.rooview.el.set_easing_duration(1000);
683 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
684 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
685 this.win.rooview.el.set_opacity(0);
686 //el.set_scale(0.0f,0.0f);
689 if (this.win.project != null) {
690 this.left_projects.selectProject(this.win.project);
694 this.clutterfiles.el.show_all();
696 this.clutterfiles.el.set_easing_duration(1000);
697 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
698 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
699 this.clutterfiles.el.set_opacity(0xff);
707 this.resizeCanvasElements();
708 this.easingRestoreAll();
713 public int redraw_count = 0;
714 public void resizeCanvas() // called by window resize .. delays redraw
716 var rc = this.redraw_count;
717 this.redraw_count = 2;
719 GLib.Timeout.add(100, () =>{
720 return this.resizeCanvasQueue();
724 public bool resizeCanvasQueue()
726 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
728 if (this.redraw_count < 1) {
729 return false; // should not really happen...
735 if (this.redraw_count > 0) {
736 return true; // do it again in 1 second...
738 // got down to 0 or -1....
739 this.redraw_count = 0;
740 this.resizeCanvasElements();
744 public void resizeCanvasElements()
746 Gtk.Allocation alloc;
747 this.win.clutterembed.el.get_allocation(out alloc);
749 // print("WindowState.resizeCanvasElements\n");
750 if (!this.children_loaded || this.win.clutterembed == null) {
751 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
755 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
756 var palsize = avail < 300.0f ? avail : 300.0f;
759 // -------- code edit min 600
761 var codesize = avail < 800.0f ? avail : 800.0f;
764 //print("set code size %f\n", codesize);
768 switch ( this.state) {
770 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
774 this.clutterfiles.set_size(alloc.width-50, alloc.height);
779 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
781 // this.win.rooview.el.save_easing_state();
782 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
783 this.win.rooview.el.set_scale(0.5f, 0.5f);
784 //this.win.rooview.el.restore_easing_state();
788 this.win.codeeditview.el.set_size(codesize, alloc.height);
789 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
790 //this.win.rooview.el.save_easing_state();
792 this.win.rooview.el.set_scale(scale,scale);
793 // this.win.rooview.el.restore_easing_state();
798 this.win.addpropsview.el.set_size(palsize, alloc.height);
799 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
800 this.win.rooview.el.set_scale(scale,scale);
804 this.win.objectview.el.set_size(palsize, alloc.height);
805 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
806 //this.win.rooview.el.save_easing_state();
807 this.win.rooview.el.set_scale(scale,scale);
808 // this.win.rooview.el.restore_easing_state();
813 // -- buttons show hide.....
815 public void buttonsShowHide()
817 // basically hide everything, then show the relivant..
819 this.win.backbutton.el.hide();
821 this.win.projectbutton.el.hide(); // show file nav...
822 this.win.editfilebutton.el.hide();
823 this.win.projecteditbutton.el.hide();
826 this.win.objectshowbutton.el.hide(); // add objects
827 this.win.addpropbutton.el.hide();
828 this.win.addlistenerbutton.el.hide();
832 this.win.addprojectbutton.el.hide();
833 this.win.addfilebutton.el.hide();
834 this.win.delprojectbutton.el.hide();
837 switch (this.state) {
839 case State.PREVIEW: // this is the default state when working...
841 this.win.projectbutton.el.show(); // show file nav...
842 this.win.editfilebutton.el.show();
843 this.win.projecteditbutton.el.show();
846 this.win.objectshowbutton.el.show(); // add objects
847 this.win.addpropbutton.el.show();
848 this.win.addlistenerbutton.el.show();
857 this.win.backbutton.el.show();
858 this.win.objectshowbutton.el.show(); // add objects
859 this.win.addpropbutton.el.show();
860 this.win.addlistenerbutton.el.show();
865 this.win.backbutton.el.show();
870 if (this.win.left_projects.getSelectedProject() != null ) {
871 this.win.backbutton.el.show();
872 this.win.addfilebutton.el.show();
875 this.win.addprojectbutton.el.show();
876 this.win.delprojectbutton.el.show();