Skip to content

Commit

Permalink
Remember cursor position after various actions
Browse files Browse the repository at this point in the history
Closes #59
  • Loading branch information
nathanhoad committed Jul 8, 2022
1 parent 1fe1ab3 commit 93dcd83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 29 deletions.
9 changes: 9 additions & 0 deletions addons/dialogue_manager/components/code_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func _gui_input(event):
choose_title_dialog.choose_a_title(get_titles())


func get_cursor() -> Vector2:
return Vector2(cursor_get_column(), cursor_get_line())


func set_cursor(cursor: Vector2) -> void:
cursor_set_line(cursor.y, true)
cursor_set_column(cursor.x, true)


func insert_bbcode(open_tag: String, close_tag: String = "") -> void:
if close_tag == "":
insert_text_at_cursor(open_tag)
Expand Down
18 changes: 18 additions & 0 deletions addons/dialogue_manager/views/main_view.gd
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func set_resource(value: DialogueResource) -> void:
file_label.visible = true
editor.text = current_resource.raw_text
editor.clear_undo_history()
var cursors = settings.get_editor_value("resource_cursors", {})
if cursors.has(current_resource.resource_path):
var cursor = cursors.get(current_resource.resource_path)
editor.cursor_set_line(cursor.y, true)
editor.cursor_set_column(cursor.x, true)
content.visible = true
error_button.disabled = false
run_node_button.disabled = false
Expand Down Expand Up @@ -234,6 +239,8 @@ func generate_translations_keys() -> void:
randomize()
seed(OS.get_unix_time())

var cursor: Vector2 = editor.get_cursor()

var lines: PoolStringArray = editor.text.split("\n")

var key_regex = RegEx.new()
Expand Down Expand Up @@ -286,6 +293,7 @@ func generate_translations_keys() -> void:
known_keys[key] = text

editor.text = lines.join("\n")
editor.set_cursor(cursor)
_on_CodeEditor_text_changed()


Expand Down Expand Up @@ -359,6 +367,7 @@ func _on_open_menu_index_pressed(index):
"Clear recent files":
recent_resources.clear()
settings.set_editor_value("recent_resources", recent_resources)
settings.set_editor_value("resource_cursors", {})
build_open_menu()
_:
open_resource_from_path(item)
Expand Down Expand Up @@ -422,6 +431,12 @@ func _on_CodeEditor_active_title_changed(title):
run_node_button.hint_tooltip = "Play the test scene using \"%s\"" % title


func _on_CodeEditor_cursor_changed():
var next_resource_cursors = settings.get_editor_value("resource_cursors", {})
next_resource_cursors[current_resource.resource_path] = Vector2(editor.cursor_get_column(), editor.cursor_get_line())
settings.set_editor_value("resource_cursors", next_resource_cursors)


func _on_ParseTimeout_timeout():
parse_timeout.stop()
parse()
Expand Down Expand Up @@ -501,6 +516,8 @@ func _on_SearchToolbar_open_requested():

func _on_ImportTranslationsDialog_file_selected(path):
settings.set_editor_value("last_csv_path", path.get_base_dir())

var cursor: Vector2 = editor.get_cursor()

# Open the CSV file and build a dictionary of the known keys
var file = File.new()
Expand Down Expand Up @@ -546,3 +563,4 @@ func _on_ImportTranslationsDialog_file_selected(path):
lines[i] = (line.substr(0, start_index) + keys.get(translation_key) + " [TR:" + translation_key + "]" + line.substr(end_index)).replace("!ESCAPED_COLON!", ":")

editor.text = lines.join("\n")
editor.set_cursor(cursor)
59 changes: 30 additions & 29 deletions addons/dialogue_manager/views/main_view.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -105,56 +105,56 @@ icon = SubResource( 2 )
flat = true

[node name="Control" type="Control" parent="Margin/VBox/Toolbar"]
margin_right = 610.0
margin_right = 666.0
margin_bottom = 24.0
size_flags_horizontal = 3

[node name="NewButton" type="ToolButton" parent="Margin/VBox/Toolbar"]
margin_left = 614.0
margin_right = 642.0
margin_left = 670.0
margin_right = 698.0
margin_bottom = 24.0
hint_tooltip = "Make a new dialogue file"
icon = SubResource( 2 )

