@@ -7,14 +7,16 @@ use std::{
7
7
#[ cfg( not( target_arch = "wasm32" ) ) ]
8
8
use anyhow:: { bail, Context } ;
9
9
use data:: filter:: { Comparator , FieldSpecifier , FilterConfig , FilterOn } ;
10
- use egui:: { Align , KeyboardShortcut , Modifiers } ;
10
+ use egui:: Align ;
11
11
use egui_extras:: { Column , TableBuilder } ;
12
12
use log:: info;
13
+ use shortcut:: Shortcuts ;
13
14
14
15
use self :: { data:: Data , data_display_options:: DataDisplayOptions } ;
15
16
16
17
mod data;
17
18
mod data_display_options;
19
+ mod shortcut;
18
20
19
21
#[ derive( serde:: Deserialize , serde:: Serialize ) ]
20
22
#[ serde( default ) ] // if we add new fields, give them default values when deserializing old state
@@ -25,11 +27,7 @@ pub struct LogViewerApp {
25
27
last_filename : Arc < Mutex < Option < PathBuf > > > ,
26
28
show_last_filename : bool ,
27
29
track_item_align : Option < Align > ,
28
- shortcut_prev : KeyboardShortcut ,
29
- shortcut_next : KeyboardShortcut ,
30
- shortcut_first : KeyboardShortcut ,
31
- shortcut_last : KeyboardShortcut ,
32
- shortcut_unfilter : KeyboardShortcut ,
30
+ shortcuts : Shortcuts ,
33
31
34
32
#[ serde( skip) ]
35
33
should_scroll : bool ,
@@ -46,11 +44,7 @@ impl Default for LogViewerApp {
46
44
loading_status : Default :: default ( ) ,
47
45
last_filename : Default :: default ( ) ,
48
46
track_item_align : Default :: default ( ) ,
49
- shortcut_prev : KeyboardShortcut :: new ( Modifiers :: NONE , egui:: Key :: ArrowUp ) ,
50
- shortcut_next : KeyboardShortcut :: new ( Modifiers :: NONE , egui:: Key :: ArrowDown ) ,
51
- shortcut_first : KeyboardShortcut :: new ( Modifiers :: NONE , egui:: Key :: Home ) ,
52
- shortcut_last : KeyboardShortcut :: new ( Modifiers :: NONE , egui:: Key :: End ) ,
53
- shortcut_unfilter : KeyboardShortcut :: new ( Modifiers :: NONE , egui:: Key :: Escape ) ,
47
+ shortcuts : Default :: default ( ) ,
54
48
should_scroll : Default :: default ( ) ,
55
49
show_last_filename : true ,
56
50
}
@@ -441,23 +435,23 @@ impl LogViewerApp {
441
435
}
442
436
443
437
fn check_shortcuts ( & mut self , ui : & mut egui:: Ui ) {
444
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcut_prev ) ) {
438
+ if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . prev ) ) {
445
439
self . move_selected_prev ( ) ;
446
440
}
447
441
448
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcut_next ) ) {
442
+ if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . next ) ) {
449
443
self . move_selected_next ( ) ;
450
444
}
451
445
452
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcut_first ) ) {
446
+ if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . first ) ) {
453
447
self . move_selected_first ( ) ;
454
448
}
455
449
456
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcut_last ) ) {
450
+ if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . last ) ) {
457
451
self . move_selected_last ( ) ;
458
452
}
459
453
460
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcut_unfilter ) ) {
454
+ if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . unfilter ) ) {
461
455
if let Some ( data) = self . data . as_mut ( ) {
462
456
data. unfilter ( ) ;
463
457
}
@@ -495,7 +489,7 @@ impl LogViewerApp {
495
489
. button ( "Unfilter" )
496
490
. on_hover_text ( format ! (
497
491
"Clears Filter ({})" ,
498
- ui. ctx( ) . format_shortcut( & self . shortcut_unfilter )
492
+ ui. ctx( ) . format_shortcut( & self . shortcuts . unfilter )
499
493
) )
500
494
. clicked ( )
501
495
{
@@ -580,7 +574,7 @@ impl LogViewerApp {
580
574
. button ( "⏪" )
581
575
. on_hover_text ( format ! (
582
576
"First ({})" ,
583
- ui. ctx( ) . format_shortcut( & self . shortcut_first )
577
+ ui. ctx( ) . format_shortcut( & self . shortcuts . first )
584
578
) )
585
579
. clicked ( )
586
580
{
@@ -590,7 +584,7 @@ impl LogViewerApp {
590
584
. button ( "⬆" )
591
585
. on_hover_text ( format ! (
592
586
"Previous ({})" ,
593
- ui. ctx( ) . format_shortcut( & self . shortcut_prev )
587
+ ui. ctx( ) . format_shortcut( & self . shortcuts . prev )
594
588
) )
595
589
. clicked ( )
596
590
{
@@ -600,7 +594,7 @@ impl LogViewerApp {
600
594
. button ( "⬇" )
601
595
. on_hover_text ( format ! (
602
596
"Next ({})" ,
603
- ui. ctx( ) . format_shortcut( & self . shortcut_next )
597
+ ui. ctx( ) . format_shortcut( & self . shortcuts . next )
604
598
) )
605
599
. clicked ( )
606
600
{
@@ -610,7 +604,7 @@ impl LogViewerApp {
610
604
. button ( "⏩" )
611
605
. on_hover_text ( format ! (
612
606
"Last ({})" ,
613
- ui. ctx( ) . format_shortcut( & self . shortcut_last )
607
+ ui. ctx( ) . format_shortcut( & self . shortcuts . last )
614
608
) )
615
609
. clicked ( )
616
610
{
0 commit comments