* Contributors: Details at https://graphviz.org
*************************************************************************/
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "gui.h"
Generic Open File dialog, if a file is selected and return value is 1, else 0
file name is copied to char* filename,which should be allocated before using the function
*/
-int openfiledlg(agxbuf *xbuf) {
+int openfiledlg(char **filename) {
+ assert(filename != NULL);
+
GtkWidget *dialog;
int rv;
GTK_RESPONSE_ACCEPT, NULL);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- agxbput(xbuf,
- gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)));
+ *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
rv = 1;
} else
rv = 0;
void Color_Widget_bg(char *colorstring, GtkWidget * widget);
/*generic warning pop up*/
void show_gui_warning(char *str);
-/*generic open file dialog*/
- int openfiledlg(agxbuf * xbuf);
+/** generic open file dialog
+ *
+ * \param [out] filename Selected filename on success. Caller should \p g_free
+ * this.
+ * \return Non-zero on success.
+ */
+ int openfiledlg(char **filename);
/*generic save file dialog*/
int savefiledlg(int filtercnt, char **filters, agxbuf * xbuf);
void append_textview(GtkTextView * textv, const char *s, size_t bytes);
#include <cgraph/agxbuf.h>
#include <assert.h>
#include <ctype.h>
+#include <glib.h>
#include "frmobjectui.h"
void mAttributesSlot(GtkWidget * widget, gpointer user_data)
agxbinit(&xbuf, SMALLBUF, xbuffer);
- /*file name should be returned in xbuf */
- if (openfiledlg(&xbuf)) {
- input_file = fopen(agxbuse(&xbuf), "r");
+ char *filename = NULL;
+ if (openfiledlg(&filename)) {
+ input_file = fopen(filename, "r");
+ g_free(filename);
if (input_file) {
while (fgets(buf, BUFSIZ, input_file))
agxbput(&xbuf, buf);