[node name="OpenButton" type="MenuButton" parent="Margin/VBox/Toolbar"]
margin_left = 646.0
margin_right = 674.0
margin_left = 702.0
margin_right = 730.0
margin_bottom = 24.0
hint_tooltip = "Open a dialogue file"
icon = SubResource( 2 )
items = [ "Open...", SubResource( 2 ), 0, false, false, 0, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "res://assets/dialogue/town.tres", SubResource( 2 ), 0, false, false, 2, 0, null, "", false, "res://test.tres", SubResource( 2 ), 0, false, false, 3, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Clear recent files", null, 0, false, false, 5, 0, null, "", false ]
items = [ "Open...", SubResource( 2 ), 0, false, false, 0, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "res://assets/dialogue/town.tres", SubResource( 2 ), 0, false, false, 2, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Clear recent files", null, 0, false, false, 4, 0, null, "", false ]

[node name="VSeparator" type="VSeparator" parent="Margin/VBox/Toolbar"]
margin_left = 678.0
margin_right = 682.0
margin_left = 734.0
margin_right = 738.0
margin_bottom = 24.0

[node name="SettingsButton" type="ToolButton" parent="Margin/VBox/Toolbar"]
margin_left = 686.0
margin_right = 714.0
margin_left = 742.0
margin_right = 770.0
margin_bottom = 24.0
hint_tooltip = "Configure dialogue editor settings"
icon = SubResource( 2 )

[node name="ErrorButton" type="ToolButton" parent="Margin/VBox/Toolbar"]
margin_left = 718.0
margin_right = 746.0
margin_left = 774.0
margin_right = 802.0
margin_bottom = 24.0
hint_tooltip = "Check syntax"
disabled = true
icon = SubResource( 2 )

[node name="RunButton" type="ToolButton" parent="Margin/VBox/Toolbar"]
margin_left = 750.0
margin_right = 778.0
margin_left = 806.0
margin_right = 834.0
margin_bottom = 24.0
hint_tooltip = "Play the test scene"
disabled = true
icon = SubResource( 2 )

[node name="SearchButton" type="ToolButton" parent="Margin/VBox/Toolbar"]
margin_left = 782.0
margin_right = 810.0
margin_left = 838.0
margin_right = 866.0
margin_bottom = 24.0
hint_tooltip = "Find text"
disabled = true
Expand All @@ -165,49 +165,49 @@ __meta__ = {
}

[node name="VSeparator2" type="VSeparator" parent="Margin/VBox/Toolbar"]
margin_left = 814.0
margin_right = 818.0
margin_left = 870.0
margin_right = 874.0
margin_bottom = 24.0

[node name="InsertMenu" type="MenuButton" parent="Margin/VBox/Toolbar"]
margin_left = 822.0
margin_right = 891.0
margin_left = 878.0
margin_right = 947.0
margin_bottom = 24.0
disabled = true
text = "Insert"
icon = SubResource( 2 )
items = [ "Wave BBCode", SubResource( 2 ), 0, false, false, 0, 0, null, "", false, "Shake BBCode", SubResource( 2 ), 0, false, false, 1, 0, null, "", false, "-", null, 0, false, true, 2, 0, null, "", true, "Typing pause", SubResource( 2 ), 0, false, false, 3, 0, null, "", false, "Typing speed change", SubResource( 2 ), 0, false, false, 4, 0, null, "", false, "Auto advance", SubResource( 2 ), 0, false, false, 5, 0, null, "", false ]

[node name="TranslationsMenu" type="MenuButton" parent="Margin/VBox/Toolbar"]
margin_left = 895.0
margin_right = 1003.0
margin_left = 951.0
margin_right = 1059.0
margin_bottom = 24.0
disabled = true
text = "Translations"
icon = SubResource( 2 )
items = [ "Generate static keys", SubResource( 2 ), 0, false, false, 0, 0, null, "", false, "Save to CSV...", SubResource( 2 ), 0, false, false, 1, 0, null, "", false, "", null, 0, false, false, 2, 0, null, "", true, "Import updates from CSV...", SubResource( 2 ), 0, false, false, 3, 0, null, "", false ]

[node name="Control2" type="Control" parent="Margin/VBox/Toolbar"]
margin_left = 1007.0
margin_right = 1618.0
margin_left = 1063.0
margin_right = 1729.0
margin_bottom = 24.0
size_flags_horizontal = 3

[node name="HelpButton" type="ToolButton" parent="Margin/VBox/Toolbar"]
margin_left = 1622.0
margin_right = 1752.0
margin_left = 1733.0
margin_right = 1863.0
margin_bottom = 24.0
hint_tooltip = "Get some help"
text = "Documentation"
icon = SubResource( 2 )

[node name="VersionLabel" type="Label" parent="Margin/VBox/Toolbar"]
modulate = Color( 1, 1, 1, 0.392157 )
margin_left = 1756.0
margin_right = 1795.0
margin_left = 1867.0
margin_right = 1914.0
margin_bottom = 24.0
size_flags_vertical = 1
text = "v1.8.0"
text = "v1.11.2"
valign = 1

[node name="UpdateButton" type="Button" parent="Margin/VBox/Toolbar"]
Expand Down Expand Up @@ -315,6 +315,7 @@ filters = PoolStringArray( "*.csv ; Translations" )
[connection signal="close_requested" from="Margin/VBox/Content/VBox2/SearchToolbar" to="." method="_on_SearchToolbar_close_requested"]
[connection signal="open_requested" from="Margin/VBox/Content/VBox2/SearchToolbar" to="." method="_on_SearchToolbar_open_requested"]
[connection signal="active_title_changed" from="Margin/VBox/Content/VBox2/CodeEditor" to="." method="_on_CodeEditor_active_title_changed"]
[connection signal="cursor_changed" from="Margin/VBox/Content/VBox2/CodeEditor" to="." method="_on_CodeEditor_cursor_changed"]
[connection signal="text_changed" from="Margin/VBox/Content/VBox2/CodeEditor" to="." method="_on_CodeEditor_text_changed"]
[connection signal="file_selected" from="NewDialogueDialog" to="." method="_on_NewDialogueDialog_file_selected"]
[connection signal="confirmed" from="OpenDialogueDialog" to="." method="_on_OpenDialogueDialog_confirmed"]
Expand Down

0 comments on commit 93dcd83

Please sign in to comment.