Commit 23fee901448771377dc0cd9afee3a6672ce5c62c
1 parent
9d432ec2
Exists in
master
and in
1 other branch
Auto selecting format from file extension.
Showing
1 changed file
with
47 additions
and
0 deletions
Show diff stats
src/dialogs/save/save.c
| ... | ... | @@ -137,6 +137,51 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ |
| 137 | 137 | } |
| 138 | 138 | #endif // _WIN32 |
| 139 | 139 | |
| 140 | + | |
| 141 | + static void filename_changed(GtkEntry *entry, GtkComboBox *formats) | |
| 142 | + { | |
| 143 | + const gchar * text = gtk_entry_get_text(entry); | |
| 144 | + | |
| 145 | + if(!(text && *text)) | |
| 146 | + return; | |
| 147 | + | |
| 148 | + const gchar * extension = strrchr(text,'.'); | |
| 149 | + if(!extension) | |
| 150 | + return; | |
| 151 | + | |
| 152 | + extension++; | |
| 153 | + const gchar * format = gtk_combo_box_get_active_id(formats); | |
| 154 | + if(*format == '.') | |
| 155 | + format++; | |
| 156 | + | |
| 157 | + if(g_ascii_strcasecmp(extension,format) == 0) | |
| 158 | + return; | |
| 159 | + | |
| 160 | + gint column = gtk_combo_box_get_id_column(formats); | |
| 161 | + GtkTreeModel * model = gtk_combo_box_get_model(formats); | |
| 162 | + GtkTreeIter iter; | |
| 163 | + | |
| 164 | + debug("id_column=%d",column); | |
| 165 | + | |
| 166 | + if(gtk_tree_model_get_iter_first(model,&iter)) | |
| 167 | + { | |
| 168 | + do | |
| 169 | + { | |
| 170 | + g_autofree gchar *id = NULL; | |
| 171 | + gtk_tree_model_get(model, &iter, column, &id, -1); | |
| 172 | + | |
| 173 | + if(g_ascii_strcasecmp(extension,id + (*id == '.' ? 1 : 0)) == 0) | |
| 174 | + { | |
| 175 | + gtk_combo_box_set_active_iter(formats,&iter); | |
| 176 | + break; | |
| 177 | + } | |
| 178 | + | |
| 179 | + } while(gtk_tree_model_iter_next(model,&iter)); | |
| 180 | + } | |
| 181 | + | |
| 182 | + } | |
| 183 | + | |
| 184 | + | |
| 140 | 185 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) |
| 141 | 186 | { |
| 142 | 187 | // 0--------1---------------------2-------3--------------------4 |
| ... | ... | @@ -243,6 +288,8 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ |
| 243 | 288 | |
| 244 | 289 | } |
| 245 | 290 | |
| 291 | + g_signal_connect(dialog->filename,"changed",G_CALLBACK(filename_changed),dialog->format); | |
| 292 | + | |
| 246 | 293 | } |
| 247 | 294 | |
| 248 | 295 | ... | ... |