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_ValaCompileErrors valacompileerrors;
39 public Xcls_ClutterFiles clutterfiles;
41 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
43 public DialogTemplateSelect template_select;
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.fileDetailsInit();
80 this.webkit_plugin = new Xcls_DialogPluginWebkit();
81 this.template_select = new DialogTemplateSelect();
83 this.vala_compile_errors = new Xcls_ValaCompileErrors();
84 this.vala_compile_errors.window = this.win;
86 this.children_loaded = true;
92 public void leftTreeInit()
95 this.left_tree = new Xcls_WindowLeftTree();
97 this.left_tree.main_window = this.win;
99 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
100 this.left_tree.el.show_all();
102 this.left_tree.before_node_change.connect(() => {
103 return this.leftTreeBeforeChange();
107 this.left_tree.node_selected.connect((sel) => {
108 this.leftTreeNodeSelected(sel);
111 this.left_tree.changed.connect(() => {
112 this.window_rooview.requestRedraw();
113 this.left_tree.model.file.save();
118 public bool leftTreeBeforeChange()
120 if (this.state != State.CODE) {
121 this.left_props.finish_editing();
124 if (!this.code_editor.saveContents()) {
130 public void leftTreeNodeSelected(JsRender.Node? sel)
133 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
136 this.left_props.el.hide();
138 this.left_props.el.show();
139 this.left_props.load(this.left_tree.getActiveFile(), sel);
140 switch (this.state) {
145 this.rightpalete.clear();
148 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
154 this.add_props.clear();
157 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
163 this.add_props.clear();
166 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
170 this.switchState(State.PREVIEW);
183 public void propsListInit()
186 this.left_props =new Xcls_LeftProps();
187 this.left_props.ref();
188 this.left_props.main_window = this.win;
189 this.win.props.el.pack_start(this.left_props.el,true, true,0);
190 this.left_props.el.show_all();
192 this.left_props.show_editor.connect( (file, node, type, key) => {
193 this.switchState(State.CODE);
194 this.code_editor.show(
205 this.left_props.stop_editor.connect( () => {
206 if (this.state != State.CODE) {
210 var ret = this.code_editor.saveContents();
214 this.switchState(State.PREVIEW);
218 this.left_props.changed.connect(() => {
219 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
220 this.window_rooview.requestRedraw();
223 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
225 this.left_tree.model.updateSelected();
226 this.left_tree.model.file.save();
233 //------------- projects edit
235 public void projectEditInit()
237 this.projectsettings =new Xcls_ProjectSettings();
238 this.projectsettings.ref(); /// really?
240 this.vala_projectsettings =new ValaProjectSettings();
241 this.vala_projectsettings.ref();
242 this.vala_projectsettings.window = this.win;
244 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
245 //this.projectsettings.el.show_all();
247 var stage = this.win.projecteditview.el.get_stage();
248 stage.set_background_color( Clutter.Color.from_string("#000"));
250 this.projectsettings.buttonPressed.connect((btn) => {
251 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
253 this.window_rooview.view.renderJS(true);
255 if (btn == "apply") {
256 this.window_rooview.view.renderJS(true);
260 // do nothing for gtk..
262 if (btn == "save" || btn == "apply") {
263 this.win.project.save();
266 this.switchState (State.PREVIEW);
271 // ----------- object adding
272 public void objectAddInit()
275 this.rightpalete = new Xcls_RightPalete();
276 this.rightpalete.ref(); /// really?
277 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
278 //this.projectsettings.el.show_all();
280 var stage = this.win.objectview.el.get_stage();
281 stage.set_background_color( Clutter.Color.from_string("#000"));
285 // ----------- properties adding list...
286 // listener uses the properties
287 public void propsAddInit()
290 this.add_props = new Xcls_WindowAddProp();
291 this.add_props.ref(); /// really?
292 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
293 //this.projectsettings.el.show_all();
295 var stage = this.win.addpropsview.el.get_stage();
296 stage.set_background_color( Clutter.Color.from_string("#000"));
299 this.add_props.select.connect( (key,type,skel, etype) => {
300 this.left_props.addProp(etype, key, skel, type);
304 public void propsAddShow()
308 public void propsAddHide()
316 // ----------- Add / Edit listener
317 // listener uses the properties
318 //public void listenerInit() { }
319 public void listenerShow()
323 public void listenerHide()
328 // -------------- codeEditor
330 public void codeEditInit()
332 this.code_editor = new Editor();
333 //this.code_editor.ref(); /// really?
334 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
336 this.code_editor.window = this.win;
337 //this.projectsettings.el.show_all();
339 var stage = this.win.codeeditview.el.get_stage();
340 stage.set_background_color( Clutter.Color.from_string("#000"));
343 this.code_editor.save.connect( () => {
344 this.left_tree.model.file.save();
345 this.left_tree.model.updateSelected();
350 // ----------- list of projects on left
351 public void projectListInit()
354 this.left_projects = new Xcls_WindowLeftProjects();
355 this.left_projects.ref();
356 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
357 this.left_projects.el.show_all();
358 this.left_projects.project_selected.connect((proj) => {
359 this.buttonsShowHide();
361 this.clutterfiles.loadProject(proj);
366 // ----------- file view
368 public void fileViewInit()
370 var stage = this.win.rooview.el.get_stage(); // seems odd...
371 this.clutterfiles = new Xcls_ClutterFiles();
372 this.clutterfiles.ref();
373 stage.add_child(this.clutterfiles.el);
374 this.clutterfiles.el.show_all();
377 this.clutterfiles.open.connect((file) => {
378 this.fileViewOpen(file);
380 this.clutterfiles.el.transitions_completed.connect(() => {
381 if (this.state == State.FILES) {
382 this.win.rooview.el.hide();
384 this.clutterfiles.el.hide();
392 public void fileDetailsInit()
394 this.file_details = new Xcls_PopoverFileDetails();
395 this.file_details.mainwindow = this.win;
396 // force it modal to the main window..
398 this.file_details.success.connect((project,file) =>
400 this.fileViewOpen(file);
405 public void fileViewOpen(JsRender.JsRender file)
407 this.win.project = file.project;
408 this.switchState (State.PREVIEW);
410 this.left_tree.model.loadFile(file);
412 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
413 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
415 if (file.xtype == "Roo" ) {
416 ctr.foreach( (w) => { ctr.remove(w); });
417 ctr_p.foreach( (w) => { ctr_p.remove(w); });
418 ctr.add(this.window_rooview.el);
419 ctr_p.add(this.projectsettings.el);
420 this.window_rooview.loadFile(file);
421 this.window_rooview.el.show_all();
422 this.projectsettings.el.show_all();
425 ctr.foreach( (w) => { ctr.remove(w); });
426 ctr_p.foreach( (w) => { ctr_p.remove(w); });
427 ctr.add(this.window_gladeview.el);
428 ctr_p.add(this.vala_projectsettings.el);
429 this.window_gladeview.loadFile(file);
430 this.window_gladeview.el.show_all();
431 this.vala_projectsettings.el.show_all();
433 print("OPEN : " + file.name);
434 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
435 this.win.setTitle(file.project.name + " : " +file.name);
441 // --------- webkit view
442 public void webkitViewInit()
444 this.window_rooview =new Xcls_WindowRooView();
445 this.window_rooview.ref();
446 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
447 this.window_rooview.el.show_all();
449 var stage = this.win.rooview.el.get_stage();
450 stage.set_background_color( Clutter.Color.from_string("#000"));
455 public void gtkViewInit()
457 this.window_gladeview =new Xcls_GtkView();
458 this.window_gladeview.ref();
459 this.window_gladeview.main_window = this.win;
462 public void easingSaveAll()
464 this.win.addpropsview.el.save_easing_state();
465 this.win.codeeditview.el.save_easing_state();
466 this.win.objectview.el.save_easing_state();
467 this.win.projecteditview.el.save_easing_state();
468 this.win.rooview.el.save_easing_state();
469 this.clutterfiles.el.save_easing_state();
472 public void easingRestoreAll()
474 this.win.addpropsview.el.restore_easing_state();
475 this.win.codeeditview.el.restore_easing_state();
476 this.win.objectview.el.restore_easing_state();
477 this.win.projecteditview.el.restore_easing_state();
478 this.win.rooview.el.restore_easing_state();
479 this.clutterfiles.el.restore_easing_state();
482 public void switchState(State new_state)
485 // save the easing state of everything..
486 this.easingSaveAll();
488 switch (this.state) {
491 if (this.left_tree.getActiveFile() != null) {
492 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
493 this.window_rooview.createThumb();
495 this.window_gladeview.createThumb();
498 // normally we are going from preview to another state.
499 // and different windows hide the preview in differnt ways..
506 this.win.addpropsview.el.set_scale(0.0f,0.0f);
512 this.code_editor.saveContents();
514 this.win.codeeditview.el.set_scale(0.0f,0.0f);
520 this.win.objectview.el.set_scale(0.0f,0.0f);
524 if (this.win.project.xtype == "Gtk") {
525 this.vala_projectsettings.save();
528 this.win.projecteditview.el.set_scale(0.0f,0.0f);
534 this.win.rooview.el.show_all();
535 this.win.rooview.el.set_easing_duration(1000);
536 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
537 this.win.rooview.el.set_scale(1.0f,1.0f);
538 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
539 this.win.rooview.el.set_opacity(0xff);
543 this.clutterfiles.el.set_easing_duration(1000);
544 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
545 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
546 this.clutterfiles.el.set_opacity(0);
548 //this.clutterfiles.el.hide();
556 var oldstate =this.state;
557 this.state = new_state;
561 this.buttonsShowHide();
564 switch (this.state) {
566 case State.PREVIEW: // this is the default state when working...
567 this.win.editpane.el.show(); // holder for tree and properties..
570 this.left_projects.el.hide();
571 if (oldstate != State.FILES) {
572 // it's handled above..
573 print ("changing state to preview from NOT files..");
576 this.win.rooview.el.set_scale(1.0f,1.0f);
585 var ae = this.left_tree.getActiveElement();
587 this.state = oldstate;
588 this.buttonsShowHide();
589 this.resizeCanvasElements();
590 this.easingRestoreAll();
593 this.add_props.el.show_all();
595 Palete.factory(this.win.project.xtype),
596 this.state == State.LISTENER ? "signals" : "props",
603 // -- FIXME? this needs to be State aware?
605 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
607 this.win.addpropsview.el.set_scale(1.0f,1.0f);
611 var n = this.left_tree.getActiveElement();
613 if (this.left_tree.model.file == null) {
614 this.state =oldstate;
615 this.buttonsShowHide();
616 this.resizeCanvasElements();
617 this.easingRestoreAll();
621 if (n == null && this.left_tree.model.file.tree != null) {
622 this.state = oldstate;
623 this.buttonsShowHide();
624 this.resizeCanvasElements();
625 this.easingRestoreAll();
629 this.rightpalete.el.show_all();
630 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
635 this.win.objectview.el.set_scale(1.0f,1.0f);
642 this.code_editor.el.show_all();
644 // caller needs to call editor - show....
647 this.win.codeeditview.el.set_scale(1.0f,1.0f);
654 if (this.win.project.xtype == "Roo") {
655 this.projectsettings.el.show_all();
656 this.projectsettings.show(this.win.project);
658 this.vala_projectsettings.el.show_all();
659 this.vala_projectsettings.show((Project.Gtk)this.win.project);
662 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
664 this.win.projecteditview.el.set_scale(1.0f,1.0f);
669 case State.FILES: // can only get here from PREVIEW state.. in theory..
672 this.win.editpane.el.hide(); // holder for tree and properties..
674 this.left_projects.el.show();
676 this.win.rooview.el.set_easing_duration(1000);
677 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
678 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
679 this.win.rooview.el.set_opacity(0);
680 //el.set_scale(0.0f,0.0f);
683 if (this.win.project != null) {
684 this.left_projects.selectProject(this.win.project);
688 this.clutterfiles.el.show_all();
690 this.clutterfiles.el.set_easing_duration(1000);
691 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
692 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
693 this.clutterfiles.el.set_opacity(0xff);
701 this.resizeCanvasElements();
702 this.easingRestoreAll();
707 public int redraw_count = 0;
708 public void resizeCanvas() // called by window resize .. delays redraw
710 var rc = this.redraw_count;
711 this.redraw_count = 2;
713 GLib.Timeout.add(100, () =>{
714 return this.resizeCanvasQueue();
718 public bool resizeCanvasQueue()
720 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);
722 if (this.redraw_count < 1) {
723 return false; // should not really happen...
729 if (this.redraw_count > 0) {
730 return true; // do it again in 1 second...
732 // got down to 0 or -1....
733 this.redraw_count = 0;
734 this.resizeCanvasElements();
738 public void resizeCanvasElements()
740 Gtk.Allocation alloc;
741 this.win.clutterembed.el.get_allocation(out alloc);
743 // print("WindowState.resizeCanvasElements\n");
744 if (!this.children_loaded || this.win.clutterembed == null) {
745 print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
749 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
750 var palsize = avail < 300.0f ? avail : 300.0f;
753 // -------- code edit min 600
755 var codesize = avail < 800.0f ? avail : 800.0f;
758 //print("set code size %f\n", codesize);
762 switch ( this.state) {
764 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
768 this.clutterfiles.set_size(alloc.width-50, alloc.height);
773 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
775 // this.win.rooview.el.save_easing_state();
776 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
777 this.win.rooview.el.set_scale(0.5f, 0.5f);
778 //this.win.rooview.el.restore_easing_state();
782 this.win.codeeditview.el.set_size(codesize, alloc.height);
783 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
784 //this.win.rooview.el.save_easing_state();
786 this.win.rooview.el.set_scale(scale,scale);
787 // this.win.rooview.el.restore_easing_state();
792 this.win.addpropsview.el.set_size(palsize, alloc.height);
793 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
794 this.win.rooview.el.set_scale(scale,scale);
798 this.win.objectview.el.set_size(palsize, alloc.height);
799 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
800 //this.win.rooview.el.save_easing_state();
801 this.win.rooview.el.set_scale(scale,scale);
802 // this.win.rooview.el.restore_easing_state();
807 // -- buttons show hide.....
809 public void buttonsShowHide()
811 // basically hide everything, then show the relivant..
813 this.win.backbutton.el.hide();
815 this.win.projectbutton.el.hide(); // show file nav...
816 this.win.editfilebutton.el.hide();
817 this.win.projecteditbutton.el.hide();
820 this.win.objectshowbutton.el.hide(); // add objects
821 this.win.addpropbutton.el.hide();
822 this.win.addlistenerbutton.el.hide();
826 this.win.addprojectbutton.el.hide();
827 this.win.addfilebutton.el.hide();
828 this.win.delprojectbutton.el.hide();
831 switch (this.state) {
833 case State.PREVIEW: // this is the default state when working...
835 this.win.projectbutton.el.show(); // show file nav...
836 this.win.editfilebutton.el.show();
837 this.win.projecteditbutton.el.show();
840 this.win.objectshowbutton.el.show(); // add objects
841 this.win.addpropbutton.el.show();
842 this.win.addlistenerbutton.el.show();
851 this.win.backbutton.el.show();
852 this.win.objectshowbutton.el.show(); // add objects
853 this.win.addpropbutton.el.show();
854 this.win.addlistenerbutton.el.show();
859 this.win.backbutton.el.show();
864 if (this.left_projects.getSelectedProject() != null ) {
865 if (this.left_tree.getActiveFile() != null) {
866 this.win.backbutton.el.show();
868 this.win.addfilebutton.el.show();
871 this.win.addprojectbutton.el.show();
872 this.win.delprojectbutton.el.show();