mirror of
https://github.com/fspc/gbootroot.git
synced 2025-04-04 07:43:22 -04:00
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.
This commit is contained in:
parent
b05e0a4262
commit
695738d932
@ -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,8 +1191,26 @@ 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: " .
|
||||||
"$new is not " .
|
"$new is not " .
|
||||||
@ -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_text("$new_template already exists, " .
|
||||||
$label->set_justify( 'left' );
|
"do\nyou want to write over it, " .
|
||||||
$save_as->vbox->pack_start( $label, $false, $false, 2 );
|
"or\nsave it with a different name?");
|
||||||
$label->show();
|
|
||||||
$write_over = 1;
|
$event_count++;
|
||||||
}
|
my $event = pop(@_);
|
||||||
else {
|
|
||||||
$write_over = "";
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$write_over) {
|
}, "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" );
|
|
||||||
$save_as->destroy;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$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…
x
Reference in New Issue
Block a user