Latest changes.
This commit is contained in:
@@ -45,7 +45,8 @@ bool is_windows_reserved_filename(const string& in upperName) {
|
|||||||
return false;
|
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 normalized = normalize_name_whitespace(name);
|
||||||
string result = "";
|
string result = "";
|
||||||
bool lastSeparator = false;
|
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)) {
|
if (is_windows_reserved_filename(upperName)) {
|
||||||
result = "file_" + result;
|
string safePrefix = reservedPrefix;
|
||||||
|
if (safePrefix == "")
|
||||||
|
safePrefix = "file_";
|
||||||
|
result = safePrefix + result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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",
|
string build_filename_from_name(const string& in name, const string& in extension = ".dat",
|
||||||
const int maxBaseLength = 40, const string fallback = "item") {
|
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_");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,18 @@ string[] speechHistory;
|
|||||||
int speechHistoryMaxEntries = 10;
|
int speechHistoryMaxEntries = 10;
|
||||||
int speechHistoryCurrentIndex = -1;
|
int speechHistoryCurrentIndex = -1;
|
||||||
bool speechHistoryDeduplicate = true;
|
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) {
|
void speech_history_set_max_entries(int maxEntries) {
|
||||||
if (maxEntries < 1) {
|
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) {
|
void speak_with_history(const string& in message, bool interrupt) {
|
||||||
speech_history_add(message);
|
string transformedMessage = speech_history_transform_message(message);
|
||||||
screen_reader_speak(message, interrupt);
|
speech_history_add(transformedMessage);
|
||||||
|
screen_reader_speak(transformedMessage, interrupt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_speech_history_keys() {
|
void check_speech_history_keys() {
|
||||||
// Comma: older.
|
// Comma: older.
|
||||||
if (key_pressed(KEY_COMMA)) {
|
if (key_pressed(KEY_COMMA)) {
|
||||||
if (speechHistory.length() == 0) {
|
if (speechHistory.length() == 0) {
|
||||||
screen_reader_speak("No speech history.", true);
|
screen_reader_speak(speech_history_transform_message("No speech history."), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
speechHistoryCurrentIndex--;
|
speechHistoryCurrentIndex--;
|
||||||
if (speechHistoryCurrentIndex < 0) {
|
if (speechHistoryCurrentIndex < 0) {
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int position = speechHistoryCurrentIndex + 1;
|
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);
|
true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -83,19 +98,21 @@ void check_speech_history_keys() {
|
|||||||
// Period: newer.
|
// Period: newer.
|
||||||
if (key_pressed(KEY_PERIOD)) {
|
if (key_pressed(KEY_PERIOD)) {
|
||||||
if (speechHistory.length() == 0) {
|
if (speechHistory.length() == 0) {
|
||||||
screen_reader_speak("No speech history.", true);
|
screen_reader_speak(speech_history_transform_message("No speech history."), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
speechHistoryCurrentIndex++;
|
speechHistoryCurrentIndex++;
|
||||||
if (speechHistoryCurrentIndex >= int(speechHistory.length())) {
|
if (speechHistoryCurrentIndex >= int(speechHistory.length())) {
|
||||||
speechHistoryCurrentIndex = speechHistory.length() - 1;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int position = speechHistoryCurrentIndex + 1;
|
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);
|
true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
ui.nvgt
26
ui.nvgt
@@ -2,6 +2,18 @@
|
|||||||
|
|
||||||
string uiDefaultWindowTitle = "";
|
string uiDefaultWindowTitle = "";
|
||||||
bool uiUsePromptAsDialogTitle = true;
|
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) {
|
void ui_set_default_window_title(const string windowTitle) {
|
||||||
uiDefaultWindowTitle = 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 = "",
|
string ui_input_box(const string title, const string prompt, const string defaultValue = "",
|
||||||
const string windowTitle = "") {
|
const string windowTitle = "") {
|
||||||
string dialogTitle = ui_resolve_dialog_title(title, prompt);
|
string transformedTitle = ui_transform_text(title);
|
||||||
string result = virtual_input_box(dialogTitle, prompt, defaultValue);
|
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);
|
ui_restore_window(windowTitle);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ui_question(const string title, const string prompt, const string windowTitle = "", const bool canCancel = false) {
|
int ui_question(const string title, const string prompt, const string windowTitle = "", const bool canCancel = false) {
|
||||||
string dialogTitle = ui_resolve_dialog_title(title, prompt);
|
string transformedTitle = ui_transform_text(title);
|
||||||
int result = virtual_question(dialogTitle, prompt, canCancel);
|
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);
|
ui_restore_window(windowTitle);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_info_box(const string title, const string heading, const string message, const string windowTitle = "") {
|
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);
|
ui_restore_window(windowTitle);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user