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;
47 public Xcls_ValaCompileResults compile_results;
50 public Xcls_DialogPluginWebkit webkit_plugin;
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)
66 // on clutter space...
67 this.projectEditInit();
69 //this.codePopoverEditInit();
70 //this.projectListInit();
71 //this.fileViewInit();
80 this.webkitViewInit();
84 this.fileDetailsInit();
86 this.webkit_plugin = new Xcls_DialogPluginWebkit();
87 this.template_select = new DialogTemplateSelect();
88 this.children_loaded = true;
92 BuilderApplication.valasource.compiled.connect(this.showCompileResult);
94 this.compile_results = new Xcls_ValaCompileResults(); // the poup dialogs with results in.
95 this.compile_results.window = this.win;
96 BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
98 this.win.statusbar_compilestatus_label.el.hide();
99 this.win.statusbar_run.el.hide();
100 this.win.search_results.el.hide();
102 this.popover_files = new Xcls_PopoverFiles();
103 this.popover_files.setMainWindow(this.win);
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.add(this.left_tree.el);
121 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
122 this.left_tree.el.show_all();
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, source) => {
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);
144 this.left_tree.node_selected.connect((sel, source) => {
145 this.leftTreeNodeSelected(sel, source);
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 bool leftTreeBeforeChange()
163 // in theory code editor has to hide before tree change occurs.
164 //if (this.state != State.CODE) {
165 this.left_props.finish_editing();
167 if (this.state == State.CODE) {
168 this.code_editor_tab.saveContents();
169 this.switchState(State.PREVIEW);
175 //if (!this.code_editor.saveContents()) {
181 int tree_width = 300;
182 int props_width = 300;
184 public void leftTreeNodeSelected(JsRender.Node? sel, string source)
187 // do we really want to flip paletes if differnt nodes are selected
188 // showing palete should be deliberate thing..
191 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
193 this.add_props.hide(); // always hide add node/add listener if we change node.
194 this.rightpalete.hide();
196 this.left_props.load(this.left_tree.getActiveFile(), sel);
198 var outerpane = this.win.mainpane.el;
199 var innerpane = this.win.editpane.el;
201 if (this.win.editpane.el.parent != null && sel != null) {
202 // select another node... no change to show hide/resize
207 // remove win.editpane from leftpane
208 // remove lefttree from from win.tree
209 // add win.tree to leftpane
210 if (this.win.editpane.el.parent != null) {
211 this.props_width = outerpane.get_position() - innerpane.get_position();
212 this.tree_width = innerpane.get_position();
213 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
215 this.win.leftpane.el.remove(this.win.editpane.el);
216 this.win.tree.el.remove(this.left_tree.el);
217 this.win.leftpane.el.add(this.left_tree.el);
221 //GLib.debug("Hide Properties");
222 outerpane.show_all(); // make sure it's visiable..
223 this.left_props.el.hide();
224 GLib.debug("set position: %d", this.tree_width);
225 outerpane.set_position(this.tree_width);
226 //outerpane.set_position(int.max(250,innerpane.get_position()));
227 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
231 // at this point we are showing the outer only,
236 this.tree_width = outerpane.get_position();
238 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
240 // remove this.ldeftree from this.win.leftpane
241 this.win.leftpane.el.remove(this.left_tree.el);
242 this.win.tree.el.add(this.left_tree.el);
243 this.win.leftpane.el.add(this.win.editpane.el);
248 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
249 // at start (hidden) - outer = 400 inner = 399
250 // expanded out -> outer = 686, inner = 399
251 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
252 this.left_props.el.show_all();
253 //if (!this.left_props.el.visible) {
255 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
256 outerpane.set_position(this.tree_width + this.props_width);
257 innerpane.set_position(this.tree_width);
258 /* var cw = outerpane.el.get_position();
259 var rw = int.min(this.left_props.el.width_request, 150);
260 print("outerpos : %d, innerpos : %d", cw + rw, cw);
262 innerpane.set_position(cw); */
263 this.left_props.el.show();
274 // if either of these are active.. then we should update them??
280 make outerpane = {current width of left pane} + width of props
281 make innerpane = {current width of left pane}
287 var outerpane = _this.main_window.leftpane.el;
288 var pane = _this.main_window.editpane.el;
292 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
293 GLib.Timeout.add_seconds(1, () => {
296 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
297 (int) (pane.max_position * 0.2f) :
298 pane.max_position-try_size);
299 return GLib.Source.REMOVE;
305 switch (this.state) {
308 this.switchState(State.PREVIEW);
323 public void propsListInit()
326 this.left_props =new Xcls_LeftProps();
327 this.left_props.ref();
328 this.left_props.main_window = this.win;
329 this.win.props.el.pack_start(this.left_props.el,true, true,0);
330 this.left_props.el.show_all();
332 this.left_props.show_editor.connect( (file, node, prop) => {
333 this.switchState(State.CODE);
336 this.code_editor_tab.show(
346 // not sure if this is needed - as closing the popvoer should save it.
347 this.left_props.stop_editor.connect( () => {
348 var ret = this.code_editor_tab.saveContents();
352 this.switchState(State.PREVIEW);
357 this.left_props.changed.connect(() => {
358 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
359 this.window_rooview.requestRedraw();
361 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
363 this.left_tree.model.updateSelected();
365 if (this.file.xtype=="Gtk") {
366 BuilderApplication.valasource.checkFileSpawn(this.file);
373 //------------- projects edit
375 public void projectEditInit()
377 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
378 this.roo_projectsettings_pop.ref(); /// really?
380 this.vala_projectsettings_pop =new ValaProjectSettingsPopover();
381 this.vala_projectsettings_pop.ref();
382 this.vala_projectsettings_pop.window = this.win;
384 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
387 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
388 // in theory active file can only be rooo...
389 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
391 this.window_rooview.view.renderJS(true);
392 this.roo_projectsettings_pop.el.hide();
394 if (btn == "apply") {
395 this.window_rooview.view.renderJS(true);
399 // do nothing for gtk..
401 if (btn == "save" || btn == "apply") {
402 this.win.project.save();
405 //this.switchState (State.PREVIEW);
411 public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr)
418 var active_file = this.left_tree.getActiveFile() ;
419 if (active_file != null) {
420 xtype = active_file.xtype;
423 return; // no active project
424 // we might be on the file brower..
425 //pr = this.left_projects.getSelectedProject();
431 if (pr.xtype == "") {
434 if (pr.xtype == "Roo" ) {
435 this.roo_projectsettings_pop.show(btn,pr);
440 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
445 // ----------- object adding
446 public void objectAddInit()
449 this.rightpalete = new Xcls_PopoverAddObject();
450 this.rightpalete.mainwindow = this.win;
451 this.rightpalete.ref(); /// really?
452 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
455 var stage = this.win.objectview.el.get_stage();
456 stage.set_background_color( Clutter.Color.from_string("#000"));
460 // ----------- properties adding list...
461 // listener uses the properties
462 public void propsAddInit()
465 this.add_props = new Xcls_PopoverAddProp();
466 this.add_props.mainwindow = this.win;
467 this.add_props.ref(); /// really?
468 // don't need to add it..
469 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
472 //var stage = this.win.addpropsview.el.get_stage();
473 //stage.set_background_color( Clutter.Color.from_string("#000"));
476 this.add_props.select.connect( (prop) => {
478 this.left_props.addProp(prop);
482 public void propsAddShow()
486 public void propsAddHide()
492 // ----------- Add / Edit listener
493 // listener uses the properties
494 //public void listenerInit() { }
495 public void listenerShow()
499 public void listenerHide()
504 // -------------- codeEditor
506 public void codeEditInit()
508 this.code_editor_tab = new Editor();
509 //this.code_editor.ref(); /// really?
510 this.win.codeeditviewbox.el.add(this.code_editor_tab.el);
512 this.win.codeeditviewbox.el.hide();
513 this.code_editor_tab.window = this.win;
517 this.code_editor_tab.save.connect( () => {
519 this.left_tree.model.updateSelected();
520 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
521 this.window_rooview.requestRedraw();
523 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
525 // we do not need to call spawn... - as it's already called by the editor?
531 public void codePopoverEditInit()
533 this.code_editor_popover = new Xcls_PopoverEditor();
534 //this.code_editor.ref(); /// really?
536 this.code_editor_popover.setMainWindow( this.win);
538 this.code_editor_popover.editor.save.connect( () => {
540 this.left_tree.model.updateSelected();
541 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
542 this.window_rooview.requestRedraw();
544 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
546 // we do not need to call spawn... - as it's already called by the editor?
552 // ----------- list of projects on left
554 public void projectListInit()
557 this.left_projects = new Xcls_WindowLeftProjects();
558 this.left_projects.ref();
559 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
560 this.left_projects.el.show_all();
561 this.left_projects.project_selected.connect((proj) => {
562 this.buttonsShowHide();
564 this.clutterfiles.loadProject(proj);
572 // ----------- file view
573 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
575 this.popover_files.show(btn, project, new_window);
581 public void fileDetailsInit()
583 this.file_details = new Xcls_PopoverFileDetails();
584 this.file_details.mainwindow = this.win;
585 // force it modal to the main window..
587 this.file_details.success.connect((project,file) =>
589 this.fileViewOpen(file, this.file_details.new_window, -1);
595 public void gotoLine(int line)
598 if (file.xtype == "PlainFile") {
599 this.switchState (State.CODEONLY);
601 this.code_editor_tab.scroll_to_line(line);
605 this.switchState (State.PREVIEW);
607 if (file.project.xtype == "Gtk" && line> -1 ) {
608 // fixme - show the editing tab.
609 this.window_gladeview.scroll_to_line(line);
611 // fixme - what about Roo?
617 public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
619 var existing = BuilderApplication.getWindow(file);
621 if (existing != null) {
622 existing.el.present();
623 existing.windowstate.gotoLine(line);
628 BuilderApplication.newWindow(file, line);
633 this.win.project = file.project;
634 this.project = file.project;
636 BuilderApplication.updateWindows();
638 if (file.xtype == "PlainFile") {
639 this.win.codeeditviewbox.el.show();
640 this.switchState (State.CODEONLY);
642 this.code_editor_tab.show(file, null, null);
646 this.switchState (State.PREVIEW);
647 // this triggers loadItems..
648 this.left_tree.model.loadFile(file);
654 var ctr= this.win.rooviewbox.el;
657 if (file.project.xtype == "Roo" ) {
658 // removes all the childe elemnts from rooviewbox
660 ctr.foreach( (w) => { ctr.remove(w); });
662 ctr.add(this.window_rooview.el);
664 if (file.xtype != "PlainFile") {
666 this.window_rooview.loadFile(file);
667 this.window_rooview.el.show_all();
673 ctr.foreach( (w) => { ctr.remove(w); });
675 ctr.add(this.window_gladeview.el);
677 if (file.xtype != "PlainFile") {
679 this.window_gladeview.loadFile(file);
680 this.window_gladeview.el.show_all();
684 print("OPEN : " + file.name);
685 if (file.xtype != "PlainFile") {
686 // hide the file editor.
687 this.win.codeeditviewbox.el.hide();
688 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
690 this.win.setTitle(file.project.name + " : " + file.name);
697 public void fileViewOpenPlain(string fname)
700 this.switchState (State.CODEONLY);
701 this.code_editor.showPlainFile(fname);
705 // --------- webkit view
706 public void webkitViewInit()
708 this.window_rooview =new Xcls_WindowRooView();
709 this.window_rooview.main_window = this.win;
710 this.window_rooview.ref();
711 this.win.rooviewbox.el.add(this.window_rooview.el);
713 this.window_rooview.el.show_all();
714 this.win.rooviewbox.el.hide();
720 public void gtkViewInit()
725 this.window_gladeview =new Xcls_GtkView( );
726 this.window_gladeview.ref();
727 this.window_gladeview.main_window = this.win;
734 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
736 var ae = this.left_tree.getActiveElement();
740 this.rightpalete.hide();
742 this.add_props.el.show_all();
744 this.win.project.palete, //Palete.factory(this.win.project.xtype),
745 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
752 public void showAddObject(Gtk.Widget btn)
755 var n = this.left_tree.getActiveElement();
756 this.add_props.hide();
757 this.rightpalete.el.show_all();
758 this.rightpalete.show(
759 this.left_tree.getActiveFile().palete(),
760 n == null ? "*top" : n.fqn(),
767 public void switchState(State new_state)
770 // if the new state and the old state are the same..
772 if (new_state == this.state) {
776 // anything to do beforehand?
778 switch (this.state) {
783 // stop editing the editor tab.
784 // always save before calling switch state to preview?
786 this.code_editor_tab.reset();
788 if (this.left_tree.getActiveFile() != null) {
789 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
790 this.window_rooview.createThumb();
792 this.window_gladeview.createThumb();
795 // normally we are going from preview to another state.
796 // and different windows hide the preview in differnt ways..
806 this.state = new_state;
810 this.buttonsShowHide();
813 switch (this.state) {
815 case State.PREVIEW: // this is the default state when working...
816 this.win.leftpane.el.show();
817 this.win.editpane.el.show(); // holder for tree and properties..
818 this.win.rooviewbox.el.show();
819 this.win.codeeditviewbox.el.hide();
823 this.win.leftpane.el.show();
824 this.win.editpane.el.show();
826 this.win.rooviewbox.el.hide();
827 this.win.codeeditviewbox.el.show();
828 this.code_editor_tab.el.show_all();
834 this.win.leftpane.el.hide();
835 this.win.codeeditviewbox.el.show();
836 this.win.rooviewbox.el.hide();
837 this.code_editor_tab.el.show_all();
850 // -- buttons show hide.....
852 public void buttonsShowHide()
854 // basically hide everything, then show the relivant..
857 //this.win.openbtn.el.hide();
858 //this.win.openbackbtn.el.hide();
860 //this.win.backbutton.el.hide();
867 this.win.search_entry.el.hide();
868 this.win.search_results.el.hide();
869 switch (this.state) {
871 case State.PREVIEW: // this is the default state when working...
877 this.win.search_entry.el.show();
879 // this.win.openbtn.el.show();
884 // this.win.openbtn.el.show();
885 this.win.search_entry.el.show();
891 if (this.left_projects.getSelectedProject() != null ) {
892 if (this.left_tree.getActiveFile() != null) {
894 this.win.openbackbtn.el.show();
896 this.win.addfilebutton.el.show();
897 this.win.search_entry.el.show();
898 this.win.projecteditbutton.el.show();
902 this.win.addprojectbutton.el.show();
903 this.win.delprojectbutton.el.show();
917 public void showCompileResult(Json.Object obj)
919 // vala has finished compiling...
921 // stop the spinner...
922 GLib.debug("vala compiled Built Project: %s Window Project %s",
924 BuilderApplication.valasource.file == null ? "No file?" : (
926 BuilderApplication.valasource.file.project == null ? "No Project" : BuilderApplication.valasource.file.project.fn
928 this.project != null ? this.project.fn : "No Project?"
933 if (this.project != null &&
934 BuilderApplication.valasource.file != null &&
935 BuilderApplication.valasource.file.project != null &&
936 this.project.fn != BuilderApplication.valasource.file.project.fn) {
937 GLib.debug("skip update - not our project");
941 var generator = new Json.Generator ();
942 var n = new Json.Node(Json.NodeType.OBJECT);
944 generator.set_root (n);
945 print("result :%s", generator.to_data (null));
948 var buf = this.code_editor_tab.buffer;
949 buf.check_running = false;
950 var has_errors = false;
952 if (obj.has_member("ERR-TOTAL")) {
953 if (obj.get_int_member("ERR-TOTAL")> 0) {
956 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
958 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
961 if (obj.has_member("WARN-TOTAL")) {
963 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
965 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
968 if (obj.has_member("DEPR-TOTAL")) {
970 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
973 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
975 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
976 if ( this.state == State.CODEONLY) {
977 buf.highlightErrorsJson("ERR", obj);
978 buf.highlightErrorsJson("WARN", obj);
979 buf.highlightErrorsJson("DEPR", obj);
982 this.win.statusbar_compilestatus_label.el.hide();
983 this.win.statusbar_run.el.hide();
985 this.win.statusbar_compilestatus_label.el.show();
986 this.win.statusbar_run.el.show();
988 if (this.file.xtype == "Gtk") {
989 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
990 var gbuf = this.window_gladeview.sourceview;
991 gbuf.highlightErrorsJson("ERR", obj);
992 gbuf.highlightErrorsJson("WARN", obj);
993 gbuf.highlightErrorsJson("DEPR", obj);
996 this.win.statusbar_run.el.show();
1001 if (this.file.xtype == "Roo") {
1002 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
1003 var gbuf = this.window_rooview.sourceview;
1004 gbuf.highlightErrorsJson("ERR", obj);
1005 gbuf.highlightErrorsJson("WARN", obj);
1006 gbuf.highlightErrorsJson("DEPR", obj);
1010 this.last_compile_result = obj;