From 59f288049826e86c33f597e9db77c094a2435ecb Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 24 Feb 2026 23:11:47 -0500 Subject: [PATCH] Latest changes. --- name_sanitize.nvgt | 20 +++++++++++++++++--- speech_history.nvgt | 33 +++++++++++++++++++++++++-------- ui.nvgt | 26 +++++++++++++++++++++----- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/name_sanitize.nvgt b/name_sanitize.nvgt index a47ccc8..0561f24 100644 --- a/name_sanitize.nvgt +++ b/name_sanitize.nvgt @@ -45,7 +45,8 @@ bool is_windows_reserved_filename(const string& in upperName) { return false; } -string sanitize_filename_base(string name, const int maxLength = 40, const string fallback = "item") { +string sanitize_filename_base_with_reserved_prefix(string name, const int maxLength = 40, const string fallback = "item", + const string reservedPrefix = "file_") { string normalized = normalize_name_whitespace(name); string result = ""; bool lastSeparator = false; @@ -93,13 +94,26 @@ string sanitize_filename_base(string name, const int maxLength = 40, const strin } if (is_windows_reserved_filename(upperName)) { - result = "file_" + result; + string safePrefix = reservedPrefix; + if (safePrefix == "") + safePrefix = "file_"; + result = safePrefix + result; } return result; } +string sanitize_filename_base(string name, const int maxLength = 40, const string fallback = "item") { + return sanitize_filename_base_with_reserved_prefix(name, maxLength, fallback, "file_"); +} + +string build_filename_from_name_ex(const string& in name, const string& in extension = ".dat", + const int maxBaseLength = 40, const string fallback = "item", + const string reservedPrefix = "file_") { + return sanitize_filename_base_with_reserved_prefix(name, maxBaseLength, fallback, reservedPrefix) + extension; +} + string build_filename_from_name(const string& in name, const string& in extension = ".dat", const int maxBaseLength = 40, const string fallback = "item") { - return sanitize_filename_base(name, maxBaseLength, fallback) + extension; + return build_filename_from_name_ex(name, extension, maxBaseLength, fallback, "file_"); } diff --git a/speech_history.nvgt b/speech_history.nvgt index 298a9e9..0ce04f7 100644 --- a/speech_history.nvgt +++ b/speech_history.nvgt @@ -5,6 +5,18 @@ string[] speechHistory; int speechHistoryMaxEntries = 10; int speechHistoryCurrentIndex = -1; bool speechHistoryDeduplicate = true; +funcdef string speech_history_message_transform_callback(const string& in message); +speech_history_message_transform_callback @speechHistoryMessageTransform = null; + +void speech_history_set_message_transform_callback(speech_history_message_transform_callback @callback) { + @speechHistoryMessageTransform = @callback; +} + +string speech_history_transform_message(const string& in message) { + if (@speechHistoryMessageTransform is null) + return message; + return speechHistoryMessageTransform(message); +} void speech_history_set_max_entries(int maxEntries) { if (maxEntries < 1) { @@ -55,27 +67,30 @@ void speech_history_add(const string& in message) { } void speak_with_history(const string& in message, bool interrupt) { - speech_history_add(message); - screen_reader_speak(message, interrupt); + string transformedMessage = speech_history_transform_message(message); + speech_history_add(transformedMessage); + screen_reader_speak(transformedMessage, interrupt); } void check_speech_history_keys() { // Comma: older. if (key_pressed(KEY_COMMA)) { if (speechHistory.length() == 0) { - screen_reader_speak("No speech history.", true); + screen_reader_speak(speech_history_transform_message("No speech history."), true); return; } speechHistoryCurrentIndex--; if (speechHistoryCurrentIndex < 0) { speechHistoryCurrentIndex = 0; - screen_reader_speak("Oldest message. " + speechHistory[speechHistoryCurrentIndex], true); + screen_reader_speak(speech_history_transform_message("Oldest message. " + speechHistory[speechHistoryCurrentIndex]), + true); return; } int position = speechHistoryCurrentIndex + 1; - screen_reader_speak(speechHistory[speechHistoryCurrentIndex] + " " + position + " of " + speechHistory.length(), + screen_reader_speak(speech_history_transform_message(speechHistory[speechHistoryCurrentIndex] + " " + position + + " of " + speechHistory.length()), true); return; } @@ -83,19 +98,21 @@ void check_speech_history_keys() { // Period: newer. if (key_pressed(KEY_PERIOD)) { if (speechHistory.length() == 0) { - screen_reader_speak("No speech history.", true); + screen_reader_speak(speech_history_transform_message("No speech history."), true); return; } speechHistoryCurrentIndex++; if (speechHistoryCurrentIndex >= int(speechHistory.length())) { speechHistoryCurrentIndex = speechHistory.length() - 1; - screen_reader_speak("Newest message. " + speechHistory[speechHistoryCurrentIndex], true); + screen_reader_speak(speech_history_transform_message("Newest message. " + speechHistory[speechHistoryCurrentIndex]), + true); return; } int position = speechHistoryCurrentIndex + 1; - screen_reader_speak(speechHistory[speechHistoryCurrentIndex] + " " + position + " of " + speechHistory.length(), + screen_reader_speak(speech_history_transform_message(speechHistory[speechHistoryCurrentIndex] + " " + position + + " of " + speechHistory.length()), true); } } diff --git a/ui.nvgt b/ui.nvgt index 6a6b1c0..0d668d7 100644 --- a/ui.nvgt +++ b/ui.nvgt @@ -2,6 +2,18 @@ string uiDefaultWindowTitle = ""; bool uiUsePromptAsDialogTitle = true; +funcdef string ui_text_transform_callback(const string& in text); +ui_text_transform_callback @uiTextTransformCallback = null; + +void ui_set_text_transform_callback(ui_text_transform_callback @callback) { + @uiTextTransformCallback = @callback; +} + +string ui_transform_text(const string& in text) { + if (@uiTextTransformCallback is null) + return text; + return uiTextTransformCallback(text); +} void ui_set_default_window_title(const string windowTitle) { uiDefaultWindowTitle = windowTitle; @@ -36,20 +48,24 @@ void ui_restore_window(const string windowTitle = "") { string ui_input_box(const string title, const string prompt, const string defaultValue = "", const string windowTitle = "") { - string dialogTitle = ui_resolve_dialog_title(title, prompt); - string result = virtual_input_box(dialogTitle, prompt, defaultValue); + string transformedTitle = ui_transform_text(title); + string transformedPrompt = ui_transform_text(prompt); + string dialogTitle = ui_resolve_dialog_title(transformedTitle, transformedPrompt); + string result = virtual_input_box(dialogTitle, transformedPrompt, defaultValue); ui_restore_window(windowTitle); return result; } int ui_question(const string title, const string prompt, const string windowTitle = "", const bool canCancel = false) { - string dialogTitle = ui_resolve_dialog_title(title, prompt); - int result = virtual_question(dialogTitle, prompt, canCancel); + string transformedTitle = ui_transform_text(title); + string transformedPrompt = ui_transform_text(prompt); + string dialogTitle = ui_resolve_dialog_title(transformedTitle, transformedPrompt); + int result = virtual_question(dialogTitle, transformedPrompt, canCancel); ui_restore_window(windowTitle); return result; } void ui_info_box(const string title, const string heading, const string message, const string windowTitle = "") { - virtual_info_box(title, heading, message); + virtual_info_box(ui_transform_text(title), ui_transform_text(heading), ui_transform_text(message)); ui_restore_window(windowTitle); }