1 static Xcls_WindowLeftTree _WindowLeftTree;
3 public class Xcls_WindowLeftTree : Object
6 private Xcls_WindowLeftTree _this;
8 public static Xcls_WindowLeftTree singleton()
10 if (_WindowLeftTree == null) {
11 _WindowLeftTree= new Xcls_WindowLeftTree();
13 return _WindowLeftTree;
15 public Xcls_viewwin viewwin;
16 public Xcls_view view;
17 public Xcls_keystate keystate;
18 public Xcls_drop drop;
19 public Xcls_selmodel selmodel;
20 public Xcls_model model;
21 public Xcls_maincol maincol;
22 public Xcls_LeftTreeMenu LeftTreeMenu;
25 public signal bool before_node_change ();
26 public Xcls_MainWindow? main_window;
27 public int last_error_counter;
28 public signal void changed ();
29 public signal void node_selected (JsRender.Node? node);
32 public Xcls_WindowLeftTree()
35 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
38 this.main_window = null;
39 this.last_error_counter = -1;
42 this.el.hexpand = true;
43 this.el.vexpand = true;
44 var child_1 = new Xcls_ListView1( _this );
46 this.el.append( child_1.el );
47 new Xcls_viewwin( _this );
48 this.el.append( _this.viewwin.el );
51 // user defined functions
52 public void updateErrors () {
53 var file = this.getActiveFile();
58 var ar = file.getErrors();
59 if (ar == null || ar.size < 1) {
60 if (this.last_error_counter != file.error_counter) {
64 this.last_error_counter = file.error_counter ;
68 if (this.last_error_counter == file.error_counter) {
73 foreach(var diag in ar) {
76 // print("get inter\n");
77 var node= file.lineToNode( (int)diag.range.start.line) ;
81 var row = _this.model.nodeToRow(node);
85 var w = this.view.getWidgetAtRow(row);
89 // always show errors.
90 var ed = diag.category.down();
91 if (ed != "err" && w.has_css_class("node-err")) {
94 if (ed == "err" && w.has_css_class("node-warn")) {
95 w.remove_css_class("node-warn");
97 if (ed == "err" && w.has_css_class("node-depr")) {
98 w.remove_css_class("node-depr");
100 if (!w.has_css_class("node-"+ ed)) {
101 w.add_css_class("node-" + ed);
107 public void onresize () {
110 //GLib.debug("Got allocation width of scrolled view %d", allocation.width );
111 // _this.maincol.el.set_max_width( _this.viewwin.el.get_width() - 32 );
113 public void removeErrors () {
114 var child = this.view.el.get_first_child();
116 var reading_header = true;
118 while (child != null) {
119 //GLib.debug("Got %s", child.get_type().name());
121 if (reading_header) {
124 if (child.get_type().name() != "GtkColumnListView") {
126 child = child.get_next_sibling();
129 // should be columnlistview
130 child = child.get_first_child();
134 reading_header = false;
138 if (child.has_css_class("node-err")) {
139 child.remove_css_class("node-err");
141 if (child.has_css_class("node-warn")) {
142 child.remove_css_class("node-warn");
145 if (child.has_css_class("node-depr")) {
146 child.remove_css_class("node-depr");
149 child = child.get_next_sibling();
151 //GLib.debug("Rturning null");
154 public JsRender.Node? getActiveElement () { // return path to actie node.
157 return _this.selmodel.getSelectedNode();
161 public JsRender.JsRender getActiveFile () {
162 return this.main_window.windowstate.file;
165 public class Xcls_ListView1 : Object
167 public Gtk.ListView el;
168 private Xcls_WindowLeftTree _this;
174 public Xcls_ListView1(Xcls_WindowLeftTree _owner )
177 var child_1 = new Xcls_SignalListItemFactory2( _this );
179 this.el = new Gtk.ListView( null, child_1.el );
183 // set gobject values
186 // user defined functions
188 public class Xcls_SignalListItemFactory2 : Object
190 public Gtk.SignalListItemFactory el;
191 private Xcls_WindowLeftTree _this;
197 public Xcls_SignalListItemFactory2(Xcls_WindowLeftTree _owner )
200 this.el = new Gtk.SignalListItemFactory();
204 // set gobject values
207 // user defined functions
211 public class Xcls_viewwin : Object
213 public Gtk.ScrolledWindow el;
214 private Xcls_WindowLeftTree _this;
220 public Xcls_viewwin(Xcls_WindowLeftTree _owner )
223 _this.viewwin = this;
224 this.el = new Gtk.ScrolledWindow();
228 // set gobject values
229 this.el.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
230 this.el.has_frame = true;
231 this.el.hexpand = true;
232 this.el.vexpand = true;
233 this.el.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
234 new Xcls_view( _this );
235 this.el.child = _this.view.el;
236 new Xcls_LeftTreeMenu( _this );
239 // user defined functions
241 public class Xcls_view : Object
243 public Gtk.ColumnView el;
244 private Xcls_WindowLeftTree _this;
248 public bool blockChanges;
249 public bool headers_visible;
250 public string lastEventSource;
251 public bool button_is_pressed;
252 public Gtk.CssProvider css;
253 public JsRender.Node? dragNode;
256 public Xcls_view(Xcls_WindowLeftTree _owner )
260 new Xcls_selmodel( _this );
261 this.el = new Gtk.ColumnView( _this.selmodel.el );
264 this.blockChanges = false;
265 this.headers_visible = false;
266 this.lastEventSource = "";
267 this.button_is_pressed = false;
268 this.dragNode = null;
270 // set gobject values
271 this.el.name = "left-tree-view";
272 this.el.hexpand = false;
273 this.el.vexpand = true;
274 var child_2 = new Xcls_GestureClick5( _this );
276 this.el.add_controller( child_2.el );
277 var child_3 = new Xcls_GestureClick6( _this );
279 this.el.add_controller( child_3.el );
280 var child_4 = new Xcls_DragSource7( _this );
282 this.el.add_controller( child_4.el );
283 var child_5 = new Xcls_EventControllerKey8( _this );
285 this.el.add_controller( child_5.el );
286 new Xcls_keystate( _this );
287 this.el.add_controller( _this.keystate.el );
288 new Xcls_drop( _this );
289 this.el.add_controller( _this.drop.el );
290 new Xcls_maincol( _this );
291 this.el.append_column ( _this.maincol.el );
292 var child_9 = new Xcls_ColumnViewColumn15( _this );
294 this.el.append_column ( child_9.el );
300 this.css = new Gtk.CssProvider();
302 this.css.load_from_string("
303 #left-tree-view { font-size: 12px;}
304 .drag-over { background-color:#88a3bc; }
306 border-bottom-width: 5px;
307 border-bottom-style: solid;
308 border-bottom-color: #88a3bc;
311 border-top-width: 5px;
312 border-top-style: solid;
313 border-top-color: #88a3bc;
316 border-top-width: 5px;
317 border-top-style: solid;
318 border-top-color: red;
319 border-bottom-width: 5px;
320 border-bottom-style: solid;
321 border-bottom-color: red;
324 border-top-width: 5px;
325 border-top-style: solid;
326 border-top-color: #ABF4EB;
327 border-bottom-width: 5px;
328 border-bottom-style: solid;
329 border-bottom-color: #ABF4EB;
332 border-top-width: 5px;
333 border-top-style: solid;
334 border-top-color: #EEA9FF;
335 border-bottom-width: 5px;
336 border-bottom-style: solid;
337 border-bottom-color: #EEA9FF;
340 #left-tree-view indent {
341 -gtk-icon-size : 2px;
343 #left-tree-view indent:nth-last-child(2) {
348 Gtk.StyleContext.add_provider_for_display(
349 this.el.get_display(),
351 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
358 // user defined functions
359 public Gtk.Widget? getWidgetAtRow (uint row) {
362 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
363 var colview = gesture.widget;
364 var line_no = check_list_widget(colview, x,y);
366 var item = colview.model.get_item(line_no);
370 //GLib.debug("Get Widget At Row %d", (int)row);
371 var child = this.el.get_first_child();
373 var reading_header = true;
375 while (child != null) {
376 //GLib.debug("Got %s", child.get_type().name());
378 if (reading_header) {
381 if (child.get_type().name() != "GtkColumnListView") {
383 child = child.get_next_sibling();
386 // should be columnlistview
387 child = child.get_first_child();
391 reading_header = false;
398 if (line_no == row) {
399 //GLib.debug("Returning widget %s", child.get_type().name());
400 return (Gtk.Widget)child;
402 child = child.get_next_sibling();
404 //GLib.debug("Rturning null");
408 public int getColAt (double x, double y) {
411 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
414 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
415 //GLib.debug("Cehck %d, %d", x,y);
416 var child = this.el.get_first_child();
420 while (child != null) {
422 if (child.get_type().name() == "GtkColumnViewRowWidget") {
423 child = child.get_first_child();
427 //child.get_allocation(out alloc);
428 if (x < (child.get_width() + offx)) {
432 //offx += child.get_width();
434 //child = child.get_next_sibling();
441 public int getRowAt (double x, double in_y, out string pos) {
448 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
449 var colview = gesture.widget;
450 var line_no = check_list_widget(colview, x,y);
452 var item = colview.model.get_item(line_no);
458 GLib.debug("get Widget At Row x = %d y = %d", (int) x, (int) in_y);
459 var y = in_y + _this.viewwin.el.vadjustment.value;
460 var child = this.el.get_first_child();
461 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
463 var reading_header = true;
465 var header_height = 0;
468 while (child != null) {
469 //GLib.debug("Got %s", child.get_type().name());
470 if (reading_header) {
473 if (child.get_type().name() != "GtkColumnListView") {
474 h += child.get_height();
475 child = child.get_next_sibling();
478 // should be columnlistview
479 child = child.get_first_child();
480 //GLib.debug("header height=%d", h);
483 reading_header = false;
488 if (child.get_type().name() != "GtkColumnViewRowWidget") {
489 child = child.get_next_sibling();
493 if (y < header_height) {
498 var hh = child.get_height();
500 if (child.has_css_class("node-err") ||
501 child.has_css_class("node-warn") ||
502 child.has_css_class("node-depr")) {
506 //child.get_allocation(out alloc);
507 //GLib.debug("got cell xy = %d,%d w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
508 //GLib.debug("row %d y= %d %s", line_no, (int) (header_height + alloc.y),
510 // child.visible ? "VIS" : "hidden");
512 if (y > (header_height + real_y) && y <= (header_height + real_y + hh) ) {
513 if (y > ( header_height + real_y + (hh * 0.8))) {
515 } else if (y > ( header_height + real_y + (hh * 0.2))) {
520 GLib.debug("getRowAt return : %d, %s", line_no, pos);
525 if (real_y + hh > y) {
529 child = child.get_next_sibling();
534 public Gtk.Widget? getWidgetAt (double x, double in_y) {
537 from https://discourse.gnome.org/t/gtk4-finding-a-row-data-on-gtkcolumnview/8465
538 var colview = gesture.widget;
539 var line_no = check_list_widget(colview, x,y);
541 var item = colview.model.get_item(line_no);
545 var y = in_y + _this.viewwin.el.vadjustment.value;
546 var child = this.el.get_first_child();
547 //Gtk.Allocation alloc = { 0, 0, 0, 0 };
549 var reading_header = true;
551 var header_height = 0;
553 while (child != null) {
554 //GLib.debug("Got %s", child.get_type().name());
555 if (reading_header) {
558 if (child.get_type().name() != "GtkColumnListView") {
559 h += child.get_height();
560 child = child.get_next_sibling();
563 // should be columnlistview
564 child = child.get_first_child();
565 GLib.debug("header height=%d", h);
568 reading_header = false;
573 if (y < header_height) {
577 var hh = child.get_height();
578 //GLib.debug("got cell xy = %d,%d w,h= %d,%d", alloc.x, alloc.y, alloc.width, alloc.height);
579 if (child.has_css_class("node-err") ||
580 child.has_css_class("node-warn") ||
581 child.has_css_class("node-depr")) {
585 if (y > curr_y && y <= header_height + hh + curr_y ) {
586 return (Gtk.Widget)child;
593 child = child.get_next_sibling();
599 public class Xcls_GestureClick5 : Object
601 public Gtk.GestureClick el;
602 private Xcls_WindowLeftTree _this;
608 public Xcls_GestureClick5(Xcls_WindowLeftTree _owner )
611 this.el = new Gtk.GestureClick();
615 // set gobject values
618 this.el.released.connect( (n_press, x, y) => {
620 _this.view.button_is_pressed = false;
624 this.el.pressed.connect( (n_press, x, y) => {
626 //console.log("button press?");
628 //this.el.set_state(Gtk.EventSequenceState.CLAIMED);
632 _this.view.button_is_pressed = true;
634 _this.view.lastEventSource = "tree";
635 if (! _this.before_node_change() ) {
636 GLib.debug("before_node_change return false");
640 // nothing there -show dialog
641 if (_this.model.el.get_n_items() < 1) {
642 _this.main_window.windowstate.showAddObject(_this.view.el, null);
643 GLib.debug("no items");
647 var row = _this.view.getRowAt(x,y, out pos );
649 GLib.debug("no row selected items");
653 var node = _this.selmodel.getNodeAt(row);
655 GLib.warning("No node found at row %d", row);
661 if (_this.view.getColAt(x,y) > 0 ) {
662 GLib.debug("add colum clicked.");
663 var fqn = node.fqn();
664 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn, false);
669 _this.main_window.windowstate.leftTreeBeforeChange();
670 //_this.view.el.get_selection().select_path(res);
671 GLib.debug("Button Pressed - start show window");
672 _this.main_window.windowstate.showAddObject(_this.view.el, node);
673 GLib.debug("Button Pressed - finsihed show window");
682 // user defined functions
685 public class Xcls_GestureClick6 : Object
687 public Gtk.GestureClick el;
688 private Xcls_WindowLeftTree _this;
694 public Xcls_GestureClick6(Xcls_WindowLeftTree _owner )
697 this.el = new Gtk.GestureClick();
701 // set gobject values
705 this.el.pressed.connect( (n_press, x, y) => {
710 if (_this.model.el.get_n_items() < 1) {
712 GLib.debug("no items");
716 var row = _this.view.getRowAt(x,y, out pos );
718 GLib.debug("no row selected items");
722 var node = _this.selmodel.getNodeAt(row);
724 GLib.warning("No node found at row %d", row);
729 _this.model.selectNode(node);
733 GLib.debug("Prssed %d", (int) this.el.get_current_button());
734 //_this.deletemenu.el.set_parent(_this.view.el);
735 _this.LeftTreeMenu.el.set_parent(_this.view.el);
738 //Gtk.Allocation rect;
739 //_this.view.el.get_allocation(out rect);
740 //_this.deletemenu.el.set_has_arrow(false);
741 _this.LeftTreeMenu.el.set_position(Gtk.PositionType.BOTTOM);
744 _this.LeftTreeMenu.el.set_offset(
746 (int)y - (int)_this.view.el.get_height());
748 _this.LeftTreeMenu.el.popup();
753 // user defined functions
756 public class Xcls_DragSource7 : Object
758 public Gtk.DragSource el;
759 private Xcls_WindowLeftTree _this;
765 public Xcls_DragSource7(Xcls_WindowLeftTree _owner )
768 this.el = new Gtk.DragSource();
772 // set gobject values
773 this.el.actions = Gdk.DragAction.COPY | Gdk.DragAction.MOVE ;
776 this.el.drag_cancel.connect( (drag, reason) => {
778 _this.view.dragNode = null;
781 this.el.prepare.connect( (x, y) => {
785 /// ( drag_context, data, info, time) => {
788 //print("drag-data-get");
789 var ndata = _this.selmodel.getSelectedNode();
791 GLib.debug("return empty string - no selection..");
797 //data.set_text(tp,tp.length);
799 var str = ndata.toJsonString();
800 GLib.debug("prepare store: %s", str);
801 GLib.Value ov = GLib.Value(typeof(string));
803 var cont = new Gdk.ContentProvider.for_value(ov);
805 GLib.Value v = GLib.Value(typeof(string));
806 //var str = drop.read_text( [ "text/plain" ] 0);
808 cont.get_value(ref v);
811 GLib.debug("set %s", v.get_string());
817 this.el.drag_begin.connect( ( drag ) => {
818 GLib.debug("SOURCE: drag-begin");
820 // find what is selected in our tree...
821 var data = _this.selmodel.getSelectedNode();
825 _this.view.dragNode = data;
826 var xname = data.fqn();
827 GLib.debug ("XNAME IS %s", xname);
829 var widget = _this.view.getWidgetAtRow(_this.selmodel.el.selected);
832 var paintable = new Gtk.WidgetPaintable(widget);
833 this.el.set_icon(paintable, 0,0);
837 this.el.drag_end.connect( (drag, delete_data) => {
839 _this.view.dragNode = null;
843 // user defined functions
846 public class Xcls_EventControllerKey8 : Object
848 public Gtk.EventControllerKey el;
849 private Xcls_WindowLeftTree _this;
855 public Xcls_EventControllerKey8(Xcls_WindowLeftTree _owner )
858 this.el = new Gtk.EventControllerKey();
862 // set gobject values
865 this.el.key_pressed.connect( (keyval, keycode, state) => {
869 if (keyval != Gdk.Key.Delete && keyval != Gdk.Key.BackSpace) {
873 _this.model.deleteSelected();
879 // user defined functions
882 public class Xcls_keystate : Object
884 public Gtk.EventControllerKey el;
885 private Xcls_WindowLeftTree _this;
892 public Xcls_keystate(Xcls_WindowLeftTree _owner )
895 _this.keystate = this;
896 this.el = new Gtk.EventControllerKey();
901 // set gobject values
904 this.el.key_released.connect( (keyval, keycode, state) => {
905 GLib.debug("key release %d, %d, %d" , (int) keyval, (int) keycode, state);
906 if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
909 //GLib.debug("set state %d , shift = %d", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK);
914 this.el.key_pressed.connect( (keyval, keycode, state) => {
916 if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
923 // user defined functions
926 public class Xcls_drop : Object
928 public Gtk.DropTarget el;
929 private Xcls_WindowLeftTree _this;
933 public Gtk.Widget? highlightWidget;
934 public JsRender.Node? lastDragNode;
935 public string lastDragString;
938 public Xcls_drop(Xcls_WindowLeftTree _owner )
942 this.el = new Gtk.DropTarget ( typeof(string) ,
943 Gdk.DragAction.COPY | Gdk.DragAction.MOVE );
946 this.highlightWidget = null;
947 this.lastDragNode = null;
948 this.lastDragString = "";
950 // set gobject values
953 this.el.accept.connect( (drop) => {
955 GLib.debug("got DropTarget:accept");
957 // NOT REALLY NEEDED? = put stuff in drop?
960 /* ( ctx, x, y, time) => {
961 //Seed.print("TARGET: drag-drop");
964 var src = Gtk.drag_get_source_widget(ctx);
966 if (src != this.el) {
970 this.drag_in_motion = false;
971 // request data that will be recieved by the recieve...
974 this.el, // will receive 'drag-data-received' signal
975 ctx, // represents the current state of the DnD
976 Gdk.Atom.intern("application/json",true), // the target type we want
981 // No target offered by source => error
987 // handle drop around self..
991 //print("GETTING POS");
995 Gtk.TreeViewDropPosition pos;
996 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
998 // if there are not items in the tree.. the we have to set isOver to true for anything..
1000 if (_this.model.el.iter_n_children(null) < 1) {
1001 print("got NO children?\n");
1002 isOver = true; //???
1004 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
1009 //var action = Gdk.DragAction.COPY;
1010 // unless we are copying!!! ctl button..
1012 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
1013 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
1014 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
1017 if (_this.model.el.iter_n_children(null) < 1) {
1018 // no children.. -- asume it's ok..
1020 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
1022 // continue through to allow drop...
1030 //print("ISOVER? " + isOver);
1033 Gtk.drag_finish (ctx, false, false, time); // drop failed..
1034 return true; // not over apoint!?! - no action on drop or motion..
1037 // drag node is parent of child..
1038 //console.log("SRC TREEPATH: " + src.treepath);
1039 //console.log("TARGET TREEPATH: " + data.path.to_string());
1041 // nned to check a few here..
1042 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
1043 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
1044 //Gtk.TreeViewDropPosition.AFTER
1045 //Gtk.TreeViewDropPosition.BEFORE
1047 // locally dragged items to not really use the
1048 var selection_text = this.dragData;
1052 if (selection_text == null || selection_text.length < 1) {
1053 //print("Error - drag selection text returned NULL");
1055 Gtk.drag_finish (ctx, false, false, time); // drop failed..
1056 return true; /// -- fixme -- this is not really correct..
1059 // see if we are dragging into ourself?
1060 print ("got selection text of " + selection_text);
1062 var target_path = path.to_string();
1063 //print("target_path="+target_path);
1066 if (selection_text == target_path) {
1067 print("self drag ?? == we should perhaps allow copy onto self..\n");
1069 Gtk.drag_finish (ctx, false, false, time); // drop failed..
1071 return true; /// -- fixme -- this is not really correct..
1076 //print("DUMPING DATA");
1077 //console.dump(data);
1080 //print(data.path.to_string() +' => '+ data.pos);
1082 // dropList is a list of xtypes that this node could be dropped on.
1083 // it is set up when we start to drag..
1086 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
1088 print("targetDAta: " + targetData +"\n");
1090 if (targetData.length < 1) {
1091 //print("Can not find drop node path");
1093 Gtk.drag_finish (ctx, false, false, time); // drop failed..
1099 // continue on to allow drop..
1101 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
1104 var delete_selection_data = false;
1106 if (action == Gdk.DragAction.ASK) {
1107 // Ask the user to move or copy, then set the ctx action.
1110 if (action == Gdk.DragAction.MOVE) {
1111 delete_selection_data = true;
1114 // drag around.. - reorder..
1115 _this.model.moveNode(targetData, action);
1121 // we can send stuff to souce here...
1124 // do we always say failure, so we handle the reall drop?
1125 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
1138 this.el.motion.connect( ( x, y) => {
1140 var is_shift = _this.keystate.is_shift > 0;
1142 GLib.debug("shift is %s", _this.keystate.is_shift > 0 ? "SHIFT" : "-");
1143 string pos; // over / before / after..
1145 //GLib.debug("got drag motion");
1147 GLib.Value v = GLib.Value(typeof(string));
1148 //var str = drop.read_text( [ "text/plain" ] 0);
1149 var cont = this.el.current_drop.get_drag().content ;
1151 cont.get_value(ref v);
1152 } catch (GLib.Error e) {
1153 GLib.debug("failed to get drag value");
1154 return Gdk.DragAction.COPY;
1158 //GLib.debug("got %s", v.get_string());
1160 if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
1161 // still dragging same node
1163 this.lastDragNode = new JsRender.Node();
1164 this.lastDragNode.loadFromJsonString(v.get_string(), 1);
1168 var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(
1169 this.lastDragNode.fqn());
1172 foreach(var dp in drop_on_to) {
1175 GLib.debug("droplist: %s", string.joinv(", ", str));
1178 // if there are not items in the tree.. the we have to set isOver to true for anything..
1180 if (_this.model.el.n_items < 1) {
1181 // FIXME check valid drop types?
1182 if (drop_on_to.contains("*top")) {
1183 this.addHighlight(_this.view.el, "over");
1185 this.addHighlight(null, "");
1188 return Gdk.DragAction.COPY; // no need to highlight?
1193 GLib.debug("check is over");
1195 // if path of source and dest are inside each other..
1196 // need to add source info to drag?
1198 var row = _this.view.getRowAt(x,y, out pos);
1201 this.addHighlight(null, "");
1202 return Gdk.DragAction.COPY;
1204 var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
1206 var node = (JsRender.Node)tr.get_item();
1208 GLib.debug("Drop over node: %s", node.fqn());
1211 if (pos == "above" || pos == "below") {
1212 if (node.parent == null) {
1213 GLib.debug("no parent try center");
1217 if (!drop_on_to.contains(node.parent.fqn())) {
1218 GLib.debug("drop on does not contain %s - try center" , node.parent.fqn());
1221 GLib.debug("drop contains %s - using %s" , node.parent.fqn(), pos);
1222 if (_this.view.dragNode != null && is_shift) {
1223 if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
1224 GLib.debug("shift drop not self not allowed");
1225 this.addHighlight(null, "");
1226 return Gdk.DragAction.COPY;
1239 if (pos == "over") {
1240 if (!drop_on_to.contains(node.fqn())) {
1241 GLib.debug("drop on does not contain %s - try center" , node.fqn());
1242 this.addHighlight(null, "");
1243 return is_shift ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY;
1245 if (_this.view.dragNode != null && is_shift) {
1246 if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
1247 GLib.debug("shift drop not self not allowed");
1248 this.addHighlight(null, "");
1249 return Gdk.DragAction.COPY;
1256 // _this.view.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
1257 var w = _this.view.getWidgetAt(x,y);
1258 this.addHighlight(w, pos);
1259 return is_shift ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY;
1261 this.el.leave.connect( ( ) => {
1262 this.addHighlight(null,"");
1265 this.el.drop.connect( (v, x, y) => {
1267 this.addHighlight(null,"");
1269 var is_shift = _this.keystate.is_shift > 0;
1272 // -- get position..
1273 if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
1274 // still dragging same node
1276 this.lastDragNode = new JsRender.Node();
1277 this.lastDragNode.loadFromJsonString(v.get_string(), 1);
1282 var dropNode = new JsRender.Node();
1283 dropNode.loadFromJsonString(v.get_string(), 1);
1284 var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(dropNode.fqn());
1286 // if there are not items in the tree.. the we have to set isOver to true for anything..
1288 if (_this.model.el.n_items < 1) {
1289 // FIXME check valid drop types?
1290 if (!drop_on_to.contains("*top")) {
1291 GLib.debug("drop on to list does not contain top?");
1294 // add new node to top..
1297 var m = (GLib.ListStore) _this.model.el.model;
1298 _this.main_window.windowstate.file.tree = dropNode;
1299 dropNode.updated_count++;
1302 _this.model.selectNode(dropNode);
1304 return true; // no need to highlight?
1310 var row = _this.view.getRowAt(x,y, out pos);
1312 return false; //Gdk.DragAction.COPY;
1314 var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
1316 var node = (JsRender.Node)tr.get_item();
1318 if (pos == "above" || pos == "below") {
1319 if (node.parent == null) {
1322 if (!drop_on_to.contains(node.parent.fqn())) {
1325 GLib.debug("drop contains %s - using %s" , node.parent.fqn(), pos);
1326 if (_this.view.dragNode != null && is_shift) {
1327 if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
1328 GLib.debug("shift drop not self not allowed");
1339 if (pos == "over") {
1340 if (!drop_on_to.contains(node.fqn())) {
1341 GLib.debug("drop on does not contain %s - try center" , node.fqn());
1345 if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
1346 GLib.debug("shift drop not self not allowed");
1353 node.appendChild(dropNode);
1354 if (is_shift && _this.view.dragNode != null) {
1355 _this.model.selectNode(null);
1356 _this.view.dragNode.remove();
1359 dropNode.updated_count++;
1360 _this.model.selectNode(dropNode);
1366 GLib.debug("Above - insertBefore");
1368 node.parent.insertBefore(dropNode, node);
1369 if (is_shift && _this.view.dragNode != null) {
1370 _this.model.selectNode(null);
1371 _this.view.dragNode.remove();
1373 dropNode.updated_count++;
1374 _this.model.selectNode(dropNode);
1379 GLib.debug("Below - insertAfter");
1380 if (is_shift && _this.view.dragNode != null) {
1381 _this.model.selectNode(null);
1382 _this.view.dragNode.remove();
1386 node.parent.insertAfter(dropNode, node);
1387 dropNode.updated_count++;
1388 _this.model.selectNode(dropNode);
1394 // should not happen
1406 // user defined functions
1407 public void addHighlight (Gtk.Widget? w, string hl) {
1408 if (this.highlightWidget != null) {
1409 var ww = this.highlightWidget;
1410 GLib.debug("clear drag from previous highlight");
1411 if (ww.has_css_class("drag-below")) {
1412 ww.remove_css_class("drag-below");
1414 if (ww.has_css_class("drag-above")) {
1415 ww.remove_css_class("drag-above");
1417 if (ww.has_css_class("drag-over")) {
1418 ww.remove_css_class("drag-over");
1422 GLib.debug("add drag=%s to widget", hl);
1423 if (!w.has_css_class("drag-" + hl)) {
1424 w.add_css_class("drag-" + hl);
1427 this.highlightWidget = w;
1431 public class Xcls_selmodel : Object
1433 public Gtk.SingleSelection el;
1434 private Xcls_WindowLeftTree _this;
1440 public Xcls_selmodel(Xcls_WindowLeftTree _owner )
1443 _this.selmodel = this;
1444 new Xcls_model( _this );
1445 this.el = new Gtk.SingleSelection( _this.model.el );
1449 // set gobject values
1452 this.el.selection_changed.connect( (position, n_items) => {
1456 //if (!this.button_is_pressed && !this.key_is_pressed) {
1457 // then event was started by some other action
1458 // which should manually trigger all the events..
1459 // print("SKIPPING select - no button or key pressed\n");
1464 if (_this.view.blockChanges) { // probably not needed..
1465 GLib.debug("SKIPPING select - blockchanges set..");
1469 if (!_this.before_node_change( ) ) {
1470 _this.view.blockChanges = true;
1471 _this.selmodel.el.unselect_all();
1472 _this.view.blockChanges = false;
1476 if (_this.main_window.windowstate.file == null) {
1477 GLib.debug("SKIPPING select windowstate file is not set...");
1481 //var render = this.get('/LeftTree').getRenderer();
1482 GLib.debug("LEFT TREE -> view -> selection changed called");
1485 // -- it appears that the selection is not updated.
1486 // select the node...
1487 //_this.selmodel.el.set_selected(row);
1489 GLib.debug("LEFT TREE -> view -> selection changed TIMEOUT CALLED");
1491 var snode = _this.selmodel.getSelectedNode();
1492 if (snode == null) {
1494 GLib.debug("selected rows < 1");
1495 //??this.model.load( false);
1496 _this.node_selected(null);
1504 GLib.debug ("calling left_tree.node_selected");
1505 _this.node_selected(snode);
1510 // no need to scroll. it's in the view as we clicked on it.
1511 // _this.view.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
1517 // user defined functions
1518 public JsRender.Node? getSelectedNode () {
1519 if (this.el.selected_item == null) {
1522 var tr = (Gtk.TreeListRow)this.el.selected_item;
1523 return (JsRender.Node)tr.get_item();
1526 public JsRender.Node getNodeAt (uint row) {
1528 var tr = (Gtk.TreeListRow)this.el.get_item(row);
1530 var a = tr.get_item();;
1531 GLib.debug("get_item (2) = %s", a.get_type().name());
1534 return (JsRender.Node)tr.get_item();
1538 public class Xcls_model : Object
1540 public Gtk.TreeListModel el;
1541 private Xcls_WindowLeftTree _this;
1547 public Xcls_model(Xcls_WindowLeftTree _owner )
1551 this.el = this.updateModel(null);
1555 // set gobject values
1558 // user defined functions
1559 public void loadFile (JsRender.JsRender f) {
1562 _this.drop.highlightWidget = null;
1564 var m = (GLib.ListStore) this.el.model;
1566 _this.main_window.windowstate.leftTreeNodeSelected(null);
1568 _this.main_window.windowstate.file = f;
1569 _this.last_error_counter = -1;
1571 if (f.tree == null) {
1578 // if it's still null?
1579 if (f.tree == null) {
1580 _this.main_window.windowstate.showAddObject(_this.view.el, null);
1581 _this.updateErrors();
1585 _this.updateErrors();
1587 _this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);
1593 public int nodeToRow (JsRender.Node node)
1596 var s = _this.view.el.model as Gtk.SingleSelection;
1597 for (var i = 0; i < s.n_items; i++) {
1598 //GLib.debug("check node %s", s.get_item(i).get_type().name());
1599 var lr = s.get_item(i) as Gtk.TreeListRow;
1600 //GLib.debug("check node %s", lr.get_item().get_type().name());
1601 if ((lr.get_item() as JsRender.Node).oid == node.oid) {
1610 public void deleteSelected () {
1614 var node = _this.selmodel.getSelectedNode();
1618 GLib.debug("delete Selected - no node slected?");
1621 _this.selmodel.el.unselect_all();
1624 GLib.debug("delete Selected - done");
1627 print("DELETE SELECTED?");
1628 //_this.view.blockChanges = true;
1629 print("GET SELECTION?");
1631 var s = _this.view.el.get_selection();
1633 print("GET SELECTED?");
1638 if (!s.get_selected(out mod, out iter)) {
1639 return; // nothing seleted..
1644 this.activePath= "";
1645 print("GET vnode value?");
1648 this.el.get_value(iter, 2, out value);
1649 var data = (JsRender.Node)(value.get_object());
1650 print("removing node from Render\n");
1651 if (data.parent == null) {
1652 _this.main_window.windowstate.file.tree = null;
1656 print("removing node from Tree\n");
1658 this.el.remove(ref iter);
1668 this.activePath= ""; // again!?!?
1669 //this.changed(null,true);
1673 _this.view.blockChanges = false;
1676 public Gtk.TreeListModel updateModel (GLib.ListStore? m) {
1677 this.el = new Gtk.TreeListModel(
1678 m != null ? m : new GLib.ListStore(typeof(JsRender.Node)), //..... << that's our store..
1682 return ((JsRender.Node)item).childstore;
1686 if (_this.selmodel.el == null) {
1689 _this.selmodel.el.set_model(this.el);
1692 public void selectNode (JsRender.Node node)
1694 var row = this.nodeToRow(node);
1695 var s = _this.view.el.model as Gtk.SingleSelection;
1699 GLib.debug("Could not find node");
1702 GLib.debug("Select %d", row);
1703 s.set_selected(row);
1704 _this.view.el.scroll_to(row, null, Gtk.ListScrollFlags.SELECT, null);
1705 //_this.node_selected(node);
1712 public class Xcls_maincol : Object
1714 public Gtk.ColumnViewColumn el;
1715 private Xcls_WindowLeftTree _this;
1721 public Xcls_maincol(Xcls_WindowLeftTree _owner )
1724 _this.maincol = this;
1725 var child_1 = new Xcls_SignalListItemFactory14( _this );
1727 this.el = new Gtk.ColumnViewColumn( "Property", child_1.el );
1731 // set gobject values
1732 this.el.id = "maincol";
1733 this.el.expand = true;
1734 this.el.resizable = true;
1737 // user defined functions
1739 public class Xcls_SignalListItemFactory14 : Object
1741 public Gtk.SignalListItemFactory el;
1742 private Xcls_WindowLeftTree _this;
1748 public Xcls_SignalListItemFactory14(Xcls_WindowLeftTree _owner )
1751 this.el = new Gtk.SignalListItemFactory();
1755 // set gobject values
1758 this.el.setup.connect( (listitem) => {
1760 var expand = new Gtk.TreeExpander();
1762 expand.set_indent_for_depth(true);
1763 expand.set_indent_for_icon(true);
1764 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1765 var icon = new Gtk.Image();
1766 var lbl = new Gtk.Label("");
1767 lbl.use_markup = true;
1768 lbl.ellipsize = Pango.EllipsizeMode.END;
1770 icon.margin_end = 4;
1771 lbl.justify = Gtk.Justification.LEFT;
1774 // listitem.activatable = true; ??
1778 expand.set_child(hbox);
1779 ((Gtk.ListItem)listitem).set_child(expand);
1782 this.el.bind.connect( (listitem) => {
1783 GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
1785 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1786 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1789 var hbox = (Gtk.Box) expand.child;
1792 var img = (Gtk.Image) hbox.get_first_child();
1793 var lbl = (Gtk.Label) img.get_next_sibling();
1795 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1796 var node = (JsRender.Node) lr.get_item();
1798 GLib.debug("node is %s", node.get_type().name());
1799 // was item (1) in old layout
1804 var ic = Gtk.IconTheme.get_for_display(_this.el.get_display());
1805 var clsname = node.fqn();
1807 var clsb = clsname.split(".");
1808 var sub = clsb.length > 1 ? clsb[1].down() : "";
1810 var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
1814 if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
1815 img.set_from_file(fn);
1818 img.set_from_paintable(
1820 "media-playback-stop", null, 16,1,
1821 Gtk.TextDirection.NONE, 0
1825 } catch (GLib.Error e) {}
1827 expand.set_hide_expander( !node.hasChildren() );
1828 expand.set_list_row(lr);
1830 node.bind_property("iconResourceName",
1832 GLib.BindingFlags.SYNC_CREATE);
1834 node.bind_property("nodeTitleProp",
1836 GLib.BindingFlags.SYNC_CREATE);
1837 node.bind_property("nodeTipProp",
1838 lbl, "tooltip_markup",
1839 GLib.BindingFlags.SYNC_CREATE);
1845 // user defined functions
1849 public class Xcls_ColumnViewColumn15 : Object
1851 public Gtk.ColumnViewColumn el;
1852 private Xcls_WindowLeftTree _this;
1858 public Xcls_ColumnViewColumn15(Xcls_WindowLeftTree _owner )
1861 var child_1 = new Xcls_SignalListItemFactory16( _this );
1863 this.el = new Gtk.ColumnViewColumn( "Add", child_1.el );
1867 // set gobject values
1868 this.el.fixed_width = 25;
1871 // user defined functions
1873 public class Xcls_SignalListItemFactory16 : Object
1875 public Gtk.SignalListItemFactory el;
1876 private Xcls_WindowLeftTree _this;
1882 public Xcls_SignalListItemFactory16(Xcls_WindowLeftTree _owner )
1885 this.el = new Gtk.SignalListItemFactory();
1889 // set gobject values
1892 this.el.setup.connect( (listitem) => {
1895 var icon = new Gtk.Image();
1897 ((Gtk.ListItem)listitem).set_child(icon);
1899 this.el.bind.connect( (listitem) => {
1901 var img = (Gtk.Image) ((Gtk.ListItem)listitem).get_child();
1902 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1903 var node = (JsRender.Node) lr.get_item();
1906 var ic = Gtk.IconTheme.get_for_display(_this.el.get_display());
1907 img.set_from_paintable(
1909 "list-add", null, 16,1,
1910 Gtk.TextDirection.NONE, 0
1914 var fqn = node.fqn();
1915 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn, false);
1917 img.set_visible(cn.size > 0 ? true : false);
1922 // user defined functions
1927 public class Xcls_LeftTreeMenu : Object
1929 public Gtk.Popover el;
1930 private Xcls_WindowLeftTree _this;
1936 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1939 _this.LeftTreeMenu = this;
1940 this.el = new Gtk.Popover();
1944 // set gobject values
1945 var child_1 = new Xcls_Box18( _this );
1946 this.el.child = child_1.el;
1949 // user defined functions
1951 public class Xcls_Box18 : Object
1954 private Xcls_WindowLeftTree _this;
1960 public Xcls_Box18(Xcls_WindowLeftTree _owner )
1963 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1967 // set gobject values
1968 var child_1 = new Xcls_Button19( _this );
1970 this.el.append( child_1.el );
1971 var child_2 = new Xcls_Button20( _this );
1973 this.el.append( child_2.el );
1974 var child_3 = new Xcls_Button21( _this );
1976 this.el.append( child_3.el );
1979 // user defined functions
1981 public class Xcls_Button19 : Object
1983 public Gtk.Button el;
1984 private Xcls_WindowLeftTree _this;
1990 public Xcls_Button19(Xcls_WindowLeftTree _owner )
1993 this.el = new Gtk.Button();
1997 // set gobject values
1998 this.el.has_frame = false;
1999 this.el.label = "Delete Element";
2002 this.el.clicked.connect( ( ) => {
2003 _this.LeftTreeMenu.el.hide();
2004 _this.model.deleteSelected();
2009 // user defined functions
2012 public class Xcls_Button20 : Object
2014 public Gtk.Button el;
2015 private Xcls_WindowLeftTree _this;
2021 public Xcls_Button20(Xcls_WindowLeftTree _owner )
2024 this.el = new Gtk.Button();
2028 // set gobject values
2029 this.el.has_frame = false;
2030 this.el.label = "Save as Template";
2033 this.el.clicked.connect( () => {
2034 _this.LeftTreeMenu.el.hide();
2035 DialogSaveTemplate.singleton().showIt(
2036 (Gtk.Window) _this.el.get_root (),
2037 _this.main_window.windowstate.file.palete(),
2038 _this.getActiveElement()
2045 // user defined functions
2048 public class Xcls_Button21 : Object
2050 public Gtk.Button el;
2051 private Xcls_WindowLeftTree _this;
2057 public Xcls_Button21(Xcls_WindowLeftTree _owner )
2060 this.el = new Gtk.Button();
2064 // set gobject values
2065 this.el.has_frame = false;
2066 this.el.label = "Save as Module";
2069 this.el.clicked.connect( () => {
2071 _this.LeftTreeMenu.el.hide();
2072 var node = _this.getActiveElement();
2075 var sm = DialogSaveModule.singleton();
2079 (Gtk.Window) _this.el.get_root (),
2080 _this.main_window.windowstate.project,
2084 gtk4 migration - disabled this part.. probably not used muchanyway
2087 if (name.length < 1) {
2091 node.set_prop( new JsRender.NodeProp.special("xinclude", name));
2095 var s = _this.view.el.get_selection();
2097 print("GET SELECTED?");
2102 if (!s.get_selected(out mod, out iter)) {
2103 return; // nothing seleted..
2106 var n_cn = mod.iter_n_children(iter) -1;
2107 for (var i = n_cn; i > -1; i--) {
2108 mod.iter_nth_child(out citer, iter, i);
2111 print("removing node from Tree\n");
2113 _this.model.el.remove(ref citer);
2116 _this.node_selected(node, "tree");
2122 // user defined functions