~ubuntu-branches/ubuntu/saucy/padre/saucy-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package Padre::Wx::Dialog::Special;

use 5.008;
use strict;
use warnings;
use Padre::Wx::FBP::Special ();

our $VERSION = '0.92';
our @ISA     = 'Padre::Wx::FBP::Special';





######################################################################
# Constructor

sub new {
	my $class  = shift;
	my $self   = $class->SUPER::new(@_);
	my $select = $self->select;

	# Fill the dropbox
	$select->Clear;
	foreach my $special ( $self->catalogue ) {
		$select->Append(@$special);
	}
	$select->SetSelection(0);

	# Set the initial preview
	$self->refresh;

	return $self;
}





######################################################################
# Event Handlers

sub refresh {
	my $self  = shift;
	my $value = $self->value;
	$self->preview->SetValue($value);
}

sub insert_preview {
	my $self = shift;
	my $editor = $self->current->editor or return;
	$editor->insert_text( $self->value );
}





######################################################################
# Special Value Catalogue

sub catalogue {
	my $date = Wx::gettext('Date/Time');
	my $file = Wx::gettext('File');
	return (
		[ "$date - " . Wx::gettext('Now'),   'time_now' ],
		[ "$date - " . Wx::gettext('Today'), 'time_today' ],
		[ "$date - " . Wx::gettext('Year'),  'time_year' ],
		[ "$date - " . Wx::gettext('Epoch'), 'time_epoch' ],
		[ "$file - " . Wx::gettext('Name'),  'file_name' ],
		[ "$file - " . Wx::gettext('Size'),  'file_size' ],
		[ "$file - " . Wx::gettext('Lines'), 'file_lines' ],
	);
}

sub value {
	my $self   = shift;
	my @list   = $self->catalogue;
	my $method = $list[ $self->select->GetSelection ]->[1];
	return $self->$method;
}

sub time_now {
	return scalar localtime;
}

sub time_today {
	my @t = localtime;
	return sprintf( "%s-%02s-%02s", $t[5] + 1900, $t[4], $t[3] );
}

sub time_year {
	my @t = localtime;
	return $t[5] + 1900;
}

sub time_epoch {
	return time;
}

sub file_name {
	my $self = shift;
	my $document = $self->current->document or return '';
	if ( $document->file ) {
		return $document->{file}->filename;
	}

	# Use the title instead
	my $title = $document->get_title;
	$title =~ s/^\s+//;
	return $title;
}

sub file_size {
	my $self     = shift;
	my $document = $self->current->document or return 0;
	my $filename = $document->filename || $document->tempfile or return 0;
	return -s $filename;
}

sub file_lines {
	my $self = shift;
	my $editor = $self->current->editor or return 0;
	return $editor->GetLineCount;
}

1;

# Copyright 2008-2011 The Padre development team as listed in Padre.pm.
# LICENSE
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl 5 itself.