App-Codit

 view release on metacpan or  search on metacpan

lib/App/Codit/Plugins/Sessions.pm  view on Meta::CPAN

=head1 DESCRIPTION

Manage your sessions. Saves your named session on exit and reloads it on start.

=head1 DETAILS

The sessions plugin allows you to save a collection of documents as a session.
When re-opening the session the documents are loaded in the exact order as they
were when the session was closed. Also the syntax option, tab size, indent style,
bookmarks and insert cursor position are saved. The only thing that is lost is your
undo stack.

The sessions plugin also saves the following from plugins if they are loaded:

=over 4

=item The working folder from the Console plugin

=item The working folder from the FileBrowser plugin

=item The project name of the currently loaded project in the Git plugin

=back

The session manager allows you to keep your sessions orderly.

=head1 COMMANDS

=over 4

=item B<session_dialog>

Pops the dialog for managing sessions.

=item B<session_fill_menu>

Called when the Session menu in the menu bar is opened.

=item B<session_new>

Closes current session and creates a new, unnamed, one.

=item B<session_open>

Takes a session name as parameter. Closes current session and opens the new one.

=item B<session_save>

Save current session. If the session was not saved before, a dialog will pop to enter a name.

=item B<session_save_as>

Save current session under a new name.

=back

=cut

sub new {
	my $class = shift;
	my $self = $class->SUPER::new(@_, 'ConfigFolder', 'MenuBar');
	return undef unless defined $self;

	$self->sessionFolder;

	$self->{CURRENT} = '';
	$self->{DATA} = {};

	$self->cmdConfig(
		session_dialog => ['sessionDialog', $self],
		session_fill_menu => ['sessionFillMenu', $self],
		session_new => ['sessionNew', $self],
		session_open => ['sessionOpen', $self],
		session_save => ['sessionSave', $self],
		session_save_as => ['sessionSaveAs', $self],
	);
	$self->cmdHookAfter('set_title', 'AdjustTitle', $self);
	return $self;
}

sub AdjustTitle {
	my $self = shift;
	my $mdi = $self->mdi;
	my $doc = $mdi->docSelected;
	my $name = $self->configGet('-appname');
	if (defined $doc) {
		my $label = $mdi->docTitle($doc);
		$name = "$label - $name";
	}
	my $current = $self->sessionCurrent;
	if ($current ne '') {
		$name =  "$current: $name" ;
	}
	$self->configPut(-title => $name);
}

sub bookmarksInitialize {
	my $self = shift;
	my $bookmarks = $self->extGet('Plugins')->plugGet('Bookmarks');
	$self->after(200, ['Initialize', $bookmarks]) if defined $bookmarks;
}

sub browserDir {
	my ($self, $dir) = @_;
	my $b = $self->extGet('Plugins')->plugGet('FileBrowser');
	return unless defined $b;
	my $browser = $b->browser;
	$browser->load($dir) if defined $dir;
	return $browser->folder;
}

sub CanQuit {
	my $self = shift;
	$self->sessionSave unless $self->sessionCurrent eq '';
	$self->mdi->docForceClose(1);
	return 1
}

sub consoleDir {
	my ($self, $dir) = @_;
	my $console = $self->extGet('Plugins')->plugGet('Console');

lib/App/Codit/Plugins/Sessions.pm  view on Meta::CPAN

			if (@l) {
				my $bm = '';
				for (@l) {
					$bm = "$bm$_ ";
				}
				$h{'bookmarks'} = $bm;
			}			

			push @list, [$item, \%h]
		}
	}
	$cff->saveSectionedList($file, 'cdt session', @list)
}

sub sessionSaveAs {
	my $self = shift;
	my $dialog = $self->YADialog(
		-buttons => ['Ok', 'Cancel'],
	);
	$dialog->Label(
		-text => 'Please enter a session name',
		-justify => 'left',
	)->pack(-fill => 'x', -padx => 3, -pady => 3);
	my $text = '';
	my $e = $dialog->Entry(
		-textvariable => \$text,
	)->pack(-fill => 'x', -padx => 3, -pady => 3);
	$e->focus;
	my $but = $dialog->show(-popover => $self->toplevel);
	if (($but eq 'Ok') and ($text ne '')) {
		$self->sessionCurrent($text);
		$self->sessionSave;
		$self->AdjustTitle;
	}

}

sub sessionValidateName {
	my ($self, $name) = @_;
	return 0 if $name eq '';
	return 0 if $name +~ /\//;
	return 0 if $name +~ /\\/;
	return 1
}

sub Unload {
	my $self = shift;
	for (qw/
		session_dialog
		session_fill_menu
		session_new
		session_open
		session_save
		session_save_as
	/) {
		$self->cmdRemove($_);
	}
	$self->sessionCurrent('');
	$self->cmdUnhookAfter('set_title', 'AdjustTitle', $self);
	$self->AdjustTitle;
	return $self->SUPER::Unload
}

=head1 LICENSE

Same as Perl.

=head1 AUTHOR

Hans Jeuken (hanje at cpan dot org)

=head1 TODO

=over 4

=back

=head1 BUGS AND CAVEATS

If you find any bugs, please report them here L<https://github.com/haje61/App-Codit/issues>.

=head1 SEE ALSO

=over 4

=back

=cut



1;















( run in 0.598 second using v1.01-cache-2.11-cpan-99c4e6809bf )