This file is indexed.

/usr/lib/python2.7/dist-packages/notebook/static/notebook/js/actions.js is in python-notebook 5.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

// How to pick action names:
//
// * First pick a noun and a verb for the action. For example, if the action is "restart kernel," the verb is
//   "restart" and the noun is "kernel".
// * Omit terms like "selected" and "active" by default, so "delete-cell", rather than "delete-selected-cell".
//   Only provide a scope like "-all-" if it is other than the default "selected" or "active" scope.
// * If an action has a secondary action, separate the secondary action with "-and-", so
//   "restart-kernel-and-clear-output".
// * Don't ever use before/after as they have a temporal connotation that is confusing when used in a spatial
//   context.
// * Use above/below or previous/next to indicate spacial and sequential relationships.
// * For dialogs, use a verb that indicates what the dialog will accomplish, such as "confirm-restart-kernel".


define([
    'base/js/i18n',
    ], function(i18n){
    "use strict";

    var warn_bad_name = function(name){
        if(name !== "" && !name.match(/:/)){
            console.warn('You are trying to use an action/command name, where the separator between prefix and name is not `:`\n'+
                         '"'+name+'"\n'+
                         'You are likely to not use the API in a correct way. Typically use the following:\n'+
                         '`var key = actions.register(<object>, "<name>", "<prefix>");` and reuse the `key` variable'+
                         'instead of re-generating the key yourself.'
                    );
        }
    };

    var ActionHandler = function (env) {
        this.env = env || {};
        Object.seal(this);
    };

    var $ = require('jquery');
    var events =  require('base/js/events');

    /**
     *  A bunch of predefined `Simple Actions` used by Jupyter.
     *  `Simple Actions` have the following keys:
     *  help (optional): a short string the describe the action.
     *      will be used in various context, like as menu name, tool tips on buttons,
     *      and short description in help menu.
     *  help_index (optional): a string used to sort action in help menu.
     *  icon (optional): a short string that represent the icon that have to be used with this
     *  action. this should mainly correspond to a Font_awesome class.
     *  handler : a function which is called when the action is activated. It will receive at first parameter
     *      a dictionary containing various handle to element of the notebook.
     *
     *  action need to be registered with a **name** that can be use to refer to this action.
     *
     *  if `help` is not provided it will be derived by replacing any dash by space
     *  in the **name** of the action. It is advised to provide a prefix to action name to
     *  avoid conflict the prefix should be all lowercase and end with a dot `.`
     *  in the absence of a prefix the behavior of the action is undefined.
     *
     *  All action provided by the Jupyter notebook are prefixed with `jupyter-notebook:`.
     *
     *  One can register extra actions or replace an existing action with another one is possible
     *  but is considered undefined behavior.
     *
     **/
    var _actions = {
        'toggle-rtl-layout': {
            cmd: i18n.msg._('toggle rtl layout'),
            help: i18n.msg._('Toggle the screen directionality between left-to-right and right-to-left'),
            handler: function () {
              (document.body.getAttribute('dir')=='rtl') ? document.body.setAttribute('dir','ltr') : document.body.setAttribute('dir','rtl');
            }
        },
        'edit-command-mode-keyboard-shortcuts': {
            cmd: i18n.msg._('edit command mode keyboard shortcuts'),
            help: i18n.msg._('Open a dialog to edit the command mode keyboard shortcuts'),
            handler: function (env) {
                env.notebook.show_shortcuts_editor();
            }
        },
        'shutdown-kernel': {
            help: 'Shutdown the kernel (no confirmation dialog)',
            handler: function (env) {
                env.notebook.shutdown_kernel({confirm: false});
            }
        },
        'confirm-shutdown-kernel':{
            icon: 'fa-repeat',
            help_index : 'hb',
            help: 'Shutdown the kernel (with confirmation dialog)',
            handler : function (env) {
                env.notebook.shutdown_kernel();
            }
        },
        'restart-kernel': {
            cmd: i18n.msg._('restart kernel'),
            help: i18n.msg._('restart the kernel (no confirmation dialog)'),
            handler: function (env) {
                env.notebook.restart_kernel({confirm: false});
            },
        },
        'confirm-restart-kernel':{
            icon: 'fa-repeat',
            help_index : 'hb',
            cmd: i18n.msg._('confirm restart kernel'),
            help: i18n.msg._('restart the kernel (with dialog)'),
            handler : function (env) {
                env.notebook.restart_kernel();
            }
        },
        'restart-kernel-and-run-all-cells': {
            cmd: i18n.msg._('restart kernel and run all cells'),
            help: i18n.msg._('restart the kernel, then re-run the whole notebook (no confirmation dialog)'),
            handler: function (env) {
                env.notebook.restart_run_all({confirm: false});
            }
        },
        'confirm-restart-kernel-and-run-all-cells': {
            cmd: i18n.msg._('confirm restart kernel and run all cells'),
            help: i18n.msg._('restart the kernel, then re-run the whole notebook (with dialog)'),
            handler: function (env) {
                env.notebook.restart_run_all();
            }
        },
        'restart-kernel-and-clear-output': {
            cmd: i18n.msg._('restart kernel and clear output'),
            help: i18n.msg._('restart the kernel and clear all output (no confirmation dialog)'),
            handler: function (env) {
                env.notebook.restart_clear_output({confirm: false});
            }
        },
        'confirm-restart-kernel-and-clear-output': {
            cmd: i18n.msg._('confirm restart kernel and clear output'),
            help: i18n.msg._('restart the kernel and clear all output (with dialog)'),
            handler: function (env) {
                env.notebook.restart_clear_output();
            }
        },
        'interrupt-kernel':{
            icon: 'fa-stop',
            cmd: i18n.msg._('interrupt the kernel'),
            help: i18n.msg._('interrupt the kernel'),
            help_index : 'ha',
            handler : function (env) {
                env.notebook.kernel.interrupt();
            }
        },
        'run-cell-and-select-next': {
            cmd: i18n.msg._('run cell and select next'),
            icon: 'fa-step-forward',
            help: i18n.msg._('run cell, select below'),
            help_index : 'ba',
            handler : function (env) {
                env.notebook.execute_cell_and_select_below();
            }
        },
        'run-cell':{
            cmd: i18n.msg._('run selected cells'),
            help    : i18n.msg._('run selected cells'),
            help_index : 'bb',
            handler : function (env) {
                env.notebook.execute_selected_cells();
            }
        },
        'run-cell-and-insert-below':{
            cmd: i18n.msg._('run cell and insert below'),
            help    : i18n.msg._('run cell and insert below'),
            help_index : 'bc',
            handler : function (env) {
                env.notebook.execute_cell_and_insert_below();
            }
        },
        'run-all-cells': {
            cmd: i18n.msg._('run all cells'),
            help: i18n.msg._('run all cells'),
            help_index: 'bd',
            handler: function (env) {
                env.notebook.execute_all_cells();
            }
        },
        'run-all-cells-above':{
            cmd: i18n.msg._('run all cells above'),
            help: i18n.msg._('run all cells above'),
            handler : function (env) {
                env.notebook.execute_cells_above();
            }
        },
        'run-all-cells-below':{
            cmd: i18n.msg._('run all cells below'),
            help: i18n.msg._('run all cells below'),
            handler : function (env) {
                env.notebook.execute_cells_below();
            }
        },
        'enter-command-mode': {
            cmd: i18n.msg._('enter command mode'),
            help    : i18n.msg._('enter command mode'),
            help_index : 'aa',
            handler : function (env) {
                env.notebook.command_mode();
            }
        },
        'insert-image': {
            cmd: i18n.msg._('insert image'),
            help      : i18n.msg._('insert image'),
            help_index : 'dz',
            handler : function (env) {
                env.notebook.insert_image();
            }
        },
        'cut-cell-attachments': {
            cmd: i18n.msg._('cut cell attachments'),
            help    : i18n.msg._('cut cell attachments'),
            help_index : 'dza',
            handler: function (env) {
                env.notebook.cut_cell_attachments();
            }
        },
        'copy-cell-attachments': {
            cmd: i18n.msg._('copy cell attachments'),
            help    : i18n.msg._('copy cell attachments'),
            help_index: 'dzb',
            handler: function (env) {
                env.notebook.copy_cell_attachments();
            }
        },
        'paste-cell-attachments': {
            cmd: i18n.msg._('paste cell attachments'),
            help    : i18n.msg._('paste cell attachments'),
            help_index: 'dzc',
            handler: function (env) {
                env.notebook.paste_cell_attachments();
            }
        },
        'split-cell-at-cursor': {
            cmd: i18n.msg._('split cell at cursor'),
            help    : i18n.msg._('split cell at cursor'),
            help_index : 'ea',
            handler : function (env) {
                env.notebook.split_cell();
            }
        },
        'enter-edit-mode' : {
            cmd: i18n.msg._('enter edit mode'),
            help : i18n.msg._('enter edit mode'),
            help_index : 'aa',
            handler : function (env) {
                env.notebook.edit_mode();
            }
        },
        'select-previous-cell' : {
            cmd: i18n.msg._('select previous cell'),
            help: i18n.msg._('select cell above'),
            help_index : 'da',
            handler : function (env) {
                var index = env.notebook.get_selected_index();
                if (index !== 0 && index !== null) {
                    env.notebook.select_prev(true);
                    env.notebook.focus_cell();
                }
            }
        },
        'select-next-cell' : {
            cmd: i18n.msg._('select next cell'),
            help: i18n.msg._('select cell below'),
            help_index : 'db',
            handler : function (env) {
                var index = env.notebook.get_selected_index();
                if (index !== (env.notebook.ncells()-1) && index !== null) {
                    env.notebook.select_next(true);
                    env.notebook.focus_cell();
                }
            }
        },
        'extend-selection-above' : {
            cmd: i18n.msg._('extend selection above'),
            help: i18n.msg._('extend selected cells above'),
            help_index : 'dc',
            handler : function (env) {
                env.notebook.extend_selection_by(-1);
                // scroll into view,
                // do not call notebook.focus_cell(), or
                // all the selection get thrown away
                env.notebook.get_selected_cell().element.focus();
            }
        },
        'extend-selection-below' : {
            cmd: i18n.msg._('extend selection below'),
            help: i18n.msg._('extend selected cells below'),
            help_index : 'dd',
            handler : function (env) {
                env.notebook.extend_selection_by(1);
                // scroll into view,
                // do not call notebook.focus_cell(), or
                // all the selection get thrown away
                env.notebook.get_selected_cell().element.focus();
            }
        },
        'cut-cell' : {
            cmd: i18n.msg._('cut selected cells'),
            help: i18n.msg._('cut selected cells'),
            icon: 'fa-cut',
            help_index : 'ee',
            handler : function (env) {
                var index = env.notebook.get_selected_index();
                env.notebook.cut_cell();
                env.notebook.select(index);
            }
        },
        'copy-cell' : {
            cmd: i18n.msg._('copy selected cells'),
            help: i18n.msg._('copy selected cells'),
            icon: 'fa-copy',
            help_index : 'ef',
            handler : function (env) {
                env.notebook.copy_cell();
            }
        },
        'paste-cell-replace' : {
            help: 'paste cells replace',
            handler : function (env) {
                env.notebook.paste_cell_replace();
            }
        },
        'paste-cell-above' : {
            cmd: i18n.msg._('paste cells above'),
            help: i18n.msg._('paste cells above'),
            help_index : 'eg',
            handler : function (env) {
                env.notebook.paste_cell_above();
            }
        },
        'paste-cell-below' : {
            cmd: i18n.msg._('paste cells below'),
            help: i18n.msg._('paste cells below'),
            icon: 'fa-paste',
            help_index : 'eh',
            handler : function (env) {
                env.notebook.paste_cell_below();
            }
        },
        'insert-cell-above' : {
            cmd: i18n.msg._('insert cell above'),
            help: i18n.msg._('insert cell above'),
            help_index : 'ec',
            handler : function (env) {
                env.notebook.insert_cell_above();
                env.notebook.select_prev(true);
                env.notebook.focus_cell();
            }
        },
        'insert-cell-below' : {
            cmd: i18n.msg._('insert cell below'),
            help: i18n.msg._('insert cell below'),
            icon : 'fa-plus',
            help_index : 'ed',
            handler : function (env) {
                env.notebook.insert_cell_below();
                env.notebook.select_next(true);
                env.notebook.focus_cell();
            }
        },
        'change-cell-to-code' : {
            cmd: i18n.msg._('change cell to code'),
            help    : i18n.msg._('change cell to code'),
            help_index : 'ca',
            handler : function (env) {
                env.notebook.cells_to_code();
            }
        },
        'change-cell-to-markdown' : {
            cmd: i18n.msg._('change cell to markdown'),
            help    : i18n.msg._('change cell to markdown'),
            help_index : 'cb',
            handler : function (env) {
                env.notebook.cells_to_markdown();
            }
        },
        'change-cell-to-raw' : {
            cmd: i18n.msg._('change cell to raw'),
            help    : i18n.msg._('change cell to raw'),
            help_index : 'cc',
            handler : function (env) {
                env.notebook.cells_to_raw();
            }
        },
        'change-cell-to-heading-1' : {
            cmd: i18n.msg._('change cell to heading 1'),
            help    : i18n.msg._('change cell to heading 1'),
            help_index : 'cd',
            handler : function (env) {
                env.notebook.to_heading(undefined, 1);
            }
        },
        'change-cell-to-heading-2' : {
            cmd: i18n.msg._('change cell to heading 2'),
            help    : i18n.msg._('change cell to heading 2'),
            help_index : 'ce',
            handler : function (env) {
                env.notebook.to_heading(undefined, 2);
            }
        },
        'change-cell-to-heading-3' : {
            cmd: i18n.msg._('change cell to heading 3'),
            help    : i18n.msg._('change cell to heading 3'),
            help_index : 'cf',
            handler : function (env) {
                env.notebook.to_heading(undefined, 3);
            }
        },
        'change-cell-to-heading-4' : {
            cmd: i18n.msg._('change cell to heading 4'),
            help    : i18n.msg._('change cell to heading 4'),
            help_index : 'cg',
            handler : function (env) {
                env.notebook.to_heading(undefined, 4);
            }
        },
        'change-cell-to-heading-5' : {
            cmd: i18n.msg._('change cell to heading 5'),
            help    : i18n.msg._('change cell to heading 5'),
            help_index : 'ch',
            handler : function (env) {
                env.notebook.to_heading(undefined, 5);
            }
        },
        'change-cell-to-heading-6' : {
            cmd: i18n.msg._('change cell to heading 6'),
            help    : i18n.msg._('change cell to heading 6'),
            help_index : 'ci',
            handler : function (env) {
                env.notebook.to_heading(undefined, 6);
            }
        },
        'toggle-cell-output-collapsed' : {
            cmd: i18n.msg._('toggle cell output'),
            help    : i18n.msg._('toggle output of selected cells'),
            help_index : 'gb',
            handler : function (env) {
                env.notebook.toggle_cells_outputs();
            }
        },
        'toggle-cell-output-scrolled' : {
            cmd: i18n.msg._('toggle cell scrolling'),
            help    : i18n.msg._('toggle output scrolling of selected cells'),
            help_index : 'gc',
            handler : function (env) {
                env.notebook.toggle_cells_outputs_scroll();
            }
        },
        'clear-cell-output' : {
            cmd: i18n.msg._('clear cell output'),
            help    : i18n.msg._('clear output of selected cells'),
            handler : function (env) {
                env.notebook.clear_cells_outputs();
            }
        },
        'move-cell-down' : {
            cmd: i18n.msg._('move cells down'),
            help: i18n.msg._('move selected cells down'),
            icon: 'fa-arrow-down',
            help_index : 'eb',
            handler : function (env) {
                env.notebook.move_cell_down();
            }
        },
        'move-cell-up' : {
            cmd: i18n.msg._('move cells up'),
            help: i18n.msg._('move selected cells up'),
            icon: 'fa-arrow-up',
            help_index : 'ea',
            handler : function (env) {
                env.notebook.move_cell_up();
            }
        },
        'toggle-cell-line-numbers' : {
            cmd: i18n.msg._('toggle line numbers'),
            help    : i18n.msg._('toggle line numbers'),
            help_index : 'ga',
            handler : function (env) {
                env.notebook.cell_toggle_line_numbers();
            }
        },
        'show-keyboard-shortcuts' : {
            cmd: i18n.msg._('show keyboard shortcuts'),
            help    : i18n.msg._('show keyboard shortcuts'),
            help_index : 'ge',
            handler : function (env) {
                env.quick_help.show_keyboard_shortcuts();
            }
        },
        'delete-cell': {
            cmd: i18n.msg._('delete cells'),
            help: i18n.msg._('delete selected cells'),
            help_index : 'ej',
            handler : function (env) {
                env.notebook.delete_cell();
            }
        },
        'undo-cell-deletion' : {
            cmd: i18n.msg._('undo cell deletion'),
            help: i18n.msg._('undo cell deletion'),
            help_index : 'ei',
            handler : function (env) {
                env.notebook.undelete_cell();
            }
        },
        // TODO reminder
        // open an issue, merge with above merge with last cell of notebook if at top.
        'merge-cell-with-previous-cell' : {
            cmd: i18n.msg._('merge cell with previous cell'),
            help    : i18n.msg._('merge cell above'),
            handler : function (env) {
                env.notebook.merge_cell_above();
            }
        },
        'merge-cell-with-next-cell' : {
            cmd: i18n.msg._('merge cell with next cell'),
            help    : i18n.msg._('merge cell below'),
            help_index : 'ek',
            handler : function (env) {
                env.notebook.merge_cell_below();
            }
        },
        'merge-selected-cells' : {
            cmd: i18n.msg._('merge selected cells'),
            help : i18n.msg._('merge selected cells'),
            help_index: 'el',
            handler: function(env) {
                env.notebook.merge_selected_cells();
            }
        },
        'merge-cells' : {
            cmd: i18n.msg._('merge cells'),
            help : i18n.msg._('merge selected cells, or current cell with cell below if only one cell is selected'),
            help_index: 'el',
            handler: function(env) {
                var l = env.notebook.get_selected_cells_indices().length;
                if(l == 1){
                    env.notebook.merge_cell_below();
                } else {
                    env.notebook.merge_selected_cells();
                }
            }
        },
        'show-command-palette': {
            help_index : 'aa',
            cmd: i18n.msg._('show command pallette'),
            help: i18n.msg._('open the command palette'),
            icon: 'fa-keyboard-o',
            handler : function(env){
                env.notebook.show_command_palette();
            }
        },
        'toggle-all-line-numbers': {
            cmd: i18n.msg._('toggle all line numbers'),
            help : i18n.msg._('toggles line numbers in all cells, and persist the setting'),
            icon: 'fa-list-ol',
            handler: function(env) {
                var value = !env.notebook.line_numbers;
                env.notebook.get_cells().map(function(c) {
                    c.code_mirror.setOption('lineNumbers', value);
                });
                env.notebook.line_numbers = value;
            }
        },
        'show-all-line-numbers': {
            cmd: i18n.msg._('show all line numbers'),
            help : i18n.msg._('show line numbers in all cells, and persist the setting'),
            handler: function(env) {
                env.notebook.get_cells().map(function(c) {
                    c.code_mirror.setOption('lineNumbers', true);
                });
                env.notebook.line_numbers = true;
            }
        },
        'hide-all-line-numbers': {
            cmd: i18n.msg._('hide all line numbers'),
            help : i18n.msg._('hide line numbers in all cells, and persist the setting'),
            handler: function(env) {
                env.notebook.get_cells().map(function(c) {
                    c.code_mirror.setOption('lineNumbers', false);
                });
                env.notebook.line_numbers = false;
            }
        },
        'toggle-header':{
            cmd: i18n.msg._('toggle header'),
            help: i18n.msg._('switch between showing and hiding the header'),
            handler : function(env) {
                var value = !env.notebook.header;
                if (value === true) {
                    $('#header-container').show();
                    $('.header-bar').show();
                } else if (value === false) {
                    $('#header-container').hide();
                    $('.header-bar').hide();
                }
                events.trigger('resize-header.Page');
                env.notebook.header = value;
            }
        },
        'show-header':{
            cmd: i18n.msg._('show the header'),
            help: i18n.msg._('show the header'),
            handler : function(env) {
                $('#header-container').show();
                $('.header-bar').show();
                events.trigger('resize-header.Page');
                env.notebook.header = true;
            }
        },
        'hide-header':{
            cmd: i18n.msg._('hide the header'),
            help: i18n.msg._('hide the header'),
            handler : function(env) {
                $('#header-container').hide();
                $('.header-bar').hide();
                events.trigger('resize-header.Page');
                env.notebook.header = false;
            }
        },
        'toggle-menubar':{
            help: 'hide/show the menu bar',
            handler : function(env) {
                $('#menubar-container').toggle();
                events.trigger('resize-header.Page');
            }
        },
        'show-menubar':{
            help: 'show the menu bar',
            handler : function(env) {
                $('#menubar-container').show();
                events.trigger('resize-header.Page');
            }
        },
        'hide-menubar':{
            help: 'hide the menu bar',
            handler : function(env) {
                $('#menubar-container').hide();
                events.trigger('resize-header.Page');
            }
        },
        'toggle-toolbar':{
            cmd: i18n.msg._('toggle toolbar'),
            help: i18n.msg._('switch between showing and hiding the toolbar'),
            handler : function(env) {
                var value = !env.notebook.toolbar;
                if (value === true) {
                    $('div#maintoolbar').show();
                } else if (value === false) {
                    $('div#maintoolbar').hide();
                }
                events.trigger('resize-header.Page');
                env.notebook.toolbar = value;
            }
        },
        'show-toolbar':{
            cmd: i18n.msg._('show the toolbar'),
            help: i18n.msg._('show the toolbar'),
            handler : function(env) {
                $('div#maintoolbar').show();
                events.trigger('resize-header.Page');
                env.notebook.toolbar = true;
            }
        },
        'hide-toolbar':{
            cmd: i18n.msg._('hide the toolbar'),
            help: i18n.msg._('hide the toolbar'),
            handler : function(env) {
                $('div#maintoolbar').hide();
                events.trigger('resize-header.Page');
                env.notebook.toolbar = false;
            }
        },
        'close-pager': {
            cmd: i18n.msg._('close the pager'),
            help : i18n.msg._('close the pager'),
            handler : function(env) {
                // Collapse the page if it is open
                if (env.pager && env.pager.expanded) {
                    env.pager.collapse();
                }
            }
        },
    };

    /**
     * A bunch of `Advance actions` for Jupyter.
     * Cf `Simple Action` plus the following properties.
     *
     * handler: first argument of the handler is the event that triggerd the action
     *      (typically keypress). The handler is responsible for any modification of the
     *      event and event propagation.
     *      Is also responsible for returning false if the event have to be further ignored,
     *      true, to tell keyboard manager that it ignored the event.
     *
     *      the second parameter of the handler is the environemnt passed to Simple Actions
     *
     **/
    var custom_ignore = {
        'ignore':{
            cmd: i18n.msg._('ignore'),
            handler : function () {
                return true;
            }
        },
        'move-cursor-up':{
            cmd: i18n.msg._('move cursor up'),
            help: i18n.msg._("move cursor up"),
            handler : function (env, event) {
                var index = env.notebook.get_selected_index();
                var cell = env.notebook.get_cell(index);
                var cm = env.notebook.get_selected_cell().code_mirror;
                var cur = cm.getCursor();
                if (cell && cell.at_top() && index !== 0 && cur.ch === 0) {
                    if(event){
                        event.preventDefault();
                    }
                    env.notebook.command_mode();
                    env.notebook.select_prev(true);
                    env.notebook.edit_mode();
                    cm = env.notebook.get_selected_cell().code_mirror;
                    cm.setCursor(cm.lastLine(), 0);
                }
                return false;
            }
        },
        'move-cursor-down':{
            cmd: i18n.msg._('move cursor down'),
            help: i18n.msg._("move cursor down"),
            handler : function (env, event) {
                var index = env.notebook.get_selected_index();
                var cell = env.notebook.get_cell(index);
                if (cell.at_bottom() && index !== (env.notebook.ncells()-1)) {
                    if(event){
                        event.preventDefault();
                    }
                    env.notebook.command_mode();
                    env.notebook.select_next(true);
                    env.notebook.edit_mode();
                    var cm = env.notebook.get_selected_cell().code_mirror;
                    cm.setCursor(0, 0);
                }
                return false;
            }
        },
        'scroll-notebook-down': {
            cmd: i18n.msg._('scroll notebook down'),
            help: i18n.msg._("scroll notebook down"),
            handler: function(env, event) {
                if(event){
                    event.preventDefault();
                }
                return env.notebook.scroll_manager.scroll(1);
            },
        },
        'scroll-notebook-up': {
            cmd: i18n.msg._('scroll notebook up'),
            help: i18n.msg._("scroll notebook up"),
            handler: function(env, event) {
                if(event){
                    event.preventDefault();
                }
                return env.notebook.scroll_manager.scroll(-1);
            },
        },
        'scroll-cell-center': {
            cmd: i18n.msg._('scroll cell center'),
            help: i18n.msg._("Scroll the current cell to the center"),
            handler: function (env, event) {
                if(event){
                    event.preventDefault();
                }
                var cell = env.notebook.get_selected_index();
                return env.notebook.scroll_cell_percent(cell, 50, 0);
            }
        },
        'scroll-cell-top': {
            cmd: i18n.msg._('scroll cell top'),
            help: i18n.msg._("Scroll the current cell to the top"),
            handler: function (env, event) {
                if(event){
                    event.preventDefault();
                }
                var cell = env.notebook.get_selected_index();
                return env.notebook.scroll_cell_percent(cell, 0, 0);
            }
        },
        'duplicate-notebook':{
            cmd: i18n.msg._('duplicate notebook'),
            help: i18n.msg._("Create and open a copy of the current notebook"),
            handler : function (env, event) {
                env.notebook.copy_notebook();
            }
        },
        'trust-notebook':{
            cmd: i18n.msg._('trust notebook'),
            help: i18n.msg._("Trust the current notebook"),
            handler : function (env, event) {
                env.notebook.trust_notebook();
            }
        },
        'rename-notebook':{
            cmd: i18n.msg._('rename notebook'),
            help: i18n.msg._("Rename the current notebook"),
            handler : function (env, event) {
                env.notebook.save_widget.rename_notebook({notebook: env.notebook});
            }
        },
        'toggle-all-cells-output-collapsed':{
            cmd: i18n.msg._('toggle all cells output collapsed'),
            help: i18n.msg._("Toggle the hidden state of all output areas"),
            handler : function (env, event) {
                env.notebook.toggle_all_output();
            }
        },
        'toggle-all-cells-output-scrolled':{
            cmd: i18n.msg._('toggle all cells output scrolled'),
            help: i18n.msg._("Toggle the scrolling state of all output areas"),
            handler : function (env, event) {
                env.notebook.toggle_all_output_scroll();
            }
        },

        'clear-all-cells-output':{
            cmd: i18n.msg._('clear all cells output'),
            help: i18n.msg._("Clear the content of all the outputs"),
            handler : function (env, event) {
                env.notebook.clear_all_output();
            }
        },
        'save-notebook':{
            cmd: i18n.msg._('save notebook'),
            help: i18n.msg._("Save and Checkpoint"),
            help_index : 'fb',
            icon: 'fa-save',
            handler : function (env, event) {
                env.notebook.save_checkpoint();
                if(event){
                    event.preventDefault();
                }
                return false;
            }
        },
    };

    // private stuff that prepend `jupyter-notebook:` to actions names
    // and uniformize/fill in missing pieces in of an action.
    var _prepare_handler = function(registry, subkey, source){
        registry['jupyter-notebook:'+subkey] = {};
        registry['jupyter-notebook:'+subkey].cmd = source[subkey].cmd;
        registry['jupyter-notebook:'+subkey].help = source[subkey].help||subkey.replace(/-/g,' ');
        registry['jupyter-notebook:'+subkey].help_index = source[subkey].help_index;
        registry['jupyter-notebook:'+subkey].icon = source[subkey].icon;
        return source[subkey].handler;
    };

    // Will actually generate/register all the Jupyter actions
    var fun = function(){
        var final_actions = {};
        var k;
        for(k in _actions){
            if(_actions.hasOwnProperty(k)){
                // Js closure are function level not block level need to wrap in a IIFE
                // and append jupyter-notebook: to event name these things do intercept event so are wrapped
                // in a function that return false.
                var handler = _prepare_handler(final_actions, k, _actions);
                (function(key, handler){
                    final_actions['jupyter-notebook:'+key].handler = function(env, event){
                        handler(env);
                        if(event){
                            event.preventDefault();
                        }
                        return false;
                    };
                })(k, handler);
            }
        }

        for(k in custom_ignore){
            // Js closure are function level not block level need to wrap in a IIFE
            // same as above, but decide for themselves whether or not they intercept events.
            if(custom_ignore.hasOwnProperty(k)){
                handler = _prepare_handler(final_actions, k, custom_ignore);
                (function(key, handler){
                    final_actions['jupyter-notebook:'+key].handler = function(env, event){
                        return handler(env, event);
                    };
                })(k, handler);
            }
        }

        return final_actions;
    };
    ActionHandler.prototype._actions = fun();


    /**
     *  extend the environment variable that will be pass to handlers
     **/
    ActionHandler.prototype.extend_env = function(env){
        for(var k in env){
            this.env[k] = env[k];
        }
    };

    ActionHandler.prototype.register = function(action, name, prefix){
        /**
         * Register an `action` with an optional name and prefix.
         *
         * if name and prefix are not given they will be determined automatically.
         * if action if just a `function` it will be wrapped in an anonymous action.
         *
         * @return the full name to access this action .
         **/
        action = this.normalise(action);
        if( !name ){
            name = 'autogenerated-'+String(action.handler);
        }
        prefix = prefix || 'auto';
        var full_name = prefix+':'+name;
        this._actions[full_name] = action;
        return full_name;

    };


    ActionHandler.prototype.normalise = function(data){
        /**
         * given an `action` or `function`, return a normalised `action`
         * by setting all known attributes and removing unknown attributes;
         **/
        if(typeof(data) === 'function'){
            data = {handler:data};
        }
        if(typeof(data.handler) !== 'function'){
            throw new Error('unknown datatype, cannot register');
        }
        var _data = data;
        data = {};
        data.handler = _data.handler;
        data.help = _data.help || '';
        data.icon = _data.icon || '';
        data.help_index = _data.help_index || '';
        return data;
    };

    ActionHandler.prototype.get_name = function(name_or_data){
        /**
         * given an `action` or `name` of a action, return the name attached to this action.
         * if given the name of and corresponding actions does not exist in registry, return `null`.
         **/

        if(typeof(name_or_data) === 'string'){
            warn_bad_name(name);
            if(this.exists(name_or_data)){
                return name_or_data;
            } else {
                return null;
            }
        } else {
            return this.register(name_or_data);
        }
    };

    ActionHandler.prototype.get = function(name){
        warn_bad_name(name);
        return this._actions[name];
    };

    ActionHandler.prototype.call = function(name, event, env){
        return this._actions[name].handler(env|| this.env, event);
    };

    ActionHandler.prototype.exists = function(name){
        return (typeof(this._actions[name]) !== 'undefined');
    };

    return {init:ActionHandler};

});