Skip to content

Commit

Permalink
Add "quick open" (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhoad authored Oct 24, 2024
1 parent b2306e3 commit e51bee8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 51 deletions.
4 changes: 3 additions & 1 deletion addons/dialogue_manager/components/files_list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const MODIFIED_SUFFIX = "(*)"
var file_map: Dictionary = {}

var current_file_path: String = ""
var last_selected_file_path: String = ""

var files: PackedStringArray = []:
set(next_files):
Expand All @@ -33,7 +34,7 @@ var files: PackedStringArray = []:

var unsaved_files: Array[String] = []

var filter: String:
var filter: String = "":
set(next_filter):
filter = next_filter
apply_filter()
Expand All @@ -57,6 +58,7 @@ func select_file(file: String) -> void:
var item_text = list.get_item_text(i).replace(MODIFIED_SUFFIX, "")
if item_text == get_nice_file(file, item_text.count("/") + 1):
list.select(i)
last_selected_file_path = file


func mark_file_as_unsaved(file: String, is_unsaved: bool) -> void:
Expand Down
3 changes: 3 additions & 0 deletions addons/dialogue_manager/l10n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ msgstr "Open a file"
msgid "open.open"
msgstr "Open..."

msgid "open.quick_open"
msgstr "Quick open..."

msgid "open.no_recent_files"
msgstr "No recent files"

Expand Down
3 changes: 3 additions & 0 deletions addons/dialogue_manager/l10n/translations.pot
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ msgstr ""
msgid "open.open"
msgstr ""

msgid "open.quick_open"
msgstr ""

msgid "open.no_recent_files"
msgstr ""

Expand Down
21 changes: 20 additions & 1 deletion addons/dialogue_manager/views/main_view.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const DialogueResource = preload("../dialogue_resource.gd")
const DialogueManagerParser = preload("../components/parser.gd")

const OPEN_OPEN = 100
const OPEN_CLEAR = 101
const OPEN_QUICK = 101
const OPEN_CLEAR = 102

const TRANSLATIONS_GENERATE_LINE_IDS = 100
const TRANSLATIONS_SAVE_CHARACTERS_TO_CSV = 201
Expand Down Expand Up @@ -38,6 +39,8 @@ signal confirmation_closed()
@onready var new_dialog: FileDialog = $NewDialog
@onready var save_dialog: FileDialog = $SaveDialog
@onready var open_dialog: FileDialog = $OpenDialog
@onready var quick_open_dialog: ConfirmationDialog = $QuickOpenDialog
@onready var quick_open_files_list: VBoxContainer = $QuickOpenDialog/QuickOpenFilesList
@onready var export_dialog: FileDialog = $ExportDialog
@onready var import_dialog: FileDialog = $ImportDialog
@onready var errors_dialog: AcceptDialog = $ErrorsDialog
Expand Down Expand Up @@ -446,6 +449,7 @@ func apply_theme() -> void:
new_dialog.min_size = Vector2(600, 500) * scale
save_dialog.min_size = Vector2(600, 500) * scale
open_dialog.min_size = Vector2(600, 500) * scale
quick_open_dialog.min_size = Vector2(400, 600) * scale
export_dialog.min_size = Vector2(600, 500) * scale
import_dialog.min_size = Vector2(600, 500) * scale
settings_dialog.min_size = Vector2(1000, 600) * scale
Expand All @@ -461,6 +465,7 @@ func build_open_menu() -> void:
var menu = open_button.get_popup()
menu.clear()
menu.add_icon_item(get_theme_icon("Load", "EditorIcons"), DialogueConstants.translate(&"open.open"), OPEN_OPEN)
menu.add_icon_item(get_theme_icon("Load", "EditorIcons"), DialogueConstants.translate(&"open.quick_open"), OPEN_QUICK)
menu.add_separator()

var recent_files = DialogueSettings.get_recent_files()
Expand Down Expand Up @@ -836,6 +841,10 @@ func _on_open_menu_id_pressed(id: int) -> void:
match id:
OPEN_OPEN:
open_dialog.popup_centered()
OPEN_QUICK:
quick_open_files_list.files = Engine.get_meta("DialogueCache").get_files()
quick_open_dialog.popup_centered()
quick_open_files_list.focus_filter()
OPEN_CLEAR:
DialogueSettings.clear_recent_files()
build_open_menu()
Expand Down Expand Up @@ -947,6 +956,16 @@ func _on_open_dialog_file_selected(path: String) -> void:
open_file(path)


func _on_quick_open_files_list_file_double_clicked(file_path: String) -> void:
quick_open_dialog.hide()
open_file(file_path)


func _on_quick_open_dialog_confirmed() -> void:
if quick_open_files_list.current_file_path:
open_file(quick_open_files_list.current_file_path)


func _on_save_all_button_pressed() -> void:
save_files()

Expand Down
Loading

0 comments on commit e51bee8

Please sign in to comment.