summaryrefslogtreecommitdiff
path: root/addons/gut/gui/BottomPanelShortcuts.gd
blob: 86fbf8dc3e2705865a8330a8f959b2d64b549816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
tool
extends WindowDialog

onready var _ctrls = {
	run_all = $Layout/CRunAll/ShortcutButton,
	run_current_script = $Layout/CRunCurrentScript/ShortcutButton,
	run_current_inner = $Layout/CRunCurrentInner/ShortcutButton,
	run_current_test = $Layout/CRunCurrentTest/ShortcutButton,
	panel_button = $Layout/CPanelButton/ShortcutButton,
}

func _ready():
	for key in _ctrls:
		var sc_button = _ctrls[key]
		sc_button.connect('start_edit', self, '_on_edit_start', [sc_button])
		sc_button.connect('end_edit', self, '_on_edit_end')


	# show dialog when running scene from editor.
	if(get_parent() == get_tree().root):
		popup_centered()

# ------------
# Events
# ------------
func _on_Hide_pressed():
	hide()

func _on_edit_start(which):
	for key in _ctrls:
		var sc_button = _ctrls[key]
		if(sc_button != which):
			sc_button.disable_set(true)
			sc_button.disable_clear(true)

func _on_edit_end():
	for key in _ctrls:
		var sc_button = _ctrls[key]
		sc_button.disable_set(false)
		sc_button.disable_clear(false)

# ------------
# Public
# ------------
func get_run_all():
	return _ctrls.run_all.get_shortcut()

func get_run_current_script():
	return _ctrls.run_current_script.get_shortcut()

func get_run_current_inner():
	return _ctrls.run_current_inner.get_shortcut()

func get_run_current_test():
	return _ctrls.run_current_test.get_shortcut()

func get_panel_button():
	return _ctrls.panel_button.get_shortcut()


func save_shortcuts(path):
	var f = ConfigFile.new()

	f.set_value('main', 'run_all', _ctrls.run_all.get_shortcut())
	f.set_value('main', 'run_current_script', _ctrls.run_current_script.get_shortcut())
	f.set_value('main', 'run_current_inner', _ctrls.run_current_inner.get_shortcut())
	f.set_value('main', 'run_current_test', _ctrls.run_current_test.get_shortcut())
	f.set_value('main', 'panel_button', _ctrls.panel_button.get_shortcut())

	f.save(path)


func load_shortcuts(path):
	var emptyShortcut = ShortCut.new()
	var f = ConfigFile.new()
	f.load(path)

	_ctrls.run_all.set_shortcut(f.get_value('main', 'run_all', emptyShortcut))
	_ctrls.run_current_script.set_shortcut(f.get_value('main', 'run_current_script', emptyShortcut))
	_ctrls.run_current_inner.set_shortcut(f.get_value('main', 'run_current_inner', emptyShortcut))
	_ctrls.run_current_test.set_shortcut(f.get_value('main', 'run_current_test', emptyShortcut))
	_ctrls.panel_button.set_shortcut(f.get_value('main', 'panel_button', emptyShortcut))