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 y, out string pos) {
443 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
444 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
449 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
454 //GLib.debug("got colview %s", row == null ? "nothing" : row.get_type().name());
459 while (cr.get_prev_sibling() != null) {
461 cr = cr.get_prev_sibling();
464 //GLib.debug("row number is %d", rn);
465 //GLib.debug("click %d, %d", (int)x, (int)y);
467 Graphene.Rect bounds;
468 row.compute_bounds(this.el, out bounds);
469 //GLib.debug("click x=%d, y=%d, w=%d, h=%d",
470 // (int)bounds.get_x(), (int)bounds.get_y(),
471 // (int)bounds.get_width(), (int)bounds.get_height()
473 var ypos = y - bounds.get_y();
474 //GLib.debug("rel ypos = %d", (int)ypos);
475 var rpos = 100.0 * (ypos / bounds.get_height());
476 //GLib.debug("rel pos = %d %%", (int)rpos);
481 } else if (rpos < 20) {
486 public Gtk.Widget? getWidgetAt (double x, double y) {
488 var w = this.el.pick(x, y, Gtk.PickFlags.DEFAULT);
489 //GLib.debug("got widget %s", w == null ? "nothing" : w.get_type().name());
494 var row= w.get_ancestor(GLib.Type.from_name("GtkColumnViewRowWidget"));
503 public class Xcls_GestureClick5 : Object
505 public Gtk.GestureClick el;
506 private Xcls_WindowLeftTree _this;
512 public Xcls_GestureClick5(Xcls_WindowLeftTree _owner )
515 this.el = new Gtk.GestureClick();
519 // set gobject values
522 this.el.released.connect( (n_press, x, y) => {
524 _this.view.button_is_pressed = false;
528 this.el.pressed.connect( (n_press, x, y) => {
530 //console.log("button press?");
532 //this.el.set_state(Gtk.EventSequenceState.CLAIMED);
536 _this.view.button_is_pressed = true;
538 _this.view.lastEventSource = "tree";
539 if (! _this.before_node_change() ) {
540 GLib.debug("before_node_change return false");
544 // nothing there -show dialog
545 if (_this.model.el.get_n_items() < 1) {
546 _this.main_window.windowstate.showAddObject(_this.view.el, null);
547 GLib.debug("no items");
551 var row = _this.view.getRowAt(x,y, out pos );
553 GLib.debug("no row selected items");
557 var node = _this.selmodel.getNodeAt(row);
559 GLib.warning("No node found at row %d", row);
565 if (_this.view.getColAt(x,y) > 0 ) {
566 GLib.debug("add colum clicked.");
567 var fqn = node.fqn();
568 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn, false);
573 _this.main_window.windowstate.leftTreeBeforeChange();
574 //_this.view.el.get_selection().select_path(res);
575 GLib.debug("Button Pressed - start show window");
576 _this.main_window.windowstate.showAddObject(_this.view.el, node);
577 GLib.debug("Button Pressed - finsihed show window");
586 // user defined functions
589 public class Xcls_GestureClick6 : Object
591 public Gtk.GestureClick el;
592 private Xcls_WindowLeftTree _this;
598 public Xcls_GestureClick6(Xcls_WindowLeftTree _owner )
601 this.el = new Gtk.GestureClick();
605 // set gobject values
609 this.el.pressed.connect( (n_press, x, y) => {
614 if (_this.model.el.get_n_items() < 1) {
616 GLib.debug("no items");
620 var row = _this.view.getRowAt(x,y, out pos );
622 GLib.debug("no row selected items");
626 var node = _this.selmodel.getNodeAt(row);
628 GLib.warning("No node found at row %d", row);
633 _this.model.selectNode(node);
637 GLib.debug("Prssed %d", (int) this.el.get_current_button());
638 //_this.deletemenu.el.set_parent(_this.view.el);
639 _this.LeftTreeMenu.el.set_parent(_this.view.el);
642 //Gtk.Allocation rect;
643 //_this.view.el.get_allocation(out rect);
644 //_this.deletemenu.el.set_has_arrow(false);
645 _this.LeftTreeMenu.el.set_position(Gtk.PositionType.BOTTOM);
648 _this.LeftTreeMenu.el.set_offset(
650 (int)y - (int)_this.view.el.get_height());
652 _this.LeftTreeMenu.el.popup();
657 // user defined functions
660 public class Xcls_DragSource7 : Object
662 public Gtk.DragSource el;
663 private Xcls_WindowLeftTree _this;
669 public Xcls_DragSource7(Xcls_WindowLeftTree _owner )
672 this.el = new Gtk.DragSource();
676 // set gobject values
677 this.el.actions = Gdk.DragAction.COPY | Gdk.DragAction.MOVE ;
680 this.el.drag_cancel.connect( (drag, reason) => {
682 _this.view.dragNode = null;
685 this.el.prepare.connect( (x, y) => {
689 /// ( drag_context, data, info, time) => {
692 //print("drag-data-get");
693 var ndata = _this.selmodel.getSelectedNode();
695 GLib.debug("return empty string - no selection..");
701 //data.set_text(tp,tp.length);
703 var str = ndata.toJsonString();
704 GLib.debug("prepare store: %s", str);
705 GLib.Value ov = GLib.Value(typeof(string));
707 var cont = new Gdk.ContentProvider.for_value(ov);
709 GLib.Value v = GLib.Value(typeof(string));
710 //var str = drop.read_text( [ "text/plain" ] 0);
712 cont.get_value(ref v);
715 GLib.debug("set %s", v.get_string());
721 this.el.drag_begin.connect( ( drag ) => {
722 GLib.debug("SOURCE: drag-begin");
724 // find what is selected in our tree...
725 var data = _this.selmodel.getSelectedNode();
729 _this.view.dragNode = data;
730 var xname = data.fqn();
731 GLib.debug ("XNAME IS %s", xname);
733 var widget = _this.view.getWidgetAtRow(_this.selmodel.el.selected);
736 var paintable = new Gtk.WidgetPaintable(widget);
737 this.el.set_icon(paintable, 0,0);
741 this.el.drag_end.connect( (drag, delete_data) => {
743 _this.view.dragNode = null;
747 // user defined functions
750 public class Xcls_EventControllerKey8 : Object
752 public Gtk.EventControllerKey el;
753 private Xcls_WindowLeftTree _this;
759 public Xcls_EventControllerKey8(Xcls_WindowLeftTree _owner )
762 this.el = new Gtk.EventControllerKey();
766 // set gobject values
769 this.el.key_pressed.connect( (keyval, keycode, state) => {
773 if (keyval != Gdk.Key.Delete && keyval != Gdk.Key.BackSpace) {
777 _this.model.deleteSelected();
783 // user defined functions
786 public class Xcls_keystate : Object
788 public Gtk.EventControllerKey el;
789 private Xcls_WindowLeftTree _this;
796 public Xcls_keystate(Xcls_WindowLeftTree _owner )
799 _this.keystate = this;
800 this.el = new Gtk.EventControllerKey();
805 // set gobject values
808 this.el.key_released.connect( (keyval, keycode, state) => {
809 GLib.debug("key release %d, %d, %d" , (int) keyval, (int) keycode, state);
810 if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
813 //GLib.debug("set state %d , shift = %d", (int)this.el.get_current_event_state(), Gdk.ModifierType.SHIFT_MASK);
818 this.el.key_pressed.connect( (keyval, keycode, state) => {
820 if (keyval == Gdk.Key.Shift_L || keyval == Gdk.Key.Shift_R) {
827 // user defined functions
830 public class Xcls_drop : Object
832 public Gtk.DropTarget el;
833 private Xcls_WindowLeftTree _this;
837 public Gtk.Widget? highlightWidget;
838 public JsRender.Node? lastDragNode;
839 public string lastDragString;
842 public Xcls_drop(Xcls_WindowLeftTree _owner )
846 this.el = new Gtk.DropTarget ( typeof(string) ,
847 Gdk.DragAction.COPY | Gdk.DragAction.MOVE );
850 this.highlightWidget = null;
851 this.lastDragNode = null;
852 this.lastDragString = "";
854 // set gobject values
857 this.el.accept.connect( (drop) => {
859 GLib.debug("got DropTarget:accept");
861 // NOT REALLY NEEDED? = put stuff in drop?
864 /* ( ctx, x, y, time) => {
865 //Seed.print("TARGET: drag-drop");
868 var src = Gtk.drag_get_source_widget(ctx);
870 if (src != this.el) {
874 this.drag_in_motion = false;
875 // request data that will be recieved by the recieve...
878 this.el, // will receive 'drag-data-received' signal
879 ctx, // represents the current state of the DnD
880 Gdk.Atom.intern("application/json",true), // the target type we want
885 // No target offered by source => error
891 // handle drop around self..
895 //print("GETTING POS");
899 Gtk.TreeViewDropPosition pos;
900 var isOver = _this.view.el.get_dest_row_at_pos(this.drag_x,this.drag_y, out path, out pos);
902 // if there are not items in the tree.. the we have to set isOver to true for anything..
904 if (_this.model.el.iter_n_children(null) < 1) {
905 print("got NO children?\n");
908 pos = Gtk.TreeViewDropPosition.INTO_OR_AFTER;
913 //var action = Gdk.DragAction.COPY;
914 // unless we are copying!!! ctl button..
916 var action = (ctx.get_actions() & Gdk.DragAction.MOVE) > 0 ?
917 Gdk.DragAction.COPY : Gdk.DragAction.MOVE ;
918 // Gdk.DragAction.MOVE : Gdk.DragAction.COPY ;
921 if (_this.model.el.iter_n_children(null) < 1) {
922 // no children.. -- asume it's ok..
924 targetData = "|%d|".printf((int)Gtk.TreeViewDropPosition.INTO_OR_AFTER);
926 // continue through to allow drop...
934 //print("ISOVER? " + isOver);
937 Gtk.drag_finish (ctx, false, false, time); // drop failed..
938 return true; // not over apoint!?! - no action on drop or motion..
941 // drag node is parent of child..
942 //console.log("SRC TREEPATH: " + src.treepath);
943 //console.log("TARGET TREEPATH: " + data.path.to_string());
945 // nned to check a few here..
946 //Gtk.TreeViewDropPosition.INTO_OR_AFTER
947 //Gtk.TreeViewDropPosition.INTO_OR_BEFORE
948 //Gtk.TreeViewDropPosition.AFTER
949 //Gtk.TreeViewDropPosition.BEFORE
951 // locally dragged items to not really use the
952 var selection_text = this.dragData;
956 if (selection_text == null || selection_text.length < 1) {
957 //print("Error - drag selection text returned NULL");
959 Gtk.drag_finish (ctx, false, false, time); // drop failed..
960 return true; /// -- fixme -- this is not really correct..
963 // see if we are dragging into ourself?
964 print ("got selection text of " + selection_text);
966 var target_path = path.to_string();
967 //print("target_path="+target_path);
970 if (selection_text == target_path) {
971 print("self drag ?? == we should perhaps allow copy onto self..\n");
973 Gtk.drag_finish (ctx, false, false, time); // drop failed..
975 return true; /// -- fixme -- this is not really correct..
980 //print("DUMPING DATA");
981 //console.dump(data);
984 //print(data.path.to_string() +' => '+ data.pos);
986 // dropList is a list of xtypes that this node could be dropped on.
987 // it is set up when we start to drag..
990 targetData = _this.model.findDropNodeByPath( path.to_string(), this.dropList, pos);
992 print("targetDAta: " + targetData +"\n");
994 if (targetData.length < 1) {
995 //print("Can not find drop node path");
997 Gtk.drag_finish (ctx, false, false, time); // drop failed..
1003 // continue on to allow drop..
1005 // at this point, drag is not in motion... -- as checked above... - so it's a real drop event..
1008 var delete_selection_data = false;
1010 if (action == Gdk.DragAction.ASK) {
1011 // Ask the user to move or copy, then set the ctx action.
1014 if (action == Gdk.DragAction.MOVE) {
1015 delete_selection_data = true;
1018 // drag around.. - reorder..
1019 _this.model.moveNode(targetData, action);
1025 // we can send stuff to souce here...
1028 // do we always say failure, so we handle the reall drop?
1029 Gtk.drag_finish (ctx, false, false,time); //delete_selection_data, time);
1042 this.el.motion.connect( ( x, y) => {
1044 var is_shift = _this.keystate.is_shift > 0;
1046 GLib.debug("shift is %s", _this.keystate.is_shift > 0 ? "SHIFT" : "-");
1047 string pos; // over / before / after..
1049 //GLib.debug("got drag motion");
1051 GLib.Value v = GLib.Value(typeof(string));
1052 //var str = drop.read_text( [ "text/plain" ] 0);
1053 var cont = this.el.current_drop.get_drag().content ;
1055 cont.get_value(ref v);
1056 } catch (GLib.Error e) {
1057 GLib.debug("failed to get drag value");
1058 return Gdk.DragAction.COPY;
1062 //GLib.debug("got %s", v.get_string());
1064 if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
1065 // still dragging same node
1067 this.lastDragNode = new JsRender.Node();
1068 this.lastDragNode.loadFromJsonString(v.get_string(), 1);
1072 var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(
1073 this.lastDragNode.fqn());
1076 foreach(var dp in drop_on_to) {
1079 GLib.debug("droplist: %s", string.joinv(", ", str));
1082 // if there are not items in the tree.. the we have to set isOver to true for anything..
1084 if (_this.model.el.n_items < 1) {
1085 // FIXME check valid drop types?
1086 if (drop_on_to.contains("*top")) {
1087 this.addHighlight(_this.view.el, "over");
1089 this.addHighlight(null, "");
1092 return Gdk.DragAction.COPY; // no need to highlight?
1097 GLib.debug("check is over");
1099 // if path of source and dest are inside each other..
1100 // need to add source info to drag?
1102 var row = _this.view.getRowAt(x,y, out pos);
1105 this.addHighlight(null, "");
1106 return Gdk.DragAction.COPY;
1108 var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
1110 var node = (JsRender.Node)tr.get_item();
1112 GLib.debug("Drop over node: %s", node.fqn());
1115 if (pos == "above" || pos == "below") {
1116 if (node.parent == null) {
1117 GLib.debug("no parent try center");
1121 if (!drop_on_to.contains(node.parent.fqn())) {
1122 GLib.debug("drop on does not contain %s - try center" , node.parent.fqn());
1125 GLib.debug("drop contains %s - using %s" , node.parent.fqn(), pos);
1126 if (_this.view.dragNode != null && is_shift) {
1127 if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
1128 GLib.debug("shift drop not self not allowed");
1129 this.addHighlight(null, "");
1130 return Gdk.DragAction.COPY;
1143 if (pos == "over") {
1144 if (!drop_on_to.contains(node.fqn())) {
1145 GLib.debug("drop on does not contain %s - try center" , node.fqn());
1146 this.addHighlight(null, "");
1147 return is_shift ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY;
1149 if (_this.view.dragNode != null && is_shift) {
1150 if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
1151 GLib.debug("shift drop not self not allowed");
1152 this.addHighlight(null, "");
1153 return Gdk.DragAction.COPY;
1160 // _this.view.highlightDropPath("", (Gtk.TreeViewDropPosition)0);
1161 var w = _this.view.getWidgetAt(x,y);
1162 this.addHighlight(w, pos);
1163 return is_shift ? Gdk.DragAction.MOVE : Gdk.DragAction.COPY;
1165 this.el.leave.connect( ( ) => {
1166 this.addHighlight(null,"");
1169 this.el.drop.connect( (v, x, y) => {
1171 this.addHighlight(null,"");
1173 var is_shift = _this.keystate.is_shift > 0;
1176 // -- get position..
1177 if (this.lastDragString != v.get_string() || this.lastDragNode == null) {
1178 // still dragging same node
1180 this.lastDragNode = new JsRender.Node();
1181 this.lastDragNode.loadFromJsonString(v.get_string(), 1);
1186 var dropNode = new JsRender.Node();
1187 dropNode.loadFromJsonString(v.get_string(), 1);
1188 var drop_on_to = _this.main_window.windowstate.file.palete().getDropList(dropNode.fqn());
1190 // if there are not items in the tree.. the we have to set isOver to true for anything..
1192 if (_this.model.el.n_items < 1) {
1193 // FIXME check valid drop types?
1194 if (!drop_on_to.contains("*top")) {
1195 GLib.debug("drop on to list does not contain top?");
1198 // add new node to top..
1201 var m = (GLib.ListStore) _this.model.el.model;
1202 _this.main_window.windowstate.file.tree = dropNode;
1203 dropNode.updated_count++;
1206 _this.model.selectNode(dropNode);
1208 return true; // no need to highlight?
1214 var row = _this.view.getRowAt(x,y, out pos);
1216 return false; //Gdk.DragAction.COPY;
1218 var tr = (Gtk.TreeListRow)_this.view.el.model.get_object(row);
1220 var node = (JsRender.Node)tr.get_item();
1222 if (pos == "above" || pos == "below") {
1223 if (node.parent == null) {
1226 if (!drop_on_to.contains(node.parent.fqn())) {
1229 GLib.debug("drop contains %s - using %s" , node.parent.fqn(), pos);
1230 if (_this.view.dragNode != null && is_shift) {
1231 if (node.parent.oid == _this.view.dragNode.oid || node.parent.has_parent(_this.view.dragNode)) {
1232 GLib.debug("shift drop not self not allowed");
1243 if (pos == "over") {
1244 if (!drop_on_to.contains(node.fqn())) {
1245 GLib.debug("drop on does not contain %s - try center" , node.fqn());
1249 if (node.oid == _this.view.dragNode.oid || node.has_parent(_this.view.dragNode)) {
1250 GLib.debug("shift drop not self not allowed");
1257 node.appendChild(dropNode);
1258 if (is_shift && _this.view.dragNode != null) {
1259 _this.model.selectNode(null);
1260 _this.view.dragNode.remove();
1263 dropNode.updated_count++;
1264 _this.model.selectNode(dropNode);
1270 GLib.debug("Above - insertBefore");
1272 node.parent.insertBefore(dropNode, node);
1273 if (is_shift && _this.view.dragNode != null) {
1274 _this.model.selectNode(null);
1275 _this.view.dragNode.remove();
1277 dropNode.updated_count++;
1278 _this.model.selectNode(dropNode);
1283 GLib.debug("Below - insertAfter");
1284 if (is_shift && _this.view.dragNode != null) {
1285 _this.model.selectNode(null);
1286 _this.view.dragNode.remove();
1290 node.parent.insertAfter(dropNode, node);
1291 dropNode.updated_count++;
1292 _this.model.selectNode(dropNode);
1298 // should not happen
1310 // user defined functions
1311 public void addHighlight (Gtk.Widget? w, string hl) {
1312 if (this.highlightWidget != null) {
1313 var ww = this.highlightWidget;
1314 GLib.debug("clear drag from previous highlight");
1315 if (ww.has_css_class("drag-below")) {
1316 ww.remove_css_class("drag-below");
1318 if (ww.has_css_class("drag-above")) {
1319 ww.remove_css_class("drag-above");
1321 if (ww.has_css_class("drag-over")) {
1322 ww.remove_css_class("drag-over");
1326 GLib.debug("add drag=%s to widget", hl);
1327 if (!w.has_css_class("drag-" + hl)) {
1328 w.add_css_class("drag-" + hl);
1331 this.highlightWidget = w;
1335 public class Xcls_selmodel : Object
1337 public Gtk.SingleSelection el;
1338 private Xcls_WindowLeftTree _this;
1344 public Xcls_selmodel(Xcls_WindowLeftTree _owner )
1347 _this.selmodel = this;
1348 new Xcls_model( _this );
1349 this.el = new Gtk.SingleSelection( _this.model.el );
1353 // set gobject values
1356 this.el.selection_changed.connect( (position, n_items) => {
1360 //if (!this.button_is_pressed && !this.key_is_pressed) {
1361 // then event was started by some other action
1362 // which should manually trigger all the events..
1363 // print("SKIPPING select - no button or key pressed\n");
1368 if (_this.view.blockChanges) { // probably not needed..
1369 GLib.debug("SKIPPING select - blockchanges set..");
1373 if (!_this.before_node_change( ) ) {
1374 _this.view.blockChanges = true;
1375 _this.selmodel.el.unselect_all();
1376 _this.view.blockChanges = false;
1380 if (_this.main_window.windowstate.file == null) {
1381 GLib.debug("SKIPPING select windowstate file is not set...");
1385 //var render = this.get('/LeftTree').getRenderer();
1386 GLib.debug("LEFT TREE -> view -> selection changed called");
1389 // -- it appears that the selection is not updated.
1390 // select the node...
1391 //_this.selmodel.el.set_selected(row);
1393 GLib.debug("LEFT TREE -> view -> selection changed TIMEOUT CALLED");
1395 var snode = _this.selmodel.getSelectedNode();
1396 if (snode == null) {
1398 GLib.debug("selected rows < 1");
1399 //??this.model.load( false);
1400 _this.node_selected(null);
1408 GLib.debug ("calling left_tree.node_selected");
1409 _this.node_selected(snode);
1414 // no need to scroll. it's in the view as we clicked on it.
1415 // _this.view.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f);
1421 // user defined functions
1422 public JsRender.Node? getSelectedNode () {
1423 if (this.el.selected_item == null) {
1426 var tr = (Gtk.TreeListRow)this.el.selected_item;
1427 return (JsRender.Node)tr.get_item();
1430 public JsRender.Node getNodeAt (uint row) {
1432 var tr = (Gtk.TreeListRow)this.el.get_item(row);
1434 var a = tr.get_item();;
1435 GLib.debug("get_item (2) = %s", a.get_type().name());
1438 return (JsRender.Node)tr.get_item();
1442 public class Xcls_model : Object
1444 public Gtk.TreeListModel el;
1445 private Xcls_WindowLeftTree _this;
1451 public Xcls_model(Xcls_WindowLeftTree _owner )
1455 this.el = this.updateModel(null);
1459 // set gobject values
1462 // user defined functions
1463 public void loadFile (JsRender.JsRender f) {
1466 _this.drop.highlightWidget = null;
1468 var m = (GLib.ListStore) this.el.model;
1470 _this.main_window.windowstate.leftTreeNodeSelected(null);
1472 _this.main_window.windowstate.file = f;
1473 _this.last_error_counter = -1;
1475 if (f.tree == null) {
1482 // if it's still null?
1483 if (f.tree == null) {
1484 _this.main_window.windowstate.showAddObject(_this.view.el, null);
1485 _this.updateErrors();
1489 _this.updateErrors();
1491 _this.selmodel.el.set_selected(Gtk.INVALID_LIST_POSITION);
1497 public int nodeToRow (JsRender.Node node)
1500 var s = _this.view.el.model as Gtk.SingleSelection;
1501 for (var i = 0; i < s.n_items; i++) {
1502 //GLib.debug("check node %s", s.get_item(i).get_type().name());
1503 var lr = s.get_item(i) as Gtk.TreeListRow;
1504 //GLib.debug("check node %s", lr.get_item().get_type().name());
1505 if ((lr.get_item() as JsRender.Node).oid == node.oid) {
1514 public void deleteSelected () {
1518 var node = _this.selmodel.getSelectedNode();
1522 GLib.debug("delete Selected - no node slected?");
1525 _this.selmodel.el.unselect_all();
1528 GLib.debug("delete Selected - done");
1531 print("DELETE SELECTED?");
1532 //_this.view.blockChanges = true;
1533 print("GET SELECTION?");
1535 var s = _this.view.el.get_selection();
1537 print("GET SELECTED?");
1542 if (!s.get_selected(out mod, out iter)) {
1543 return; // nothing seleted..
1548 this.activePath= "";
1549 print("GET vnode value?");
1552 this.el.get_value(iter, 2, out value);
1553 var data = (JsRender.Node)(value.get_object());
1554 print("removing node from Render\n");
1555 if (data.parent == null) {
1556 _this.main_window.windowstate.file.tree = null;
1560 print("removing node from Tree\n");
1562 this.el.remove(ref iter);
1572 this.activePath= ""; // again!?!?
1573 //this.changed(null,true);
1577 _this.view.blockChanges = false;
1580 public Gtk.TreeListModel updateModel (GLib.ListStore? m) {
1581 this.el = new Gtk.TreeListModel(
1582 m != null ? m : new GLib.ListStore(typeof(JsRender.Node)), //..... << that's our store..
1586 return ((JsRender.Node)item).childstore;
1590 if (_this.selmodel.el == null) {
1593 _this.selmodel.el.set_model(this.el);
1596 public void selectNode (JsRender.Node node)
1598 var row = this.nodeToRow(node);
1599 var s = _this.view.el.model as Gtk.SingleSelection;
1603 GLib.debug("Could not find node");
1606 GLib.debug("Select %d", row);
1607 s.set_selected(row);
1608 _this.view.el.scroll_to(row, null, Gtk.ListScrollFlags.SELECT, null);
1609 //_this.node_selected(node);
1616 public class Xcls_maincol : Object
1618 public Gtk.ColumnViewColumn el;
1619 private Xcls_WindowLeftTree _this;
1625 public Xcls_maincol(Xcls_WindowLeftTree _owner )
1628 _this.maincol = this;
1629 var child_1 = new Xcls_SignalListItemFactory14( _this );
1631 this.el = new Gtk.ColumnViewColumn( "Property", child_1.el );
1635 // set gobject values
1636 this.el.id = "maincol";
1637 this.el.expand = true;
1638 this.el.resizable = true;
1641 // user defined functions
1643 public class Xcls_SignalListItemFactory14 : Object
1645 public Gtk.SignalListItemFactory el;
1646 private Xcls_WindowLeftTree _this;
1652 public Xcls_SignalListItemFactory14(Xcls_WindowLeftTree _owner )
1655 this.el = new Gtk.SignalListItemFactory();
1659 // set gobject values
1662 this.el.setup.connect( (listitem) => {
1664 var expand = new Gtk.TreeExpander();
1666 expand.set_indent_for_depth(true);
1667 expand.set_indent_for_icon(true);
1668 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
1669 var icon = new Gtk.Image();
1670 var lbl = new Gtk.Label("");
1671 lbl.use_markup = true;
1672 lbl.ellipsize = Pango.EllipsizeMode.END;
1674 icon.margin_end = 4;
1675 lbl.justify = Gtk.Justification.LEFT;
1678 // listitem.activatable = true; ??
1682 expand.set_child(hbox);
1683 ((Gtk.ListItem)listitem).set_child(expand);
1686 this.el.bind.connect( (listitem) => {
1687 GLib.debug("listitme is is %s", ((Gtk.ListItem)listitem).get_type().name());
1689 //var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1690 var expand = (Gtk.TreeExpander) ((Gtk.ListItem)listitem).get_child();
1693 var hbox = (Gtk.Box) expand.child;
1696 var img = (Gtk.Image) hbox.get_first_child();
1697 var lbl = (Gtk.Label) img.get_next_sibling();
1699 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1700 var node = (JsRender.Node) lr.get_item();
1702 GLib.debug("node is %s", node.get_type().name());
1703 // was item (1) in old layout
1708 var ic = Gtk.IconTheme.get_for_display(_this.el.get_display());
1709 var clsname = node.fqn();
1711 var clsb = clsname.split(".");
1712 var sub = clsb.length > 1 ? clsb[1].down() : "";
1714 var fn = "/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-" + sub + ".png";
1718 if (FileUtils.test (fn, FileTest.IS_REGULAR)) {
1719 img.set_from_file(fn);
1722 img.set_from_paintable(
1724 "media-playback-stop", null, 16,1,
1725 Gtk.TextDirection.NONE, 0
1729 } catch (GLib.Error e) {}
1731 expand.set_hide_expander( !node.hasChildren() );
1732 expand.set_list_row(lr);
1734 node.bind_property("iconResourceName",
1736 GLib.BindingFlags.SYNC_CREATE);
1738 node.bind_property("nodeTitleProp",
1740 GLib.BindingFlags.SYNC_CREATE);
1741 node.bind_property("nodeTipProp",
1742 lbl, "tooltip_markup",
1743 GLib.BindingFlags.SYNC_CREATE);
1749 // user defined functions
1753 public class Xcls_ColumnViewColumn15 : Object
1755 public Gtk.ColumnViewColumn el;
1756 private Xcls_WindowLeftTree _this;
1762 public Xcls_ColumnViewColumn15(Xcls_WindowLeftTree _owner )
1765 var child_1 = new Xcls_SignalListItemFactory16( _this );
1767 this.el = new Gtk.ColumnViewColumn( "Add", child_1.el );
1771 // set gobject values
1772 this.el.fixed_width = 25;
1775 // user defined functions
1777 public class Xcls_SignalListItemFactory16 : Object
1779 public Gtk.SignalListItemFactory el;
1780 private Xcls_WindowLeftTree _this;
1786 public Xcls_SignalListItemFactory16(Xcls_WindowLeftTree _owner )
1789 this.el = new Gtk.SignalListItemFactory();
1793 // set gobject values
1796 this.el.setup.connect( (listitem) => {
1799 var icon = new Gtk.Image();
1801 ((Gtk.ListItem)listitem).set_child(icon);
1803 this.el.bind.connect( (listitem) => {
1805 var img = (Gtk.Image) ((Gtk.ListItem)listitem).get_child();
1806 var lr = (Gtk.TreeListRow)((Gtk.ListItem)listitem).get_item();
1807 var node = (JsRender.Node) lr.get_item();
1810 var ic = Gtk.IconTheme.get_for_display(_this.el.get_display());
1811 img.set_from_paintable(
1813 "list-add", null, 16,1,
1814 Gtk.TextDirection.NONE, 0
1818 var fqn = node.fqn();
1819 var cn = _this.main_window.windowstate.project.palete.getChildList(fqn, false);
1821 img.set_visible(cn.size > 0 ? true : false);
1826 // user defined functions
1831 public class Xcls_LeftTreeMenu : Object
1833 public Gtk.Popover el;
1834 private Xcls_WindowLeftTree _this;
1840 public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner )
1843 _this.LeftTreeMenu = this;
1844 this.el = new Gtk.Popover();
1848 // set gobject values
1849 var child_1 = new Xcls_Box18( _this );
1850 this.el.child = child_1.el;
1853 // user defined functions
1855 public class Xcls_Box18 : Object
1858 private Xcls_WindowLeftTree _this;
1864 public Xcls_Box18(Xcls_WindowLeftTree _owner )
1867 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1871 // set gobject values
1872 var child_1 = new Xcls_Button19( _this );
1874 this.el.append( child_1.el );
1875 var child_2 = new Xcls_Button20( _this );
1877 this.el.append( child_2.el );
1878 var child_3 = new Xcls_Button21( _this );
1880 this.el.append( child_3.el );
1883 // user defined functions
1885 public class Xcls_Button19 : Object
1887 public Gtk.Button el;
1888 private Xcls_WindowLeftTree _this;
1894 public Xcls_Button19(Xcls_WindowLeftTree _owner )
1897 this.el = new Gtk.Button();
1901 // set gobject values
1902 this.el.has_frame = false;
1903 this.el.label = "Delete Element";
1906 this.el.clicked.connect( ( ) => {
1907 _this.LeftTreeMenu.el.hide();
1908 _this.model.deleteSelected();
1913 // user defined functions
1916 public class Xcls_Button20 : Object
1918 public Gtk.Button el;
1919 private Xcls_WindowLeftTree _this;
1925 public Xcls_Button20(Xcls_WindowLeftTree _owner )
1928 this.el = new Gtk.Button();
1932 // set gobject values
1933 this.el.has_frame = false;
1934 this.el.label = "Save as Template";
1937 this.el.clicked.connect( () => {
1938 _this.LeftTreeMenu.el.hide();
1939 DialogSaveTemplate.singleton().showIt(
1940 (Gtk.Window) _this.el.get_root (),
1941 _this.main_window.windowstate.file.palete(),
1942 _this.getActiveElement()
1949 // user defined functions
1952 public class Xcls_Button21 : Object
1954 public Gtk.Button el;
1955 private Xcls_WindowLeftTree _this;
1961 public Xcls_Button21(Xcls_WindowLeftTree _owner )
1964 this.el = new Gtk.Button();
1968 // set gobject values
1969 this.el.has_frame = false;
1970 this.el.label = "Save as Module";
1973 this.el.clicked.connect( () => {
1975 _this.LeftTreeMenu.el.hide();
1976 var node = _this.getActiveElement();
1979 var sm = DialogSaveModule.singleton();
1983 (Gtk.Window) _this.el.get_root (),
1984 _this.main_window.windowstate.project,
1988 gtk4 migration - disabled this part.. probably not used muchanyway
1991 if (name.length < 1) {
1995 node.set_prop( new JsRender.NodeProp.special("xinclude", name));
1999 var s = _this.view.el.get_selection();
2001 print("GET SELECTED?");
2006 if (!s.get_selected(out mod, out iter)) {
2007 return; // nothing seleted..
2010 var n_cn = mod.iter_n_children(iter) -1;
2011 for (var i = n_cn; i > -1; i--) {
2012 mod.iter_nth_child(out citer, iter, i);
2015 print("removing node from Tree\n");
2017 _this.model.el.remove(ref citer);
2020 _this.node_selected(node, "tree");
2026 // user defined functions