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;
46 // used by window list..
47 public string file_name {
48 owned get { return this.file.relpath; }
53 //public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
54 public Json.Object last_compile_result;
57 public WindowState(Xcls_MainWindow win)
71 // on clutter space...
72 this.projectEditInit();
74 //this.codePopoverEditInit();
75 //this.projectListInit();
76 //this.fileViewInit();
85 this.webkitViewInit();
89 this.fileDetailsInit();
92 this.template_select = new DialogTemplateSelect();
93 this.children_loaded = true;
97 //BuilderApplication.valasource.compiled.connect(this.showCompileResult);
100 this.compile_results = new Xcls_ValaCompileResults(); // the poup dialogs with results in.
101 this.compile_results.window = this.win;
102 //BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
104 this.win.statusbar_compilestatus_label.el.hide();
105 this.win.statusbar_run.el.hide();
107 this.popover_files = new DialogFiles();
108 this.popover_files.win = this.win;
109 this.popover_files.el.application = this.win.el.application;
110 this.popover_files.el.set_transient_for( this.win.el );
118 public void leftTreeInit()
121 this.left_tree = new Xcls_WindowLeftTree();
122 this.left_tree.ref();
123 this.left_tree.main_window = this.win;
125 this.win.leftpane.el.remove(this.win.editpane.el);
126 //this.win.tree.el.remove(this.left_tree.el);
127 this.win.leftpane.el.append(this.left_tree.el);
130 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
131 this.left_tree.el.show();
133 this.left_tree.before_node_change.connect(() => {
134 // if the node change is caused by the editor (code preview)
135 if (this.left_tree.view.lastEventSource == "editor") {
138 return this.leftTreeBeforeChange();
141 // node selected -- only by clicking?
142 this.left_tree.node_selected.connect((sel) => {
143 //if (source == "editor") {
146 if (this.file.xtype == "Roo") {
147 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
149 this.window_gladeview.sourceview.nodeSelected(sel, true);
153 this.left_tree.node_selected.connect((sel) => {
154 this.leftTreeNodeSelected(sel);
157 this.left_tree.changed.connect(() => {
158 GLib.debug("LEFT TREE: Changed fired\n");
160 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
161 this.window_rooview.requestRedraw();
163 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
170 public void updateErrorMarksAll()
172 this.updateErrorMarks("ERR");
173 this.updateErrorMarks("WARN");
174 this.updateErrorMarks("DEPR");
177 void updateErrorMarks(string cat)
179 this.code_editor_tab.updateErrorMarks();
180 switch(this.file.xtype) {
182 this.window_rooview.updateErrorMarks();// foce scroll.
185 this.window_gladeview.updateErrorMarks();
194 public bool leftTreeBeforeChange()
196 // in theory code editor has to hide before tree change occurs.
197 //if (this.state != State.CODE) {
198 //this.left_props.finish_editing();
200 if (this.state == State.CODE) {
201 this.code_editor_tab.saveContents();
202 this.switchState(State.PREVIEW);
208 //if (!this.code_editor.saveContents()) {
214 int tree_width = 300;
215 int props_width = 300;
217 public void leftTreeNodeSelected(JsRender.Node? sel)
220 // do we really want to flip paletes if differnt nodes are selected
221 // showing palete should be deliberate thing..
224 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
226 this.add_props.hide(); // always hide add node/add listener if we change node.
227 this.rightpalete.hide();
229 this.left_props.load(this.left_tree.getActiveFile(), sel);
231 var outerpane = this.win.mainpane.el;
232 var innerpane = this.win.editpane.el;
234 if (this.win.editpane.el.parent != null && sel != null) {
235 // select another node... no change to show hide/resize
240 // remove win.editpane from leftpane
241 // remove lefttree from from win.tree
242 // add win.tree to leftpane
243 if (this.win.editpane.el.parent != null) {
244 this.props_width = outerpane.get_position() - innerpane.get_position();
245 this.tree_width = innerpane.get_position();
246 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
248 this.win.leftpane.el.remove(this.win.editpane.el);
249 this.win.tree.el.remove(this.left_tree.el);
250 this.win.leftpane.el.append(this.left_tree.el);
254 //GLib.debug("Hide Properties");
255 outerpane.show(); // make sure it's visiable..
256 this.left_props.el.hide();
257 GLib.debug("set position: %d", this.tree_width);
258 outerpane.set_position(this.tree_width);
259 //outerpane.set_position(int.max(250,innerpane.get_position()));
260 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
264 // at this point we are showing the outer only,
269 this.tree_width = outerpane.get_position();
271 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
273 // remove this.ldeftree from this.win.leftpane
274 this.win.leftpane.el.remove(this.left_tree.el);
275 this.win.tree.el.append(this.left_tree.el);
276 this.win.leftpane.el.append(this.win.editpane.el);
281 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
282 // at start (hidden) - outer = 400 inner = 399
283 // expanded out -> outer = 686, inner = 399
284 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
285 this.left_props.el.show(); //if (!this.left_props.el.visible) {
287 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
288 outerpane.set_position(this.tree_width + this.props_width);
289 innerpane.set_position(this.tree_width);
290 /* var cw = outerpane.el.get_position();
291 var rw = int.min(this.left_props.el.width_request, 150);
292 print("outerpos : %d, innerpos : %d", cw + rw, cw);
294 innerpane.set_position(cw); */
295 this.left_props.el.show();
306 // if either of these are active.. then we should update them??
312 make outerpane = {current width of left pane} + width of props
313 make innerpane = {current width of left pane}
319 var outerpane = _this.main_window.leftpane.el;
320 var pane = _this.main_window.editpane.el;
324 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
325 GLib.Timeout.add_seconds(1, () => {
328 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
329 (int) (pane.max_position * 0.2f) :
330 pane.max_position-try_size);
331 return GLib.Source.REMOVE;
337 switch (this.state) {
340 this.switchState(State.PREVIEW);
355 public void propsListInit()
358 this.left_props =new Xcls_LeftProps();
359 this.left_props.ref();
360 this.left_props.main_window = this.win;
361 this.win.props.el.append(this.left_props.el);
362 this.left_props.el.show();
364 this.left_props.show_editor.connect( (file, node, prop) => {
365 this.switchState(State.CODE);
368 this.code_editor_tab.show(
378 // not sure if this is needed - as closing the popvoer should save it.
379 this.left_props.stop_editor.connect( () => {
380 var ret = this.code_editor_tab.saveContents();
384 this.switchState(State.PREVIEW);
389 this.left_props.changed.connect(() => {
390 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
391 this.window_rooview.requestRedraw();
393 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
395 //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();