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 public State state = State.NONE;
20 public bool children_loaded = false;
22 public Project.Project? project = null;
23 public JsRender.JsRender? file = null;
25 public Xcls_WindowLeftTree left_tree;
26 public Xcls_PopoverAddProp add_props;
27 public Xcls_LeftProps left_props;
28 public Xcls_RooProjectSettings roo_projectsettings_pop;
29 public ValaProjectSettingsPopover vala_projectsettings_pop;
30 public Xcls_PopoverAddObject rightpalete;
31 //public Xcls_PopoverEditor code_editor_popover;
32 public Editor code_editor_tab;
33 public Xcls_WindowRooView window_rooview;
34 public Xcls_GtkView window_gladeview;
35 public DialogFiles popover_files;
37 //public Xcls_ClutterFiles clutterfiles;
38 //public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
40 public DialogTemplateSelect template_select;
42 public Xcls_PopoverFileDetails file_details;
43 public Xcls_ValaCompileResults compile_results;
49 //public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
50 public Json.Object last_compile_result;
53 public WindowState(Xcls_MainWindow win)
62 // on clutter space...
63 this.projectEditInit();
65 //this.codePopoverEditInit();
66 //this.projectListInit();
67 //this.fileViewInit();
76 this.webkitViewInit();
80 this.fileDetailsInit();
83 this.template_select = new DialogTemplateSelect();
84 this.children_loaded = true;
88 //BuilderApplication.valasource.compiled.connect(this.showCompileResult);
91 this.compile_results = new Xcls_ValaCompileResults(); // the poup dialogs with results in.
92 this.compile_results.window = this.win;
93 //BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
95 this.win.statusbar_compilestatus_label.el.hide();
96 this.win.statusbar_run.el.hide();
98 this.popover_files = new DialogFiles();
99 this.popover_files.win = this.win;
100 this.popover_files.el.application = this.win.el.application;
101 this.popover_files.el.set_transient_for( this.win.el );
109 public void leftTreeInit()
112 this.left_tree = new Xcls_WindowLeftTree();
113 this.left_tree.ref();
114 this.left_tree.main_window = this.win;
116 this.win.leftpane.el.remove(this.win.editpane.el);
117 //this.win.tree.el.remove(this.left_tree.el);
118 this.win.leftpane.el.append(this.left_tree.el);
121 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
122 this.left_tree.el.show();
124 this.left_tree.before_node_change.connect(() => {
125 // if the node change is caused by the editor (code preview)
126 if (this.left_tree.view.lastEventSource == "editor") {
129 return this.leftTreeBeforeChange();
132 // node selected -- only by clicking?
133 this.left_tree.node_selected.connect((sel) => {
134 //if (source == "editor") {
137 if (this.file.xtype == "Roo") {
138 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
140 this.window_gladeview.sourceview.nodeSelected(sel, true);
144 this.left_tree.node_selected.connect((sel) => {
145 this.leftTreeNodeSelected(sel);
148 this.left_tree.changed.connect(() => {
149 GLib.debug("LEFT TREE: Changed fired\n");
151 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
152 this.window_rooview.requestRedraw();
154 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
161 public bool leftTreeBeforeChange()
163 // in theory code editor has to hide before tree change occurs.
164 //if (this.state != State.CODE) {
165 //this.left_props.finish_editing();
167 if (this.state == State.CODE) {
168 this.code_editor_tab.saveContents();
169 this.switchState(State.PREVIEW);
175 //if (!this.code_editor.saveContents()) {
181 int tree_width = 300;
182 int props_width = 300;
184 public void leftTreeNodeSelected(JsRender.Node? sel)
187 // do we really want to flip paletes if differnt nodes are selected
188 // showing palete should be deliberate thing..
191 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
193 this.add_props.hide(); // always hide add node/add listener if we change node.
194 this.rightpalete.hide();
196 this.left_props.load(this.left_tree.getActiveFile(), sel);
198 var outerpane = this.win.mainpane.el;
199 var innerpane = this.win.editpane.el;
201 if (this.win.editpane.el.parent != null && sel != null) {
202 // select another node... no change to show hide/resize
207 // remove win.editpane from leftpane
208 // remove lefttree from from win.tree
209 // add win.tree to leftpane
210 if (this.win.editpane.el.parent != null) {
211 this.props_width = outerpane.get_position() - innerpane.get_position();
212 this.tree_width = innerpane.get_position();
213 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
215 this.win.leftpane.el.remove(this.win.editpane.el);
216 this.win.tree.el.remove(this.left_tree.el);
217 this.win.leftpane.el.append(this.left_tree.el);
221 //GLib.debug("Hide Properties");
222 outerpane.show(); // make sure it's visiable..
223 this.left_props.el.hide();
224 GLib.debug("set position: %d", this.tree_width);
225 outerpane.set_position(this.tree_width);
226 //outerpane.set_position(int.max(250,innerpane.get_position()));
227 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
231 // at this point we are showing the outer only,
236 this.tree_width = outerpane.get_position();
238 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
240 // remove this.ldeftree from this.win.leftpane
241 this.win.leftpane.el.remove(this.left_tree.el);
242 this.win.tree.el.append(this.left_tree.el);
243 this.win.leftpane.el.append(this.win.editpane.el);
248 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
249 // at start (hidden) - outer = 400 inner = 399
250 // expanded out -> outer = 686, inner = 399
251 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
252 this.left_props.el.show(); //if (!this.left_props.el.visible) {
254 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
255 outerpane.set_position(this.tree_width + this.props_width);
256 innerpane.set_position(this.tree_width);
257 /* var cw = outerpane.el.get_position();
258 var rw = int.min(this.left_props.el.width_request, 150);
259 print("outerpos : %d, innerpos : %d", cw + rw, cw);
261 innerpane.set_position(cw); */
262 this.left_props.el.show();
273 // if either of these are active.. then we should update them??
279 make outerpane = {current width of left pane} + width of props
280 make innerpane = {current width of left pane}
286 var outerpane = _this.main_window.leftpane.el;
287 var pane = _this.main_window.editpane.el;
291 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
292 GLib.Timeout.add_seconds(1, () => {
295 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
296 (int) (pane.max_position * 0.2f) :
297 pane.max_position-try_size);
298 return GLib.Source.REMOVE;
304 switch (this.state) {
307 this.switchState(State.PREVIEW);
322 public void propsListInit()
325 this.left_props =new Xcls_LeftProps();
326 this.left_props.ref();
327 this.left_props.main_window = this.win;
328 this.win.props.el.append(this.left_props.el);
329 this.left_props.el.show();
331 this.left_props.show_editor.connect( (file, node, prop) => {
332 this.switchState(State.CODE);
335 this.code_editor_tab.show(
345 // not sure if this is needed - as closing the popvoer should save it.
346 this.left_props.stop_editor.connect( () => {
347 var ret = this.code_editor_tab.saveContents();
351 this.switchState(State.PREVIEW);
356 this.left_props.changed.connect(() => {
357 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
358 this.window_rooview.requestRedraw();
360 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
362 //this.left_tree.model.updateSelected();
364 if (this.file.project.xtype=="Gtk") {
365 BuilderApplication.valacompilequeue.addFile(
366 Palete.ValaCompileRequestType.PROJECT,
367 this.file, "", true ) ;
369 //BuilderApplication.valasource.checkFileSpawn(this.file);
376 //------------- projects edit
378 public void projectEditInit()
380 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
381 this.roo_projectsettings_pop.el.application = this.win.el.application;
384 this.vala_projectsettings_pop =new ValaProjectSettingsPopover();
386 this.vala_projectsettings_pop.window = this.win;
387 this.vala_projectsettings_pop.el.application = this.win.el.application;
389 //this.vala_projectsettings_pop.el.set_parent(this.win.el); // = this.win;
391 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
394 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
395 if (btn == "save" || btn == "apply") {
396 this.roo_projectsettings_pop.save();
397 this.roo_projectsettings_pop.project.save();
401 // in theory active file can only be rooo...
402 var ep = this.roo_projectsettings_pop.project;
403 foreach(var ww in BuilderApplication.windows) {
404 if (ww.windowstate.file != null &&
405 ww.windowstate.project.path == ep.path &&
406 ww.windowstate.file.xtype == "Roo") {
408 ww.windowstate.window_rooview.view.renderJS(true);
416 this.roo_projectsettings_pop.el.hide();
418 //this.switchState (State.PREVIEW);
424 public void projectPopoverShow(Gtk.Window pwin, Project.Project? pr)
431 if (pr.xtype == "") {
434 if (pr.xtype == "Roo" ) {
435 this.roo_projectsettings_pop.show(pwin,(Project.Roo)pr);
441 this.vala_projectsettings_pop.show(pwin,(Project.Gtk)pr);
446 // ----------- object adding
447 public void objectAddInit()
450 this.rightpalete = new Xcls_PopoverAddObject();
451 this.rightpalete.mainwindow = this.win;
452 this.rightpalete.ref(); /// really?
453 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
456 var stage = this.win.objectview.el.get_stage();
457 stage.set_background_color( Clutter.Color.from_string("#000"));
461 // ----------- properties adding list...
462 // listener uses the properties
463 public void propsAddInit()
466 this.add_props = new Xcls_PopoverAddProp();
467 this.add_props.mainwindow = this.win;
468 this.add_props.ref(); /// really?
469 // don't need to add it..
470 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
473 //var stage = this.win.addpropsview.el.get_stage();
474 //stage.set_background_color( Clutter.Color.from_string("#000"));
480 public void propsAddShow()
484 public void propsAddHide()
490 // ----------- Add / Edit listener
491 // listener uses the properties
492 //public void listenerInit() { }
493 public void listenerShow()
497 public void listenerHide()
502 // -------------- codeEditor
504 public void codeEditInit()
506 this.code_editor_tab = new Editor();
507 //this.code_editor.ref(); /// really?
508 this.win.codeeditviewbox.el.append(this.code_editor_tab.el);
510 this.win.codeeditviewbox.el.hide();
511 this.code_editor_tab.window = this.win;
515 this.code_editor_tab.save.connect( () => {
517 //this.left_tree.model.updateSelected();
518 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
519 this.window_rooview.requestRedraw();
521 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
523 if (this.file.project.xtype=="Gtk") {
524 BuilderApplication.valacompilequeue.addFile(
525 Palete.ValaCompileRequestType.PROJECT,
526 this.file, "", false ) ;
529 // we do not need to call spawn... - as it's already called by the editor?
536 // ----------- file view
537 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
539 this.popover_files.show( project, new_window);
545 public void fileDetailsInit()
547 this.file_details = new Xcls_PopoverFileDetails();
548 this.file_details.mainwindow = this.win;
549 this.file_details.el.application = this.win.el.application;
550 // this.file_details.el.set_parent(this.win.el);
551 // force it modal to the main window..
553 this.file_details.success.connect((project,file) =>
555 this.popover_files.el.hide();
556 this.fileViewOpen(file, this.file_details.new_window, -1);
557 // if it's comming from the file dialog -> hide it...
564 public void gotoLine(int line)
570 if (file.xtype == "PlainFile") {
571 this.switchState (State.CODEONLY);
573 this.code_editor_tab.scroll_to_line(line);
578 this.switchState (State.PREVIEW);
581 // fixme - show the editing tab.
583 var node = file.lineToNode(line);
585 this.left_tree.model.selectNode(node);
586 var prop = node.lineToProp(line);
589 GLib.debug("could not find prop at line %d", line);
592 this.left_props.view.editProp(prop);
599 if (this.project.xtype == "Gtk") {
600 this.window_gladeview.scroll_to_line(line);
602 this.window_rooview.scroll_to_line(line);
607 var node = file.lineToNode(line);
609 this.left_tree.model.selectNode(node);
610 //var prop = node.lineToProp(line);
614 this.window_rooview.scroll_to_line(line);
620 public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
622 var existing = BuilderApplication.getWindow(file);
624 if (existing != null) {
625 existing.el.present();
626 existing.windowstate.gotoLine(line);
632 this.popover_files.el.hide();
633 BuilderApplication.newWindow(file, line);
638 this.win.project = file.project;
639 this.project = file.project;
641 BuilderApplication.updateWindows();
646 if (file.xtype == "PlainFile") {
647 this.win.codeeditviewbox.el.show();
648 this.switchState (State.CODEONLY);
652 this.code_editor_tab.show(file, null, null);
656 this.switchState (State.PREVIEW);
657 // this triggers loadItems..
658 this.left_tree.model.loadFile(file);
662 BuilderApplication.updateCompileResults();
663 if (file.project.xtype == "Gtk" && file.project.last_request == null ) {
665 BuilderApplication.valacompilequeue.addFile(
666 Palete.ValaCompileRequestType.PROJECT,
667 this.file, "" , true) ;
672 var ctr= this.win.rooviewbox.el;
675 if (file.project.xtype == "Roo" ) {
676 // removes all the childe elemnts from rooviewbox
677 while( ctr.get_last_child() != null) {
678 ctr.remove(ctr.get_last_child());
681 ctr.append(this.window_rooview.el);
683 if (file.xtype != "PlainFile") {
685 this.window_rooview.loadFile(file);
686 this.window_rooview.el.show();
692 while( ctr.get_last_child() != null) {
693 ctr.remove(ctr.get_last_child());
696 ctr.append(this.window_gladeview.el);
698 if (file.xtype != "PlainFile") {
700 this.window_gladeview.loadFile(file);
701 this.window_gladeview.el.show();
705 print("OPEN : " + file.name);
706 if (file.xtype != "PlainFile") {
707 // hide the file editor.
708 this.win.codeeditviewbox.el.hide();
709 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
718 public void fileViewOpenPlain(string fname)
721 this.switchState (State.CODEONLY);
722 this.code_editor.showPlainFile(fname);
726 // --------- webkit view
727 public void webkitViewInit()
729 this.window_rooview =new Xcls_WindowRooView();
730 this.window_rooview.main_window = this.win;
731 this.window_rooview.ref();
732 this.win.rooviewbox.el.append(this.window_rooview.el);
734 this.window_rooview.el.show();
735 this.win.rooviewbox.el.hide();
741 public void gtkViewInit()
746 this.window_gladeview =new Xcls_GtkView( );
747 this.window_gladeview.ref();
748 this.window_gladeview.main_window = this.win;
755 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
757 var ae = this.left_tree.getActiveElement();
761 this.rightpalete.hide();
762 this.add_props.el.set_parent(btn);
763 this.add_props.el.set_position(Gtk.PositionType.RIGHT);
766 this.win.project.palete, //Palete.factory(this.win.project.xtype),
767 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
774 public void showAddObject(Gtk.Widget btn, JsRender.Node? on_node)
778 this.add_props.hide();
780 this.add_props.el.set_position(Gtk.PositionType.RIGHT);
782 //this.rightpalete.el.set_parent(btn);
784 this.rightpalete.show(
785 this.left_tree.getActiveFile().palete(),
786 on_node == null ? "*top" : on_node.fqn(),
793 public void switchState(State new_state)
796 // if the new state and the old state are the same..
798 if (new_state == this.state) {
802 // anything to do beforehand?
804 switch (this.state) {
809 // stop editing the editor tab.
810 // always save before calling switch state to preview?
812 this.code_editor_tab.reset();
814 if (this.left_tree.getActiveFile() != null) {
815 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
816 this.window_rooview.createThumb();
818 this.window_gladeview.createThumb();
821 // normally we are going from preview to another state.
822 // and different windows hide the preview in differnt ways..
832 this.state = new_state;
835 switch (this.state) {
837 case State.PREVIEW: // this is the default state when working...
838 this.win.leftpane.el.show();
839 this.win.editpane.el.show(); // holder for tree and properties..
840 this.win.rooviewbox.el.show();
841 this.win.codeeditviewbox.el.hide();
845 this.win.leftpane.el.show();
846 this.win.editpane.el.show();
847 this.win.rooviewbox.el.hide();
848 this.win.codeeditviewbox.el.show();
849 this.code_editor_tab.el.show();
853 this.win.leftpane.el.hide();
854 this.win.codeeditviewbox.el.show();
855 this.win.rooviewbox.el.hide();
856 this.code_editor_tab.el.show();