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;
23 public JsRender.JsRender file;
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 Xcls_PopoverFiles 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 public Xcls_DialogPluginWebkit webkit_plugin;
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();
82 this.webkit_plugin = new Xcls_DialogPluginWebkit();
83 this.template_select = new DialogTemplateSelect();
84 this.children_loaded = true;
88 BuilderApplication.valasource.compiled.connect(this.showCompileResult);
90 this.compile_results = new Xcls_ValaCompileResults(); // the poup dialogs with results in.
91 this.compile_results.window = this.win;
92 BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
94 this.win.statusbar_compilestatus_label.el.hide();
95 this.win.statusbar_run.el.hide();
98 this.popover_files = new Xcls_PopoverFiles();
99 this.popover_files.setMainWindow(this.win);
105 public void leftTreeInit()
108 this.left_tree = new Xcls_WindowLeftTree();
109 this.left_tree.ref();
110 this.left_tree.main_window = this.win;
112 this.win.leftpane.el.remove(this.win.editpane.el);
113 //this.win.tree.el.remove(this.left_tree.el);
114 this.win.leftpane.el.add(this.left_tree.el);
117 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
118 this.left_tree.el.show_all();
120 this.left_tree.before_node_change.connect(() => {
121 // if the node change is caused by the editor (code preview)
122 if (this.left_tree.view.lastEventSource == "editor") {
125 return this.leftTreeBeforeChange();
128 // node selected -- only by clicking?
129 this.left_tree.node_selected.connect((sel, source) => {
130 //if (source == "editor") {
133 if (this.file.xtype == "Roo") {
134 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
136 this.window_gladeview.sourceview.nodeSelected(sel, true);
140 this.left_tree.node_selected.connect((sel, source) => {
141 this.leftTreeNodeSelected(sel, source);
144 this.left_tree.changed.connect(() => {
145 GLib.debug("LEFT TREE: Changed fired\n");
147 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
148 this.window_rooview.requestRedraw();
150 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
157 public bool leftTreeBeforeChange()
159 // in theory code editor has to hide before tree change occurs.
160 //if (this.state != State.CODE) {
161 this.left_props.finish_editing();
163 if (this.state == State.CODE) {
164 this.code_editor_tab.saveContents();
165 this.switchState(State.PREVIEW);
171 //if (!this.code_editor.saveContents()) {
177 int tree_width = 300;
178 int props_width = 300;
180 public void leftTreeNodeSelected(JsRender.Node? sel, string source)
183 // do we really want to flip paletes if differnt nodes are selected
184 // showing palete should be deliberate thing..
187 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
189 this.add_props.hide(); // always hide add node/add listener if we change node.
190 this.rightpalete.hide();
192 this.left_props.load(this.left_tree.getActiveFile(), sel);
194 var outerpane = this.win.mainpane.el;
195 var innerpane = this.win.editpane.el;
197 if (this.win.editpane.el.parent != null && sel != null) {
198 // select another node... no change to show hide/resize
203 // remove win.editpane from leftpane
204 // remove lefttree from from win.tree
205 // add win.tree to leftpane
206 if (this.win.editpane.el.parent != null) {
207 this.props_width = outerpane.get_position() - innerpane.get_position();
208 this.tree_width = innerpane.get_position();
209 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
211 this.win.leftpane.el.remove(this.win.editpane.el);
212 this.win.tree.el.remove(this.left_tree.el);
213 this.win.leftpane.el.add(this.left_tree.el);
217 //GLib.debug("Hide Properties");
218 outerpane.show_all(); // make sure it's visiable..
219 this.left_props.el.hide();
220 GLib.debug("set position: %d", this.tree_width);
221 outerpane.set_position(this.tree_width);
222 //outerpane.set_position(int.max(250,innerpane.get_position()));
223 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
227 // at this point we are showing the outer only,
232 this.tree_width = outerpane.get_position();
234 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
236 // remove this.ldeftree from this.win.leftpane
237 this.win.leftpane.el.remove(this.left_tree.el);
238 this.win.tree.el.add(this.left_tree.el);
239 this.win.leftpane.el.add(this.win.editpane.el);
244 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
245 // at start (hidden) - outer = 400 inner = 399
246 // expanded out -> outer = 686, inner = 399
247 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
248 this.left_props.el.show_all();
249 //if (!this.left_props.el.visible) {
251 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
252 outerpane.set_position(this.tree_width + this.props_width);
253 innerpane.set_position(this.tree_width);
254 /* var cw = outerpane.el.get_position();
255 var rw = int.min(this.left_props.el.width_request, 150);
256 print("outerpos : %d, innerpos : %d", cw + rw, cw);
258 innerpane.set_position(cw); */
259 this.left_props.el.show();
270 // if either of these are active.. then we should update them??
276 make outerpane = {current width of left pane} + width of props
277 make innerpane = {current width of left pane}
283 var outerpane = _this.main_window.leftpane.el;
284 var pane = _this.main_window.editpane.el;
288 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
289 GLib.Timeout.add_seconds(1, () => {
292 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
293 (int) (pane.max_position * 0.2f) :
294 pane.max_position-try_size);
295 return GLib.Source.REMOVE;
301 switch (this.state) {
304 this.switchState(State.PREVIEW);
319 public void propsListInit()
322 this.left_props =new Xcls_LeftProps();
323 this.left_props.ref();
324 this.left_props.main_window = this.win;
325 this.win.props.el.pack_start(this.left_props.el,true, true,0);
326 this.left_props.el.show_all();
328 this.left_props.show_editor.connect( (file, node, prop) => {
329 this.switchState(State.CODE);
332 this.code_editor_tab.show(
342 // not sure if this is needed - as closing the popvoer should save it.
343 this.left_props.stop_editor.connect( () => {
344 var ret = this.code_editor_tab.saveContents();
348 this.switchState(State.PREVIEW);
353 this.left_props.changed.connect(() => {
354 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
355 this.window_rooview.requestRedraw();
357 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
359 this.left_tree.model.updateSelected();
361 if (this.file.xtype=="Gtk") {
362 BuilderApplication.valasource.checkFileSpawn(this.file);
369 //------------- projects edit
371 public void projectEditInit()
373 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
374 this.roo_projectsettings_pop.ref(); /// really?
376 this.vala_projectsettings_pop =new ValaProjectSettingsPopover();
377 this.vala_projectsettings_pop.ref();
378 this.vala_projectsettings_pop.window = this.win;
380 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
383 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
384 if (btn == "save" || btn == "apply") {
385 this.roo_projectsettings_pop.project.save();
389 // in theory active file can only be rooo...
390 var ep = this.roo_projectsettings_pop.project;
391 foreach(var ww in BuilderApplication.windows) {
392 if (ww.windowstate.project.fn == ep.fn && ww.windowstate.file.xtype == "Roo") {
394 ww.windowstate.window_rooview.view.renderJS(true);
402 this.roo_projectsettings_pop.el.hide();
404 //this.switchState (State.PREVIEW);
410 public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr)
417 var active_file = this.left_tree.getActiveFile() ;
418 if (active_file != null) {
419 xtype = active_file.xtype;
422 return; // no active project
423 // we might be on the file brower..
424 //pr = this.left_projects.getSelectedProject();
430 if (pr.xtype == "") {
433 if (pr.xtype == "Roo" ) {
434 this.roo_projectsettings_pop.show(btn,pr);
439 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
444 // ----------- object adding
445 public void objectAddInit()
448 this.rightpalete = new Xcls_PopoverAddObject();
449 this.rightpalete.mainwindow = this.win;
450 this.rightpalete.ref(); /// really?
451 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
454 var stage = this.win.objectview.el.get_stage();
455 stage.set_background_color( Clutter.Color.from_string("#000"));
459 // ----------- properties adding list...
460 // listener uses the properties
461 public void propsAddInit()
464 this.add_props = new Xcls_PopoverAddProp();
465 this.add_props.mainwindow = this.win;
466 this.add_props.ref(); /// really?
467 // don't need to add it..
468 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
471 //var stage = this.win.addpropsview.el.get_stage();
472 //stage.set_background_color( Clutter.Color.from_string("#000"));
475 this.add_props.select.connect( (prop) => {
477 this.left_props.addProp(prop);
481 public void propsAddShow()
485 public void propsAddHide()
491 // ----------- Add / Edit listener
492 // listener uses the properties
493 //public void listenerInit() { }
494 public void listenerShow()
498 public void listenerHide()
503 // -------------- codeEditor
505 public void codeEditInit()
507 this.code_editor_tab = new Editor();
508 //this.code_editor.ref(); /// really?
509 this.win.codeeditviewbox.el.add(this.code_editor_tab.el);
511 this.win.codeeditviewbox.el.hide();
512 this.code_editor_tab.window = this.win;
516 this.code_editor_tab.save.connect( () => {
518 this.left_tree.model.updateSelected();
519 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
520 this.window_rooview.requestRedraw();
522 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
524 // we do not need to call spawn... - as it's already called by the editor?
530 public void codePopoverEditInit()
532 this.code_editor_popover = new Xcls_PopoverEditor();
533 //this.code_editor.ref(); /// really?
535 this.code_editor_popover.setMainWindow( this.win);
537 this.code_editor_popover.editor.save.connect( () => {
539 this.left_tree.model.updateSelected();
540 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
541 this.window_rooview.requestRedraw();
543 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
545 // we do not need to call spawn... - as it's already called by the editor?
551 // ----------- list of projects on left
553 public void projectListInit()
556 this.left_projects = new Xcls_WindowLeftProjects();
557 this.left_projects.ref();
558 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
559 this.left_projects.el.show_all();
560 this.left_projects.project_selected.connect((proj) => {
561 this.buttonsShowHide();
563 this.clutterfiles.loadProject(proj);
571 // ----------- file view
572 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
574 this.popover_files.show(btn, project, new_window);
580 public void fileDetailsInit()
582 this.file_details = new Xcls_PopoverFileDetails();
583 this.file_details.mainwindow = this.win;
584 // force it modal to the main window..
586 this.file_details.success.connect((project,file) =>
588 this.fileViewOpen(file, this.file_details.new_window, -1);
589 // if it's comming from the file dialog -> hide it...
596 public void gotoLine(int line)
602 if (file.xtype == "PlainFile") {
603 this.switchState (State.CODEONLY);
605 this.code_editor_tab.scroll_to_line(line);
609 this.switchState (State.PREVIEW);
611 if (file.project.xtype == "Gtk" && line> -1 ) {
612 // fixme - show the editing tab.
613 this.window_gladeview.scroll_to_line(line);
615 this.window_rooview.scroll_to_line(line);
616 // fixme - what about Roo?
622 public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
624 var existing = BuilderApplication.getWindow(file);
626 if (existing != null) {
627 existing.el.present();
628 existing.windowstate.gotoLine(line);
634 this.popover_files.el.hide();
635 BuilderApplication.newWindow(file, line);
640 this.win.project = file.project;
641 this.project = file.project;
643 BuilderApplication.updateWindows();
645 if (file.xtype == "PlainFile") {
646 this.win.codeeditviewbox.el.show();
647 this.switchState (State.CODEONLY);
649 this.code_editor_tab.show(file, null, null);
653 this.switchState (State.PREVIEW);
654 // this triggers loadItems..
655 this.left_tree.model.loadFile(file);
661 var ctr= this.win.rooviewbox.el;
664 if (file.project.xtype == "Roo" ) {
665 // removes all the childe elemnts from rooviewbox
667 ctr.foreach( (w) => { ctr.remove(w); });
669 ctr.add(this.window_rooview.el);
671 if (file.xtype != "PlainFile") {
673 this.window_rooview.loadFile(file);
674 this.window_rooview.el.show_all();
680 ctr.foreach( (w) => { ctr.remove(w); });
682 ctr.add(this.window_gladeview.el);
684 if (file.xtype != "PlainFile") {
686 this.window_gladeview.loadFile(file);
687 this.window_gladeview.el.show_all();
691 print("OPEN : " + file.name);
692 if (file.xtype != "PlainFile") {
693 // hide the file editor.
694 this.win.codeeditviewbox.el.hide();
695 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
697 this.win.setTitle(file.project.name + " : " + file.name);
704 public void fileViewOpenPlain(string fname)
707 this.switchState (State.CODEONLY);
708 this.code_editor.showPlainFile(fname);
712 // --------- webkit view
713 public void webkitViewInit()
715 this.window_rooview =new Xcls_WindowRooView();
716 this.window_rooview.main_window = this.win;
717 this.window_rooview.ref();
718 this.win.rooviewbox.el.add(this.window_rooview.el);
720 this.window_rooview.el.show_all();
721 this.win.rooviewbox.el.hide();
727 public void gtkViewInit()
732 this.window_gladeview =new Xcls_GtkView( );
733 this.window_gladeview.ref();
734 this.window_gladeview.main_window = this.win;
741 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
743 var ae = this.left_tree.getActiveElement();
747 this.rightpalete.hide();
749 this.add_props.el.show_all();
751 this.win.project.palete, //Palete.factory(this.win.project.xtype),
752 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
759 public void showAddObject(Gtk.Widget btn)
762 var n = this.left_tree.getActiveElement();
763 this.add_props.hide();
764 this.rightpalete.el.show_all();
765 this.rightpalete.show(
766 this.left_tree.getActiveFile().palete(),
767 n == null ? "*top" : n.fqn(),
774 public void switchState(State new_state)
777 // if the new state and the old state are the same..
779 if (new_state == this.state) {
783 // anything to do beforehand?
785 switch (this.state) {
790 // stop editing the editor tab.
791 // always save before calling switch state to preview?
793 this.code_editor_tab.reset();
795 if (this.left_tree.getActiveFile() != null) {
796 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
797 this.window_rooview.createThumb();
799 this.window_gladeview.createThumb();
802 // normally we are going from preview to another state.
803 // and different windows hide the preview in differnt ways..
809 this.state = new_state;
810 this.buttonsShowHide();
812 switch (this.state) {
814 case State.PREVIEW: // this is the default state when working...
815 this.win.leftpane.el.show();
816 this.win.editpane.el.show(); // holder for tree and properties..
817 this.win.rooviewbox.el.show();
818 this.win.codeeditviewbox.el.hide();
822 this.win.leftpane.el.show();
823 this.win.editpane.el.show();
824 this.win.rooviewbox.el.hide();
825 this.win.codeeditviewbox.el.show();
826 this.code_editor_tab.el.show_all();
830 this.win.leftpane.el.hide();
831 this.win.codeeditviewbox.el.show();
832 this.win.rooviewbox.el.hide();
833 this.code_editor_tab.el.show_all();
844 // -- buttons show hide.....
846 public void buttonsShowHide()
848 // basically hide everything, then show the relivant..
851 //this.win.openbtn.el.hide();
852 //this.win.openbackbtn.el.hide();
854 //this.win.backbutton.el.hide();
862 switch (this.state) {
864 case State.PREVIEW: // this is the default state when working...
872 // this.win.openbtn.el.show();
877 // this.win.openbtn.el.show();
884 if (this.left_projects.getSelectedProject() != null ) {
885 if (this.left_tree.getActiveFile() != null) {
887 this.win.openbackbtn.el.show();
889 this.win.addfilebutton.el.show();
890 this.win.search_entry.el.show();
891 this.win.projecteditbutton.el.show();
895 this.win.addprojectbutton.el.show();
896 this.win.delprojectbutton.el.show();
910 public void showCompileResult(Json.Object obj)
912 // vala has finished compiling...
914 // stop the spinner...
915 GLib.debug("vala compiled Built Project: %s Window Project %s",
917 BuilderApplication.valasource.file == null ? "No file?" : (
919 BuilderApplication.valasource.file.project == null ? "No Project" : BuilderApplication.valasource.file.project.fn
921 this.project != null ? this.project.fn : "No Project?"
926 if (this.project != null &&
927 BuilderApplication.valasource.file != null &&
928 BuilderApplication.valasource.file.project != null &&
929 this.project.fn != BuilderApplication.valasource.file.project.fn) {
930 GLib.debug("skip update - not our project");
934 var generator = new Json.Generator ();
935 var n = new Json.Node(Json.NodeType.OBJECT);
937 generator.set_root (n);
938 print("result :%s", generator.to_data (null));
941 var buf = this.code_editor_tab.buffer;
942 buf.check_running = false;
943 var has_errors = false;
945 if (obj.has_member("ERR-TOTAL")) {
946 if (obj.get_int_member("ERR-TOTAL")> 0) {
949 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
951 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
954 if (obj.has_member("WARN-TOTAL")) {
956 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
958 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
961 if (obj.has_member("DEPR-TOTAL")) {
963 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
966 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
968 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
969 if ( this.state == State.CODEONLY) {
970 buf.highlightErrorsJson("ERR", obj);
971 buf.highlightErrorsJson("WARN", obj);
972 buf.highlightErrorsJson("DEPR", obj);
975 this.win.statusbar_compilestatus_label.el.hide();
976 this.win.statusbar_run.el.hide();
978 this.win.statusbar_compilestatus_label.el.show();
979 this.win.statusbar_run.el.show();
981 if (this.file.xtype == "Gtk") {
982 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
983 var gbuf = this.window_gladeview.sourceview;
984 gbuf.highlightErrorsJson("ERR", obj);
985 gbuf.highlightErrorsJson("WARN", obj);
986 gbuf.highlightErrorsJson("DEPR", obj);
989 this.win.statusbar_run.el.show();
994 if (this.file.xtype == "Roo") {
995 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
996 var gbuf = this.window_rooview.sourceview;
997 gbuf.highlightErrorsJson("ERR", obj);
998 gbuf.highlightErrorsJson("WARN", obj);
999 gbuf.highlightErrorsJson("DEPR", obj);
1003 this.last_compile_result = obj;