Initial commit
This commit is contained in:
55
scripts/libs/ui_util.gd
Normal file
55
scripts/libs/ui_util.gd
Normal file
@@ -0,0 +1,55 @@
|
||||
extends Node
|
||||
|
||||
class_name GDBUIUtility
|
||||
|
||||
static func uncollapse_tree_item(tree_item : TreeItem):
|
||||
while tree_item:
|
||||
tree_item.collapsed = false
|
||||
tree_item = tree_item.get_parent()
|
||||
|
||||
static func find_scene_tree_editor(root : Node = null) -> Node:
|
||||
if not root:
|
||||
root = (Engine.get_main_loop() as SceneTree).root
|
||||
if root.get_class() == "SceneTreeEditor":
|
||||
return root
|
||||
for child in root.get_children():
|
||||
var scene_tree_editor := find_scene_tree_editor(child)
|
||||
if scene_tree_editor:
|
||||
return scene_tree_editor
|
||||
return null
|
||||
|
||||
static func new_item_sorted(tree : Tree, parent : TreeItem, key : String, meta_column := 0) -> TreeItem:
|
||||
var item := parent.get_children()
|
||||
var found_itm : TreeItem
|
||||
var idx := 0
|
||||
while true:
|
||||
if item == null:
|
||||
break
|
||||
|
||||
var itm_key := item.get_metadata(meta_column) as String
|
||||
if itm_key == key:
|
||||
return item
|
||||
elif itm_key > key:
|
||||
break
|
||||
item = item.get_next()
|
||||
idx += 1
|
||||
|
||||
# not found
|
||||
var new_itm : TreeItem = tree.create_item(parent, idx)
|
||||
new_itm.set_metadata(meta_column, key)
|
||||
return new_itm
|
||||
|
||||
static func copy_size(target : Control, source : Control) -> void:
|
||||
target.rect_min_size = source.rect_min_size
|
||||
target.rect_size = source.rect_size
|
||||
target.size_flags_horizontal = source.size_flags_horizontal
|
||||
target.size_flags_vertical = source.size_flags_vertical
|
||||
target.size_flags_stretch_ratio = source.size_flags_stretch_ratio
|
||||
target.anchor_top = source.anchor_top
|
||||
target.anchor_bottom = source.anchor_bottom
|
||||
target.anchor_left = source.anchor_left
|
||||
target.anchor_right = source.anchor_right
|
||||
target.margin_top = source.margin_top
|
||||
target.margin_bottom = source.margin_bottom
|
||||
target.margin_left = source.margin_left
|
||||
target.margin_right = source.margin_right
|
||||
77
scripts/libs/ux.gd
Normal file
77
scripts/libs/ux.gd
Normal file
@@ -0,0 +1,77 @@
|
||||
# various UX stuff
|
||||
extends Object
|
||||
|
||||
class_name GDBUX
|
||||
|
||||
const __META_STATE = "__gdbui_ux_state__"
|
||||
|
||||
class __State:
|
||||
signal recent_places_changed()
|
||||
signal favourite_places_changed()
|
||||
|
||||
################
|
||||
# public stuff #
|
||||
################
|
||||
static func get_recent_places() -> Array:
|
||||
return GDBSettings.get_value(GDBConstants.SETTING_RECENT_PLACES, [])
|
||||
|
||||
static func add_recent_place(place) -> void:
|
||||
if place is UIB_FileAdapter.FileEntry:
|
||||
add_recent_place(place._get_path())
|
||||
return
|
||||
|
||||
assert(place is String)
|
||||
var recent_places : Array = GDBSettings.get_value(GDBConstants.SETTING_RECENT_PLACES, [])
|
||||
recent_places.erase(place)
|
||||
recent_places.push_front(place)
|
||||
GDBSettings.set_value(GDBConstants.SETTING_RECENT_PLACES, recent_places)
|
||||
|
||||
__get_state().emit_signal("recent_places_changed")
|
||||
|
||||
static func get_favourite_places() -> Array:
|
||||
return GDBSettings.get_value(GDBConstants.SETTING_FAVOURITE_PLACES, [])
|
||||
|
||||
static func is_favourite_place(place) -> bool:
|
||||
if place is UIB_FileAdapter.FileEntry:
|
||||
return is_favourite_place(place._get_path())
|
||||
|
||||
assert(place is String)
|
||||
return GDBSettings.array_has_value(GDBConstants.SETTING_FAVOURITE_PLACES, place)
|
||||
|
||||
static func add_favourite_place(place) -> void:
|
||||
if place is UIB_FileAdapter.FileEntry:
|
||||
add_favourite_place(place._get_path())
|
||||
return
|
||||
|
||||
assert(place is String)
|
||||
var places = GDBSettings.get_value(GDBConstants.SETTING_FAVOURITE_PLACES, [])
|
||||
if !places.has(place):
|
||||
places.append(place)
|
||||
GDBSettings.set_value(GDBConstants.SETTING_FAVOURITE_PLACES, places)
|
||||
|
||||
__get_state().emit_signal("favourite_places_changed")
|
||||
|
||||
static func remove_favourite_place(place) -> void:
|
||||
if place is UIB_FileAdapter.FileEntry:
|
||||
remove_favourite_place(place._get_path())
|
||||
return
|
||||
|
||||
assert(place is String)
|
||||
var places = GDBSettings.get_value(GDBConstants.SETTING_FAVOURITE_PLACES, [])
|
||||
if places.has(place):
|
||||
places.erase(place)
|
||||
GDBSettings.set_value(GDBConstants.SETTING_FAVOURITE_PLACES, places)
|
||||
|
||||
__get_state().emit_signal("favourite_places_changed")
|
||||
|
||||
static func connect_static(sig_name : String, receiver : Object, method : String, binds := []) -> int:
|
||||
return __get_state().connect(sig_name, receiver, method, binds)
|
||||
|
||||
static func disconnect_static(sig_name : String, receiver : Object, method : String) -> void:
|
||||
__get_state().disconnect(sig_name, receiver, method)
|
||||
|
||||
#################
|
||||
# private stuff #
|
||||
#################
|
||||
static func __get_state() -> __State:
|
||||
return GDBUtility.get_state_object(__META_STATE, __State)
|
||||
Reference in New Issue
Block a user