~ubuntu-branches/ubuntu/quantal/padre/quantal

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
package Padre::Wx::Menu::View;

# Fully encapsulated View menu

use 5.008;
use strict;
use warnings;
use Padre::Constant          ();
use Padre::Current           ();
use Padre::Feature           ();
use Padre::Wx                ();
use Padre::Wx::ActionLibrary ();
use Padre::Wx::Menu          ();
use Padre::Locale            ();

our $VERSION    = '0.92';
our $COMPATIBLE = '0.87';
our @ISA        = 'Padre::Wx::Menu';





#####################################################################
# Padre::Wx::Menu Methods

sub new {
	my $class  = shift;
	my $main   = shift;
	my $config = $main->config;

	# Create the empty menu as normal
	my $self = $class->SUPER::new(@_);

	# Add additional properties
	$self->{main} = $main;

	# Can the user move stuff around
	$self->{lockinterface} = $self->add_menu_action(
		'view.lockinterface',
	);

	$self->AppendSeparator;

	# Show or hide GUI elements
	$self->{command_line} = $self->add_menu_action(
		'view.command_line',
	);

	$self->{cpan_explorer} = $self->add_menu_action('view.cpan_explorer')
		if $main->config->feature_cpan_explorer;

	$self->{functions} = $self->add_menu_action(
		'view.functions',
	);

	$self->{directory} = $self->add_menu_action(
		'view.directory',
	);

	$self->{outline} = $self->add_menu_action(
		'view.outline',
	);

	$self->{output} = $self->add_menu_action(
		'view.output',
	);

	$self->{syntaxcheck} = $self->add_menu_action(
		'view.syntaxcheck',
	);

	$self->{todo} = $self->add_menu_action(
		'view.todo',
	);

	$self->{vcs} = $self->add_menu_action('view.vcs')
		if $main->config->feature_vcs_support;

	$self->{toolbar} = $self->add_menu_action(
		'view.toolbar',
	);

	$self->{statusbar} = $self->add_menu_action(
		'view.statusbar',
	);

	$self->AppendSeparator;

	# View as (Highlighting File Type)
	SCOPE: {
		$self->{view_as_highlighting} = Wx::Menu->new;
		$self->Append(
			-1,
			Wx::gettext("&View Document As..."),
			$self->{view_as_highlighting}
		);

		my %mimes = Padre::MimeTypes::menu_view_mimes();
		my @names = $self->sort_mimes( \%mimes );
		foreach my $name (@names) {
			my $radio = $self->add_menu_action(
				$self->{view_as_highlighting},
				"view.mime.$name",
			);
		}
	}

	$self->AppendSeparator;

	# Show or hide editor elements
	$self->{currentline} = $self->add_menu_action(
		'view.currentline',
	);

	$self->{lines} = $self->add_menu_action(
		'view.lines',
	);

	$self->{indentation_guide} = $self->add_menu_action(
		'view.indentation_guide',
	);

	$self->{whitespaces} = $self->add_menu_action(
		'view.whitespaces',
	);

	$self->{calltips} = $self->add_menu_action(
		'view.calltips',
	);

	$self->{eol} = $self->add_menu_action(
		'view.eol',
	);

	$self->{rightmargin} = $self->add_menu_action(
		'view.rightmargin',
	);

	# Code folding menu entries
	if (Padre::Feature::FOLDING) {
		$self->AppendSeparator;

		$self->{folding} = $self->add_menu_action(
			'view.folding',
		);

		$self->{fold_all} = $self->add_menu_action(
			'view.fold_all',
		);

		$self->{unfold_all} = $self->add_menu_action(
			'view.unfold_all',
		);

		$self->{fold_this} = $self->add_menu_action(
			'view.fold_this',
		);
	}

	$self->AppendSeparator;

	$self->{word_wrap} = $self->add_menu_action(
		'view.word_wrap',
	);

	$self->AppendSeparator;

	# Font Size
	if (Padre::Feature::FONTSIZE) {
		$self->{fontsize} = Wx::Menu->new;
		$self->Append(
			-1,
			Wx::gettext('Font Si&ze'),
			$self->{fontsize}
		);

		$self->{font_increase} = $self->add_menu_action(
			$self->{fontsize},
			'view.font_increase',
		);

		$self->{font_decrease} = $self->add_menu_action(
			$self->{fontsize},
			'view.font_decrease',
		);

		$self->{font_reset} = $self->add_menu_action(
			$self->{fontsize},
			'view.font_reset',
		);
	}

	# Language Support
	Padre::Wx::ActionLibrary->init_language_actions;

	# TO DO: God this is horrible, there has to be a better way
	my $default  = Padre::Locale::system_rfc4646() || 'x-unknown';
	my $current  = Padre::Locale::rfc4646();
	my %language = Padre::Locale::menu_view_languages();

	# Parent Menu
	$self->{language} = Wx::Menu->new;
	$self->Append(
		-1,
		Wx::gettext('Lan&guage'),
		$self->{language}
	);

	# Default menu entry
	$self->{language_default} = $self->add_menu_action(
		$self->{language},
		'view.language.default',
	);
	if ( defined $config->locale and $config->locale eq $default ) {
		$self->{language_default}->Check(1);
	}

	$self->{language}->AppendSeparator;

	foreach my $name ( sort { $language{$a} cmp $language{$b} } keys %language ) {
		my $radio = $self->add_menu_action(
			$self->{language},
			"view.language.$name",
		);

		if ( $current eq $name ) {
			$radio->Check(1);
		}
	}

	$self->AppendSeparator;

	# Window Effects
	$self->add_menu_action(
		'view.full_screen',
	);

	return $self;
}

