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

« back to all changes in this revision

Viewing changes to lib/Padre/Wx/Dialog/KeyBindings.pm

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont, gregor herrmann, Dominique Dumont
  • Date: 2012-01-04 12:04:20 UTC
  • mfrom: (1.3.3)
  • Revision ID: package-import@ubuntu.com-20120104120420-i5oybqwf91m1d3il
Tags: 0.92.ds1-1
[ gregor herrmann ]
* Remove debian/source/local-options; abort-on-upstream-changes
  and unapply-patches are default in dpkg-source since 1.16.1.
* Swap order of alternative (build) dependencies after the perl
  5.14 transition.

[ Dominique Dumont ]
* Imported Upstream version 0.92.ds1
* removed fix-spelling patch (applied upstream)
* lintian-override: use wildcard to avoid listing a gazillion files
* updated size of some 'not-real-man-page' entries
* rules: remove dekstop cruft (replaced by a file provided in debian
  directory)
* control: removed Breaks statement. Add /me to uploaders. Updated
  dependencies
* rules: make sure that non-DFSG file (i.e. the cute butterfly, sigh)
  is not distributed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package Padre::Wx::Dialog::KeyBindings;
2
 
 
3
 
use 5.008;
4
 
use strict;
5
 
use warnings;
6
 
use Padre::Constant         ();
7
 
use Padre::Config           ();
8
 
use Padre::Util             ('_T');
9
 
use Padre::Wx               ();
10
 
use Padre::Wx::Role::Main   ();
11
 
use Padre::Wx::Role::Dialog ();
12
 
 
13
 
our $VERSION = '0.90';
14
 
our @ISA     = qw{
15
 
        Padre::Wx::Role::Main
16
 
        Padre::Wx::Role::Dialog
17
 
        Wx::Dialog
18
 
};
19
 
 
20
 
# Creates the key bindings dialog and returns the instance
21
 
sub new {
22
 
        my $class = shift;
23
 
        my $main  = shift;
24
 
 
25
 
        # Create the Wx dialog
26
 
        my $self = $class->SUPER::new(
27
 
                $main,
28
 
                -1,
29
 
                Wx::gettext('Key Bindings'),
30
 
                Wx::wxDefaultPosition,
31
 
                Wx::wxDefaultSize,
32
 
                Wx::wxDEFAULT_FRAME_STYLE,
33
 
        );
34
 
 
35
 
        # Set some internal parameters
36
 
        $self->{sortcolumn}  = 0;
37
 
        $self->{sortreverse} = 0;
38
 
 
39
 
        # Minimum dialog size
40
 
        $self->SetMinSize( [ 770, 550 ] );
41
 
 
42
 
        # Create sizer that will host all controls
43
 
        my $sizer = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
44
 
 
45
 
        # Create the controls
46
 
        $self->_create_controls($sizer);
47
 
 
48
 
        # Bind the control events
49
 
        $self->_bind_events;
50
 
 
51
 
        # Wrap everything in a vbox to add some padding
52
 
        $self->SetSizer($sizer);
53
 
        $self->Fit;
54
 
        $self->CentreOnParent;
55
 
 
56
 
        return $self;
57
 
}
58
 
 
59
 
# Create dialog controls
60
 
