| 397 | | static void file_ok_callback(GtkWidget *widget, GtkWidget *file_selector) |
|---|
| 398 | | { |
|---|
| 399 | | char *f = gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selector)); |
|---|
| 400 | | |
|---|
| 401 | | my_strcpy(savefile, f, sizeof(savefile)); |
|---|
| 402 | | |
|---|
| 403 | | gtk_widget_destroy(file_selector); |
|---|
| 404 | | |
|---|
| 405 | | game_in_progress = TRUE; |
|---|
| 406 | | Term_flush(); |
|---|
| 407 | | play_game(FALSE); |
|---|
| 408 | | cleanup_angband(); |
|---|
| 409 | | quit(NULL); |
|---|
| 410 | | } |
|---|
| | 401 | /*** Callbacks: savefile opening ***/ |
|---|
| | 402 | |
|---|
| | 403 | |
|---|
| | 404 | /* Filter function for the savefile list */ |
|---|
| | 405 | static gboolean file_open_filter(const GtkFileFilterInfo *filter_info, gpointer data) |
|---|
| | 406 | { |
|---|
| | 407 | const char *name = filter_info->display_name; |
|---|
| | 408 | |
|---|
| | 409 | (void)data; |
|---|
| | 410 | |
|---|
| | 411 | /* Count out known non-savefiles */ |
|---|
| | 412 | if (strcmp(name, "Makefile.am") == 0 || |
|---|
| | 413 | strcmp(name, "Makefile.in") == 0 || |
|---|
| | 414 | strcmp(name, "delete.me") == 0) |
|---|
| | 415 | { |
|---|
| | 416 | return FALSE; |
|---|
| | 417 | } |
|---|
| | 418 | |
|---|
| | 419 | /* Let it pass */ |
|---|
| | 420 | return TRUE; |
|---|
| | 421 | } |
|---|
| | 422 | |
|---|
| 421 | | } |
|---|
| 422 | | else |
|---|
| 423 | | { |
|---|
| 424 | | /* Prepare the savefile path */ |
|---|
| 425 | | path_build(buf, sizeof(buf), ANGBAND_DIR_SAVE, "*"); |
|---|
| 426 | | |
|---|
| 427 | | file_selector = gtk_file_selection_new("Select a savefile"); |
|---|
| 428 | | gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_selector), buf); |
|---|
| 429 | | gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(file_selector)->ok_button), |
|---|
| 430 | | "clicked", file_ok_callback, (gpointer)file_selector); |
|---|
| 431 | | |
|---|
| 432 | | /* Ensure that the dialog box is destroyed when the user clicks a button. */ |
|---|
| 433 | | gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(file_selector)->ok_button), |
|---|
| 434 | | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
|---|
| 435 | | (gpointer)file_selector); |
|---|
| 436 | | |
|---|
| 437 | | gtk_signal_connect_object(GTK_OBJECT(GTK_FILE_SELECTION(file_selector)->cancel_button), |
|---|
| 438 | | "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), |
|---|
| 439 | | (gpointer)file_selector); |
|---|
| 440 | | |
|---|
| 441 | | gtk_window_set_modal(GTK_WINDOW(file_selector), TRUE); |
|---|
| 442 | | gtk_widget_show(GTK_WIDGET(file_selector)); |
|---|
| 443 | | } |
|---|
| 444 | | } |
|---|
| | 438 | return; |
|---|
| | 439 | } |
|---|
| | 440 | |
|---|
| | 441 | /* Create a new file selector dialogue box, with no parent */ |
|---|
| | 442 | selector_wid = gtk_file_chooser_dialog_new("Select a savefile", NULL, |
|---|
| | 443 | GTK_FILE_CHOOSER_ACTION_OPEN, |
|---|
| | 444 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
|---|
| | 445 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
|---|
| | 446 | NULL); |
|---|
| | 447 | |
|---|
| | 448 | /* For convenience */ |
|---|
| | 449 | selector = GTK_FILE_CHOOSER(selector_wid); |
|---|
| | 450 | |
|---|
| | 451 | /* Get the current directory (so we can find lib/save/) */ |
|---|
| | 452 | filename = gtk_file_chooser_get_current_folder(selector); |
|---|
| | 453 | path_build(buf, sizeof buf, filename, ANGBAND_DIR_SAVE); |
|---|
| | 454 | gtk_file_chooser_set_current_folder(selector, buf); |
|---|
| | 455 | plog(buf); |
|---|
| | 456 | |
|---|
| | 457 | /* Restrict the showing of pointless files */ |
|---|
| | 458 | GtkFileFilter *filter; |
|---|
| | 459 | filter = gtk_file_filter_new(); |
|---|
| | 460 | gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_DISPLAY_NAME, file_open_filter, NULL, NULL); |
|---|
| | 461 | gtk_file_chooser_set_filter(selector, filter); |
|---|
| | 462 | |
|---|
| | 463 | /* Run the dialogue */ |
|---|
| | 464 | if (gtk_dialog_run(GTK_DIALOG(selector_wid)) == GTK_RESPONSE_ACCEPT) |
|---|
| | 465 | { |
|---|
| | 466 | /* Get the filename, copy it into the savefile name */ |
|---|
| | 467 | filename = gtk_file_chooser_get_filename(selector); |
|---|
| | 468 | my_strcpy(savefile, filename, sizeof(savefile)); |
|---|
| | 469 | |
|---|
| | 470 | /* Start playing the game */ |
|---|
| | 471 | game_in_progress = TRUE; |
|---|
| | 472 | Term_flush(); |
|---|
| | 473 | play_game(FALSE); |
|---|
| | 474 | cleanup_angband(); |
|---|
| | 475 | quit(NULL); |
|---|
| | 476 | } |
|---|
| | 477 | |
|---|
| | 478 | /* Destroy it now we're done */ |
|---|
| | 479 | gtk_widget_destroy(selector); |
|---|
| | 480 | |
|---|
| | 481 | /* Done */ |
|---|
| | 482 | return; |
|---|
| | 483 | } |
|---|
| | 484 | |
|---|
| | 485 | |
|---|
| | 486 | |
|---|
| | 487 | |
|---|
| 680 | | gtk_signal_connect(GTK_OBJECT(file_exit_item), "activate", quit_event_handler, NULL); |
|---|
| 681 | | gtk_signal_connect(GTK_OBJECT(file_new_item), "activate", new_event_handler, NULL); |
|---|
| 682 | | gtk_signal_connect(GTK_OBJECT(file_open_item), "activate", open_event_handler, NULL); |
|---|
| 683 | | gtk_signal_connect(GTK_OBJECT(options_font_item), "activate", change_font_event_handler, td); |
|---|
| | 723 | g_signal_connect(GTK_OBJECT(file_exit_item), "activate", G_CALLBACK(quit_event_handler), NULL); |
|---|
| | 724 | g_signal_connect(GTK_OBJECT(file_new_item), "activate", G_CALLBACK(new_event_handler), NULL); |
|---|
| | 725 | g_signal_connect(GTK_OBJECT(file_open_item), "activate", G_CALLBACK(open_event_handler), NULL); |
|---|
| | 726 | g_signal_connect(GTK_OBJECT(options_font_item), "activate", G_CALLBACK(change_font_event_handler), td); |
|---|