Mercurial > dwindows
comparison gtk4/dw.c @ 2346:7b04d1b9f2eb
GTK4: Fix warning message from dW_file_browse() and code cleanup.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 04 Mar 2021 08:40:14 +0000 |
parents | 1a630cddf384 |
children | e5d4c86a0c93 |
comparison
equal
deleted
inserted
replaced
2345:a15bb7a2496e | 2346:7b04d1b9f2eb |
---|---|
10009 GtkFileChooserAction action; | 10009 GtkFileChooserAction action; |
10010 GtkFileFilter *filter1 = NULL; | 10010 GtkFileFilter *filter1 = NULL; |
10011 GtkFileFilter *filter2 = NULL; | 10011 GtkFileFilter *filter2 = NULL; |
10012 gchar *button = NULL; | 10012 gchar *button = NULL; |
10013 char *filename = NULL; | 10013 char *filename = NULL; |
10014 char buf[1000]; | 10014 char buf[1001] = {0}; |
10015 DWDialog *tmp = dw_dialog_new(NULL); | 10015 DWDialog *tmp = dw_dialog_new(NULL); |
10016 | 10016 |
10017 switch (flags ) | 10017 switch(flags) |
10018 { | 10018 { |
10019 case DW_DIRECTORY_OPEN: | 10019 case DW_DIRECTORY_OPEN: |
10020 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; | 10020 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; |
10021 button = _("_Open"); | 10021 button = _("_Open"); |
10022 break; | 10022 break; |
10033 break; | 10033 break; |
10034 } | 10034 } |
10035 | 10035 |
10036 if(button) | 10036 if(button) |
10037 { | 10037 { |
10038 filew = gtk_file_chooser_dialog_new ( title, | 10038 filew = gtk_file_chooser_dialog_new(title, |
10039 NULL, | 10039 NULL, |
10040 action, | 10040 action, |
10041 _("_Cancel"), GTK_RESPONSE_CANCEL, | 10041 _("_Cancel"), GTK_RESPONSE_CANCEL, |
10042 button, GTK_RESPONSE_ACCEPT, | 10042 button, GTK_RESPONSE_ACCEPT, |
10043 NULL); | 10043 NULL); |
10044 | 10044 |
10045 if(ext) | 10045 if(ext) |
10046 { | 10046 { |
10047 filter1 = gtk_file_filter_new(); | 10047 filter1 = gtk_file_filter_new(); |
10048 sprintf( buf, "*.%s", ext ); | 10048 snprintf(buf, 1000, "*.%s", ext); |
10049 gtk_file_filter_add_pattern( filter1, (gchar *)buf ); | 10049 gtk_file_filter_add_pattern( filter1, (gchar *)buf); |
10050 sprintf( buf, "\"%s\" files", ext ); | 10050 snprintf(buf, 1000, "\"%s\" files", ext ); |
10051 gtk_file_filter_set_name( filter1, (gchar *)buf ); | 10051 gtk_file_filter_set_name(filter1, (gchar *)buf); |
10052 filter2 = gtk_file_filter_new(); | 10052 filter2 = gtk_file_filter_new(); |
10053 gtk_file_filter_add_pattern( filter2, (gchar *)"*" ); | 10053 gtk_file_filter_add_pattern(filter2, (gchar *)"*"); |
10054 gtk_file_filter_set_name( filter2, (gchar *)"All Files" ); | 10054 gtk_file_filter_set_name(filter2, (gchar *)"All Files"); |
10055 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( filew ), filter1 ); | 10055 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER( filew ), filter1); |
10056 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( filew ), filter2 ); | 10056 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER( filew ), filter2); |
10057 } | 10057 } |
10058 | 10058 |
10059 if(defpath) | 10059 if(defpath) |
10060 { | 10060 { |
10061 GFile *path = g_file_new_for_path(defpath); | 10061 GFile *path = g_file_new_for_path(defpath); |
10062 | 10062 |
10063 /* See if the path exists */ | 10063 /* See if the path exists */ |
10064 if(path) | 10064 if(path) |
10065 { | 10065 { |
10066 /* If the path is a directory... set the current folder */ | 10066 /* If the path is a directory... set the current folder */ |
10067 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filew), path, NULL); | 10067 if(g_file_query_file_type(path, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) |
10068 gtk_file_chooser_set_file(GTK_FILE_CHOOSER(filew), path, NULL); | 10068 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filew), path, NULL); |
10069 else | |
10070 gtk_file_chooser_set_file(GTK_FILE_CHOOSER(filew), path, NULL); | |
10069 | 10071 |
10070 g_object_unref(G_OBJECT(path)); | 10072 g_object_unref(G_OBJECT(path)); |
10071 } | 10073 } |
10072 } | 10074 } |
10073 | 10075 |