Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search system #11

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions addons/keychain/ShortcutEdit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,58 @@ func _on_DeleteConfirmation_confirmed() -> void:
Keychain.profile_index = 0
profile_option_button.select(Keychain.profile_index)
_on_ProfileOptionButton_item_selected(Keychain.profile_index)


func _on_Search_gui_input(event: InputEvent) -> void:
$"%Search".text = ""
if not event is InputEventKey:
return
if event.pressed:
$"%Search".text = OS.get_scancode_string(event.get_scancode_with_modifiers())
for map_action in InputMap.get_actions():
if map_action in Keychain.ignore_actions:
continue
if Keychain.ignore_ui_actions and map_action.begins_with("ui_"):
continue
for map_event in InputMap.get_action_list(map_action):
if !event.shortcut_match(map_event):
continue

# Loop through other actions to see if the event exists there, to re-assign it
var tree_item: TreeItem = tree.get_root()
var prev_tree_item: TreeItem
var results = []
while tree_item != null: # Loop through Tree's TreeItems...
if tree_item == tree.get_root():
tree_item.collapsed = false
var metadata = tree_item.get_metadata(0)
if metadata is InputEvent:
if map_event.shortcut_match(metadata):
results.append(tree_item)

# get_next_item
if tree_item.get_children():
tree_item = tree_item.get_children()
tree_item.collapsed = true
elif tree_item.get_next():
tree_item.collapsed = true
tree_item = tree_item.get_next()
else:
while tree_item and !tree_item.get_next():
if tree_item != tree.get_root():
tree_item.collapsed = true
tree_item = tree_item.get_parent()
if tree_item:
tree_item.collapsed = true
tree_item = tree_item.get_next()
var expanded = []
for result in results:
var item :TreeItem = result
while item.get_parent():
if expanded.has(item):
break
item.collapsed = false
expanded.append(item)
item = item.get_parent()
tree.scroll_to_item(results[0])
break
30 changes: 24 additions & 6 deletions addons/keychain/ShortcutEdit.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
[ext_resource path="res://addons/keychain/assets/mouse.svg" type="Texture" id=5]
[ext_resource path="res://addons/keychain/ShortcutSelectorDialog.tscn" type="PackedScene" id=6]

[node name="ShortcutEdit" type="Control"]
[node name="ShortcutEdit" type="VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_vertical = 3
script = ExtResource( 1 )

[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 1280.0
margin_bottom = 720.0
size_flags_vertical = 3

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_right = 1024.0
margin_right = 1280.0
margin_bottom = 20.0

[node name="ProfileLabel" type="Label" parent="VBoxContainer/HBoxContainer"]
Expand Down Expand Up @@ -64,40 +64,57 @@ text = "Open Folder"

[node name="ShortcutTree" type="Tree" parent="VBoxContainer"]
margin_top = 24.0
margin_right = 1024.0
margin_bottom = 600.0
margin_right = 1280.0
margin_bottom = 692.0
size_flags_vertical = 3
hide_root = true

[node name="Search" type="LineEdit" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 696.0
margin_right = 1280.0
margin_bottom = 720.0
align = 1
editable = false
placeholder_text = "Search for a shortcut by pressing it here"

[node name="ShortcutTypeMenu" type="PopupMenu" parent="."]
margin_right = 20.0
margin_bottom = 20.0
items = [ "Key", ExtResource( 3 ), 0, false, false, 0, 0, null, "", false, "Mouse Button", ExtResource( 5 ), 0, false, false, 1, 0, null, "", false, "Joy Button", ExtResource( 2 ), 0, false, false, 2, 0, null, "", false, "Joy Axis", ExtResource( 4 ), 0, false, false, 3, 0, null, "", false ]

[node name="KeyboardShortcutSelectorDialog" parent="." instance=ExtResource( 6 )]
rect_min_size = Vector2( 170, 59.5 )

[node name="MouseShortcutSelectorDialog" parent="." instance=ExtResource( 6 )]
rect_min_size = Vector2( 170, 59.5 )
input_type = 1

[node name="JoyKeyShortcutSelectorDialog" parent="." instance=ExtResource( 6 )]
rect_min_size = Vector2( 170, 59.5 )
input_type = 2

[node name="JoyAxisShortcutSelectorDialog" parent="." instance=ExtResource( 6 )]
rect_min_size = Vector2( 170, 59.5 )
input_type = 3

[node name="ProfileSettings" type="ConfirmationDialog" parent="."]
margin_right = 200.0
margin_bottom = 70.0
rect_min_size = Vector2( 170, 59.5 )

[node name="ProfileName" type="LineEdit" parent="ProfileSettings"]
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 34.0
caret_blink = true
caret_blink_speed = 0.5

[node name="DeleteConfirmation" type="ConfirmationDialog" parent="."]
margin_right = 200.0
margin_bottom = 70.0
rect_min_size = Vector2( 170, 59.5 )
dialog_text = "Are you sure you want to delete this shortcut profile?"

[connection signal="item_selected" from="VBoxContainer/HBoxContainer/ProfileOptionButton" to="." method="_on_ProfileOptionButton_item_selected"]
Expand All @@ -107,6 +124,7 @@ dialog_text = "Are you sure you want to delete this shortcut profile?"
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OpenProfileFolder" to="." method="_on_OpenProfileFolder_pressed"]
[connection signal="button_pressed" from="VBoxContainer/ShortcutTree" to="." method="_on_ShortcutTree_button_pressed"]
[connection signal="item_activated" from="VBoxContainer/ShortcutTree" to="." method="_on_ShortcutTree_item_activated"]
[connection signal="gui_input" from="VBoxContainer/Search" to="." method="_on_Search_gui_input"]
[connection signal="id_pressed" from="ShortcutTypeMenu" to="." method="_on_ShortcutTypeMenu_id_pressed"]
[connection signal="confirmed" from="ProfileSettings" to="." method="_on_ProfileSettings_confirmed"]
[connection signal="confirmed" from="DeleteConfirmation" to="." method="_on_DeleteConfirmation_confirmed"]