class_name OpenWithNode
extends ConfirmationDialog

var mime_type: String = ""
onready var mime_rich_text_label: RichTextLabel = \
		find_node("MIMERichTextLabel")
onready var command_line_edit: LineEdit = find_node("CommandLineEdit")
onready var always_use_check_box: CheckBox = find_node("AlwaysUseCheckBox")
onready var use_streaming_check_box: CheckBox = \
		find_node("UseStreamingCheckBox")


func init(mime_type_: String) -> void:
	mime_type = mime_type_


func _ready() -> void:
	if mime_type.empty():
		push_warning("MIME type is empty")
	
	mime_rich_text_label.set_bbcode("Media type: [b]" + mime_type + "[/b]")
	
	var media_opener: Dictionary = Data.get_media_opener(mime_type)
	var current_command: String = media_opener.get("command", "")
	var use_streaming: bool = media_opener.get("use_streaming", false)
	command_line_edit.set_text(current_command)
	use_streaming_check_box.set_pressed(use_streaming)
	
	var text: String = "Many programs don't support streamed files, so if you"
	text += " encounter\nissues opening the file with this option enabled, try"
	text += " disabling it."
	use_streaming_check_box.set_tooltip(text)


func get_command() -> String:
	return command_line_edit.get_text()


func get_always_use() -> bool:
	return always_use_check_box.is_pressed()


func get_use_streaming() -> bool:
	return use_streaming_check_box.is_pressed()