sub _create_controls {
61
 
        my ( $self, $sizer ) = @_;
62
 
 
63
 
        # Filter label
64
 
        my $filter_label = Wx::StaticText->new( $self, -1, Wx::gettext('&Filter:') );
65
 
 
66
 
        # Filter text field
67
 
        $self->{filter} = Wx::TextCtrl->new( $self, -1, '' );
68
 
 
69
 
        # Filtered key bindings list
70
 
        $self->{list} = Wx::ListView->new(
71
 
                $self,
72
 
                -1,
73
 
                Wx::wxDefaultPosition,
74
 
                Wx::wxDefaultSize,
75
 
                Wx::wxLC_REPORT | Wx::wxLC_SINGLE_SEL,
76
 
        );
77
 
        my @titles = qw(Action Description Shortcut);
78
 
        foreach my $i ( 0 .. 2 ) {
79
 
                $self->{list}->InsertColumn( $i, Wx::gettext( $titles[$i] ) );
80
 
                $self->{list}->SetColumnWidth( $i, Wx::wxLIST_AUTOSIZE );
81
 
        }
82
 
 
83
 
        # TODO add tooltip with the comments
84
 
 
85
 
        # Shortcut label
86
 
        my $shortcut_label = Wx::StaticText->new( $self, -1, Wx::gettext('Sh&ortcut:') );
87
 
 
88
 
        # modifier radio button fields
89
 
        $self->{ctrl}  = Wx::CheckBox->new( $self, -1, Wx::gettext('Ctrl') );
90
 
        $self->{alt}   = Wx::CheckBox->new( $self, -1, Wx::gettext('Alt') );
91
 
        $self->{shift} = Wx::CheckBox->new( $self, -1, Wx::gettext('Shift') );
92
 
 
93
 
        # + labels
94
 
        my $plus_label_1 = Wx::StaticText->new( $self, -1, '+' );
95
 
        my $plus_label_2 = Wx::StaticText->new( $self, -1, '+' );
96
 
 
97
 
        # key choice list
98
 
        my @keys = (
99
 
                _T('None'),   _T('Backspace'), _T('Tab'),    _T('Space'),  _T('Up'),   _T('Down'),
100
 
                _T('Left'),   _T('Right'),     _T('Insert'), _T('Delete'), _T('Home'), _T('End'),
101
 
                _T('PageUp'), _T('PageDown'),  _T('Enter'),  _T('Escape'),
102
 
                'F1',       'F2',       'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12',
103
 
                'A' .. 'Z', '0' .. '9', '~',  '-',  '=',  '[',  ']',  ';',  '\'', ',',   '.',   '/'
104
 
        );
105
 
        $self->{keys} = \@keys;
106
 
 
107
 
        my @translated_keys = map { Wx::gettext($_) } @keys;
108
 
        $self->{key} = Wx::Choice->new(
109
 
                $self, -1,
110
 
                Wx::wxDefaultPosition,
111
 
                Wx::wxDefaultSize,
112
 
                \@translated_keys,
113
 
        );
114
 
        $self->{key}->SetSelection(0);
115
 
 
116
 
        # TODO tooltips for all buttons
117
 
 
118
 
        # Set key binding button
119
 
        $self->{button_set} = Wx::Button->new(
120
 
                $self, -1, Wx::gettext('&Set'),
121
 
        );
122
 
        $self->{button_set}->Enable(1);
123
 
 
124
 
        # Delete button
125
 
        $self->{button_delete} = Wx::Button->new(
126
 
                $self, -1, Wx::gettext('&Delete'),
127
 
        );
128
 
        $self->{button_delete}->Enable(1);
129
 
 
130
 
        # Reset button
131
 
        $self->{button_reset} = Wx::Button->new(
132
 
                $self, -1, Wx::gettext('&Reset'),
133
 
        );
134
 
        $self->{button_reset}->SetToolTip( Wx::gettext('Reset to default shortcut') );
135
 
        $self->{button_reset}->Enable(1);
136
 
 
137
 
        # Close button
138
 
        $self->{button_close} = Wx::Button->new(
139
 
                $self, Wx::wxID_CANCEL, Wx::gettext('&Close'),
140
 
        );
141
 
 
142
 
        #
143
 
        #----- Dialog Layout -------
144
 
        #
145
 
 
146
 
        # Filter sizer
147
 
        my $filter_sizer = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
148
 
        $filter_sizer->Add( $filter_label,   0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
149
 
        $filter_sizer->Add( $self->{filter}, 1, Wx::wxALIGN_CENTER_VERTICAL, 5 );
150
 
 
151
 
        # Ctrl/Alt Modifier sizer
152
 
        my $modifier_sizer = Wx::BoxSizer->new(Wx::wxVERTICAL);
153
 
        $modifier_sizer->Add( $self->{ctrl}, 1, Wx::wxALIGN_CENTER_VERTICAL, 5 );
154
 
        $modifier_sizer->AddSpacer(3);
155
 
        $modifier_sizer->Add( $self->{alt}, 1, Wx::wxALIGN_CENTER_VERTICAL, 5 );
156
 
 
157
 
        # Value setter sizer
158
 
        my $value_sizer = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
159
 
        $value_sizer->Add( $shortcut_label, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
160
 
        $value_sizer->AddStretchSpacer;
161
 
        $value_sizer->Add( $modifier_sizer, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
162
 
        $value_sizer->AddSpacer(5);
163
 
        $value_sizer->Add( $plus_label_1, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
164
 
        $value_sizer->AddSpacer(5);
165
 
        $value_sizer->Add( $self->{shift}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
166
 
        $value_sizer->AddSpacer(5);
167
 
        $value_sizer->Add( $plus_label_2, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
168
 
        $value_sizer->AddSpacer(5);
169
 
        $value_sizer->Add( $self->{key}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
170
 
        $value_sizer->AddStretchSpacer;
171
 
        $value_sizer->Add( $self->{button_set},    0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
172
 
        $value_sizer->Add( $self->{button_delete}, 0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
173
 
        $value_sizer->Add( $self->{button_reset},  0, Wx::wxALIGN_CENTER_VERTICAL, 5 );
174
 
 
175
 
        # Button sizer
176
 
        my $button_sizer = Wx::BoxSizer->new(Wx::wxHORIZONTAL);
177
 
        $button_sizer->Add( $self->{button_close}, 1, Wx::wxLEFT, 5 );
178
 
        $button_sizer->AddSpacer(5);
179
 
 
180
 
        # Main vertical sizer
181
 
        my $vsizer = Wx::BoxSizer->new(Wx::wxVERTICAL);
182
 
        $vsizer->Add( $filter_sizer, 0, Wx::wxALL | Wx::wxEXPAND, 3 );
183
 
        $vsizer->Add( $self->{list}, 1, Wx::wxALL | Wx::wxEXPAND, 3 );
184
 
        $vsizer->Add( $value_sizer,  0, Wx::wxALL | Wx::wxEXPAND, 3 );
185
 
        $vsizer->AddSpacer(5);
186
 
        $vsizer->Add( $button_sizer, 0, Wx::wxALIGN_RIGHT, 5 );
187
 
        $vsizer->AddSpacer(5);
188
 
 
189
 
        # Hide value and info sizer at startup
190
 
        $vsizer->Show( 2, 0 );
191
 
        $vsizer->Show( 3, 0 );
192
 
 
193
 
        # Store vertical sizer reference for later usage
194
 
        $self->{vsizer} = $vsizer;
195
 
 
196
 
        # Wrap with a horizontal sizer to get left/right padding
197
 
        $sizer->Add( $vsizer, 1, Wx::wxALL | Wx::wxEXPAND, 5 );
198
 
 
199
 
        return;
200
 
}
201
 
 
202
 
# A Private method to binds events to controls
203
 
sub _bind_events {
204
 
        my $self = shift;
205
 
 
206
 
        # Set focus when Keypad Down or page down keys are pressed
207
 
        Wx::Event::EVT_CHAR(
208
 
                $self->{filter},
209
 
                sub {
210
 
                        $self->_on_char( $_[1] );
211
 
                }
212
 
        );
213
 
 
214
 
        # Update filter search results on each text change
215
 
        Wx::Event::EVT_TEXT(
216
 
                $self,
217
 
                $self->{filter},
218
 
                sub {
219
 
                        shift->_update_list;
220
 
                }
221
 
        );
222
 
 
223
 
        # When an item is selected, its values must be populated below
224
 
        Wx::Event::EVT_LIST_ITEM_SELECTED(
225
 
                $self,
226
 
                $self->{list},
227
 
                sub {
228
 
                        shift->_on_list_item_selected(@_);
229
 
                }
230
 
        );
231
 
 
232
 
        # When the title is clicked, sort the items
233
 
        Wx::Event::EVT_LIST_COL_CLICK(
234
 
                $self,
235
 
                $self->{list},
236
 
                sub {
237
 
                        shift->list_col_click(@_);
238
 
                },
239
 
        );
240
 
 
241
 
        # Set button
242
 
        Wx::Event::EVT_BUTTON(
243
 
                $self,
244
 
                $self->{button_set},
245
 
                sub {
246
 
                        shift->_on_set_button;
247
 
                }
248
 
        );
249
 
 
250
 
        # Delete button
251
 
        Wx::Event::EVT_BUTTON(
252
 
                $self,
253
 
                $self->{button_delete},
254
 
                sub {
255
 
                        shift->_on_delete_button;
256
 
                }
257
 
        );
258
 
 
259
 
        # Reset button
260
 
        Wx::Event::EVT_BUTTON(
261
 
                $self,
262
 
                $self->{button_reset},
263
 
                sub {
264
 
                        shift->_on_reset_button;
265
 
                }
266
 
        );
267
 
 
268
 
        # Close button
269
 
        Wx::Event::EVT_BUTTON(
270
 
                $self,
271
 
                $self->{button_close},
272
 
                sub {
273
 
                        shift->_on_close_button;
274
 
                }
275
 
        );
276
 
 
277
 
        return;
278
 
}
279
 
 
280
 
# Private method to handle on character pressed event
281
 
sub _on_char {
282
 
        my $self  = shift;
283
 
        my $event = shift;
284
 
        my $code  = $event->GetKeyCode;
285
 
 
286
 
        $self->{list}->SetFocus
287
 
                if ( $code == Wx::WXK_DOWN )
288
 
                or ( $code == Wx::WXK_NUMPAD_PAGEDOWN )
289
 
                or ( $code == Wx::WXK_PAGEDOWN );
290
 
 
291
 
        $event->Skip(1);
292
 
 
293
 
        return;
294
 
}
295
 
 
296
 
# Translates the shortcut to its native language
297
 
sub _translate_shortcut {
298
 
        my ($shortcut) = @_;
299
 
 
300
 
        my @parts = split /-/, $shortcut;
301
 
        my $regular_key = @parts ? $parts[-1] : '';
302
 
 
303
 
        return join '-', map { Wx::gettext($_) } @parts;
304
 
}
305
 
 
306
 
# Private method to handle the selection of a key binding item
307
 
sub _on_list_item_selected {
308
 
        my $self  = shift;
309
 
        my $event = shift;
310
 
 
311
 
        my $list        = $self->{list};
312
 
        my $index       = $list->GetFirstSelected;
313
 
        my $action_name = $list->GetItemText($index);
314
 
        my $action      = $self->ide->actions->{$action_name};
315
 
 
316
 
        my $shortcut = $self->ide->actions->{$action_name}->shortcut;
317
 
        $shortcut = '' if not defined $shortcut;
318
 
 
319
 
        $self->{button_reset}->Enable( $shortcut ne $self->config->default( $action->shortcut_setting ) );
320
 
 
321
 
        $self->{button_delete}->Enable( $shortcut ne '' );
322
 
 
323
 
        $self->_update_shortcut_ui($shortcut);
324
 
 
325
 
        return;
326
 
}
327
 
 
328
 
# Updates the shortcut UI
329
 
sub _update_shortcut_ui {
330
 
        my ( $self, $shortcut ) = @_;
331
 
 
332
 
        my @parts = split /-/, $shortcut;
333
 
        my $regular_key = @parts ? $parts[-1] : '';
334
 
 
335
 
        # Find the regular key index in the choice box
336
 
        my $regular_index = 0;
337
 
        my @keys          = @{ $self->{keys} };
338
 
        for ( my $i = 0; $i < scalar @keys; $i++ ) {
339
 
                if ( $regular_key eq $keys[$i] ) {
340
 
                        $regular_index = $i;
341
 
                        last;
342
 
                }
343
 
        }
344
 
 
345
 
        # and update the UI
346
 
        $self->{key}->SetSelection($regular_index);
347
 
        $self->{ctrl}->SetValue( $shortcut  =~ /Ctrl/  ? 1 : 0 );
348
 
        $self->{alt}->SetValue( $shortcut   =~ /Alt/   ? 1 : 0 );
349
 
        $self->{shift}->SetValue( $shortcut =~ /Shift/ ? 1 : 0 );
350
 
 
351
 
        # Make sure the value and info sizer are not hidden
352
 
        $self->{vsizer}->Show( 2, 1 );
353
 
        $self->{vsizer}->Show( 3, 1 );
354
 
        $self->{vsizer}->Layout;
355
 
 
356
 
        return;
357
 
}
358
 
 
359
 
# Private method to handle the pressing of the set value button
360
 
sub _on_set_button {
361
 
        my $self = shift;
362
 
 
363
 
        my $index       = $self->{list}->GetFirstSelected;
364
 
        my $action_name = $self->{list}->GetItemText($index);
365
 
 
366
 
        my @key_list = ();
367
 
        for my $regular_key ( 'Shift', 'Ctrl', 'Alt' ) {
368
 
                push @key_list, $regular_key if $self->{ lc $regular_key }->GetValue;
369
 
        }
370
 
        my $key_index   = $self->{key}->GetSelection;
371
 
        my $regular_key = $self->{keys}->[$key_index];
372
 
        push @key_list, $regular_key if not $regular_key eq 'None';
373
 
        my $shortcut = join '-', @key_list;
374
 
 
375
 
        $self->_try_to_set_binding( $action_name, $shortcut );
376
 
 
377
 
        return;
378
 
}
379
 
 
380
 
# Tries to set the binding and asks the user if he want to set the shortcut if has already be used elsewhere
381
 
sub _try_to_set_binding {
382
 
        my ( $self, $action_name, $shortcut ) = @_;
383
 
 
384
 
        my $other_action = $self->ide->shortcuts->{$shortcut};
385
 
        if ( defined $other_action && $other_action->name ne $action_name ) {
386
 
                my $answer = $self->yes_no(
387
 
                        sprintf(
388
 
                                Wx::gettext("The shortcut '%s' is already used by the action '%s'.\n"),
389
 
                                $shortcut, $other_action->label_text
390
 
                                )
391
 
                                . Wx::gettext('Do you want to override it with the selected action?'),
392
 
                        Wx::gettext('Override Shortcut')
393
 
                );
394
 
                if ($answer) {
395
 
                        $self->_set_binding( $other_action->name, '' );
396
 
                } else {
397
 
                        return;
398
 
                }
399
 
        }
400
 
 
401
 
        $self->_set_binding( $action_name, $shortcut );
402
 
 
403
 
        return;
404
 
}
405
 
 
406
 
# Sets the key binding in Padre's configuration
407
 
sub _set_binding {
408
 
        my ( $self, $action_name, $shortcut ) = @_;
409
 
 
410
 
        my $shortcuts = $self->ide->shortcuts;
411
 
        my $action    = $self->ide->actions->{$action_name};
412
 
 
413
 
        # modify shortcut registry
414
 
        my $old_shortcut = $action->shortcut;
415
 
        delete $shortcuts->{$old_shortcut} if defined $old_shortcut;
416
 
        $shortcuts->{$shortcut} = $action;
417
 
 
418
 
        # set the action's shortcut
419
 
        $action->shortcut( $shortcut eq '' ? undef : $shortcut );
420
 
 
421
 
        # modify the configuration database
422
 
        $self->config->set( $action->shortcut_setting, $shortcut );
423
 
        $self->config->write;
424
 
 
425
 
        # Update the action's UI
426
 
        my $non_default = $self->config->default( $action->shortcut_setting ) ne $shortcut;
427
 
        $self->_update_action_ui( $action_name, $shortcut, $non_default );
428
 
 
429
 
        return;
430
 
}
431
 
 
432
 
# Private method to update the UI from the provided preference
433
 
sub _update_action_ui {
434
 
 
435
 
        my ( $self, $action_name, $shortcut, $non_default ) = @_;
436
 
 
437
 
        my $list = $self->{list};
438
 
        my $index = $list->FindItem( -1, $action_name );
439
 
 
440
 
        $self->{button_reset}->Enable($non_default);
441
 
        $list->SetItem( $index, 2, _translate_shortcut($shortcut) );
442
 
        $self->_set_item_bold_font( $index, $non_default );
443
 
 
444
 
        $self->_update_shortcut_ui($shortcut);
445
 
 
446
 
        return;
447
 
}
448
 
 
449
 
# Private method to handle the pressing of the delete button
450
 
sub _on_delete_button {
451
 
        my $self = shift;
452
 
 
453
 
        # Prepare the key binding
454
 
        my $index       = $self->{list}->GetFirstSelected;
455
 
        my $action_name = $self->{list}->GetItemText($index);
456
 
 
457
 
        $self->_set_binding( $action_name, '' );
458
 
 
459
 
        return;
460
 
}
461
 
 
462
 
# Private method to handle the pressing of the reset button
463
 
sub _on_reset_button {
464
 
        my $self = shift;
465
 
 
466
 
        my $index       = $self->{list}->GetFirstSelected;
467
 
        my $action_name = $self->{list}->GetItemText($index);
468
 
        my $action      = $self->ide->actions->{$action_name};
469
 
 
470
 
        $self->_try_to_set_binding(
471
 
                $action_name,
472
 
                $self->config->default( $action->shortcut_setting )
473
 
        );
474
 
 
475
 
        return;
476
 
}
477
 
 
478
 
# Private method to handle the close action
479
 
sub _on_close_button {
480
 
        my $self = shift;
481
 
        my $main = $self->GetParent;
482
 
 
483
 
        # re-create menu to activate shortcuts
484
 
        delete $main->{menu};
485
 
        $main->{menu} = Padre::Wx::Menubar->new($main);
486
 
        $main->SetMenuBar( $main->menu->wx );
487
 
        $main->refresh;
488
 
 
489
 
        $self->EndModal(Wx::wxID_CLOSE);
490
 
        return;
491
 
}
492
 
 
493
 
# Private method to update the key bindings list view
494
 
sub _update_list {
495
 
        my $self   = shift;
496
 
        my $filter = quotemeta $self->{filter}->GetValue;
497
 
 
498
 
        # Clear list
499
 
        my $list = $self->{list};
500
 
        $list->DeleteAllItems;
501
 
 
502
 
        my $actions         = $self->ide->actions;
503
 
        my $real_color      = Wx::SystemSettings::GetColour(Wx::wxSYS_COLOUR_WINDOW);
504
 
        my $alternate_color = Wx::Colour->new(
505
 
                int( $real_color->Red * 0.9 ),
506
 
                int( $real_color->Green * 0.9 ),
507
 
                $real_color->Blue,
508
 
        );
509
 
        my $index = 0;
510
 
 
511
 
        my @action_names = sort { $a cmp $b } keys %$actions;
512
 
        if ( $self->{sortcolumn} == 1 ) {
513
 
 
514
 
                # Sort by Descreption
515
 
                @action_names = sort { $actions->{$a}->label_text cmp $actions->{$b}->label_text } keys %$actions;
516
 
        }
517
 
        if ( $self->{sortcolumn} == 2 ) {
518
 
 
519
 
                # Sort by Shortcut
520
 
                @action_names = sort {
521
 
                        _translate_shortcut( $actions->{$a}->shortcut || '' )
522
 
                                cmp _translate_shortcut( $actions->{$b}->shortcut || '' )
523
 
                } keys %$actions;
524
 
        }
525
 
        if ( $self->{sortreverse} ) {
526
 
                @action_names = reverse @action_names;
527
 
        }
528
 
 
529
 
        foreach my $action_name (@action_names) {
530
 
                my $action = $actions->{$action_name};
531
 
                my $shortcut = defined $action->shortcut ? $action->shortcut : '';
532
 
 
533
 
                # Ignore key binding if it does not match the filter
534
 
                next
535
 
                        if $action->label_text !~ /$filter/i
536
 
                                and $action_name !~ /$filter/i
537
 
                                and $shortcut !~ /$filter/i;
538
 
 
539
 
                # Add the key binding to the list control
540
 
                $list->InsertStringItem( $index, $action_name );
541
 
                $list->SetItem( $index, 1, $action->label_text );
542
 
                $list->SetItem( $index, 2, _translate_shortcut($shortcut) );
543
 
 
544
 
                # Non-default (i.e. overriden) shortcuts should have a bold font
545
 
                my $non_default = $self->config->default( $action->shortcut_setting ) ne $shortcut;
546
 
                $self->_set_item_bold_font( $index, $non_default );
547
 
 
548
 
                # Alternating table colors
549
 
                $list->SetItemBackgroundColour( $index, $alternate_color ) unless $index % 2;
550
 
                $index++;
551
 
        }
552
 
 
553
 
        return;
554
 
}
555
 
 
556
 
# Private method to set item to bold
557
 
# Somehow SetItemFont is not there... hence i had to write this long workaround
558
 
sub _set_item_bold_font {
559
 
        my ( $self, $index, $bold ) = @_;
560
 
 
561
 
        my $list = $self->{list};
562
 
        my $item = $list->GetItem($index);
563
 
        my $font = $item->GetFont;
564
 
        $font->SetWeight( $bold ? Wx::wxFONTWEIGHT_BOLD : Wx::wxFONTWEIGHT_NORMAL );
565
 
        $item->SetFont($font);
566
 
        $list->SetItem($item);
567
 
 
568
 
        return;
569
 
}
570
 
 
571
 
# Private method to resize list columns
572
 
sub _resize_columns {
573
 
        my $self = shift;
574
 
 
575
 
        # Resize all columns but the last to their biggest item width
576
 
        my $list = $self->{list};
577
 
        for ( 0 .. $list->GetColumnCount - 1 ) {
578
 
                $list->SetColumnWidth( $_, Wx::wxLIST_AUTOSIZE );
579
 
        }
580
 
 
581
 
        return;
582
 
}
583
 
 
584
 
sub list_col_click {
585
 
        my $self     = shift;
586
 
        my $event    = shift;
587
 
        my $column   = $event->GetColumn;
588
 
        my $prevcol  = $self->{sortcolumn};
589
 
        my $reversed = $self->{sortreverse};
590
 
        $reversed = $column == $prevcol ? !$reversed : 0;
591
 
        $self->{sortcolumn}  = $column;
592
 
        $self->{sortreverse} = $reversed;
593
 
        $self->_update_list;
594
 
        return;
595
 
}
596
 
 
597
 
# Shows the key binding dialog
598
 
sub show {
599
 
        my $self = shift;
600
 
 
601
 
        # Set focus on the filter text field
602
 
        $self->{filter}->SetFocus;
603
 
 
604
 
        # Update the preferences list
605
 
        $self->_update_list;
606
 
 
607
 
        # resize columns
608
 
        $self->_resize_columns;
609
 
 
610
 
        # If it is not shown, show the dialog
611
 
        $self->ShowModal;
612
 
 
613
 
        return;
614
 
}
615
 
 
616
 
1;
617
 
 
618
 
 
619
 
__END__
620
 
 
621
 
=pod
622
 
 
623
 
=head1 NAME
624
 
 
625
 
Padre::Wx::Dialog::KeyBindings - a dialog to show and configure key bindings
626
 
 
627
 
=head1 DESCRIPTION
628
 
 
629
 
This dialog lets the user search for an action and then configure a new
630
 
shortcut if needed
631
 
 
632
 
=head1 PUBLIC API
633
 
 
634
 
=head2 C<new>
635
 
 
636
 
  my $key_bindings = Padre::Wx::Dialog::KeyBindings->new($main);
637
 
 
638
 
Returns a new C<Padre::Wx::Dialog::KeyBindings> instance
639
 
 
640
 
=head2 C<show>
641
 
 
642
 
  $key_bindings->show($main);
643
 
 
644
 
Shows the dialog. Returns C<undef>.
645
 
 
646
 
=head1 COPYRIGHT & LICENSE
647
 
 
648
 
Copyright 2008-2011 The Padre development team as listed in Padre.pm.
649
 
 
650
 
This program is free software; you can redistribute
651
 
it and/or modify it under the same terms as Perl itself.
652
 
 
653
 
The full text of the license can be found in the
654
 
LICENSE file included with this module.
655
 
 
656
 
=cut
657
 
 
658
 
 
659
 
 
660
 
 
661
 
# Copyright 2008-2011 The Padre development team as listed in Padre.pm.
662
 
# LICENSE
663
 
# This program is free software; you can redistribute it and/or
664
 
# modify it under the same terms as Perl 5 itself.