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 void updateErrorMarksAll()
163 this.updateErrorMarks("ERR");
164 this.updateErrorMarks("WARN");
165 this.updateErrorMarks("DEPR");
168 void updateErrorMarks(string cat)
170 this.code_editor_tab.updateErrorMarks(cat);
171 switch(this.file.xtype) {
173 this.window_rooview.updateErrorMarks(cat);// foce scroll.
176 this.window_gladeview.updateErrorMarks(cat);
185 public bool leftTreeBeforeChange()
187 // in theory code editor has to hide before tree change occurs.
188 //if (this.state != State.CODE) {
189 //this.left_props.finish_editing();
191 if (this.state == State.CODE) {
192 this.code_editor_tab.saveContents();
193 this.switchState(State.PREVIEW);
199 //if (!this.code_editor.saveContents()) {
205 int tree_width = 300;
206 int props_width = 300;
208 public void leftTreeNodeSelected(JsRender.Node? sel)
211 // do we really want to flip paletes if differnt nodes are selected
212 // showing palete should be deliberate thing..
215 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
217 this.add_props.hide(); // always hide add node/add listener if we change node.
218 this.rightpalete.hide();
220 this.left_props.load(this.left_tree.getActiveFile(), sel);
222 var outerpane = this.win.mainpane.el;
223 var innerpane = this.win.editpane.el;
225 if (this.win.editpane.el.parent != null && sel != null) {
226 // select another node... no change to show hide/resize
231 // remove win.editpane from leftpane
232 // remove lefttree from from win.tree
233 // add win.tree to leftpane
234 if (this.win.editpane.el.parent != null) {
235 this.props_width = outerpane.get_position() - innerpane.get_position();
236 this.tree_width = innerpane.get_position();
237 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
239 this.win.leftpane.el.remove(this.win.editpane.el);
240 this.win.tree.el.remove(this.left_tree.el);
241 this.win.leftpane.el.append(this.left_tree.el);
245 //GLib.debug("Hide Properties");
246 outerpane.show(); // make sure it's visiable..
247 this.left_props.el.hide();
248 GLib.debug("set position: %d", this.tree_width);
249 outerpane.set_position(this.tree_width);
250 //outerpane.set_position(int.max(250,innerpane.get_position()));
251 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
255 // at this point we are showing the outer only,
260 this.tree_width = outerpane.get_position();
262 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
264 // remove this.ldeftree from this.win.leftpane
265 this.win.leftpane.el.remove(this.left_tree.el);
266 this.win.tree.el.append(this.left_tree.el);
267 this.win.leftpane.el.append(this.win.editpane.el);
272 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
273 // at start (hidden) - outer = 400 inner = 399
274 // expanded out -> outer = 686, inner = 399
275 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
276 this.left_props.el.show(); //if (!this.left_props.el.visible) {
278 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
279 outerpane.set_position(this.tree_width + this.props_width);
280 innerpane.set_position(this.tree_width);
281 /* var cw = outerpane.el.get_position();
282 var rw = int.min(this.left_props.el.width_request, 150);
283 print("outerpos : %d, innerpos : %d", cw + rw, cw);
285 innerpane.set_position(cw); */
286 this.left_props.el.show();
297 // if either of these are active.. then we should update them??
303 make outerpane = {current width of left pane} + width of props
304 make innerpane = {current width of left pane}
310 var outerpane = _this.main_window.leftpane.el;
311 var pane = _this.main_window.editpane.el;
315 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
316 GLib.Timeout.add_seconds(1, () => {
319 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
320 (int) (pane.max_position * 0.2f) :
321 pane.max_position-try_size);
322 return GLib.Source.REMOVE;
328 switch (this.state) {
331 this.switchState(State.PREVIEW);
346 public void propsListInit()
349 this.left_props =new Xcls_LeftProps();
350 this.left_props.ref();
351 this.left_props.main_window = this.win;
352 this.win.props.el.append(this.left_props.el);
353 this.left_props.el.show();
355 this.left_props.show_editor.connect( (file, node, prop) => {
356 this.switchState(State.CODE);
359 this.code_editor_tab.show(
369 // not sure if this is needed - as closing the popvoer should save it.
370 this.left_props.stop_editor.connect( () => {
371 var ret = this.code_editor_tab.saveContents();
375 this.switchState(State.PREVIEW);
380 this.left_props.changed.connect(() => {
381 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
382 this.window_rooview.requestRedraw();
384 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
386 //this.left_tree.model.updateSelected();
394 //------------- projects edit
396 public void projectEditInit()
398 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
399 this.roo_projectsettings_pop.el.application = this.win.el.application;
402 this.vala_projectsettings_pop =new ValaProjectSettingsPopover();
404 this.vala_projectsettings_pop.window = this.win;
405 this.vala_projectsettings_pop.el.application = this.win.el.application;
407 //this.vala_projectsettings_pop.el.set_parent(this.win.el); // = this.win;
409 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
412 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
413 if (btn == "save" || btn == "apply") {
414 this.roo_projectsettings_pop.save();
415 this.roo_projectsettings_pop.project.save();
419 // in theory active file can only be rooo...
420 var ep = this.roo_projectsettings_pop.project;
421 foreach(var ww in BuilderApplication.windows) {
422 if (ww.windowstate.file != null &&
423 ww.windowstate.project.path == ep.path &&
424 ww.windowstate.file.xtype == "Roo") {
426 ww.windowstate.window_rooview.view.renderJS(true);
434 this.roo_projectsettings_pop.el.hide();
436 //this.switchState (State.PREVIEW);
442 public void projectPopoverShow(Gtk.Window pwin, Project.Project? pr, Project.Callback? doneObj)
449 if (pr.xtype == "") {
452 if (pr.xtype == "Roo" ) {
453 this.roo_projectsettings_pop.show(pwin,(Project.Roo)pr);
459 this.vala_projectsettings_pop.show(pwin,(Project.Gtk)pr, doneObj);
464 // ----------- object adding
465 public void objectAddInit()
468 this.rightpalete = new Xcls_PopoverAddObject();
469 this.rightpalete.mainwindow = this.win;
470 this.rightpalete.ref(); /// really?
471 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
474 var stage = this.win.objectview.el.get_stage();
475 stage.set_background_color( Clutter.Color.from_string("#000"));
479 // ----------- properties adding list...
480 // listener uses the properties
481 public void propsAddInit()
484 this.add_props = new Xcls_PopoverAddProp();
485 this.add_props.mainwindow = this.win;
486 this.add_props.ref(); /// really?
487 // don't need to add it..
488 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
491 //var stage = this.win.addpropsview.el.get_stage();
492 //stage.set_background_color( Clutter.Color.from_string("#000"));
498 public void propsAddShow()
502 public void propsAddHide()
508 // ----------- Add / Edit listener
509 // listener uses the properties
510 //public void listenerInit() { }
511 public void listenerShow()
515 public void listenerHide()
520 // -------------- codeEditor
522 public void codeEditInit()
524 this.code_editor_tab = new Editor();
525 //this.code_editor.ref(); /// really?
526 this.win.codeeditviewbox.el.append(this.code_editor_tab.el);
528 this.win.codeeditviewbox.el.hide();
529 this.code_editor_tab.window = this.win;
533 this.code_editor_tab.save.connect( () => {
535 //this.left_tree.model.updateSelected();
536 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
537 this.window_rooview.requestRedraw();
539 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
543 // we do not need to call spawn... - as it's already called by the editor?
550 // ----------- file view
551 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
553 this.popover_files.show( project, new_window);
559 public void fileDetailsInit()
561 this.file_details = new Xcls_PopoverFileDetails();
562 this.file_details.mainwindow = this.win;
563 this.file_details.el.application = this.win.el.application;
564 // this.file_details.el.set_parent(this.win.el);
565 // force it modal to the main window..
567 this.file_details.success.connect((project,file) =>
569 this.popover_files.el.hide();
570 this.fileViewOpen(file, this.file_details.new_window, -1);
571 // if it's comming from the file dialog -> hide it...
578 public void gotoLine(int line)
584 if (file.xtype == "PlainFile") {
585 this.switchState (State.CODEONLY);
587 this.code_editor_tab.scroll_to_line(line);
592 this.switchState (State.PREVIEW);
595 // fixme - show the editing tab.
597 var node = file.lineToNode(line);
599 this.left_tree.model.selectNode(node);
600 var prop = node.lineToProp(line);
603 GLib.debug("could not find prop at line %d", line);
606 this.left_props.view.editProp(prop);
613 if (this.project.xtype == "Gtk") {
614 this.window_gladeview.scroll_to_line(line);
616 this.window_rooview.scroll_to_line(line);
621 var node = file.lineToNode(line);
623 this.left_tree.model.selectNode(node);
624 //var prop = node.lineToProp(line);
628 this.window_rooview.scroll_to_line(line);
634 public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
636 var existing = BuilderApplication.getWindow(file);
638 if (existing != null) {
639 existing.el.present();
640 existing.windowstate.gotoLine(line);
646 this.popover_files.el.hide();
647 BuilderApplication.newWindow(file, line);
652 this.win.project = file.project;
653 this.project = file.project;
655 BuilderApplication.updateWindows();
657 file.getLanguageServer().document_open(file);
658 BuilderApplication.showSpinner("spinner", "document open sent");
660 if (file.xtype == "PlainFile") {
661 this.win.codeeditviewbox.el.show();
662 this.switchState (State.CODEONLY);
666 this.code_editor_tab.show(file, null, null);
670 this.switchState (State.PREVIEW);
671 // this triggers loadItems..
672 this.left_tree.model.loadFile(file);
680 var ctr= this.win.rooviewbox.el;
683 if (file.project.xtype == "Roo" ) {
684 // removes all the childe elemnts from rooviewbox
685 while( ctr.get_last_child() != null) {
686 ctr.remove(ctr.get_last_child());
689 ctr.append(this.window_rooview.el);
691 if (file.xtype != "PlainFile") {
693 this.window_rooview.loadFile(file);
694 this.window_rooview.el.show();
700 while( ctr.get_last_child() != null) {
701 ctr.remove(ctr.get_last_child());
704 ctr.append(this.window_gladeview.el);
706 if (file.xtype != "PlainFile") {
708 this.window_gladeview.loadFile(file);
709 this.window_gladeview.el.show();
713 print("OPEN : " + file.name);
714 if (file.xtype != "PlainFile") {
715 // hide the file editor.
716 this.win.codeeditviewbox.el.hide();
717 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
721 BuilderApplication.updateCompileResults();
727 public void fileViewOpenPlain(string fname)
730 this.switchState (State.CODEONLY);
731 this.code_editor.showPlainFile(fname);
735 // --------- webkit view
736 public void webkitViewInit()
738 this.window_rooview =new Xcls_WindowRooView();
739 this.window_rooview.main_window = this.win;
740 this.window_rooview.ref();
741 this.win.rooviewbox.el.append(this.window_rooview.el);
743 this.window_rooview.el.show();
744 this.win.rooviewbox.el.hide();
750 public void gtkViewInit()
755 this.window_gladeview =new Xcls_GtkView( );
756 this.window_gladeview.ref();
757 this.window_gladeview.main_window = this.win;
764 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
766 var ae = this.left_tree.getActiveElement();
770 this.rightpalete.hide();
771 if (this.add_props.el.parent == null) {
772 this.add_props.el.set_parent(btn);
774 this.add_props.el.set_position(Gtk.PositionType.RIGHT);
777 this.win.project.palete, //Palete.factory(this.win.project.xtype),
778 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
785 public void showAddObject(Gtk.Widget btn, JsRender.Node? on_node)
789 this.add_props.hide();
791 this.add_props.el.set_position(Gtk.PositionType.RIGHT);
793 //this.rightpalete.el.set_parent(btn);
795 this.rightpalete.show(
796 this.left_tree.getActiveFile().palete(),
797 on_node == null ? "*top" : on_node.fqn(),
804 public void switchState(State new_state)
807 // if the new state and the old state are the same..
809 if (new_state == this.state) {
813 // anything to do beforehand?
815 switch (this.state) {
820 // stop editing the editor tab.
821 // always save before calling switch state to preview?
823 this.code_editor_tab.reset();
825 if (this.left_tree.getActiveFile() != null) {
826 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
827 this.window_rooview.createThumb();
829 this.window_gladeview.createThumb();
832 // normally we are going from preview to another state.
833 // and different windows hide the preview in differnt ways..
843 this.state = new_state;
846 switch (this.state) {
848 case State.PREVIEW: // this is the default state when working...
849 this.win.leftpane.el.show();
850 this.win.editpane.el.show(); // holder for tree and properties..
851 this.win.rooviewbox.el.show();
852 this.win.codeeditviewbox.el.hide();
856 this.win.leftpane.el.show();
857 this.win.editpane.el.show();
858 this.win.rooviewbox.el.hide();
859 this.win.codeeditviewbox.el.show();
860 this.code_editor_tab.el.show();
864 this.win.leftpane.el.hide();
865 this.win.codeeditviewbox.el.show();
866 this.win.rooviewbox.el.hide();
867 this.code_editor_tab.el.show();