Adding a confirmation dialog to be able to open the restored file.
This commit is contained in:
parent
185fe331a6
commit
8fd91b1e08
|
@ -33,6 +33,11 @@ has app => (
|
||||||
required => 1,
|
required => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
has main_window => (
|
||||||
|
is => 'ro',
|
||||||
|
required => 1,
|
||||||
|
);
|
||||||
|
|
||||||
has _win => ( is => 'rw', );
|
has _win => ( is => 'rw', );
|
||||||
|
|
||||||
sub start {
|
sub start {
|
||||||
|
@ -46,11 +51,11 @@ sub start {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fill_logs_win {
|
sub fill_logs_win {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $win = $self->_win;
|
my $win = $self->_win;
|
||||||
my $logs = GEmeTool::Log->new->get_logs;
|
my $logs = GEmeTool::Log->new->get_logs;
|
||||||
my $grid_log = Gtk4::Grid->new;
|
my $grid_log = Gtk4::Grid->new;
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
for my $log_message (@$logs) {
|
for my $log_message (@$logs) {
|
||||||
my $date = $log_message->{date};
|
my $date = $log_message->{date};
|
||||||
my $message = $log_message->{message};
|
my $message = $log_message->{message};
|
||||||
|
@ -68,7 +73,7 @@ sub fill_logs_win {
|
||||||
}
|
}
|
||||||
my $label = Gtk4::Label->new($message);
|
my $label = Gtk4::Label->new($message);
|
||||||
$label->set_halign('start');
|
$label->set_halign('start');
|
||||||
$grid_log->attach($label, 0, $i, 10, 1);
|
$grid_log->attach( $label, 0, $i, 10, 1 );
|
||||||
$self->create_button_restore( $grid_log, 11, $i, 'Restore input file',
|
$self->create_button_restore( $grid_log, 11, $i, 'Restore input file',
|
||||||
$backup_input_file, $input_file );
|
$backup_input_file, $input_file );
|
||||||
$self->create_button_restore( $grid_log, 12, $i, 'Restore output file',
|
$self->create_button_restore( $grid_log, 12, $i, 'Restore output file',
|
||||||
|
@ -77,7 +82,7 @@ sub fill_logs_win {
|
||||||
}
|
}
|
||||||
my $scroll = Gtk4::ScrolledWindow->new;
|
my $scroll = Gtk4::ScrolledWindow->new;
|
||||||
$scroll->set_propagate_natural_width(1);
|
$scroll->set_propagate_natural_width(1);
|
||||||
$scroll->set_policy('never', 'automatic');
|
$scroll->set_policy( 'never', 'automatic' );
|
||||||
$scroll->set_child($grid_log);
|
$scroll->set_child($grid_log);
|
||||||
$win->set_child($scroll);
|
$win->set_child($scroll);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +93,8 @@ sub open_save {
|
||||||
my $dest_file = shift;
|
my $dest_file = shift;
|
||||||
my $file_dialog = Gtk4::FileDialog->new;
|
my $file_dialog = Gtk4::FileDialog->new;
|
||||||
if ( defined $dest_file ) {
|
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->set_initial_name( $dest_file->basename );
|
||||||
}
|
}
|
||||||
$file_dialog->save(
|
$file_dialog->save(
|
||||||
|
@ -102,17 +108,54 @@ sub open_save {
|
||||||
my $dest_file = $dialog->save_finish($res);
|
my $dest_file = $dialog->save_finish($res);
|
||||||
return if !defined $dest_file;
|
return if !defined $dest_file;
|
||||||
$dest_file = path( $dest_file->get_path );
|
$dest_file = path( $dest_file->get_path );
|
||||||
logger()->msg('Restoring backup...', $file, $dest_file);
|
logger()->msg( 'Restoring backup...', $file, $dest_file );
|
||||||
$dest_file->spew_raw( $file->slurp_raw );
|
$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 {
|
sub create_button_restore {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $grid_log = shift;
|
my $grid_log = shift;
|
||||||
my $column = shift;
|
my $column = shift;
|
||||||
my $row = shift;
|
my $row = shift;
|
||||||
my $restore_label = shift;
|
my $restore_label = shift;
|
||||||
my $file = shift;
|
my $file = shift;
|
||||||
my $dest_file = shift;
|
my $dest_file = shift;
|
||||||
|
@ -130,6 +173,6 @@ sub create_button_restore {
|
||||||
$self->open_save( $file, $dest_file );
|
$self->open_save( $file, $dest_file );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$grid_log->attach($button_restore_backup, $column, $row, 1, 1);
|
$grid_log->attach( $button_restore_backup, $column, $row, 1, 1 );
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -75,7 +75,6 @@ sub activate {
|
||||||
path(__FILE__)->parent->parent->child('resources/icons')->absolute );
|
path(__FILE__)->parent->parent->child('resources/icons')->absolute );
|
||||||
Gtk4::Window::set_default_icon_name('gemetool');
|
Gtk4::Window::set_default_icon_name('gemetool');
|
||||||
|
|
||||||
my $win;
|
|
||||||
|
|
||||||
my $menu = Glib::IO::Menu->new;
|
my $menu = Glib::IO::Menu->new;
|
||||||
my $about = Glib::IO::SimpleAction->new( 'about', undef );
|
my $about = Glib::IO::SimpleAction->new( 'about', undef );
|
||||||
|
@ -104,9 +103,11 @@ sub activate {
|
||||||
);
|
);
|
||||||
$logs->signal_connect(
|
$logs->signal_connect(
|
||||||
activate => sub {
|
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, );
|
$about->signal_connect( activate => \&activate_about, );
|
||||||
|
|
||||||
my $about_menu_item = Glib::IO::MenuItem->new( 'About', 'app.about' );
|
my $about_menu_item = Glib::IO::MenuItem->new( 'About', 'app.about' );
|
||||||
|
@ -127,7 +128,7 @@ sub activate {
|
||||||
$box->append(
|
$box->append(
|
||||||
Gtk4::Label->new('You have to load a Pokemon Emerald Save.') );
|
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);
|
$self->_win($win);
|
||||||
$win->set_title('GEmeTool');
|
$win->set_title('GEmeTool');
|
||||||
$win->set_show_menubar(1);
|
$win->set_show_menubar(1);
|
||||||
|
@ -198,11 +199,21 @@ sub save {
|
||||||
$self->_save->save($file);
|
$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 {
|
sub start_editing_file {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $file = $self->_file;
|
my $file = $self->_file;
|
||||||
my $save_as = $self->_save_as;
|
my $save_as = $self->_save_as;
|
||||||
my (@saves_raw);
|
|
||||||
my $box_app = Gtk4::Box->new( 'vertical', 0 );
|
my $box_app = Gtk4::Box->new( 'vertical', 0 );
|
||||||
$self->_save(GEmeTool::Save->instance($file));
|
$self->_save(GEmeTool::Save->instance($file));
|
||||||
my $save_obj = $self->_save;
|
my $save_obj = $self->_save;
|
||||||
|
|
Loading…
Reference in New Issue