sub title {
	Wx::gettext('&View');
}

sub refresh {
	my $self     = shift;
	my $current  = Padre::Current::_CURRENT(@_);
	my $config   = $current->config;
	my $document = $current->document;
	my $doc      = $document ? 1 : 0;

	# Simple check state cases from configuration
	$self->{statusbar}->Check( $config->main_statusbar );
	$self->{lines}->Check( $config->editor_linenumbers );
	$self->{currentline}->Check( $config->editor_currentline );
	$self->{rightmargin}->Check( $config->editor_right_margin_enable );
	$self->{eol}->Check( $config->editor_eol );
	$self->{whitespaces}->Check( $config->editor_whitespace );
	$self->{output}->Check( $config->main_output );
	$self->{outline}->Check( $config->main_outline );
	$self->{directory}->Check( $config->main_directory );
	$self->{functions}->Check( $config->main_functions );
	$self->{todo}->Check( $config->main_todo );
	$self->{lockinterface}->Check( $config->main_lockinterface );
	$self->{indentation_guide}->Check( $config->editor_indentationguides );
	$self->{calltips}->Check( $config->editor_calltips );
	$self->{command_line}->Check( $config->main_command_line );
	$self->{syntaxcheck}->Check( $config->main_syntaxcheck );
	$self->{vcs}->Check( $config->main_vcs ) if $config->feature_vcs_support;
	$self->{cpan_explorer}->Check( $config->main_cpan_explorer )
		if $config->feature_cpan_explorer;
	$self->{toolbar}->Check( $config->main_toolbar );

	if (Padre::Feature::FOLDING) {
		my $folding = $config->editor_folding;
		$self->{folding}->Check($folding);
		$self->{fold_all}->Enable($folding);
		$self->{unfold_all}->Enable($folding);
		$self->{fold_this}->Enable($folding);
	}

	# Check state for word wrap is document-specific
	if ($document) {
		my $editor = $document->editor;
		my $mode   = $editor->get_wrap_mode;
		my $wrap   = $self->{word_wrap};
		if ( $mode eq 'WORD' and not $wrap->IsChecked ) {
			$wrap->Check(1);
		} elsif ( $mode eq 'NONE' and $wrap->IsChecked ) {
			$wrap->Check(0);
		}

		# Set mimetype
		my $has_checked = 0;
		if ( $document->mimetype ) {
			my %mimes = Padre::MimeTypes::menu_view_mimes();
			my @mimes = $self->sort_mimes( \%mimes );
			foreach my $pos ( 0 .. scalar @mimes - 1 ) {
				my $radio = $self->{view_as_highlighting}->FindItemByPosition($pos);
				if ( $document->mimetype eq $mimes[$pos] ) {
					$radio->Check(1);
					$has_checked = 1;
				}
			}
		}

		# By default 'Plain Text';
		unless ($has_checked) {
			$self->{view_as_highlighting}->FindItemByPosition(0)->Check(1);
		}
	}

	# Disable zooming if there's no current document
	if (Padre::Feature::FONTSIZE) {
		$self->{font_increase}->Enable($doc);
		$self->{font_decrease}->Enable($doc);
		$self->{font_reset}->Enable($doc);
	}

	return;
}

sub sort_mimes {
	my $self  = shift;
	my $mimes = shift;

	# Can't do "return sort", must sort to a list first
	my @sorted = sort {
		( $b eq 'text/plain' ) <=> ( $a eq 'text/plain' )
			or Wx::gettext( $mimes->{$a} ) cmp Wx::gettext( $mimes->{$b} )
	} keys %$mimes;

	return @sorted;
}

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.