Commit 041f6aab3e85d88a6b2b15959bdcc9094902b727

Authored by Perry Werneck
1 parent 23fee901
Exists in master and in 1 other branch develop

Updating filename extension based on file type.

Showing 1 changed file with 33 additions and 0 deletions   Show diff stats
src/dialogs/save/save.c
... ... @@ -181,6 +181,38 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
181 181  
182 182 }
183 183  
  184 + static void fileformat_changed(GtkComboBox *formats, GtkEntry *entry)
  185 + {
  186 + const gchar * text = gtk_entry_get_text(entry);
  187 +
  188 + if(!(text && *text))
  189 + return;
  190 +
  191 + gchar * extension = strrchr(text,'.');
  192 + if(!extension)
  193 + return;
  194 +
  195 + extension++;
  196 + const gchar * format = gtk_combo_box_get_active_id(formats);
  197 + if(*format == '.')
  198 + format++;
  199 +
  200 + if(g_ascii_strcasecmp(extension,format) == 0)
  201 + return;
  202 +
  203 + size_t szFilename = strlen(text) + strlen(format);
  204 + g_autofree gchar * filename = g_malloc0(szFilename + 1);
  205 +
  206 + strncpy(filename,text,szFilename);
  207 + extension = strrchr(filename,'.');
  208 + if(extension)
  209 + {
  210 + *(++extension) = 0;
  211 + strncat(filename, format + (*format == '.' ? 1 : 0),szFilename);
  212 + gtk_entry_set_text(entry,filename);
  213 + }
  214 +
  215 + }
184 216  
185 217 static void V3270SaveDialog_init(V3270SaveDialog *dialog)
186 218 {
... ... @@ -289,6 +321,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_
289 321 }
290 322  
291 323 g_signal_connect(dialog->filename,"changed",G_CALLBACK(filename_changed),dialog->format);
  324 + g_signal_connect(dialog->format,"changed",G_CALLBACK(fileformat_changed),dialog->filename);
292 325  
293 326 }
294 327  
... ...