Skip to content

Commit

Permalink
Only warn user if neither gwl nor bsl is found
Browse files Browse the repository at this point in the history
Previously used to just complain about gwl, and if there was
no gwl, it didn't try to load the bwl.
  • Loading branch information
windymilla committed Nov 28, 2023
1 parent 99ac441 commit 8c884ca
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/lib/Guiguts/SpellCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -476,51 +476,54 @@ sub spelladdtexttags {
#
# Add spellings from good_words.txt & bad_words.txt to the project dictionary
sub spelladdgoodwords {
my $textwindow = $::textwindow;
my $top = $::top;
my $ans = $top->messageBox(
my $top = $::top;
my $ans = $top->messageBox(
-icon => 'warning',
-type => 'YesNo',
-default => 'yes',
-title => 'Warning',
-message =>
'Warning: Before adding good_words.txt to project dictionary, first check it does not contain misspellings, multiple spellings, etc. Continue?'
'Before adding good/bad words to project dictionary, first check they only contain words that you wish to add. Continue?'
);
if ( $ans =~ /no/i ) {
return;
}
return if $ans =~ /no/i;

::busy();
my $pwd = ::getcwd();
chdir $::globallastpath;
my $gwladded = spelladdwords( "good_words.txt", \%::projectdict );
my $bwladded = spelladdwords( "bad_words.txt", \%::projectbadwords );
chdir $pwd;
::unbusy();

my $fh;
if ( $gwladded or $bwladded ) {
spellsaveprojdict();
} else {
$top->messageBox(
-icon => 'warning',
-title => 'Word lists not found',
-message => 'Neither good_words.txt nor bad_words.txt were found'
);
}
}

#
# Add words from given file to given dict - return whether file opened OK
sub spelladdwords {
my $filename = shift;
my $dictref = shift;

# Load good words first - these files may not be utf8-encoded, so don't assume they are
if ( open( $fh, "<", "good_words.txt" ) ) {
::busy();
my $fh;
if ( open( $fh, "<", $filename ) ) {
while ( my $line = <$fh> ) {
utf8::decode($line);
$line =~ s/\s+$//;
next if $line eq '';
$::projectdict{$line} = '';
$dictref->{$line} = '';
}
close($fh);

# The bad_words.txt file often doesn't exist, so don't error if that's the case
if ( open( $fh, "<", "bad_words.txt" ) ) {
while ( my $line = <$fh> ) {
utf8::decode($line);
$line =~ s/\s+$//;
next if $line eq '';
$::projectbadwords{$line} = '';
}
close($fh);
}
spellsaveprojdict();
::unbusy();
} else {
::warnerror("Could not open good_words.txt");
return 1;
}
chdir $pwd;
return 0; # Failed to find file
}

#
Expand Down

0 comments on commit 8c884ca

Please sign in to comment.