shithub: choc

Download patch

ref: e10af52152ba793d983497cd86d7ccc10d32a13d
parent: 50289818e9d59848c363aa3922133fee9c119c22
author: Simon Howard <[email protected]>
date: Sun Sep 8 14:57:20 EDT 2013

Fix file select widget to emit "changed" signal properly. Reset variable
value to empty string rather than NULL if cancel is pressed in dialog
(thanks Alexandre Xavier).

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2638

--- a/textscreen/txt_fileselect.c
+++ b/textscreen/txt_fileselect.c
@@ -591,6 +591,16 @@
     {
         path = TXT_SelectFile(fileselect->prompt,
                               fileselect->extensions);
+
+        // Update inputbox variable.
+        // If cancel was pressed (ie. NULL was returned by TXT_SelectFile)
+        // then reset to empty string, not NULL).
+
+        if (path == NULL)
+        {
+            path = strdup("");
+        }
+
         var = fileselect->inputbox->value;
         free(*var);
         *var = path;
@@ -658,6 +668,16 @@
     TXT_FileSelectFocused,
 };
 
+// If the (inner) inputbox widget is changed, emit a change to the
+// outer (fileselect) widget.
+
+static void InputBoxChanged(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(fileselect))
+{
+    TXT_CAST_ARG(txt_fileselect_t, fileselect);
+
+    TXT_EmitSignal(&fileselect->widget, "changed");
+}
+
 txt_fileselect_t *TXT_NewFileSelector(char **variable, int size,
                                       char *prompt, char **extensions)
 {
@@ -670,6 +690,9 @@
     fileselect->size = size;
     fileselect->prompt = prompt;
     fileselect->extensions = extensions;
+
+    TXT_SignalConnect(fileselect->inputbox, "changed",
+                      InputBoxChanged, fileselect);
 
     return fileselect;
 }