App-Codit
view release on metacpan or search on metacpan
lib/App/Codit/Ext/CoditMDI.pm view on Meta::CPAN
package App::Codit::Ext::CoditMDI;
=head1 NAME
App::Codit::Ext::CoditMDI - Multiple Document Interface for App::Codit
=cut
use strict;
use warnings;
use Carp;
use vars qw($VERSION);
$VERSION = '0.19';
use base qw( Tk::AppWindow::Ext::MDI );
#require Tk::AppWindow::PluginsForm;
require App::Codit::CoditTagsEditor;
require App::Codit::Macro;
require Tk::YADialog;
my @navcontextmenu = (
[ 'menu_normal', undef, '~Close', 'doc_close', 'document-close', '*CTRL+SHIFT+O'],
[ 'menu_normal', undef, '~Delete', 'doc_delete_dialog', 'edit-delete'],
[ 'menu_separator', undef, 'c1'],
[ 'menu_normal', undef, '~Collapse all', 'nav_collapse'],
[ 'menu_normal', undef, '~Expand all', 'nav_expand'],
);
=head1 SYNOPSIS
my $app = new App::Codit(@options,
-extensions => ['CoditMDI'],
);
$app->MainLoop;
=head1 DESCRIPTION
Inherits L<Tk::AppWindow::Ext::MDI>.
This is a specially crafted multiple document interface for l<App::Codit>.
=head1 CONFIG VARIABLES
=over 4
=item B<-doc_autobrackets> I<hookable>
Sets and returns the autobrackets option of the currently selected document.
=item B<-doc_autocomplete> I<hookable>
Sets and returns the autocomplete option of the currently selected document.
=item B<-doc_autoindent> I<hookable>
Sets and returns the autoindent option of the currently selected document.
=item B<-doc_wrap> I<hookable>
Sets and returns the wrap option of the currently selected document.
=item B<-doc_view_folds> I<hookable>
Sets and returns the showfolds option of the currently selected document.
=item B<-doc_view_numbers> I<hookable>
Sets and returns the shownumbers option of the currently selected document.
=item B<-doc_view_status> I<hookable>
Sets and returns the showstatus option of the currently selected document.
=item B<-doc_wrap>
Sets and returns the wrap option of the currently selected document.
=back
=head1 COMMANDS
=over 4
=item B<bookmark_add>
Adds the current line to the bookmarks list.
lib/App/Codit/Ext/CoditMDI.pm view on Meta::CPAN
=item B<modified>, I<$doc>, I<$index>
Called every time you make an edit, it gets a document name and an index as parameters.
It checks if there are any macros that should be restarted.
Many plugins hook on to this command.
=back
=head1 METHODS
=over 4
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
# $self->Require('Navigator');
$self->{MACROS} = {};
$self->{SHOWSPACES} = 0;
$self->{FIXINDENTSPACES} = 3;
my $nav = $self->Subwidget('NAVTREE');
$self->configInit(
-doc_autoindent => ['docAutoIndent', $self],
-doc_autobrackets => ['docAutoBrackets', $self],
-doc_autocomplete=> ['docAutoComplete', $self],
-doc_show_spaces => ['docShowSpaces', $self],
-doc_view_folds => ['docViewFolds', $self],
-doc_view_numbers => ['docViewNumbers', $self],
-doc_view_status => ['docViewStatus', $self],
-doc_wrap => ['docWrap', $self],
);
$self->cmdConfig(
bookmark_add => ['bookmarkAdd', $self],
bookmark_clear => ['bookmarkClear', $self],
bookmark_fill => ['bookmarkFill', $self],
bookmark_next => ['bookmarkNext', $self],
bookmark_prev => ['bookmarkPrev', $self],
bookmark_remove => ['bookmarkRemove', $self],
doc_autoindent => ['docAutoIndent', $self],
doc_case_lower => ['docCaseLower', $self],
doc_case_upper => ['docCaseUpper', $self],
doc_delete => ['docDelete', $self],
doc_delete_dialog => ['docDeleteDialog', $self],
doc_find => ['docPopFindReplace', $self, 1],
doc_fix_indent => ['docFixIndent', $self],
doc_get_sel => ['docGetSel', $self],
doc_get_text => ['docGetText', $self],
doc_remove_trailing => ['docRemoveTrailing', $self],
doc_replace => ['docPopFindReplace', $self, 0],
doc_wrap => ['docWrap', $self],
edit_delete => ['editDelete', $self],
edit_insert => ['editInsert', $self],
edit_replace => ['editReplace', $self],
key_released => ['keyReleased', $self],
modified => ['contentModified', $self],
nav_collapse => ['navCollapse', $self],
nav_expand => ['navExpand', $self],
);
return $self;
}
sub _mcr { return $_[0]->{MACROS} }
sub bookmarkAdd {
my $self = shift;
my $doc = $self->docSelected;
if (defined $doc) {
my $w = $self->docGet($doc)->CWidg;
$w->bookmarkNew
}
}
sub bookmarkClear {
my $self = shift;
my $doc = $self->docSelected;
if (defined $doc) {
my $w = $self->docGet($doc)->CWidg;
$w->bookmarkRemoveAll;
}
}
sub bookmarkFill {
my $self = shift;
my $mnu = $self->extGet('MenuBar');
my ($menu, $index) = $mnu->FindMenuEntry('Bookmarks');
my $submenu = $menu->entrycget($index, '-menu');
my $i = $submenu->index('end');
if ($i > 7) {
$submenu->delete(8, 'last');
}
my $doc = $self->docSelected;
if (defined $doc) {
my $w = $self->docGet($doc)->CWidg;
my @list = $w->bookmarkList;
for (@list) {
$submenu->add('command',
-label => "$_ - " . $w->bookmarkText($_),
-command => ['bookmarkGo', $w, $_],
);
}
}
}
sub bookmarkNext {
my $self = shift;
my $doc = $self->docSelected;
if (defined $doc) {
my $w = $self->docGet($doc)->CWidg;
$w->bookmarkNext
}
}
sub bookmarkPrev {
my $self = shift;
my $doc = $self->docSelected;
if (defined $doc) {
my $w = $self->docGet($doc)->CWidg;
lib/App/Codit/Ext/CoditMDI.pm view on Meta::CPAN
[ 'menu_normal', 'Edit::', '~Indent', '<Control-j>', 'format-indent-more','*CTRL+J'],
[ 'menu_normal', 'Edit::', 'Unin~dent', '<Control-J>', 'format-indent-less','*CTRL+SHIFT+J'],
[ 'menu_separator', 'Edit::', 'e4' ],
[ 'menu_normal', 'Edit::', 'U~pper case', 'doc_case_upper', 'format-text-uppercase','*CTRL+I'],
[ 'menu_normal', 'Edit::', '~Lower case', 'doc_case_lower', 'format-text-lowercase','*CTL+SHIFT+I'],
[ 'menu_separator', 'Edit::', 'e5' ],
[ 'menu_normal', 'Edit::', '~Select all', '<Control-a>', 'edit-select-all','*CTRL+A'],
[ 'menu', undef, '~Bookmarks', 'bookmark_fill'],
[ 'menu_normal', 'Bookmarks::', '~Add bookmark', 'bookmark_add', 'bookmark_new', 'CTRL+B',],
[ 'menu_normal', 'Bookmarks::', '~Remove bookmark', 'bookmark_remove', 'bookmark_remove', 'CTRL+SHIFT+B',],
[ 'menu_normal', 'Bookmarks::', '~Clear bookmarks', 'bookmark_clear', undef],
[ 'menu_separator', 'Bookmarks::', 'b1' ],
[ 'menu_normal', 'Bookmarks::', '~Previous bookmark', 'bookmark_prev', 'bookmark_previous'],
[ 'menu_normal', 'Bookmarks::', '~Next bookmark', 'bookmark_next', 'bookmark_next'],
[ 'menu_separator', 'Bookmarks::', 'b2' ],
[ 'menu_separator', 'View::', 'v1' ],
[ 'menu_check', 'View::', 'Show ~folds', undef, '-doc_view_folds', undef, 0, 1],
[ 'menu_check', 'View::', 'Show ~line numbers', undef, '-doc_view_numbers', undef, 0, 1],
[ 'menu_check', 'View::', 'Show ~document status',undef, '-doc_view_status', undef, 0, 1],
[ 'menu_separator', 'View::', 'v2' ],
[ 'menu_check', 'View::', 'Show ~spaces and tabs','show-spaces', '-doc_show_spaces', undef, 0, 1],
[ 'menu', undef, '~Tools'],
[ 'menu_normal', 'Tools::', '~Find', 'doc_find', 'edit-find', '*CTRL+F',],
[ 'menu_normal', 'Tools::', '~Replace', 'doc_replace', 'edit-find-replace','*CTRL+R',],
[ 'menu_separator', 'Tools::', 't1' ],
[ 'menu_check', 'Tools::', 'A~uto indent', undef, '-doc_autoindent', undef, 0, 1],
[ 'menu_check', 'Tools::', 'A~uto brackets', undef, '-doc_autobrackets', undef, 0, 1],
[ 'menu_check', 'Tools::', 'A~uto complete', undef, '-doc_autocomplete', undef, 0, 1],
[ 'menu_radio_s', 'Tools::', '~Wrap', [qw/char word none/], undef, '-doc_wrap'],
[ 'menu_separator', 'Tools::', 't1' ],
[ 'menu_normal', 'Tools::', 'R~emove trailing spaces', 'doc_remove_trailing',],
[ 'menu_normal', 'Tools::', 'F~ix indentation', 'doc_fix_indent',],
);
}
sub navCollapse {
my $self = shift;
my $tree = $self->Subwidget('NAVTREE');
$tree->collapseAll;
}
sub navContextMenu {
my $self = shift;
my $nav = $self->Subwidget('NAVTREE');
my @items = @navcontextmenu;
#checking if Git is loaded;
my $git = $self->extGet('Plugins')->plugGet('Git');
push @items, [ 'menu_normal', 'c1', '~Add to project', 'git_add', 'git-icon',] if defined $git;
my $stack = $self->extGet('MenuBar')->menuStack(@items);
$nav->configure('-contextmenu', $stack);
}
sub navExpand {
my $self = shift;
my $tree = $self->Subwidget('NAVTREE');
$tree->expandAll;
}
sub SettingsPage {
my $self = shift;
my ($first) = $self->docList;
my $doc = $self->docGet($first);
return () unless defined $doc;
my $themefile = $doc->cget('-highlight_themefile');
my $historyfile = $self->extGet('ConfigFolder')->ConfigFolder . '/color_history';
my @opt = (
-applycall => sub {
my $themefile = shift;
my @list = $self->docList;
for (@list) {
my $d = $self->docGet($_);
$d->configure(-highlight_themefile => $themefile);
$d->configureTags;
}
},
-defaultbackground => $doc->cget('-contentbackground'),
-defaultforeground => $doc->cget('-contentforeground'),
-defaultfont => $doc->CWidg->Subwidget('XText')->cget('-font'),
-historyfile => $historyfile,
-extension => $self,
-themefile => $themefile,
);
return (
'Highlighting' => ['CoditTagsEditor', @opt]
)
}
sub ToolItems {
my $self = shift;
my @items = $self->SUPER::ToolItems;
return (@items,
# type label cmd icon help
[ 'tool_separator' ],
[ 'tool_button', 'Copy', '<Control-c>', 'edit-copy', 'Copy selected text to clipboard'],
[ 'tool_button', 'Cut', '<Control-x>', 'edit-cut', 'Move selected text to clipboard'],
[ 'tool_button', 'Paste', '<Control-v>', 'edit-paste', 'Paste clipboard content into document'],
[ 'tool_separator' ],
[ 'tool_button', 'Undo', '<Control-z>', 'edit-undo', 'Undo last action'],
[ 'tool_button', 'Redo', '<Control-Z>', 'edit-redo', 'Cancel undo'],
);
}
=back
=head1 LICENSE
Same as Perl.
=head1 AUTHOR
Hans Jeuken (hanje at cpan dot org)
=head1 BUGS
Unknown. If you find any, please report them here L<https://github.com/haje61/App-Codit/issues>.
( run in 0.640 second using v1.01-cache-2.11-cpan-5b529ec07f3 )