@@ -201,9 +201,6 @@ func update_config() -> void:
201201 var gui : Node = x .get_control ()
202202 if is_instance_valid (gui ) and gui is Control :
203203 gui .modulate = Color .WHITE
204-
205- for x : Mickeytools in _code_editors :
206- x .update_focus_behaviour ()
207204
208205func _update_container () -> void :
209206 if ! is_instance_valid (_main ):
@@ -441,26 +438,36 @@ class Mickeytools extends Object:
441438
442439 func set_root (root : Node ) -> void :
443440 _root = root
444-
445- func _on_input (__ : InputEvent ) -> void :
446- if __ is InputEventMouseMotion :
447- return
441+
442+ func _context_update (window : Window , control : Control ) -> void :
443+ if is_instance_valid (window ) and is_instance_valid (control ) and is_instance_valid (_root ):
444+ var root : Viewport = _root .get_viewport ()
445+ var gvp : Vector2 = control .get_global_mouse_position ()
446+ gvp .x += (window .size .x / 4.0 )
447+ gvp .y = min (gvp .y , root .size .y - window .size .y + 16.0 )
448+ gvp .x = min (gvp .x , root .size .x - window .size .x + 16.0 )
449+
450+ window .set_deferred (& "position" , gvp )
451+
448452
449- var tab : TabContainer = _root
450-
451- var parent : Node = tab .get_parent ()
452- if parent and parent .has_method (& "show_splited_container" ):
453- parent .call (& "show_splited_container" )
454453
455- func update_focus_behaviour ( ) -> void :
456- if ! is_instance_valid ( _gui ) or _gui . focus_mode == Control . FOCUS_NONE :
454+ func _on_input ( input : InputEvent ) -> void :
455+ if input is InputEventMouseMotion :
457456 return
458457
458+ if input is InputEventMouseButton :
459+ if input .pressed and input .button_index == 2 :
460+ if _reference .get_child_count () > 1 :
461+ var variant : Node = _reference .get_child (1 )
462+ if variant is Window and _gui is Control :
463+ _context_update .call_deferred (variant , _gui )
464+
459465 if _helper .can_expand_same_focus ():
460- if ! _gui .gui_input .is_connected (_on_input ):
461- _gui .gui_input .connect (_on_input )
462- elif _gui .gui_input .is_connected (_on_input ):
463- _gui .gui_input .disconnect (_on_input )
466+ var tab : TabContainer = _root
467+
468+ var parent : Node = tab .get_parent ()
469+ if parent and parent .has_method (& "show_splited_container" ):
470+ parent .call (& "show_splited_container" )
464471
465472 func set_reference (control : Node ) -> void :
466473 if ! is_instance_valid (control ):
@@ -469,6 +476,8 @@ class Mickeytools extends Object:
469476 return
470477 elif is_instance_valid (_reference ):
471478 reset ()
479+ # if _reference is CanvasItem:
480+ # _gui.get_parent()
472481
473482 if is_instance_valid (_gui ) and _gui .gui_input .is_connected (_on_input ):
474483 _gui .gui_input .disconnect (_on_input )
@@ -479,7 +488,6 @@ class Mickeytools extends Object:
479488
480489 if control is ScriptEditorBase :
481490 _gui = control .get_base_editor ()
482- update_focus_behaviour ()
483491
484492 if _gui is CodeEdit :
485493 var carets : PackedInt32Array = _gui .get_sorted_carets ()
@@ -504,8 +512,18 @@ class Mickeytools extends Object:
504512 else :
505513 for x : Node in control .get_children ():
506514 if x is RichTextLabel :
507- _gui = x
508- _control = x
515+ if _reference is CanvasItem :
516+ var canvas : VBoxContainer = VBoxContainer .new ()
517+ canvas .size_flags_vertical = Control .SIZE_EXPAND_FILL
518+ canvas .size_flags_vertical = Control .SIZE_EXPAND_FILL
519+ if canvas .get_child_count () < 1 :
520+ for n : Node in _reference .get_children ():
521+ n .reparent (canvas )
522+ _gui = canvas
523+ _control = canvas
524+ else :
525+ _gui = x
526+ _control = x
509527 break
510528
511529 if _control == null :
@@ -518,21 +536,27 @@ class Mickeytools extends Object:
518536 if null != parent :
519537 _parent = parent
520538
521- if null != _gui :
522- if ! _gui .focus_entered .is_connected (_i_like_coffe ):
523- _gui .focus_entered .connect (_i_like_coffe )
524-
525539 if is_instance_valid (_parent ) and _control .get_parent () == _parent :
526540 _index = _control .get_index ()
527541 _parent .remove_child (_control )
528542
529543 _root .add_child (_control )
530544
531545 if _gui :
532- if ! _gui .is_node_ready ():
533- await _gui .ready
534- if is_instance_valid (_gui ):
535- focus .emit (self )
546+ var gui : Control = _gui
547+
548+ if gui .focus_mode != Control .FOCUS_NONE :
549+ if ! gui .gui_input .is_connected (_on_input ):
550+ gui .gui_input .connect (_on_input )
551+
552+ if gui is VBoxContainer :
553+ gui = gui .get_child (0 )
554+ if ! gui .focus_entered .is_connected (_i_like_coffe ):
555+ gui .focus_entered .connect (_i_like_coffe )
556+ if ! gui .is_node_ready ():
557+ await gui .ready
558+ if is_instance_valid (gui ):
559+ focus .emit (self )
536560
537561 func update () -> void :
538562 if is_instance_valid (_control ) and is_instance_valid (_reference ):
@@ -553,11 +577,23 @@ class Mickeytools extends Object:
553577 func reset (disconnect_signals : bool = true ) -> void :
554578 if is_instance_valid (_gui ):
555579 if disconnect_signals :
556- if _gui .focus_entered .is_connected (_i_like_coffe ):
557- _gui .focus_entered .disconnect (_i_like_coffe )
558- if _gui .gui_input .is_connected (_on_input ):
559- _gui .gui_input .disconnect (_on_input )
580+ var gui : Control = _gui
581+ if gui is VBoxContainer :
582+ gui = gui .get_child (0 )
583+ if gui .focus_entered .is_connected (_i_like_coffe ):
584+ gui .focus_entered .disconnect (_i_like_coffe )
585+ if gui .gui_input .is_connected (_on_input ):
586+ gui .gui_input .disconnect (_on_input )
560587 _gui .modulate = Color .WHITE
588+
589+ if _gui is VBoxContainer :
590+ for x : Node in _gui .get_children ():
591+ x .reparent (_reference )
592+ if _gui != _control :
593+ _gui .queue_free ()
594+ _gui = null
595+ _control .queue_free ()
596+ _control = null
561597
562598 if is_instance_valid (_control ):
563599 if is_instance_valid (_parent ):
@@ -693,6 +729,8 @@ func _set_focus(tool : Mickeytools, txt : String = "", items : PackedStringArray
693729 if wm and ! wm .has_focus ():
694730 wm .grab_focus ()
695731 if ! gui .has_focus ():
732+ if gui is VBoxContainer :
733+ gui = gui .get_child (0 )
696734 gui .grab_focus ()
697735
698736 var item_list : ItemList = _item_list
@@ -1216,6 +1254,11 @@ func find_editor(node : Node) -> Control:
12161254func can_remove_split (node : Node ) -> bool :
12171255 if ! is_instance_valid (_main ):
12181256 return false
1257+
1258+ if node == null :
1259+ return _code_editors .size () > 1
1260+
1261+
12191262 if _code_editors .size () > 1 :
12201263 if node is CodeEdit :
12211264 var main : bool = false
@@ -1244,6 +1287,9 @@ func can_add_split(_node : Node) -> bool:
12441287 if ! is_instance_valid (_main ):
12451288 return false
12461289
1290+ if _node == null :
1291+ return _code_editors .size () < _editor .get_child_count ()
1292+
12471293 for o : int in _editor .get_child_count ():
12481294 if get_item_text (o ).begins_with (_POP_SCRIPT_PLACEHOLDER ):
12491295 continue
0 commit comments