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 Xcls_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;
91 this.valasource = new Palete.ValaSource(this.win);
93 this.valasource.compiled.connect(this.showCompileResult);
95 this.compile_results = new Xcls_ValaCompileResults();
96 this.compile_results.window = this.win;
97 this.valasource.compile_output.connect(this.compile_results.addLine);
99 this.win.statusbar_compilestatus_label.el.hide();
100 this.win.statusbar_run.el.hide();
101 this.win.search_results.el.hide();
103 this.popover_files = new Xcls_PopoverFiles();
104 this.popover_files.setMainWindow(this.win);
110 public void leftTreeInit()
113 this.left_tree = new Xcls_WindowLeftTree();
114 this.left_tree.ref();
115 this.left_tree.main_window = this.win;
117 this.win.leftpane.el.remove(this.win.editpane.el);
118 //this.win.tree.el.remove(this.left_tree.el);
119 this.win.leftpane.el.add(this.left_tree.el);
122 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
123 this.left_tree.el.show_all();
125 this.left_tree.before_node_change.connect(() => {
126 // if the node change is caused by the editor (code preview)
127 if (this.left_tree.view.lastEventSource == "editor") {
130 return this.leftTreeBeforeChange();
133 // node selected -- only by clicking?
134 this.left_tree.node_selected.connect((sel, source) => {
135 if (source == "editor") {
138 if (this.file.xtype == "Roo") {
139 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
141 this.window_gladeview.sourceview.nodeSelected(sel);
145 this.left_tree.node_selected.connect((sel, source) => {
146 this.leftTreeNodeSelected(sel, source);
149 this.left_tree.changed.connect(() => {
150 print("LEFT TREE: Changed fired\n");
152 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
153 this.window_rooview.requestRedraw();
155 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
162 public bool leftTreeBeforeChange()
164 // in theory code editor has to hide before tree change occurs.
165 //if (this.state != State.CODE) {
166 this.left_props.finish_editing();
168 if (this.state == State.CODE) {
169 this.code_editor_tab.saveContents();
170 this.switchState(State.PREVIEW);
176 //if (!this.code_editor.saveContents()) {
182 int tree_width = 300;
183 int props_width = 300;
185 public void leftTreeNodeSelected(JsRender.Node? sel, string source)
188 // do we really want to flip paletes if differnt nodes are selected
189 // showing palete should be deliberate thing..
192 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
194 this.add_props.hide(); // always hide add node/add listener if we change node.
195 this.rightpalete.hide();
197 this.left_props.load(this.left_tree.getActiveFile(), sel);
199 var outerpane = this.win.mainpane.el;
200 var innerpane = this.win.editpane.el;
202 if (this.win.editpane.el.parent != null && sel != null) {
203 // select another node... no change to show hide/resize
208 // remove win.editpane from leftpane
209 // remove lefttree from from win.tree
210 // add win.tree to leftpane
211 if (this.win.editpane.el.parent != null) {
212 this.props_width = outerpane.get_position() - innerpane.get_position();
213 this.tree_width = innerpane.get_position();
214 GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
216 this.win.leftpane.el.remove(this.win.editpane.el);
217 this.win.tree.el.remove(this.left_tree.el);
218 this.win.leftpane.el.add(this.left_tree.el);
222 //GLib.debug("Hide Properties");
223 outerpane.show_all(); // make sure it's visiable..
224 this.left_props.el.hide();
225 GLib.debug("set position: %d", this.tree_width);
226 outerpane.set_position(this.tree_width);
227 //outerpane.set_position(int.max(250,innerpane.get_position()));
228 //this.left_props.el.width_request = this.left_props.el.get_allocated_width();
232 // at this point we are showing the outer only,
237 this.tree_width = outerpane.get_position();
239 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
241 // remove this.ldeftree from this.win.leftpane
242 this.win.leftpane.el.remove(this.left_tree.el);
243 this.win.tree.el.add(this.left_tree.el);
244 this.win.leftpane.el.add(this.win.editpane.el);
249 GLib.debug("left props is %s", this.left_props.el.visible ? "shown" : "hidden");
250 // at start (hidden) - outer = 400 inner = 399
251 // expanded out -> outer = 686, inner = 399
252 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
253 this.left_props.el.show_all();
254 //if (!this.left_props.el.visible) {
256 GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
257 outerpane.set_position(this.tree_width + this.props_width);
258 innerpane.set_position(this.tree_width);
259 /* var cw = outerpane.el.get_position();
260 var rw = int.min(this.left_props.el.width_request, 150);
261 print("outerpos : %d, innerpos : %d", cw + rw, cw);
263 innerpane.set_position(cw); */
264 this.left_props.el.show();
275 // if either of these are active.. then we should update them??
281 make outerpane = {current width of left pane} + width of props
282 make innerpane = {current width of left pane}
288 var outerpane = _this.main_window.leftpane.el;
289 var pane = _this.main_window.editpane.el;
293 var try_size = (i * 25) + 60; // est. 20px per line + 40px header
294 GLib.Timeout.add_seconds(1, () => {
297 ((try_size * 1.0f) / (pane.max_position * 1.0f)) > 0.8f ?
298 (int) (pane.max_position * 0.2f) :
299 pane.max_position-try_size);
300 return GLib.Source.REMOVE;
306 switch (this.state) {
309 this.switchState(State.PREVIEW);
324 public void propsListInit()
327 this.left_props =new Xcls_LeftProps();
328 this.left_props.ref();
329 this.left_props.main_window = this.win;
330 this.win.props.el.pack_start(this.left_props.el,true, true,0);
331 this.left_props.el.show_all();
333 this.left_props.show_editor.connect( (file, node, prop) => {
334 this.switchState(State.CODE);
337 this.code_editor_tab.show(
347 // not sure if this is needed - as closing the popvoer should save it.
348 this.left_props.stop_editor.connect( () => {
349 var ret = this.code_editor_tab.saveContents();
353 this.switchState(State.PREVIEW);
358 this.left_props.changed.connect(() => {
359 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
360 this.window_rooview.requestRedraw();
362 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
364 this.left_tree.model.updateSelected();
366 if (this.file.xtype=="Gtk") {
367 this.valasource.checkFileSpawn(this.file);
374 //------------- projects edit
376 public void projectEditInit()
378 this.roo_projectsettings_pop =new Xcls_RooProjectSettings();
379 this.roo_projectsettings_pop.ref(); /// really?
381 this.vala_projectsettings_pop =new Xcls_ValaProjectSettingsPopover();
382 this.vala_projectsettings_pop.ref();
383 this.vala_projectsettings_pop.window = this.win;
385 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
388 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
389 // in theory active file can only be rooo...
390 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
392 this.window_rooview.view.renderJS(true);
393 this.roo_projectsettings_pop.el.hide();
395 if (btn == "apply") {
396 this.window_rooview.view.renderJS(true);
400 // do nothing for gtk..
402 if (btn == "save" || btn == "apply") {
403 this.win.project.save();
406 //this.switchState (State.PREVIEW);
412 public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr)
419 var active_file = this.left_tree.getActiveFile() ;
420 if (active_file != null) {
421 xtype = active_file.xtype;
424 return; // no active project
425 // we might be on the file brower..
426 //pr = this.left_projects.getSelectedProject();
432 if (pr.xtype == "") {
435 if (pr.xtype == "Roo" ) {
436 this.roo_projectsettings_pop.show(btn,pr);
441 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
446 // ----------- object adding
447 public void objectAddInit()
450 this.rightpalete = new Xcls_PopoverAddObject();
451 this.rightpalete.mainwindow = this.win;
452 this.rightpalete.ref(); /// really?
453 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
456 var stage = this.win.objectview.el.get_stage();
457 stage.set_background_color( Clutter.Color.from_string("#000"));
461 // ----------- properties adding list...
462 // listener uses the properties
463 public void propsAddInit()
466 this.add_props = new Xcls_PopoverAddProp();
467 this.add_props.mainwindow = this.win;
468 this.add_props.ref(); /// really?
469 // don't need to add it..
470 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
473 //var stage = this.win.addpropsview.el.get_stage();
474 //stage.set_background_color( Clutter.Color.from_string("#000"));
477 this.add_props.select.connect( (prop) => {
479 this.left_props.addProp(prop);
483 public void propsAddShow()
487 public void propsAddHide()
493 // ----------- Add / Edit listener
494 // listener uses the properties
495 //public void listenerInit() { }
496 public void listenerShow()
500 public void listenerHide()
505 // -------------- codeEditor
507 public void codeEditInit()
509 this.code_editor_tab = new Editor();
510 //this.code_editor.ref(); /// really?
511 this.win.codeeditviewbox.el.add(this.code_editor_tab.el);
513 this.win.codeeditviewbox.el.hide();
514 this.code_editor_tab.window = this.win;
518 this.code_editor_tab.save.connect( () => {
520 this.left_tree.model.updateSelected();
521 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
522 this.window_rooview.requestRedraw();
524 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
526 // we do not need to call spawn... - as it's already called by the editor?
532 public void codePopoverEditInit()
534 this.code_editor_popover = new Xcls_PopoverEditor();
535 //this.code_editor.ref(); /// really?
537 this.code_editor_popover.setMainWindow( this.win);
539 this.code_editor_popover.editor.save.connect( () => {
541 this.left_tree.model.updateSelected();
542 if (this.left_tree.getActiveFile().xtype == "Roo" ) {
543 this.window_rooview.requestRedraw();
545 this.window_gladeview.loadFile(this.left_tree.getActiveFile());
547 // we do not need to call spawn... - as it's already called by the editor?
553 // ----------- list of projects on left
555 public void projectListInit()
558 this.left_projects = new Xcls_WindowLeftProjects();
559 this.left_projects.ref();
560 this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
561 this.left_projects.el.show_all();
562 this.left_projects.project_selected.connect((proj) => {
563 this.buttonsShowHide();
565 this.clutterfiles.loadProject(proj);
573 // ----------- file view
574 public void showPopoverFiles(Gtk.Widget btn, Project.Project? project)
576 this.popover_files.show(btn, project);
582 public void fileViewInit()
584 var stage = this.win.rooview.el.get_stage(); // seems odd...
585 this.clutterfiles = new Xcls_ClutterFiles();
586 this.clutterfiles.ref();
587 stage.add_child(this.clutterfiles.el);
588 this.clutterfiles.el.show();
591 this.clutterfiles.open.connect((file) => {
592 this.fileViewOpen(file);
594 this.clutterfiles.el.transitions_completed.connect(() => {
595 if (this.state == State.FILES) {
596 this.win.rooview.el.hide();
598 this.clutterfiles.el.hide();
607 public void fileDetailsInit()
609 this.file_details = new Xcls_PopoverFileDetails();
610 this.file_details.mainwindow = this.win;
611 // force it modal to the main window..
613 this.file_details.success.connect((project,file) =>
615 this.fileViewOpen(file);
620 public void fileViewOpen(JsRender.JsRender file, int line = -1)
622 this.win.project = file.project;
623 this.project = file.project;
627 if (file.xtype == "PlainFile") {
628 this.win.codeeditviewbox.el.show();
629 this.switchState (State.CODEONLY);
631 this.code_editor_tab.show(file, null, null);
633 this.code_editor_tab.scroll_to_line(line);
637 this.switchState (State.PREVIEW);
638 // this triggers loadItems..
639 this.left_tree.model.loadFile(file);
640 if (file.project.xtype == "Gtk" && line> -1 ) {
641 this.window_gladeview.scroll_to_line(line);
647 var ctr= this.win.rooviewbox.el;
650 if (file.project.xtype == "Roo" ) {
651 // removes all the childe elemnts from rooviewbox
653 ctr.foreach( (w) => { ctr.remove(w); });
655 ctr.add(this.window_rooview.el);
657 if (file.xtype != "PlainFile") {
659 this.window_rooview.loadFile(file);
660 this.window_rooview.el.show_all();
666 ctr.foreach( (w) => { ctr.remove(w); });
668 ctr.add(this.window_gladeview.el);
670 if (file.xtype != "PlainFile") {
672 this.window_gladeview.loadFile(file);
673 this.window_gladeview.el.show_all();
677 print("OPEN : " + file.name);
678 if (file.xtype != "PlainFile") {
679 // hide the file editor.
680 this.win.codeeditviewbox.el.hide();
681 //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
683 this.win.setTitle(file.project.name + " : " + file.name);
690 public void fileViewOpenPlain(string fname)
693 this.switchState (State.CODEONLY);
694 this.code_editor.showPlainFile(fname);
698 // --------- webkit view
699 public void webkitViewInit()
701 this.window_rooview =new Xcls_WindowRooView();
702 this.window_rooview.main_window = this.win;
703 this.window_rooview.ref();
704 this.win.rooviewbox.el.add(this.window_rooview.el);
706 this.window_rooview.el.show_all();
707 this.win.rooviewbox.el.hide();
713 public void gtkViewInit()
718 this.window_gladeview =new Xcls_GtkView( );
719 this.window_gladeview.ref();
720 this.window_gladeview.main_window = this.win;
727 public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
729 var ae = this.left_tree.getActiveElement();
733 this.rightpalete.hide();
735 this.add_props.el.show_all();
737 this.win.project.palete, //Palete.factory(this.win.project.xtype),
738 sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
745 public void showAddObject(Gtk.Widget btn)
748 var n = this.left_tree.getActiveElement();
749 this.add_props.hide();
750 this.rightpalete.el.show_all();
751 this.rightpalete.show(
752 this.left_tree.getActiveFile().palete(),
753 n == null ? "*top" : n.fqn(),
757 public void showFilesPopover(Gtk.Widget btn)
759 this.popover_files.el.show_all();
760 this.popover_files.show(btn, this.win.project);
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..
804 this.state = new_state;
808 this.buttonsShowHide();
811 switch (this.state) {
813 case State.PREVIEW: // this is the default state when working...
814 this.win.leftpane.el.show();
815 this.win.editpane.el.show(); // holder for tree and properties..
816 this.win.rooviewbox.el.show();
817 this.win.codeeditviewbox.el.hide();
821 this.win.leftpane.el.show();
822 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();
832 this.win.leftpane.el.hide();
833 this.win.codeeditviewbox.el.show();
834 this.win.rooviewbox.el.hide();
835 this.code_editor_tab.el.show_all();
848 // -- buttons show hide.....
850 public void buttonsShowHide()
852 // basically hide everything, then show the relivant..
855 //this.win.openbtn.el.hide();
856 //this.win.openbackbtn.el.hide();
858 //this.win.backbutton.el.hide();
865 this.win.search_entry.el.hide();
866 this.win.search_results.el.hide();
867 switch (this.state) {
869 case State.PREVIEW: // this is the default state when working...
875 this.win.search_entry.el.show();
877 // this.win.openbtn.el.show();
882 // this.win.openbtn.el.show();
883 this.win.search_entry.el.show();
889 if (this.left_projects.getSelectedProject() != null ) {
890 if (this.left_tree.getActiveFile() != null) {
892 this.win.openbackbtn.el.show();
894 this.win.addfilebutton.el.show();
895 this.win.search_entry.el.show();
896 this.win.projecteditbutton.el.show();
900 this.win.addprojectbutton.el.show();
901 this.win.delprojectbutton.el.show();
915 public void showCompileResult(Json.Object obj)
917 // vala has finished compiling...
918 print("vala compiled");
919 // stop the spinner...
922 var generator = new Json.Generator ();
923 var n = new Json.Node(Json.NodeType.OBJECT);
925 generator.set_root (n);
926 print("result :%s", generator.to_data (null));
929 var buf = this.code_editor_tab.buffer;
930 buf.check_running = false;
931 var has_errors = false;
933 if (obj.has_member("ERR-TOTAL")) {
934 if (obj.get_int_member("ERR-TOTAL")> 0) {
937 this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
939 this.win.statusbar_errors.setNotices( new Json.Object() , 0);
942 if (obj.has_member("WARN-TOTAL")) {
944 this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
946 this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
949 if (obj.has_member("DEPR-TOTAL")) {
951 this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"), (int) obj.get_int_member("DEPR-TOTAL"));
954 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
956 //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
957 if ( this.state == State.CODEONLY) {
958 buf.highlightErrorsJson("ERR", obj);
959 buf.highlightErrorsJson("WARN", obj);
960 buf.highlightErrorsJson("DEPR", obj);
963 this.win.statusbar_compilestatus_label.el.hide();
964 this.win.statusbar_run.el.hide();
966 this.win.statusbar_compilestatus_label.el.show();
967 this.win.statusbar_run.el.show();
969 if (this.file.xtype == "Gtk") {
970 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
971 var gbuf = this.window_gladeview.sourceview;
972 gbuf.highlightErrorsJson("ERR", obj);
973 gbuf.highlightErrorsJson("WARN", obj);
974 gbuf.highlightErrorsJson("DEPR", obj);
977 this.win.statusbar_run.el.show();
982 if (this.file.xtype == "Roo") {
983 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
984 var gbuf = this.window_rooview.sourceview;
985 gbuf.highlightErrorsJson("ERR", obj);
986 gbuf.highlightErrorsJson("WARN", obj);
987 gbuf.highlightErrorsJson("DEPR", obj);
991 this.last_compile_result = obj;