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;
380 this.switchState (State.PREVIEW);
382 this.left_tree.model.loadFile(file);
384 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
385 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
387 if (file.xtype == "Roo" ) {
388 ctr.foreach( (w) => { ctr.remove(w); });
389 ctr_p.foreach( (w) => { ctr_p.remove(w); });
390 ctr.add(this.window_rooview.el);
391 ctr_p.add(this.projectsettings.el);
392 this.window_rooview.loadFile(file);
393 this.window_rooview.el.show_all();
394 this.projectsettings.el.show_all();
397 ctr.foreach( (w) => { ctr.remove(w); });
398 ctr_p.foreach( (w) => { ctr_p.remove(w); });
399 ctr.add(this.window_gladeview.el);
400 ctr_p.add(this.vala_projectsettings.el);
401 this.window_gladeview.loadFile(file);
402 this.window_gladeview.el.show_all();
403 this.vala_projectsettings.el.show_all();
405 print("OPEN : " + file.name);
406 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
407 this.win.setTitle(file.project.name + " : " +file.name);
413 // --------- webkit view
414 public void webkitViewInit()
416 this.window_rooview =new Xcls_WindowRooView();
417 this.window_rooview.ref();
418 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
419 this.window_rooview.el.show_all();
421 var stage = this.win.rooview.el.get_stage();
422 stage.set_background_color( Clutter.Color.from_string("#000"));
427 public void gtkViewInit()
429 this.window_gladeview =new Xcls_GtkView();
430 this.window_gladeview.ref();
433 public void switchState(State new_state)
438 switch (this.state) {
441 if (this.left_tree.getActiveFile() != null) {
442 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
443 this.window_rooview.createThumb();
445 this.window_gladeview.createThumb();
448 // normally we are going from preview to another state.
449 // and different windows hide the preview in differnt ways..
455 this.win.addpropsview.el.save_easing_state();
456 this.win.addpropsview.el.set_scale(0.0f,0.0f);
457 this.win.addpropsview.el.restore_easing_state();
463 this.code_editor.saveContents();
464 this.win.codeeditview.el.save_easing_state();
465 this.win.codeeditview.el.set_scale(0.0f,0.0f);
466 this.win.codeeditview.el.restore_easing_state();
471 this.win.objectview.el.save_easing_state();
472 this.win.objectview.el.set_scale(0.0f,0.0f);
473 this.win.objectview.el.restore_easing_state();
477 this.win.projecteditview.el.save_easing_state();
478 this.win.projecteditview.el.set_scale(0.0f,0.0f);
479 this.win.projecteditview.el.restore_easing_state();
483 this.win.rooview.el.save_easing_state();
484 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
485 this.win.rooview.el.set_scale(1.0f,1.0f);
486 this.win.rooview.el.restore_easing_state();
488 this.win.clutterfiles.el.hide();
494 var oldstate =this.state;
495 this.state = new_state;
498 this.buttonsShowHide();
500 switch (this.state) {
502 case State.PREVIEW: // this is the default state when working...
503 this.win.rooview.el.save_easing_state();
504 this.win.rooview.el.set_scale(1.0f,1.0f);
505 this.win.rooview.el.restore_easing_state();
512 var ae = this.left_tree.getActiveElement();
514 this.state = oldstate;
515 this.buttonsShowHide();
518 this.add_props.el.show_all();
520 Palete.factory(this.win.project.xtype),
521 this.state == State.LISTENER ? "signals" : "props",
527 this.win.rooview.el.save_easing_state();
528 // -- FIXME? this needs to be State aware?
529 this.resizeCanvasElementsA();
530 this.win.rooview.el.restore_easing_state();
533 this.win.addpropsview.el.save_easing_state();
534 this.win.addpropsview.el.set_scale(1.0f,1.0f);
535 this.win.addpropsview.el.restore_easing_state();
540 this.code_editor.el.show_all();
542 // caller needs to call editor - show....
543 this.win.rooview.el.save_easing_state();
544 this.resizeCanvasElementsA();
545 this.win.rooview.el.restore_easing_state();
548 this.win.codeeditview.el.save_easing_state();
549 this.win.codeeditview.el.set_scale(1.0f,1.0f);
550 this.win.codeeditview.el.restore_easing_state();
555 var n = this.left_tree.getActiveElement();
557 if (this.left_tree.model.file == null) {
558 this.state =oldstate;
559 this.buttonsShowHide();
563 if (n == null && this.left_tree.model.file.tree != null) {
564 this.state = oldstate;
565 this.buttonsShowHide();
569 this.rightpalete.el.show_all();
570 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
572 this.win.rooview.el.save_easing_state();
573 this.resizeCanvasElementsA();
574 this.win.rooview.el.restore_easing_state();
577 this.win.objectview.el.save_easing_state();
578 this.win.objectview.el.set_scale(1.0f,1.0f);
579 this.win.objectview.el.restore_easing_state();
584 if (this.win.project.xtype == "Roo") {
585 this.projectsettings.el.show_all();
586 this.projectsettings.show(this.win.project);
588 this.vala_projectsettings.el.show_all();
589 this.vala_projectsettings.show((Project.Gtk)this.win.project);
592 this.win.rooview.el.save_easing_state();
593 this.resizeCanvasElementsA();
594 this.win.rooview.el.restore_easing_state();
596 this.win.projecteditview.el.save_easing_state();
597 this.win.projecteditview.el.set_scale(0.0f,0.0f);
598 this.win.projecteditview.el.restore_easing_state();
601 case State.FILES: // can only get here from PREVIEW state.. in theory..
604 this.win.editpane.el.hide(); // holder for tree and properties..
606 this.left_projects.el.show();
608 var el = this.win.rooview.el;
609 el.save_easing_state();
610 el.set_easing_duration(1000);
612 el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 360.0f);
613 el.set_scale(0.0f,0.0f);
616 if (this.win.project != null) {
617 this.left_projects.selectProject(this.win.project);
620 el.restore_easing_state();
630 // -- buttons show hide.....
632 public void buttonsShowHide()
634 // basically hide everything, then show the relivant..
636 this.win.backbutton.el.hide();
638 this.win.projectbutton.el.hide(); // show file nav...
639 this.win.editfilebutton.el.hide();
640 this.win.projecteditbutton.el.hide();
643 this.win.objectshowbutton.el.hide(); // add objects
644 this.win.addpropbutton.el.hide();
645 this.win.addlistenerbutton.el.hide();
649 this.win.addprojectbutton.el.hide();
650 this.win.addfilebutton.el.hide();
651 this.win.delprojectbutton.el.hide();
652 this.win.new_window.el.hide();
655 switch (this.state) {
657 case State.PREVIEW: // this is the default state when working...
659 this.win.projectbutton.el.show(); // show file nav...
660 this.win.editfilebutton.el.show();
661 this.win.projecteditbutton.el.show();
664 this.win.objectshowbutton.el.show(); // add objects
665 this.win.addpropbutton.el.show();
666 this.win.addlistenerbutton.el.show();
675 this.win.backbutton.el.show();
676 this.win.objectshowbutton.el.show(); // add objects
677 this.win.addpropbutton.el.show();
678 this.win.addlistenerbutton.el.show();
682 this.win.backbutton.el.show();
684 this.win.addprojectbutton.el.show();
685 this.win.addfilebutton.el.show();
686 this.win.delprojectbutton.el.show();
687 this.win.new_window.el.show();
692 public void resizeCanvasElementsA()
694 Gtk.Allocation alloc;
695 this.win.clutterembed.el.get_allocation(out alloc);
696 this.resizeCanvasElements(alloc);
698 public void resizeCanvasElements(Gtk.Allocation alloc)
700 if (!this.children_loaded) {
704 this.win.clutterfiles.set_size(alloc.width-50, alloc.height);
706 // ------- project view appears at top...
707 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
709 // ------- add property/object left - max 300px, min 50... (or disapear..)
711 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
712 var palsize = avail < 300.0f ? avail : 300.0f;
713 //print("set palsize size %f\n", palsize);
714 // palate / props : fixed 300 pix
716 this.win.objectview.el.set_size(palsize, alloc.height);
717 this.win.addpropsview.el.set_size(palsize, alloc.height);
721 // -------- code edit min 600
723 var codesize = avail < 800.0f ? avail : 800.0f;
724 //print("set code size %f\n", codesize);
726 this.win.codeeditview.el.set_size(codesize, alloc.height);
727 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
731 switch ( this.state) {
733 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
734 this.win.rooview.el.set_scale(scale,scale);
740 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
741 this.win.rooview.el.set_scale(scale,scale);