summaryrefslogtreecommitdiff
path: root/support/autolatex/pm/AutoLaTeX/GUI/Gtk/GeneralPanel.pm
blob: 3a706c1c2a9dab26776edc8db2e9137d0f997894 (plain)
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# Copyright (C) 2007-13  Stephane Galland <galland@arakhne.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

=pod

=head1 NAME

AutoLaTeX::GUI::Gtk::GeneralPanel - A GTK panel for general management

=head1 DESCRIPTION

AutoLaTeX::GUI::Gtk::GeneralPanel is a Perl module, which permits to
display a Gtk panel that manages AutoLaTeX options.

=head1 METHOD DESCRIPTIONS

This section contains only the methods in GtkGeneralPanel.pm itself.

=over

=cut

package AutoLaTeX::GUI::Gtk::GeneralPanel;

@ISA = qw( Gtk2::Table AutoLaTeX::GUI::Gtk::WidgetUtil AutoLaTeX::GUI::AbstractGeneralPanel );
@EXPORT = qw();
@EXPORT_OK = qw();

require 5.014;
use strict;
use utf8;
use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
use Exporter;

use Glib qw(TRUE FALSE);
use Gtk2;
use Gtk2::SimpleList;

use AutoLaTeX::Core::Util;
use AutoLaTeX::Core::IntUtils;
use AutoLaTeX::GUI::AbstractGeneralPanel;
use AutoLaTeX::GUI::Gtk::WidgetUtil;

#------------------------------------------------------
#
# Global vars
#
#------------------------------------------------------

# Version number
my $VERSION = "9.0" ;

my %GENERATION_TYPES = ();

my %MAKEINDEX_STYLE_TYPES = ();

#------------------------------------------------------
#
# Functions
#
#------------------------------------------------------

=pod

=item * new(\%$)

Contructor.

Parameters are:

=over 4

=item the configuration extracted from the configuration files.

=item is the name of the subroutine that permits to get the configuration filename

=back

=cut
sub new(\%$) : method {
	my $proto = shift;
	my $class = ref($proto) || $proto;

	my $self = bless( $class->SUPER::new(
						4, #rows
						1, #columns
						FALSE), #non uniform
			$class ) ;

	die("The first parameter of AutoLaTeX::GUI::Gtk::GeneralPanel::new() should be a hastable\nIf you pass a %v variable, please use the \%v syntax instead.\n")
		unless ((!defined($_[0]))||(isHash($_[0])));
	$self->attr('configuration') = {};
	%{$self->attr('configuration')} = %{$_[0]};

	$self->attr('configuration-filename') = $_[1];

	# Initialization
	$self->initializeGeneralPanel();

	return $self;
}

=pod

=item * initControls()

Initializing the controls.

