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;
19 PROJECT // project settings..
24 public bool children_loaded = false;
27 public Xcls_WindowLeftTree left_tree;
28 public Xcls_WindowAddProp add_props;
29 public Xcls_LeftProps left_props;
30 public Xcls_ProjectSettings projectsettings;
31 public ValaProjectSettings vala_projectsettings;
32 public Xcls_RightPalete rightpalete;
33 public Editor code_editor;
34 public Xcls_WindowRooView window_rooview;
35 public Xcls_GtkView window_gladeview;
36 public Xcls_DialogNewComponent new_file_dialog;
37 public Xcls_ClutterFiles clutterfiles;
39 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
41 public WindowState(Xcls_MainWindow win)
50 // on clutter space...
51 this.projectEditInit();
53 this.projectListInit();
63 this.webkitViewInit();
69 this.children_loaded = true;
75 public void leftTreeInit()
78 this.left_tree = new Xcls_WindowLeftTree();
80 this.left_tree.main_window = this.win;
82 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
83 this.left_tree.el.show_all();
85 this.left_tree.before_node_change.connect(() => {
86 return this.leftTreeBeforeChange();
90 this.left_tree.node_selected.connect((sel) => {
91 this.leftTreeNodeSelected(sel);
94 this.left_tree.changed.connect(() => {
95 this.window_rooview.requestRedraw();
96 this.left_tree.model.file.save();
101 public bool leftTreeBeforeChange()
103 if (this.state != State.CODE) {
104 this.left_props.finish_editing();
107 if (!this.code_editor.saveContents()) {
113 public void leftTreeNodeSelected(JsRender.Node? sel)
116 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
119 this.left_props.el.hide();
121 this.left_props.el.show();
122 this.left_props.load(this.left_tree.getActiveFile(), sel);
123 switch (this.state) {
128 this.rightpalete.clear();
131 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
137 this.add_props.clear();
140 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
146 this.add_props.clear();
149 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
153 this.switchState(State.PREVIEW);
166 public void propsListInit()
169 this.left_props =new Xcls_LeftProps();
170 this.left_props.ref();
171 this.left_props.main_window = this.win;
172 this.win.props.el.pack_start(this.left_props.el,true, true,0);
173 this.left_props.el.show_all();
175 this.left_props.show_editor.connect( (file, node, type, key) => {
176 this.switchState(State.CODE);
177 this.code_editor.show(
188 this.left_props.stop_editor.connect( () => {
189 if (this.state != State.CODE) {
193 var ret = this.code_editor.saveContents();
197 this.switchState(State.PREVIEW);
201 this.left_props.changed.connect(() => {
202 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
203 this.win.window_rooview.requestRedraw();
206 this.win.window_gladeview.loadFile(this.left_tree.getActiveFile());
208 this.left_tree.model.updateSelected();
209 this.left_tree.model.file.save();
216 //------------- projects edit
218 public void projectEditInit()
220 this.projectsettings =new Xcls_ProjectSettings();
221 this.projectsettings.ref(); /// really?
223 this.vala_projectsettings =new ValaProjectSettings();
224 this.vala_projectsettings.ref();
225 this.vala_projectsettings.window = this.win;
227 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
228 //this.projectsettings.el.show_all();
230 var stage = this.win.projecteditview.el.get_stage();
231 stage.set_background_color( Clutter.Color.from_string("#000"));
233 this.projectsettings.buttonPressed.connect((btn) => {
234 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
236 this.window_rooview.view.renderJS(true);
238 if (btn == "apply") {
239 this.window_rooview.view.renderJS(true);
243 // do nothing for gtk..
245 if (btn == "save" || btn == "apply") {
246 this.win.project.save();
249 this.switchState (State.PREVIEW);
254 // ----------- object adding
255 public void objectAddInit()
258 this.rightpalete = new Xcls_RightPalete();
259 this.rightpalete.ref(); /// really?
260 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
261 //this.projectsettings.el.show_all();
263 stage = _this.win.objectview.el.get_stage();
264 stage.set_background_color( Clutter.Color.from_string("#000"));
268 // ----------- properties adding list...
269 // listener uses the properties
270 public void propsAddInit()
273 this.add_props = new Xcls_WindowAddProp();
274 this.add_props.ref(); /// really?
275 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
276 //this.projectsettings.el.show_all();
278 var stage = _this.win.addpropsview.el.get_stage();
279 stage.set_background_color( Clutter.Color.from_string("#000"));
282 this.add_props.select.connect( (key,type,skel, etype) => {
283 this.left_props.addProp(etype, key, skel, type);
287 public void propsAddShow()
291 public void propsAddHide()
299 // ----------- Add / Edit listener
300 // listener uses the properties
301 //public void listenerInit() { }
302 public void listenerShow()
306 public void listenerHide()
311 // -------------- codeEditor
313 public void codeEditInit()
315 this.code_editor = new Editor();
316 this.code_editor.ref(); /// really?
317 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
318 //this.projectsettings.el.show_all();
320 var stage = _this.win.codeeditview.el.get_stage();
321 stage.set_background_color( Clutter.Color.from_string("#000"));
324 this.code_editor.save.connect( () => {
325 this.left_tree.model.file.save();
326 this.left_tree.model.updateSelected();
331 // ----------- list of projects on left
332 public void projectListInit()
335 this.left_projects = new Xcls_WindowLeftProjects();
336 this.left_projects.ref();
337 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
338 this.left_projects.el.show_all();
339 this.left_projects.project_selected.connect((proj) => {
341 this.clutterfiles.loadProject(proj);
346 // ----------- file view
348 public void fileViewInit()
350 var stage = this.win.rooview.el.get_stage(); // seems odd...
351 this.clutterfiles = new Xcls_ClutterFiles();
352 this.clutterfiles.ref();
353 stage.add_child(this.clutterfiles.el);
354 this.clutterfiles.el.show_all();
357 this.clutterfiles.open.connect((file) => {
358 this.fileViewOpen(file);
362 public void fileNewInit()
364 this.new_file_dialog = new Xcls_DialogNewComponent();
365 // force it modal to the main window..
366 this.new_file_dialog.el.set_transient_for(this.win.el);
367 this.new_file_dialog.el.set_modal(true);
369 this.new_file_dialog.success.connect((project,file) =>
371 this.fileViewOpen(file);
377 public void fileViewOpen(JsRender.JsRender file)
379 this.win.project = file.project;
381 this.left_tree.model.loadFile(file);
383 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
384 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
386 if (file.xtype == "Roo" ) {
387 ctr.foreach( (w) => { ctr.remove(w); });
388 ctr_p.foreach( (w) => { ctr_p.remove(w); });
389 ctr.add(this.window_rooview.el);
390 ctr_p.add(this.projectsettings.el);
391 this.window_rooview.loadFile(file);
392 this.window_rooview.el.show_all();
393 this.projectsettings.el.show_all();
396 ctr.foreach( (w) => { ctr.remove(w); });
397 ctr_p.foreach( (w) => { ctr_p.remove(w); });
398 ctr.add(this.window_gladeview.el);
399 ctr_p.add(this.vala_projectsettings.el);
400 this.window_gladeview.loadFile(file);
401 this.window_gladeview.el.show_all();
402 this.vala_projectsettings.el.show_all();
404 print("OPEN : " + file.name);
405 this.editpane.el.set_position(_this.editpane.el.max_position);
406 this.win.setTitle(file.project.name + " : " +file.name);
412 // --------- webkit view
413 public void webkitViewInit()
415 this.window_rooview =new Xcls_WindowRooView();
416 this.window_rooview.ref();
417 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
418 this.window_rooview.el.show_all();
420 stage = this.win.rooview.el.get_stage();
421 stage.set_background_color( Clutter.Color.from_string("#000"));
426 public void gtkViewInit()
428 this.window_gladeview =new Xcls_GtkView();
429 this.window_gladeview.ref();
432 public void switchState(State new_state)
437 switch (this.state) {
440 if (this.left_tree.getActiveFile() != null) {
441 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
442 this.window_rooview.createThumb();
444 this.window_gladeview.createThumb();
447 // normally we are going from preview to another state.
448 // and different windows hide the preview in differnt ways..
454 this.win.addpropsview.el.save_easing_state();
455 this.win.addpropsview.el.set_scale(0.0f,0.0f);
456 this.win.addpropsview.el.restore_easing_state();
462 this.code_editor.saveContents();
463 this.win.codeeditview.el.save_easing_state();
464 this.win.codeeditview.el.set_scale(0.0f,0.0f);
465 this.win.codeeditview.el.restore_easing_state();
470 this.win.objectview.el.save_easing_state();
471 this.win.objectview.el.set_scale(0.0f,0.0f);
472 this.win.objectview.el.restore_easing_state();
476 this.win.projecteditview.el.save_easing_state();
477 this.win.projecteditview.el.set_scale(0.0f,0.0f);
478 this.win.projecteditview.el.restore_easing_state();
482 this.win.rooview.el.save_easing_state();
483 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
484 this.win.rooview.el.set_scale(1.0f,1.0f);
485 this.win.rooview.el.restore_easing_state();
487 this.win.clutterfiles.el.hide();
493 var oldstate =this.state;
494 this.state = new_state;
497 this.buttonsShowHide();
499 switch (this.state) {
501 case State.PREVIEW: // this is the default state when working...
502 this.win.rooview.el.save_easing_state();
503 this.win.rooview.el.set_scale(1.0f,1.0f);
504 this.win.rooview.el.restore_easing_state();
511 var ae = this.left_tree.getActiveElement();
513 this.state = oldstate;
514 this.buttonsShowHide();
517 this.add_props.el.show_all();
519 Palete.factory(this.win.project.xtype),
520 this.state == State.LISTENER ? "signals" : "props",
526 this.win.rooview.el.save_easing_state();
527 // -- FIXME? this needs to be State aware?
528 this.resizeCanvasElementsA();
529 this.win.rooview.el.restore_easing_state();
532 this.win.addpropsview.el.save_easing_state();
533 this.win.addpropsview.el.set_scale(1.0f,1.0f);
534 this.win.addpropsview.el.restore_easing_state();
539 this.code_editor.el.show_all();
541 // caller needs to call editor - show....
542 this.win.rooview.el.save_easing_state();
543 this.resizeCanvasElementsA();
544 this.win.rooview.el.restore_easing_state();
547 this.win.codeeditview.el.save_easing_state();
548 this.win.codeeditview.el.set_scale(1.0f,1.0f);
549 this.win.codeeditview.el.restore_easing_state();
554 var n = this.left_tree.getActiveElement();
556 if (this.left_tree.model.file == null) {
557 this.state =oldstate;
558 this.buttonsShowHide();
562 if (n == null && this.left_tree.model.file.tree != null) {
563 this.state = oldstate;
564 this.buttonsShowHide();
568 this.rightpalete.el.show_all();
569 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
571 this.win.rooview.el.save_easing_state();
572 this.resizeCanvasElementsA();
573 this.win.rooview.el.restore_easing_state();
576 this.win.objectview.el.save_easing_state();
577 this.win.objectview.el.set_scale(1.0f,1.0f);
578 this.win.objectview.el.restore_easing_state();
583 if (this.win.project.xtype == "Roo") {
584 this.projectsettings.el.show_all();
585 this.projectsettings.show(this.win.project);
587 this.vala_projectsettings.el.show_all();
588 this.vala_projectsettings.show((Project.Gtk)this.win.project);
591 this.win.rooview.el.save_easing_state();
592 this.resizeCanvasElementsA();
593 this.win.rooview.el.restore_easing_state();
595 this.win.projecteditview.el.save_easing_state();
596 this.win.projecteditview.el.set_scale(0.0f,0.0f);
597 this.win.projecteditview.el.restore_easing_state();
600 case State.FILES: // can only get here from PREVIEW state.. in theory..
603 this.win.editpane.el.hide(); // holder for tree and properties..
605 this.left_projects.el.show();
607 var el = this.win.rooview.el;
608 el.save_easing_state();
609 el.set_easing_duration(1000);
611 el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 360.0f);
612 el.set_scale(0.0f,0.0f);
615 if (this.win.project != null) {
616 this.left_projects.selectProject(this.win.project);
619 el.restore_easing_state();
629 // -- buttons show hide.....
631 public void buttonsShowHide()
633 // basically hide everything, then show the relivant..
635 this.win.backbutton.el.hide();
637 this.win.projectbutton.el.hide(); // show file nav...
638 this.win.editfilebutton.el.hide();
639 this.win.projecteditbutton.el.hide();
642 this.win.objectshowbutton.el.hide(); // add objects
643 this.win.addpropbutton.el.hide();
644 this.win.addlistenerbutton.el.hide();
648 this.win.addprojectbutton.el.hide();
649 this.win.addfilebutton.el.hide();
650 this.win.delprojectbutton.el.hide();
651 this.win.new_window.el.hide();
654 switch (this.state) {
656 case State.PREVIEW: // this is the default state when working...
658 this.win.projectbutton.el.show(); // show file nav...
659 this.win.editfilebutton.el.show();
660 this.win.projecteditbutton.el.show();
663 this.win.objectshowbutton.el.show(); // add objects
664 this.win.addpropbutton.el.show();
665 this.win.addlistenerbutton.el.show();
674 this.win.backbutton.el.show();
675 this.win.objectshowbutton.el.show(); // add objects
676 this.win.addpropbutton.el.show();
677 this.win.addlistenerbutton.el.show();
681 this.win.backbutton.el.show();
683 this.win.addprojectbutton.el.show();
684 this.win.addfilebutton.el.show();
685 this.win.delprojectbutton.el.show();
686 this.win.new_window.el.show();
691 public void resizeCanvasElementsA()
693 Gtk.Allocation alloc;
694 this.win.clutterembed.el.get_allocation(out alloc);
695 this.resizeCanvasElements(alloc);
697 public void resizeCanvasElements(Gtk.Allocation alloc)
699 if (!this.children_loaded) {
703 this.win.clutterfiles.set_size(alloc.width-50, alloc.height);
705 // ------- project view appears at top...
706 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
708 // ------- add property/object left - max 300px, min 50... (or disapear..)
710 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
711 var palsize = avail < 300.0f ? avail : 300.0f;
712 //print("set palsize size %f\n", palsize);
713 // palate / props : fixed 300 pix
715 this.win.objectview.el.set_size(palsize, alloc.height);
716 this.win.addpropsview.el.set_size(palsize, alloc.height);
720 // -------- code edit min 600
722 var codesize = avail < 800.0f ? avail : 800.0f;
723 //print("set code size %f\n", codesize);
725 this.win.codeeditview.el.set_size(codesize, alloc.height);
726 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
730 switch ( this.state) {
732 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
733 this.win.rooview.el.set_scale(scale,scale);
739 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
740 this.win.rooview.el.set_scale(scale,scale);