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 Editor code_editor_tab;
32 public Xcls_WindowRooView window_rooview;
33 public Xcls_GtkView window_gladeview;
34 public DialogFiles popover_files;
36 //public Xcls_ClutterFiles clutterfiles;
37 //public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
39 public DialogTemplateSelect template_select;
41 public Xcls_PopoverFileDetails file_details;
42 public Xcls_ValaCompileResults compile_results;
45 // used by window list..
46 public string file_name {
47 owned get { return this.file.relpath; }
52 //public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
53 public Json.Object last_compile_result;
56 public WindowState(Xcls_MainWindow win)
70 // on clutter space...
71 this.projectEditInit();
73 //this.codePopoverEditInit();
74 //this.projectListInit();
75 //this.fileViewInit();
84 this.webkitViewInit();
88 this.fileDetailsInit();
91 this.template_select = new DialogTemplateSelect();
92 this.children_loaded = true;
96 //BuilderApplication.valasource.compiled.connect(this.showCompileResult);
99 this.compile_results = new Xcls_ValaCompileResults(); // the poup dialogs with results in.
100 this.compile_results.window = this.win;
101 //BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
103 this.win.statusbar_compilestatus_label.el.hide();
104 this.win.statusbar_run.el.hide();
106 this.popover_files = new DialogFiles();
107 this.popover_files.win = this.win;
108 this.popover_files.el.application = this.win.el.application;
109 this.popover_files.el.set_transient_for( this.win.el );
117 public void leftTreeInit()
120 this.left_tree = new Xcls_WindowLeftTree();
121 this.left_tree.ref();
122 this.left_tree.main_window = this.win;
124 this.win.leftpane.el.remove(this.win.editpane.el);
125 //this.win.tree.el.remove(this.left_tree.el);
126 this.win.leftpane.el.append(this.left_tree.el);
129 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
130 this.left_tree.el.show();
132 this.left_tree.before_node_change.connect(() => {
133 // if the node change is caused by the editor (code preview)
134 if (this.left_tree.view.lastEventSource == "editor") {
137 return this.leftTreeBeforeChange();
140 // node selected -- only by clicking?
141 this.left_tree.node_selected.connect((sel) => {
142 //if (source == "editor") {
145 if (this.file.xtype == "Roo") {
146 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
148 this.window_gladeview.sourceview.nodeSelected(sel, true);
152 this.left_tree.node_selected.connect((sel) => {
153 this.leftTreeNodeSelected(sel);
156 this.left_tree.changed.connect(() => {
157 GLib.debug("LEFT TREE: Changed fired\n");
159 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
160 this.window_rooview.requestRedraw();
162 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
169 public void updateErrorMarksAll()
171 this.updateErrorMarks("ERR");
172 this.updateErrorMarks("WARN");
173 this.updateErrorMarks("DEPR");
176 void updateErrorMarks(string cat)
178 this.code_editor_tab.updateErrorMarks();
179 switch(this.file.xtype) {
181 this.window_rooview.updateErrorMarks();// foce scroll.
184 this.window_gladeview.updateErrorMarks();
193 public bool leftTreeBeforeChange()
195 // in theory code editor has to hide before tree change occurs.
196 //if (this.state != State.CODE) {
197 //this.left_props.finish_editing();
199 if (this.state == State.CODE) {
200 this.code_editor_tab.saveContents();
201 this.switchState(State.PREVIEW);
207 //if (!this.code_editor.saveContents()) {
213 int tree_width = 300;
214 int props_width = 300;
216 public void leftTreeNodeSelected(JsRender.Node? sel)
219 // do we really want to flip paletes if differnt nodes are selected
220 // showing palete should be deliberate thing..
223 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
225 this.add_props.hide(); // always hide add node/add listener if we change node.
226 this.rightpalete.hide();
228 this.left_props.load(this.left_tree.getActiveFile(), sel);
230 var outerpane = this.win.mainpane.el;
231 var innerpane = this.win.editpane.el;
233 if (this.win.editpane.el.parent != null && sel != null) {
234 // select another node... no change to show hide/resize
239 // remove win.editpane from leftpane
240 // remove lefttree from from win.tree
241 // add win.tree to leftpane
242 if (this.win.editpane.el.parent != null) {
243 this.props_width = outerpane.get_position() - innerpane.get_position();
244 this.tree_width = innerpane.get_position();
245 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
247 this.win.leftpane.el.remove(this.win.editpane.el);
248 this.win.tree.el.remove(this.left_tree.el);
249 this.win.leftpane.el.append(this.left_tree.el);
253 //GLib.debug("Hide Properties");
254 outerpane.show(); // make sure it's visiable..
255 this.left_props.el.hide();
256 GLib.debug("set position: %d", this.tree_width);
257 outerpane.set_position(this.tree_width);
258 //outerpane.set_position(int.max(250,innerpane.get_position()));
259 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
263 // at this point we are showing the outer only,
268 this.tree_width = outerpane.get_position();
270 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
272 // remove this.ldeftree from this.win.leftpane
273 this.win.leftpane.el.remove(this.left_tree.el);
274 this.win.tree.el.append(this.left_tree.el);
275 this.win.leftpane.el.append(this.win.editpane.el);
280 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
281 // at start (hidden) - outer = 400 inner = 399
282 // expanded out -> outer = 686, inner = 399
283 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
284 this.left_props.el.show(); //if (!this.left_props.el.visible) {
286 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
287 outerpane.set_position(this.tree_width + this.props_width);
288 innerpane.set_position(this.tree_width);
289 /* var cw = outerpane.el.get_position();
290 var rw = int.min(this.left_props.el.width_request, 150);
291 print("outerpos : %d, innerpos : %d", cw + rw, cw);
293 innerpane.set_position(cw); */
294 this.left_props.el.show();
305 // if either of these are active.. then we should update them??
311 make outerpane = {current width of left pane} + width of props
312 make innerpane = {current width of left pane}
318 var outerpane = _this.main_window.leftpane.el;
319 var pane = _this.main_window.editpane.el;
323 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
324 GLib.Timeout.add_seconds(1, () => {
327 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
328 (int) (pane.max_position * 0.2f) :
329 pane.max_position-try_size);
330 return GLib.Source.REMOVE;
336 switch (this.state) {
339 this.switchState(State.PREVIEW);
354 public void propsListInit()
357 this.left_props =new Xcls_LeftProps();
358 this.left_props.ref();
359 this.left_props.main_window = this.win;
360 this.win.props.el.append(this.left_props.el);
361 this.left_props.el.show();
363 this.left_props.show_editor.connect( (file, node, prop) => {
364 this.switchState(State.CODE);
367 this.code_editor_tab.show(
377 // not sure if this is needed - as closing the popvoer should save it.
378 this.left_props.stop_editor.connect( () => {
379 var ret = this.code_editor_tab.saveContents();
383 this.switchState(State.PREVIEW);
388 this.left_props.changed.connect(() => {
389 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
390 this.window_rooview.requestRedraw();
392 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
394 //this.left_tree.model.updateSelected();
403 //------------- projects edit
405 public void projectEditInit()
407 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
408 this.roo_projectsettings_pop.el.application = this.win.el.application;
411 this.vala_projectsettings_pop =new ValaProjectSettingsPopover();
413 this.vala_projectsettings_pop.window = this.win;
414 this.vala_projectsettings_pop.el.application = this.win.el.application;
416 //this.vala_projectsettings_pop.el.set_parent(this.win.el); // = this.win;
418 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
421 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
422 if (btn == "save" || btn == "apply") {
423 this.roo_projectsettings_pop.save();
424 this.roo_projectsettings_pop.project.save();
428 // in theory active file can only be rooo...
429 var ep = this.roo_projectsettings_pop.project;
430 foreach(var ww in BuilderApplication.windows) {
431 if (ww.windowstate.file != null &&
432 ww.windowstate.project.path == ep.path &&
433 ww.windowstate.file.xtype == "Roo") {
435 ww.windowstate.window_rooview.view.renderJS(true);
443 this.roo_projectsettings_pop.el.hide();
445 //this.switchState (State.PREVIEW);
451 public void projectPopoverShow(Gtk.Window pwin, Project.Project? pr, Project.Callback? doneObj)
458 if (pr.xtype == "") {
461 if (pr.xtype == "Roo" ) {
462 this.roo_projectsettings_pop.show(pwin,(Project.Roo)pr);
468 this.vala_projectsettings_pop.show(pwin,(Project.Gtk)pr, doneObj);
473 // ----------- object adding
474 public void objectAddInit()
477 this.rightpalete = new Xcls_PopoverAddObject();
478 this.rightpalete.mainwindow = this.win;
479 this.rightpalete.ref(); /// really?
480 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
483 var stage = this.win.objectview.el.get_stage();
484 stage.set_background_color( Clutter.Color.from_string("#000"));
488 // ----------- properties adding list...
489 // listener uses the properties
490 public void propsAddInit()
493 this.add_props = new Xcls_PopoverAddProp();
494 this.add_props.mainwindow = this.win;
495 this.add_props.ref(); /// really?
496 // don't need to add it..
497 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
500 //var stage = this.win.addpropsview.el.get_stage();
501 //stage.set_background_color( Clutter.Color.from_string("#000"));
507 public void propsAddShow()
511 public void propsAddHide()
517 // ----------- Add / Edit listener
518 // listener uses the properties
519 //public void listenerInit() { }
520 public void listenerShow()
524 public void listenerHide()
529 // -------------- codeEditor
531 public void codeEditInit()
533 this.code_editor_tab = new Editor();
534 //this.code_editor.ref(); /// really?
535 this.win.codeeditviewbox.el.append(this.code_editor_tab.el);
537 this.win.codeeditviewbox.el.hide();
538 this.code_editor_tab.window = this.win;
542 this.code_editor_tab.save.connect( () => {
544 //this.left_tree.model.updateSelected();
545 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
546 this.window_rooview.requestRedraw();
548 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
552 // we do not need to call spawn... - as it's already called by the editor?
559 // ----------- file view
560 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
562 this.popover_files.show( project, new_window);
568 public void fileDetailsInit()
570 this.file_details = new Xcls_PopoverFileDetails();
571 this.file_details.mainwindow = this.win;
572 this.file_details.el.application = this.win.el.application;
573 // this.file_details.el.set_parent(this.win.el);
574 // force it modal to the main window..
576 this.file_details.success.connect((project,file) =>
578 this.popover_files.el.hide();
579 this.fileViewOpen(file, this.file_details.new_window, -1);
580 // if it's comming from the file dialog -> hide it...
587 public void gotoLine(int line)
593 if (file.xtype == "PlainFile") {
594 this.switchState (State.CODEONLY);
596 this.code_editor_tab.scroll_to_line(line);
601 this.switchState (State.PREVIEW);
604 // fixme - show the editing tab.
606 var node = file.lineToNode(line);
608 this.left_tree.model.selectNode(node);
609 var prop = node.lineToProp(line);
612 GLib.debug("could not find prop at line %d", line);
615 this.left_props.view.editProp(prop);
622 if (this.project.xtype == "Gtk") {
623 this.window_gladeview.scroll_to_line(line);
625 this.window_rooview.scroll_to_line(line);
630 var node = file.lineToNode(line);
632 this.left_tree.model.selectNode(node);
633 //var prop = node.lineToProp(line);
637 this.window_rooview.scroll_to_line(line);
643 public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
645 var existing = BuilderApplication.getWindow(file);
647 if (existing != null) {
648 existing.el.present();
649 existing.windowstate.gotoLine(line);
655 this.popover_files.el.hide();
656 BuilderApplication.newWindow(file, line);
661 this.win.project = file.project;
662 this.project = file.project;
666 file.getLanguageServer().document_open(file);
667 BuilderApplication.showSpinner("spinner", "document open sent");
669 if (file.xtype == "PlainFile") {
670 this.win.codeeditviewbox.el.show();
671 this.switchState (State.CODEONLY);
675 this.code_editor_tab.show(file, null, null);
679 this.switchState (State.PREVIEW);
680 // this triggers loadItems..
681 this.left_tree.model.loadFile(file);
689 var ctr= this.win.rooviewbox.el;
692 if (file.project.xtype == "Roo" ) {
693 // removes all the childe elemnts from rooviewbox
694 while( ctr.get_last_child() != null) {
695 ctr.remove(ctr.get_last_child());
698 ctr.append(this.window_rooview.el);
700 if (file.xtype != "PlainFile") {
702 this.window_rooview.loadFile(file);
703 this.window_rooview.el.show();
709 while( ctr.get_last_child() != null) {
710 ctr.remove(ctr.get_last_child());
713 ctr.append(this.window_gladeview.el);
715 if (file.xtype != "PlainFile") {
717 this.window_gladeview.loadFile(file);
718 this.window_gladeview.el.show();
722 print("OPEN : " + file.name);
723 if (file.xtype != "PlainFile") {
724 // hide the file editor.
725 this.win.codeeditviewbox.el.hide();
726 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
730 BuilderApplication.updateCompileResults();
736 public void fileViewOpenPlain(string fname)
739 this.switchState (State.CODEONLY);
740 this.code_editor.showPlainFile(fname);
744 // --------- webkit view
745 public void webkitViewInit()
747 this.window_rooview =new Xcls_WindowRooView();
748 this.window_rooview.main_window = this.win;
749 this.window_rooview.ref();
750 this.win.rooviewbox.el.append(this.window_rooview.el);
752 this.window_rooview.el.show();
753 this.win.rooviewbox.el.hide();
759 public void gtkViewInit()
764 this.window_gladeview =new Xcls_GtkView( );
765 this.window_gladeview.ref();
766 this.window_gladeview.main_window = this.win;
773 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
775 var ae = this.left_tree.getActiveElement();
779 this.rightpalete.hide();
780 if (this.add_props.el.parent == null) {
781 this.add_props.el.set_parent(btn);
783 this.add_props.el.set_position(Gtk.PositionType.RIGHT);
786 this.win.project.palete, //Palete.factory(this.win.project.xtype),
787 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
794 public void showAddObject(Gtk.Widget btn, JsRender.Node? on_node)
798 this.add_props.hide();
800 this.add_props.el.set_position(Gtk.PositionType.RIGHT);
802 //this.rightpalete.el.set_parent(btn);
804 this.rightpalete.show(
805 this.left_tree.getActiveFile().palete(),
806 on_node == null ? "*top" : on_node.fqn(),
813 public void switchState(State new_state)
816 // if the new state and the old state are the same..
818 if (new_state == this.state) {
822 // anything to do beforehand?
824 switch (this.state) {
829 // stop editing the editor tab.
830 // always save before calling switch state to preview?
832 this.code_editor_tab.reset();
834 if (this.left_tree.getActiveFile() != null) {
835 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
836 this.window_rooview.createThumb();
838 this.window_gladeview.createThumb();
841 // normally we are going from preview to another state.
842 // and different windows hide the preview in differnt ways..
852 this.state = new_state;
855 switch (this.state) {
857 case State.PREVIEW: // this is the default state when working...
858 this.win.leftpane.el.show();
859 this.win.editpane.el.show(); // holder for tree and properties..
860 this.win.rooviewbox.el.show();
861 this.win.codeeditviewbox.el.hide();
865 this.win.leftpane.el.show();
866 this.win.editpane.el.show();
867 this.win.rooviewbox.el.hide();
868 this.win.codeeditviewbox.el.show();
869 this.code_editor_tab.el.show();
873 this.win.leftpane.el.hide();
874 this.win.codeeditviewbox.el.show();
875 this.win.rooviewbox.el.hide();
876 this.code_editor_tab.el.show();