125 |
125 |
126 obj->widget = toplevel; |
126 obj->widget = toplevel; |
127 nwindows++; |
127 nwindows++; |
128 return obj; |
128 return obj; |
129 } |
129 } |
|
130 |
|
131 typedef struct FileDialogData { |
|
132 int running; |
|
133 char *file; |
|
134 } FileDialogData; |
|
135 |
|
136 static void filedialog_select( |
|
137 Widget widget, |
|
138 FileDialogData *data, |
|
139 XmFileSelectionBoxCallbackStruct *selection) |
|
140 { |
|
141 char *path = NULL; |
|
142 XmStringGetLtoR(selection->value, XmSTRING_DEFAULT_CHARSET, &path); |
|
143 data->running = 0; |
|
144 data->file = strdup(path); |
|
145 XtFree(path); |
|
146 XtUnmanageChild(widget); |
|
147 } |
|
148 |
|
149 static void filedialog_cancel( |
|
150 Widget widget, |
|
151 FileDialogData *data, |
|
152 XmFileSelectionBoxCallbackStruct *selection) |
|
153 |
|
154 { |
|
155 data->running = 0; |
|
156 XtUnmanageChild(widget); |
|
157 } |
|
158 |
|
159 char* ui_openfiledialog(UiObject *obj) { |
|
160 Widget dialog = XmCreateFileSelectionDialog(obj->widget, "openfiledialog", NULL, 0); |
|
161 XtManageChild(dialog); |
|
162 |
|
163 FileDialogData data; |
|
164 data.running = 1; |
|
165 data.file = NULL; |
|
166 |
|
167 XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)filedialog_select, &data); |
|
168 XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc)filedialog_cancel, &data); |
|
169 |
|
170 ui_secondary_event_loop(&data.running); |
|
171 return data.file; |
|
172 } |
|
173 |
|
174 char* ui_savefiledialog(UiObject *obj) { |
|
175 return ui_openfiledialog(obj); |
|
176 } |