78 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			GDScript
		
	
	
	
	
	
| # 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)
 |