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 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;
38 public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
40 public WindowState(MainWindow win)
49 // on clutter space...
50 this.projectEditInit();
52 this.projectListInit();)
62 this.webkitViewInit();
68 this.children_loaded = true;
74 public void leftTreeInit()
77 this.left_tree = new Xcls_WindowLeftTree();
79 this.left_tree.main_window = _this.win;
81 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
82 this.left_tree.el.show_all();
84 this.left_tree.before_node_change.connect(() => {
85 return this.leftTreeBeforeChange();
89 this.left_tree.node_selected.connect((sel) => {
90 this.leftTreeNodeSelected(sel);
93 this.left_tree.changed.connect(() => {
94 this.window_rooview.requestRedraw();
95 this.left_tree.model.file.save();
100 public bool leftTreeBeforeChange(JsRender.Node? sel)
102 if (this.state != "codeedit") {
103 this.left_props.finish_editing();
106 if (!this.code_editor.saveContents()) {
112 public void leftTreeNodeSelected(JsRender.Node? sel)
115 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
118 this.left_props.el.hide();
120 this.left_props.el.show();
121 this.left_props.load(this.left_tree.getActiveFile(), sel);
122 switch (this.state) {
127 this.rightpalete.clear();
130 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
136 this.add_props.clear();
139 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
145 this.add_props.clear();
148 this.add_props.show(_this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
166 public void propsListInit()
169 this.left_props =new Xcls_LeftProps();
170 this.left_props.ref();
171 this.left_props.main_window = _this;
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.codeEditShow(file, node, type, key);
180 this.left_props.stop_editor.connect( () => {
181 if (this.state != "codeedit") {
185 var ret = this.code_editor.saveContents();
193 this.left_props.changed.connect(() => {
194 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
195 this.window_rooview.requestRedraw();
198 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
200 this.left_tree.model.updateSelected();
201 this.left_tree.model.file.save();
208 //------------- projects edit
210 public void projectEditInit()
212 this.projectsettings =new Xcls_ProjectSettings();
213 this.projectsettings.ref(); /// really?
215 this.vala_projectsettings =new ValaProjectSettings();
216 this.vala_projectsettings.ref();
217 this.vala_projectsettings.window = this;
219 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
220 //this.projectsettings.el.show_all();
222 var stage = this.win.projecteditview.el.get_stage();
223 stage.set_background_color( Clutter.Color.from_string("#000"));
225 this.projectsettings.buttonPressed.connect((btn) => {
226 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
228 this.window_rooview.view.renderJS(true);
230 if (btn == "apply") {
231 this.window_rooview.view.renderJS(true);
235 // do nothing for gtk..
237 if (btn == "save" || btn == "apply") {
238 this.win.project.save();
242 this.projectEditHide();
247 // ----------- object adding
248 public void objectAddInit()
251 this.rightpalete = new Xcls_RightPalete();
252 this.rightpalete.ref(); /// really?
253 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
254 //this.projectsettings.el.show_all();
256 stage = _this.win.objectview.el.get_stage();
257 stage.set_background_color( Clutter.Color.from_string("#000"));
261 // ----------- properties adding list...
262 // listener uses the properties
263 public void propsAddInit()
266 this.add_props = new Xcls_WindowAddProp();
267 this.add_props.ref(); /// really?
268 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
269 //this.projectsettings.el.show_all();
271 var stage = _this.win.addpropsview.el.get_stage();
272 stage.set_background_color( Clutter.Color.from_string("#000"));
275 this.add_props.select.connect( (key,type,skel, etype) => {
276 this.left_props.addProp(etype, key, skel, type);
280 public void propsAddShow()
284 public void propsAddHide()
292 // ----------- Add / Edit listener
293 // listener uses the properties
294 //public void listenerInit() { }
295 public void listenerShow()
299 public void listenerHide()
304 // -------------- codeEditor
306 public void codeEditInit()
308 this.code_editor = new Editor();
309 this.code_editor.ref(); /// really?
310 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
311 //this.projectsettings.el.show_all();
313 stage = _this.win.codeeditview.el.get_stage();
314 stage.set_background_color( Clutter.Color.from_string("#000"));
317 this.code_editor.save.connect( () => {
318 this.left_tree.model.file.save();
319 this.left_tree.model.updateSelected();
324 // ----------- list of projects on left
325 public void projectListInit()
328 this.left_projects = new Xcls_WindowLeftProjects();
329 this.left_projects.ref();
330 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
331 this.left_projects.el.show_all();
332 this.left_projects.project_selected.connect((proj) => {
334 this.clutterfiles.loadProject(proj);
339 // ----------- file view
341 public void fileViewInit()
343 stage = _this.rooview.el.get_stage(); \\ seems odd...
344 this.clutterfiles = new Xcls_ClutterFiles();
345 this.clutterfiles.ref();
346 stage.add_child(this.clutterfiles.el);
347 this.clutterfiles.el.show_all();
350 this.clutterfiles.open.connect((file) => {
351 this.fileViewOpen(file);
355 public void fileNewInit()
357 this.new_file_dialog = new Xcls_DialogNewComponent();
358 // force it modal to the main window..
359 this.new_file_dialog.el.set_transient_for(this.el);
360 this.new_file_dialog.el.set_modal(true);
362 this.new_file_dialog.success.connect((project,file) =>
364 this.fileViewOpen(file);
370 public void fileViewOpen(JsRender.JsRender file)
372 this.win.project = file.project;
374 this.left_tree.model.loadFile(file);
376 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
377 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
379 if (file.xtype == "Roo" ) {
380 ctr.foreach( (w) => { ctr.remove(w); });
381 ctr_p.foreach( (w) => { ctr_p.remove(w); });
382 ctr.add(this.window_rooview.el);
383 ctr_p.add(this.projectsettings.el);
384 this.window_rooview.loadFile(file);
385 this.window_rooview.el.show_all();
386 this.projectsettings.el.show_all();
389 ctr.foreach( (w) => { ctr.remove(w); });
390 ctr_p.foreach( (w) => { ctr_p.remove(w); });
391 ctr.add(this.window_gladeview.el);
392 ctr_p.add(this.vala_projectsettings.el);
393 this.window_gladeview.loadFile(file);
394 this.window_gladeview.el.show_all();
395 this.vala_projectsettings.el.show_all();
397 print("OPEN : " + file.name);
398 this.editpane.el.set_position(_this.editpane.el.max_position);
399 this.win.setTitle(file.project.name + " : " +file.name);
405 // --------- webkit view
406 public void webkitViewInit()
408 this.window_rooview =new Xcls_WindowRooView();
409 this.window_rooview.ref();
410 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
411 this.window_rooview.el.show_all();
413 stage = this.win.rooview.el.get_stage();
414 stage.set_background_color( Clutter.Color.from_string("#000"));
419 public void gtkViewInit()
421 this.window_gladeview =new Xcls_GtkView();
422 this.window_gladeview.ref();
425 public void switchState(State new_state)
427 if (this.state == State.PREVIEW) {
428 // try and do a snapshot..
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();
460 this.win.codeeditview.el.save_easing_state();
461 this.win.codeeditview.el.set_scale(0.0f,0.0f);
462 this.win.codeeditview.el.restore_easing_state();
467 this.win.objectview.el.save_easing_state();
468 this.win.objectview.el.set_scale(0.0f,0.0f);
469 this.win.objectview.el.restore_easing_state();
473 this.win.projecteditview.el.save_easing_state();
474 this.win.projecteditview.el.set_scale(0.0f,0.0f);
475 this.win.projecteditview.el.restore_easing_state();
479 this.win.rooview.el.save_easing_state();
480 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
481 this.win.rooview.el.set_scale(1.0f,1.0f);
482 this.win.rooview.el.restore_easing_state();
484 this.win.clutterfiles.el.hide();
490 var oldstate =this.state;
491 this.state = new_state;
494 this.buttonShowHide();
496 switch (this.state) {
498 case State.PREVIEW: // this is the default state when working...
499 this.win.rooview.el.save_easing_state();
500 this.win.rooview.el.set_scale(1.0f,1.0f);
501 this.win.rooview.el.restore_easing_state();
508 var ae = this.left_tree.getActiveElement();
510 this.state = this.oldstate;
511 this.buttonShowHide();
514 this.add_props.el.show_all();
516 Palete.factory(this.win.project.xtype),
517 this.state == State.LISTENER ? "signals" : "props",
523 this.win.rooview.el.save_easing_state();
524 // -- FIXME? this needs to be State aware?
525 _this.clutterembed.setSizesAlloc( this.state == State.LISTENER ? "addlistener" : "addprop");
526 this.win.rooview.el.restore_easing_state();
529 this.win.addpropsview.el.save_easing_state();
530 this.win.addpropsview.el.set_scale(1.0f,1.0f);
531 this.win.addpropsview.el.restore_easing_state();
536 this.code_editor.el.show_all();
538 // caller needs to call editor - show....
539 this.win.rooview.el.save_easing_state();
540 // -- FIXME? this needs to be State aware?
541 _this.clutterembed.setSizesAlloc( "codeedit");
542 this.win.rooview.el.restore_easing_state();
545 this.win.codeeditview.el.save_easing_state();
546 this.win.codeeditview.el.set_scale(1.0f,1.0f);
547 this.win.codeeditview.el.restore_easing_state();
552 var n = _this.left_tree.getActiveElement();
554 if (_this.left_tree.model.file == null) {
555 this.state = this.oldstate;
556 this.buttonShowHide();
560 if (n == null && _this.left_tree.model.file.tree != null) {
561 this.state = this.oldstate;
562 this.buttonShowHide();
566 this.rightpalete.el.show_all();
567 this.rightpalete.load(_this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
569 this.win.rooview.el.save_easing_state();
570 // -- FIXME? this needs to be State aware?
571 _this.clutterembed.setSizesAlloc( "codeedit");
572 this.win.rooview.el.restore_easing_state();
575 this.win.objectview.el.save_easing_state();
576 this.win.objectview.el.sset_scale(1.0f,1.0f);
577 this.win.objectview.el.restore_easing_state();
582 if (this.win.project.xtype == "Roo") {
583 this.projectsettings.el.show_all();
584 this.projectsettings.show(this.project);
586 this.vala_projectsettings.el.show_all();
587 this.vala_projectsettings.show((Project.Gtk)this.project);
590 this.win.rooview.el.save_easing_state();
591 // -- FIXME? this needs to be State aware?
592 _this.clutterembed.setSizesAlloc( "projectedit"); // was doing 0.5f....
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.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();
692 public void resizeCanvasElements(Gtk.Allocation alloc)
694 if (!_this.children_loaded) {
698 this.win.clutterfiles.set_size(alloc.width-50, alloc.height);
700 // ------- project view appears at top...
701 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
703 // ------- add property/object left - max 300px, min 50... (or disapear..)
705 var avail = alloc.width < 50.0f ? 0 : alloc.width - 50.0f;
706 var palsize = avail < 300.0f ? avail : 300.0f;
707 //print("set palsize size %f\n", palsize);
708 // palate / props : fixed 300 pix
710 this.win.objectview.el.set_size(palsize, alloc.height);
711 this.win.addpropsview.el.set_size(palsize, alloc.height);
715 // -------- code edit min 600
717 var codesize = avail < 800.0f ? avail : 800.0f;
718 //print("set code size %f\n", codesize);
720 this.win.codeeditview.el.set_size(codesize, alloc.height);
721 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
725 switch ( this.state) {
727 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
728 this.win.rooview.el.set_scale(scale,scale);
734 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
735 this.win.rooview.el.set_scale(scale,scale);