Dropdown menu for premade commands

This commit is contained in:
Sebastian Morr 2020-09-14 19:25:57 +02:00
parent 6d0fff27ad
commit 0b4c4f9449
2 changed files with 40 additions and 13 deletions

View file

@ -8,11 +8,22 @@ var history_position = 0
onready var input = $Control/Input
onready var output = $Control/Output
onready var repo = $"../Repositories/ActiveRepository"
onready var command_dropdown = $Control/CommandDropdown
onready var main = get_parent()
var premade_commands = [
'git commit --allow-empty -m "empty"',
'echo $RANDOM | git hash-object -w --stdin',
'git switch -c $RANDOM',
]
func _ready():
repo.shell.connect("output", self, "receive_output")
for command in premade_commands:
command_dropdown.get_popup().add_item(command)
command_dropdown.get_popup().connect("id_pressed", self, "load_command")
func _input(event):
if event is InputEventKey:
input.grab_focus()
@ -31,6 +42,10 @@ func _input(event):
input.caret_position = input.text.length()
get_tree().set_input_as_handled()
func load_command(id):
input.text = premade_commands[id]
input.caret_position = input.text.length()
func send_command(command):
history.push_back(command)
history_position = history.size()

View file

@ -43,7 +43,7 @@ __meta__ = {
[node name="Output" type="RichTextLabel" parent="Control"]
margin_right = 1920.0
margin_bottom = 979.0
margin_bottom = 1007.0
focus_mode = 2
size_flags_vertical = 3
custom_styles/normal = SubResource( 1 )
@ -53,54 +53,66 @@ scroll_following = true
selection_enabled = true
[node name="Button" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 979.0
margin_top = 887.0
margin_right = 1920.0
margin_bottom = 999.0
margin_bottom = 907.0
text = "git commit --allow-empty"
align = 0
[node name="Button5" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 999.0
margin_top = 907.0
margin_right = 1920.0
margin_bottom = 1019.0
margin_bottom = 927.0
text = "echo $RANDOM | git hash-object -w --stdin"
align = 0
[node name="Button6" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 1019.0
margin_top = 927.0
margin_right = 1920.0
margin_bottom = 1039.0
margin_bottom = 947.0
text = "git update-index --add noises; git write-tree"
align = 0
[node name="Button2" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 1019.0
margin_top = 947.0
margin_right = 1920.0
margin_bottom = 1039.0
margin_bottom = 967.0
text = "git switch -c $RANDOM"
align = 0
[node name="Button3" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 999.0
margin_top = 967.0
margin_right = 1920.0
margin_bottom = 1019.0
margin_bottom = 987.0
text = "git checkout HEAD^"
align = 0
[node name="Button4" parent="Control" instance=ExtResource( 4 )]
visible = false
margin_left = 0.0
margin_top = 1019.0
margin_top = 987.0
margin_right = 1920.0
margin_bottom = 1007.0
text = "sleep 1;echo hey"
align = 0
[node name="CommandDropdown" type="MenuButton" parent="Control"]
margin_top = 1007.0
margin_right = 1920.0
margin_bottom = 1039.0
text = "sleep 1;echo hey"
custom_fonts/font = ExtResource( 1 )
text = "Pick a command..."
flat = false
align = 0
[node name="Input" type="LineEdit" parent="Control"]