Adding a confirmation dialog to be able to open the restored file.

This commit is contained in:
Sergiotarxz 2024-03-04 04:24:22 +01:00
parent 185fe331a6
commit 8fd91b1e08
2 changed files with 69 additions and 15 deletions

View File

@ -33,6 +33,11 @@ has app => (
required => 1,
);
has main_window => (
is => 'ro',
required => 1,
);
has _win => ( is => 'rw', );
sub start {
@ -88,7 +93,8 @@ sub open_save {
my $dest_file = shift;
my $file_dialog = Gtk4::FileDialog->new;
if ( defined $dest_file ) {
$file_dialog->set_initial_folder( Glib::IO::File::new_for_path($dest_file->parent ));
$file_dialog->set_initial_folder(
Glib::IO::File::new_for_path( $dest_file->parent ) );
$file_dialog->set_initial_name( $dest_file->basename );
}
$file_dialog->save(
@ -104,10 +110,47 @@ sub open_save {
$dest_file = path( $dest_file->get_path );
logger()->msg( 'Restoring backup...', $file, $dest_file );
$dest_file->spew_raw( $file->slurp_raw );
$self->offer_to_edit_the_new_file($dest_file);
}
);
}
sub offer_to_edit_the_new_file {
my $self = shift;
my $file = shift;
my $main_window = $self->main_window;
my $confirm = Gtk4::Window->new;
my $box_window = Gtk4::Box->new('vertical', 30);
my $label_question = Gtk4::Label->new("Do you want to open the restored file?");
my $label_warning = Gtk4::Label->new("Any unsaved changes in the save editor will be lost forever");
my $box_options = Gtk4::Box->new('horizontal', 0);
my $cancel_button = Gtk4::Button->new_with_label('Do nothing');
my $confirm_button = Gtk4::Button->new_with_label('Load new file');
$box_options->set_property('hexpand', 1);
$cancel_button->set_property('halign', 'start');
$confirm_button->set_property('halign', 'end');
$confirm_button->set_property('hexpand', 1);
$cancel_button->signal_connect('clicked' => sub {
$confirm->close;
});
$confirm_button->signal_connect('clicked' => sub {
$main_window->open_file($file);
$confirm->close;
});
$confirm->set_titlebar(Gtk4::Label->new('Open the restored file'));
$box_window->append($label_question);
$box_window->append($label_warning);
$box_options->append($cancel_button);
$box_options->append($confirm_button);
$box_window->append($box_options);
$confirm->set_child($box_window);
$confirm->present;
}
sub create_button_restore {
my $self = shift;
my $grid_log = shift;

View File

@ -75,7 +75,6 @@ sub activate {
path(__FILE__)->parent->parent->child('resources/icons')->absolute );
Gtk4::Window::set_default_icon_name('gemetool');
my $win;
my $menu = Glib::IO::Menu->new;
my $about = Glib::IO::SimpleAction->new( 'about', undef );
@ -104,9 +103,11 @@ sub activate {
);
$logs->signal_connect(
activate => sub {
GEmeTool::View::LogWindow->new(app => $self->_app)->start;
my $win = $self->_win;
GEmeTool::View::LogWindow->new(app => $self->_app, main_window => $self)->start;
}
);
$about->signal_connect( activate => \&activate_about, );
my $about_menu_item = Glib::IO::MenuItem->new( 'About', 'app.about' );
@ -127,7 +128,7 @@ sub activate {
$box->append(
Gtk4::Label->new('You have to load a Pokemon Emerald Save.') );
$win = Gtk4::ApplicationWindow->new($app);
my $win = Gtk4::ApplicationWindow->new($app);
$self->_win($win);
$win->set_title('GEmeTool');
$win->set_show_menubar(1);
@ -198,11 +199,21 @@ sub save {
$self->_save->save($file);
}
sub open_file {
my $self = shift;
my $file = shift;
if (!-e $file) {
return;
}
$file = path( $file );
$self->_file($file);
$self->start_editing_file;
}
sub start_editing_file {
my $self = shift;
my $file = $self->_file;
my $save_as = $self->_save_as;
my (@saves_raw);
my $box_app = Gtk4::Box->new( 'vertical', 0 );
$self->_save(GEmeTool::Save->instance($file));
my $save_obj = $self->_save;