Padre::Plugin::SpellCheck - Check spelling in Padre


Padre-Plugin-SpellCheck documentation Contained in the Padre-Plugin-SpellCheck distribution.

Index


Code Index:

NAME

Top

Padre::Plugin::SpellCheck - Check spelling in Padre

VERSION

Top

version 1.21

SYNOPSIS

Top

    $ padre file-with-spell-errors
    F7

DESCRIPTION

Top

This plugins allows one to checking her text spelling within Padre using F7 (standard spelling shortcut accross text processors). One can change the dictionary language used in the preferences window (menu Plugins / SpellCheck / Preferences).

This plugin is using Text::Aspell underneath, so check this module's pod for more information.

Of course, you need to have the aspell binary and dictionnary installed.

PUBLIC METHODS

Top

Standard Padre::Plugin API

Padre::Plugin::SpellCheck defines a plugin which follows Padre::Plugin API. Refer to this module's documentation for more information.

The following methods are implemented:

padre_interfaces()
plugin_icon()
plugin_name()

Spell checking methods

* config()

Return the plugin's configuration, or a suitable default one if none exist previously.

* spell_check()

Spell checks the current selection (or the whole document).

* plugin_preferences()

Open the check spelling preferences window.

BUGS

Top

Spell-checking non-ascii files has bugs: the selection does not match the word boundaries, and as the spell checks moves further in the document, offsets are totally irrelevant. This is a bug in Wx::StyledTextCtrl that has some unicode problems... So unfortunately, there's nothing that I can do in this plugin to tackle this bug.

Please report any bugs or feature requests to padre-plugin-spellcheck at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Padre-Plugin- SpellCheck. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

Top

Plugin icon courtesy of Mark James, at http://www.famfamfam.com/lab/icons/silk/.

Our svn repository is located at http://svn.perlide.org/padre/trunk/Padre-Plugin- SpellCheck, and can be browsed at http://padre.perlide.org/browser/trunk/Padre-Plugin- SpellCheck.

You can also look for information on this module at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Padre-Plugin-SpellCheck

* CPAN Ratings

http://cpanratings.perl.org/d/Padre-Plugin-SpellCheck

* Open bugs

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Padre-Plugin-SpellCheck

Everything aspell related: http://aspell.net.

AUTHORS

Top

COPYRIGHT AND LICENSE

Top


Padre-Plugin-SpellCheck documentation Contained in the Padre-Plugin-SpellCheck distribution.

package Padre::Plugin::SpellCheck;
BEGIN {
  $Padre::Plugin::SpellCheck::VERSION = '1.21';
}

# ABSTRACT: Check spelling in Padre

use warnings;
use strict;

use File::Basename qw{ fileparse };
use File::Spec::Functions qw{ catdir catfile };
use Module::Util qw{ find_installed };

use base 'Padre::Plugin';
use Padre::Current;
use Padre::Plugin::SpellCheck::Dialog;
use Padre::Plugin::SpellCheck::Engine;
use Padre::Plugin::SpellCheck::Preferences;


# -- padre plugin api, refer to Padre::Plugin

# plugin name
sub plugin_name { Wx::gettext('Spell check') }

# plugin icon
sub plugin_icon {
	my $self = shift;

	# find resource path
	my $pkgpath = find_installed(__PACKAGE__);
	my ( undef, $dirname, undef ) = fileparse($pkgpath);
	my $iconpath = catfile( $self->plugin_directory_share, 'icons', 'spellcheck.png' );

	# create and return icon
	return Wx::Bitmap->new( $iconpath, Wx::wxBITMAP_TYPE_PNG );
}

# padre interfaces
sub padre_interfaces {
	'Padre::Plugin' => '0.43',;
}

# plugin menu.
sub menu_plugins_simple {
	Wx::gettext('Spell check') => [
		Wx::gettext("Check spelling\tF7") => 'spell_check',
		Wx::gettext('Preferences')        => 'plugin_preferences',
	];
}


# -- public methods

sub config {
	my ($self) = @_;
	my $config = {
		dictionary => 'en_US',
	};
	return $self->config_read || $config;
}

sub spell_check {
	my ($self) = @_;
	my $main = Padre::Current->main;

	# TODO: maybe grey out the menu option if
	# no file is opened?
	unless ( $main->current->document ) {
		$main->message( Wx::gettext('No document opened.'), 'Padre' );
		return;
	}

	my $mime_type = $main->current->document->mimetype;
	my $engine = Padre::Plugin::SpellCheck::Engine->new($self, $mime_type);

	# fetch text to check
	my $selection = Padre::Current->text;
	my $wholetext = Padre::Current->document->text_get;
	my $text      = $selection || $wholetext;
	my $offset    = $selection ? Padre::Current->editor->GetSelectionStart : 0;

	# try to find a mistake
	my ( $word, $pos ) = $engine->check($text);

	# no mistake means we're done
	if ( not defined $word ) {
		$main->message( Wx::gettext('Spell check finished.'), 'Padre' );
		return;
	}

	my $dialog = Padre::Plugin::SpellCheck::Dialog->new(
		text   => $text,
		error  => [ $word, $pos ],
		engine => $engine,
		offset => $offset,
		plugin => $self,
	);
	$dialog->ShowModal;
}

sub plugin_preferences {
	my ($self) = @_;
	my $prefs = Padre::Plugin::SpellCheck::Preferences->new($self);
	$prefs->Show;
}


1;



__END__