Adding save as.

This commit is contained in:
Sergiotarxz 2024-10-17 07:21:48 +02:00
parent 12966354f1
commit 042fef3cab

View File

@ -89,6 +89,8 @@ EOF
}
);
has _save_path => ( is => 'rw' );
sub _tempdir_previews($self) {
if ( !defined $self->_tempdir_previews_guts ) {
$self->_tempdir_previews_guts( Path::Tiny->tempdir );
@ -125,6 +127,26 @@ sub start($self) {
}
sub _save_action($self) {
my $file_format = $self->_file_format;
my $dialog = Gtk4::FileDialog->new;
if (defined $self->_save_path) {
my $zip = $file_format->to_zip;
$zip->writeToFileNamed(''.$self->_save_path);
return;
}
$dialog->set_initial_name('project.exd');
$dialog->save($self->window, undef, sub ($source, $res, $data) {
eval {
my $file = $dialog->save_finish($res);
$file = $file->get_path;
$self->_save_path($file);
my $zip = $file_format->to_zip;
$zip->writeToFileNamed(''.$file);
};
});
}
sub _save_as_action($self) {
my $file_format = $self->_file_format;
my $dialog = Gtk4::FileDialog->new;
$dialog->set_initial_name('project.exd');
@ -142,10 +164,13 @@ sub _open_action($self) {
my $file_format = $self->_file_format;
my $dialog = Gtk4::FileDialog->new;
$dialog->set_initial_name('project.exd');
my $window = $self->window;
$dialog->open($self->window, undef, sub ($source, $res, $data) {
eval {
my $file = $dialog->open_finish($res);
$file = $file->get_path;
$self->_save_path($file);
$window->set_title("Exd (Thermal Printer) ". path($self->_save_path)->basename);
$self->_file_format(Exd::FileFormat->from_zip_file($file));
$self->_update_editor_buffer;
};
@ -158,16 +183,22 @@ sub _startup($self) {
my $file_menu = Glib::IO::Menu->new;
my $open_action = Glib::IO::SimpleAction->new('open', undef);
my $save_action = Glib::IO::SimpleAction->new('save', undef);
my $save_as_action = Glib::IO::SimpleAction->new('save-as', undef);
$open_action->signal_connect('activate', sub {
$self->_open_action;
});
$save_action->signal_connect('activate', sub {
$self->_save_action;
});
$save_as_action->signal_connect('activate', sub {
$self->_save_as_action;
});
$app->add_action($open_action);
$app->add_action($save_action);
$app->add_action($save_as_action);
$file_menu->append('Open', 'app.open');
$file_menu->append('Save', 'app.save');
$file_menu->append('Save as', 'app.save-as');
$menu_model->append_submenu('File', $file_menu);
$app->set_menubar($menu_model);
}
@ -402,7 +433,7 @@ sub _populate_preview( $self, $box_editor_preview ) {
sub _open_gallery($self) {
my $window = Gtk4::Window->new;
$window->set_transient_for( $self->window );
$window->set_default_size( 600, 600 );
$window->set_default_size( 650, 650 );
$window->set_title('Image gallery');
my $box = Gtk4::Box->new( 'vertical', 1 );
my $box_upper_menu = Gtk4::Box->new( 'horizontal', 10 );