=cut
sub initControls() : method {
	my $self = shift;

	# GENERATION part
	{
		my $generationFrame = Gtk2::Frame->new(_T("Generation"));
		$self->attach ($generationFrame, 
					0,1,0,1, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					5,2); # horizontal and vertical paddings
		my $subtable = Gtk2::Table->new (
						5, #rows
						2, #columns
						FALSE); #non uniform
		$generationFrame->add ($subtable);

		my $label1 = Gtk2::Label->new (_T("Main TeX file (optional):"));
		$subtable->attach ($label1, 
					0,1,0,1, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit1 = Gtk2::Entry->new ();
		$self->connectSignal($edit1,'changed','onMainTeXFileChanged');
		$subtable->attach ($edit1, 
					1,2,0,1, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','MAIN_TEX_FILE') = $edit1;

		my $label2b = Gtk2::CheckButton->new (_T("Run bibliography tool"));
		$self->connectSignal($label2b,'toggled','onRunBiblioToggled');
		$subtable->attach ($label2b, 
					0,2,1,2, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','ENABLE_BIBLIO') = $label2b;

		my $label2 = Gtk2::CheckButton->new (_T("Automatic generation of pictures"));
		$self->connectSignal($label2,'toggled','onGenerateImageToggled');
		$subtable->attach ($label2, 
					0,2,2,3, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','AUTO_PICTURE_GENERATION') = $label2;


		my $label3 = Gtk2::Label->new (_T("Image search directory:"));
		$subtable->attach ($label3, 
					0,1,3,4, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit2 = Gtk2::Entry->new ();
		$self->connectSignal($edit2,'changed','onImageSearchDirectoryChanged');
		$subtable->attach ($edit2, 
					1,2,3,4, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','AUTO_GENERATE_IMAGE_DIRECTORY') = $edit2;

		my $label4 = Gtk2::Label->new (_T("Type of generation:"));
		$subtable->attach ($label4, 
					0,1,4,5, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit3 = Gtk2::ComboBox->new_text ();
		$self->fillComboBox('generationType',$edit3,\%GENERATION_TYPES);
		$self->connectSignal($edit3,'changed','onGenerationTypeChanged');
		$subtable->attach ($edit3, 
					1,2,4,5, # left, right, top and bottom columns
					['expand','fill'],'shrink', # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','GENERATION_TYPE') = $edit3;

		my $label5 = Gtk2::Label->new (_T("Type of MakeIndex style research:"));
		$subtable->attach ($label5, 
					0,1,5,6, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit4 = Gtk2::ComboBox->new_text ();
		$self->fillComboBox('makeindexStyleType',$edit4,\%MAKEINDEX_STYLE_TYPES);
		$self->connectSignal($edit4,'changed','onMakeIndexStyleChanged');
		$subtable->attach ($edit4, 
					1,2,5,6, # left, right, top and bottom columns
					['expand','fill'],'shrink', # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','MAKEINDEX_STYLE') = $edit4;
	}

	# VIEWER part
	{
		my $viewerFrame = Gtk2::Frame->new(_T("Viewer"));
		$self->attach ($viewerFrame, 
					0,1,1,2, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					5,2); # horizontal and vertical paddings
		my $subtable = Gtk2::Table->new (
						2, #rows
						2, #columns
						FALSE); #non uniform
		$viewerFrame->add ($subtable);

		my $label1 = Gtk2::CheckButton->new (_T("Launch a viewer after compilation"));
		$self->connectSignal($label1,'toggled','onLaunchViewerToggled');
		$subtable->attach ($label1, 
					0,2,0,1, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','LAUNCH_VIEWER') = $label1;

		my $label2 = Gtk2::Label->new (_T("Command of the viewer (optional):"));
		$subtable->attach ($label2, 
					0,1,1,2, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('LABELS','VIEWER_PATH') = $label2;

		my $edit1 = Gtk2::Entry->new ();
		$self->connectSignal($edit1,'changed','onPDFViewerChanged');
		$subtable->attach ($edit1, 
					1,2,1,2, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','VIEWER_PATH') = $edit1;
	}

	# CLEAN part
	{
		my $cleaningFrame = Gtk2::Frame->new(_T("Cleaning"));
		$self->attach ($cleaningFrame, 
					0,1,2,3, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					5,2); # horizontal and vertical paddings
		my $subtable = Gtk2::Table->new (
						2, #rows
						2, #columns
						FALSE); #non uniform
		$cleaningFrame->add ($subtable);

		my $label1 = Gtk2::Label->new (_T("Files to clean:"));
		$subtable->attach ($label1, 
					0,1,0,1, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit1 = Gtk2::Entry->new ();
		$self->connectSignal($edit1,'changed','onFilesToCleanChanged');
		$subtable->attach ($edit1, 
					1,2,0,1, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','FILES_TO_CLEAN') = $edit1;

		my $label2 = Gtk2::Label->new (_T("Files to desintegrate:"));
		$subtable->attach ($label2, 
					0,1,1,2, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit2 = Gtk2::Entry->new ();
		$self->connectSignal($edit2,'changed','onFilesToDesintegrateChanged');
		$subtable->attach ($edit2, 
					1,2,1,2, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','FILES_TO_DESINTEGRATE') = $edit2;
	}

	# SCM part
	{
		my $scmFrame = Gtk2::Frame->new(_T("SCM support"));
		$self->attach ($scmFrame, 
					0,1,3,4, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					5,2); # horizontal and vertical paddings
		my $subtable = Gtk2::Table->new (
						2, #rows
						2, #columns
						FALSE); #non uniform
		$scmFrame->add ($subtable);

		my $label1 = Gtk2::Label->new (_T("Update command line:"));
		$subtable->attach ($label1, 
					0,1,0,1, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit1 = Gtk2::Entry->new ();
		$self->connectSignal($edit1,'changed','onSCMUpdateChanged');
		$subtable->attach ($edit1, 
					1,2,0,1, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','SCM_UPDATE') = $edit1;

		my $label2 = Gtk2::Label->new (_T("Commit command line:"));
		$subtable->attach ($label2, 
					0,1,1,2, # left, right, top and bottom columns
					'shrink','shrink', # x and y options
					2,2); # horizontal and vertical paddings

		my $edit2 = Gtk2::Entry->new ();
		$self->connectSignal($edit2,'changed','onSCMCommitChanged');
		$subtable->attach ($edit2, 
					1,2,1,2, # left, right, top and bottom columns
					['expand','fill'],['expand','fill'], # x and y options
					2,2); # horizontal and vertical paddings
		$self->attr('EDITORS','SCM_COMMIT') = $edit2;
	}
}

=pod

=item * initializeGeneralPanel()

Initializing the panel content before displaying.

=cut
sub initializeGeneralPanel() : method {
	my $self = shift;
	$self->SUPER::initializeGeneralPanel();

	unless (%GENERATION_TYPES) {
		$GENERATION_TYPES{'01_'._T('Generate PDF document')} = 'pdf';
		$GENERATION_TYPES{'02_'._T('Generate DVI document')} = 'dvi';
		$GENERATION_TYPES{'03_'._T('Generate Postscript document')} = 'ps';
		$GENERATION_TYPES{'04_'._T('Generate PDF document via Postscript')} = 'pspdf';
	}

	unless (%MAKEINDEX_STYLE_TYPES) {
		$MAKEINDEX_STYLE_TYPES{'01_'._T('Use current configuration file value')} = '';
		$MAKEINDEX_STYLE_TYPES{'02_'._T('Auto-detect the style inside the project directory')} = '@detect';
		$MAKEINDEX_STYLE_TYPES{'03_'._T('Use only the default AutoLaTeX style')} = '@system';
		$MAKEINDEX_STYLE_TYPES{'04_'._T('No style is passed to MakeIndex')} = '@none';
	}

	$self->initControls();

	# Fill fields
	$self->attr('EDITORS','MAIN_TEX_FILE')->set_text ($self->attr('configuration','generation.main file'))
		if ($self->hasattr('configuration','generation.main file'));
	if ($self->hasattr('configuration','generation.generate images')) {
		$self->attr('EDITORS','AUTO_PICTURE_GENERATION')->set_active ($self->cfgGtkBoolean($self->attr('configuration','generation.generate images')));
	}
	else {
		$self->attr('EDITORS','AUTO_PICTURE_GENERATION')->set_active (TRUE);
	}
	if ($self->hasattr('configuration','generation.biblio')) {
		$self->attr('EDITORS','ENABLE_BIBLIO')->set_active ($self->cfgGtkBoolean($self->attr('configuration','generation.biblio')));
	}
	else {
		$self->attr('EDITORS','ENABLE_BIBLIO')->set_active (TRUE);
	}
	if ($self->hasattr('configuration','generation.image directory')) {
		$self->attr('EDITORS','AUTO_GENERATE_IMAGE_DIRECTORY')->set_text ($self->attr('configuration','generation.image directory'));
	}
	else {
		$self->attr('EDITORS','AUTO_GENERATE_IMAGE_DIRECTORY')->set_text ('.');
	}
	if ($self->hasattr('configuration','generation.generation type')) {
		my $val = $self->attr('configuration','generation.generation type') || '';
		if ($val eq 'pspdf') {
			$self->attr('EDITORS','GENERATION_TYPE')->set_active (3);
		}
		elsif ($val eq 'ps') {
			$self->attr('EDITORS','GENERATION_TYPE')->set_active (2);
		}
		elsif ($val eq 'dvi') {
			$self->attr('EDITORS','GENERATION_TYPE')->set_active (1);
		}
		else {
			$self->attr('EDITORS','GENERATION_TYPE')->set_active (0);
		}
	}
	else {
		$self->attr('EDITORS','GENERATION_TYPE')->set_active (0);
	}
	if ($self->hasattr('configuration','generation.makeindex style')) {
		my $val = $self->attr('configuration','generation.makeindex style') || '';
		if (isArray($val)) {
			if (@{$val} == 1) {
				$val = $val->[0];
			}
			else {
				$val = '';
			}
		}
		if ($val eq '@none') {
			$self->attr('EDITORS','MAKEINDEX_STYLE')->set_active (3);
		}
		elsif ($val eq '@system') {
			$self->attr('EDITORS','MAKEINDEX_STYLE')->set_active (2);
		}
		elsif ($val eq '@detect') {
			$self->attr('EDITORS','MAKEINDEX_STYLE')->set_active (1);
		}
		else {
			$self->attr('EDITORS','MAKEINDEX_STYLE')->set_active (0);
		}		
	}
	else {
		$self->attr('EDITORS','MAKEINDEX_STYLE')->set_active (0);
	}
	if ($self->hasattr('configuration','viewer.view')) {
		$self->attr('EDITORS','LAUNCH_VIEWER')->set_active ($self->cfgGtkBoolean($self->attr('configuration','viewer.view')));
	}
	else {
		$self->attr('EDITORS','LAUNCH_VIEWER')->set_active (TRUE);
	}
	$self->attr('EDITORS','VIEWER_PATH')->set_text ($self->attr('configuration','viewer.viewer'))
		if ($self->hasattr('configuration','viewer.viewer'));
	$self->attr('EDITORS','FILES_TO_CLEAN')->set_text ($self->attr('configuration','clean.files to clean'))
		if ($self->hasattr('configuration','clean.files to clean'));
	$self->attr('EDITORS','FILES_TO_DESINTEGRATE')->set_text ($self->attr('configuration','clean.files to desintegrate'))
		if ($self->hasattr('configuration','clean.files to desintegrate'));
	$self->attr('EDITORS','SCM_UPDATE')->set_text ($self->attr('configuration','scm.scm update'))
		if ($self->hasattr('configuration','scm.scm update'));
	$self->attr('EDITORS','SCM_COMMIT')->set_text ($self->attr('configuration','scm.scm commit'))
		if ($self->hasattr('configuration','scm.scm commit'));
}

#
#------------------------------------- SIGNALS
#

sub onLaunchViewerToggled(@) {
	my $self = shift;

	$self->attr('configuration','viewer.view') = $self->cfgToGtkBoolean($_[0]->get_active ());

	$self->attr('LABELS','VIEWER_PATH')->set_sensitive ($_[0]->get_active ());
	$self->attr('EDITORS','VIEWER_PATH')->set_sensitive ($_[0]->get_active ());
}

sub onGenerateImageToggled(@) {
	my $self = shift;
	$self->attr('configuration','generation.generate images') = $self->cfgToGtkBoolean($_[0]->get_active ());
}

sub onRunBiblioToggled(@) {
	my $self = shift;
	$self->attr('configuration','generation.biblio') = $self->cfgToGtkBoolean($_[0]->get_active ());
}

sub onMainTeXFileChanged(@) {
	my $self = shift;
	$self->attr('configuration','generation.main file') = $_[0]->get_text ();
}

sub onImageSearchDirectoryChanged(@) {
	my $self = shift;
	$self->attr('configuration','generation.image directory') = $_[0]->get_text ();
}

sub onPDFViewerChanged(@) {
	my $self = shift;
	$self->attr('configuration','viewer.viewer') = $_[0]->get_text ();
}

sub onFilesToCleanChanged(@) {
	my $self = shift;
	$self->attr('configuration','clean.files to clean') = $_[0]->get_text ();
}

sub onFilesToDesintegrateChanged(@) {
	my $self = shift;
	$self->attr('configuration','clean.files to desintegrate') = $_[0]->get_text ();
}

sub onSCMUpdateChanged(@) {
	my $self = shift;
	$self->attr('configuration','scm.scm update') = $_[0]->get_text ();
}

sub onSCMCommitChanged(@) {
	my $self = shift;
	$self->attr('configuration','scm.scm commit') = $_[0]->get_text ();
}

sub onGenerationTypeChanged(@) {
	my $self = shift;
	my $value = $self->getComboBoxValue($_[0]);
	$self->attr('configuration','generation.generation type') = $value || 'pdf';
}

sub onMakeIndexStyleChanged(@) {
	my $self = shift;
	my $value = $self->getComboBoxValue($_[0]);
	if ($value) {
		$self->attr('configuration','generation.makeindex style') = $value;
	}
	else {
		$self->deleteattr('configuration','generation.makeindex style');
	}
}

1;
__END__

=back

=head1 COPYRIGHT

(c) Copyright 2007-13 Stephane Galland E<lt>galland@arakhne.orgE<gt>, under GPL.

=head1 AUTHORS

=over

=item *

Conceived and initially developed by Stéphane Galland E<lt>galland@arakhne.orgE<gt>.

=back

=head1 SEE ALSO

L<autolatex>