Browse Source

This improves the save_as function and makes it like the one in gbootroot, so

that it keeps checking that the entry isn't an existing file, before it only
checked once.
master
freesource 24 years ago
parent
commit
695738d932
  1. 83
      BootRoot/YardBox.pm

83
BootRoot/YardBox.pm

@ -1153,13 +1153,14 @@ sub save_as {
$save_as->vbox->pack_start( $label, $false, $false, 2 ); $save_as->vbox->pack_start( $label, $false, $false, 2 );
$label->show(); $label->show();
my $button = Gtk::Button->new("OK"); my $button = Gtk::Button->new("OK");
my $new_template_tmp = "nothing";
my $event_count = 0;
$button->signal_connect("clicked", sub { $button->signal_connect("clicked", sub {
# Here's where we get to undef Yard variable and start over at # Here's where we get to undef Yard variable and start over at
# check # check
my $new = "$template_dir$new_template" if $new_template; my $new = "$template_dir$new_template" if $new_template;
#if (!basename($new)) {
if (!$new_template) { if (!$new_template) {
if ( file_mode("$template_dir$template") =~ /l/ ) { if ( file_mode("$template_dir$template") =~ /l/ ) {
error_window("gBootRoot: ERROR: " . error_window("gBootRoot: ERROR: " .
@ -1190,7 +1191,25 @@ sub save_as {
# An existing file shouldn't be written over unless the user wants # An existing file shouldn't be written over unless the user wants
# this to happen. # this to happen.
if (-f $new && !$write_over) { if (!-f $new) {
open(NEW,">$new") or
($error = error("Can't create $new"));
return if $error && $error eq "ERROR";
print NEW $changed_text_from_template;
close(NEW);
$template = $new_template;
opendir(DIR,$template_dir) if -d $template_dir;
my @templates = grep { m,\.yard$, } readdir(DIR) if $template_dir;
closedir(DIR);
$main::combo->set_popdown_strings( @templates ) if @templates;
$main::combo->entry->set_text($new_template);
$main::yard_window->set_title( "Yard Box - $template" );
$save_as->destroy;
}
else {
if ( file_mode("$new") =~ /l/ ) { if ( file_mode("$new") =~ /l/ ) {
error_window("gBootRoot: ERROR: " . error_window("gBootRoot: ERROR: " .
@ -1207,38 +1226,42 @@ sub save_as {
"[Alt-S] with the yard suffix."); "[Alt-S] with the yard suffix.");
$save_as->destroy; $save_as->destroy;
return; return;
#save_as();
} }
my $label = Gtk::Label->new("$new_template already exists, " .
"do\nyou want to write over it?");
$label->set_justify( 'left' );
$save_as->vbox->pack_start( $label, $false, $false, 2 );
$label->show();
$write_over = 1;
}
else {
$write_over = "";
}
if (!$write_over) { $label->set_text("$new_template already exists, " .
open(NEW,">$new") or "do\nyou want to write over it, " .
($error = error("Can't create $new")); "or\nsave it with a different name?");
return if $error && $error eq "ERROR";
print NEW $changed_text_from_template;
close(NEW);
$template = $new_template;
opendir(DIR,$template_dir) if -d $template_dir;
my @templates = grep { m,\.yard$, } readdir(DIR) if $template_dir;
closedir(DIR);
$main::combo->set_popdown_strings( @templates ) if @templates;
$main::combo->entry->set_text($new_template);
$main::yard_window->set_title( "Yard Box - $template" );
$save_as->destroy;
}
}); $event_count++;
my $event = pop(@_);
if ($new_template eq $new_template_tmp) {
if ($event_count >= 2 && $event && $event eq "clicked") {
open(NEW,">$new") or
($error = error("Can't create $new"));
return if $error && $error eq "ERROR";
print NEW $changed_text_from_template;
close(NEW);
$template = $new_template;
opendir(DIR,$template_dir) if -d $template_dir;
my @templates = grep { m,\.yard$, } readdir(DIR)
if $template_dir;
closedir(DIR);
$main::combo->set_popdown_strings( @templates ) if @templates;
$main::combo->entry->set_text($new_template);
$main::yard_window->set_title( "Yard Box - $template" );
$event_count = 0;
$save_as->destroy;
}
}
$new_template_tmp = $new_template;
}
}, "clicked");
$button->can_default(1); $button->can_default(1);
$save_as->action_area->pack_start($button, $false, $false,0); $save_as->action_area->pack_start($button, $false, $false,0);

Loading…
Cancel
Save