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;
20 public State state = State.NONE;
22 public bool children_loaded = false;
24 public Project.Project project;
25 public JsRender.JsRender file;
27 public Xcls_WindowLeftTree left_tree;
28 public Xcls_PopoverAddProp add_props;
29 public Xcls_LeftProps left_props;
30 public Xcls_RooProjectSettings roo_projectsettings_pop;
31 public ValaProjectSettingsPopover vala_projectsettings_pop;
32 public Xcls_PopoverAddObject rightpalete;
33 //public Xcls_PopoverEditor code_editor_popover;
34 public Editor code_editor_tab;
35 public Xcls_WindowRooView window_rooview;
36 public Xcls_GtkView window_gladeview;
37 public Xcls_PopoverFiles popover_files;
39 //public Xcls_ClutterFiles clutterfiles;
40 //public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized..
42 public DialogTemplateSelect template_select;
44 public Xcls_PopoverFileDetails file_details;
45 public Xcls_ValaCompileResults compile_results;
48 public Xcls_DialogPluginWebkit webkit_plugin;
51 //public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
52 public Json.Object last_compile_result;
55 public WindowState(Xcls_MainWindow win)
64 // on clutter space...
65 this.projectEditInit();
67 //this.codePopoverEditInit();
68 //this.projectListInit();
69 //this.fileViewInit();
78 this.webkitViewInit();
82 this.fileDetailsInit();
84 this.webkit_plugin = new Xcls_DialogPluginWebkit();
85 this.template_select = new DialogTemplateSelect();
86 this.children_loaded = true;
90 BuilderApplication.valasource.compiled.connect(this.showCompileResult);
92 this.compile_results = new Xcls_ValaCompileResults(); // the poup dialogs with results in.
93 this.compile_results.window = this.win;
94 BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
96 this.win.statusbar_compilestatus_label.el.hide();
97 this.win.statusbar_run.el.hide();
98 this.win.search_results.el.hide();
100 this.popover_files = new Xcls_PopoverFiles();
101 this.popover_files.setMainWindow(this.win);
107 public void leftTreeInit()
110 this.left_tree = new Xcls_WindowLeftTree();
111 this.left_tree.ref();
112 this.left_tree.main_window = this.win;
114 this.win.leftpane.el.remove(this.win.editpane.el);
115 //this.win.tree.el.remove(this.left_tree.el);
116 this.win.leftpane.el.add(this.left_tree.el);
119 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
120 this.left_tree.el.show_all();
122 this.left_tree.before_node_change.connect(() => {
123 // if the node change is caused by the editor (code preview)
124 if (this.left_tree.view.lastEventSource == "editor") {
127 return this.leftTreeBeforeChange();
130 // node selected -- only by clicking?
131 this.left_tree.node_selected.connect((sel, source) => {
132 if (source == "editor") {
135 if (this.file.xtype == "Roo") {
136 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
138 this.window_gladeview.sourceview.nodeSelected(sel);
142 this.left_tree.node_selected.connect((sel, source) => {
143 this.leftTreeNodeSelected(sel, source);
146 this.left_tree.changed.connect(() => {
147 GLib.debug("LEFT TREE: Changed fired\n");
149 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
150 this.window_rooview.requestRedraw();
152 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
159 public bool leftTreeBeforeChange()
161 // in theory code editor has to hide before tree change occurs.
162 //if (this.state != State.CODE) {
163 this.left_props.finish_editing();
165 if (this.state == State.CODE) {
166 this.code_editor_tab.saveContents();
167 this.switchState(State.PREVIEW);
173 //if (!this.code_editor.saveContents()) {
179 int tree_width = 300;
180 int props_width = 300;
182 public void leftTreeNodeSelected(JsRender.Node? sel, string source)
185 // do we really want to flip paletes if differnt nodes are selected
186 // showing palete should be deliberate thing..
189 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
191 this.add_props.hide(); // always hide add node/add listener if we change node.
192 this.rightpalete.hide();
194 this.left_props.load(this.left_tree.getActiveFile(), sel);
196 var outerpane = this.win.mainpane.el;
197 var innerpane = this.win.editpane.el;
199 if (this.win.editpane.el.parent != null && sel != null) {
200 // select another node... no change to show hide/resize
205 // remove win.editpane from leftpane
206 // remove lefttree from from win.tree
207 // add win.tree to leftpane
208 if (this.win.editpane.el.parent != null) {
209 this.props_width = outerpane.get_position() - innerpane.get_position();
210 this.tree_width = innerpane.get_position();
211 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
213 this.win.leftpane.el.remove(this.win.editpane.el);
214 this.win.tree.el.remove(this.left_tree.el);
215 this.win.leftpane.el.add(this.left_tree.el);
219 //GLib.debug("Hide Properties");
220 outerpane.show_all(); // make sure it's visiable..
221 this.left_props.el.hide();
222 GLib.debug("set position: %d", this.tree_width);
223 outerpane.set_position(this.tree_width);
224 //outerpane.set_position(int.max(250,innerpane.get_position()));
225 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
229 // at this point we are showing the outer only,
234 this.tree_width = outerpane.get_position();
236 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
238 // remove this.ldeftree from this.win.leftpane
239 this.win.leftpane.el.remove(this.left_tree.el);
240 this.win.tree.el.add(this.left_tree.el);
241 this.win.leftpane.el.add(this.win.editpane.el);
246 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
247 // at start (hidden) - outer = 400 inner = 399
248 // expanded out -> outer = 686, inner = 399
249 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
250 this.left_props.el.show_all();
251 //if (!this.left_props.el.visible) {
253 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
254 outerpane.set_position(this.tree_width + this.props_width);
255 innerpane.set_position(this.tree_width);
256 /* var cw = outerpane.el.get_position();
257 var rw = int.min(this.left_props.el.width_request, 150);
258 print("outerpos : %d, innerpos : %d", cw + rw, cw);
260 innerpane.set_position(cw); */
261 this.left_props.el.show();
272 // if either of these are active.. then we should update them??
278 make outerpane = {current width of left pane} + width of props
279 make innerpane = {current width of left pane}
285 var outerpane = _this.main_window.leftpane.el;
286 var pane = _this.main_window.editpane.el;
290 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
291 GLib.Timeout.add_seconds(1, () => {
294 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
295 (int) (pane.max_position * 0.2f) :
296 pane.max_position-try_size);
297 return GLib.Source.REMOVE;
303 switch (this.state) {
306 this.switchState(State.PREVIEW);
321 public void propsListInit()
324 this.left_props =new Xcls_LeftProps();
325 this.left_props.ref();
326 this.left_props.main_window = this.win;
327 this.win.props.el.pack_start(this.left_props.el,true, true,0);
328 this.left_props.el.show_all();
330 this.left_props.show_editor.connect( (file, node, prop) => {
331 this.switchState(State.CODE);
334 this.code_editor_tab.show(
344 // not sure if this is needed - as closing the popvoer should save it.
345 this.left_props.stop_editor.connect( () => {
346 var ret = this.code_editor_tab.saveContents();
350 this.switchState(State.PREVIEW);
355 this.left_props.changed.connect(() => {
356 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
357 this.window_rooview.requestRedraw();
359 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
361 this.left_tree.model.updateSelected();
363 if (this.file.xtype=="Gtk") {
364 BuilderApplication.valasource.checkFileSpawn(this.file);
371 //------------- projects edit
373 public void projectEditInit()
375 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
376 this.roo_projectsettings_pop.ref(); /// really?
378 this.vala_projectsettings_pop =new ValaProjectSettingsPopover();
379 this.vala_projectsettings_pop.ref();
380 this.vala_projectsettings_pop.window = this.win;
382 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
385 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
386 // in theory active file can only be rooo...
387 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
389 this.window_rooview.view.renderJS(true);
390 this.roo_projectsettings_pop.el.hide();
392 if (btn == "apply") {
393 this.window_rooview.view.renderJS(true);
397 // do nothing for gtk..
399 if (btn == "save" || btn == "apply") {
400 this.win.project.save();
403 //this.switchState (State.PREVIEW);
409 public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr)
416 var active_file = this.left_tree.getActiveFile() ;
417 if (active_file != null) {
418 xtype = active_file.xtype;
421 return; // no active project
422 // we might be on the file brower..
423 //pr = this.left_projects.getSelectedProject();
429 if (pr.xtype == "") {
432 if (pr.xtype == "Roo" ) {
433 this.roo_projectsettings_pop.show(btn,pr);
438 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
443 // ----------- object adding
444 public void objectAddInit()
447 this.rightpalete = new Xcls_PopoverAddObject();
448 this.rightpalete.mainwindow = this.win;
449 this.rightpalete.ref(); /// really?
450 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
453 var stage = this.win.objectview.el.get_stage();
454 stage.set_background_color( Clutter.Color.from_string("#000"));
458 // ----------- properties adding list...
459 // listener uses the properties
460 public void propsAddInit()
463 this.add_props = new Xcls_PopoverAddProp();
464 this.add_props.mainwindow = this.win;
465 this.add_props.ref(); /// really?
466 // don't need to add it..
467 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
470 //var stage = this.win.addpropsview.el.get_stage();
471 //stage.set_background_color( Clutter.Color.from_string("#000"));
474 this.add_props.select.connect( (prop) => {
476 this.left_props.addProp(prop);
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.add(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 // we do not need to call spawn... - as it's already called by the editor?
529 public void codePopoverEditInit()
531 this.code_editor_popover = new Xcls_PopoverEditor();
532 //this.code_editor.ref(); /// really?
534 this.code_editor_popover.setMainWindow( this.win);
536 this.code_editor_popover.editor.save.connect( () => {
538 this.left_tree.model.updateSelected();
539 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
540 this.window_rooview.requestRedraw();
542 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
544 // we do not need to call spawn... - as it's already called by the editor?
550 // ----------- list of projects on left
552 public void projectListInit()
555 this.left_projects = new Xcls_WindowLeftProjects();
556 this.left_projects.ref();
557 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
558 this.left_projects.el.show_all();
559 this.left_projects.project_selected.connect((proj) => {
560 this.buttonsShowHide();
562 this.clutterfiles.loadProject(proj);
570 // ----------- file view
571 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
573 this.popover_files.show(btn, project, new_window);
579 public void fileDetailsInit()
581 this.file_details = new Xcls_PopoverFileDetails();
582 this.file_details.mainwindow = this.win;
583 // force it modal to the main window..
585 this.file_details.success.connect((project,file) =>
587 this.fileViewOpen(file, this.file_details.new_window, -1);
593 public void gotoLine(int line)
596 if (file.xtype == "PlainFile") {
597 this.switchState (State.CODEONLY);
599 this.code_editor_tab.scroll_to_line(line);
603 this.switchState (State.PREVIEW);
605 if (file.project.xtype == "Gtk" && line> -1 ) {
606 // fixme - show the editing tab.
607 this.window_gladeview.scroll_to_line(line);
609 // fixme - what about Roo?
615 public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
617 var existing = BuilderApplication.getWindow(file);
619 if (existing != null) {
620 existing.el.present();
621 existing.windowstate.gotoLine(line);
626 BuilderApplication.newWindow(file, line);
631 this.win.project = file.project;
632 this.project = file.project;
634 BuilderApplication.updateWindows();
636 if (file.xtype == "PlainFile") {
637 this.win.codeeditviewbox.el.show();
638 this.switchState (State.CODEONLY);
640 this.code_editor_tab.show(file, null, null);
644 this.switchState (State.PREVIEW);
645 // this triggers loadItems..
646 this.left_tree.model.loadFile(file);
652 var ctr= this.win.rooviewbox.el;
655 if (file.project.xtype == "Roo" ) {
656 // removes all the childe elemnts from rooviewbox
658 ctr.foreach( (w) => { ctr.remove(w); });
660 ctr.add(this.window_rooview.el);
662 if (file.xtype != "PlainFile") {
664 this.window_rooview.loadFile(file);
665 this.window_rooview.el.show_all();
671 ctr.foreach( (w) => { ctr.remove(w); });
673 ctr.add(this.window_gladeview.el);
675 if (file.xtype != "PlainFile") {
677 this.window_gladeview.loadFile(file);
678 this.window_gladeview.el.show_all();
682 print("OPEN : " + file.name);
683 if (file.xtype != "PlainFile") {
684 // hide the file editor.
685 this.win.codeeditviewbox.el.hide();
686 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
688 this.win.setTitle(file.project.name + " : " + file.name);
695 public void fileViewOpenPlain(string fname)
698 this.switchState (State.CODEONLY);
699 this.code_editor.showPlainFile(fname);
703 // --------- webkit view
704 public void webkitViewInit()
706 this.window_rooview =new Xcls_WindowRooView();
707 this.window_rooview.main_window = this.win;
708 this.window_rooview.ref();
709 this.win.rooviewbox.el.add(this.window_rooview.el);
711 this.window_rooview.el.show_all();
712 this.win.rooviewbox.el.hide();
718 public void gtkViewInit()
723 this.window_gladeview =new Xcls_GtkView( );
724 this.window_gladeview.ref();
725 this.window_gladeview.main_window = this.win;
732 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
734 var ae = this.left_tree.getActiveElement();
738 this.rightpalete.hide();
740 this.add_props.el.show_all();
742 this.win.project.palete, //Palete.factory(this.win.project.xtype),
743 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
750 public void showAddObject(Gtk.Widget btn)
753 var n = this.left_tree.getActiveElement();
754 this.add_props.hide();
755 this.rightpalete.el.show_all();
756 this.rightpalete.show(
757 this.left_tree.getActiveFile().palete(),
758 n == null ? "*top" : n.fqn(),
765 public void switchState(State new_state)
768 // if the new state and the old state are the same..
770 if (new_state == this.state) {
774 // anything to do beforehand?
776 switch (this.state) {
781 // stop editing the editor tab.
782 // always save before calling switch state to preview?
784 this.code_editor_tab.reset();
786 if (this.left_tree.getActiveFile() != null) {
787 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
788 this.window_rooview.createThumb();
790 this.window_gladeview.createThumb();
793 // normally we are going from preview to another state.
794 // and different windows hide the preview in differnt ways..
800 this.state = new_state;
801 this.buttonsShowHide();
803 switch (this.state) {
805 case State.PREVIEW: // this is the default state when working...
806 this.win.leftpane.el.show();
807 this.win.editpane.el.show(); // holder for tree and properties..
808 this.win.rooviewbox.el.show();
809 this.win.codeeditviewbox.el.hide();
813 this.win.leftpane.el.show();
814 this.win.editpane.el.show();
815 this.win.rooviewbox.el.hide();
816 this.win.codeeditviewbox.el.show();
817 this.code_editor_tab.el.show_all();
821 this.win.leftpane.el.hide();
822 this.win.codeeditviewbox.el.show();
823 this.win.rooviewbox.el.hide();
824 this.code_editor_tab.el.show_all();
835 // -- buttons show hide.....
837 public void buttonsShowHide()
839 // basically hide everything, then show the relivant..
842 //this.win.openbtn.el.hide();
843 //this.win.openbackbtn.el.hide();
845 //this.win.backbutton.el.hide();
852 this.win.search_entry.el.hide();
853 this.win.search_results.el.hide();
854 switch (this.state) {
856 case State.PREVIEW: // this is the default state when working...
862 this.win.search_entry.el.show();
864 // this.win.openbtn.el.show();
869 // this.win.openbtn.el.show();
870 this.win.search_entry.el.show();
876 if (this.left_projects.getSelectedProject() != null ) {
877 if (this.left_tree.getActiveFile() != null) {
879 this.win.openbackbtn.el.show();
881 this.win.addfilebutton.el.show();
882 this.win.search_entry.el.show();
883 this.win.projecteditbutton.el.show();
887 this.win.addprojectbutton.el.show();
888 this.win.delprojectbutton.el.show();
902 public void showCompileResult(Json.Object obj)
904 // vala has finished compiling...
906 // stop the spinner...
907 GLib.debug("vala compiled Built Project: %s Window Project %s",
909 BuilderApplication.valasource.file == null ? "No file?" : (
911 BuilderApplication.valasource.file.project == null ? "No Project" : BuilderApplication.valasource.file.project.fn
913 this.project != null ? this.project.fn : "No Project?"
918 if (this.project != null &&
919 BuilderApplication.valasource.file != null &&
920 BuilderApplication.valasource.file.project != null &&
921 this.project.fn != BuilderApplication.valasource.file.project.fn) {
922 GLib.debug("skip update - not our project");
926 var generator = new Json.Generator ();
927 var n = new Json.Node(Json.NodeType.OBJECT);
929 generator.set_root (n);
930 print("result :%s", generator.to_data (null));
933 var buf = this.code_editor_tab.buffer;
934 buf.check_running = false;
935 var has_errors = false;
937 if (obj.has_member("ERR-TOTAL")) {
938 if (obj.get_int_member("ERR-TOTAL")> 0) {
941 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
943 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
946 if (obj.has_member("WARN-TOTAL")) {
948 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
950 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
953 if (obj.has_member("DEPR-TOTAL")) {
955 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
958 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
960 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
961 if ( this.state == State.CODEONLY) {
962 buf.highlightErrorsJson("ERR", obj);
963 buf.highlightErrorsJson("WARN", obj);
964 buf.highlightErrorsJson("DEPR", obj);
967 this.win.statusbar_compilestatus_label.el.hide();
968 this.win.statusbar_run.el.hide();
970 this.win.statusbar_compilestatus_label.el.show();
971 this.win.statusbar_run.el.show();
973 if (this.file.xtype == "Gtk") {
974 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
975 var gbuf = this.window_gladeview.sourceview;
976 gbuf.highlightErrorsJson("ERR", obj);
977 gbuf.highlightErrorsJson("WARN", obj);
978 gbuf.highlightErrorsJson("DEPR", obj);
981 this.win.statusbar_run.el.show();
986 if (this.file.xtype == "Roo") {
987 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
988 var gbuf = this.window_rooview.sourceview;
989 gbuf.highlightErrorsJson("ERR", obj);
990 gbuf.highlightErrorsJson("WARN", obj);
991 gbuf.highlightErrorsJson("DEPR", obj);
995 this.last_compile_result = obj;