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);
588 // if it's comming from the file dialog -> hide it...
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);
629 this.popover_files.el.hide();
630 BuilderApplication.newWindow(file, line);
635 this.win.project = file.project;
636 this.project = file.project;
638 BuilderApplication.updateWindows();
640 if (file.xtype == "PlainFile") {
641 this.win.codeeditviewbox.el.show();
642 this.switchState (State.CODEONLY);
644 this.code_editor_tab.show(file, null, null);
648 this.switchState (State.PREVIEW);
649 // this triggers loadItems..
650 this.left_tree.model.loadFile(file);
656 var ctr= this.win.rooviewbox.el;
659 if (file.project.xtype == "Roo" ) {
660 // removes all the childe elemnts from rooviewbox
662 ctr.foreach( (w) => { ctr.remove(w); });
664 ctr.add(this.window_rooview.el);
666 if (file.xtype != "PlainFile") {
668 this.window_rooview.loadFile(file);
669 this.window_rooview.el.show_all();
675 ctr.foreach( (w) => { ctr.remove(w); });
677 ctr.add(this.window_gladeview.el);
679 if (file.xtype != "PlainFile") {
681 this.window_gladeview.loadFile(file);
682 this.window_gladeview.el.show_all();
686 print("OPEN : " + file.name);
687 if (file.xtype != "PlainFile") {
688 // hide the file editor.
689 this.win.codeeditviewbox.el.hide();
690 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
692 this.win.setTitle(file.project.name + " : " + file.name);
699 public void fileViewOpenPlain(string fname)
702 this.switchState (State.CODEONLY);
703 this.code_editor.showPlainFile(fname);
707 // --------- webkit view
708 public void webkitViewInit()
710 this.window_rooview =new Xcls_WindowRooView();
711 this.window_rooview.main_window = this.win;
712 this.window_rooview.ref();
713 this.win.rooviewbox.el.add(this.window_rooview.el);
715 this.window_rooview.el.show_all();
716 this.win.rooviewbox.el.hide();
722 public void gtkViewInit()
727 this.window_gladeview =new Xcls_GtkView( );
728 this.window_gladeview.ref();
729 this.window_gladeview.main_window = this.win;
736 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
738 var ae = this.left_tree.getActiveElement();
742 this.rightpalete.hide();
744 this.add_props.el.show_all();
746 this.win.project.palete, //Palete.factory(this.win.project.xtype),
747 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
754 public void showAddObject(Gtk.Widget btn)
757 var n = this.left_tree.getActiveElement();
758 this.add_props.hide();
759 this.rightpalete.el.show_all();
760 this.rightpalete.show(
761 this.left_tree.getActiveFile().palete(),
762 n == null ? "*top" : n.fqn(),
769 public void switchState(State new_state)
772 // if the new state and the old state are the same..
774 if (new_state == this.state) {
778 // anything to do beforehand?
780 switch (this.state) {
785 // stop editing the editor tab.
786 // always save before calling switch state to preview?
788 this.code_editor_tab.reset();
790 if (this.left_tree.getActiveFile() != null) {
791 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
792 this.window_rooview.createThumb();
794 this.window_gladeview.createThumb();
797 // normally we are going from preview to another state.
798 // and different windows hide the preview in differnt ways..
804 this.state = new_state;
805 this.buttonsShowHide();
807 switch (this.state) {
809 case State.PREVIEW: // this is the default state when working...
810 this.win.leftpane.el.show();
811 this.win.editpane.el.show(); // holder for tree and properties..
812 this.win.rooviewbox.el.show();
813 this.win.codeeditviewbox.el.hide();
817 this.win.leftpane.el.show();
818 this.win.editpane.el.show();
819 this.win.rooviewbox.el.hide();
820 this.win.codeeditviewbox.el.show();
821 this.code_editor_tab.el.show_all();
825 this.win.leftpane.el.hide();
826 this.win.codeeditviewbox.el.show();
827 this.win.rooviewbox.el.hide();
828 this.code_editor_tab.el.show_all();
839 // -- buttons show hide.....
841 public void buttonsShowHide()
843 // basically hide everything, then show the relivant..
846 //this.win.openbtn.el.hide();
847 //this.win.openbackbtn.el.hide();
849 //this.win.backbutton.el.hide();
856 this.win.search_entry.el.hide();
857 this.win.search_results.el.hide();
858 switch (this.state) {
860 case State.PREVIEW: // this is the default state when working...
866 this.win.search_entry.el.show();
868 // this.win.openbtn.el.show();
873 // this.win.openbtn.el.show();
874 this.win.search_entry.el.show();
880 if (this.left_projects.getSelectedProject() != null ) {
881 if (this.left_tree.getActiveFile() != null) {
883 this.win.openbackbtn.el.show();
885 this.win.addfilebutton.el.show();
886 this.win.search_entry.el.show();
887 this.win.projecteditbutton.el.show();
891 this.win.addprojectbutton.el.show();
892 this.win.delprojectbutton.el.show();
906 public void showCompileResult(Json.Object obj)
908 // vala has finished compiling...
910 // stop the spinner...
911 GLib.debug("vala compiled Built Project: %s Window Project %s",
913 BuilderApplication.valasource.file == null ? "No file?" : (
915 BuilderApplication.valasource.file.project == null ? "No Project" : BuilderApplication.valasource.file.project.fn
917 this.project != null ? this.project.fn : "No Project?"
922 if (this.project != null &&
923 BuilderApplication.valasource.file != null &&
924 BuilderApplication.valasource.file.project != null &&
925 this.project.fn != BuilderApplication.valasource.file.project.fn) {
926 GLib.debug("skip update - not our project");
930 var generator = new Json.Generator ();
931 var n = new Json.Node(Json.NodeType.OBJECT);
933 generator.set_root (n);
934 print("result :%s", generator.to_data (null));
937 var buf = this.code_editor_tab.buffer;
938 buf.check_running = false;
939 var has_errors = false;
941 if (obj.has_member("ERR-TOTAL")) {
942 if (obj.get_int_member("ERR-TOTAL")> 0) {
945 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
947 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
950 if (obj.has_member("WARN-TOTAL")) {
952 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
954 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
957 if (obj.has_member("DEPR-TOTAL")) {
959 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
962 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
964 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
965 if ( this.state == State.CODEONLY) {
966 buf.highlightErrorsJson("ERR", obj);
967 buf.highlightErrorsJson("WARN", obj);
968 buf.highlightErrorsJson("DEPR", obj);
971 this.win.statusbar_compilestatus_label.el.hide();
972 this.win.statusbar_run.el.hide();
974 this.win.statusbar_compilestatus_label.el.show();
975 this.win.statusbar_run.el.show();
977 if (this.file.xtype == "Gtk") {
978 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
979 var gbuf = this.window_gladeview.sourceview;
980 gbuf.highlightErrorsJson("ERR", obj);
981 gbuf.highlightErrorsJson("WARN", obj);
982 gbuf.highlightErrorsJson("DEPR", obj);
985 this.win.statusbar_run.el.show();
990 if (this.file.xtype == "Roo") {
991 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
992 var gbuf = this.window_rooview.sourceview;
993 gbuf.highlightErrorsJson("ERR", obj);
994 gbuf.highlightErrorsJson("WARN", obj);
995 gbuf.highlightErrorsJson("DEPR", obj);
999 this.last_compile_result = obj;