| 479 | } |
| 480 | |
| 481 | nfdresult_t NFD_SaveDialogN(nfdnchar_t** outPath, |
| 482 | const nfdnfilteritem_t* filterList, |
| 483 | nfdfiltersize_t filterCount, |
| 484 | const nfdnchar_t* defaultPath, |
| 485 | const nfdnchar_t* defaultName) { |
| 486 | GtkWidget* widget = gtk_file_chooser_dialog_new("Save File", |
| 487 | nullptr, |
| 488 | GTK_FILE_CHOOSER_ACTION_SAVE, |
| 489 | "_Cancel", |
| 490 | GTK_RESPONSE_CANCEL, |
| 491 | nullptr); |
| 492 | |
| 493 | // guard to destroy the widget when returning from this function |
| 494 | Widget_Guard widgetGuard(widget); |
| 495 | |
| 496 | GtkWidget* saveButton = gtk_dialog_add_button(GTK_DIALOG(widget), "_Save", GTK_RESPONSE_ACCEPT); |
| 497 | |
| 498 | // Prompt on overwrite |
| 499 | gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(widget), TRUE); |
| 500 | |
| 501 | /* Build the filter list */ |
| 502 | ButtonClickedArgs buttonClickedArgs; |
| 503 | buttonClickedArgs.chooser = GTK_FILE_CHOOSER(widget); |
| 504 | buttonClickedArgs.map = |
| 505 | AddFiltersToDialogWithMap(GTK_FILE_CHOOSER(widget), filterList, filterCount); |
| 506 | |
| 507 | /* Set the default path */ |
| 508 | SetDefaultPath(GTK_FILE_CHOOSER(widget), defaultPath); |
| 509 | |
| 510 | /* Set the default file name */ |
| 511 | SetDefaultName(GTK_FILE_CHOOSER(widget), defaultName); |
| 512 | |
| 513 | /* set the handler to add file extension */ |
| 514 | gulong handlerID = g_signal_connect(G_OBJECT(saveButton), |
| 515 | "pressed", |
| 516 | G_CALLBACK(FileActivatedSignalHandler), |
| 517 | static_cast<void*>(&buttonClickedArgs)); |
| 518 | |
| 519 | /* invoke the dialog (blocks until dialog is closed) */ |
| 520 | gint result = RunDialogWithFocus(GTK_DIALOG(widget)); |
| 521 | /* unset the handler */ |
| 522 | g_signal_handler_disconnect(G_OBJECT(saveButton), handlerID); |
| 523 | |
| 524 | /* free the filter map */ |
| 525 | NFDi_Free(buttonClickedArgs.map); |
| 526 | |
| 527 | if (result == GTK_RESPONSE_ACCEPT) { |
| 528 | // write out the file name |
| 529 | *outPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); |
| 530 | |
| 531 | return NFD_OKAY; |
| 532 | } else { |
| 533 | return NFD_CANCEL; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | nfdresult_t NFD_PickFolderN(nfdnchar_t** outPath, const nfdnchar_t* defaultPath) { |
| 538 | GtkWidget* widget = gtk_file_chooser_dialog_new("Select folder", |
nothing calls this directly
no test coverage detected